Add a helper function to show wml messages.
This way the code can be kept a bit more clean and is easier to extend for the future.
This commit is contained in:
parent
ce49173888
commit
4827a78055
3 changed files with 44 additions and 17 deletions
|
@ -3010,31 +3010,20 @@ std::string get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
}
|
||||
|
||||
const size_t right_offset = image.find("~RIGHT()");
|
||||
if(right_offset != std::string::npos) {
|
||||
const bool left_side = (right_offset == std::string::npos);
|
||||
if(!left_side) {
|
||||
image.erase(right_offset);
|
||||
|
||||
gui2::twml_message_right dlg(
|
||||
caption,
|
||||
cfg["message"],
|
||||
image,
|
||||
false);
|
||||
|
||||
dlg.show(screen->video());
|
||||
if(dlg.get_retval() == gui2::twindow::CANCEL) {
|
||||
handler.skip_messages() = true;
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
gui2::twml_message_left dlg(
|
||||
const int dlg_result = gui2::show_wml_message(
|
||||
left_side,
|
||||
screen->video(),
|
||||
caption,
|
||||
cfg["message"],
|
||||
image,
|
||||
false);
|
||||
|
||||
dlg.show(screen->video());
|
||||
if(dlg.get_retval() == gui2::twindow::CANCEL) {
|
||||
if(dlg_result == gui2::twindow::CANCEL) {
|
||||
handler.skip_messages() = true;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -39,5 +39,24 @@ twindow* twml_message_right::build_window(CVideo& video)
|
|||
return build(video, get_id(WML_MESSAGE_RIGHT));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::auto_ptr<twml_message_> dlg;
|
||||
if(left_side) {
|
||||
dlg.reset(new twml_message_left(title, message, portrait, mirror));
|
||||
} else {
|
||||
dlg.reset(new twml_message_right(title, message, portrait, mirror));
|
||||
}
|
||||
assert(dlg.get());
|
||||
|
||||
dlg->show(video);
|
||||
return dlg->get_retval();
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -82,6 +82,25 @@ private:
|
|||
twindow* build_window(CVideo& video);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to show a portrait.
|
||||
*
|
||||
* @param left_side If true the portrait is shown on the left,
|
||||
* on the right side otherwise.
|
||||
* @param video The display variable.
|
||||
* @param title The title of the dialog.
|
||||
* @param message The message to show.
|
||||
* @param portrait Filename of the portrait.
|
||||
* @param mirror Does the portrait need to be mirrored?
|
||||
*/
|
||||
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);
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue