Add proof-of-concept code to init a listbox from a WML config.
This commit is contained in:
parent
f9c47354d2
commit
897d9605db
6 changed files with 74 additions and 17 deletions
|
@ -132,7 +132,7 @@
|
|||
retval = 1
|
||||
label = _ "Join Official Server"
|
||||
tooltip = _ "Log on to the official Wesnoth multiplayer server"
|
||||
icon = "server.png"
|
||||
icon = "icons/icon-server.png"
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
@ -143,7 +143,7 @@
|
|||
retval = 2
|
||||
label = _ "Connect to Server"
|
||||
tooltip = _ "Join a different server"
|
||||
icon = "serverother.png"
|
||||
icon = "icons/icon-serverother.png"
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
@ -154,7 +154,7 @@
|
|||
retval = 3
|
||||
label = _ "Local Game"
|
||||
tooltip = _ "Play a multiplayer game with the AI or humans sharing the same machine"
|
||||
icon = "hotseat.png"
|
||||
icon = "icons/icon-hotseat.png"
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
|
|
@ -1589,10 +1589,8 @@ bool game_controller::play_multiplayer()
|
|||
dlg.show(disp().video());
|
||||
|
||||
if(dlg.get_retval() == gui2::tbutton::OK) {
|
||||
std::cerr << "OK\n";
|
||||
res = dlg.get_choice();
|
||||
} else {
|
||||
std::cerr << "CANCEL\n";
|
||||
return false;
|
||||
|
||||
}
|
||||
|
|
|
@ -51,11 +51,6 @@ void tmp_method_selection::show(CVideo& video)
|
|||
tlistbox* list = dynamic_cast<tlistbox*>(window.find_widget("method_list", false));
|
||||
VALIDATE(list, "No list defined.");
|
||||
|
||||
list->add_item("Join Official Server", "icons/icon-server.png");
|
||||
list->add_item("Connect to Server", "icons/icon-serverother.png");
|
||||
list->add_item("Local Game", "icons/icon-hotseat.png");
|
||||
list->select_row(0);
|
||||
|
||||
window.recalculate_size();
|
||||
|
||||
retval_ = window.show(true);
|
||||
|
|
|
@ -388,6 +388,24 @@ void tlistbox::add_item(const t_string& label, const std::string& icon)
|
|||
set_scrollbar_button_status();
|
||||
}
|
||||
|
||||
void tlistbox::add_items(const std::vector< std::map<std::string, t_string> >& data)
|
||||
{
|
||||
// foreach(const std::map<std::string, t_string>& cell, data) {
|
||||
// doesn't compile it sees 3 paramters instead of 2 so use a typedef.
|
||||
typedef std::map<std::string, t_string> hack ;
|
||||
foreach(const hack& cell, data) {
|
||||
std::map<std::string, t_string >::const_iterator itor = cell.find("icon");
|
||||
assert(itor != cell.end());
|
||||
const t_string& icon = itor->second;
|
||||
|
||||
itor = cell.find("label");
|
||||
assert(itor != cell.end());
|
||||
const std::string& label = itor->second;
|
||||
|
||||
add_item(label, icon);
|
||||
}
|
||||
}
|
||||
|
||||
tscrollbar_* tlistbox::scrollbar()
|
||||
{
|
||||
// Note we don't cache the result, we might want change things later.
|
||||
|
|
|
@ -108,6 +108,13 @@ public:
|
|||
*/
|
||||
void add_item(const t_string& label, const std::string& icon = "");
|
||||
|
||||
/**
|
||||
* Adds one or more items to the listbox.
|
||||
*
|
||||
* Just a proof-of-concept version to add a list of items to a listbox.
|
||||
*/
|
||||
void add_items(const std::vector< std::map<std::string, t_string> >& data);
|
||||
|
||||
unsigned get_item_count() const { return rows_.size(); }
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "gui/widgets/window_builder.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
|
@ -128,6 +129,14 @@ public:
|
|||
|
||||
tbuilder_grid* list_builder;
|
||||
|
||||
/**
|
||||
* Listbox data.
|
||||
*
|
||||
* Contains a vector with the data to set in every cell, it's used to
|
||||
* serialize the data in the config, so the config is no longer required.
|
||||
*/
|
||||
std::vector<std::map<std::string /*key*/, t_string/*value*/> >list_data;
|
||||
|
||||
const bool assume_fixed_row_size;
|
||||
};
|
||||
|
||||
|
@ -739,6 +748,7 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg) :
|
|||
header(cfg.child("header") ? new tbuilder_grid(*(cfg.child("header"))) : 0),
|
||||
footer(cfg.child("footer") ? new tbuilder_grid(*(cfg.child("footer"))) : 0),
|
||||
list_builder(0),
|
||||
list_data(),
|
||||
assume_fixed_row_size(utils::string_bool(cfg["assume_fixed_row_size"]))
|
||||
{
|
||||
/*WIKI
|
||||
|
@ -764,12 +774,14 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg) :
|
|||
* header (section = []) Defines the grid for the optional header.
|
||||
* footer (section = []) Defines the grid for the optional footer.
|
||||
*
|
||||
* list_definition (section) The list can be a hardcoded list (uses
|
||||
* list) or a definition is which case the
|
||||
* engine knows how to 'build' the widget.
|
||||
* When both exist [list] and
|
||||
* [list_definition] the results are
|
||||
* unexpected.
|
||||
* list_definition (section) This defines how a listboxs list data
|
||||
* looks. It must contain the grid
|
||||
* definition for 1 row of the list.
|
||||
*
|
||||
* list_data(section = []) A grid alike section which stores the
|
||||
* initial data for the listbox. Every row
|
||||
* must have the same number of columns as
|
||||
* the 'list_definition'.
|
||||
*
|
||||
* assume_fixed_row_size (bool = true)
|
||||
* If not all rows can be shown this value
|
||||
|
@ -793,6 +805,30 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg) :
|
|||
|
||||
VALIDATE(cfg.child("list_definition"), _("No list defined."));
|
||||
list_builder = new tbuilder_grid(*(cfg.child("list_definition")));
|
||||
assert(list_builder);
|
||||
VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row."));
|
||||
|
||||
const config *data = cfg.child("list_data");
|
||||
if(data) {
|
||||
|
||||
const config::child_list& row_cfgs = data->get_children("row");
|
||||
for(std::vector<config*>::const_iterator row_itor = row_cfgs.begin();
|
||||
row_itor != row_cfgs.end(); ++row_itor) {
|
||||
|
||||
unsigned col = 0;
|
||||
|
||||
const config::child_list& col_cfgs = (**row_itor).get_children("column");
|
||||
for(std::vector<config*>::const_iterator col_itor = col_cfgs.begin();
|
||||
col_itor != col_cfgs.end(); ++col_itor) {
|
||||
|
||||
list_data.push_back((**col_itor).values);
|
||||
++col;
|
||||
}
|
||||
|
||||
VALIDATE(col == list_builder->cols, _("'list_data' must have "
|
||||
"the same number of columns as the 'list_definition'."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
twidget* tbuilder_listbox::build() const
|
||||
|
@ -802,7 +838,6 @@ twidget* tbuilder_listbox::build() const
|
|||
init_control(listbox);
|
||||
|
||||
listbox->set_list_builder(list_builder);
|
||||
|
||||
listbox->set_assume_fixed_row_size(assume_fixed_row_size);
|
||||
|
||||
DBG_G << "Window builder: placed listbox '" << id << "' with defintion '"
|
||||
|
@ -835,6 +870,10 @@ twidget* tbuilder_listbox::build() const
|
|||
| tgrid::HORIZONTAL_ALIGN_CENTER
|
||||
, 0);
|
||||
|
||||
if(!list_data.empty()) {
|
||||
listbox->add_items(list_data);
|
||||
}
|
||||
|
||||
listbox->finalize_setup();
|
||||
|
||||
return listbox;
|
||||
|
|
Loading…
Add table
Reference in a new issue