Add wesnoth.show_message_box function
This commit is contained in:
parent
b6eedd3df6
commit
cef3e0d266
5 changed files with 56 additions and 6 deletions
|
@ -79,6 +79,7 @@ void message::pre_show(window& window)
|
|||
styled_widget& title_widget = find_widget<label>(&window, "title", false);
|
||||
if(!title_.empty()) {
|
||||
title_widget.set_label(title_);
|
||||
title_widget.set_use_markup(title_use_markup_);
|
||||
} else {
|
||||
title_widget.set_visible(widget::visibility::invisible);
|
||||
}
|
||||
|
@ -153,9 +154,10 @@ void show_message(CVideo& video,
|
|||
const std::string& msg,
|
||||
const std::string& button_caption,
|
||||
const bool auto_close,
|
||||
const bool message_use_markup)
|
||||
const bool message_use_markup,
|
||||
const bool title_use_markup)
|
||||
{
|
||||
message dlg(title, msg, auto_close, message_use_markup);
|
||||
message dlg(title, msg, auto_close, message_use_markup, title_use_markup);
|
||||
dlg.set_button_caption(message::ok, button_caption);
|
||||
dlg.show(video);
|
||||
}
|
||||
|
@ -165,12 +167,13 @@ int show_message(CVideo& video,
|
|||
const std::string& msg,
|
||||
const message::button_style button_style,
|
||||
bool message_use_markup,
|
||||
bool /*message_title_mode*/)
|
||||
bool title_use_markup)
|
||||
{
|
||||
message dlg(title,
|
||||
msg,
|
||||
button_style == message::auto_close,
|
||||
message_use_markup);
|
||||
message_use_markup,
|
||||
title_use_markup);
|
||||
|
||||
switch(button_style) {
|
||||
case message::auto_close:
|
||||
|
|
|
@ -40,12 +40,14 @@ public:
|
|||
message(const std::string& title,
|
||||
const std::string& message,
|
||||
const bool auto_close,
|
||||
const bool message_use_markup)
|
||||
const bool message_use_markup,
|
||||
const bool title_use_markup)
|
||||
: title_(title)
|
||||
, image_()
|
||||
, message_(message)
|
||||
, auto_close_(auto_close)
|
||||
, message_use_markup_(message_use_markup)
|
||||
, title_use_markup_(title_use_markup)
|
||||
, buttons_(count)
|
||||
{
|
||||
}
|
||||
|
@ -138,6 +140,9 @@ private:
|
|||
/** Whether to enable formatting markup for the dialog message. */
|
||||
bool message_use_markup_;
|
||||
|
||||
/** Whether to enable formatting markup for the dialog title. */
|
||||
bool title_use_markup_;
|
||||
|
||||
struct button_status
|
||||
{
|
||||
button_status();
|
||||
|
@ -169,13 +174,16 @@ private:
|
|||
* @param auto_close When true the window will hide the ok button
|
||||
* when the message doesn't need a scrollbar to
|
||||
* show itself.
|
||||
* @param message_use_markup Use markup for the message?
|
||||
* @param title_use_markup Use markup for the title?
|
||||
*/
|
||||
void show_message(CVideo& video,
|
||||
const std::string& title,
|
||||
const std::string& message,
|
||||
const std::string& button_caption = "",
|
||||
const bool auto_close = true,
|
||||
const bool message_use_markup = false);
|
||||
const bool message_use_markup = false,
|
||||
const bool title_use_markup = false);
|
||||
|
||||
/**
|
||||
* Shows a message to the user.
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "gui/dialogs/wml_message.hpp"
|
||||
#include "gui/dialogs/story_viewer.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/widgets/clickable_item.hpp"
|
||||
#include "gui/widgets/styled_widget.hpp"
|
||||
#include "gui/widgets/multi_page.hpp"
|
||||
|
@ -62,6 +63,7 @@
|
|||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "lua/lauxlib.h" // for luaL_checkinteger, etc
|
||||
#include "lua/lua.h" // for lua_setfield, etc
|
||||
|
@ -427,6 +429,41 @@ int show_menu(lua_State* L, CVideo& video) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a simple message box.
|
||||
*/
|
||||
int show_message_box(lua_State* L, CVideo& video) {
|
||||
const std::string title = luaL_checkstring(L, 1), message = luaL_checkstring(L, 2);
|
||||
std::string button = luaL_optstring(L, 3, "ok");
|
||||
std::transform(button.begin(), button.end(), button.begin(), std::tolower);
|
||||
bool markup = lua_isnoneornil(L, 3) ? luaW_toboolean(L, 3) : luaW_toboolean(L, 4);
|
||||
using button_style = gui2::dialogs::message::button_style;
|
||||
boost::optional<button_style> style;
|
||||
if(button.empty()) {
|
||||
style = button_style::auto_close;
|
||||
} else if(button == "ok") {
|
||||
style = button_style::ok_button;
|
||||
} else if(button == "close") {
|
||||
style = button_style::close_button;
|
||||
} else if(button == "ok_cancel") {
|
||||
style = button_style::ok_cancel_buttons;
|
||||
} else if(button == "cancel") {
|
||||
style = button_style::cancel_button;
|
||||
} else if(button == "yes_no") {
|
||||
style = button_style::yes_no_buttons;
|
||||
}
|
||||
if(style) {
|
||||
int result = gui2::show_message(video, title, message, *style, markup, markup);
|
||||
if(style == button_style::ok_cancel_buttons || style == button_style::yes_no_buttons) {
|
||||
lua_pushboolean(L, result == gui2::window::OK);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
gui2::show_message(video, title, message, button, false, markup, markup);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a widget on the current dialog.
|
||||
* - Arg 1: scalar.
|
||||
|
|
|
@ -39,6 +39,7 @@ int show_message_dialog(lua_State *L, CVideo & video);
|
|||
int show_popup_dialog(lua_State *L, CVideo & video);
|
||||
int show_menu(lua_State* L, CVideo& video);
|
||||
int show_story(lua_State* L, CVideo& video);
|
||||
int show_message_box(lua_State* L, CVideo& video);
|
||||
int show_lua_console(lua_State*L, CVideo & video, lua_kernel_base * lk);
|
||||
int show_gamestate_inspector(CVideo& video, const vconfig& cfg, const game_data& data, const game_state& state);
|
||||
int intf_remove_dialog_item(lua_State *L);
|
||||
|
|
|
@ -368,6 +368,7 @@ lua_kernel_base::lua_kernel_base()
|
|||
{ "show_message_dialog", &video_dispatch<lua_gui2::show_message_dialog> },
|
||||
{ "show_popup_dialog", &video_dispatch<lua_gui2::show_popup_dialog> },
|
||||
{ "show_story", &video_dispatch<lua_gui2::show_story> },
|
||||
{ "show_message_box", &video_dispatch<lua_gui2::show_message_box> },
|
||||
{ "show_lua_console", &dispatch<&lua_kernel_base::intf_show_lua_console> },
|
||||
{ "compile_formula", &lua_formula_bridge::intf_compile_formula},
|
||||
{ "eval_formula", &lua_formula_bridge::intf_eval_formula},
|
||||
|
|
Loading…
Add table
Reference in a new issue