foxygit / doom Log in
commit 5e3314ddca27eb4ef5090b482b169d7e8f31690f
Author:     Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Tue Mar 21 07:42:25 2017 +0000
Commit:     Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Tue Mar 21 14:01:23 2017 +0000

    Adjustments to selecting save slots via joypad

    Reorder to reduce dupliation in M_Responder and move "active" code
    out and set flags instead.

    Expand M_SaveSelect to check a joypadSave flag and set a more useful
    default save name if its set.

    Remaining bug: the fire action bleeds through into the game after
    the save dialog is dismissed.
---
 src/doom/m_menu.c | 54 ++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c
index 490e32a9..ea555b3b 100644
--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -112,6 +112,7 @@ char gammamsg[5][26] =
 int			saveStringEnter;
 int             	saveSlot;	// which slot to save in
 int			saveCharIndex;	// which char we're editing
+static boolean          joypadSave = false; // was the save action initiated by joypad?
 // old save description before edit
 char			saveOldString[SAVESTRINGSIZE];

@@ -630,6 +631,17 @@ void M_DoSave(int slot)
 	quickSaveSlot = slot;
 }

+//
+// Generate a default save slot name when the user saves to
+// an empty slot via the joypad.
+//
+static void SetDefaultSaveName(int slot)
+{
+    M_snprintf(savegamestrings[itemOn], SAVESTRINGSIZE - 1,
+               "JOYSTICK SLOT %i", itemOn + 1);
+    joypadSave = false;
+}
+
 //
 // User wants to save. Start string input for M_Responder
 //
@@ -648,7 +660,14 @@ void M_SaveSelect(int choice)
     saveSlot = choice;
     M_StringCopy(saveOldString,savegamestrings[choice], SAVESTRINGSIZE);
     if (!strcmp(savegamestrings[choice], EMPTYSTRING))
-	savegamestrings[choice][0] = 0;
+    {
+        savegamestrings[choice][0] = 0;
+
+        if (joypadSave)
+        {
+            SetDefaultSaveName(choice);
+        }
+    }
     saveCharIndex = strlen(savegamestrings[choice]);
 }

@@ -1430,8 +1449,19 @@ boolean M_Responder (event_t* ev)
             {
                 key = key_menu_confirm;
             }
+            // Simulate pressing "Enter" when we are supplying a save slot name
+            else if (saveStringEnter)
+            {
+                key = KEY_ENTER;
+                // XXX: fire action bleeding into game
+            }
             else
             {
+                // if selecting a save slot via joypad, set a flag
+                if (currentMenu == &SaveDef)
+                {
+                    joypadSave = true;
+                }
                 key = key_menu_forward;
             }
             joywait = I_GetTime() + 5;
@@ -1443,6 +1473,11 @@ boolean M_Responder (event_t* ev)
             {
                 key = key_menu_abort;
             }
+            // If user was entering a save name, back out
+            else if (saveStringEnter)
+            {
+                key = KEY_ESCAPE;
+            }
             else
             {
                 key = key_menu_back;
@@ -1454,23 +1489,6 @@ boolean M_Responder (event_t* ev)
             key = key_menu_activate;
             joywait = I_GetTime() + 5;
         }
-
-        // Fill-in the savegame name if user press Fire on the joystick
-        if (saveStringEnter && joybmenu >= 0 && ev->data1&1)
-        {
-            // Create a savegame string
-            char savestring[SAVESTRINGSIZE];
-
-            memset(savestring, 0, SAVESTRINGSIZE);
-            M_snprintf(savestring, SAVESTRINGSIZE - 1, "JOYSTICK SLOT %i", saveSlot);
-            saveCharIndex = strlen(savestring);
-            memcpy(savegamestrings[saveSlot], savestring, SAVESTRINGSIZE);
-
-            // Simulate a KEY_ENTER press. Wait a log time to generate another
-            // keypress.
-            key = KEY_ENTER;
-            joywait = I_GetTime() + 15;
-        }
     }
     else
     {