From: Holger Schemel Date: Wed, 4 Jul 2018 22:35:27 +0000 (+0200) Subject: added drawing players with level preview when using network or team mode X-Git-Tag: 4.1.1.0~86 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7ffc20bb526bb0fe79bfbf206cb5b76cb3c9f052;p=rocksndiamonds.git added drawing players with level preview when using network or team mode --- diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 6cc2ebab..ed906604 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -8074,6 +8074,16 @@ struct ConfigInfo image_config[] = { "main.network_players.font", "font.main.network_players" }, { "main.network_players.tile_size", "16" }, + { "main.preview_players.x", "474" }, + { "main.preview_players.y", "448" }, + { "main.preview_players.align", "center" }, + { "main.preview_players.valign", "middle" }, + { "main.preview_players.tile_size", "32" }, + { "main.preview_players.border_size", "2" }, + { "main.preview_players.vertical", "false" }, + { "main.preview_players.xoffset", "-1" }, + { "main.preview_players.yoffset", "-1" }, + { "preview.x", "272" }, { "preview.y", "380" }, { "preview.align", "center" }, diff --git a/src/libgame/system.h b/src/libgame/system.h index 839a5258..5e61476f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1539,6 +1539,7 @@ struct TextPosInfo int x, y; int xoffset; /* special case for tape date and time */ int xoffset2; /* special case for tape date */ + int yoffset; /* special case for list of preview players */ int width, height; int align, valign; int size; /* also used for suffix ".digits" */ @@ -1553,6 +1554,8 @@ struct TextPosInfo int style; /* needed for panel time/health graphics */ int tile_size; /* special case for list of network players */ + int border_size; /* special case for list of preview players */ + int vertical; /* special case for list of preview players */ }; struct MouseActionInfo diff --git a/src/main.h b/src/main.h index 1ee2037a..0f7f6637 100644 --- a/src/main.h +++ b/src/main.h @@ -2686,6 +2686,7 @@ struct MenuMainInfo struct MenuMainTextInfo text; struct MenuMainInputInfo input; + struct TextPosInfo preview_players; struct TextPosInfo network_players; }; diff --git a/src/tools.c b/src/tools.c index ec52e93e..4fed1cd9 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3504,9 +3504,85 @@ static void DrawPreviewLevelExt(boolean restart) } } +void DrawPreviewPlayers() +{ + if (game_status != GAME_MODE_MAIN) + return; + + if (!network.enabled && !setup.team_mode) + return; + + boolean player_found[MAX_PLAYERS]; + int num_players = 0; + int i, x, y; + + for (i = 0; i < MAX_PLAYERS; i++) + player_found[i] = FALSE; + + /* check which players can be found in the level (simple approach) */ + for (x = 0; x < lev_fieldx; x++) + { + for (y = 0; y < lev_fieldy; y++) + { + int element = level.field[x][y]; + + if (ELEM_IS_PLAYER(element)) + { + int player_nr = GET_PLAYER_NR(element); + + player_nr = MIN(MAX(0, player_nr), MAX_PLAYERS - 1); + + if (!player_found[player_nr]) + num_players++; + + player_found[player_nr] = TRUE; + } + } + } + + struct TextPosInfo *pos = &menu.main.preview_players; + int tile_size = pos->tile_size; + int border_size = pos->border_size; + int player_xoffset_raw = (pos->vertical ? 0 : tile_size + border_size); + int player_yoffset_raw = (pos->vertical ? tile_size + border_size : 0); + int player_xoffset = (pos->xoffset != -1 ? pos->xoffset : player_xoffset_raw); + int player_yoffset = (pos->yoffset != -1 ? pos->yoffset : player_yoffset_raw); + int max_players_width = (MAX_PLAYERS - 1) * player_xoffset + tile_size; + int max_players_height = (MAX_PLAYERS - 1) * player_yoffset + tile_size; + int all_players_width = (num_players - 1) * player_xoffset + tile_size; + int all_players_height = (num_players - 1) * player_yoffset + tile_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 xpos = SX + ALIGNED_XPOS(pos->x, all_players_width, pos->align); + int ypos = SY + ALIGNED_YPOS(pos->y, all_players_height, pos->valign); + + /* clear area in which the players will be drawn */ + ClearRectangleOnBackground(drawto, max_xpos, max_ypos, + max_players_width, max_players_height); + + /* only draw players if level is suited for team mode */ + if (num_players < 2) + return; + + /* draw all players that were found in the level */ + for (i = 0; i < MAX_PLAYERS; i++) + { + if (player_found[i]) + { + int graphic = el2img(EL_PLAYER_1 + i); + + DrawSizedGraphicThruMaskExt(drawto, xpos, ypos, graphic, 0, tile_size); + + xpos += player_xoffset; + ypos += player_yoffset; + } + } +} + void DrawPreviewLevelInitial() { DrawPreviewLevelExt(TRUE); + DrawPreviewPlayers(); } void DrawPreviewLevelAnimation()