Hilite the terrain the mouse is over in the scenario editor so that you can tell which terrain will be affected when clicking, even in cases where it's not so obvious (for example when the cursor's hotspot is in an unexpected place).

This commit is contained in:
2015-02-01 22:22:32 -05:00
parent 0bfe08c0d9
commit b4e82733a4
4 changed files with 42 additions and 30 deletions

View File

@@ -32,7 +32,7 @@ rectangle border_rect[4];
short current_block_edited = 0;
short current_terrain_type = 0;
short safety = 0;
location spot_hit,last_spot_hit(-1,-1);
location spot_hit,last_spot_hit(-1,-1),mouse_spot(-1,-1);
bool sign_error_received = false;
short copied_spec = -1;
@@ -137,6 +137,21 @@ void init_screen_locs() {
}
}
void update_mouse_spot(location the_point) {
rectangle terrain_rect = world_screen;
terrain_rect.inset(8,8);
if(terrain_rect.contains(the_point)) {
if(cur_viewing_mode == 0) {
mouse_spot.x = (the_point.x - TER_RECT_UL_X - 8) / 28;
mouse_spot.y = (the_point.y - TER_RECT_UL_Y - 8) / 36;
} else {
short scale = mini_map_scales[cur_viewing_mode - 1];
mouse_spot.x = (the_point.x - TER_RECT_UL_X - 8) / scale;
mouse_spot.y = (the_point.y - TER_RECT_UL_Y - 8) / scale;
}
} else mouse_spot = {-1,-1};
}
bool handle_action(location the_point,sf::Event /*event*/) {
using kb = sf::Keyboard;
short i,j, x;
@@ -434,32 +449,27 @@ bool handle_action(location the_point,sf::Event /*event*/) {
mouse_button_held = false;
}
}
if((overall_mode < MODE_MAIN_SCREEN)
&& (the_point.x > world_screen.left + 8) && (the_point.x < world_screen.right - 8)
&& (the_point.y > world_screen.top + 8) && (the_point.y < world_screen.bottom - 8) ) {
update_mouse_spot(the_point);
if(overall_mode < MODE_MAIN_SCREEN) {;
if(mouse_spot.x >= 0 && mouse_spot.y >= 0) {
if(cur_viewing_mode == 0) {
i = (the_point.x - TER_RECT_UL_X - 8) / 28;
j = (the_point.y - TER_RECT_UL_Y - 8) / 36;
spot_hit.x = cen_x + i - 4;
spot_hit.y = cen_y + j - 4;
spot_hit.x = cen_x + mouse_spot.x - 4;
spot_hit.y = cen_y + mouse_spot.y - 4;
if((i < 0) || (i > 8) || (j < 0) || (j > 8))
spot_hit.x = -1;
}
else {
short scale = mini_map_scales[cur_viewing_mode - 1];
i = (the_point.x - TER_RECT_UL_X - 8) / scale;
j = (the_point.y - TER_RECT_UL_Y - 8) / scale;
if(scale > 4) {
if(cen_x + 5 > 256 / scale)
spot_hit.x = cen_x + 5 - 256/scale + i;
else spot_hit.x = i;
spot_hit.x = cen_x + 5 - 256/scale + mouse_spot.x;
else spot_hit.x = mouse_spot.x;
if(cen_y + 5 > 324 / scale)
spot_hit.y = cen_y + 5 - 324/scale + j;
else spot_hit.y = j;
spot_hit.y = cen_y + 5 - 324/scale + mouse_spot.y;
else spot_hit.y = mouse_spot.y;
} else {
spot_hit.x = i;
spot_hit.y = j;
spot_hit.x = mouse_spot.x;
spot_hit.y = mouse_spot.y;
}
}
@@ -929,7 +939,6 @@ bool handle_action(location the_point,sf::Event /*event*/) {
draw_terrain();
}
if(overall_mode < MODE_MAIN_SCREEN) {
if((the_point.in(border_rect[0])) & (cen_y > (editing_town ? 4 : 3))) {
cen_y--;
if(ctrl_hit)

View File

@@ -52,6 +52,7 @@ void start_special_editing(short mode,short just_redo_text);
void town_entry(location spot_hit);
void start_dialogue_editing(short restoring);
bool is_erasable_water(short i,short j);
void update_mouse_spot(location the_point);
bool monst_on_space(location loc,short m_num);
void place_edit_special(location loc);

View File

@@ -57,7 +57,7 @@ extern std::array<rb_t,NRS> right_button_status;
short mini_map_scales[3] = {12, 6, 4};
// TODO: What is this for?
//extern btn_t buttons[];
extern location cur_out;
extern location cur_out, mouse_spot;
short num_ir[3] = {12,10,4};
@@ -81,6 +81,7 @@ sf::Texture roads_gworld;
sf::Texture missiles_gworld;
sf::Texture status_gworld;
sf::Texture pc_gworld;
const sf::Color hilite_colour = {0xff, 0x00, 0x80, 0x40};
extern tessel_ref_t map_pat[];
// begin new stuff
@@ -670,12 +671,6 @@ void draw_terrain(){
rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to);
tiny_to.offset(0,-7);
}
if((t_to_draw == 7) || (t_to_draw == 10) || (t_to_draw == 13) || (t_to_draw == 16)) {
tiny_from = base_small_button_from;
tiny_from.offset(7 * (3),7 * (2));
rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to);
tiny_to.offset(0,-7);
}
//if(is_s_d(cen_x + q - 4,cen_y + r - 4)) {
//}
if(!editing_town) {
@@ -774,6 +769,14 @@ void draw_terrain(){
}
}
if(where_draw == mouse_spot) {
rectangle destrec;
destrec.left = 8 + BITMAP_WIDTH * where_draw.x;
destrec.right = destrec.left + BITMAP_WIDTH;
destrec.top = 8 + BITMAP_HEIGHT * where_draw.y;
destrec.bottom = destrec.top + BITMAP_HEIGHT;
fill_rect(ter_draw_gworld, destrec, hilite_colour);
}
}
if(editing_town) {
draw_monsts();
@@ -991,9 +994,6 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
}
void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short size) {
location where_draw;
// TODO: Update for new 12x12 map graphics, rather than 4x4
rectangle dest_rect = {0,0,size,size},from_rect = {0,0,12,12};
short picture_wanted;
bool drawLargeIcon = false;
@@ -1005,8 +1005,6 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
picture_wanted = scenario.ter_types[terrain_to_draw].picture;
}
where_draw.x = (char) i;
where_draw.y = (char) j;
dest_rect.offset(8 + size * i,8 + size * j);
if(drawLargeIcon) {
if(picture_wanted >= 1000) {
@@ -1061,6 +1059,9 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
}
break;
}
if(loc(i,j) == mouse_spot) {
fill_rect(ter_draw_gworld, dest_rect, hilite_colour);
}
}
/* Draw a bitmap in the world window. hor in 0 .. 8, vert in 0 .. 8,

View File

@@ -157,6 +157,7 @@ void Handle_One_Event() {
case sf::Event::MouseMoved:
if(mouse_button_held)
handle_action(loc(event.mouseMove.x,event.mouseMove.y),event);
update_mouse_spot(loc(event.mouseMove.x,event.mouseMove.y));
break;
case sf::Event::MouseButtonReleased: