Dialogs with an input text are converted to the new dialogs.
This commit is contained in:
parent
d89ff98609
commit
937a349888
6 changed files with 210 additions and 6 deletions
|
@ -8,6 +8,7 @@ Version 1.5.8+svn:
|
|||
* User interface:
|
||||
* Hide the "Network Player" option for Local MP Games (bug #12596).
|
||||
* Potraits with an icon are TC'ed again.
|
||||
* Dialogs with an input text are converted to the new dialogs.
|
||||
* WML Engine:
|
||||
* Prevent duplicate id conflicts when cloning units with WML (bug #12894)
|
||||
* [time_area], in EventWML, can now accept comma-separated lists of area ids
|
||||
|
|
|
@ -296,6 +296,49 @@
|
|||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "input_caption"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[text_box]
|
||||
id = "input"
|
||||
definition = "default"
|
||||
[/text_box]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
@ -424,6 +467,49 @@
|
|||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "input_caption"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[text_box]
|
||||
id = "input"
|
||||
definition = "default"
|
||||
[/text_box]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
|
|
@ -14,6 +14,7 @@ Version 1.5.8+svn:
|
|||
* User interface
|
||||
* Disable the "Network Player" option when playing a non-networked MP
|
||||
game.
|
||||
* Dialogs with an input text are converted to the new dialogs.
|
||||
|
||||
Version 1.5.8:
|
||||
* Campaigns
|
||||
|
|
|
@ -2984,7 +2984,7 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
if (side_for_show && !get_replay_source().is_skipping())
|
||||
{
|
||||
// We whether we can show the new dialog.
|
||||
if(options.empty() && !has_text_input && speaker != units->end()) {
|
||||
if(options.empty() && speaker != units->end()) {
|
||||
|
||||
|
||||
// At the moment we use a hack if the image in portrait has
|
||||
|
@ -3015,18 +3015,42 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
image.erase(right_offset);
|
||||
}
|
||||
|
||||
// Parse input text, if not available all fields are empty
|
||||
const std::string text_input_label =
|
||||
text_input_element["label"];
|
||||
std::string text_input_content =
|
||||
text_input_element["text"];
|
||||
unsigned input_max_size =
|
||||
lexical_cast_default<unsigned>(
|
||||
text_input_element["max_length"], 256);
|
||||
if(input_max_size > 1024 || input_max_size < 1){
|
||||
lg::wml_error << "invalid maximum size for input "
|
||||
<< input_max_size<<"\n";
|
||||
input_max_size=256;
|
||||
}
|
||||
|
||||
const int dlg_result = gui2::show_wml_message(
|
||||
left_side,
|
||||
screen->video(),
|
||||
caption,
|
||||
cfg["message"],
|
||||
image,
|
||||
false);
|
||||
false,
|
||||
text_input_label,
|
||||
&text_input_content,
|
||||
input_max_size);
|
||||
|
||||
if(has_text_input) {
|
||||
recorder.text_input(text_input_content);
|
||||
text_input_result = text_input_content;
|
||||
}
|
||||
if(dlg_result == gui2::twindow::CANCEL) {
|
||||
handler.skip_messages() = true;
|
||||
}
|
||||
return;
|
||||
|
||||
// This goto skips the old dialog but makes sure the
|
||||
// options and text input are properly processed.
|
||||
goto outro;
|
||||
|
||||
/**
|
||||
* @todo enable portrait code in 1.7 and write a clean api.
|
||||
|
@ -3130,7 +3154,7 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
text_input_result = (*(action->get_children("input").front()))["text"];
|
||||
}
|
||||
}
|
||||
|
||||
outro:
|
||||
// Implement the consequences of the choice
|
||||
if(options.empty() == false) {
|
||||
if(size_t(option_chosen) >= menu_items.size()) {
|
||||
|
|
|
@ -16,10 +16,25 @@
|
|||
|
||||
#include "gui/dialogs/wml_message.hpp"
|
||||
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
void twml_message_::set_input(const std::string& caption,
|
||||
std::string* text, const unsigned maximum_length)
|
||||
{
|
||||
assert(!caption.empty());
|
||||
assert(text);
|
||||
|
||||
input_caption_ = caption;
|
||||
input_text_ = text;
|
||||
input_maximum_lenght_ = maximum_length;
|
||||
|
||||
set_auto_close(false);
|
||||
}
|
||||
|
||||
void twml_message_::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
// Inherited.
|
||||
|
@ -27,6 +42,36 @@ void twml_message_::pre_show(CVideo& video, twindow& window)
|
|||
|
||||
window.canvas(1).set_variable("portrait_image", variant(portrait_));
|
||||
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
|
||||
|
||||
// Find the input box related fields.
|
||||
tlabel* caption = dynamic_cast<tlabel*>(
|
||||
window.find_widget("input_caption", false));
|
||||
VALIDATE(caption, missing_widget("input_caption"));
|
||||
|
||||
ttext_box* input = dynamic_cast<ttext_box*>(
|
||||
window.find_widget("input", true));
|
||||
VALIDATE(input, missing_widget("input"));
|
||||
|
||||
if(has_input()) {
|
||||
caption->set_label(input_caption_);
|
||||
input->set_value(*input_text_);
|
||||
input->set_maximum_length(input_maximum_lenght_);
|
||||
window.keyboard_capture(input);
|
||||
} else {
|
||||
caption->set_visible(twidget::INVISIBLE);
|
||||
input->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
void twml_message_::post_show(twindow& window)
|
||||
{
|
||||
if(has_input()) {
|
||||
ttext_box* input = dynamic_cast<ttext_box*>(
|
||||
window.find_widget("input", true));
|
||||
VALIDATE(input, missing_widget("input"));
|
||||
|
||||
*input_text_ = input->get_value();
|
||||
}
|
||||
}
|
||||
|
||||
twindow* twml_message_left::build_window(CVideo& video)
|
||||
|
@ -44,7 +89,10 @@ int show_wml_message(const bool left_side
|
|||
, const std::string& title
|
||||
, const std::string& message
|
||||
, const std::string& portrait
|
||||
, const bool mirror)
|
||||
, const bool mirror
|
||||
, const std::string& input_caption
|
||||
, std::string* input_text
|
||||
, const unsigned maximum_length)
|
||||
{
|
||||
std::auto_ptr<twml_message_> dlg;
|
||||
if(left_side) {
|
||||
|
@ -53,6 +101,10 @@ int show_wml_message(const bool left_side
|
|||
dlg.reset(new twml_message_right(title, message, portrait, mirror));
|
||||
}
|
||||
assert(dlg.get());
|
||||
|
||||
if(!input_caption.empty()) {
|
||||
dlg->set_input(input_caption, input_text, maximum_length);
|
||||
}
|
||||
|
||||
dlg->show(video);
|
||||
return dlg->get_retval();
|
||||
|
|
|
@ -32,9 +32,23 @@ public:
|
|||
: tmessage(title, message, true)
|
||||
, portrait_(portrait)
|
||||
, mirror_(mirror)
|
||||
, input_caption_("")
|
||||
, input_text_(NULL)
|
||||
, input_maximum_lenght_(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the input text variables.
|
||||
*
|
||||
* @param caption The caption for the label.
|
||||
* @param text The initial text, after showing the final
|
||||
* text.
|
||||
* @param maximum_length The maximum length of the text.
|
||||
*/
|
||||
void set_input(const std::string& caption,
|
||||
std::string* text, const unsigned maximum_length);
|
||||
|
||||
private:
|
||||
|
||||
/** Filename of the portrait. */
|
||||
|
@ -43,6 +57,18 @@ private:
|
|||
/** Mirror the portrait? */
|
||||
bool mirror_;
|
||||
|
||||
/** The caption to show for the input text. */
|
||||
std::string input_caption_;
|
||||
|
||||
/** The text input. */
|
||||
std::string* input_text_;
|
||||
|
||||
/** The maximum length of the input text. */
|
||||
unsigned input_maximum_lenght_;
|
||||
|
||||
/** Does the dialog have an input text? */
|
||||
bool has_input() { return !input_caption_.empty(); }
|
||||
|
||||
/**
|
||||
* Inherited from tmessage.
|
||||
*
|
||||
|
@ -52,6 +78,9 @@ private:
|
|||
|
||||
/** Inherited from tmessage. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
};
|
||||
|
||||
/** Shows a dialog with the portrait on the left side. */
|
||||
|
@ -93,13 +122,24 @@ private:
|
|||
* @param message The message to show.
|
||||
* @param portrait Filename of the portrait.
|
||||
* @param mirror Does the portrait need to be mirrored?
|
||||
*
|
||||
* @param input_caption The caption for the optional input text
|
||||
* box. If this value != "" there is an input
|
||||
* and the input text parameter is mandatory.
|
||||
* @param input_text Pointer to the initial text value will be
|
||||
* set to the result.
|
||||
* @param maximum_length The maximum length of the text.
|
||||
*/
|
||||
int show_wml_message(const bool left_side
|
||||
, CVideo& video
|
||||
, const std::string& title
|
||||
, const std::string& message
|
||||
, const std::string& portrait
|
||||
, const bool mirror);
|
||||
, const bool mirror
|
||||
, const std::string& input_caption
|
||||
, std::string* input_text
|
||||
, const unsigned maximum_length);
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue