Unit List + Game Stats: don't show dialogs if nothing to show
This commit is contained in:
parent
ac7508d427
commit
b2cd7fa1df
5 changed files with 47 additions and 44 deletions
|
@ -35,13 +35,11 @@
|
|||
#include "formatter.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "game_classification.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "play_controller.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "units/map.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
#include "units/unit.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
|
@ -54,9 +52,10 @@ namespace gui2
|
|||
|
||||
REGISTER_DIALOG(game_stats)
|
||||
|
||||
tgame_stats::tgame_stats(game_board& board, const int viewing_team)
|
||||
tgame_stats::tgame_stats(game_board& board, const int viewing_team, int& selected_index)
|
||||
: board_(board)
|
||||
, viewing_team_(board_.teams()[viewing_team])
|
||||
, selected_index_(selected_index)
|
||||
{
|
||||
for(const auto& team : board_.teams()) {
|
||||
team_data_.push_back(board_.calculate_team_data(team, team.side()));
|
||||
|
|
|
@ -14,32 +14,36 @@
|
|||
#ifndef GUI_DIALOGS_GAME_STATS_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_GAME_STATS_HPP_INCLUDED
|
||||
|
||||
#include "game_board.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "team.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class display;
|
||||
class game_board;
|
||||
class team;
|
||||
struct team_data;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class ttext_;
|
||||
|
||||
class tgame_stats : public tdialog
|
||||
{
|
||||
public:
|
||||
tgame_stats(game_board& board, const int viewing_team);
|
||||
tgame_stats(game_board& board, const int viewing_team, int& selected_index);
|
||||
|
||||
int get_selected_index() const
|
||||
static execute(game_board& board, const int viewing_team, int& selected_index, CVideo& video)
|
||||
{
|
||||
return selected_index_;
|
||||
if(std::all_of(board.teams().begin(), board.teams().end(), [](team& team) { return team.hidden(); })) {
|
||||
show_transient_message(video, "", _("No visible sides found."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return tgame_stats(board, viewing_team, selected_index).show(video);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -50,7 +54,7 @@ private:
|
|||
|
||||
std::vector<team_data> team_data_;
|
||||
|
||||
int selected_index_;
|
||||
int& selected_index_;
|
||||
|
||||
unit_const_ptr get_leader(const int side);
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "gui/widgets/window.hpp"
|
||||
#include "display.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "units/map.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
|
@ -49,16 +48,10 @@ namespace gui2
|
|||
|
||||
REGISTER_DIALOG(unit_list)
|
||||
|
||||
tunit_list::tunit_list(const display& gui)
|
||||
tunit_list::tunit_list(unit_ptr_vector& unit_list, map_location& scroll_to)
|
||||
: unit_list_(unit_list)
|
||||
, scroll_to_(scroll_to)
|
||||
{
|
||||
const unit_map& units = gui.get_units();
|
||||
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
|
||||
if(i->side() != gui.viewing_side()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unit_list_.push_back(i.get_shared_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
static std::string format_level_string(const int level)
|
||||
|
@ -116,8 +109,6 @@ void tunit_list::pre_show(twindow& window)
|
|||
|
||||
window.keyboard_capture(&list);
|
||||
|
||||
if(unit_list_.empty()) return;
|
||||
|
||||
for(const unit_const_ptr& unit : unit_list_) {
|
||||
std::map<std::string, string_map> row_data;
|
||||
string_map column;
|
||||
|
@ -204,21 +195,27 @@ void tunit_list::post_show(twindow& window)
|
|||
if(get_retval() == twindow::OK) {
|
||||
const int selected_row = find_widget<tlistbox>(&window, "units_list", false).get_selected_row();
|
||||
|
||||
location_of_selected_unit_ = unit_list_[selected_row].get()->get_location();
|
||||
scroll_to_ = unit_list_[selected_row].get()->get_location();
|
||||
}
|
||||
}
|
||||
|
||||
void show_unit_list(display& gui)
|
||||
{
|
||||
gui2::tunit_list dlg(gui);
|
||||
unit_ptr_vector unit_list;
|
||||
map_location scroll_to;
|
||||
|
||||
dlg.show(gui.video());
|
||||
const unit_map& units = gui.get_units();
|
||||
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
|
||||
if(i->side() != gui.viewing_side()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dlg.get_retval() == gui2::twindow::OK) {
|
||||
const map_location& loc = dlg.get_location_to_scroll_to();
|
||||
unit_list.push_back(i.get_shared_ptr());
|
||||
}
|
||||
|
||||
gui.scroll_to_tile(loc, display::WARP);
|
||||
gui.select_hex(loc);
|
||||
if(gui2::tunit_list::execute(unit_list, scroll_to, gui.video())) {
|
||||
gui.scroll_to_tile(scroll_to, display::WARP);
|
||||
gui.select_hex(scroll_to);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
#ifndef GUI_DIALOGS_UNIT_LIST_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_UNIT_LIST_HPP_INCLUDED
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
|
||||
|
@ -27,26 +29,29 @@ class display;
|
|||
namespace gui2
|
||||
{
|
||||
|
||||
class ttext_;
|
||||
using unit_ptr_vector = std::vector<unit_const_ptr>;
|
||||
|
||||
void show_unit_list(display& gui);
|
||||
|
||||
class tunit_list : public tdialog
|
||||
{
|
||||
typedef std::vector<unit_const_ptr> unit_ptr_vector;
|
||||
|
||||
public:
|
||||
explicit tunit_list(const display& gui);
|
||||
explicit tunit_list(unit_ptr_vector& unit_list, map_location& scroll_to);
|
||||
|
||||
map_location get_location_to_scroll_to() const
|
||||
static bool execute(unit_ptr_vector& unit_list, map_location& scroll_to, CVideo& video)
|
||||
{
|
||||
return location_of_selected_unit_;
|
||||
if(unit_list.empty()) {
|
||||
show_transient_message(video, "", _("No units found."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return tunit_list(unit_list, scroll_to).show(video);
|
||||
}
|
||||
|
||||
private:
|
||||
unit_ptr_vector unit_list_;
|
||||
unit_ptr_vector& unit_list_;
|
||||
|
||||
map_location location_of_selected_unit_;
|
||||
map_location& scroll_to_;
|
||||
|
||||
/** Callbacks */
|
||||
void list_item_clicked(twindow& window);
|
||||
|
|
|
@ -152,12 +152,10 @@ void menu_handler::unit_list()
|
|||
|
||||
void menu_handler::status_table()
|
||||
{
|
||||
gui2::tgame_stats dlg(board(), gui_->viewing_team());
|
||||
int selected_index;
|
||||
|
||||
dlg.show(gui_->video());
|
||||
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
gui_->scroll_to_leader(teams()[dlg.get_selected_index()].side());
|
||||
if(gui2::tgame_stats::execute(board(), gui_->viewing_team(), selected_index, gui_->video())) {
|
||||
gui_->scroll_to_leader(teams()[selected_index].side());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue