Add a new simple item selector GUI2 dialog, and convert :cl to use it
This commit is contained in:
parent
b768631545
commit
0d7e330103
7 changed files with 316 additions and 4 deletions
162
data/gui/default/window/simple_item_selector.cfg
Normal file
162
data/gui/default/window/simple_item_selector.cfg
Normal file
|
@ -0,0 +1,162 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to select an addon for installation.
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "simple_item_selector"
|
||||
description = "Generic item selection dialog."
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "center"
|
||||
horizontal_placement = "center"
|
||||
|
||||
[linked_group]
|
||||
id = "item"
|
||||
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]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
id = "message"
|
||||
definition = "default"
|
||||
[/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 = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "item"
|
||||
definition = "default"
|
||||
linked_group = "item"
|
||||
[/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]
|
|
@ -419,6 +419,7 @@ set(wesnoth-main_SRC
|
|||
gui/dialogs/mp_create_game.cpp
|
||||
gui/dialogs/mp_method_selection.cpp
|
||||
gui/dialogs/mp_cmd_wrapper.cpp
|
||||
gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
gui/dialogs/transient_message.cpp
|
||||
gui/dialogs/unit_attack.cpp
|
||||
|
|
|
@ -189,6 +189,7 @@ wesnoth_source = \
|
|||
gui/dialogs/mp_create_game.cpp \
|
||||
gui/dialogs/mp_method_selection.cpp \
|
||||
gui/dialogs/mp_cmd_wrapper.cpp \
|
||||
gui/dialogs/simple_item_selector.cpp \
|
||||
gui/dialogs/title_screen.cpp \
|
||||
gui/dialogs/transient_message.cpp \
|
||||
gui/dialogs/unit_attack.cpp \
|
||||
|
|
|
@ -357,6 +357,7 @@ wesnoth_sources = Split("""
|
|||
gui/dialogs/mp_create_game.cpp
|
||||
gui/dialogs/mp_method_selection.cpp
|
||||
gui/dialogs/mp_cmd_wrapper.cpp
|
||||
gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
gui/dialogs/transient_message.cpp
|
||||
gui/dialogs/unit_attack.cpp
|
||||
|
|
83
src/gui/dialogs/simple_item_selector.cpp
Normal file
83
src/gui/dialogs/simple_item_selector.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* $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/simple_item_selector.hpp"
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "gui/widgets/label.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(simple_item_selector)
|
||||
|
||||
tsimple_item_selector::tsimple_item_selector(const std::string& title, const std::string& message, list_type const& items, bool title_uses_markup, bool message_uses_markup)
|
||||
: index_(-1)
|
||||
, title_(title)
|
||||
, msg_(message)
|
||||
, markup_title_(title_uses_markup)
|
||||
, markup_msg_(message_uses_markup)
|
||||
, items_(items)
|
||||
{
|
||||
}
|
||||
|
||||
void tsimple_item_selector::pre_show(CVideo& /*video*/, twindow& window)
|
||||
{
|
||||
tlabel& ltitle = find_widget<tlabel>(&window, "title", false);
|
||||
tlabel& lmessage = find_widget<tlabel>(&window, "message", false);
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
|
||||
|
||||
ltitle.set_label(title_);
|
||||
ltitle.set_use_markup(markup_title_);
|
||||
|
||||
lmessage.set_label(msg_);
|
||||
lmessage.set_use_markup(markup_msg_);
|
||||
|
||||
foreach(const tsimple_item_selector::item_type& it, items_) {
|
||||
std::map<std::string, string_map> data;
|
||||
string_map column;
|
||||
|
||||
column["label"] = it;
|
||||
data.insert(std::make_pair("item", column));
|
||||
|
||||
list.add_row(data);
|
||||
}
|
||||
|
||||
if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
|
||||
list.select_row(index_);
|
||||
}
|
||||
|
||||
index_ = -1;
|
||||
}
|
||||
|
||||
void tsimple_item_selector::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() != twindow::OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "listbox", false);
|
||||
index_ = list.get_selected_row();
|
||||
}
|
||||
|
||||
}
|
60
src/gui/dialogs/simple_item_selector.hpp
Normal file
60
src/gui/dialogs/simple_item_selector.hpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* $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_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class tsimple_item_selector : public tdialog
|
||||
{
|
||||
public:
|
||||
typedef std::vector< std::string > list_type;
|
||||
typedef std::string item_type;
|
||||
|
||||
tsimple_item_selector(
|
||||
const std::string& title,
|
||||
const std::string& message,
|
||||
list_type const& items,
|
||||
bool title_uses_markup = false,
|
||||
bool message_uses_markup = false);
|
||||
|
||||
int selected_index() const { return index_; }
|
||||
void set_selected_index(int index) { index_ = index; }
|
||||
|
||||
private:
|
||||
int index_;
|
||||
|
||||
std::string title_, msg_;
|
||||
bool markup_title_, markup_msg_;
|
||||
list_type 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_SIMPLE_ITEM_SELECTOR_HPP_INCLUDED */
|
|
@ -37,6 +37,7 @@
|
|||
#include "gui/dialogs/wml_message.hpp"
|
||||
#include "gui/dialogs/gamestate_inspector.hpp"
|
||||
#include "gui/dialogs/data_manage.hpp"
|
||||
#include "gui/dialogs/simple_item_selector.hpp"
|
||||
#include "gui/dialogs/unit_create.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
@ -3312,12 +3313,15 @@ void console_handler::do_choose_level() {
|
|||
std::sort(options.begin(), options.end());
|
||||
int choice = 0;
|
||||
{
|
||||
gui::dialog menu(*menu_handler_.gui_, _("Choose Scenario (Debug!)"), "", gui::OK_CANCEL);
|
||||
menu.set_menu(options);
|
||||
menu.get_menu().move_selection(next);
|
||||
choice = menu.show();
|
||||
gui2::tsimple_item_selector dlg(_("Choose Scenario (Debug!)"), "", options);
|
||||
dlg.set_selected_index(next);
|
||||
dlg.show(menu_handler_.gui_->video());
|
||||
choice = dlg.selected_index();
|
||||
}
|
||||
|
||||
if(choice == -1)
|
||||
return;
|
||||
|
||||
if (size_t(choice) < options.size()) {
|
||||
menu_handler_.gamestate_.classification().next_scenario = options[choice];
|
||||
end_level_data &e = resources::controller->get_end_level_data();
|
||||
|
|
Loading…
Add table
Reference in a new issue