added drawing players with level preview when using network or team mode
authorHolger Schemel <info@artsoft.org>
Wed, 4 Jul 2018 22:35:27 +0000 (00:35 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 4 Jul 2018 22:37:16 +0000 (00:37 +0200)
src/conf_gfx.c
src/libgame/system.h
src/main.h
src/tools.c

index 6cc2ebabbd0290aede51adbb574aa76fe72b6f49..ed90660431767af6f830d84d426992ce6b796d3a 100644 (file)
@@ -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"                },
index 839a52586fb5fba4268eb297cf50c99f44841e85..5e61476f721fa110f262056acdf03977d0eba3a5 100644 (file)
@@ -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
index 1ee2037ae68101f7d156027795f719f5c7d448e0..0f7f6637c78057ba79fe1d800691ef05af83fe7a 100644 (file)
@@ -2686,6 +2686,7 @@ struct MenuMainInfo
   struct MenuMainTextInfo text;
   struct MenuMainInputInfo input;
 
+  struct TextPosInfo preview_players;
   struct TextPosInfo network_players;
 };
 
index ec52e93e56816447bdf7d8d31c162c231f47f448..4fed1cd982a7223367deaee0ce8e1b2c26cb6327 100644 (file)
@@ -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()