1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Formspec: Fix malfunctioning 'Proceed' button on sizeless formspecs

This commit is contained in:
SmallJoker 2025-05-28 14:18:06 +02:00 committed by sfan5
parent 9f7501d20a
commit fcddac6c07
3 changed files with 25 additions and 31 deletions

View file

@ -23,8 +23,8 @@ Callbacks
* `core.button_handler(fields)`: called when a button is pressed. * `core.button_handler(fields)`: called when a button is pressed.
* `fields` = `{name1 = value1, name2 = value2, ...}` * `fields` = `{name1 = value1, name2 = value2, ...}`
* `core.event_handler(event)` * `core.event_handler(event)`
* `event`: `"MenuQuit"`, `"KeyEnter"`, `"ExitButton"`, `"EditBoxEnter"` or * `event`: `"MenuQuit"` (derived from `quit`) or `"FullscreenChange"`
`"FullscreenChange"` The main menu may issue custom events, such as `"Refresh"` (server list).
* `core.on_before_close()`: called before the menu is closed, either to exit or * `core.on_before_close()`: called before the menu is closed, either to exit or
to join a game to join a game

View file

@ -77,6 +77,9 @@
return; \ return; \
} }
// Element ID of the "Proceed" button shown for sizeless formspecs
constexpr s32 ID_PROCEED_BTN = 257;
/* /*
GUIFormSpecMenu GUIFormSpecMenu
*/ */
@ -2998,7 +3001,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
gui::IGUIElement *focused_element = Environment->getFocus(); gui::IGUIElement *focused_element = Environment->getFocus();
if (focused_element && focused_element->getParent() == this) { if (focused_element && focused_element->getParent() == this) {
s32 focused_id = focused_element->getID(); s32 focused_id = focused_element->getID();
if (focused_id > 257) { if (focused_id > ID_PROCEED_BTN) {
for (const GUIFormSpecMenu::FieldSpec &field : m_fields) { for (const GUIFormSpecMenu::FieldSpec &field : m_fields) {
if (field.fid == focused_id) { if (field.fid == focused_id) {
m_focused_element = field.fname; m_focused_element = field.fname;
@ -3308,7 +3311,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
size.X / 2 - 70, pos.Y, size.X / 2 - 70, pos.Y,
size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2 size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2
); );
GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, 257, GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, ID_PROCEED_BTN,
wstrgettext("Proceed").c_str()); wstrgettext("Proceed").c_str());
} }
} }
@ -4031,12 +4034,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
if (m_joystick->wasKeyDown(KeyType::ESC)) { if (m_joystick->wasKeyDown(KeyType::ESC)) {
tryClose(); tryClose();
} else if (m_joystick->wasKeyDown(KeyType::JUMP)) { } else if (m_joystick->wasKeyDown(KeyType::JUMP)) {
if (m_allowclose) { trySubmitClose();
acceptInput(quit_mode_accept);
quitMenu();
} else {
acceptInput(quit_mode_try);
}
} }
} }
return handled; return handled;
@ -4056,6 +4054,16 @@ void GUIFormSpecMenu::tryClose()
} }
} }
void GUIFormSpecMenu::trySubmitClose()
{
if (m_allowclose) {
acceptInput(quit_mode_accept);
quitMenu();
} else {
acceptInput(quit_mode_try);
}
}
bool GUIFormSpecMenu::OnEvent(const SEvent& event) bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{ {
if (event.EventType==EET_KEY_INPUT_EVENT) { if (event.EventType==EET_KEY_INPUT_EVENT) {
@ -4099,12 +4107,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
break; break;
} }
if (current_keys_pending.key_enter) { if (current_keys_pending.key_enter) {
if (m_allowclose) { trySubmitClose();
acceptInput(quit_mode_accept);
quitMenu();
} else {
acceptInput(quit_mode_try);
}
} else { } else {
acceptInput(); acceptInput();
} }
@ -4848,10 +4851,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
(event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED)) { (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED)) {
s32 caller_id = event.GUIEvent.Caller->getID(); s32 caller_id = event.GUIEvent.Caller->getID();
if (caller_id == 257) { if (caller_id == ID_PROCEED_BTN) {
acceptInput(quit_mode_accept); trySubmitClose();
m_text_dst->gotText(L"ExitButton");
quitMenu();
return true; return true;
} }
@ -4881,7 +4882,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (s.is_exit) { if (s.is_exit) {
acceptInput(quit_mode_accept); acceptInput(quit_mode_accept);
m_text_dst->gotText(L"ExitButton");
quitMenu(); quitMenu();
return true; return true;
} }
@ -4931,7 +4931,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
} }
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) { if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
if (event.GUIEvent.Caller->getID() > 257) { if (event.GUIEvent.Caller->getID() > ID_PROCEED_BTN) {
bool close_on_enter = true; bool close_on_enter = true;
for (GUIFormSpecMenu::FieldSpec &s : m_fields) { for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
if (s.ftype == f_Unknown && if (s.ftype == f_Unknown &&
@ -4948,12 +4948,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
current_keys_pending.key_enter = true; current_keys_pending.key_enter = true;
if (close_on_enter) { if (close_on_enter) {
if (m_allowclose) { trySubmitClose();
acceptInput(quit_mode_accept);
quitMenu();
} else {
acceptInput(quit_mode_try);
}
} else { } else {
acceptInput(); acceptInput();
} }
@ -4963,7 +4958,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (event.GUIEvent.EventType == gui::EGET_TABLE_CHANGED) { if (event.GUIEvent.EventType == gui::EGET_TABLE_CHANGED) {
int current_id = event.GUIEvent.Caller->getID(); int current_id = event.GUIEvent.Caller->getID();
if (current_id > 257) { if (current_id > ID_PROCEED_BTN) {
// find the element that was clicked // find the element that was clicked
for (GUIFormSpecMenu::FieldSpec &s : m_fields) { for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
// if it's a table, set the send field // if it's a table, set the send field

View file

@ -68,8 +68,6 @@ struct TextDest
{ {
virtual ~TextDest() = default; virtual ~TextDest() = default;
// This is deprecated I guess? -celeron55
virtual void gotText(const std::wstring &text) {}
virtual void gotText(const StringMap &fields) = 0; virtual void gotText(const StringMap &fields) = 0;
std::string m_formname; std::string m_formname;
@ -493,6 +491,7 @@ private:
bool parseMiddleRect(const std::string &value, core::rect<s32> *parsed_rect); bool parseMiddleRect(const std::string &value, core::rect<s32> *parsed_rect);
void tryClose(); void tryClose();
void trySubmitClose();
void showTooltip(const std::wstring &text, const irr::video::SColor &color, void showTooltip(const std::wstring &text, const irr::video::SColor &color,
const irr::video::SColor &bgcolor); const irr::video::SColor &bgcolor);