Ported the options messages to the new dialog.
The background of the listbox is still a bit ugly. Also the escape key hasn't been disabled yet.
This commit is contained in:
parent
3ff245d713
commit
0d66f0b154
4 changed files with 161 additions and 5 deletions
|
@ -343,6 +343,43 @@
|
|||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[listbox]
|
||||
id = "input_list"
|
||||
definition = "default"
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_button]
|
||||
definition = "listbox_text"
|
||||
|
||||
return_value = -1
|
||||
[/toggle_button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/list_definition]
|
||||
|
||||
[/listbox]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
@ -514,6 +551,43 @@
|
|||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[listbox]
|
||||
id = "input_list"
|
||||
definition = "default"
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_button]
|
||||
definition = "listbox_text"
|
||||
|
||||
return_value = -1
|
||||
[/toggle_button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/list_definition]
|
||||
|
||||
[/listbox]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
|
|
@ -2998,7 +2998,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() && speaker != units->end()) {
|
||||
if(speaker != units->end()) {
|
||||
|
||||
|
||||
// At the moment we use a hack if the image in portrait has
|
||||
|
@ -3043,6 +3043,7 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
input_max_size=256;
|
||||
}
|
||||
|
||||
option_chosen = 0; // can be initialized to 0 at the top later.
|
||||
const int dlg_result = gui2::show_wml_message(
|
||||
left_side,
|
||||
screen->video(),
|
||||
|
@ -3052,8 +3053,13 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
false,
|
||||
text_input_label,
|
||||
&text_input_content,
|
||||
input_max_size);
|
||||
input_max_size,
|
||||
options,
|
||||
&option_chosen);
|
||||
|
||||
if(!options.empty()) {
|
||||
recorder.choose_option(option_chosen);
|
||||
}
|
||||
if(has_text_input) {
|
||||
recorder.text_input(text_input_content);
|
||||
text_input_result = text_input_content;
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
#include "gui/dialogs/wml_message.hpp"
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
|
@ -35,6 +37,18 @@ void twml_message_::set_input(const std::string& caption,
|
|||
set_auto_close(false);
|
||||
}
|
||||
|
||||
void twml_message_::set_option_list(
|
||||
const std::vector<std::string>& option_list, int* choosen_option)
|
||||
{
|
||||
assert(!option_list.empty());
|
||||
assert(choosen_option);
|
||||
|
||||
option_list_ = option_list;
|
||||
chosen_option_ = choosen_option;
|
||||
|
||||
set_auto_close(false);
|
||||
}
|
||||
|
||||
void twml_message_::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
// Inherited.
|
||||
|
@ -62,6 +76,36 @@ void twml_message_::pre_show(CVideo& video, twindow& window)
|
|||
caption->set_visible(twidget::INVISIBLE);
|
||||
input->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
|
||||
// Find the option list related fields.
|
||||
tlistbox* options = dynamic_cast<tlistbox*>(
|
||||
window.find_widget("input_list", true));
|
||||
VALIDATE(options, missing_widget("input_list"));
|
||||
|
||||
if(!option_list_.empty()) {
|
||||
string_map row_data;
|
||||
foreach(const std::string& option, option_list_) {
|
||||
row_data["label"] = option;
|
||||
options->add_row(row_data);
|
||||
}
|
||||
// Avoid negetive and 0 since item 0 is already selected.
|
||||
if(*chosen_option_ > 0
|
||||
&& static_cast<size_t>(*chosen_option_)
|
||||
< option_list_.size()) {
|
||||
|
||||
options->select_row(*chosen_option_);
|
||||
}
|
||||
|
||||
if(!has_input()) {
|
||||
window.keyboard_capture(options);
|
||||
window.set_easy_close(false);
|
||||
} else {
|
||||
window.add_to_keyboard_chain(options);
|
||||
// easy_close has been disabled due to the input.
|
||||
}
|
||||
} else {
|
||||
options->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
void twml_message_::post_show(twindow& window)
|
||||
|
@ -73,6 +117,14 @@ void twml_message_::post_show(twindow& window)
|
|||
|
||||
*input_text_ = input->get_value();
|
||||
}
|
||||
|
||||
if(!option_list_.empty()) {
|
||||
tlistbox* options = dynamic_cast<tlistbox*>(
|
||||
window.find_widget("input_list", true));
|
||||
VALIDATE(options, missing_widget("input_list"));
|
||||
|
||||
*chosen_option_ = options->get_selected_row();
|
||||
}
|
||||
}
|
||||
|
||||
twindow* twml_message_left::build_window(CVideo& video)
|
||||
|
@ -93,7 +145,9 @@ int show_wml_message(const bool left_side
|
|||
, const bool mirror
|
||||
, const std::string& input_caption
|
||||
, std::string* input_text
|
||||
, const unsigned maximum_length)
|
||||
, const unsigned maximum_length
|
||||
, const std::vector<std::string>& option_list
|
||||
, int* chosen_option)
|
||||
{
|
||||
std::auto_ptr<twml_message_> dlg;
|
||||
if(left_side) {
|
||||
|
@ -106,6 +160,10 @@ int show_wml_message(const bool left_side
|
|||
if(!input_caption.empty()) {
|
||||
dlg->set_input(input_caption, input_text, maximum_length);
|
||||
}
|
||||
|
||||
if(!option_list.empty()) {
|
||||
dlg->set_option_list(option_list, chosen_option);
|
||||
}
|
||||
|
||||
dlg->show(video);
|
||||
return dlg->get_retval();
|
||||
|
|
|
@ -34,7 +34,9 @@ public:
|
|||
, mirror_(mirror)
|
||||
, input_caption_("")
|
||||
, input_text_(NULL)
|
||||
, input_maximum_lenght_(0)
|
||||
, input_maximum_lenght_(0)
|
||||
, option_list_()
|
||||
, chosen_option_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,6 +51,9 @@ public:
|
|||
void set_input(const std::string& caption,
|
||||
std::string* text, const unsigned maximum_length);
|
||||
|
||||
void set_option_list(
|
||||
const std::vector<std::string>& option_list, int* choosen_option);
|
||||
|
||||
private:
|
||||
|
||||
/** Filename of the portrait. */
|
||||
|
@ -66,6 +71,12 @@ private:
|
|||
/** The maximum length of the input text. */
|
||||
unsigned input_maximum_lenght_;
|
||||
|
||||
/** The list of options the user can choose. */
|
||||
std::vector<std::string> option_list_;
|
||||
|
||||
/** The chosen option. */
|
||||
int *chosen_option_;
|
||||
|
||||
/** Does the dialog have an input text? */
|
||||
bool has_input() { return !input_caption_.empty(); }
|
||||
|
||||
|
@ -129,6 +140,11 @@ private:
|
|||
* @param input_text Pointer to the initial text value will be
|
||||
* set to the result.
|
||||
* @param maximum_length The maximum length of the text.
|
||||
*
|
||||
* @param option_list A list of options to select in the dialog.
|
||||
* @param chosen_option Pointer to the initially chosen option.
|
||||
* Will be set to the chosen_option when the
|
||||
* dialog closes.
|
||||
*/
|
||||
int show_wml_message(const bool left_side
|
||||
, CVideo& video
|
||||
|
@ -138,7 +154,9 @@ int show_wml_message(const bool left_side
|
|||
, const bool mirror
|
||||
, const std::string& input_caption
|
||||
, std::string* input_text
|
||||
, const unsigned maximum_length);
|
||||
, const unsigned maximum_length
|
||||
, const std::vector<std::string>& option_list
|
||||
, int* chosen_option);
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
|
Loading…
Add table
Reference in a new issue