From e7b7abe209fb63c35aa528e4642363bdcde61671 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Tue, 21 Dec 2010 21:08:36 +0000 Subject: [PATCH] GUI2: New add-ons description dialog... ...with more details than the description (merge 1) --- data/gui/default/window/addon_description.cfg | 152 ++++++++++++++++++ src/SConscript | 1 + src/addon/manager.cpp | 44 +++-- src/gui/dialogs/addon/description.cpp | 64 ++++++++ src/gui/dialogs/addon/description.hpp | 53 ++++++ 5 files changed, 298 insertions(+), 16 deletions(-) create mode 100644 data/gui/default/window/addon_description.cfg create mode 100644 src/gui/dialogs/addon/description.cpp create mode 100644 src/gui/dialogs/addon/description.hpp diff --git a/data/gui/default/window/addon_description.cfg b/data/gui/default/window/addon_description.cfg new file mode 100644 index 00000000000..8d12d64134d --- /dev/null +++ b/data/gui/default/window/addon_description.cfg @@ -0,0 +1,152 @@ +#textdomain wesnoth-lib + +[window] + id = "addon_description" + description = "Add-on description and details for the add-ons manager interface." + + [resolution] + definition = "message" + + click_dismiss = "true" + maximum_width = 800 + + [grid] + + [row] + + [column] + vertical_alignment = "top" + + [image] + id = "image" + definition = "default" + [/image] + + [/column] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "left" + vertical_alignment = "top" + + [label] + id = "title" + definition = "title" + [/label] + + [/column] + + [/row] + + [row] + + {GUI_FILLER} + + [column] + + horizontal_alignment = "left" + + [grid] + + [row] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + definition = "default" + label = _ "Version:" + [/label] + + [/column] + + [column] + border = "all" + border_size = 5 + vertical_alignment = "top" + horizontal_alignment = "left" + + [label] + id = "version" + definition = "default" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 1 + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + definition = "default" + label = _ "Description:" + [/label] + + [/column] + + [column] + border = "all" + border_size = 5 + vertical_alignment = "top" + horizontal_alignment = "left" + + [scroll_label] + id = "description" + definition = "default" + [/scroll_label] + + [/column] + + [/row] + + [row] + grow_factor = 1 + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + definition = "default" + label = _ "Translations:" + [/label] + + [/column] + + [column] + border = "all" + border_size = 5 + vertical_alignment = "top" + horizontal_alignment = "left" + + [scroll_label] + id = "translations" + definition = "default" + [/scroll_label] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [/grid] + + [/resolution] + +[/window] + diff --git a/src/SConscript b/src/SConscript index e078959e28f..0d6bfbd786e 100644 --- a/src/SConscript +++ b/src/SConscript @@ -342,6 +342,7 @@ wesnoth_sources = Split(""" gui/auxiliary/window_builder.cpp gui/dialogs/addon_connect.cpp gui/dialogs/addon_list.cpp + gui/dialogs/addon/description.cpp gui/dialogs/campaign_difficulty.cpp gui/dialogs/campaign_selection.cpp gui/dialogs/data_manage.cpp diff --git a/src/addon/manager.cpp b/src/addon/manager.cpp index 188f4bc79c8..bdae6106b2c 100644 --- a/src/addon/manager.cpp +++ b/src/addon/manager.cpp @@ -26,6 +26,7 @@ #include "gettext.hpp" #include "gui/dialogs/addon_connect.hpp" #include "gui/dialogs/addon_list.hpp" +#include "gui/dialogs/addon/description.hpp" #include "gui/dialogs/message.hpp" #include "gui/dialogs/simple_item_selector.hpp" #include "gui/dialogs/transient_message.hpp" @@ -329,14 +330,13 @@ namespace { class display_description : public gui::dialog_button_action { display& disp_; - std::vector titles_, desc_; + std::vector infov_; gui::filter_textbox* filter_; public: - display_description(display& disp, std::vector const& titles, std::vector const& descriptions, gui::filter_textbox* filter) + display_description(display& disp, std::vector const& infov, gui::filter_textbox* filter) : disp_(disp) - , titles_(titles) - , desc_(descriptions) + , infov_(infov) , filter_(filter) {} @@ -347,18 +347,10 @@ namespace { if(menu_selection < 0) { return gui::CONTINUE_DIALOG; } size_t const uchoice = static_cast(menu_selection); - std::string text; - std::string title; - - if(uchoice >= desc_.size()) { - text = _("No description available."); + if(uchoice < infov_.size()) { + gui2::taddon_description ddlg(infov_[uchoice]); + ddlg.show(disp_.video()); } - else { - title = titles_[uchoice]; - text = desc_[uchoice]; - } - - gui2::show_transient_message(disp_.video(), title, text); return gui::CONTINUE_DIALOG; } @@ -1161,6 +1153,8 @@ namespace { std::vector< std::string > delete_options; + std::vector< addon_info > infos; + foreach(const config &c, addon_cfgs) { const std::string& name = c["name"]; @@ -1171,10 +1165,15 @@ namespace { const ADDON_TYPE type = get_addon_type(type_str); const std::string& type_label_str = get_translatable_addon_type(type); + addon_info inf; + addons.push_back(name); versions.push_back(c["version"]); uploads.push_back(c["uploads"]); descriptions.push_back(c["description"]); + + inf.description = c["description"]; + types.push_back(type_str); if(std::count(publish_options.begin(), publish_options.end(), name) != 0) { @@ -1188,14 +1187,20 @@ namespace { } titles.push_back(title); + inf.name = title; + std::string version = c["version"], author = c["author"]; + inf.version = version; + //add negative sizes to reverse the sort order sizes.push_back(-size); std::string icon = c["icon"]; do_addon_icon_fixups(icon, name); + inf.icon = icon; + std::string text_columns = title + COLUMN_SEPARATOR + version + COLUMN_SEPARATOR + @@ -1221,6 +1226,13 @@ namespace { sizef + COLUMN_SEPARATOR; options.push_back(text_columns); + + config::const_child_itors const& linguas = c.child_range("translation"); + for(config::const_child_iterator i = linguas.first; i != linguas.second; ++i) { + inf.translations.push_back((*i)["language"]); + } + + infos.push_back(inf); } std::string pub_option_text, del_option_text; @@ -1270,7 +1282,7 @@ namespace { _("Filter: "), options, options_to_filter, 1, addon_dialog, 300); addon_dialog.set_textbox(filter); - display_description description_helper(disp, titles, descriptions, filter); + display_description description_helper(disp, infos, filter); gui::dialog_button* description = new gui::dialog_button(disp.video(), _("Description"), gui::button::TYPE_PRESS, gui::CONTINUE_DIALOG, &description_helper); addon_dialog.add_button(description, gui::dialog::BUTTON_EXTRA); diff --git a/src/gui/dialogs/addon/description.cpp b/src/gui/dialogs/addon/description.cpp new file mode 100644 index 00000000000..ba3751ce131 --- /dev/null +++ b/src/gui/dialogs/addon/description.cpp @@ -0,0 +1,64 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio R. Morelle + Part of 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/addon/description.hpp" + +#include "foreach.hpp" +#include "gui/widgets/settings.hpp" +#include "gui/widgets/window.hpp" +#include "language.hpp" + +namespace { + t_string langcode_to_tstring(const std::string& lcode) + { + foreach(const language_def& ld, get_languages()) { + if(ld.localename == lcode) { + return ld.language; + } + } + + return ""; + } +} + +namespace gui2 { + +REGISTER_WINDOW(addon_description) + +void taddon_description::pre_show(CVideo& /*video*/, twindow& window) +{ + const std::string fixed_icon = ainfo_.icon + "~SCALE(72,72)"; + find_widget(&window, "image", false).set_label(fixed_icon); + + find_widget(&window, "title", false).set_label(ainfo_.name); + find_widget(&window, "description", false).set_label(ainfo_.description); + find_widget(&window, "version", false).set_label(ainfo_.version); + + std::string languages; + + foreach(const std::string& lc, ainfo_.translations) { + if(languages.empty() == false) { + languages += ", "; + } + languages += langcode_to_tstring(lc); + } + + find_widget(&window, "translations", false).set_label(languages); +} + +} + diff --git a/src/gui/dialogs/addon/description.hpp b/src/gui/dialogs/addon/description.hpp new file mode 100644 index 00000000000..3830f14000a --- /dev/null +++ b/src/gui/dialogs/addon/description.hpp @@ -0,0 +1,53 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio R. Morelle + Part of 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_ADDON_DESCRIPTION_HPP_INCLUDED +#define GUI_DIALOGS_ADDON_DESCRIPTION_HPP_INCLUDED + +#include "gui/dialogs/dialog.hpp" +#include "tstring.hpp" + +#include + +struct addon_info +{ + t_string name; + t_string description; + std::string icon; + std::string version; + std::vector translations; +}; + +namespace gui2 { + +class taddon_description : public tdialog +{ +public: + taddon_description(const addon_info& ainfo) + : ainfo_(ainfo) {} + + /** Inherited from tdialog, implemented by REGISTER_WINDOW. */ + virtual const std::string& window_id() const; + + /** Inherited from tdialog. */ + void pre_show(CVideo& video, twindow& window); + +private: + addon_info ainfo_; +}; + +} + +#endif