mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Add allow_close[]
element to formspecs (#15971)
This commit is contained in:
parent
04e82749db
commit
fd85737460
9 changed files with 71 additions and 44 deletions
|
@ -1050,10 +1050,6 @@ void Game::shutdown()
|
|||
if (g_touchcontrols)
|
||||
g_touchcontrols->hide();
|
||||
|
||||
// only if the shutdown progress bar isn't shown yet
|
||||
if (m_shutdown_progress == 0.0f)
|
||||
showOverlayMessage(N_("Shutting down..."), 0, 0);
|
||||
|
||||
clouds.reset();
|
||||
|
||||
gui_chat_console.reset();
|
||||
|
@ -1065,6 +1061,10 @@ void Game::shutdown()
|
|||
g_menumgr.deleteFront();
|
||||
}
|
||||
|
||||
// only if the shutdown progress bar isn't shown yet
|
||||
if (m_shutdown_progress == 0.0f)
|
||||
showOverlayMessage(N_("Shutting down..."), 0, 0);
|
||||
|
||||
chat_backend->addMessage(L"", L"# Disconnected.");
|
||||
chat_backend->addMessage(L"", L"");
|
||||
|
||||
|
|
|
@ -205,6 +205,9 @@ void GameFormSpec::init(Client *client, RenderingEngine *rendering_engine, Input
|
|||
m_input = input;
|
||||
m_pause_script = std::make_unique<PauseMenuScripting>(client);
|
||||
m_pause_script->loadBuiltin();
|
||||
|
||||
// Make sure any remaining game callback requests are cleared out.
|
||||
*g_gamecallback = MainGameCallback();
|
||||
}
|
||||
|
||||
void GameFormSpec::deleteFormspec()
|
||||
|
|
|
@ -148,6 +148,10 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
|||
}
|
||||
fullscreen_is_down = event.KeyInput.PressedDown;
|
||||
return true;
|
||||
} else if (keyCode == EscapeKey &&
|
||||
event.KeyInput.PressedDown && event.KeyInput.Control) {
|
||||
g_gamecallback->disconnect();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||
"",
|
||||
false);
|
||||
|
||||
m_menu->allowClose(false);
|
||||
m_menu->defaultAllowClose(false);
|
||||
m_menu->lockSize(true,v2u32(800,600));
|
||||
|
||||
// Initialize scripting
|
||||
|
|
|
@ -105,7 +105,6 @@ GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
|||
current_keys_pending.key_down = false;
|
||||
current_keys_pending.key_up = false;
|
||||
current_keys_pending.key_enter = false;
|
||||
current_keys_pending.key_escape = false;
|
||||
|
||||
m_tooltip_show_delay = (u32)g_settings->getS32("tooltip_show_delay");
|
||||
m_tooltip_append_itemname = g_settings->getBool("tooltip_append_itemname");
|
||||
|
@ -2833,6 +2832,11 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
|
|||
m_fields.push_back(spec);
|
||||
}
|
||||
|
||||
void GUIFormSpecMenu::parseAllowClose(parserData *data, const std::string &element)
|
||||
{
|
||||
m_allowclose = is_yes(element);
|
||||
}
|
||||
|
||||
void GUIFormSpecMenu::removeAll()
|
||||
{
|
||||
// Remove children
|
||||
|
@ -2901,6 +2905,7 @@ const std::unordered_map<std::string, std::function<void(GUIFormSpecMenu*, GUIFo
|
|||
{"scroll_container_end", &GUIFormSpecMenu::parseScrollContainerEnd},
|
||||
{"set_focus", &GUIFormSpecMenu::parseSetFocus},
|
||||
{"model", &GUIFormSpecMenu::parseModel},
|
||||
{"allow_close", &GUIFormSpecMenu::parseAllowClose},
|
||||
};
|
||||
|
||||
|
||||
|
@ -3003,6 +3008,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
field_close_on_enter.clear();
|
||||
m_dropdown_index_event.clear();
|
||||
|
||||
m_allowclose = m_default_allowclose;
|
||||
m_bgnonfullscreen = true;
|
||||
m_bgfullscreen = false;
|
||||
|
||||
|
@ -3788,12 +3794,12 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
|
|||
|
||||
if (quitmode == quit_mode_accept) {
|
||||
fields["quit"] = "true";
|
||||
}
|
||||
|
||||
if (quitmode == quit_mode_cancel) {
|
||||
} else if (quitmode == quit_mode_cancel) {
|
||||
fields["quit"] = "true";
|
||||
m_text_dst->gotText(fields);
|
||||
return;
|
||||
} else if (quitmode == quit_mode_try) {
|
||||
fields["try_quit"] = "true";
|
||||
}
|
||||
|
||||
if (current_keys_pending.key_down) {
|
||||
|
@ -3816,11 +3822,6 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
|
|||
current_field_enter_pending.clear();
|
||||
}
|
||||
|
||||
if (current_keys_pending.key_escape) {
|
||||
fields["key_escape"] = "true";
|
||||
current_keys_pending.key_escape = false;
|
||||
}
|
||||
|
||||
for (const GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
||||
if (s.send) {
|
||||
std::string name = s.fname;
|
||||
|
@ -3997,6 +3998,8 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|||
if (m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
} else {
|
||||
acceptInput(quit_mode_try);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4013,6 +4016,7 @@ void GUIFormSpecMenu::tryClose()
|
|||
acceptInput(quit_mode_cancel);
|
||||
quitMenu();
|
||||
} else {
|
||||
acceptInput(quit_mode_try);
|
||||
m_text_dst->gotText(L"MenuQuit");
|
||||
}
|
||||
}
|
||||
|
@ -4059,9 +4063,13 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||
FATAL_ERROR("Reached a source line that can't ever been reached");
|
||||
break;
|
||||
}
|
||||
if (current_keys_pending.key_enter && m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
if (current_keys_pending.key_enter) {
|
||||
if (m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
} else {
|
||||
acceptInput(quit_mode_try);
|
||||
}
|
||||
} else {
|
||||
acceptInput();
|
||||
}
|
||||
|
@ -4806,14 +4814,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||
s32 caller_id = event.GUIEvent.Caller->getID();
|
||||
|
||||
if (caller_id == 257) {
|
||||
if (m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
} else {
|
||||
acceptInput();
|
||||
m_text_dst->gotText(L"ExitButton");
|
||||
}
|
||||
// quitMenu deallocates menu
|
||||
acceptInput(quit_mode_accept);
|
||||
m_text_dst->gotText(L"ExitButton");
|
||||
quitMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4842,12 +4845,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||
}
|
||||
|
||||
if (s.is_exit) {
|
||||
if (m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
} else {
|
||||
m_text_dst->gotText(L"ExitButton");
|
||||
}
|
||||
acceptInput(quit_mode_accept);
|
||||
m_text_dst->gotText(L"ExitButton");
|
||||
quitMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4910,15 +4910,18 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
if (m_allowclose && close_on_enter) {
|
||||
current_keys_pending.key_enter = true;
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
current_keys_pending.key_enter = true;
|
||||
|
||||
if (close_on_enter) {
|
||||
if (m_allowclose) {
|
||||
acceptInput(quit_mode_accept);
|
||||
quitMenu();
|
||||
} else {
|
||||
acceptInput(quit_mode_try);
|
||||
}
|
||||
} else {
|
||||
current_keys_pending.key_enter = true;
|
||||
acceptInput();
|
||||
}
|
||||
// quitMenu deallocates menu
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ enum FormspecFieldType {
|
|||
enum FormspecQuitMode {
|
||||
quit_mode_no,
|
||||
quit_mode_accept,
|
||||
quit_mode_cancel
|
||||
quit_mode_cancel,
|
||||
quit_mode_try,
|
||||
};
|
||||
|
||||
enum ButtonEventType : u8
|
||||
|
@ -203,9 +204,9 @@ public:
|
|||
m_text_dst = text_dst;
|
||||
}
|
||||
|
||||
void allowClose(bool value)
|
||||
void defaultAllowClose(bool value)
|
||||
{
|
||||
m_allowclose = value;
|
||||
m_default_allowclose = value;
|
||||
}
|
||||
|
||||
void setDebugView(bool value)
|
||||
|
@ -363,6 +364,7 @@ protected:
|
|||
u64 m_hovered_time = 0;
|
||||
s32 m_old_tooltip_id = -1;
|
||||
|
||||
bool m_default_allowclose = true;
|
||||
bool m_allowclose = true;
|
||||
bool m_lock = false;
|
||||
v2u32 m_lockscreensize;
|
||||
|
@ -422,7 +424,6 @@ private:
|
|||
bool key_up;
|
||||
bool key_down;
|
||||
bool key_enter;
|
||||
bool key_escape;
|
||||
};
|
||||
|
||||
fs_key_pending current_keys_pending;
|
||||
|
@ -484,6 +485,7 @@ private:
|
|||
void parseStyle(parserData *data, const std::string &element);
|
||||
void parseSetFocus(parserData *, const std::string &element);
|
||||
void parseModel(parserData *data, const std::string &element);
|
||||
void parseAllowClose(parserData *data, const std::string &element);
|
||||
|
||||
bool parseMiddleRect(const std::string &value, core::rect<s32> *parsed_rect);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue