diff --git a/src/game/boe.actions.cpp b/src/game/boe.actions.cpp index da6a4dfa..321db2fc 100644 --- a/src/game/boe.actions.cpp +++ b/src/game/boe.actions.cpp @@ -1689,7 +1689,7 @@ bool handle_keystroke(const sf::Event& event){ bool need_redraw=true; if (i>=1 && i<=3 && center.y < univ.town->in_town_rect.bottom && center.y < univ.town->max_dim - 5) center.y++; - else if (i>=6 && i<=9 && center.y > univ.town->in_town_rect.top && center.y > 4) + else if (i>=7 && i<=9 && center.y > univ.town->in_town_rect.top && center.y > 4) center.y--; if ((i%3)==1 && center.x > univ.town->in_town_rect.left && center.x > 4) center.x--; diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index eaac77e0..8ed5f32e 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -42,7 +42,6 @@ static cTown::cItem store_place_item; rectangle terrain_rects[256]; static rectangle terrain_rect_base = {0,0,16,16}; -extern rectangle terrain_buttons_rect; extern short cen_x, cen_y, cur_town; extern eScenMode overall_mode; @@ -1134,33 +1133,28 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { return true; } bool need_redraw = false; - if((the_point.in(border_rect[0])) & (cen_y > (editing_town ? 4 : 3))) { + short const minV=editing_town ? 4 : 3; + short const maxV=(editing_town ? town->max_dim - 1 : 48)-4; + if(the_point.in(border_rect[0]) && cen_y > minV) { cen_y--; - if(ctrl_hit) - cen_y = ((editing_town) ? 4 : 3); - need_redraw = true; - mouse_button_held = true; + if(ctrl_hit) cen_y = minV; + mouse_button_held = need_redraw = true; } - if((the_point.in(border_rect[1])) & (cen_x > (editing_town ? 4 : 3))) { + if(the_point.in(border_rect[1]) && cen_x > minV) { cen_x--; if(ctrl_hit) - cen_x = ((editing_town) ? 4 : 3); - need_redraw = true; - mouse_button_held = true; + cen_x = minV; + mouse_button_held = need_redraw = true; } - if((the_point.in(border_rect[2])) & (cen_y < (editing_town ? town->max_dim - 5 : 44))) { + if(the_point.in(border_rect[2]) && cen_y < maxV) { cen_y++; - if(ctrl_hit) - cen_y = (editing_town) ? town->max_dim - 5 : 44; - need_redraw = true; - mouse_button_held = true; + if(ctrl_hit) cen_y = maxV; + mouse_button_held = need_redraw = true; } - if((the_point.in(border_rect[3])) & (cen_x < (editing_town ? town->max_dim - 5 : 44))) { + if(the_point.in(border_rect[3]) && cen_x < maxV) { cen_x++; - if(ctrl_hit) - cen_x = (editing_town) ? town->max_dim - 5 : 44; - need_redraw = true; - mouse_button_held = true; + if(ctrl_hit) cen_x = maxV; + mouse_button_held = need_redraw = true; } if(need_redraw) { draw_terrain(); @@ -1760,9 +1754,12 @@ void handle_scroll(const sf::Event& event) { location pos { translate_mouse_coordinates({event.mouseMove.x,event.mouseMove.y}) }; int amount = event.mouseWheel.delta; if(overall_mode < MODE_MAIN_SCREEN && pos.in(terrain_rect)) { + short const minV=editing_town ? 4 : 3; + short const maxV=(editing_town ? town->max_dim - 1 : 48)-4; if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl)) - cen_x = minmax(4, town->max_dim - 5, cen_x - amount); - else cen_y = minmax(4, town->max_dim - 5, cen_y - amount); + cen_x = minmax(minV, maxV, cen_x - amount); + else + cen_y = minmax(minV, maxV, cen_y - amount); } } diff --git a/src/scenedit/scen.btnmg.cpp b/src/scenedit/scen.btnmg.cpp index c38cc16c..ae845510 100644 --- a/src/scenedit/scen.btnmg.cpp +++ b/src/scenedit/scen.btnmg.cpp @@ -14,10 +14,7 @@ extern rectangle right_sbar_rect; extern rectangle right_buttons[NRSONPAGE]; -rectangle right_scrollbar_rect; -extern short current_rs_top; -bool left_buttons_active = 1,right_buttons_active = 0; extern std::array left_button_status; extern std::vector right_button_status; extern std::shared_ptr right_sbar; diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 764cf1c6..a250e90b 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -37,7 +37,6 @@ #include "view_dialogs.hpp" extern short cen_x, cen_y,cur_town; -extern bool mouse_button_held; extern bool editing_town; extern short cur_viewing_mode; extern cTown* town; diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 2204603f..6800b31b 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -27,14 +27,8 @@ #include "scen.btnmg.hpp" -void load_terrain_template(); -short terrain_in_index(); -void put_terrain_in_template(); void undo_clip(); -short find_index_spot(); -bool is_s_d(); - extern cOutdoors* current_terrain; extern sf::RenderWindow mainPtr; extern sf::View mainView; @@ -45,39 +39,31 @@ extern cTown* town; extern short cur_viewing_mode; extern eScenMode overall_mode; eDrawMode draw_mode = DRAW_TERRAIN; -extern short available_dlog_buttons[NUM_DLOG_B]; extern bool editing_town; extern cScenario scenario; extern sf::Texture bg_gworld; extern rectangle right_buttons[NRSONPAGE]; -extern rectangle right_scrollbar_rect; extern std::shared_ptr right_sbar, pal_sbar; -extern bool left_buttons_active,right_buttons_active; extern std::array left_button_status; extern std::vector right_button_status; short mini_map_scales[3] = {12, 6, 4}; -// TODO: What is this for? -//extern btn_t buttons[]; extern location cur_out, mouse_spot; extern ter_num_t current_ground; -short num_ir[3] = {12,10,4}; - cCustomGraphics spec_scen_g; const sf::Color hilite_colour = {0xff, 0x00, 0x80, 0x40}; // begin new stuff rectangle blue_button_from = {120,235,134,251}; -rectangle start_button_from = {120,70,127,91}; rectangle base_small_button_from = {120,0,127,7}; extern rectangle palette_buttons[10][6]; extern ePalBtn town_buttons[6][10], out_buttons[6][10]; -rectangle palette_button_base = {0,0,18,26}; +static rectangle palette_button_base = {0,0,18,26}; rectangle terrain_buttons_rect = {0,0,410,294}; extern rectangle left_buttons[NLS][2]; // 0 - whole, 1 - blue button -rectangle left_button_base = {5,5,21,280}; -rectangle right_button_base = {RIGHT_AREA_UL_Y,RIGHT_AREA_UL_X,17,RIGHT_AREA_UL_Y}; +static rectangle left_button_base = {5,5,21,280}; +static rectangle right_button_base = {RIGHT_AREA_UL_Y,RIGHT_AREA_UL_X,17,RIGHT_AREA_UL_Y}; rectangle terrain_rect = {0,0,340,272}; std::string current_string[2]; extern rectangle terrain_rects[256]; @@ -688,7 +674,7 @@ void draw_terrain(){ frame_rect(mainPtr, terrain_rect, sf::Color::Black); // limits for town: only town and for outside terrain: sector+one outside bordering int const limits[]={editing_town ? 4 : 3, int(editing_town ? town->max_dim-1 : 48)-4}; - // if outside, resets the position to center of the map + // if the position is outside, resets it to center of the map if (cen_xlimits[1]) cen_x=(editing_town ? town->max_dim-1 : 48)/2; if (cen_ylimits[1]) cen_y=(editing_town ? town->max_dim-1 : 48)/2; for(short q = 0; q < 9; q++) @@ -775,41 +761,44 @@ void draw_terrain(){ rect_draw_some_item(vehicle_gworld,source_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, FIELD_WEB)) { + std::set list_fields; + for(auto const &field : town->preset_fields) + if(field.loc.x == cen_x + q - 4 && field.loc.y == cen_y + r - 4) + list_fields.insert(field.type); + if(list_fields.count(FIELD_WEB)) { from_rect = calc_rect(5,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, OBJECT_CRATE)) { + if(list_fields.count(OBJECT_CRATE)) { from_rect = calc_rect(6,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, OBJECT_BARREL)) { + if(list_fields.count(OBJECT_BARREL)) { from_rect = calc_rect(7,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, BARRIER_FIRE)) { + if(list_fields.count(BARRIER_FIRE)) { from_rect = calc_rect(8,4); rect_draw_some_item(*ResMgr::textures.get("teranim"),from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, FIELD_QUICKFIRE)) { + if(list_fields.count(FIELD_QUICKFIRE)) { from_rect = calc_rect(7,1); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, BARRIER_FORCE)) { + if(list_fields.count(BARRIER_FORCE)) { from_rect = calc_rect(10,4); rect_draw_some_item(*ResMgr::textures.get("teranim"),from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, OBJECT_BLOCK)) { + if(list_fields.count(OBJECT_BLOCK)) { from_rect = calc_rect(3,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - if(is_field_type(cen_x + q - 4,cen_y + r - 4, BARRIER_CAGE)) { + if(list_fields.count(BARRIER_CAGE)) { from_rect = calc_rect(0,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } for(short i = 0; i < 8; i++) { - eFieldType sfx = eFieldType(SFX_SMALL_BLOOD + i); - if(is_field_type(cen_x + q - 4,cen_y + r - 4,sfx)) { + if(list_fields.count(eFieldType(SFX_SMALL_BLOOD + i))) { from_rect = calc_rect(i,3); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } @@ -848,16 +837,13 @@ void draw_terrain(){ if(mouse_spot.x >= 0 && mouse_spot.y >= 0) { bool need_hilite = false, large_hilite = false; int d = dist(where_draw, mouse_spot); - if(overall_mode == MODE_SMALL_PAINTBRUSH && d <= 1) { - need_hilite = true; - large_hilite = true; - } else if((overall_mode == MODE_ERASER || overall_mode == MODE_SMALL_SPRAYCAN) && d <= 2) { - need_hilite = true; - large_hilite = true; - } else if((overall_mode == MODE_LARGE_PAINTBRUSH || overall_mode == MODE_LARGE_SPRAYCAN) && d <= 4) { - need_hilite = true; - large_hilite = true; - } else if(where_draw == mouse_spot) + if(overall_mode == MODE_SMALL_PAINTBRUSH && d <= 1) + large_hilite = need_hilite = true; + else if((overall_mode == MODE_ERASER || overall_mode == MODE_SMALL_SPRAYCAN) && d <= 2) + large_hilite = need_hilite = true; + else if((overall_mode == MODE_LARGE_PAINTBRUSH || overall_mode == MODE_LARGE_SPRAYCAN) && d <= 4) + large_hilite = need_hilite = true; + else if(where_draw == mouse_spot) need_hilite = true; else if(overall_mode == MODE_PLACE_CREATURE || overall_mode == MODE_PLACE_SAME_CREATURE) { extern short mode_count; @@ -937,8 +923,6 @@ void draw_terrain(){ } else { - // fixme: the bounds are now correct and the scrolling must be fluid, - // however, the select procedure is bad tileImage(mainPtr, terrain_rect,bg[17]); frame_rect(mainPtr, terrain_rect, sf::Color::Black); // Width available: 64 4x4 tiles, 42 6x6 tiles, or 21 12x12 tiles -- 256 pixels @@ -1116,16 +1100,13 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short location where_draw(i,j); bool need_hilite = false, large_hilite = false; int d = dist(where_draw, mouse_spot); - if(overall_mode == MODE_SMALL_PAINTBRUSH && d <= 1) { - need_hilite = true; - large_hilite = true; - } else if((overall_mode == MODE_ERASER || overall_mode == MODE_SMALL_SPRAYCAN) && d <= 2) { - need_hilite = true; - large_hilite = true; - } else if((overall_mode == MODE_LARGE_PAINTBRUSH || overall_mode == MODE_LARGE_SPRAYCAN) && d <= 4) { - need_hilite = true; - large_hilite = true; - } else if(where_draw == mouse_spot) + if(overall_mode == MODE_SMALL_PAINTBRUSH && d <= 1) + large_hilite = need_hilite = true; + else if((overall_mode == MODE_ERASER || overall_mode == MODE_SMALL_SPRAYCAN) && d <= 2) + large_hilite = need_hilite = true; + else if((overall_mode == MODE_LARGE_PAINTBRUSH || overall_mode == MODE_LARGE_SPRAYCAN) && d <= 4) + large_hilite = need_hilite = true; + else if(where_draw == mouse_spot) need_hilite = true; if(need_hilite) { fill_rect(mainPtr, dest_rect, hilite_colour); @@ -1210,9 +1191,8 @@ void place_location() { frame_rect(mainPtr, terrain_buttons_rect, sf::Color::Black); location mouse = translate_mouse_coordinates(sf::Mouse::getPosition(mainPtr)); - location moveTo(5, terrain_rects[255].top + 18); draw_rect = text_rect; - draw_rect.offset(moveTo); + draw_rect.offset({5, terrain_rects[255].top + 18}); if(overall_mode < MODE_MAIN_SCREEN) { // std::cout << "Mouse: " << mouse << " Buttons: " << terrain_buttons_rect << " Terrain: " << terrain_rect << std::endl; if(mouse.in(terrain_buttons_rect)) { @@ -1252,7 +1232,6 @@ void place_location() { if(sout.str().empty()) sout << "Center: x = " << cen_x << ", y = " << cen_y; } else { - moveTo.y += 13; // TODO: Not sure how important this is. sout << "Click terrain to edit. "; } TextStyle style; @@ -1260,21 +1239,18 @@ void place_location() { win_draw_string(mainPtr, draw_rect, sout.str(), eTextMode::LEFT_TOP, style); sout.str(""); - moveTo = location(260 ,terrain_rects[255].top + 18); draw_rect = text_rect; - draw_rect.offset(moveTo); + draw_rect.offset({260 ,terrain_rects[255].top + 18}); sout << current_terrain_type; win_draw_string(mainPtr, draw_rect, sout.str(), eTextMode::LEFT_TOP, style); sout.str(""); if(overall_mode < MODE_MAIN_SCREEN) { - moveTo = location(5,terrain_rects[255].bottom + 121); draw_rect = text_rect; - draw_rect.offset(moveTo); + draw_rect.offset({5,terrain_rects[255].bottom + 121}); win_draw_string(mainPtr, draw_rect, current_string[0], eTextMode::LEFT_TOP, style); - moveTo = location(RIGHT_AREA_WIDTH / 2,terrain_rects[255].bottom + 121); draw_rect = text_rect; - draw_rect.offset(moveTo); + draw_rect.offset({RIGHT_AREA_WIDTH / 2,terrain_rects[255].bottom + 121}); win_draw_string(mainPtr, draw_rect, current_string[1], eTextMode::LEFT_TOP, style); } @@ -1441,36 +1417,30 @@ void set_string(std::string string,std::string string2) { bool is_special(short i,short j) { location check(i,j); - if(editing_town) - for(short k = 0; k < town->special_locs.size(); k++) - if(town->special_locs[k] == check && town->special_locs[k].spec >= 0) + if(editing_town) { + for(auto const &spec : town->special_locs) + if(spec == check && spec.spec >= 0) return true; - if(!editing_town) - for(short k = 0; k < current_terrain->special_locs.size(); k++) - if(current_terrain->special_locs[k] == check && current_terrain->special_locs[k].spec >= 0) + } + else { + for(auto const &spec : current_terrain->special_locs) + if(spec == check && spec.spec >= 0) return true; - + } return false; } bool is_spot(short i,short j){ - if(editing_town) - return is_field_type(i,j,SPECIAL_SPOT); - return current_terrain->is_special_spot(i,j); + return editing_town ? is_field_type(i,j,SPECIAL_SPOT) : current_terrain->is_special_spot(i,j); } bool is_road(short i,short j){ - if(editing_town) - return is_field_type(i,j,SPECIAL_ROAD); - else - return current_terrain->is_road(i,j); + return editing_town ? is_field_type(i,j,SPECIAL_ROAD) : current_terrain->is_road(i,j); } bool is_field_type(short i,short j,eFieldType field_type) { - for(short k = 0; k < town->preset_fields.size(); k++) - if((town->preset_fields[k].type == field_type) && - (town->preset_fields[k].loc.x == i) && - (town->preset_fields[k].loc.y == j)) + for(auto const &field : town->preset_fields) + if(field.type == field_type && field.loc.x == i && field.loc.y == j) return true; return false; } @@ -1478,27 +1448,20 @@ bool is_field_type(short i,short j,eFieldType field_type) { void make_field_type(short i,short j,eFieldType field_type) { if(is_field_type(i,j,field_type)) return; - for(short k = 0; k < town->preset_fields.size(); k++) - if(town->preset_fields[k].type == 0) { - town->preset_fields[k].loc.x = i; - town->preset_fields[k].loc.y = j; - town->preset_fields[k].type = field_type; + cTown::cField the_field={{i,j}, field_type}; + for(auto &field : town->preset_fields) + if(field.type == 0) { + field=the_field; return; } - cTown::cField the_field; - the_field.loc.x = i; - the_field.loc.y = j; - the_field.type = field_type; town->preset_fields.push_back(the_field); } void take_field_type(short i,short j,eFieldType field_type) { - for(short k = 0; k < town->preset_fields.size(); k++) - if((town->preset_fields[k].type == field_type) && - (town->preset_fields[k].loc.x == i) && - (town->preset_fields[k].loc.y == j)) { - town->preset_fields[k].type = FIELD_DISPEL; + for(auto &field : town->preset_fields) + if(field.type == field_type && field.loc.x == i && field.loc.y == j) { + field.type = FIELD_DISPEL; return; } } @@ -1508,15 +1471,9 @@ bool container_there(location l) { return false; if(scenario.get_terrain(town->terrain(l.x,l.y)).special == eTerSpec::IS_A_CONTAINER) return true; - if(is_field_type(l.x,l.y, OBJECT_BARREL)) - return true; - if(is_field_type(l.x,l.y, OBJECT_CRATE)) - return true; - return 0; + return is_field_type(l.x,l.y, OBJECT_BARREL) || is_field_type(l.x,l.y, OBJECT_CRATE); } -void record_display_strings(){} - // Translate mouse event coordinates based on the global view and viewport sf::Vector2f translate_mouse_coordinates(sf::Vector2i const point) { return mainPtr.mapPixelToCoords(point, mainView); diff --git a/src/scenedit/scen.graphics.hpp b/src/scenedit/scen.graphics.hpp index 59dc00af..d7651833 100644 --- a/src/scenedit/scen.graphics.hpp +++ b/src/scenedit/scen.graphics.hpp @@ -37,5 +37,4 @@ bool is_road(short i,short j); short string_length(char *str); rectangle get_custom_rect (short which_rect); void init_dialogs(); -void record_display_strings(); sf::Vector2f translate_mouse_coordinates(sf::Vector2i const point); diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index 9d38e532..64a50d51 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -23,7 +23,6 @@ #include "render_shapes.hpp" // for colour constants extern short cen_x, cen_y; -extern bool mouse_button_held; extern short cur_viewing_mode; extern cTown* town; extern short mode_count,to_create; diff --git a/src/scenedit/scen.townout.cpp b/src/scenedit/scen.townout.cpp index a14d22a7..4d722ce1 100644 --- a/src/scenedit/scen.townout.cpp +++ b/src/scenedit/scen.townout.cpp @@ -25,7 +25,7 @@ #include "fileio.hpp" extern short cen_x, cen_y, overall_mode; -extern bool mouse_button_held,editing_town,change_made; +extern bool editing_town,change_made; extern short cur_viewing_mode; extern cTown* town; extern short mode_count,to_create,cur_town;