From: Holger Schemel Date: Sun, 1 Jul 2018 23:12:57 +0000 (+0200) Subject: added drawing network players (graphics and names) to main menu screen X-Git-Tag: 4.1.1.0~90 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=dad6457f2f778d11ad84e90d328981532d0ba0ea;p=rocksndiamonds.git added drawing network players (graphics and names) to main menu screen --- diff --git a/src/conf_gfx.c b/src/conf_gfx.c index d2415073..6cc2ebab 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -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" }, diff --git a/src/libgame/system.h b/src/libgame/system.h index 039f328e..839a5258 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -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 diff --git a/src/main.c b/src/main.c index b46609a1..312cb2cb 100644 --- a/src/main.c +++ b/src/main.c @@ -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 } }; diff --git a/src/main.h b/src/main.h index b71bb3ce..1ee2037a 100644 --- a/src/main.h +++ b/src/main.h @@ -2440,8 +2440,9 @@ #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 diff --git a/src/network.c b/src/network.c index 656c0ab9..6f06d610 100644 --- a/src/network.c +++ b/src/network.c @@ -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() diff --git a/src/network.h b/src/network.h index fbbea6db..c682105c 100644 --- a/src/network.h +++ b/src/network.h @@ -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); diff --git a/src/screens.c b/src/screens.c index 3eab4a73..758e536d 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1642,6 +1642,7 @@ void DrawMainMenu() DrawCursorAndText_Main(-1, FALSE, FALSE); DrawPreviewLevelInitial(); + DrawNetworkPlayers(); HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE); diff --git a/src/tools.c b/src/tools.c index aac531f0..b0773082 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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) diff --git a/src/tools.h b/src/tools.h index 5d9bdcce..61541f37 100644 --- a/src/tools.h +++ b/src/tools.h @@ -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);