gui2/trename_unit: Implement new GUI2 Rename Unit dialog

This is probably the simplest GUI2 dialog I've ever implemented.
This commit is contained in:
Ignacio R. Morelle 2013-03-26 21:26:05 -03:00
parent 17414644c1
commit 66efdbab26
6 changed files with 309 additions and 0 deletions

View File

@ -0,0 +1,151 @@
#textdomain wesnoth-lib
###
### Definition of the window to rename in-game units.
###
[window]
id = "rename_unit"
description = "In-game unit rename action dialog."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
maximum_width = 800
[tooltip]
id = "tooltip_large"
[/tooltip]
[helptip]
id = "tooltip_large"
[/helptip]
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
label = _ "Rename Unit"
[/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 = _ "Name:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "name"
definition = "default"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
horizontal_alignment = "right"
[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]

View File

@ -8754,6 +8754,62 @@
RelativePath="..\..\src\gui\dialogs\popup.hpp"
>
</File>
<File
RelativePath="..\..\src\gui\dialogs\rename_unit.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_with_VLD|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDEBUG|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\gui\dialogs\rename_unit.hpp"
>
</File>
<File
RelativePath="..\..\src\gui\dialogs\simple_item_selector.cpp"
>

View File

@ -744,6 +744,7 @@ set(wesnoth-main_SRC
gui/dialogs/mp_method_selection.cpp
gui/dialogs/network_transmission.cpp
gui/dialogs/popup.cpp
gui/dialogs/rename_unit.cpp
gui/dialogs/simple_item_selector.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/transient_message.cpp

View File

@ -372,6 +372,7 @@ wesnoth_sources = Split("""
gui/dialogs/mp_method_selection.cpp
gui/dialogs/network_transmission.cpp
gui/dialogs/popup.cpp
gui/dialogs/rename_unit.cpp
gui/dialogs/simple_item_selector.cpp
gui/dialogs/tip.cpp
gui/dialogs/title_screen.cpp

View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2013 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/rename_unit.hpp"
#include "gui/widgets/settings.hpp"
namespace gui2 {
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_rename_unit
*
* == Rename unit ==
*
* Dialog for renaming units in-game.
*
* @begin{table}{dialog_widgets}
*
* name & & text_box & m &
* Input field for the unit name. $
*
* @end{table}
*/
REGISTER_DIALOG(rename_unit)
trename_unit::trename_unit(std::string& name)
{
register_text("name", true, name, true);
}
}

View File

@ -0,0 +1,54 @@
/*
Copyright (C) 2013 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_RENAME_UNIT_INCLUDED
#define GUI_DIALOGS_RENAME_UNIT_INCLUDED
#include "gui/dialogs/dialog.hpp"
namespace gui2 {
class trename_unit : public tdialog
{
public:
/**
* Constructor.
*
* @param name [in] The initial value of the unit name.
* @param name [out] The new unit name the user entered if the dialog
* returns @ref twindow::OK, undefined otherise.
*/
trename_unit(std::string& name);
/**
* Executes the dialog.
* See @ref tdialog for more information.
*
* @param name [in] The initial value of the unit name.
* @param name [out] The new unit name the user entered if this method
* returns @a true, undefined otherwise.
*/
static bool execute(std::string& name, CVideo& video)
{
return trename_unit(name).show(video);
}
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
};
}
#endif /* ! GUI_DIALOGS_RENAME_UNIT_INCLUDED */