shithub: choc

Download patch

ref: 5e3314ddca27eb4ef5090b482b169d7e8f31690f
parent: 98e31e07cff79b30ec5631373dc0b16ece02f1cf
author: Jonathan Dowland <jon+github@alcopop.org>
date: Tue Mar 21 03:42:25 EDT 2017

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.

--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -112,6 +112,7 @@
 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];  
 
@@ -631,6 +632,17 @@
 }
 
 //
+// 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
 //
 void M_SaveSelect(int choice)
@@ -648,7 +660,14 @@
     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 @@
             {
                 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 @@
             {
                 key = key_menu_abort;
             }
+            // If user was entering a save name, back out
+            else if (saveStringEnter)
+            {
+                key = KEY_ESCAPE;
+            }
             else
             {
                 key = key_menu_back;
@@ -1453,23 +1488,6 @@
         {
             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