Fix #69
[neverball] / ball / st_conf.c
index 8d254dc..988fd9d 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
 #include "game.h"
 #include "audio.h"
 #include "config.h"
+#include "st_shared.h"
 
 #include "st_conf.h"
 #include "st_title.h"
 #include "st_lang.h"
+#include "st_resol.h"
+#include "st_name.h"
 
 /*---------------------------------------------------------------------------*/
 
 #define CONF_FULL  1
 #define CONF_WIN   2
-#define CONF_16x12 3
-#define CONF_12x10 4
-#define CONF_10x7  5
-#define CONF_8x6   6
-#define CONF_6x4   7
 #define CONF_TEXHI 8
 #define CONF_TEXLO 9
 #define CONF_GEOHI 10
@@ -48,6 +46,8 @@
 #define CONF_AUDLO 19
 #define CONF_BACK  20
 #define CONF_LANG  21
+#define CONF_RESOL 22
+#define CONF_PLAYER 23
 
 static int audlo_id;
 static int audhi_id;
@@ -56,7 +56,6 @@ static int sound_id[11];
 
 static int conf_action(int i)
 {
-    int f = config_get_d(CONFIG_FULLSCREEN);
     int w = config_get_d(CONFIG_WIDTH);
     int h = config_get_d(CONFIG_HEIGHT);
     int s = config_get_d(CONFIG_SOUND_VOLUME);
@@ -78,36 +77,6 @@ static int conf_action(int i)
         r = config_mode(0, w, h);
         goto_state(&st_conf);
         break;
-        
-    case CONF_16x12:
-        goto_state(&st_null);
-        r = config_mode(f, 1600, 1200);
-        goto_state(&st_conf);
-        break;
-
-    case CONF_12x10:
-        goto_state(&st_null);
-        r = config_mode(f, 1280, 1024);
-        goto_state(&st_conf);
-        break;
-
-    case CONF_10x7:
-        goto_state(&st_null);
-        r = config_mode(f, 1024, 768);
-        goto_state(&st_conf);
-        break;
-            
-    case CONF_8x6:
-        goto_state(&st_null);
-        r = config_mode(f, 800, 600);
-        goto_state(&st_conf);
-        break;
-
-    case CONF_6x4:
-        goto_state(&st_null);
-        r = config_mode(f, 640, 480);
-        goto_state(&st_conf);
-        break;
 
     case CONF_TEXHI:
         goto_state(&st_null);
@@ -190,11 +159,19 @@ static int conf_action(int i)
     case CONF_BACK:
         goto_state(&st_title);
         break;
-       
+
     case CONF_LANG:
         goto_state(&st_lang);
         break;
-       
+
+    case CONF_RESOL:
+        goto_state(&st_resol);
+        break;
+
+    case CONF_PLAYER:
+        goto_name(&st_conf, &st_conf);
+        break;
+
     default:
         if (100 <= i && i <= 110)
         {
@@ -235,7 +212,7 @@ static int conf_enter(void)
     {
         if ((jd = gui_varray(id)))
         {
-            int w = config_get_d(CONFIG_WIDTH);
+            int f = config_get_d(CONFIG_FULLSCREEN);
             int t = config_get_d(CONFIG_TEXTURES);
             int g = config_get_d(CONFIG_GEOMETRY);
             int r = config_get_d(CONFIG_REFLECTION);
@@ -253,16 +230,18 @@ static int conf_enter(void)
 
             /* Add mode selectors only for existing modes. */
 
-            if (SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE))
-                gui_state(jd, "1600 x 1200", GUI_SML, CONF_16x12, (w == 1600));
-            if (SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE))
-                gui_state(jd, "1280 x 1024", GUI_SML, CONF_12x10, (w == 1280));
-            if (SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE))
-                gui_state(jd, "1024 x 768",  GUI_SML, CONF_10x7,  (w == 1024));
-            if (SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE))
-                gui_state(jd, "800 x 600",   GUI_SML, CONF_8x6,   (w ==  800));
-            if (SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE))
-                gui_state(jd, "640 x 480",   GUI_SML, CONF_6x4,   (w ==  640));
+            if ((kd = gui_harray(jd)))
+            {
+                gui_state(kd, _("No"), GUI_SML, CONF_WIN, (f == 0));
+                gui_state(kd, _("Yes"),  GUI_SML, CONF_FULL, (f == 1));
+            }
+
+            {
+                static char msg[20];
+                sprintf(msg, "%d x %d", config_get_d(CONFIG_WIDTH),
+                        config_get_d(CONFIG_HEIGHT));
+                gui_state(jd, msg, GUI_SML, CONF_RESOL, 0);
+            }
 
             if ((kd = gui_harray(jd)))
             {
@@ -316,7 +295,7 @@ static int conf_enter(void)
             if ((kd = gui_harray(jd)))
             {
                 /* A series of empty buttons forms the music volume control. */
+
                 music_id[10] = gui_state(kd, NULL, GUI_SML, 210, (m == 10));
                 music_id[ 9] = gui_state(kd, NULL, GUI_SML, 209, (m ==  9));
                 music_id[ 8] = gui_state(kd, NULL, GUI_SML, 208, (m ==  8));
@@ -329,24 +308,21 @@ static int conf_enter(void)
                 music_id[ 1] = gui_state(kd, NULL, GUI_SML, 201, (m ==  1));
                 music_id[ 0] = gui_state(kd, NULL, GUI_SML, 200, (m ==  0));
             }
-           gui_state(jd, _(language_get_name(language_from_code(config_simple_get_s(CONFIG_LANG)))), GUI_SML, CONF_LANG, 0);
+            gui_state(jd, _(language_get_name(language_from_code(config_simple_get_s(CONFIG_LANG)))), GUI_SML, CONF_LANG, 0);
+            gui_state(jd, config_simple_get_s(CONFIG_PLAYER), GUI_SML,
+                      CONF_PLAYER, 0);
         }
         if ((jd = gui_vstack(id)))
         {
-            int f = config_get_d(CONFIG_FULLSCREEN);
-
             if ((kd = gui_harray(jd)))
             {
                 gui_filler(kd);
                 gui_start(kd, _("Back"), GUI_SML, CONF_BACK, 0);
             }
 
-            gui_state(jd, _("Fullscreen"),   GUI_SML, CONF_FULL, (f == 1));
-            gui_state(jd, _("Window"),       GUI_SML, CONF_WIN,  (f == 0));
+            gui_label(jd, _("Fullscreen"),   GUI_SML, GUI_ALL, 0, 0);
+            gui_label(jd, _("Resolution"),   GUI_SML, GUI_ALL, 0, 0);
 
-            /* This filler expands to accomodate an unknown number of modes. */
-            gui_filler(jd);
-           
             gui_label(jd, _("Textures"),     GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Geometry"),     GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Reflection"),   GUI_SML, GUI_ALL, 0, 0);
@@ -356,6 +332,7 @@ static int conf_enter(void)
             gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Language"),     GUI_SML, GUI_ALL, 0, 0);
+            gui_label(jd, _("Player Name"),  GUI_SML, GUI_ALL, 0, 0);
         }
         gui_layout(id, 0, 0);
     }
@@ -381,47 +358,14 @@ static void conf_paint(int id, float st)
     gui_paint(id);
 }
 
-static void conf_timer(int id, float dt)
-{
-    gui_timer(id, dt);
-    audio_timer(dt);
-}
-
-static void conf_point(int id, int x, int y, int dx, int dy)
-{
-    gui_pulse(gui_point(id, x, y), 1.2f);
-}
-
-static void conf_stick(int id, int a, int v)
-{
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        gui_pulse(gui_stick(id, v, 0), 1.2f);
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        gui_pulse(gui_stick(id, 0, v), 1.2f);
-}
-
-static int conf_click(int b, int d)
-{
-    if (b < 0 && d == 1)
-        return conf_action(gui_token(gui_click()));
-    return 1;
-}
-
-static int conf_keybd(int c, int d)
-{
-    return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
-}
-
 static int conf_buttn(int b, int d)
 {
     if (d)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
             return conf_action(gui_token(gui_click()));
-        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
-            return goto_state(&st_title);
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return goto_state(&st_title);
+            return conf_action(CONF_BACK);
     }
     return 1;
 }
@@ -464,11 +408,11 @@ struct state st_conf = {
     conf_enter,
     conf_leave,
     conf_paint,
-    conf_timer,
-    conf_point,
-    conf_stick,
-    conf_click,
-    conf_keybd,
+    shared_timer,
+    shared_point,
+    shared_stick,
+    shared_click,
+    NULL,
     conf_buttn,
     1, 0
 };