add gui.confirm(...)
This commit is contained in:
parent
e2f6c263e7
commit
7fce735ca1
@ -61,3 +61,21 @@ gui.escape_markup(
|
|||||||
```
|
```
|
||||||
|
|
||||||
Escapes markup in text.
|
Escapes markup in text.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
gui.confirm(
|
||||||
|
-- message (does not translate automatically, use gui.str(...))
|
||||||
|
message: str,
|
||||||
|
-- function called upon confirmation
|
||||||
|
on_confirm: function() -> nil,
|
||||||
|
-- function called upon denial/cancellation
|
||||||
|
[optional] on_deny: function() -> nil,
|
||||||
|
-- text for the confirmation button (default: "Yes")
|
||||||
|
-- use an empty string for the default value if you want to specify no_text.
|
||||||
|
[optional] yes_text: str,
|
||||||
|
-- text for the denial button (default: "No")
|
||||||
|
[optional] no_text: str,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Requests confirmation from the user for an action. **Does not** stop code execution.
|
||||||
|
|||||||
@ -58,3 +58,21 @@ gui.escape_markup(
|
|||||||
```
|
```
|
||||||
|
|
||||||
Экранирует разметку в тексте.
|
Экранирует разметку в тексте.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
gui.confirm(
|
||||||
|
-- сообщение (не переводится автоматически, используйте gui.str(...))
|
||||||
|
message: str,
|
||||||
|
-- функция, вызываемая при подтвержении
|
||||||
|
on_confirm: function() -> nil,
|
||||||
|
-- функция, вызываемая при отказе/отмене
|
||||||
|
[опционально] on_deny: function() -> nil,
|
||||||
|
-- текст кнопки подтвержения (по-умолчанию: "Да")
|
||||||
|
-- используйте пустую строку для значения по-умолчанию, если нужно указать no_text.
|
||||||
|
[опционально] yes_text: str,
|
||||||
|
-- текст кнопки отказа (по-умолчанию: "Нет")
|
||||||
|
[опционально] no_text: str,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрашивает у пользователя подтверждение действия. **Не** останавливает выполнение кода.
|
||||||
|
|||||||
@ -53,8 +53,10 @@ void guiutil::confirm(
|
|||||||
const std::shared_ptr<gui::Menu>& menu,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_confirm,
|
const runnable& on_confirm,
|
||||||
|
const runnable& on_deny,
|
||||||
std::wstring yestext,
|
std::wstring yestext,
|
||||||
std::wstring notext) {
|
std::wstring notext
|
||||||
|
) {
|
||||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||||
if (notext.empty()) notext = langs::get(L"No");
|
if (notext.empty()) notext = langs::get(L"No");
|
||||||
|
|
||||||
@ -71,6 +73,8 @@ void guiutil::confirm(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
subpanel->add(std::make_shared<Button>(notext, glm::vec4(8.f), [=](GUI*){
|
subpanel->add(std::make_shared<Button>(notext, glm::vec4(8.f), [=](GUI*){
|
||||||
|
if (on_deny)
|
||||||
|
on_deny();
|
||||||
menu->back();
|
menu->back();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ namespace guiutil {
|
|||||||
const std::shared_ptr<gui::Menu>& menu,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_confirm=nullptr,
|
const runnable& on_confirm=nullptr,
|
||||||
|
const runnable& on_deny=nullptr,
|
||||||
std::wstring yestext=L"",
|
std::wstring yestext=L"",
|
||||||
std::wstring notext=L"");
|
std::wstring notext=L"");
|
||||||
|
|
||||||
|
|||||||
@ -122,6 +122,7 @@ static void show_convert_request(
|
|||||||
engine.getGUI()->getMenu(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(message),
|
langs::get(message),
|
||||||
on_confirm,
|
on_confirm,
|
||||||
|
nullptr,
|
||||||
L"",
|
L"",
|
||||||
langs::get(L"Cancel")
|
langs::get(L"Cancel")
|
||||||
);
|
);
|
||||||
|
|||||||
@ -759,6 +759,34 @@ static int l_gui_escape_markup(lua::State* L) {
|
|||||||
return lua::pushstring(L, text);
|
return lua::pushstring(L, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_gui_confirm(lua::State* L) {
|
||||||
|
auto question = lua::require_wstring(L, 1);
|
||||||
|
lua::pushvalue(L, 2);
|
||||||
|
auto onconfirm = lua::create_runnable(L);
|
||||||
|
runnable ondeny = nullptr;
|
||||||
|
if (lua::gettop(L) > 2) {
|
||||||
|
lua::pushvalue(L, 3);
|
||||||
|
ondeny = lua::create_runnable(L);
|
||||||
|
}
|
||||||
|
std::wstring yestext = L"";
|
||||||
|
if (lua::gettop(L) > 3) {
|
||||||
|
yestext = lua::require_wstring(L, 4);
|
||||||
|
}
|
||||||
|
std::wstring notext = L"";
|
||||||
|
if (lua::gettop(L) > 4) {
|
||||||
|
notext = lua::require_wstring(L, 5);
|
||||||
|
}
|
||||||
|
guiutil::confirm(
|
||||||
|
engine->getGUI()->getMenu(),
|
||||||
|
question,
|
||||||
|
onconfirm,
|
||||||
|
ondeny,
|
||||||
|
yestext,
|
||||||
|
notext
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg guilib[] = {
|
const luaL_Reg guilib[] = {
|
||||||
{"get_viewport", lua::wrap<l_gui_getviewport>},
|
{"get_viewport", lua::wrap<l_gui_getviewport>},
|
||||||
{"getattr", lua::wrap<l_gui_getattr>},
|
{"getattr", lua::wrap<l_gui_getattr>},
|
||||||
@ -768,6 +796,7 @@ const luaL_Reg guilib[] = {
|
|||||||
{"get_locales_info", lua::wrap<l_gui_get_locales_info>},
|
{"get_locales_info", lua::wrap<l_gui_get_locales_info>},
|
||||||
{"clear_markup", lua::wrap<l_gui_clear_markup>},
|
{"clear_markup", lua::wrap<l_gui_clear_markup>},
|
||||||
{"escape_markup", lua::wrap<l_gui_escape_markup>},
|
{"escape_markup", lua::wrap<l_gui_escape_markup>},
|
||||||
|
{"confirm", lua::wrap<l_gui_confirm>},
|
||||||
{"__reindex", lua::wrap<l_gui_reindex>},
|
{"__reindex", lua::wrap<l_gui_reindex>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user