rnd-20030428-1-src
[rocksndiamonds.git] / src / screens.c
index 1c20e6ad344e8e1b84816e128439bbea2143c65e..f10614fd52f8a92846216d1d80fd992dd9496af7 100644 (file)
@@ -71,15 +71,12 @@ static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
 static int setup_mode = SETUP_MODE_MAIN;
 
-#if 0
-static int mSX = SX;
-static int mSY = SY;
-#else
-#define mSX (SX + (game_status == MAINMENU ? global.menu_draw_xoffset_MAIN : \
-                  global.menu_draw_xoffset))
-#define mSY (SY + (game_status == MAINMENU ? global.menu_draw_yoffset_MAIN : \
-                  global.menu_draw_yoffset))
-#endif
+#define mSX (SX + (game_status >= GAME_MODE_MAIN &&    \
+                  game_status <= GAME_MODE_SETUP ?     \
+                  menu.draw_xoffset[game_status] : menu.draw_xoffset_default))
+#define mSY (SY + (game_status >= GAME_MODE_MAIN &&    \
+                  game_status <= GAME_MODE_SETUP ?     \
+                  menu.draw_yoffset[game_status] : menu.draw_yoffset_default))
 
 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
 #define NUM_SCROLLBAR_BITMAPS          2
@@ -106,14 +103,9 @@ static void drawCursorExt(int xpos, int ypos, int color, int graphic)
 
   ypos += MENU_SCREEN_START_YPOS;
 
-#if 1
   DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
   DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
                         graphic, 0);
-#else
-  DrawBackground(SX + xpos * 32, SY + ypos * 32, TILEX, TILEY);
-  DrawGraphicThruMask(xpos, ypos, graphic, 0);
-#endif
 }
 
 static void initCursor(int ypos, int graphic)
@@ -189,11 +181,6 @@ void DrawMainMenu()
   int level_width = font_width * strlen("Level:");
   int i;
 
-#if 0
-  mSX = SX + global.menu_draw_xoffset;
-  mSY = SY + global.menu_draw_yoffset;
-#endif
-
   UnmapAllGadgets();
   FadeSounds();
 
@@ -208,7 +195,7 @@ void DrawMainMenu()
   /* needed if last screen was the playing screen, invoked from level editor */
   if (level_editor_test_game)
   {
-    game_status = LEVELED;
+    game_status = GAME_MODE_EDITOR;
     DrawLevelEd();
     return;
   }
@@ -252,7 +239,7 @@ void DrawMainMenu()
   DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
   DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
   DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
-  DrawText(mSY + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
+  DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
   DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
   DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
   DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
@@ -343,8 +330,8 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
   if (mx || my)                /* mouse input */
   {
-    x = (mx - SX) / 32;
-    y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
+    x = (mx - mSX) / 32;
+    y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
   }
   else if (dx || dy)   /* keyboard input */
   {
@@ -406,14 +393,14 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
     {
       if (y == 0)
       {
-       game_status = TYPENAME;
+       game_status = GAME_MODE_PSEUDO_TYPENAME;
        HandleTypeName(strlen(setup.player_name), 0);
       }
       else if (y == 1)
       {
        if (leveldir_first)
        {
-         game_status = CHOOSELEVEL;
+         game_status = GAME_MODE_LEVELS;
          SaveLevelSetup_LastSeries();
          SaveLevelSetup_SeriesInfo();
 
@@ -424,7 +411,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
       }
       else if (y == 2)
       {
-       game_status = HALLOFFAME;
+       game_status = GAME_MODE_SCORES;
        DrawHallOfFame(-1);
       }
       else if (y == 3)
@@ -432,12 +419,12 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
        if (leveldir_current->readonly &&
            strcmp(setup.player_name, "Artsoft") != 0)
          Request("This level is read only !", REQ_CONFIRM);
-       game_status = LEVELED;
+       game_status = GAME_MODE_EDITOR;
        DrawLevelEd();
       }
       else if (y == 4)
       {
-       game_status = HELPSCREEN;
+       game_status = GAME_MODE_INFO;
        DrawHelpScreen();
       }
       else if (y == 5)
@@ -451,14 +438,14 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
        else
 #endif
        {
-         game_status = PLAYING;
+         game_status = GAME_MODE_PLAYING;
          StopAnimation();
          InitGame();
        }
       }
       else if (y == 6)
       {
-       game_status = SETUP;
+       game_status = GAME_MODE_SETUP;
        setup_mode = SETUP_MODE_MAIN;
        DrawSetupScreen();
       }
@@ -467,7 +454,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
        SaveLevelSetup_LastSeries();
        SaveLevelSetup_SeriesInfo();
         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
-         game_status = EXITGAME;
+         game_status = GAME_MODE_QUIT;
       }
     }
   }
@@ -476,7 +463,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
   out:
 
-  if (game_status == MAINMENU)
+  if (game_status == GAME_MODE_MAIN)
   {
     DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
     DoAnimation();
@@ -579,15 +566,15 @@ static int helpscreen_action[] =
   IMG_KEY_3,                           50,
   IMG_KEY_4,                           50,                     HA_NEXT,
 
-  IMG_GATE_1_CLOSED,                   50,
-  IMG_GATE_2_CLOSED,                   50,
-  IMG_GATE_3_CLOSED,                   50,
-  IMG_GATE_4_CLOSED,                   50,                     HA_NEXT,
+  IMG_GATE_1,                          50,
+  IMG_GATE_2,                          50,
+  IMG_GATE_3,                          50,
+  IMG_GATE_4,                          50,                     HA_NEXT,
 
-  IMG_GATE_1_GRAY_CLOSED,              50,
-  IMG_GATE_2_GRAY_CLOSED,              50,
-  IMG_GATE_3_GRAY_CLOSED,              50,
-  IMG_GATE_4_GRAY_CLOSED,              50,                     HA_NEXT,
+  IMG_GATE_1_GRAY,                     50,
+  IMG_GATE_2_GRAY,                     50,
+  IMG_GATE_3_GRAY,                     50,
+  IMG_GATE_4_GRAY,                     50,                     HA_NEXT,
 
   IMG_DYNAMITE,                                -1,                     HA_NEXT,
 
@@ -1101,7 +1088,7 @@ void HandleHelpScreen(int button)
     {
       FadeSounds();
 
-      game_status = MAINMENU;
+      game_status = GAME_MODE_MAIN;
       DrawMainMenu();
     }
   }
@@ -1177,7 +1164,7 @@ void HandleTypeName(int newxpos, Key key)
     DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
 
     SaveSetup();
-    game_status = MAINMENU;
+    game_status = GAME_MODE_MAIN;
   }
 
   BackToFront();
@@ -1221,7 +1208,10 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
   int max_buffer_len = (SCR_FIELDX - 2) * 2;
   int num_entries = numTreeInfoInGroup(ti);
   char *title_string = NULL;
-  int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
+  int xoffset_setup = 16;
+  int yoffset_setup = 0;
+  int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
+  int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
   int last_game_status = game_status;  /* save current game status */
 
   DrawBackground(SX, SY, SXSIZE - 32, SYSIZE);
@@ -1233,9 +1223,10 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
      ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
      ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
 
-  DrawText(SX + offset, SY + offset, title_string, FONT_TITLE_1);
+  DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
 
-  game_status = CHOOSELEVEL;   /* force LEVELS font on artwork setup screen */
+  /* force LEVELS font on artwork setup screen */
+  game_status = GAME_MODE_LEVELS;
 
   for(i=0; i<num_page_entries; i++)
   {
@@ -1263,16 +1254,18 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
   {
     int ypos = 1;
 
-    DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
-    DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_UP, 0);
+    DrawBackground(mSX, mSY + ypos * TILEY, TILEX, TILEY);
+    DrawGraphicThruMaskExt(drawto, mSX, mSY + ypos * TILEY,
+                          IMG_MENU_BUTTON_UP, 0);
   }
 
   if (first_entry + num_page_entries < num_entries)
   {
     int ypos = MAX_MENU_ENTRIES_ON_SCREEN + 1;
 
-    DrawBackground(SX, SY + ypos * 32, TILEX, TILEY);
-    DrawGraphicThruMask(0, ypos, IMG_MENU_BUTTON_DOWN, 0);
+    DrawBackground(mSX, mSY + ypos * TILEY, TILEX, TILEY);
+    DrawGraphicThruMaskExt(drawto, mSX, mSY + ypos * TILEY,
+                          IMG_MENU_BUTTON_DOWN, 0);
   }
 
   game_status = last_game_status;      /* restore current game status */
@@ -1352,13 +1345,13 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       *ti_ptr = ti->node_parent;
       DrawChooseTree(ti_ptr);
     }
-    else if (game_status == SETUP)
+    else if (game_status == GAME_MODE_SETUP)
     {
       execSetupArtwork();
     }
     else
     {
-      game_status = MAINMENU;
+      game_status = GAME_MODE_MAIN;
       DrawMainMenu();
     }
 
@@ -1367,8 +1360,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
   if (mx || my)                /* mouse input */
   {
-    x = (mx - SX) / 32;
-    y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
+    x = (mx - mSX) / 32;
+    y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
   }
   else if (dx || dy)   /* keyboard input */
   {
@@ -1489,13 +1482,13 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
          TapeErase();
        }
 
-       if (game_status == SETUP)
+       if (game_status == GAME_MODE_SETUP)
        {
          execSetupArtwork();
        }
        else
        {
-         game_status = MAINMENU;
+         game_status = GAME_MODE_MAIN;
          DrawMainMenu();
        }
       }
@@ -1504,7 +1497,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
 
   BackToFront();
 
-  if (game_status == CHOOSELEVEL || game_status == SETUP)
+  if (game_status == GAME_MODE_LEVELS || game_status == GAME_MODE_SETUP)
     DoAnimation();
 }
 
@@ -1554,16 +1547,22 @@ static void drawHallOfFameList(int first_entry, int highlight_position)
   for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
   {
     int entry = first_entry + i;
+    boolean active = (entry == highlight_position);
+    int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
+    int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
+    int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
+    int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
+    int dx1 = 3 * getFontWidth(font_nr1);
+    int dx2 = dx1 + getFontWidth(font_nr1);
+    int dx3 = dx2 + 25 * getFontWidth(font_nr3);
+    int sy = mSY + 64 + i * 32;
 
-    DrawText(mSX, mSY + 64 + i * 32, "..................................",
-            (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
-    DrawText(mSX, mSY + 64 + i * 32, int2str(entry + 1, 3),
-            (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
-    DrawText(mSX + 64, mSY + 64 + i * 32, highscore[entry].Name,
-            (entry == highlight_position ? FONT_TEXT_3 : FONT_TEXT_1));
-    DrawText(mSX + 14 * 32 + 16, mSY + 64 + i * 32,
-            int2str(highscore[entry].Score, 5),
-            (entry == highlight_position ? FONT_TEXT_4 : FONT_TEXT_2));
+    DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
+    DrawText(mSX + dx1, sy, ".", font_nr1);
+    DrawText(mSX + dx2, sy, ".........................", font_nr3);
+    if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
+      DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
+    DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
   }
 }
 
@@ -1613,13 +1612,13 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
   if (button_released)
   {
     FadeSound(SND_BACKGROUND_SCORES);
-    game_status = MAINMENU;
+    game_status = GAME_MODE_MAIN;
     DrawMainMenu();
   }
 
   BackToFront();
 
-  if (game_status == HALLOFFAME)
+  if (game_status == GAME_MODE_SCORES)
   {
     DoAnimation();
 #if 1
@@ -1720,7 +1719,7 @@ static void execSetupShortcut()
 
 static void execExitSetup()
 {
-  game_status = MAINMENU;
+  game_status = GAME_MODE_MAIN;
   DrawMainMenu();
 }
 
@@ -2064,8 +2063,8 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
 
   if (mx || my)                /* mouse input */
   {
-    x = (mx - SX) / 32;
-    y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
+    x = (mx - mSX) / 32;
+    y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
   }
   else if (dx || dy)   /* keyboard input */
   {
@@ -2120,7 +2119,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
 
   BackToFront();
 
-  if (game_status == SETUP)
+  if (game_status == GAME_MODE_SETUP)
     DoAnimation();
 }
 
@@ -2275,8 +2274,8 @@ void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
 
   if (mx || my)                /* mouse input */
   {
-    x = (mx - SX) / 32;
-    y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
+    x = (mx - mSX) / 32;
+    y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
   }
   else if (dx || dy)   /* keyboard input */
   {
@@ -2366,7 +2365,7 @@ void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
 
   out:
 
-  if (game_status == SETUP)
+  if (game_status == GAME_MODE_SETUP)
     DoAnimation();
 }
 
@@ -2730,7 +2729,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
 
 void HandleGameActions()
 {
-  if (game_status != PLAYING)
+  if (game_status != GAME_MODE_PLAYING)
     return;
 
   if (local_player->LevelSolved)
@@ -2742,6 +2741,11 @@ void HandleGameActions()
   GameActions();
 
   BackToFront();
+
+#if 1
+  if (tape.auto_play && !tape.playing)
+    AutoPlayTape();    /* continue automatically playing next tape */
+#endif
 }
 
 /* ---------- new screen button stuff -------------------------------------- */
@@ -3003,29 +3007,29 @@ static void HandleScreenGadgets(struct GadgetInfo *gi)
 {
   int id = gi->custom_id;
 
-  if (game_status != CHOOSELEVEL && game_status != SETUP)
+  if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
     return;
 
   switch (id)
   {
     case SCREEN_CTRL_ID_SCROLL_UP:
-      if (game_status == CHOOSELEVEL)
-       HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
-      else if (game_status == SETUP)
-       HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
+      if (game_status == GAME_MODE_LEVELS)
+       HandleChooseLevel(mSX,mSY + 32, 0,0, MB_MENU_MARK);
+      else if (game_status == GAME_MODE_SETUP)
+       HandleSetupScreen(mSX,mSY + 32, 0,0, MB_MENU_MARK);
       break;
 
     case SCREEN_CTRL_ID_SCROLL_DOWN:
-      if (game_status == CHOOSELEVEL)
-       HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
-      else if (game_status == SETUP)
-       HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
+      if (game_status == GAME_MODE_LEVELS)
+       HandleChooseLevel(mSX,mSY + SYSIZE - 32, 0,0, MB_MENU_MARK);
+      else if (game_status == GAME_MODE_SETUP)
+       HandleSetupScreen(mSX,mSY + SYSIZE - 32, 0,0, MB_MENU_MARK);
       break;
 
     case SCREEN_CTRL_ID_SCROLL_VERTICAL:
-      if (game_status == CHOOSELEVEL)
+      if (game_status == GAME_MODE_LEVELS)
        HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
-      else if (game_status == SETUP)
+      else if (game_status == GAME_MODE_SETUP)
        HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
       break;