Support for defining the controller of a side in the editor.
This commit is contained in:
parent
05aab56e44
commit
904383ea4f
2 changed files with 67 additions and 23 deletions
|
@ -16,25 +16,29 @@
|
|||
|
||||
#include "gui/dialogs/editor/editor_edit_side.hpp"
|
||||
|
||||
#include "gui/dialogs/field.hpp"
|
||||
#include "gui/widgets/toggle_button.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowDefinitionWML
|
||||
* @order = 2_edit_scenario
|
||||
* @order = 2_edit_side
|
||||
*
|
||||
* == Edit scenario ==
|
||||
* == Edit side ==
|
||||
*
|
||||
* Dialog for editing gamemap scenarios.
|
||||
* Dialog for editing gamemap sides.
|
||||
*
|
||||
* @begin{table}{dialog_widgets}
|
||||
*
|
||||
* title & & label & m &
|
||||
* Dialog title label. $
|
||||
*
|
||||
* label & & text_box & m &
|
||||
* Input field for the map label. $
|
||||
* id & & text_box & m &
|
||||
* Input field for the id. $
|
||||
*
|
||||
* team_only_toggle & & toggle_button & m &
|
||||
* Checkbox for whether to make the label visible to the player's team
|
||||
|
@ -46,7 +50,8 @@ namespace gui2 {
|
|||
REGISTER_DIALOG(editor_edit_side)
|
||||
|
||||
teditor_edit_side::teditor_edit_side(std::string& id, std::string& name, int& gold, int& income,
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps)
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps, team::CONTROLLER& controller) :
|
||||
controller_(controller)
|
||||
{
|
||||
register_text("id", true, id, true);
|
||||
register_text("name", true, name, true);
|
||||
|
@ -61,5 +66,42 @@ teditor_edit_side::teditor_edit_side(std::string& id, std::string& name, int& go
|
|||
register_bool("share_maps", true, share_maps);
|
||||
}
|
||||
|
||||
void teditor_edit_side::pre_show(CVideo& /*video*/, twindow& window)
|
||||
{
|
||||
register_controller_toggle(window, "by_human", team::HUMAN);
|
||||
register_controller_toggle(window, "by_ai", team::AI);
|
||||
register_controller_toggle(window, "by_null", team::EMPTY);
|
||||
}
|
||||
|
||||
void teditor_edit_side::register_controller_toggle(twindow& window, const std::string& toggle_id, team::CONTROLLER value)
|
||||
{
|
||||
ttoggle_button* b = &find_widget<ttoggle_button>(&window, "controller_" + toggle_id, false);
|
||||
|
||||
b->set_value(value == controller_);
|
||||
connect_signal_mouse_left_click(*b, boost::bind(&teditor_edit_side::toggle_controller_callback, this, b));
|
||||
|
||||
controller_tgroup_.push_back(std::make_pair(b, value));
|
||||
}
|
||||
|
||||
void teditor_edit_side::toggle_controller_callback(ttoggle_button* active)
|
||||
{
|
||||
FOREACH(const AUTO& e, controller_tgroup_) {
|
||||
ttoggle_button* const b = e.first;
|
||||
if(b == NULL) {
|
||||
continue;
|
||||
}
|
||||
else if(b == active && !b->get_value()) {
|
||||
b->set_value(true);
|
||||
}
|
||||
else if(b == active) {
|
||||
controller_ = e.second;
|
||||
}
|
||||
else if(b != active && b->get_value()) {
|
||||
b->set_value(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -17,42 +17,44 @@
|
|||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "config.hpp"
|
||||
#include "team.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class ttoggle_button;
|
||||
|
||||
class teditor_edit_side : public tdialog
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* TODO
|
||||
* @param[in] text The initial value of the label.
|
||||
* @param[out] text The label text the user entered if the dialog
|
||||
* returns @ref twindow::OK undefined otherwise.
|
||||
* @param[in] team_only The initial value of the team only toggle.
|
||||
* @param[out] team_only The final value of the team only toggle if the
|
||||
* dialog returns @ref twindow::OK undefined
|
||||
* otherwise.
|
||||
*/
|
||||
|
||||
teditor_edit_side(std::string& id, std::string& name, int& gold, int& income,
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps);
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps, team::CONTROLLER& controller);
|
||||
|
||||
/** The execute function see @ref tdialog for more information. */
|
||||
static bool execute(std::string& id, std::string& name, int& gold, int& income,
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps,
|
||||
bool& fog, bool& share_view, bool& shroud, bool& share_maps, team::CONTROLLER& controller,
|
||||
CVideo& video)
|
||||
{
|
||||
return teditor_edit_side(id, name, gold, income, fog, share_view, shroud, share_maps).show(video);
|
||||
return teditor_edit_side(id, name, gold, income, fog, share_view, shroud, share_maps, controller).show(video);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void pre_show(CVideo& /*video*/, twindow& window);
|
||||
|
||||
void register_controller_toggle(twindow& window, const std::string& toggle_id, team::CONTROLLER value);
|
||||
|
||||
team::CONTROLLER& controller_;
|
||||
|
||||
typedef std::pair<ttoggle_button*, team::CONTROLLER> controller_toggle;
|
||||
// Dialog display state variables.
|
||||
std::vector<controller_toggle> controller_tgroup_;
|
||||
|
||||
void toggle_controller_callback(ttoggle_button* active);
|
||||
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const;
|
||||
|
||||
// std::string id_;
|
||||
// std::string name_;
|
||||
// int turns_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue