Skip to content

Commit 0b78889

Browse files
committedNov 3, 2013
Send a on_receive_fields event when formspec is closed, with fields.quit = "true"
1 parent 06a5ece commit 0b78889

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

Diff for: ‎src/guiFormSpecMenu.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -2041,12 +2041,16 @@ ItemStack GUIFormSpecMenu::verifySelectedItem()
20412041
return ItemStack();
20422042
}
20432043

2044-
void GUIFormSpecMenu::acceptInput()
2044+
void GUIFormSpecMenu::acceptInput(bool quit=false)
20452045
{
20462046
if(m_text_dst)
20472047
{
20482048
std::map<std::string, std::string> fields;
20492049

2050+
if (quit) {
2051+
fields["quit"] = "true";
2052+
}
2053+
20502054
if (current_keys_pending.key_down) {
20512055
fields["key_down"] = "true";
20522056
current_keys_pending.key_down = false;
@@ -2188,10 +2192,12 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
21882192
if (event.KeyInput.PressedDown && (kp == EscapeKey ||
21892193
kp == getKeySetting("keymap_inventory")))
21902194
{
2191-
if (m_allowclose)
2195+
if (m_allowclose) {
2196+
acceptInput(true);
21922197
quitMenu();
2193-
else
2198+
} else {
21942199
m_text_dst->gotText(narrow_to_wide("MenuQuit"));
2200+
}
21952201
return true;
21962202
}
21972203
if (event.KeyInput.PressedDown &&
@@ -2204,7 +2210,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
22042210
switch (event.KeyInput.Key) {
22052211
case KEY_RETURN:
22062212
if (m_allowclose) {
2207-
acceptInput();
2213+
acceptInput(true);
22082214
quitMenu();
22092215
}
22102216
else
@@ -2551,11 +2557,13 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
25512557
unsigned int btn_id = event.GUIEvent.Caller->getID();
25522558

25532559
if (btn_id == 257) {
2554-
acceptInput();
2555-
if (m_allowclose)
2560+
if (m_allowclose) {
2561+
acceptInput(true);
25562562
quitMenu();
2557-
else
2563+
} else {
2564+
acceptInput();
25582565
m_text_dst->gotText(narrow_to_wide("ExitButton"));
2566+
}
25592567
// quitMenu deallocates menu
25602568
return true;
25612569
}
@@ -2572,10 +2580,12 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
25722580
s.send = true;
25732581
acceptInput();
25742582
if(s.is_exit){
2575-
if (m_allowclose)
2583+
if (m_allowclose) {
2584+
acceptInput(true);
25762585
quitMenu();
2577-
else
2586+
} else {
25782587
m_text_dst->gotText(narrow_to_wide("ExitButton"));
2588+
}
25792589
return true;
25802590
}else{
25812591
s.send = false;
@@ -2590,7 +2600,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
25902600
{
25912601

25922602
if (m_allowclose) {
2593-
acceptInput();
2603+
acceptInput(true);
25942604
quitMenu();
25952605
}
25962606
else {

Diff for: ‎src/guiFormSpecMenu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class GUIFormSpecMenu : public GUIModalMenu
227227
void updateSelectedItem();
228228
ItemStack verifySelectedItem();
229229

230-
void acceptInput();
230+
void acceptInput(bool quit);
231231
bool preprocessEvent(const SEvent& event);
232232
bool OnEvent(const SEvent& event);
233233

1 commit comments

Comments
 (1)

4aiman commented on Nov 6, 2013

@4aiman
Contributor

Finally :-)

Please sign in to comment.