Beispiel #1
0
Datei: setup.c Projekt: rj76/kq
/*! \brief Display configuration menu
 *
 * This is the config menu that is called from the system
 * menu.  Here you can adjust the music or sound volume, or
 * the speed that the battle gauge moves at.
 */
void config_menu (void)
{
   int stop = 0, ptr = 0, p;
   int temp_key = 0;

#ifdef DEBUGMODE
   #define MENU_SIZE 18
#else
   #define MENU_SIZE 17
#endif
   static const char *dc[MENU_SIZE];

   /* Define rows with appropriate spacings for breaks between groups */
   int row[MENU_SIZE];
   for (p = 0; p < 4; p++)
      row[p] = (p + 4) * 8;     // (p * 8) + 32
   for (p = 4; p < 12; p++)
      row[p] = (p + 5) * 8;     // (p * 8) + 40
   for (p = 12; p < 15; p++)
      row[p] = (p + 6) * 8;     // (p * 8) + 48
   for (p = 15; p < MENU_SIZE; p++)
      row[p] = (p + 7) * 8;     // (p * 8) + 56

   /* Helper strings */
   dc[0]=_("Display KQ in a window.");
   dc[1]=_("Stretch to fit 640x480 resolution.");
   dc[2]=_("Display the frame rate during play.");
   dc[3]=_("Wait for vertical retrace.");
   dc[4]=_("Key used to move up.");
   dc[5]=_("Key used to move down.");
   dc[6]=_("Key used to move left.");
   dc[7]=_("Key used to move right.");
   dc[8]=_("Key used to confirm action.");
   dc[9]=_("Key used to cancel action.");
   dc[10]=_("Key used to call character menu.");
   dc[11]=_("Key used to call system menu.");
   dc[12]=_("Toggle sound and music on/off.");
   dc[13]=_("Overall sound volume (affects music).");
   dc[14]=_("Music volume.");
   dc[15]=_("Animation speed-ups for slow machines.");
   dc[16]=_("Toggle how to allocate CPU usage.");
#ifdef DEBUGMODE
      dc[17]=_("Things you can do only in DebugMode.");
#endif

   unpress ();
   push_config_state ();
   set_config_file (kqres (SETTINGS_DIR, "kq.cfg"));
   while (!stop) {
      check_animation ();
      drawmap ();
      menubox (double_buffer, 88 + xofs, yofs, 16, 1, BLUE);
      print_font (double_buffer, 96 + xofs, 8 + yofs, _("KQ Configuration"),
                  FGOLD);
      menubox (double_buffer, 32 + xofs, 24 + yofs, 30, MENU_SIZE + 3, BLUE);

      citem (row[0], _("Windowed mode:"), windowed == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[1], _("Stretch Display:"), stretch_view == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[2], _("Show Frame Rate:"), show_frate == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[3], _("Wait for Retrace:"), wait_retrace == 1 ? _("YES") : _("NO"), FNORMAL);
      citem (row[4], _("Up Key:"), kq_keyname (kup), FNORMAL);
      citem (row[5], _("Down Key:"), kq_keyname (kdown), FNORMAL);
      citem (row[6], _("Left Key:"), kq_keyname (kleft), FNORMAL);
      citem (row[7], _("Right Key:"), kq_keyname (kright), FNORMAL);
      citem (row[8], _("Confirm Key:"), kq_keyname (kalt), FNORMAL);
      citem (row[9], _("Cancel Key:"), kq_keyname (kctrl), FNORMAL);
      citem (row[10], _("Menu Key:"), kq_keyname (kenter), FNORMAL);
      citem (row[11], _("System Menu Key:"), kq_keyname (kesc), FNORMAL);
      citem (row[12], _("Sound System:"), is_sound ? _("ON") : _("OFF"), FNORMAL);

      p = FNORMAL;
      /* TT: This needs to check for ==0 because 1 means sound init */
      if (is_sound == 0)
         p = FDARK;

      sprintf (strbuf, "%3d%%", gsvol * 100 / 250);
      citem (row[13], _("Sound Volume:"), strbuf, p);

      sprintf (strbuf, "%3d%%", gmvol * 100 / 250);
      citem (row[14], _("Music Volume:"), strbuf, p);

      citem (row[15], _("Slow Computer:"), slow_computer ? _("YES") : _("NO"), FNORMAL);

      if (cpu_usage)
         sprintf (strbuf, _("rest(%d)"), cpu_usage - 1);
      else
         sprintf (strbuf, "yield_timeslice()");
      citem (row[16], _("CPU Usage:"), strbuf, FNORMAL);

#ifdef DEBUGMODE
      if (debugging)
         sprintf (strbuf, "%d", debugging);
      citem (row[17], _("DebugMode Stuff:"), debugging ? strbuf : _("OFF"), FNORMAL);
#endif

      /* This affects the VISUAL placement of the arrow */
      p = ptr;
      if (ptr > 3)
         p++;
      if (ptr > 11)
         p++;
      if (ptr > 14)
         p++;
      draw_sprite (double_buffer, menuptr, 32 + xofs, p * 8 + 32 + yofs);

      /* This is the bottom window, where the description goes */
      menubox (double_buffer, xofs, 216 + yofs, 38, 1, BLUE);
      print_font (double_buffer, 8 + xofs, 224 + yofs, dc[ptr], FNORMAL);
      blit2screen (xofs, yofs);

      readcontrols ();
      if (up) {
         unpress ();
         // "jump" over unusable options
         if (ptr == 15 && is_sound == 0)
            ptr -= 2;
         ptr--;
         if (ptr < 0)
            ptr = MENU_SIZE - 1;
         play_effect (SND_CLICK, 128);
      }
      if (down) {
         unpress ();
         // "jump" over unusable options
         if (ptr == 12 && is_sound == 0)
            ptr += 2;
         ptr++;
         if (ptr > MENU_SIZE - 1)
            ptr = 0;
         play_effect (SND_CLICK, 128);
      }
      if (balt) {
         unpress ();
         switch (ptr) {
         case 0:
#ifdef __DJGPP__
            text_ex (B_TEXT, 255,
                     _("This version of KQ was compiled for DOS and does not support windowed mode"));
#else
            text_ex (B_TEXT, 255,
                     _("Changing the display mode to or from windowed view could have serious ramifications. It is advised that you save first."));
            if (windowed == 0)
               sprintf (strbuf, _("Switch to windowed mode?"));
            else
               sprintf (strbuf, _("Switch to full screen?"));
            p = prompt (255, 2, B_TEXT, strbuf, _("  no"), _("  yes"), "");
            if (p == 1) {
               if (windowed == 0)
                  windowed = 1;
               else
                  windowed = 0;
               set_config_int (NULL, "windowed", windowed);
               set_graphics_mode ();
            }
#endif
            break;
         case 1:
#ifdef __DJGPP__
            text_ex (B_TEXT, 255,
                     _("This version of KQ was compiled for DOS and does not support stretching"));
#else
            text_ex (B_TEXT, 255,
                     _("Changing the stretched view option could have serious ramifications. It is advised that you save your game before trying this."));
            if (stretch_view == 0)
               sprintf (strbuf, _("Try to stretch the display?"));
            else
               sprintf (strbuf, _("Switch to unstretched display?"));
            p = prompt (255, 2, B_TEXT, strbuf, _("  no"), _("  yes"), "");
            if (p == 1) {
               if (stretch_view == 0)
                  stretch_view = 1;
               else
                  stretch_view = 0;
               set_config_int (NULL, "stretch_view", stretch_view);
               set_graphics_mode ();
            }
#endif
            break;
         case 2:
            if (show_frate == 0)
               show_frate = 1;
            else
               show_frate = 0;
            set_config_int (NULL, "show_frate", show_frate);
            break;
         case 3:
            if (wait_retrace == 0)
               wait_retrace = 1;
            else
               wait_retrace = 0;
            set_config_int (NULL, "wait_retrace", wait_retrace);
            break;
         case 4:
            while ((temp_key = getakey ()) == 0);
            kup = temp_key;
            unpress ();
            set_config_int (NULL, "kup", kup);
            break;
         case 5:
            while ((temp_key = getakey ()) == 0);
            kdown = temp_key;
            unpress ();
            set_config_int (NULL, "kdown", kdown);
            break;
         case 6:
            while ((temp_key = getakey ()) == 0);
            kleft = temp_key;
            unpress ();
            set_config_int (NULL, "kleft", kleft);
            break;
         case 7:
            while ((temp_key = getakey ()) == 0);
            kright = temp_key;
            unpress ();
            set_config_int (NULL, "kright", kright);
            break;
         case 8:
            while ((temp_key = getakey ()) == 0);
            kalt = temp_key;
            unpress ();
            set_config_int (NULL, "kalt", kalt);
            break;
         case 9:
            while ((temp_key = getakey ()) == 0);
            kctrl = temp_key;
            unpress ();
            set_config_int (NULL, "kctrl", kctrl);
            break;
         case 10:
            while ((temp_key = getakey ()) == 0);
            kenter = temp_key;
            unpress ();
            set_config_int (NULL, "kenter", kenter);
            break;
         case 11:
            while ((temp_key = getakey ()) == 0);
            kesc = temp_key;
            unpress ();
            set_config_int (NULL, "kesc", kesc);
            break;
         case 12:
            if (is_sound == 2)
               sound_init ();
            else {
               if (is_sound == 0) {
                  is_sound = 1;
                  print_font (double_buffer, 92 + 2 + xofs, 204 + yofs,
                              _("...please wait..."), FNORMAL);
                  blit2screen (xofs, yofs);
                  sound_init ();
                  play_music (g_map.song_file, 0);
               }
            }
            set_config_int (NULL, "is_sound", is_sound != 0);
            break;
         case 13:
            if (is_sound == 2) {
               p = getavalue (_("Sound Volume"), 0, 25, gsvol / 10, 1);
               if (p != -1)
                  gsvol = p * 10;

               /* make sure to set it no matter what */
               set_volume (gsvol, 0);
               set_config_int (NULL, "gsvol", gsvol);
            } else
               /* Not as daft as it seems, SND_BAD also wobbles the screen */
               play_effect (SND_BAD, 128);
            break;
         case 14:
            if (is_sound == 2) {
               p = getavalue (_("Music Volume"), 0, 25, gmvol / 10, 1);
               if (p != -1)
                  gmvol = p * 10;

               /* make sure to set it no matter what */
               set_music_volume (gmvol / 250.0);
               set_config_int (NULL, "gmvol", gmvol);
            } else
               play_effect (SND_BAD, 128);
            break;
         case 15:
            /* TT: toggle slow_computer */
            slow_computer = !slow_computer;
            set_config_int (NULL, "slow_computer", slow_computer);
            break;
         case 16:
            /* TT: Adjust the CPU usage:yield_timeslice() or rest() */
            cpu_usage++;
            if (cpu_usage > 2)
               cpu_usage = 0;
            break;
#ifdef DEBUGMODE
         case 17:
            /* TT: Things we only have access to when we're in debug mode */
            if (debugging < 4)
               debugging++;
            else
               debugging = 0;
            break;
#endif
         }
      }
      if (bctrl) {
         unpress ();
         stop = 1;
      }
   }
   pop_config_state ();
}
Beispiel #2
0
static int l_engine_set_music_volume(lua_State *l)
{
	const float volume = Clamp(luaL_checknumber(l, 1), 0.0, 1.0);
	set_music_volume(Pi::config->Int("MusicMuted") != 0, volume);
	return 0;
}