From 4379c471dc24ca6fa21ec80c7b69b2835a5a6a6a Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Mon, 15 Nov 2010 20:25:09 +0000 Subject: [PATCH] Convert campaign difficulty selection dialog to GUI2 Changelog entries pending. May need wmllint changes. --- .../default/window/campaign_difficulty.cfg | 197 ++++++++++++++++++ src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/SConscript | 1 + src/game.cpp | 11 +- src/gui/dialogs/campaign_difficulty.cpp | 77 +++++++ src/gui/dialogs/campaign_difficulty.hpp | 51 +++++ 7 files changed, 334 insertions(+), 5 deletions(-) create mode 100644 data/gui/default/window/campaign_difficulty.cfg create mode 100644 src/gui/dialogs/campaign_difficulty.cpp create mode 100644 src/gui/dialogs/campaign_difficulty.hpp diff --git a/data/gui/default/window/campaign_difficulty.cfg b/data/gui/default/window/campaign_difficulty.cfg new file mode 100644 index 00000000000..3a1c3dcf3fd --- /dev/null +++ b/data/gui/default/window/campaign_difficulty.cfg @@ -0,0 +1,197 @@ +#textdomain wesnoth-lib +### +### Definition of the dialog window for campaign +### difficulty level selection. +### + +[window] + id = "campaign_difficulty" + description = "Campaign difficulty level selector." + + [resolution] + definition = "default" + + automatic_placement = "true" + vertical_placement = "center" + horizontal_placement = "center" + + [linked_group] + id = "icon" + fixed_width = "true" + [/linked_group] + + [linked_group] + id = "label" + fixed_width = "true" + [/linked_group] + + [linked_group] + id = "description" + 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 = _ "Difficulty" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + id = "message" + definition = "default" + label = _ "Select difficulty level:" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 1 + + [column] + grow_factor = 1 + + horizontal_grow = "true" + vertical_grow = "true" + + [listbox] + id = "listbox" + 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 = 0 + horizontal_alignment = "left" + border = "all" + border_size = 5 + [image] + id = "icon" + definition = "default" + linked_group = "icon" + [/image] + [/column] + [column] + grow_factor = 1 + horizontal_grow = "true" + border = "all" + border_size = 5 + [label] + id = "label" + definition = "default" + linked_group = "label" + [/label] + [/column] + [column] + grow_factor = 1 + horizontal_grow = "true" + border = "all" + border_size = 5 + [label] + id = "description" + definition = "default" + linked_group = "description" + [/label] + [/column] + [/row] + [/grid] + [/toggle_panel] + [/column] + + [/row] + + [/list_definition] + + [/listbox] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + horizontal_grow = "true" + + [grid] + + [row] + grow_factor = 0 + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "ok" + definition = "default" + label = _ "OK" + [/button] + + [/column] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "cancel" + definition = "default" + label = _ "Cancel" + [/button] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [/grid] + + [/resolution] + +[/window] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76167a5d1f0..e2cd57a5ef0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -402,6 +402,7 @@ set(wesnoth-main_SRC gui/auxiliary/window_builder.cpp gui/dialogs/addon_connect.cpp gui/dialogs/addon_list.cpp + gui/dialogs/campaign_difficulty.cpp gui/dialogs/campaign_selection.cpp gui/dialogs/data_manage.cpp gui/dialogs/dialog.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 1cad56a9b7c..3f063fddd20 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -172,6 +172,7 @@ wesnoth_source = \ gui/auxiliary/window_builder.cpp \ gui/dialogs/addon_connect.cpp \ gui/dialogs/addon_list.cpp \ + gui/dialogs/campaign_difficulty.cpp \ gui/dialogs/campaign_selection.cpp \ gui/dialogs/data_manage.cpp \ gui/dialogs/dialog.cpp \ diff --git a/src/SConscript b/src/SConscript index a68632bcfcd..283895435be 100644 --- a/src/SConscript +++ b/src/SConscript @@ -341,6 +341,7 @@ wesnoth_sources = Split(""" gui/auxiliary/window_builder.cpp gui/dialogs/addon_connect.cpp gui/dialogs/addon_list.cpp + gui/dialogs/campaign_difficulty.cpp gui/dialogs/campaign_selection.cpp gui/dialogs/data_manage.cpp gui/dialogs/dialog.cpp diff --git a/src/game.cpp b/src/game.cpp index 2ec3bd72d56..b90cd094b12 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -41,6 +41,7 @@ #include "gamestatus.hpp" #include "gettext.hpp" #include "gui/dialogs/addon_connect.hpp" +#include "gui/dialogs/campaign_difficulty.hpp" #include "gui/dialogs/campaign_selection.hpp" #include "gui/dialogs/language_selection.hpp" #include "gui/dialogs/message.hpp" @@ -1184,10 +1185,10 @@ bool game_controller::new_campaign() std::copy(difficulties.begin(),difficulties.end(),difficulty_options.begin()); } - gui::dialog dlg(disp(), _("Difficulty"), - _("Select difficulty level:"), gui::OK_CANCEL); - dlg.set_menu(difficulty_options); - if(dlg.show() == -1) { + gui2::tcampaign_difficulty dlg(difficulty_options); + dlg.show(disp().video()); + + if(dlg.selected_index() == -1) { if (jump_to_campaign_.campaign_id_.empty() == false) { jump_to_campaign_.campaign_id_ = ""; @@ -1195,7 +1196,7 @@ bool game_controller::new_campaign() // canceled difficulty dialog, relaunch the campaign selection dialog return new_campaign(); } - difficulty = dlg.result(); + difficulty = dlg.selected_index(); } else { diff --git a/src/gui/dialogs/campaign_difficulty.cpp b/src/gui/dialogs/campaign_difficulty.cpp new file mode 100644 index 00000000000..e06f6b58e89 --- /dev/null +++ b/src/gui/dialogs/campaign_difficulty.cpp @@ -0,0 +1,77 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio Riquelme 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/campaign_difficulty.hpp" + +#include "foreach.hpp" +#include "gui/auxiliary/old_markup.hpp" +#ifdef GUI2_EXPERIMENTAL_LISTBOX + #include "gui/widgets/list.hpp" +#else + #include "gui/widgets/listbox.hpp" +#endif +#include "gui/widgets/settings.hpp" +#include "gui/widgets/window.hpp" + +namespace gui2 { + +REGISTER_WINDOW(campaign_difficulty) + +tcampaign_difficulty::tcampaign_difficulty(const std::vector& items) + : index_(-1), items_() +{ + foreach(const std::string& it, items) { + items_.push_back(it); + } +} + +void tcampaign_difficulty::pre_show(CVideo& /*video*/, twindow& window) +{ + tlistbox& list = find_widget(&window, "listbox", false); + std::map data; + + foreach(const legacy_menu_item& item, items_) { + if(item.is_default()) { + index_ = list.get_item_count(); + } + + data["icon"]["label"] = item.icon(); + data["label"]["label"] = item.label(); + data["label"]["use_markup"] = "true"; + data["description"]["label"] = item.description(); + data["description"]["use_markup"] = "true"; + + list.add_row(data); + } + + if(index_ != -1) { + list.select_row(index_); + } +} + +void tcampaign_difficulty::post_show(twindow& window) +{ + if(get_retval() != twindow::OK) { + index_ = -1; + return; + } + + tlistbox& list = find_widget(&window, "listbox", false); + index_ = list.get_selected_row(); +} + +} diff --git a/src/gui/dialogs/campaign_difficulty.hpp b/src/gui/dialogs/campaign_difficulty.hpp new file mode 100644 index 00000000000..f93224a4b13 --- /dev/null +++ b/src/gui/dialogs/campaign_difficulty.hpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio Riquelme 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_CAMPAIGN_DIFFICULTY_HPP_INCLUDED +#define GUI_DIALOGS_CAMPAIGN_DIFFICULTY_HPP_INCLUDED + +#include "gui/dialogs/dialog.hpp" + +#include "gui/auxiliary/old_markup.hpp" +#include + +namespace gui2 { + +class tcampaign_difficulty : public tdialog +{ +public: + tcampaign_difficulty(const std::vector& items); + + int selected_index() const { return index_; } + +private: + int index_; + std::vector items_; + + /** Inherited from tdialog, implemented by REGISTER_WINDOW. */ + 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); +}; + + +} + + +#endif /* ! GUI_DIALOGS_CAMPAIGN_DIFFICULTY_HPP_INCLUDED */ \ No newline at end of file