Skip to content

Commit

Permalink
Implement the tile debugger selection logic
Browse files Browse the repository at this point in the history
See #632.
  • Loading branch information
lmoureaux committed Sep 12, 2021
1 parent 2715996 commit 5ddba34
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void set_hover_state(struct unit_list *punits, enum cursor_hover_state state,
enum unit_orders order)
{
fc_assert_ret((punits && unit_list_size(punits) > 0)
|| state == HOVER_NONE);
|| (state == HOVER_NONE || state == HOVER_DEBUG_TILE));
fc_assert_ret(state == HOVER_CONNECT || activity == ACTIVITY_LAST);
fc_assert_ret((state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT)
|| order == ORDER_LAST);
Expand Down Expand Up @@ -1285,6 +1285,7 @@ void control_mouse_cursor(struct tile *ptile)
break;
case HOVER_ACT_SEL_TGT:
case HOVER_GOTO_SEL_TGT:
case HOVER_DEBUG_TILE:
/* Select a tile to target / find targets on. */
mouse_cursor_type = CURSOR_SELECT;
break;
Expand Down Expand Up @@ -2748,6 +2749,16 @@ void do_map_click(struct tile *ptile, enum quickselect_type qtype)
fc_assert(action_id_exists(goto_last_action));
do_unit_goto(ptile);
break;
case HOVER_DEBUG_TILE:
// This function is called twice, once on mouse press and once on mouse
// release. We get SELECT_POPUP the second time.
// We don't want to do anything the first time we're called to avoid
// selecting units or opening the tile dialog.
if (qtype == SELECT_POPUP) {
debug_tile(ptile);
clear_hover_state();
}
return;
}

clear_hover_state();
Expand Down Expand Up @@ -3032,6 +3043,9 @@ void key_cancel_action()
keyboardless_goto_active = false;
keyboardless_goto_start_tile = NULL;
break;
case HOVER_DEBUG_TILE:
clear_hover_state();
break;
case HOVER_NONE:
break;
};
Expand Down
1 change: 1 addition & 0 deletions client/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum cursor_hover_state {
HOVER_PATROL,
HOVER_ACT_SEL_TGT,
HOVER_GOTO_SEL_TGT,
HOVER_DEBUG_TILE,
};

// Selecting unit from a stack without popup.
Expand Down
1 change: 1 addition & 0 deletions client/goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ static void goto_fill_parameter_full(struct goto_map *goto_map,
case HOVER_NONE:
case HOVER_PARADROP:
case HOVER_ACT_SEL_TGT:
case HOVER_DEBUG_TILE:
fc_assert_msg(hover_state != HOVER_NONE, "Goto with HOVER_NONE?");
fc_assert_msg(hover_state != HOVER_PARADROP,
"Goto with HOVER_PARADROP?");
Expand Down
19 changes: 19 additions & 0 deletions client/gui-qt/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ void map_view::show_debugger()
if (!m_debugger) {
// We never destroy it once it's created.
m_debugger = new freeciv::tileset_debugger(this);
connect(m_debugger, &freeciv::tileset_debugger::tile_picking_requested,
[](bool active) {
if (active) {
set_hover_state(NULL, HOVER_DEBUG_TILE, ACTIVITY_LAST, NULL,
NO_TARGET, NO_TARGET, ACTION_NONE,
ORDER_LAST);
} else if (!active && hover_state == HOVER_DEBUG_TILE) {
clear_hover_state();
}
});
}

m_debugger->show();
Expand Down Expand Up @@ -797,3 +807,12 @@ void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y,

p.end();
}

/**
* Callback to set the tile being debugged.
*/
void debug_tile(tile *tile)
{
fc_assert_ret(queen()->mapview_wdg->m_debugger);
queen()->mapview_wdg->m_debugger->set_tile(tile);
}
4 changes: 4 additions & 0 deletions client/gui-qt/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void draw_calculated_trade_routes(QPainter *painter);
**************************************************************************/
class map_view : public QWidget {
Q_OBJECT

// Ought to be a private slot
friend void debug_tile(tile *tile);

void shortcut_pressed(int key);
void shortcut_released(Qt::MouseButton mb);

Expand Down
2 changes: 2 additions & 0 deletions client/include/mapview_g.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ GUI_FUNC_PROTO(void, draw_selection_rectangle, int canvas_x, int canvas_y,
GUI_FUNC_PROTO(void, tileset_changed, void)
void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y,
struct city *pcity, int *width, int *height);

void debug_tile(tile *t);
2 changes: 2 additions & 0 deletions client/mapctrl_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ void update_line(int canvas_x, int canvas_y)
case HOVER_NONE:
case HOVER_PARADROP:
case HOVER_ACT_SEL_TGT:
case HOVER_DEBUG_TILE:
break;
};
}
Expand Down Expand Up @@ -666,6 +667,7 @@ void overview_update_line(int overview_x, int overview_y)
case HOVER_NONE:
case HOVER_PARADROP:
case HOVER_ACT_SEL_TGT:
case HOVER_DEBUG_TILE:
break;
};
}
Expand Down
1 change: 1 addition & 0 deletions client/mapview_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0)
case HOVER_NONE:
case HOVER_PARADROP:
case HOVER_ACT_SEL_TGT:
case HOVER_DEBUG_TILE:
break;
};
if (rectangle_active) {
Expand Down

0 comments on commit 5ddba34

Please sign in to comment.