mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 17:11:17 +00:00
Convert campaign difficulty selection dialog to GUI2
Changelog entries pending. May need wmllint changes.
This commit is contained in:
parent
895f6b333c
commit
4379c471dc
197
data/gui/default/window/campaign_difficulty.cfg
Normal file
197
data/gui/default/window/campaign_difficulty.cfg
Normal file
@ -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]
|
@ -402,6 +402,7 @@ set(wesnoth-main_SRC
|
|||||||
gui/auxiliary/window_builder.cpp
|
gui/auxiliary/window_builder.cpp
|
||||||
gui/dialogs/addon_connect.cpp
|
gui/dialogs/addon_connect.cpp
|
||||||
gui/dialogs/addon_list.cpp
|
gui/dialogs/addon_list.cpp
|
||||||
|
gui/dialogs/campaign_difficulty.cpp
|
||||||
gui/dialogs/campaign_selection.cpp
|
gui/dialogs/campaign_selection.cpp
|
||||||
gui/dialogs/data_manage.cpp
|
gui/dialogs/data_manage.cpp
|
||||||
gui/dialogs/dialog.cpp
|
gui/dialogs/dialog.cpp
|
||||||
|
@ -172,6 +172,7 @@ wesnoth_source = \
|
|||||||
gui/auxiliary/window_builder.cpp \
|
gui/auxiliary/window_builder.cpp \
|
||||||
gui/dialogs/addon_connect.cpp \
|
gui/dialogs/addon_connect.cpp \
|
||||||
gui/dialogs/addon_list.cpp \
|
gui/dialogs/addon_list.cpp \
|
||||||
|
gui/dialogs/campaign_difficulty.cpp \
|
||||||
gui/dialogs/campaign_selection.cpp \
|
gui/dialogs/campaign_selection.cpp \
|
||||||
gui/dialogs/data_manage.cpp \
|
gui/dialogs/data_manage.cpp \
|
||||||
gui/dialogs/dialog.cpp \
|
gui/dialogs/dialog.cpp \
|
||||||
|
@ -341,6 +341,7 @@ wesnoth_sources = Split("""
|
|||||||
gui/auxiliary/window_builder.cpp
|
gui/auxiliary/window_builder.cpp
|
||||||
gui/dialogs/addon_connect.cpp
|
gui/dialogs/addon_connect.cpp
|
||||||
gui/dialogs/addon_list.cpp
|
gui/dialogs/addon_list.cpp
|
||||||
|
gui/dialogs/campaign_difficulty.cpp
|
||||||
gui/dialogs/campaign_selection.cpp
|
gui/dialogs/campaign_selection.cpp
|
||||||
gui/dialogs/data_manage.cpp
|
gui/dialogs/data_manage.cpp
|
||||||
gui/dialogs/dialog.cpp
|
gui/dialogs/dialog.cpp
|
||||||
|
11
src/game.cpp
11
src/game.cpp
@ -41,6 +41,7 @@
|
|||||||
#include "gamestatus.hpp"
|
#include "gamestatus.hpp"
|
||||||
#include "gettext.hpp"
|
#include "gettext.hpp"
|
||||||
#include "gui/dialogs/addon_connect.hpp"
|
#include "gui/dialogs/addon_connect.hpp"
|
||||||
|
#include "gui/dialogs/campaign_difficulty.hpp"
|
||||||
#include "gui/dialogs/campaign_selection.hpp"
|
#include "gui/dialogs/campaign_selection.hpp"
|
||||||
#include "gui/dialogs/language_selection.hpp"
|
#include "gui/dialogs/language_selection.hpp"
|
||||||
#include "gui/dialogs/message.hpp"
|
#include "gui/dialogs/message.hpp"
|
||||||
@ -1184,10 +1185,10 @@ bool game_controller::new_campaign()
|
|||||||
std::copy(difficulties.begin(),difficulties.end(),difficulty_options.begin());
|
std::copy(difficulties.begin(),difficulties.end(),difficulty_options.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
gui::dialog dlg(disp(), _("Difficulty"),
|
gui2::tcampaign_difficulty dlg(difficulty_options);
|
||||||
_("Select difficulty level:"), gui::OK_CANCEL);
|
dlg.show(disp().video());
|
||||||
dlg.set_menu(difficulty_options);
|
|
||||||
if(dlg.show() == -1) {
|
if(dlg.selected_index() == -1) {
|
||||||
if (jump_to_campaign_.campaign_id_.empty() == false)
|
if (jump_to_campaign_.campaign_id_.empty() == false)
|
||||||
{
|
{
|
||||||
jump_to_campaign_.campaign_id_ = "";
|
jump_to_campaign_.campaign_id_ = "";
|
||||||
@ -1195,7 +1196,7 @@ bool game_controller::new_campaign()
|
|||||||
// canceled difficulty dialog, relaunch the campaign selection dialog
|
// canceled difficulty dialog, relaunch the campaign selection dialog
|
||||||
return new_campaign();
|
return new_campaign();
|
||||||
}
|
}
|
||||||
difficulty = dlg.result();
|
difficulty = dlg.selected_index();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
77
src/gui/dialogs/campaign_difficulty.cpp
Normal file
77
src/gui/dialogs/campaign_difficulty.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
|
||||||
|
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<std::string>& 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<tlistbox>(&window, "listbox", false);
|
||||||
|
std::map<std::string, string_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<tlistbox>(&window, "listbox", false);
|
||||||
|
index_ = list.get_selected_row();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/gui/dialogs/campaign_difficulty.hpp
Normal file
51
src/gui/dialogs/campaign_difficulty.hpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
Copyright (C) 2010 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
|
||||||
|
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 <vector>
|
||||||
|
|
||||||
|
namespace gui2 {
|
||||||
|
|
||||||
|
class tcampaign_difficulty : public tdialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
tcampaign_difficulty(const std::vector<std::string>& items);
|
||||||
|
|
||||||
|
int selected_index() const { return index_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int index_;
|
||||||
|
std::vector<legacy_menu_item> 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 */
|
Loading…
x
Reference in New Issue
Block a user