foxygit / doom Log in
commit a1b066a0eb0d2cf5d17ad68ca833fcdd21f80725
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Thu Apr 10 00:48:04 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Thu Apr 10 00:48:04 2014 -0400

    setup: Save selected game when browsing menus.

    Once a game type (IWAD) has been selected, remember that selection
    rather than resetting to the first item in the list when the window is
    closed and reopened. This fixes #169 (thanks Alexandre Xavier).
---
 src/setup/multiplayer.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/setup/multiplayer.c b/src/setup/multiplayer.c
index 35552349..8b461066 100644
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -66,7 +66,7 @@ static char *iwad_labels[8];

 // Index of the currently selected IWAD

-static int found_iwad_selected;
+static int found_iwad_selected = -1;

 // Filename to pass to '-iwad'.

@@ -599,9 +599,15 @@ static txt_widget_t *IWADSelector(void)
         result = (txt_widget_t *) dropdown;
     }

-    // Select first in the list.
+    // The first time the dialog is opened, found_iwad_selected=-1,
+    // so select the first IWAD in the list. Don't lose the setting
+    // if we close and reopen the dialog.
+
+    if (found_iwad_selected < 0 || found_iwad_selected >= num_iwads)
+    {
+        found_iwad_selected = 0;
+    }

-    found_iwad_selected = 0;
     IWADSelected(NULL, NULL);

     return result;