Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
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& , 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 }