Convert unit advancement dialog to GUI2
This commit is contained in:
parent
a8477e3ce0
commit
febb34cfbb
6 changed files with 415 additions and 48 deletions
198
data/gui/window/unit_advance.cfg
Normal file
198
data/gui/window/unit_advance.cfg
Normal file
|
@ -0,0 +1,198 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to recruit units
|
||||
###
|
||||
|
||||
#define _GUI_ADVANCE_LIST
|
||||
[listbox]
|
||||
id = "advance_choice"
|
||||
definition = "default"
|
||||
|
||||
[list_definition]
|
||||
[row]
|
||||
[column]
|
||||
vertical_grow = "true"
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_panel]
|
||||
definition = "default"
|
||||
|
||||
return_value_id = "ok"
|
||||
[grid]
|
||||
[row]
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
# Smaller border deliberately
|
||||
border = "all"
|
||||
border_size = 1
|
||||
[image]
|
||||
id = "advancement_image"
|
||||
definition = "default"
|
||||
linked_group = "image"
|
||||
[/image]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
id = "advancement_name"
|
||||
definition = "default"
|
||||
linked_group = "type"
|
||||
[/label]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/toggle_panel]
|
||||
[/column]
|
||||
[/row]
|
||||
[/list_definition]
|
||||
[/listbox]
|
||||
#enddef
|
||||
|
||||
[window]
|
||||
id = "unit_advance"
|
||||
description = "Unit advancement dialog"
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "center"
|
||||
horizontal_placement = "center"
|
||||
|
||||
maximum_height = 700
|
||||
|
||||
[linked_group]
|
||||
id = "image"
|
||||
fixed_width = "true"
|
||||
[/linked_group]
|
||||
|
||||
[linked_group]
|
||||
id = "type"
|
||||
fixed_width = "true"
|
||||
[/linked_group]
|
||||
|
||||
[tooltip]
|
||||
id = "tooltip"
|
||||
[/tooltip]
|
||||
|
||||
[helptip]
|
||||
id = "tooltip"
|
||||
[/helptip]
|
||||
|
||||
[grid]
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
definition = "title"
|
||||
label = _ "Advance Unit"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
vertical_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[unit_preview_pane]
|
||||
definition = "default"
|
||||
id = "advancement_details"
|
||||
[/unit_preview_pane]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
horizontal_alignment = "right"
|
||||
vertical_alignment = "top"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[grid]
|
||||
[row]
|
||||
grow_factor=0
|
||||
[column]
|
||||
[label]
|
||||
definition = "default"
|
||||
label = _ "What should our victorious unit become?"
|
||||
[/label]
|
||||
[/column]
|
||||
[/row]
|
||||
[row]
|
||||
grow_factor=1
|
||||
[column]
|
||||
{_GUI_ADVANCE_LIST}
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/column]
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
horizontal_grow = "true"
|
||||
[grid]
|
||||
[row]
|
||||
grow_factor=0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[button]
|
||||
id = "show_help"
|
||||
definition = "help"
|
||||
[/button]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
||||
#undef _GUI_ADVANCE_LIST
|
|
@ -155,6 +155,8 @@
|
|||
918C8A201D05F9AA009744A0 /* wesnothd_connection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 918C8A1C1D05F9AA009744A0 /* wesnothd_connection.cpp */; };
|
||||
918C8A231D05FDAA009744A0 /* logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 918C8A211D05FDAA009744A0 /* logging.cpp */; };
|
||||
918C8A241D05FDB0009744A0 /* logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 918C8A211D05FDAA009744A0 /* logging.cpp */; };
|
||||
9193FC751D5A62FA004F6C07 /* unit_advance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9193FC731D5A62FA004F6C07 /* unit_advance.cpp */; };
|
||||
9193FC761D5A62FA004F6C07 /* unit_advance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9193FC731D5A62FA004F6C07 /* unit_advance.cpp */; };
|
||||
919B37F81BAF789E00E0094C /* synced_user_choice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37F71BAF789D00E0094C /* synced_user_choice.cpp */; };
|
||||
919B37FC1BAF7A9D00E0094C /* synced_choice_wait.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */; };
|
||||
91A214E51CAD666B00927AEA /* arrow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8A1121359A600CFBDAB /* arrow.cpp */; };
|
||||
|
@ -1580,6 +1582,8 @@
|
|||
918C8A221D05FDAA009744A0 /* logging.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = logging.hpp; sourceTree = "<group>"; };
|
||||
9190B73A1CA0554900B0EF66 /* lua_pathfind_cost_calculator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = lua_pathfind_cost_calculator.hpp; sourceTree = "<group>"; };
|
||||
9190B73B1CA0564700B0EF66 /* register_widget.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = register_widget.hpp; sourceTree = "<group>"; };
|
||||
9193FC731D5A62FA004F6C07 /* unit_advance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unit_advance.cpp; sourceTree = "<group>"; };
|
||||
9193FC741D5A62FA004F6C07 /* unit_advance.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = unit_advance.hpp; sourceTree = "<group>"; };
|
||||
919B37F71BAF789D00E0094C /* synced_user_choice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_user_choice.cpp; sourceTree = "<group>"; };
|
||||
919B37F91BAF78AB00E0094C /* synced_user_choice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = synced_user_choice.hpp; sourceTree = "<group>"; };
|
||||
919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_choice_wait.cpp; sourceTree = "<group>"; };
|
||||
|
@ -4336,6 +4340,8 @@
|
|||
B5A9BCCA0ECA805A002BE442 /* title_screen.hpp */,
|
||||
B54AC6F10FEA9F92006F6FBD /* transient_message.cpp */,
|
||||
B54AC6F20FEA9F92006F6FBD /* transient_message.hpp */,
|
||||
9193FC731D5A62FA004F6C07 /* unit_advance.cpp */,
|
||||
9193FC741D5A62FA004F6C07 /* unit_advance.hpp */,
|
||||
B52EE8891213589100CFBDAB /* unit_attack.cpp */,
|
||||
B52EE88A1213589100CFBDAB /* unit_attack.hpp */,
|
||||
B59F9731103716E400A57C1A /* unit_create.cpp */,
|
||||
|
@ -5218,6 +5224,7 @@
|
|||
913D26771D3C9697002FF3AB /* name_generator_factory.cpp in Sources */,
|
||||
918438611D503E4000C42277 /* unit_recall.cpp in Sources */,
|
||||
9176FECE1D59745F006EF694 /* unit_list.cpp in Sources */,
|
||||
9193FC751D5A62FA004F6C07 /* unit_advance.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -5787,6 +5794,7 @@
|
|||
9164077F1D3C381B0057C4DE /* chat_command_handler.cpp in Sources */,
|
||||
918438621D503E5300C42277 /* unit_recall.cpp in Sources */,
|
||||
9176FECF1D59745F006EF694 /* unit_list.cpp in Sources */,
|
||||
9193FC761D5A62FA004F6C07 /* unit_advance.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "gui/dialogs/game_delete.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/dialogs/unit_advance.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "help/help.hpp"
|
||||
|
@ -85,61 +86,32 @@ namespace dialogs
|
|||
|
||||
int advance_unit_dialog(const map_location &loc)
|
||||
{
|
||||
unit_map::iterator u = resources::units->find(loc);
|
||||
const unit& u = *resources::units->find(loc);
|
||||
std::vector<unit_const_ptr> previews;
|
||||
|
||||
const std::vector<std::string>& options = u->advances_to();
|
||||
|
||||
std::vector<std::string> lang_options;
|
||||
|
||||
std::shared_ptr<std::vector<unit_const_ptr> > sample_units(std::make_shared<std::vector<unit_const_ptr> >());
|
||||
for(std::vector<std::string>::const_iterator op = options.begin(); op != options.end(); ++op) {
|
||||
sample_units->push_back(::get_advanced_unit(*u, *op));
|
||||
const unit& type = *sample_units->back();
|
||||
|
||||
#ifdef LOW_MEM
|
||||
lang_options.push_back(IMAGE_PREFIX
|
||||
+ static_cast<std::string const &>(type.absolute_image())
|
||||
+ COLUMN_SEPARATOR + type.type_name());
|
||||
#else
|
||||
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + u->image_mods() + COLUMN_SEPARATOR + type.type_name());
|
||||
#endif
|
||||
preferences::encountered_units().insert(*op);
|
||||
for(const std::string& advance : u.advances_to()) {
|
||||
preferences::encountered_units().insert(advance);
|
||||
previews.push_back(get_advanced_unit(u, advance));
|
||||
}
|
||||
|
||||
size_t num_real_advances = previews.size();
|
||||
bool always_display = false;
|
||||
for (const config &mod : u->get_modification_advances())
|
||||
{
|
||||
if (mod["always_display"].to_bool()) always_display = true;
|
||||
sample_units->push_back(::get_amla_unit(*u, mod));
|
||||
const unit& type = *sample_units->back();
|
||||
if (!mod["image"].empty()) {
|
||||
lang_options.push_back(IMAGE_PREFIX + mod["image"].str() + COLUMN_SEPARATOR + mod["description"].str());
|
||||
} else {
|
||||
#ifdef LOW_MEM
|
||||
lang_options.push_back(IMAGE_PREFIX
|
||||
+ static_cast<std::string const &>(type.absolute_image())
|
||||
+ COLUMN_SEPARATOR + mod["description"].str());
|
||||
#else
|
||||
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + u->image_mods() + COLUMN_SEPARATOR + mod["description"].str());
|
||||
#endif
|
||||
|
||||
for(const config& advance : u.get_modification_advances()) {
|
||||
if(advance["always_display"]) {
|
||||
always_display = true;
|
||||
}
|
||||
previews.push_back(get_amla_unit(u, advance));
|
||||
}
|
||||
|
||||
assert(!lang_options.empty());
|
||||
|
||||
if (lang_options.size() > 1 || always_display)
|
||||
{
|
||||
units_list_preview_pane unit_preview(sample_units);
|
||||
std::vector<gui::preview_pane*> preview_panes;
|
||||
preview_panes.push_back(&unit_preview);
|
||||
|
||||
gui::dialog advances = gui::dialog(resources::screen->video(),
|
||||
_("Advance Unit"),
|
||||
_("What should our victorious unit become?"),
|
||||
gui::OK_ONLY);
|
||||
advances.set_menu(lang_options);
|
||||
advances.set_panes(preview_panes);
|
||||
return advances.show();
|
||||
if(previews.size() > 1 || always_display) {
|
||||
gui2::tunit_advance dlg(previews, num_real_advances);
|
||||
dlg.show(CVideo::get_singleton());
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
return dlg.get_selected_index();
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
136
src/gui/dialogs/unit_advance.cpp
Normal file
136
src/gui/dialogs/unit_advance.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/dialogs/unit_advance.hpp"
|
||||
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/dialogs/helper.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/image.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
#include "gui/widgets/list.hpp"
|
||||
#else
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#endif
|
||||
#include "gui/widgets/unit_preview_pane.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "units/unit.hpp"
|
||||
//#include "gettext.hpp"
|
||||
#include "help/help.hpp"
|
||||
//#include "marked-up_text.hpp"
|
||||
//#include "play_controller.hpp"
|
||||
//#include "resources.hpp"
|
||||
//#include "team.hpp"
|
||||
//#include "actions/attack.hpp" // for get_advanced_unit, get_amla_unit
|
||||
//#include "units/types.hpp"
|
||||
//#include "whiteboard/manager.hpp"
|
||||
//#include "game_preferences.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
REGISTER_DIALOG(unit_advance)
|
||||
|
||||
tunit_advance::tunit_advance(const unit_ptr_vector& samples, size_t real)
|
||||
: previews_(samples)
|
||||
, selected_index_(0)
|
||||
, real_(real)
|
||||
{
|
||||
}
|
||||
|
||||
void tunit_advance::pre_show(twindow& window)
|
||||
{
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "advance_choice", false);
|
||||
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
connect_signal_notify_modified(*list,
|
||||
std::bind(&tunit_advance::list_item_clicked,
|
||||
*this,
|
||||
std::ref(window)));
|
||||
#else
|
||||
list.set_callback_value_change(
|
||||
dialog_callback<tunit_advance, &tunit_advance::list_item_clicked>);
|
||||
#endif
|
||||
|
||||
window.keyboard_capture(&list);
|
||||
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<tbutton>(&window, "show_help", false),
|
||||
std::bind(&tunit_advance::show_help, this, std::ref(window)));
|
||||
|
||||
for(size_t i = 0; i < previews_.size(); i++) {
|
||||
const unit& sample = *previews_[i];
|
||||
std::map<std::string, string_map> row_data;
|
||||
string_map column;
|
||||
|
||||
std::string image_string, name = sample.type_name();
|
||||
if(i >= real_) {
|
||||
auto iter = sample
|
||||
.get_modifications()
|
||||
.child_range("advancement")
|
||||
.second;
|
||||
iter--;
|
||||
if(iter->has_attribute("image")) {
|
||||
image_string = iter->get("image")->str();
|
||||
}
|
||||
name = iter->get("description")->str();
|
||||
}
|
||||
if(image_string.empty()) {
|
||||
image_string = sample.type().image() + sample.image_mods();
|
||||
}
|
||||
|
||||
column["label"] = image_string;
|
||||
row_data.insert({"advancement_image", column});
|
||||
|
||||
column["label"] = name;
|
||||
row_data.insert({"advancement_name", column});
|
||||
|
||||
list.add_row(row_data);
|
||||
}
|
||||
|
||||
list_item_clicked(window);
|
||||
}
|
||||
|
||||
void tunit_advance::list_item_clicked(twindow& window)
|
||||
{
|
||||
const int selected_row
|
||||
= find_widget<tlistbox>(&window, "advance_choice", false).get_selected_row();
|
||||
|
||||
if(selected_row == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
find_widget<tunit_preview_pane>(&window, "advancement_details", false)
|
||||
.set_displayed_unit(*previews_[selected_row]);
|
||||
}
|
||||
|
||||
void tunit_advance::show_help(twindow& window)
|
||||
{
|
||||
help::show_help(window.video(), "advancement");
|
||||
}
|
||||
|
||||
void tunit_advance::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() == twindow::OK) {
|
||||
selected_index_ = find_widget<tlistbox>(&window, "advance_choice", false)
|
||||
.get_selected_row();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
52
src/gui/dialogs/unit_advance.hpp
Normal file
52
src/gui/dialogs/unit_advance.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_DIALOGS_UNIT_RECRUIT_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_UNIT_RECRUIT_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class tunit_advance : public tdialog
|
||||
{
|
||||
typedef std::vector<unit_const_ptr> unit_ptr_vector;
|
||||
public:
|
||||
tunit_advance(const unit_ptr_vector& samples, size_t real);
|
||||
|
||||
int get_selected_index() const
|
||||
{
|
||||
return selected_index_;
|
||||
}
|
||||
|
||||
private:
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const;
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(twindow& window);
|
||||
void post_show(twindow& window);
|
||||
|
||||
void list_item_clicked(twindow& window);
|
||||
|
||||
void show_help(twindow& window);
|
||||
|
||||
const unit_ptr_vector& previews_;
|
||||
|
||||
size_t selected_index_, real_;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif /* ! GUI_DIALOGS_UNIT_RECRUIT_HPP_INCLUDED */
|
|
@ -317,6 +317,7 @@ public:
|
|||
|
||||
std::vector<config> get_modification_advances() const;
|
||||
config& get_modifications() { return modifications_; }
|
||||
const config& get_modifications() const { return modifications_; }
|
||||
|
||||
typedef boost::ptr_vector<config> t_advancements;
|
||||
void set_advancements(std::vector<config> advancements);
|
||||
|
|
Loading…
Add table
Reference in a new issue