added basic support for user name selection screen (not used yet)
authorHolger Schemel <info@artsoft.org>
Sun, 18 Oct 2020 00:52:13 +0000 (02:52 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:57:57 +0000 (00:57 +0100)
src/events.c
src/libgame/system.h
src/screens.c
src/screens.h

index b4f7594837de7fedf1a1cb8b93260437e4605962..a5bbf458ccc3f91381023161f01d945b75bd819a 100644 (file)
@@ -1752,6 +1752,10 @@ void HandleButton(int mx, int my, int button, int button_nr)
       HandleTypeName(KSYM_Return);
       break;
 
+    case GAME_MODE_NAMES:
+      HandleChoosePlayerName(mx, my, 0, 0, button);
+      break;
+
     case GAME_MODE_LEVELS:
       HandleChooseLevelSet(mx, my, 0, 0, button);
       break;
@@ -2302,6 +2306,7 @@ void HandleKey(Key key, int key_status)
 
     case GAME_MODE_TITLE:
     case GAME_MODE_MAIN:
+    case GAME_MODE_NAMES:
     case GAME_MODE_LEVELS:
     case GAME_MODE_LEVELNR:
     case GAME_MODE_SETUP:
@@ -2319,6 +2324,8 @@ void HandleKey(Key key, int key_status)
            HandleTitleScreen(0, 0, 0, 0, MB_MENU_CHOICE);
          else if (game_status == GAME_MODE_MAIN)
            HandleMainMenu(0, 0, 0, 0, MB_MENU_CHOICE);
+          else if (game_status == GAME_MODE_NAMES)
+            HandleChoosePlayerName(0, 0, 0, 0, MB_MENU_CHOICE);
           else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevelSet(0, 0, 0, 0, MB_MENU_CHOICE);
           else if (game_status == GAME_MODE_LEVELNR)
@@ -2337,6 +2344,8 @@ void HandleKey(Key key, int key_status)
 
          if (game_status == GAME_MODE_TITLE)
            HandleTitleScreen(0, 0, 0, 0, MB_MENU_LEAVE);
+          else if (game_status == GAME_MODE_NAMES)
+            HandleChoosePlayerName(0, 0, 0, 0, MB_MENU_LEAVE);
           else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevelSet(0, 0, 0, 0, MB_MENU_LEAVE);
           else if (game_status == GAME_MODE_LEVELNR)
@@ -2350,7 +2359,9 @@ void HandleKey(Key key, int key_status)
          break;
 
         case KSYM_Page_Up:
-          if (game_status == GAME_MODE_LEVELS)
+          if (game_status == GAME_MODE_NAMES)
+            HandleChoosePlayerName(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
+          else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevelSet(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
           else if (game_status == GAME_MODE_LEVELNR)
             HandleChooseLevelNr(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
@@ -2363,7 +2374,9 @@ void HandleKey(Key key, int key_status)
          break;
 
         case KSYM_Page_Down:
-          if (game_status == GAME_MODE_LEVELS)
+          if (game_status == GAME_MODE_NAMES)
+            HandleChoosePlayerName(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
+          else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevelSet(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
           else if (game_status == GAME_MODE_LEVELNR)
             HandleChooseLevelNr(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
@@ -2594,6 +2607,7 @@ void HandleJoystick(void)
   {
     case GAME_MODE_TITLE:
     case GAME_MODE_MAIN:
+    case GAME_MODE_NAMES:
     case GAME_MODE_LEVELS:
     case GAME_MODE_LEVELNR:
     case GAME_MODE_SETUP:
@@ -2607,6 +2621,8 @@ void HandleJoystick(void)
        HandleTitleScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
       else if (game_status == GAME_MODE_MAIN)
        HandleMainMenu(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
+      else if (game_status == GAME_MODE_NAMES)
+        HandleChoosePlayerName(0,0,dx,dy,newbutton?MB_MENU_CHOICE:MB_MENU_MARK);
       else if (game_status == GAME_MODE_LEVELS)
         HandleChooseLevelSet(0,0,dx,dy,newbutton?MB_MENU_CHOICE : MB_MENU_MARK);
       else if (game_status == GAME_MODE_LEVELNR)
index 2011aaacf3e6932985f32011b946555c7199b8e2..549d003e45bfda2fda5529629c4535c3ea4e0ef1 100644 (file)
 #define TREE_TYPE_MUSIC_DIR    ARTWORK_TYPE_MUSIC
 #define TREE_TYPE_LEVEL_DIR    3
 #define TREE_TYPE_LEVEL_NR     4
+#define TREE_TYPE_PLAYER_NAME  5
+#define TREE_TYPE_PLAYER_TEAM  6
 
 #define NUM_BASE_TREE_TYPES    4
-#define NUM_TREE_TYPES         5
+#define NUM_TREE_TYPES         7
 
 #define INFOTEXT_UNDEFINED     ""
 #define INFOTEXT_GRAPHICS_DIR  "Custom Graphics"
 #define INFOTEXT_MUSIC_DIR     "Custom Music"
 #define INFOTEXT_LEVEL_DIR     "Level Sets"
 #define INFOTEXT_LEVEL_NR      "Levels"
-
-#define TREE_INFOTEXT(t)       ((t) == TREE_TYPE_LEVEL_NR ?            \
+#define INFOTEXT_PLAYER_NAME   "Player Names"
+#define INFOTEXT_PLAYER_TEAM   "Player Teams"
+
+#define TREE_INFOTEXT(t)       ((t) == TREE_TYPE_PLAYER_NAME ?         \
+                                INFOTEXT_PLAYER_NAME :                 \
+                                (t) == TREE_TYPE_PLAYER_TEAM ?         \
+                                INFOTEXT_PLAYER_TEAM :                 \
+                                (t) == TREE_TYPE_LEVEL_NR ?            \
                                 INFOTEXT_LEVEL_NR :                    \
                                 (t) == TREE_TYPE_LEVEL_DIR ?           \
                                 INFOTEXT_LEVEL_DIR :                   \
index 040a45c56a47dbdadc2d61af9d8d63be172c2889..95b56934b1ba724ec404442afd310387fdf2d829 100644 (file)
@@ -248,6 +248,7 @@ static void execSetupTouch(void);
 static void execSetupArtwork(void);
 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
 
+static void DrawChoosePlayerName(void);
 static void DrawChooseLevelSet(void);
 static void DrawChooseLevelNr(void);
 static void DrawInfoScreen(void);
@@ -327,6 +328,9 @@ static TreeInfo *transparency_current = NULL;
 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
 
+static TreeInfo *player_name = NULL;
+static TreeInfo *player_name_current = NULL;
+
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
@@ -2081,9 +2085,20 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
        }
        else
        {
-         SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
+         if (0 && setup.multiple_users)        // (not used yet)
+         {
+           CloseDoor(DOOR_CLOSE_2);
+
+           SetGameStatus(GAME_MODE_NAMES);
 
-         DrawTypeName();
+           DrawChoosePlayerName();
+         }
+         else
+         {
+           SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
+
+           DrawTypeName();
+         }
        }
       }
       else if (pos == MAIN_CONTROL_LEVELS)
@@ -4123,7 +4138,9 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   // needed if different viewport properties defined for choosing level (set)
   ChangeViewportPropertiesIfNeeded();
 
-  if (game_status == GAME_MODE_LEVELNR)
+  if (game_status == GAME_MODE_NAMES)
+    SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
+  else if (game_status == GAME_MODE_LEVELNR)
     SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
   else if (game_status == GAME_MODE_LEVELS)
     SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
@@ -4565,6 +4582,65 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   }
 }
 
+void DrawChoosePlayerName(void)
+{
+  int i;
+
+  FadeMenuSoundsAndMusic();
+
+  if (player_name != NULL)
+  {
+    freeTreeInfo(player_name);
+
+    player_name = NULL;
+  }
+
+  for (i = 0; i < MAX_PLAYER_NAMES; i++)
+  {
+    boolean team_mode = (!network.enabled && setup.team_mode);
+    int tree_type = (team_mode ? TREE_TYPE_PLAYER_TEAM : TREE_TYPE_PLAYER_NAME);
+    TreeInfo *ti = newTreeInfo_setDefaults(tree_type);
+    char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
+    int value = i;
+
+    ti->node_top = &player_name;
+    ti->sort_priority = 10000 + value;
+    ti->color = FC_RED;
+
+    if (strEqual(global.user_names[i], EMPTY_PLAYER_NAME))
+      ti->color = FC_BLUE;
+
+    snprintf(identifier, sizeof(identifier), "%d", value);
+    snprintf(name, sizeof(name), "%s", global.user_names[i]);
+
+    setString(&ti->identifier, identifier);
+    setString(&ti->name, name);
+    setString(&ti->name_sorting, name);
+
+    pushTreeInfo(&player_name, ti);
+  }
+
+  // sort player entries by player number
+  sortTreeInfo(&player_name);
+
+  // set current player entry to selected player entry
+  player_name_current =
+    getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
+
+  // if that fails, set current player name to first available name
+  if (player_name_current == NULL)
+    player_name_current = player_name;
+
+  DrawChooseTree(&player_name_current);
+
+  PlayMenuSoundsAndMusic();
+}
+
+void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
+{
+  HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
+}
+
 void DrawChooseLevelSet(void)
 {
   FadeMenuSoundsAndMusic();
@@ -9074,7 +9150,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi)
       break;
 
     case SCREEN_CTRL_ID_SCROLL_UP:
-      if (game_status == GAME_MODE_LEVELS)
+      if (game_status == GAME_MODE_NAMES)
+       HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
+      else if (game_status == GAME_MODE_LEVELS)
        HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
       else if (game_status == GAME_MODE_LEVELNR)
        HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
@@ -9085,7 +9163,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi)
       break;
 
     case SCREEN_CTRL_ID_SCROLL_DOWN:
-      if (game_status == GAME_MODE_LEVELS)
+      if (game_status == GAME_MODE_NAMES)
+       HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
+      else if (game_status == GAME_MODE_LEVELS)
        HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
       else if (game_status == GAME_MODE_LEVELNR)
        HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
@@ -9096,7 +9176,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi)
       break;
 
     case SCREEN_CTRL_ID_SCROLL_VERTICAL:
-      if (game_status == GAME_MODE_LEVELS)
+      if (game_status == GAME_MODE_NAMES)
+       HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
+      else if (game_status == GAME_MODE_LEVELS)
        HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
       else if (game_status == GAME_MODE_LEVELNR)
        HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
index 3cb08c1eec94846834c799118159f92dd76ea94c..d79745df4623a89a016d6b9c3ec79ed4bae2444e 100644 (file)
@@ -30,6 +30,7 @@ void RedrawSetupScreenAfterScreenRotation(int);
 
 void HandleTitleScreen(int, int, int, int, int);
 void HandleMainMenu(int, int, int, int, int);
+void HandleChoosePlayerName(int, int, int, int, int);
 void HandleChooseLevelSet(int, int, int, int, int);
 void HandleChooseLevelNr(int, int, int, int, int);
 void HandleHallOfFame(int, int, int, int, int);