Convert the gamemap label editor dialog to GUI2 adding a new dialog class

This commit is contained in:
Ignacio R. Morelle 2010-11-07 13:57:42 +00:00
parent 6bea1c8904
commit 1f16bd7f7a
7 changed files with 296 additions and 8 deletions

View file

@ -0,0 +1,161 @@
#textdomain wesnoth-lib
###
### Definition of the window to place and edit gamemap labels
###
[window]
id = "edit_label"
description = "Map label editor."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
label = _ "Place Label"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 1
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Label:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "label"
definition = "default"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[toggle_button]
id = "team_only_toggle"
definition = "default"
label= _ "Team only"
[/toggle_button]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 0
{GUI_FILLER}
[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]

View file

@ -404,6 +404,7 @@ set(wesnoth-main_SRC
gui/dialogs/campaign_selection.cpp
gui/dialogs/data_manage.cpp
gui/dialogs/dialog.cpp
gui/dialogs/edit_label.cpp
gui/dialogs/formula_debugger.cpp
gui/dialogs/game_load.cpp
gui/dialogs/game_delete.cpp

View file

@ -174,6 +174,7 @@ wesnoth_source = \
gui/dialogs/campaign_selection.cpp \
gui/dialogs/data_manage.cpp \
gui/dialogs/dialog.cpp \
gui/dialogs/edit_label.cpp \
gui/dialogs/formula_debugger.cpp \
gui/dialogs/game_load.cpp \
gui/dialogs/game_delete.cpp \

View file

@ -343,6 +343,7 @@ wesnoth_sources = Split("""
gui/dialogs/campaign_selection.cpp
gui/dialogs/data_manage.cpp
gui/dialogs/dialog.cpp
gui/dialogs/edit_label.cpp
gui/dialogs/formula_debugger.cpp
gui/dialogs/game_load.cpp
gui/dialogs/game_delete.cpp

View file

@ -0,0 +1,55 @@
/* $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/edit_label.hpp"
#include "gui/dialogs/field.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
namespace gui2 {
REGISTER_WINDOW(edit_label)
tedit_label::tedit_label(const std::string& label, bool team_only)
: team_only_(team_only)
, label_(label)
, label_field_(register_text("label", false))
{
}
void tedit_label::pre_show(CVideo& /*video*/, twindow& window)
{
assert(label_field_);
find_widget<ttoggle_button>(&window, "team_only_toggle", false).set_value(team_only_);
label_field_->set_widget_value(window, label_);
window.keyboard_capture(label_field_->widget(window));
}
void tedit_label::post_show(twindow& window)
{
if(get_retval() != twindow::OK) {
return;
}
label_ = label_field_->get_widget_value(window);
}
}

View file

@ -0,0 +1,65 @@
/* $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_EDIT_LABEL_HPP_INCLUDED
#define GUI_DIALOGS_EDIT_LABEL_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "gui/dialogs/field-fwd.hpp"
#include <vector>
namespace gui2 {
class tedit_label : public tdialog
{
public:
tedit_label(const std::string& label, bool team_only = true);
const std::string& label() const {
return label_;
}
void set_label(const std::string& label) {
label_ = label;
}
bool team_only() const {
return team_only_;
}
void set_team_only(bool team_only) {
team_only_ = team_only;
}
private:
bool team_only_;
std::string label_;
tfield_text* label_field_;
/** 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_EDIT_LABEL_INCLUDED */

View file

@ -32,6 +32,7 @@
#include "game_events.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/dialogs/edit_label.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/dialogs/wml_message.hpp"
@ -1616,27 +1617,30 @@ void menu_handler::label_terrain(mouse_handler& mousehandler, bool team_only)
if (map_.on_board(loc) == false) {
return;
}
gui::dialog d(*gui_, _("Place Label"), "", gui::OK_CANCEL);
const terrain_label* old_label = gui_->labels().get_label(loc);
d.set_textbox(_("Label: "), (old_label ? old_label->text() : ""), map_labels::get_max_chars());
d.add_option(_("Team only"), team_only, gui::dialog::BUTTON_CHECKBOX_LEFT);
if(!d.show()) {
const terrain_label* old_label = gui_->labels().get_label(loc);
std::string label = old_label ? old_label->text() : "";
gui2::tedit_label d(label, team_only);
d.show(gui_->video());
if(d.get_retval() != gui2::twindow::CANCEL) {
std::string team_name;
SDL_Color color = font::LABEL_COLOR;
if (d.option_checked()) {
label = d.label();
if (d.team_only()) {
team_name = gui_->labels().team_name();
} else {
color = int_to_color(team::get_side_rgb(gui_->viewing_side()));
}
const std::string& old_team_name = old_label ? old_label->team_name() : "";
// remove the old label if we changed the team_name
if (d.option_checked() == (old_team_name == "")) {
if (d.team_only() == (old_team_name == "")) {
const terrain_label* old = gui_->labels().set_label(loc, "", old_team_name, color);
if (old) recorder.add_label(old);
}
const terrain_label* res = gui_->labels().set_label(loc, d.textbox_text(), team_name, color);
const terrain_label* res = gui_->labels().set_label(loc, label, team_name, color);
if (res)
recorder.add_label(res);
}