gui/dialogs/campaign_difficulty.cpp

Go to the documentation of this file.
00001 /* $Id: campaign_difficulty.cpp 53011 2012-02-14 18:36:48Z mordante $ */
00002 /*
00003    Copyright (C) 2010 - 2012 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/dialogs/campaign_difficulty.hpp"
00019 
00020 #include "foreach.hpp"
00021 #include "gui/auxiliary/old_markup.hpp"
00022 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00023     #include "gui/widgets/list.hpp"
00024 #else
00025     #include "gui/widgets/listbox.hpp"
00026 #endif
00027 #include "gui/widgets/settings.hpp"
00028 #include "gui/widgets/window.hpp"
00029 
00030 namespace gui2 {
00031 
00032 /*WIKI
00033  * @page = GUIWindowDefinitionWML
00034  * @order = 2_campaign_difficulty
00035  *
00036  * == Campaign difficulty ==
00037  *
00038  * The campaign mode difficulty menu.
00039  *
00040  * @begin{table}{dialog_widgets}
00041  *
00042  * title & & label & m &
00043  *         Dialog title label. $
00044  *
00045  * message & & scroll_label & o &
00046  *         Text label displaying a description or instructions. $
00047  *
00048  * listbox & & listbox & m &
00049  *         Listbox displaying user choices, defined by WML for each campaign. $
00050  *
00051  * -icon & & control & m &
00052  *         Widget which shows a listbox item icon, first item markup column. $
00053  *
00054  * -label & & control & m &
00055  *         Widget which shows a listbox item label, second item markup column. $
00056  *
00057  * -description & & control & m &
00058  *         Widget which shows a listbox item description, third item markup column. $
00059  *
00060  * @end{table}
00061  */
00062 
00063 REGISTER_DIALOG(campaign_difficulty)
00064 
00065 tcampaign_difficulty::tcampaign_difficulty(
00066           const std::vector<std::string>& items
00067         , const int default_difficulty)
00068     : index_(-1)
00069     , items_()
00070     , default_difficulty_(default_difficulty)
00071 {
00072     foreach(const std::string& it, items) {
00073         items_.push_back(tlegacy_menu_item(it));
00074     }
00075 }
00076 
00077 void tcampaign_difficulty::pre_show(CVideo& /*video*/, twindow& window)
00078 {
00079     tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00080     window.keyboard_capture(&list);
00081 
00082     std::map<std::string, string_map> data;
00083 
00084     foreach(const tlegacy_menu_item& item, items_) {
00085         if(item.is_default()) {
00086             index_ = list.get_item_count();
00087         }
00088 
00089         data["icon"]["label"] = item.icon();
00090         data["label"]["label"] = item.label();
00091         data["label"]["use_markup"] = "true";
00092         data["description"]["label"] = item.description();
00093         data["description"]["use_markup"] = "true";
00094 
00095         list.add_row(data);
00096     }
00097 
00098     if(index_ != -1) {
00099         list.select_row(index_);
00100     }
00101 }
00102 
00103 void tcampaign_difficulty::post_show(twindow& window)
00104 {
00105     if(get_retval() != twindow::OK) {
00106         index_ = -1;
00107         return;
00108     }
00109 
00110     tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
00111     index_ = list.get_selected_row();
00112 }
00113 
00114 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:43 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs