added drawing network players (graphics and names) to main menu screen
authorHolger Schemel <info@artsoft.org>
Sun, 1 Jul 2018 23:12:57 +0000 (01:12 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 1 Jul 2018 23:12:57 +0000 (01:12 +0200)
src/conf_gfx.c
src/libgame/system.h
src/main.c
src/main.h
src/network.c
src/network.h
src/screens.c
src/tools.c
src/tools.h

index d24150738af9202d140e95b417e273212dbec91b..6cc2ebabbd0290aede51adbb574aa76fe72b6f49 100644 (file)
@@ -6674,6 +6674,9 @@ struct ConfigInfo image_config[] =
   { "font.info.levelset",                      UNDEFINED_FILENAME      },
   { "font.info.levelset.clone_from",           "font.level_number"     },
 
+  { "font.main.network_players",               UNDEFINED_FILENAME      },
+  { "font.main.network_players.clone_from",    "font.level_number"     },
+
   { "editor.element_border",                   "RocksMore.png"         },
   { "editor.element_border.xpos",              "0"                     },
   { "editor.element_border.ypos",              "2"                     },
@@ -8064,6 +8067,13 @@ struct ConfigInfo image_config[] =
   { "main.input.name.valign",                  "top"                   },
   { "main.input.name.font",                    "font.input_1"          },
 
+  { "main.network_players.x",                  "68"                    },
+  { "main.network_players.y",                  "448"                   },
+  { "main.network_players.align",              "center"                },
+  { "main.network_players.valign",             "middle"                },
+  { "main.network_players.font",               "font.main.network_players" },
+  { "main.network_players.tile_size",          "16"                    },
+
   { "preview.x",                               "272"                   },
   { "preview.y",                               "380"                   },
   { "preview.align",                           "center"                },
index 039f328e1a3fbdafca496c64585c377b4dc270e6..839a52586fb5fba4268eb297cf50c99f44841e85 100644 (file)
@@ -1551,6 +1551,8 @@ struct TextPosInfo
   int direction;               /* needed for panel time/health graphics */
   int class;                   /* needed for panel time/health graphics */
   int style;                   /* needed for panel time/health graphics */
+
+  int tile_size;               /* special case for list of network players */
 };
 
 struct MouseActionInfo
index b46609a18602558b3223bc72469dd66ee38c79f7..312cb2cbb1eb5ac170a1ac265faa27c6eb32150a 100644 (file)
@@ -7492,6 +7492,7 @@ struct FontInfo font_info[NUM_FONTS + 1] =
   { "font.game_info"           },
   { "font.info.elements"       },
   { "font.info.levelset"       },
+  { "font.main.network_players"        },
 
   { NULL                       }
 };
index b71bb3cef6ad46165484a3fff54cd67ed82556c3..1ee2037ae68101f7d156027795f719f5c7d448e0 100644 (file)
 #define FONT_GAME_INFO                 39
 #define FONT_INFO_ELEMENTS             40
 #define FONT_INFO_LEVELSET             41
+#define FONT_MAIN_NETWORK_PLAYERS      42
 
-#define NUM_FONTS                      42
+#define NUM_FONTS                      43
 #define NUM_INITIAL_FONTS              4
 
 /* values for toon animation configuration */
@@ -2684,6 +2685,8 @@ struct MenuMainInfo
   struct MenuMainButtonInfo button;
   struct MenuMainTextInfo text;
   struct MenuMainInputInfo input;
+
+  struct TextPosInfo network_players;
 };
 
 struct TitleFadingInfo
index 656c0ab988d12c9e385205f31618d65b978584b2..6f06d610392aa6d6d3b36c11b2af5315254b6381 100644 (file)
@@ -518,6 +518,9 @@ static void Handle_OP_NUMBER_WANTED()
     Error(ERR_NETWORK_CLIENT, "cannot switch -- you keep client # %d",
          new_client_nr);
   }
+
+  if (game_status == GAME_MODE_MAIN)
+    DrawNetworkPlayers();
 }
 
 static void Handle_OP_PLAYER_NAME(unsigned int len)
@@ -591,6 +594,10 @@ static void Handle_OP_PLAYER_DISCONNECTED()
 
     DrawMainMenu();
   }
+  else if (game_status == GAME_MODE_MAIN)
+  {
+    DrawNetworkPlayers();
+  }
 }
 
 static void Handle_OP_START_PLAYING()
index fbbea6dbb1495ee9bc9300e76a01acdb4cf1582e..c682105ce89a7b3985e7e68e1ef872b512183a13 100644 (file)
@@ -17,6 +17,8 @@
 #define NETWORK_STOP_BY_PLAYER         0
 #define NETWORK_STOP_BY_ERROR          1
 
+char *getNetworkPlayerName(int);
+
 boolean ConnectToServer(char *, int);
 void SendToServer_PlayerName(char *);
 void SendToServer_ProtocolVersion(void);
index 3eab4a7343e9235371708e03f4e4b2bdea08dd83..758e536d29a16b17e97e7bdc095e29d094ea8f6e 100644 (file)
@@ -1642,6 +1642,7 @@ void DrawMainMenu()
 
   DrawCursorAndText_Main(-1, FALSE, FALSE);
   DrawPreviewLevelInitial();
+  DrawNetworkPlayers();
 
   HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
 
index aac531f02f3964afc8504d3cbbbe3372c67628b4..b0773082c16981783208ab5c7c815a2b2790ea6e 100644 (file)
@@ -3514,6 +3514,85 @@ void DrawPreviewLevelAnimation()
   DrawPreviewLevelExt(FALSE);
 }
 
+static void DrawNetworkPlayer(int x, int y, int player_nr, int tile_size,
+                             int border_size, int font_nr)
+{
+  int graphic = el2img(EL_PLAYER_1 + player_nr);
+  int font_height = getFontHeight(font_nr);
+  int player_height = MAX(tile_size, font_height);
+  int xoffset_text = tile_size + border_size;
+  int yoffset_text    = (player_height - font_height) / 2;
+  int yoffset_graphic = (player_height - tile_size) / 2;
+  char *player_name = getNetworkPlayerName(player_nr + 1);
+
+  DrawSizedGraphicThruMaskExt(drawto, x, y + yoffset_graphic, graphic, 0,
+                             tile_size);
+  DrawText(x + xoffset_text, y + yoffset_text, player_name, font_nr);
+}
+
+void DrawNetworkPlayers()
+{
+  if (!network.enabled || !network.connected)
+    return;
+
+  int num_players = 0;
+  int i;
+
+  for (i = 0; i < MAX_PLAYERS; i++)
+    if (stored_player[i].connected_network)
+      num_players++;
+
+  struct TextPosInfo *pos = &menu.main.network_players;
+  int tile_size = pos->tile_size;
+  int border_size = 2;
+  int xoffset_text = tile_size + border_size;
+  int font_nr = pos->font;
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int player_height = MAX(tile_size, font_height);
+  int player_yoffset = player_height + border_size;
+  int max_players_width = xoffset_text + MAX_PLAYER_NAME_LEN * font_width;
+  int max_players_height = MAX_PLAYERS * player_yoffset - border_size;
+  int all_players_height = num_players * player_yoffset - border_size;
+  int max_xpos = SX + ALIGNED_XPOS(pos->x, max_players_width,  pos->align);
+  int max_ypos = SY + ALIGNED_YPOS(pos->y, max_players_height, pos->valign);
+  int ypos = SY + ALIGNED_YPOS(pos->y, all_players_height, pos->valign);
+
+  ClearRectangleOnBackground(drawto, max_xpos, max_ypos,
+                            max_players_width, max_players_height);
+
+  /* first draw local network player ... */
+  for (i = 0; i < MAX_PLAYERS; i++)
+  {
+    if (stored_player[i].connected_locally)
+    {
+      char *player_name = getNetworkPlayerName(i + 1);
+      int player_width = xoffset_text + getTextWidth(player_name, font_nr);
+      int xpos = SX + ALIGNED_XPOS(pos->x, player_width,  pos->align);
+
+      DrawNetworkPlayer(xpos, ypos, i, tile_size, border_size, font_nr);
+
+      ypos += player_yoffset;
+    }
+  }
+
+  /* ... then draw all other network players */
+  for (i = 0; i < MAX_PLAYERS; i++)
+  {
+    if (stored_player[i].connected_network &&
+       !stored_player[i].connected_locally)
+    {
+      char *player_name = getNetworkPlayerName(i + 1);
+      int player_width = xoffset_text + getTextWidth(player_name, font_nr);
+      int xpos = SX + ALIGNED_XPOS(pos->x, player_width,  pos->align);
+
+      DrawNetworkPlayer(xpos, ypos, i, tile_size, border_size, font_nr);
+
+      ypos += player_yoffset;
+    }
+  }
+}
+
 inline static void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
                                           int graphic, int sync_frame,
                                           int mask_mode)
index 5d9bdccebc31566065e7011769b7c2075ab368a9..61541f370287d7bf5ebb9f4a85706aa055642e99 100644 (file)
@@ -197,6 +197,8 @@ void DrawMiniLevel(int, int, int, int);
 void DrawPreviewLevelInitial(void);
 void DrawPreviewLevelAnimation(void);
 
+void DrawNetworkPlayers(void);
+
 void WaitForEventToContinue(void);
 boolean Request(char *, unsigned int);
 void InitGraphicCompatibilityInfo_Doors(void);