Modified GameCreationMenu to make it use PlayersColors (goal -> remove SDL_Colors from model (+easier for some functions))

origin/fixingSettings
marouault 3 years ago
parent c433025706
commit a841982dc5

@ -58,16 +58,17 @@ int main(int argc, char *argv[]) {
size_t nbPlayers = 2;
Player* players = (Player*)malloc(sizeof(Player)*2);
players[0] = newPlayer("Bépo", PlayerViolet);
players[1] = newPlayer("Azeryty", PlayerYellow);
/*players[0] = newPlayer("Bépo", PlayerViolet);
players[1] = newPlayer("Azeryty", PlayerYellow);*/
//players[2] = newPlayer("Adcsg", PlayerRed);
//bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers);
bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers);
/* if (crashed) {
if (crashed) {
fprintf(stderr,"sorry");
exit(-1);
}*/
}
generalState = GS_Game;
gameView(&generalState, window, renderer, players, nbPlayers);

@ -7,7 +7,7 @@
//#include "../test/testDrawMainMenu.c
//#include "../test/testSettingsView.c"
#include "../test/testCreationMenu.c"
#include "../test/testGameInterface.c"
//#include "../test/testGameInterface.c"
//#include "../test/testConnectionMenu.c"
//#include "../test/testDrawMainMenu.c"
//#include "../test/testSettingsView.c"
@ -26,10 +26,10 @@ int main(int argc, char *argv[]) {
//testConnectionMenu();
//testMenuEndGame();
//testButton();
testGameInterface();
//testGameInterface();
//testConnectionMenu();
//testDrawMainMenu();
//testCreationMenu();
testCreationMenu();
//testSettingsView();
return 0;

@ -7,9 +7,7 @@ extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND;
extern const SDL_Color COLOR_GENERIC_BUTTON_BORDER;
extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER;
extern const SDL_Color PLAYER_ONE_COLOR;
extern const SDL_Color PLAYER_TWO_COLOR;
extern const SDL_Color PLAYER_THREE_COLOR;
extern const SDL_Color PLAYER_FOUR_COLOR;
extern const SDL_Color PLAYER_SDL_COLORS[];
#endif

@ -1,11 +1,20 @@
#ifndef PLAYERS_COLORS_INCLUDED
#define PLAYERS_COLORS_INCLUDED
#define MACRO_FOR_EACH_PLAYER_COLOR(M) \
M(Red) \
M(Violet) \
M(Blue) \
M(Yellow)
#define MACRO_GEN_ENUM_PLAYER_COLOR(Elem) Player##Elem,
typedef enum {
PlayerRed,
PlayerViolet,
PlayerBlue,
PlayerYellow
MACRO_FOR_EACH_PLAYER_COLOR(MACRO_GEN_ENUM_PLAYER_COLOR)
NB_PLAYER_COLORS
} PlayersColors;
extern const PlayersColors playersColors[];
#endif //PLAYERS_COLORS_INCLUDED

@ -30,7 +30,7 @@ typedef struct
typedef struct
{
Player* p;
SDL_Color color;
PlayersColors color;
} ChangeColorParams;
typedef struct

@ -4,7 +4,10 @@ const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND = {225, 225, 225, 255};
const SDL_Color COLOR_GENERIC_BUTTON_BORDER = {10, 10, 10, 255};
const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER = {250, 250, 250, 255};
const SDL_Color PLAYER_ONE_COLOR = {166, 58, 252, 255};
const SDL_Color PLAYER_TWO_COLOR = {14, 159, 100, 255};
const SDL_Color PLAYER_THREE_COLOR = {240, 45, 45, 255};
const SDL_Color PLAYER_FOUR_COLOR = {255, 255, 255, 255};
const SDL_Color PLAYER_SDL_COLORS[] = {//Order mater (need to be the same as in model/PlayersColors.h)
{241, 0, 4 , 255}, // Red
{175, 0, 202, 255}, // Violet
{6 , 0, 202, 255}, // Blue
{202, 152, 0, 255}, // Yellow
};

@ -0,0 +1,6 @@
#include "model/PlayersColors.h"
const PlayersColors playersColors[] = {
MACRO_FOR_EACH_PLAYER_COLOR(MACRO_GEN_ENUM_PLAYER_COLOR)
};

@ -107,12 +107,7 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int
int const hColorBtn = 32;
int const colorBtnXMargin = 8;
SDL_Texture* btnTexture, *btnTextureHover;
SDL_Color const colors[NB_COLORS]= {
PLAYER_ONE_COLOR,
PLAYER_TWO_COLOR,
PLAYER_THREE_COLOR,
PLAYER_FOUR_COLOR
};
P_Button* colorsBtn = (P_Button*) malloc(sizeof(P_Button)*NB_COLORS);
P_Button ai = createButton(NULL, NULL, xmin, y, 0, 0, NULL);
@ -134,11 +129,11 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int
{
params = (ChangeColorParams*) malloc(sizeof(ChangeColorParams));
params->p = player;
params->color=colors[i];
params->color=playersColors[i];
colorsBtn[i] = createButton(NULL, NULL, xmax-wColorBtn*(i+1), y, wColorBtn, hColorBtn, changePlayerColor);
colorsBtn[i].arg = params;
btnTexture = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BORDER, colors[i], 4, 8, NULL, NULL, renderer);
btnTextureHover = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BACKGROUND, colors[i], 4, 8, NULL, NULL, renderer);
btnTexture = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BORDER, PLAYER_SDL_COLORS[i], 4, 8, NULL, NULL, renderer);
btnTextureHover = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BACKGROUND, PLAYER_SDL_COLORS[i], 4, 8, NULL, NULL, renderer);
colorsBtn[i].texture = btnTexture;
colorsBtn[i].hoverTexture = btnTextureHover;

Loading…
Cancel
Save