diff --git a/changelog.md b/changelog.md index d614ef65ce40..8098d4e3c067 100644 --- a/changelog.md +++ b/changelog.md @@ -256,6 +256,8 @@ TODO! REMOVE ALL DUPLICATE ENTRIES FOR CHANGES THAT BELONG UNDER THE 1.13.13 - 1 * Fixed [scenario] map_file= being unusable in most circumstances. ## Version 1.14.3+dev + ### User interface + * Improved the layout of the Statistics dialog. ## Version 1.14.3 ### AI diff --git a/data/gui/window/statistics_dialog.cfg b/data/gui/window/statistics_dialog.cfg index ab841894c13e..6a956732a546 100644 --- a/data/gui/window/statistics_dialog.cfg +++ b/data/gui/window/statistics_dialog.cfg @@ -440,78 +440,15 @@ grow_factor = 0 [column] - horizontal_grow = true - - [grid] - - [row] - - [column] - grow_factor = 0 - border = "all" - border_size = 5 - horizontal_alignment = "left" - - [menu_button] - id = "scenario_menu" - definition = "default" - [/menu_button] - [/column] - - [column] - grow_factor = 1 - border = all - border_size = 5 - horizontal_alignment = "right" - - [horizontal_listbox] - id = "tab_bar" - - [list_definition] - [row] - [column] - {_GUI_STATS_TAB_BAR} - [/column] - [/row] - [/list_definition] - - [list_data] - [row] - - [column] - - [widget] - id = "tab_label" - label = _ "Scenario" - [/widget] - - [/column] - - [/row] - - [row] - - [column] - - [widget] - id = "tab_label" - label = _ "Campaign" - [/widget] - - [/column] - - [/row] - - [/list_data] - - [/horizontal_listbox] - - [/column] - - [/row] - - [/grid] + grow_factor = 0 + border = "all" + border_size = 5 + horizontal_alignment = "left" + [menu_button] + id = "scenario_menu" + definition = "default" + [/menu_button] [/column] [/row] diff --git a/src/gui/dialogs/statistics_dialog.cpp b/src/gui/dialogs/statistics_dialog.cpp index 877b61aeb123..fde31e2050af 100644 --- a/src/gui/dialogs/statistics_dialog.cpp +++ b/src/gui/dialogs/statistics_dialog.cpp @@ -30,24 +30,21 @@ #include "gui/widgets/window.hpp" #include "team.hpp" #include "units/types.hpp" - #include "utils/functional.hpp" + #include namespace gui2 { namespace dialogs { - -static bool use_campaign = false; - REGISTER_DIALOG(statistics_dialog) statistics_dialog::statistics_dialog(const team& current_team) : current_team_(current_team) , campaign_(statistics::calculate_stats(current_team.save_id_or_number())) , scenarios_(statistics::level_stats(current_team.save_id_or_number())) - , scenario_index_(scenarios_.size() - 1) + , selection_index_(scenarios_.size()) // The extra All Scenarios menu entry makes size() a valid initial index. , main_stat_table_() { } @@ -64,24 +61,19 @@ void statistics_dialog::pre_show(window& window) // Set up scenario menu // std::vector menu_items; + + // Keep this first! + menu_items.emplace_back("label", _("All Scenarios")); + for(const auto& scenario : scenarios_) { menu_items.emplace_back("label", *scenario.first); } menu_button& scenario_menu = find_widget(&window, "scenario_menu", false); - scenario_menu.set_values(menu_items, scenario_index_); + scenario_menu.set_values(menu_items, selection_index_); scenario_menu.connect_click_handler(std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window))); - // - // Set up tab toggle - // - listbox& tab_bar = find_widget(&window, "tab_bar", false); - tab_bar.select_row(use_campaign); - - connect_signal_notify_modified(tab_bar, - std::bind(&statistics_dialog::on_tab_select, this, std::ref(window))); - // // Set up primary stats list // @@ -95,7 +87,7 @@ void statistics_dialog::pre_show(window& window) inline const statistics::stats& statistics_dialog::current_stats() { - return use_campaign ? campaign_ : *scenarios_[scenario_index_].second; + return selection_index_ == 0 ? campaign_ : *scenarios_[selection_index_ - 1].second; } void statistics_dialog::add_stat_row(window& window, const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost) @@ -193,7 +185,7 @@ void statistics_dialog::update_lists(window& window) // // Update damage stats list // - const bool show_this_turn = use_campaign || scenario_index_ + 1 == scenarios_.size(); + const bool show_this_turn = selection_index_ == scenarios_.size(); listbox& damage_list = find_widget(&window, "stats_list_damage", false); @@ -216,24 +208,12 @@ void statistics_dialog::update_lists(window& window) ); } -void statistics_dialog::on_tab_select(window& window) -{ - const bool is_campaign_tab = find_widget(&window, "tab_bar", false).get_selected_row() == 1; - - if(use_campaign != is_campaign_tab) { - use_campaign = is_campaign_tab; - - update_lists(window); - } -} - void statistics_dialog::on_scenario_select(window& window) { const std::size_t new_index = find_widget(&window, "scenario_menu", false).get_value(); - if(scenario_index_ != new_index) { - scenario_index_ = new_index; - + if(selection_index_ != new_index) { + selection_index_ = new_index; update_lists(window); } } diff --git a/src/gui/dialogs/statistics_dialog.hpp b/src/gui/dialogs/statistics_dialog.hpp index d2ca3d50b2bd..e079a976afcf 100644 --- a/src/gui/dialogs/statistics_dialog.hpp +++ b/src/gui/dialogs/statistics_dialog.hpp @@ -41,7 +41,7 @@ class statistics_dialog : public modal_dialog /** * Picks out the stats structure that was selected for displaying. */ - inline const statistics::stats & current_stats(); + inline const statistics::stats& current_stats(); void add_stat_row(window& window, const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost = true); @@ -58,14 +58,13 @@ class statistics_dialog : public modal_dialog void on_primary_list_select(window& window); void on_scenario_select(window& window); - void on_tab_select(window& window); const team& current_team_; const statistics::stats campaign_; const statistics::levels scenarios_; - std::size_t scenario_index_; + std::size_t selection_index_; std::vector main_stat_table_; };