Moved UI object from display to play_controller

Design change from 075a9bac34.

After discussion with @celticminstrel, we decided it better for the controller to
own the UI object as well as the display object, instead of the display owning the UI.

I've added a pure virtual function declaration to controller_base to ensure all controllers
implement this.
This commit is contained in:
Charles Dang 2018-03-21 13:13:54 +11:00
parent a5344ae52a
commit 3254bb2c7d
7 changed files with 33 additions and 31 deletions

View file

@ -109,6 +109,9 @@ protected:
/** Get a reference to a display member a derived class uses. */ /** Get a reference to a display member a derived class uses. */
virtual display& get_display() = 0; virtual display& get_display() = 0;
/** Creates and displays the HUD UI that accompanies this controller. */
virtual void initialize_and_show_ui() = 0;
/** Get (optionally) a soundsources manager a derived class uses. */ /** Get (optionally) a soundsources manager a derived class uses. */
virtual soundsource::manager* get_soundsource_man() virtual soundsource::manager* get_soundsource_man()
{ {

View file

@ -79,19 +79,9 @@ class manager;
class gamemap; class gamemap;
namespace gui2
{
namespace dialogs
{
class ingame_ui_base;
}
}
class display : public events::sdl_handler class display : public events::sdl_handler
{ {
public: public:
using ui_t = gui2::dialogs::ingame_ui_base;
display(const display_context* dc, display(const display_context* dc,
std::weak_ptr<wb::manager> wb, std::weak_ptr<wb::manager> wb,
reports& reports_object, reports& reports_object,
@ -871,12 +861,6 @@ protected:
/** Draws the minimap. */ /** Draws the minimap. */
void draw_minimap(); void draw_minimap();
public:
virtual void initialize_ui()
{
}
private: private:
enum TERRAIN_TYPE { FOREGROUND, BACKGROUND }; enum TERRAIN_TYPE { FOREGROUND, BACKGROUND };
@ -1003,8 +987,6 @@ protected:
CVideo& video_; CVideo& video_;
std::unique_ptr<ui_t> ui_;
std::size_t currentTeam_; std::size_t currentTeam_;
bool dont_show_all_; // const team *viewpoint_; bool dont_show_all_; // const team *viewpoint_;
int xpos_, ypos_; int xpos_, ypos_;

View file

@ -178,6 +178,11 @@ class editor_controller : public controller_base,
mouse_handler_base& get_mouse_handler_base() override { return *this; } mouse_handler_base& get_mouse_handler_base() override { return *this; }
editor_display& get_display() override { return *gui_; } editor_display& get_display() override { return *gui_; }
virtual void initialize_and_show_ui() override
{
// TODO: IMPLEMENT
}
/** Get the current mouse action */ /** Get the current mouse action */
const mouse_action& get_mouse_action() const { return toolkit_->get_mouse_action(); } const mouse_action& get_mouse_action() const { return toolkit_->get_mouse_action(); }
/** Get the current mouse action */ /** Get the current mouse action */

View file

@ -28,7 +28,6 @@
#include "font/standard_colors.hpp" #include "font/standard_colors.hpp"
#include "game_board.hpp" #include "game_board.hpp"
#include "gettext.hpp" #include "gettext.hpp"
#include "gui/dialogs/game_ui.hpp"
#include "halo.hpp" #include "halo.hpp"
#include "log.hpp" #include "log.hpp"
#include "map/label.hpp" #include "map/label.hpp"
@ -91,15 +90,6 @@ game_display::~game_display()
} }
} }
void game_display::initialize_ui()
{
// Set member in the base class
ui_.reset(new gui2::dialogs::game_ui());
assert(ui_);
ui_->show(true);
}
void game_display::new_turn() void game_display::new_turn()
{ {
const time_of_day& tod = resources::tod_manager->get_time_of_day(); const time_of_day& tod = resources::tod_manager->get_time_of_day();

View file

@ -147,8 +147,6 @@ protected:
virtual void draw_hex_overlays() override; virtual void draw_hex_overlays() override;
public: public:
virtual void initialize_ui() override;
/** Set the attack direction indicator. */ /** Set the attack direction indicator. */
void set_attack_indicator(const map_location& src, const map_location& dst); void set_attack_indicator(const map_location& src, const map_location& dst);
void clear_attack_indicator(); void clear_attack_indicator();

View file

@ -32,6 +32,7 @@
#include "game_events/pump.hpp" #include "game_events/pump.hpp"
#include "game_state.hpp" #include "game_state.hpp"
#include "gettext.hpp" #include "gettext.hpp"
#include "gui/dialogs/game_ui.hpp"
#include "gui/dialogs/loading_screen.hpp" #include "gui/dialogs/loading_screen.hpp"
#include "gui/dialogs/transient_message.hpp" #include "gui/dialogs/transient_message.hpp"
#include "hotkey/command_executor.hpp" #include "hotkey/command_executor.hpp"
@ -148,6 +149,7 @@ play_controller::play_controller(const config& level,
, soundsources_manager_() , soundsources_manager_()
, persist_() , persist_()
, gui_() , gui_()
, ui_()
, xp_mod_(new unit_experience_accelerator(level["experience_modifier"].to_int(100))) , xp_mod_(new unit_experience_accelerator(level["experience_modifier"].to_int(100)))
, statistics_context_(new statistics::scenario_context(level["name"])) , statistics_context_(new statistics::scenario_context(level["name"]))
, replay_(new replay(state_of_game.get_replay())) , replay_(new replay(state_of_game.get_replay()))
@ -295,7 +297,17 @@ void play_controller::init(const config& level)
// Do this after the loadingscreen, so that ita happens in the main thread. // Do this after the loadingscreen, so that ita happens in the main thread.
gui_->join(); gui_->join();
gui_->initialize_ui();
initialize_and_show_ui();
}
void play_controller::initialize_and_show_ui()
{
// Set member in the base class
ui_.reset(new gui2::dialogs::game_ui());
assert(ui_);
ui_->show(true);
} }
void play_controller::reset_gamestate(const config& level, int replay_pos) void play_controller::reset_gamestate(const config& level, int replay_pos)

View file

@ -76,6 +76,14 @@ namespace wb
class manager; // whiteboard manager class manager; // whiteboard manager
} // namespace wb } // namespace wb
namespace gui2
{
namespace dialogs
{
class game_ui;
}
}
// Holds gamestate related objects // Holds gamestate related objects
class game_state; class game_state;
@ -333,6 +341,8 @@ public:
game_display& get_display() override; game_display& get_display() override;
virtual void initialize_and_show_ui() override;
void update_savegame_snapshot() const; void update_savegame_snapshot() const;
/** /**
* Changes the UI for this client to the passed side index. * Changes the UI for this client to the passed side index.
@ -422,6 +432,8 @@ protected:
// other objects // other objects
std::unique_ptr<game_display> gui_; std::unique_ptr<game_display> gui_;
std::unique_ptr<gui2::dialogs::game_ui> ui_; // TODO: better name?
const std::unique_ptr<unit_experience_accelerator> xp_mod_; const std::unique_ptr<unit_experience_accelerator> xp_mod_;
const std::unique_ptr<const statistics::scenario_context> statistics_context_; const std::unique_ptr<const statistics::scenario_context> statistics_context_;