gui2/tgame_version: Turned into a tabbed dialog, added plenty more info

The dialog now includes the game and OS version, and has three tabs with
extra information: the Game Paths tab with the existing contents
inherited from the tgame_paths dialog, the Libraries tab with a table
listing the build/runtime library versions, and the Features tab listing
the status of optional build-time features.

Had to move a lot of code around for this, obviously. Now I have to
decide again where to move the button from Preferences -> General.
This commit is contained in:
Ignacio R. Morelle 2015-07-13 20:55:29 -03:00
parent 51c026dc91
commit 43dd063425
3 changed files with 623 additions and 49 deletions

View file

@ -1,8 +1,8 @@
#textdomain wesnoth-lib
#define __GUI_GAME_PATHS_ENTRY ID_STEM LABEL
#define _GUI_GAME_PATHS_ENTRY ID_STEM LABEL
[row]
grow_factor = 1
grow_factor = 0
[column]
grow_factor = 0
@ -69,6 +69,269 @@
[/row]
#enddef
#
# Used to emulate a basic horizontal listbox.
# (TODO: implement a real horizontal listbox.)
#
#define _GUI_VERINFO_TAB _ID _LABEL
[toggle_panel]
id = {_ID}
linked_group = "tabs"
[grid]
[row]
{_GUI_VERINFO_TAB_PADDING}
[column]
grow_factor = 1
border = all
border_size = 5
[label]
label = {_LABEL}
wrap = true
[/label]
[/column]
{_GUI_VERINFO_TAB_PADDING}
[/row]
[/grid]
[/toggle_panel]
#enddef
#define _GUI_VERINFO_TAB_PADDING
[column]
border = all
border_size = 5
[spacer][/spacer]
[/column]
#enddef
#define _GUI_VERINFO_TAB_PAGE_GAME_PATHS
[row]
[column]
horizontal_grow = true
vertical_alignment = top
[grid]
#
# NOTE: the following ids must follow the C++ code's expectations
# (see gui2::tgame_version::path_map_).
#
{_GUI_GAME_PATHS_ENTRY datadir ( _ "Game data:")}
{_GUI_GAME_PATHS_ENTRY config ( _ "Configuration:")}
{_GUI_GAME_PATHS_ENTRY userdata ( _ "User data:")}
{_GUI_GAME_PATHS_ENTRY saves ( _ "Saved games:")}
{_GUI_GAME_PATHS_ENTRY addons ( _ "Add-ons:")}
{_GUI_GAME_PATHS_ENTRY cache ( _ "Cache:")}
[/grid]
[/column]
[/row]
#enddef
#define _GUI_VERINFO_TAB_PAGE_BUILD_INFO
[row]
[column]
horizontal_grow = true
vertical_alignment = top
border = "left,right,bottom"
border_size = 5
[listbox]
id = "deps_listbox"
definition = "default"
[header]
[row]
[column]
horizontal_grow = true
border = "all"
border_size = 5
[label]
label = _ "library^Name"
linked_group = "dep_name"
[/label]
[/column]
[column]
horizontal_grow = true
border = "all"
border_size = 5
[label]
label = _ "library^Build version"
linked_group = "dep_build_version"
[/label]
[/column]
[column]
horizontal_grow = true
border = "all"
border_size = 5
[label]
label = _ "library^Runtime version"
linked_group = "dep_rt_version"
[/label]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
horizontal_grow = true
vertical_grow = true
[toggle_panel]
[grid]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "dep_name"
definition = "default"
linked_group = "dep_name"
wrap = true
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "dep_build_version"
linked_group = "dep_build_version"
wrap = true
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "dep_rt_version"
linked_group = "dep_rt_version"
wrap = true
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
#enddef
#define _GUI_VERINFO_TAB_PAGE_GAME_FEATURES
[row]
grow_factor = 0
[column]
horizontal_alignment = left
vertical_alignment = top
border = "all"
border_size = 5
[label]
label = _ "The following features were enabled when building this version of Wesnoth:"
wrap = true
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
horizontal_grow = true
vertical_alignment = top
border = "all"
border_size = 5
[listbox]
id = "opts_listbox"
definition = "default"
[list_definition]
[row]
[column]
horizontal_grow = true
vertical_grow = true
[toggle_panel]
[grid]
[row]
[column]
grow_factor = 2
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "opt_name"
linked_group = "opt_name"
wrap = true
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[image]
id = "opt_status"
linked_group = "opt_status"
[/image]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
#enddef
[window]
id = "game_version"
description = "List of paths used by the game to locate resource and configuration files."
@ -77,7 +340,8 @@
definition = "default"
click_dismiss = "true"
maximum_width = 800
maximum_width = 600
maximum_height = 480
[tooltip]
id = "tooltip_large"
@ -87,54 +351,188 @@
id = "tooltip_large"
[/helptip]
[linked_group]
id = "tabs"
fixed_width = "true"
fixed_height = "true"
[/linked_group]
[linked_group]
id = "dep_name"
fixed_width = "true"
[/linked_group]
[linked_group]
id = "dep_build_version"
fixed_width = "true"
[/linked_group]
[linked_group]
id = "dep_rt_version"
fixed_width = "true"
[/linked_group]
[linked_group]
id = "opt_name"
fixed_width = "true"
[/linked_group]
[linked_group]
id = "opt_status"
fixed_width = "true"
[/linked_group]
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
label = _ "Game Paths"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
horizontal_grow = "true"
horizontal_alignment = left
vertical_alignment = top
[grid]
#
# NOTE: the following ids must follow the C++ code's expectations
# (see gui2::tgame_paths::path_map_).
#
[row]
{__GUI_GAME_PATHS_ENTRY datadir ( _ "Game data:")}
[column]
horizontal_alignment = left
vertical_alignment = top
border = all
border_size = 5
{__GUI_GAME_PATHS_ENTRY config ( _ "Configuration:")}
[image]
label = "wesnoth-icon.png"
[/image]
{__GUI_GAME_PATHS_ENTRY userdata ( _ "User data:")}
[/column]
{__GUI_GAME_PATHS_ENTRY saves ( _ "Saved games:")}
[column]
horizontal_grow = true
vertical_alignment = top
{__GUI_GAME_PATHS_ENTRY addons ( _ "Add-ons:")}
[grid]
[row]
[column]
horizontal_alignment = left
vertical_alignment = top
border = all
border_size = 5
{__GUI_GAME_PATHS_ENTRY cache ( _ "Cache:")}
[label]
label = _ "The Battle for Wesnoth"
definition = "title"
wrap = true
[/label]
[/column]
[/row]
[row]
[column]
horizontal_alignment = left
vertical_alignment = top
border = all
border_size = 5
[label]
id = version
definition = default_bold
label = "Version X.XX.XX XXXXXXXXXXXXX"
wrap = true
[/label]
[/column]
[/row]
[row]
[column]
horizontal_alignment = left
vertical_alignment = top
border = all
border_size = 5
[label]
id = os
label = "Running on XXXXXXXXXX"
wrap = true
[/label]
[/column]
[/row]
[row]
[column]
border = all
border_size = 5
[spacer][/spacer]
[/column]
[/row]
[row]
[column]
border = all
border_size = 5
[grid]
[row]
[column]
{_GUI_VERINFO_TAB tab_game_paths ( _ "Paths")}
[/column]
[column]
{_GUI_VERINFO_TAB tab_game_deps ( _ "Libraries")}
[/column]
[column]
{_GUI_VERINFO_TAB tab_game_features ( _ "Features")}
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
horizontal_grow = true
[stacked_widget]
id = tabs_container
[stack]
[layer]
{_GUI_VERINFO_TAB_PAGE_GAME_PATHS}
[/layer]
[layer]
{_GUI_VERINFO_TAB_PAGE_BUILD_INFO}
[/layer]
[layer]
{_GUI_VERINFO_TAB_PAGE_GAME_FEATURES}
[/layer]
[/stack]
[/stacked_widget]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
@ -146,7 +544,7 @@
grow_factor = 0
[column]
horizontal_alignment = "right"
horizontal_grow = true
[grid]
@ -154,15 +552,15 @@
grow_factor = 0
[column]
horizontal_alignment = right
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "OK"
label = _ "Close"
[/button]
[/column]
@ -175,11 +573,15 @@
[/row]
[/grid]
[/resolution]
[/window]
#undef __GUI_GAME_PATHS_ENTRY
#undef _GUI_GAME_PATHS_ENTRY
#undef _GUI_VERINFO_TAB
#undef _GUI_VERINFO_TAB_PADDING
#undef _GUI_VERINFO_TAB_PAGE_GAME_PATHS
#undef _GUI_VERINFO_TAB_PAGE_BUILD_INFO
#undef _GUI_VERINFO_TAB_PAGE_GAME_FEATURES

View file

@ -16,14 +16,24 @@
#include "gui/dialogs/game_version.hpp"
#include "build_info.hpp"
#include "desktop/clipboard.hpp"
#include "desktop/open.hpp"
#include "desktop/version.hpp"
#include "filesystem.hpp"
#include "formula_string_utils.hpp"
#include "game_config.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/control.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/selectable.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/stacked_widget.hpp"
#include "gui/widgets/text.hpp"
#include "gui/widgets/window.hpp"
#include "serialization/string_utils.hpp"
@ -32,6 +42,14 @@
#include <boost/bind.hpp>
namespace
{
const std::string img_feature_on = "buttons/checkbox-pressed.png";
const std::string img_feature_off = "buttons/checkbox.png";
} // end anonymous namespace
namespace gui2
{
@ -69,6 +87,9 @@ tgame_version::tgame_version()
, copy_wid_stem_("copy_")
, browse_wid_stem_("browse_")
, path_map_()
, deps_()
, opts_(game_config::optional_features_table())
, tabs_()
{
// NOTE: these path_map_ entries are referenced by the GUI2 WML
// definition of this dialog using preprocessor macros.
@ -78,10 +99,38 @@ tgame_version::tgame_version()
path_map_["saves"] = filesystem::get_saves_dir();
path_map_["addons"] = filesystem::get_addons_dir();
path_map_["cache"] = filesystem::get_cache_dir();
for(unsigned k = 0; k < game_config::LIB_COUNT; ++k) {
const game_config::LIBRARY_ID lib = game_config::LIBRARY_ID(k);
deplist_entry e;
e[0] = game_config::library_name(lib);
e[1] = game_config::library_build_version(lib);
e[2] = game_config::library_runtime_version(lib);
deps_.push_back(e);
}
}
void tgame_version::pre_show(CVideo& /*video*/, twindow& window)
{
string_map i18n_syms;
//
// General information.
//
tcontrol& version_label = find_widget<tcontrol>(&window, "version", false);
i18n_syms["version"] = game_config::revision;
version_label.set_label(VGETTEXT("Version $version", i18n_syms));
tcontrol& os_label = find_widget<tcontrol>(&window, "os", false);
i18n_syms["os"] = desktop::os_version();
os_label.set_label(VGETTEXT("Running on $os", i18n_syms));
//
// Game paths tab.
//
FOREACH(const AUTO & path_ent, path_map_)
{
const std::string& path_id = path_ent.first;
@ -119,6 +168,99 @@ void tgame_version::pre_show(CVideo& /*video*/, twindow& window)
copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
}
}
//
// Build info tab.
//
std::map<std::string, string_map> list_data;
tlistbox& deps_listbox
= find_widget<tlistbox>(&window, "deps_listbox", false);
FOREACH(const AUTO & dep, deps_)
{
list_data["dep_name"]["label"] = dep[0];
list_data["dep_build_version"]["label"] = dep[1];
// The build version is always known, but runtime version isn't, esp.
// for header-only libraries like Boost for which the concept does not
// apply.
if(!dep[2].empty()) {
list_data["dep_rt_version"]["label"] = dep[2];
} else {
list_data["dep_rt_version"]["label"] = _("version^N/A");
}
deps_listbox.add_row(list_data);
}
deps_listbox.select_row(0);
list_data.clear();
//
// Features tab.
//
tlistbox& opts_listbox
= find_widget<tlistbox>(&window, "opts_listbox", false);
FOREACH(const AUTO & opt, opts_)
{
list_data["opt_name"]["label"] = opt.name;
if(opt.enabled) {
list_data["opt_status"]["label"] = img_feature_on;
} else {
list_data["opt_status"]["label"] = img_feature_off;
}
opts_listbox.add_row(list_data);
}
opts_listbox.select_row(0);
list_data.clear();
//
// Set-up page stack and auxiliary controls last.
//
tstacked_widget& pager
= find_widget<tstacked_widget>(&window, "tabs_container", false);
pager.select_layer(0);
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_paths", false));
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_deps", false));
tabs_.push_back(&find_widget<tselectable_>(&window, "tab_game_features", false));
tabs_.front()->set_value(true);
FOREACH(const AUTO & tab, tabs_)
{
tab->set_callback_state_change(
boost::bind(&tgame_version::tab_switch_callback, this, boost::ref(*tab), boost::ref(pager)));
}
}
void tgame_version::post_show(twindow& /*window*/)
{
tabs_.clear();
}
void tgame_version::tab_switch_callback(tselectable_& me, tstacked_widget& tab_container)
{
for(size_t k = 0; k < tabs_.size(); ++k) {
tselectable_* const current = tabs_[k];
if(!current) {
continue;
}
current->set_value(&me == current);
if(&me == current) {
tab_container.select_layer(k);
}
}
}
void tgame_version::browse_directory_callback(const std::string& path)
@ -130,4 +272,5 @@ void tgame_version::copy_to_clipboard_callback(const std::string& path)
{
desktop::clipboard::copy_to_clipboard(path, false);
}
}
} // end namespace gui2

View file

@ -17,11 +17,18 @@
#include "gui/dialogs/dialog.hpp"
#include "build_info.hpp"
#include <map>
#include <boost/array.hpp>
namespace gui2
{
class tselectable_;
class tstacked_widget;
class tgame_version : public tdialog
{
public:
@ -47,6 +54,34 @@ private:
std::map<std::string, std::string> path_map_;
typedef boost::array<std::string, 4> deplist_entry;
std::vector<deplist_entry> deps_;
std::vector<game_config::optional_feature> opts_;
std::vector<tselectable_*> tabs_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
//
// Widget event callbacks.
//
/**
* Callback function called when the tab switch widgets' state changes.
*
* @param me The widget whose state just changed.
* @param tab_container The tab pages container widget.
*/
void tab_switch_callback(tselectable_& me, tstacked_widget& tab_container);
/**
* Callback function for copy-to-clipboard action buttons.
*
@ -60,12 +95,6 @@ private:
* @param path Filesystem path associated with the widget.
*/
void browse_directory_callback(const std::string& path);
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
};
}