From 3a2803a968a8cdae88389502b1b876ec9a5d6d85 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 20 Nov 2021 05:29:31 +0200 Subject: [PATCH 35/35] Make unit stack size display configurable See osdn #43190 Signed-off-by: Marko Lindqvist --- client/control.c | 21 +++++++++++++++++++++ client/control.h | 2 ++ client/gui-qt/menu.cpp | 14 ++++++++++++++ client/gui-qt/menu.h | 1 + client/gui-qt/shortcuts.cpp | 4 +++- client/gui-qt/shortcuts.h | 3 ++- client/options.c | 6 ++++++ client/options.h | 1 + client/tilespec.c | 3 ++- 9 files changed, 52 insertions(+), 3 deletions(-) diff --git a/client/control.c b/client/control.c index 8732f81dd5..a096d694ab 100644 --- a/client/control.c +++ b/client/control.c @@ -2386,6 +2386,19 @@ void request_toggle_city_trade_routes(void) update_map_canvas_visible(); } +/**********************************************************************//** + Toggle display of unit stack sizes +**************************************************************************/ +void request_toggle_unit_stack_size(void) +{ + if (!can_client_change_view()) { + return; + } + + gui_options.draw_unit_stack_size ^= 1; + update_map_canvas_visible(); +} + /**********************************************************************//** Toggle display of terrain **************************************************************************/ @@ -3730,6 +3743,14 @@ void key_city_trade_routes_toggle(void) request_toggle_city_trade_routes(); } +/**********************************************************************//** + Handle client request to toggle drawing of unit stack size information +**************************************************************************/ +void key_unit_stack_size_toggle(void) +{ + request_toggle_unit_stack_size(); +} + /**********************************************************************//** Handle user 'toggle terrain display' input **************************************************************************/ diff --git a/client/control.h b/client/control.h index bd3bb30a95..7fb5f3f236 100644 --- a/client/control.h +++ b/client/control.h @@ -149,6 +149,7 @@ void request_toggle_city_growth(void); void request_toggle_city_productions(void); void request_toggle_city_buycost(void); void request_toggle_city_trade_routes(void); +void request_toggle_unit_stack_size(void); void request_toggle_terrain(void); void request_toggle_coastline(void); void request_toggle_roads_rails(void); @@ -205,6 +206,7 @@ void key_city_growth_toggle(void); void key_city_productions_toggle(void); void key_city_buycost_toggle(void); void key_city_trade_routes_toggle(void); +void key_unit_stack_size_toggle(void); void key_terrain_toggle(void); void key_coastline_toggle(void); void key_roads_rails_toggle(void); diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 6172c46849..d801c42840 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -1138,6 +1138,12 @@ void mr_menu::setup_menus() act->setShortcut(QKeySequence(shortcut_to_string( fc_shortcuts::sc()->get_shortcut(SC_TRADE_ROUTES)))); connect(act, &QAction::triggered, this, &mr_menu::slot_city_traderoutes); + act = menu->addAction(_("Unit Stack Size")); + act->setCheckable(true); + act->setChecked(gui_options.draw_unit_stack_size); + act->setShortcut(QKeySequence(shortcut_to_string( + fc_shortcuts::sc()->get_shortcut(SC_STACK_SIZE)))); + connect(act, &QAction::triggered, this, &mr_menu::slot_stack_size); /* Select Menu */ menu = this->addMenu(_("Select")); @@ -3297,6 +3303,14 @@ void mr_menu::slot_city_traderoutes() key_city_trade_routes_toggle(); } +/**********************************************************************//** + Action "SHOW UNIT STACK SIZE" +**************************************************************************/ +void mr_menu::slot_stack_size() +{ + key_unit_stack_size_toggle(); +} + /**********************************************************************//** Action "SHOW FULLBAR" **************************************************************************/ diff --git a/client/gui-qt/menu.h b/client/gui-qt/menu.h index 1bc37836e5..ecf59266ae 100644 --- a/client/gui-qt/menu.h +++ b/client/gui-qt/menu.h @@ -366,6 +366,7 @@ private slots: void slot_city_production(); void slot_city_buycost(); void slot_city_traderoutes(); + void slot_stack_size(); void slot_city_names(); void zoom_in(); void zoom_scale_fonts(); diff --git a/client/gui-qt/shortcuts.cpp b/client/gui-qt/shortcuts.cpp index e0c7a3dca5..1e0265fb4c 100644 --- a/client/gui-qt/shortcuts.cpp +++ b/client/gui-qt/shortcuts.cpp @@ -170,7 +170,9 @@ fc_shortcut default_shortcuts[] = { {SC_GOBUILDCITY, Qt::Key_B, Qt::AllButtons, Qt::ShiftModifier, _("Go And Build City") }, {SC_GOJOINCITY, Qt::Key_J, Qt::AllButtons, Qt::ShiftModifier, - _("Go And Join City") } + _("Go And Join City") }, + {SC_STACK_SIZE, Qt::Key_S, Qt::AllButtons, Qt::ShiftModifier, + _("Unit Stack Size") } }; diff --git a/client/gui-qt/shortcuts.h b/client/gui-qt/shortcuts.h index 678deeb1b2..a580f70b31 100644 --- a/client/gui-qt/shortcuts.h +++ b/client/gui-qt/shortcuts.h @@ -90,7 +90,8 @@ enum shortcut_id { SC_RELOAD_LUA = 56, SC_ZOOM_RESET = 57, SC_GOBUILDCITY = 58, - SC_GOJOINCITY = 59 + SC_GOJOINCITY = 59, + SC_STACK_SIZE = 60 }; diff --git a/client/options.c b/client/options.c index 366141631e..a2942a9016 100644 --- a/client/options.c +++ b/client/options.c @@ -175,6 +175,7 @@ struct client_options gui_options = { .draw_native = FALSE, .draw_full_citybar = TRUE, .draw_unit_shields = TRUE, + .draw_unit_stack_size = TRUE, .player_dlg_show_dead_players = TRUE, .reqtree_show_icons = TRUE, .reqtree_curved_lines = FALSE, @@ -2084,6 +2085,11 @@ static struct client_option client_options[] = { "as the flags on units. If unset, the full flag will " "be drawn."), COC_GRAPHICS, GUI_STUB, TRUE, view_option_changed_callback), + GEN_BOOL_OPTION(draw_unit_stack_size, N_("Draw size of the unit stacks"), + N_("Setting this option will draw a numbers indicating " + "size of the unit stacks. Not all clients support " + "this."), + COC_GRAPHICS, GUI_STUB, TRUE, view_option_changed_callback), GEN_BOOL_OPTION(draw_focus_unit, N_("Draw the units in focus"), N_("Setting this option will cause the currently focused " "unit(s) to always be drawn, even if units are not " diff --git a/client/options.h b/client/options.h index de97e9e343..84d5ea803a 100644 --- a/client/options.h +++ b/client/options.h @@ -204,6 +204,7 @@ struct client_options bool draw_native; bool draw_full_citybar; bool draw_unit_shields; + bool draw_unit_stack_size; bool player_dlg_show_dead_players; bool reqtree_show_icons; diff --git a/client/tilespec.c b/client/tilespec.c index 88dbe0ddd0..2ec34bd509 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -4429,7 +4429,8 @@ static int fill_unit_sprite_array(const struct tileset *t, if (stack == 1 && punit->client.occupied) { ADD_SPRITE_FULL(t->sprites.unit.stack[0]); } else if (stack > 1) { - if (t->sprites.unit.num_stack_sprites >= stack) { + if (gui_options.draw_unit_stack_size + && t->sprites.unit.num_stack_sprites >= stack) { ADD_SPRITE(t->sprites.unit.stack[stack - 1], FALSE, FULL_TILE_X_OFFSET + t->unit_offset_x, FULL_TILE_Y_OFFSET + t->unit_offset_y); -- 2.33.0