Let windows register themselves automatically.

This reduces the bindings between modules.
This commit is contained in:
Mark de Wever 2010-03-26 14:48:35 +00:00
parent 038aeabc95
commit 867f52dc96
53 changed files with 258 additions and 309 deletions

View file

@ -29,7 +29,6 @@
#include "gettext.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "help.hpp"
#include "log.hpp"

View file

@ -41,10 +41,7 @@ namespace gui2 {
* @end_table
*/
twindow* taddon_connect::build_window(CVideo& video)
{
return build(video, get_id(ADDON_CONNECT));
}
REGISTER_WINDOW(addon_connect)
void taddon_connect::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -58,8 +58,8 @@ private:
bool allow_updates_;
bool allow_remove_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -44,10 +44,7 @@ namespace gui2 {
* @end_table
*/
twindow* taddon_list::build_window(CVideo& video)
{
return build(video, get_id(ADDON_LIST));
}
REGISTER_WINDOW(addon_list)
void taddon_list::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -32,8 +32,9 @@ public:
}
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -60,6 +60,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(campaign_selection)
void tcampaign_selection::campaign_selected(twindow& window)
{
if(new_widgets) {
@ -88,11 +90,6 @@ void tcampaign_selection::campaign_selected(twindow& window)
}
}
twindow* tcampaign_selection::build_window(CVideo& video)
{
return build(video, get_id(CAMPAIGN_SELECTION));
}
void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
{
if(new_widgets) {

View file

@ -39,8 +39,8 @@ public:
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -39,6 +39,8 @@ void tdialog::show(CVideo& video, const unsigned auto_close_time)
std::auto_ptr<twindow> window(build_window(video));
assert(window.get());
post_build(video, *window);
window->set_owner(this);
init_fields(*window);
@ -102,6 +104,11 @@ tfield_text* tdialog::register_text(const std::string& id, const bool optional,
return field;
}
twindow* tdialog::build_window(CVideo& video) const
{
return build(video, window_id());
}
void tdialog::init_fields(twindow& window)
{
foreach(tfield_* field, fields_) {

View file

@ -24,6 +24,57 @@ class CVideo;
namespace gui2 {
/**
* Registers a window.
*
* Call this function to register a window. In the header of the class add the
* following code:
*@code
* // Inherited from tdialog, implemented by REGISTER_WINDOW.
* virtual const std::string& id() const;
*@endcode
* Then use this macro in the implementation, inside the gui2 namespace.
*
* @note When the window_id is "foo" and the type tfoo it's easier to use
* REGISTER_WINDOW(foo).
*
* @param type Class type of the window to register.
* @param widget_id Id of the window, multiple dialogs can use
* the same window so the id doesn't need to be
* unique.
*/
#define REGISTER_WINDOW2( \
type \
, id) \
namespace { \
\
namespace ns_##type { \
\
struct tregister_helper { \
tregister_helper() \
{ \
register_window(id); \
} \
}; \
\
tregister_helper register_helper; \
} \
} \
\
const std::string& \
type::window_id() const \
{ \
static const std::string result(id); \
return result; \
}
/**
* Wrapper for REGISTER_WINDOW2.
*
* "Calls" REGISTER_WINDOW2(twindow_id, "window_id")
*/
#define REGISTER_WINDOW(window_id) REGISTER_WINDOW2(t##window_id, #window_id)
/**
* Abstract base class for all dialogs.
*
@ -130,6 +181,9 @@ private:
*/
bool restore_;
/** The id of the window to build. */
virtual const std::string& window_id() const = 0;
/**
* Builds the window.
*
@ -140,7 +194,16 @@ private:
* upon.
* @returns The window to show.
*/
virtual twindow* build_window(CVideo& video) = 0;
twindow* build_window(CVideo& video) const;
/**
* Actions to be taken directly after the window is build.
*
* @param video The video which contains the surface to draw
* upon.
* @param window The window just created.
*/
virtual void post_build(CVideo& /*video*/, twindow& /*window*/) {}
/**
* Actions to be taken before showing the window.

View file

@ -45,6 +45,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(editor_generate_map)
teditor_generate_map::teditor_generate_map()
: map_generators_()
, current_map_generator_(0)
@ -87,11 +89,6 @@ void teditor_generate_map::update_current_generator_label(twindow& window)
window.invalidate_layout();
}
twindow* teditor_generate_map::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_GENERATE_MAP));
}
void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& window)
{
assert(!map_generators_.empty());

View file

@ -52,8 +52,9 @@ public:
display* get_gui() { return gui_; }
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -38,6 +38,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(editor_new_map)
teditor_new_map::teditor_new_map() :
map_width_(register_integer("width", false)),
map_height_(register_integer("height", false))
@ -64,9 +66,5 @@ int teditor_new_map::map_height() const
return map_height_->get_cache_value();
}
twindow* teditor_new_map::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_NEW_MAP));
}
} // namespace gui2

View file

@ -37,8 +37,8 @@ private:
tfield_integer* map_width_;
tfield_integer* map_height_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};
} // namespace gui2

View file

@ -73,6 +73,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(editor_resize_map)
/**
* @todo Test whether the slider can be changed to an interger selector.
* Should be possible, since it's also done in the new map dialog.
@ -124,11 +126,6 @@ bool teditor_resize_map::copy_edge_terrain() const
return copy_edge_terrain_->get_cache_value();
}
twindow* teditor_resize_map::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_RESIZE_MAP));
}
void teditor_resize_map::pre_show(CVideo& /*video*/, twindow& window)
{
tlabel& old_width = find_widget<tlabel>(&window, "old_width", false);

View file

@ -68,8 +68,8 @@ private:
EXPAND_DIRECTION expand_direction_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
void pre_show(CVideo& video, twindow& window);

View file

@ -21,8 +21,8 @@
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gettext.hpp"
@ -67,6 +67,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(editor_settings)
teditor_settings::teditor_settings()
: redraw_callback_()
, tods_()
@ -188,11 +190,6 @@ void teditor_settings::update_selected_tod_info(twindow& window)
window.invalidate_layout();
}
twindow* teditor_settings::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_SETTINGS));
}
void teditor_settings::pre_show(CVideo& /*video*/, twindow& window)
{
assert(!tods_.empty());

View file

@ -59,8 +59,8 @@ public:
void set_use_mdi(bool value);
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -47,10 +47,7 @@ namespace gui2 {
* @end_table
*/
twindow* tformula_debugger::build_window(CVideo& video)
{
return build(video, get_id(FORMULA_DEBUGGER));
}
REGISTER_WINDOW(formula_debugger)
void tformula_debugger::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -30,10 +30,6 @@ public:
fdb_(fdb)
{}
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
@ -51,6 +47,9 @@ public:
private:
game_logic::formula_debugger &fdb_;
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};
}

View file

@ -32,16 +32,13 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(game_delete)
tgame_delete::tgame_delete()
: chk_dont_ask_again_(register_bool("dont_ask_again"))
, dont_ask_again_(false)
{}
twindow* tgame_delete::build_window(CVideo& video)
{
return build(video, get_id(GAME_DELETE));
}
void tgame_delete::post_show(twindow& window)
{
dont_ask_again_ = chk_dont_ask_again_->get_widget_value(window);

View file

@ -32,8 +32,9 @@ protected:
void post_show(twindow& window);
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
tfield_bool* chk_dont_ask_again_;
bool dont_ask_again_;

View file

@ -68,6 +68,8 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(game_load)
tgame_load::tgame_load(const config& cache_config)
: txtFilter_(register_text("txtFilter", false))
, chk_show_replay_(register_bool("show_replay"))
@ -81,11 +83,6 @@ tgame_load::tgame_load(const config& cache_config)
{
}
twindow* tgame_load::build_window(CVideo& video)
{
return build(video, get_id(GAME_LOAD));
}
void tgame_load::pre_show(CVideo& /*video*/, twindow& window)
{
assert(txtFilter_);

View file

@ -40,8 +40,9 @@ protected:
void post_show(twindow& window);
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
bool filter_text_changed(ttext_* textbox, const std::string& text);
void list_item_clicked(twindow& window);

View file

@ -39,6 +39,9 @@ namespace gui2 {
* The name of the savefile.
* @end_table
*/
REGISTER_WINDOW(game_save)
tgame_save::tgame_save(const std::string& title, const std::string& filename) :
txtFilename_(register_text("txtFilename", false)),
title_(title),
@ -46,11 +49,6 @@ tgame_save::tgame_save(const std::string& title, const std::string& filename) :
{
}
twindow* tgame_save::build_window(CVideo& video)
{
return build(video, get_id(GAME_SAVE));
}
void tgame_save::pre_show(CVideo& /*video*/, twindow& window)
{
assert(txtFilename_);
@ -66,16 +64,14 @@ void tgame_save::post_show(twindow& window)
filename_ = txtFilename_->get_widget_value(window);
}
REGISTER_WINDOW(game_save_message)
tgame_save_message::tgame_save_message(const std::string& title, const std::string& filename, const std::string& message)
: tgame_save(title, filename),
message_(message)
{}
twindow* tgame_save_message::build_window(CVideo& video)
{
return build(video, get_id(GAME_SAVE_MESSAGE));
}
void tgame_save_message::pre_show(CVideo& video, twindow& window)
{
find_widget<tlabel>(&window, "lblMessage", false).set_label(message_);
@ -83,17 +79,14 @@ void tgame_save_message::pre_show(CVideo& video, twindow& window)
tgame_save::pre_show(video, window);
}
REGISTER_WINDOW(game_save_oos)
tgame_save_oos::tgame_save_oos(const std::string& title, const std::string& filename, const std::string& message)
: tgame_save_message(title, filename, message),
btnIgnoreAll_(register_bool("ignore_all", false)),
ignore_all_(false)
{}
twindow* tgame_save_oos::build_window(CVideo& video)
{
return build(video, get_id(GAME_SAVE_OOS));
}
void tgame_save_oos::post_show(twindow& window)
{
tgame_save::post_show(window);

View file

@ -35,8 +35,9 @@ protected:
void post_show(twindow& window);
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
tfield_text* txtFilename_;
std::string title_;
@ -49,11 +50,11 @@ public:
tgame_save_message(const std::string& title, const std::string& filename="", const std::string& message="");
private:
/** Inherited from tgame_save. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tgame_save. */
twindow* build_window(CVideo& video);
void pre_show(CVideo& video, twindow& window);
std::string message_;
};
@ -66,8 +67,8 @@ public:
bool ignore_all() const { return ignore_all_; }
private:
/** Inherited from tgame_save. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void post_show(twindow& window);

View file

@ -519,6 +519,8 @@ private:
};
REGISTER_WINDOW(gamestate_inspector)
tgamestate_inspector::tgamestate_inspector(const vconfig &cfg)
: view_()
{
@ -526,19 +528,11 @@ tgamestate_inspector::tgamestate_inspector(const vconfig &cfg)
view_ = boost::shared_ptr<view>(new view(cfg));
}
twindow* tgamestate_inspector::build_window(CVideo& video)
{
return build(video, get_id(GAMESTATE_INSPECTOR));
}
boost::shared_ptr<tgamestate_inspector::view> tgamestate_inspector::get_view()
{
return view_;
}
void tgamestate_inspector::pre_show(CVideo& video, twindow& window)
{
view_->bind(window);

View file

@ -29,15 +29,15 @@ public:
class controller;
tgamestate_inspector(const vconfig &cfg);
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
boost::shared_ptr<view> get_view();
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
boost::shared_ptr<view> view_;
};

View file

@ -39,10 +39,8 @@ namespace gui2 {
* -[] (control) () Gets the name of the language.
* @end_table
*/
twindow* tlanguage_selection::build_window(CVideo& video)
{
return build(video, get_id(LANGUAGE_SELECTION));
}
REGISTER_WINDOW(language_selection)
void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -26,8 +26,8 @@ public:
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -67,6 +67,8 @@ static lg::log_domain log_lobby("lobby");
namespace gui2 {
REGISTER_WINDOW(lobby_main)
void tsub_player_list::init(gui2::twindow &w, const std::string &id)
{
list = find_widget<tlistbox>(&w, id, false, true);
@ -477,18 +479,15 @@ static bool fullscreen(CVideo& video)
return true;
}
twindow* tlobby_main::build_window(CVideo& video)
void tlobby_main::post_build(CVideo& video, twindow& window)
{
twindow* window = build(video, get_id(LOBBY_MAIN));
assert(window);
/** @todo Should become a global hotkey after 1.8, then remove it here. */
window->register_hotkey(hotkey::HOTKEY_FULLSCREEN
window.register_hotkey(hotkey::HOTKEY_FULLSCREEN
, boost::bind(fullscreen, boost::ref(video)));
/** @todo Remove this code once the resizing in twindow is finished. */
window->connect_signal<event::SDL_VIDEO_RESIZE>(
window.connect_signal<event::SDL_VIDEO_RESIZE>(
boost::bind(&signal_handler_sdl_video_resize
, _2, _3, _4, _5, boost::ref(video))
, event::tdispatcher::front_child);
@ -497,15 +496,13 @@ twindow* tlobby_main::build_window(CVideo& video)
preferences_wrapper_ = boost::bind(
&tlobby_main::show_preferences_button_callback
, this
, boost::ref(*window));
, boost::ref(window));
window->register_hotkey(
window.register_hotkey(
hotkey::HOTKEY_PREFERENCES
, boost::bind(function_wrapper<bool, boost::function<void()> >
, true
, boost::cref(preferences_wrapper_)));
return window;
}
namespace {

View file

@ -326,8 +326,11 @@ private:
void skip_replay_changed_callback(twidget* w);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
virtual void post_build(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -24,6 +24,8 @@
namespace gui2 {
REGISTER_WINDOW(lobby_player_info)
tlobby_player_info::tlobby_player_info(events::chat_handler& chat, user_info& info, const lobby_info& li)
: chat_(chat), info_(info), reason_(NULL), time_(NULL), relation_(NULL),
add_to_friends_(NULL), add_to_ignores_(NULL), remove_from_list_(NULL),
@ -35,11 +37,6 @@ tlobby_player_info::~tlobby_player_info()
{
}
twindow* tlobby_player_info::build_window(CVideo& video)
{
return build(video, get_id(LOBBY_PLAYER_INFO));
}
void tlobby_player_info::pre_show(CVideo& /*video*/, twindow& window)
{
relation_ = find_widget<tlabel>(&window, "relation_info", false, true);

View file

@ -36,8 +36,9 @@ public:
bool result_open_whisper() const { return result_open_whisper_; }
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -27,6 +27,8 @@
namespace gui2 {
REGISTER_WINDOW(message)
/**
* Helper to implement private functions without modifing the header.
*
@ -134,11 +136,6 @@ tmessage::tbutton_status::tbutton_status()
{
}
twindow* tmessage::build_window(CVideo& video)
{
return build(video, get_id(MESSAGE));
}
void show_message(CVideo& video, const std::string& title,
const std::string& message, const std::string& button_caption,
const bool auto_close)

View file

@ -124,8 +124,8 @@ private:
/** Holds a pointer to the buttons. */
std::vector<tbutton_status> buttons_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};
/**

View file

@ -48,14 +48,11 @@ namespace gui2 {
* @end_table
*/
REGISTER_WINDOW(mp_cmd_wrapper)
tmp_cmd_wrapper::tmp_cmd_wrapper(const t_string& user) :
message_(), reason_(), time_(), user_(user) { }
twindow* tmp_cmd_wrapper::build_window(CVideo& video)
{
return build(video, get_id(MP_CMD_WRAPPER));
}
void tmp_cmd_wrapper::pre_show(CVideo& /*video*/, twindow& window)
{
ttext_box* message =

View file

@ -30,8 +30,9 @@ public:
const std::string& time() const { return time_; }
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -49,6 +49,7 @@ namespace {
* -(address) (control) () The address/host_name of the server.
* @end_table
*/
class tmp_server_list : public tdialog
{
public:
@ -61,9 +62,8 @@ public:
private:
std::string host_name_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video)
{ return build(video, get_id(MP_SERVER_LIST)); }
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
@ -72,6 +72,8 @@ private:
void post_show(twindow& window);
};
REGISTER_WINDOW(mp_server_list)
void tmp_server_list::pre_show(CVideo& /*video*/, twindow& window)
{
tlistbox& list = find_widget<tlistbox>(&window, "server_list", false);
@ -126,6 +128,9 @@ void tmp_server_list::post_show(twindow& window)
* predefined servers to connect to.
* @end_table
*/
REGISTER_WINDOW(mp_connect)
tmp_connect::tmp_connect() :
video_(0),
host_name_(register_text("host_name", false,
@ -134,11 +139,6 @@ tmp_connect::tmp_connect() :
{
}
twindow* tmp_connect::build_window(CVideo& video)
{
return build(video, get_id(MP_CONNECT));
}
void tmp_connect::pre_show(CVideo& video, twindow& window)
{
assert(!video_);
@ -194,14 +194,11 @@ void tmp_connect::show_server_list(twindow& window)
* @end_table
*/
REGISTER_WINDOW(mp_login)
tmp_login::tmp_login(const t_string& label, const bool focus_password) :
label_(label), focus_password_(focus_password) { }
twindow* tmp_login::build_window(CVideo& video)
{
return build(video, get_id(MP_LOGIN));
}
void tmp_login::pre_show(CVideo& /*video*/, twindow& window)
{
ttext_box* username =

View file

@ -30,8 +30,8 @@ private:
/** Used in show in order to show list. */
CVideo* video_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
@ -52,8 +52,9 @@ public:
const bool focus_password = false);
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -29,6 +29,8 @@
namespace gui2 {
REGISTER_WINDOW(mp_create_game)
tmp_create_game::tmp_create_game(const config& cfg) :
cfg_(cfg),
scenario_(NULL),
@ -58,11 +60,6 @@ tmp_create_game::tmp_create_game(const config& cfg) :
{
}
twindow* tmp_create_game::build_window(CVideo& video)
{
return build(video, get_id(MP_CREATE_GAME));
}
void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window)
{
find_widget<tminimap>(&window, "minimap", false).set_config(&cfg_);

View file

@ -31,8 +31,8 @@ public:
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -40,10 +40,8 @@ namespace gui2 {
* (method_list) (listbox) () The list with possible game methods.
* @end_table
*/
twindow* tmp_method_selection::build_window(CVideo& video)
{
return build(video, get_id(MP_METHOD_SELECTION));
}
REGISTER_WINDOW(mp_method_selection)
void tmp_method_selection::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -36,8 +36,8 @@ private:
int choice_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -66,6 +66,8 @@ void show_dialog(twidget* caller)
* @end_table
*/
REGISTER_WINDOW(title_screen)
ttitle_screen::ttitle_screen()
: video_(NULL)
, tips_()
@ -73,11 +75,6 @@ ttitle_screen::ttitle_screen()
read_tips_of_day(tips_);
}
twindow* ttitle_screen::build_window(CVideo& video)
{
return build(video, get_id(TITLE_SCREEN));
}
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
assert(!video_);

View file

@ -32,8 +32,8 @@ private:
/** Used in show in order to show child windows. */
CVideo* video_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -24,10 +24,7 @@
namespace gui2 {
twindow* ttransient_message::build_window(CVideo& video)
{
return build(video, get_id(TRANSIENT_MESSAGE));
}
REGISTER_WINDOW(transient_message)
void ttransient_message::pre_show(CVideo& /*video*/, twindow& window)
{

View file

@ -52,8 +52,8 @@ private:
/** Use markup for the message. */
bool message_use_markup_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};
/**

View file

@ -45,6 +45,8 @@ namespace {
namespace gui2 {
REGISTER_WINDOW(unit_create)
/* TODO: wiki-doc me! */
tunit_create::tunit_create()
@ -55,11 +57,6 @@ tunit_create::tunit_create()
{
}
twindow* tunit_create::build_window(CVideo& video)
{
return build(video, get_id(UNIT_CREATE));
}
void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
{
ttoggle_button& male_toggle = find_widget<ttoggle_button>(

View file

@ -47,8 +47,8 @@ private:
std::string choice_;
std::vector<std::string> type_ids_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);

View file

@ -187,15 +187,9 @@ void twml_message_::post_show(twindow& window)
}
}
twindow* twml_message_left::build_window(CVideo& video)
{
return build(video, get_id(WML_MESSAGE_LEFT));
}
REGISTER_WINDOW(wml_message_left)
twindow* twml_message_right::build_window(CVideo& video)
{
return build(video, get_id(WML_MESSAGE_RIGHT));
}
REGISTER_WINDOW(wml_message_right)
int show_wml_message(const bool left_side
, CVideo& video

View file

@ -96,13 +96,6 @@ private:
/** The chosen option. */
int *chosen_option_;
/**
* Inherited from tdialog.
*
* The subclasses need to implement the left or right definition.
*/
twindow* build_window(CVideo& /*video*/) = 0;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
@ -119,9 +112,11 @@ public:
: twml_message_(title, message, portrait, mirror)
{
}
private:
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};
/** Shows a dialog with the portrait on the right side. */
@ -133,9 +128,11 @@ public:
: twml_message_(title, message, portrait, mirror)
{
}
private:
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog, implemented by REGISTER_WINDOW. */
virtual const std::string& window_id() const;
};

View file

@ -53,6 +53,7 @@
#include "serialization/preprocessor.hpp"
#include "formula_string_utils.hpp"
namespace gui2 {
bool new_widgets = false;
@ -79,13 +80,16 @@ namespace settings {
namespace {
/**
* Vector with all known windows, these are validated on existance on
* startup.
*
* The enum twindow_type is the index of the array.
*/
std::vector<std::string> window_type_list(COUNT);
/**
* Returns the list of registered windows.
*
* The function can be used the look for registered windows or to add them.
*/
static std::vector<std::string>& registered_window_types()
{
static std::vector<std::string> result;
return result;
}
struct tgui_definition
{
@ -297,10 +301,13 @@ const std::string& tgui_definition::read(const config& cfg)
if(id == "default") {
// The default gui needs to define all window types since we're the
// fallback in case another gui doesn't define the window type.
for(std::vector<std::string>::const_iterator itor = window_type_list.begin();
itor != window_type_list.end(); ++itor) {
for(std::vector<std::string>::const_iterator itor
= registered_window_types().begin()
; itor != registered_window_types().end()
; ++itor) {
VALIDATE(window_types.find(*itor) != window_types.end(), _("Window not defined."));
VALIDATE(window_types.find(*itor) != window_types.end()
, _("Window not defined."));
}
}
@ -422,46 +429,26 @@ void tgui_definition::load_definitions(
} // namespace
static void fill_window_types()
void register_window(const std::string& id)
{
window_type_list[ADDON_CONNECT] = "addon_connect";
window_type_list[ADDON_LIST] = "addon_list";
window_type_list[CAMPAIGN_SELECTION] = "campaign_selection";
window_type_list[LANGUAGE_SELECTION] = "language_selection";
window_type_list[WML_MESSAGE_LEFT] = "wml_message_left";
window_type_list[WML_MESSAGE_RIGHT] = "wml_message_right";
window_type_list[MESSAGE] = "message";
window_type_list[TRANSIENT_MESSAGE] = "transient_message";
window_type_list[MP_CONNECT] = "mp_connect";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
window_type_list[MP_SERVER_LIST] = "mp_server_list";
window_type_list[MP_LOGIN] = "mp_login";
window_type_list[MP_CMD_WRAPPER] = "mp_cmd_wrapper";
window_type_list[MP_CREATE_GAME] = "mp_create_game";
window_type_list[TITLE_SCREEN] = "title_screen";
window_type_list[GAME_LOAD] = "game_load";
window_type_list[GAME_DELETE] = "game_delete";
window_type_list[GAME_SAVE] = "game_save";
window_type_list[GAME_SAVE_MESSAGE] = "game_save_message";
window_type_list[GAME_SAVE_OOS] = "game_save_oos";
#ifndef DISABLE_EDITOR
window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";
window_type_list[EDITOR_RESIZE_MAP] = "editor_resize_map";
window_type_list[EDITOR_SETTINGS] = "editor_settings";
#endif
window_type_list[LOBBY_MAIN] = "lobby_main";
window_type_list[LOBBY_PLAYER_INFO] = "lobby_player_info";
window_type_list[UNIT_CREATE] = "unit_create";
window_type_list[FORMULA_DEBUGGER] = "formula_debugger";
window_type_list[GAMESTATE_INSPECTOR] = "gamestate_inspector";
}
const std::vector<std::string>::iterator itor = std::find(
registered_window_types().begin()
, registered_window_types().end()
, id);
const std::string& get_id(const twindow_type window_type)
{
assert(window_type >= 0 && window_type < COUNT);
/* Our own logger since the global ones might not be initialized yet. */
lg::log_domain log("gui/general");
return window_type_list[window_type];
if(itor == registered_window_types().end()) {
registered_window_types().push_back(id);
LOG_STREAM_INDENT(debug, log)
<< "Registered window '" << id << "'.\n";
} else {
LOG_STREAM_INDENT(info, log)
<< "Tried to reregister window '" << id
<< "', request ignored.\n";
}
}
void load_settings()
@ -469,8 +456,6 @@ void load_settings()
LOG_GUI_G << "Setting: init gui.\n";
// Init.
fill_window_types();
twindow::update_screen_size();
// Read file.

View file

@ -30,54 +30,21 @@ namespace gui2 {
/** Do we wish to use the new library or not. */
extern bool new_widgets;
enum twindow_type {
TITLE_SCREEN, /**< The main title screen of the game. */
ADDON_CONNECT, /**< The addon server connection dialog. */
ADDON_LIST, /**< The addon list dialog. */
CAMPAIGN_SELECTION, /**< The campaign selection dialog. */
LANGUAGE_SELECTION, /**< The language selection dialog. */
MESSAGE, /**< A generic message dialog. */
TRANSIENT_MESSAGE, /**< A transient message dialog. */
WML_MESSAGE_LEFT, /**<
* A WML message dialog with the portrait on
* the left side.
*/
WML_MESSAGE_RIGHT, /**<
* A WML message dialog with the portrait on
* the right side.
*/
MP_CONNECT, /**< The mp server connection dialog. */
MP_METHOD_SELECTION, /**<
* The dialog which allows you to choose the kind
* mp game the user wants to play.
*/
MP_SERVER_LIST, /**< The mp server list dialog. */
MP_LOGIN, /**< The mp login dialog. */
MP_CMD_WRAPPER, /**< graphical front-end to various mp commands*/
MP_CREATE_GAME, /**< The mp creation dialog. */
#ifndef DISABLE_EDITOR
EDITOR_NEW_MAP, /**< New map dialog. */
EDITOR_GENERATE_MAP, /**< Editor random map genarator dialog. */
EDITOR_RESIZE_MAP, /**< Editor resize map dialog. */
EDITOR_SETTINGS, /**< Editor settings dialog. */
#endif
GAME_LOAD, /**< Load game dialog. */
GAME_DELETE, /**< Confirm delete dialog. */
GAME_SAVE, /**< Save game dialog. */
GAME_SAVE_MESSAGE, /**< Save game dialog with additional message. */
GAME_SAVE_OOS, /**< Save game dialog for processing OOS. */
LOBBY_MAIN, /**< Main MP lobby screen */
LOBBY_PLAYER_INFO, /**< MP lobby player info dialog */
UNIT_CREATE, /**< Debug-mode unit creation dialog */
FORMULA_DEBUGGER, /**< Formula debugger dialog */
GAMESTATE_INSPECTOR, /**< Visual inspector of the game state (WML variables, events)*/
COUNT /**<
* The last one to hold the number of items and as
* sentinel.
*/
};
const std::string& get_id(const twindow_type window_type);
/**
* Registers a window.
*
* This function registers the available windows defined in WML. All windows
* need to register themselves before @ref gui2::init) is called.
*
* @warning This function runs before @ref main() so needs to be careful
* regarding the static initialization problem.
*
* @note Double registering a window can't hurt, but no way to probe for it,
* this can be added if needed. The same for an unregister function.
*
* @param id The id of the window to register.
*/
void register_window(const std::string& id);
tresolution_definition_ptr get_control(