marouault 3 years ago
commit f6d2d45f20

3
.gitignore vendored

@ -97,3 +97,6 @@ Documentation/doxygen/
# .idea since only 1 person uses CLion
Pontu/.idea/
*.swp

@ -86,7 +86,7 @@ int main(int argc, char *argv[]) {
}*/
//generalState = GS_Game;
gameView(&generalState, window, renderer, players, nbPlayers, &fontHandler);
gameView(&generalState, window, renderer, players, nbPlayers, &fontHandler,audioHandler);
//Pour tester le endGameMenu directement
/*

@ -10,9 +10,20 @@ void action_print(P_Button* caller);
/**
* @brief Button handle which set a generalState to GS_MainMenu
*
* @param caller The button clicked
*/
void action_setStateToMainMenu(P_Button* caller);
/**
* @brief Button handle wich mute the sound
* @param caller The button clicked
*/
void action_muteSound(P_Button* caller);
/**
* @brief Button handle which show Settings
* @param caller The button clicked
*/
void action_showSettings(P_Button* caller);
#endif //BUTTON_ACTION_INCLUDED

@ -10,6 +10,7 @@
#include "engine/Colors.h"
#include "model/Player.h"
#include "engine/TextInput.h"
#include "engine/AudioHandler.h"
#define NB_COLORS 4
#define NB_PLAYER_MAX 4
@ -48,6 +49,8 @@ typedef struct
CreateMenuLine* lines;
SDL_Renderer* renderer;
SDL_Color* bg;
InputProcessor* inproc;
Player players[4];
}IncrementParams;
typedef struct
@ -60,4 +63,4 @@ typedef struct
TTF_Font* font;
}DecrementParams;
bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, TTF_Font* font, int width, int height, Player players[], int* nbPlayers);
bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioHandler* ah, TTF_Font* font, int width, int height, Player players[], int* nbPlayers);

@ -13,21 +13,16 @@
#include <engine/FontLoader.h>
#include "engine/arrayButton.h"
#include "engine/GeneralState.h"
#include "engine/AudioHandler.h"
/**
* \brief Draw different buttons on the game interface : menu, setting, sound, nbTurn, and timers
* param Renderer
*/
void drawButtons(SDL_Renderer* renderer,FontHandler fontHandler);
/**
* \brief Create an array of P_Button for the game interface
* \param renderer The renderer on which we create P_buttons
* \param fontHandler The fontHandler to apply
* \return an array of P_Button to draw on the renderer
*/
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState);
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState, AudioHandler audioHandler);
/**

@ -5,7 +5,8 @@
#include <SDL2/SDL.h>
#include "model/Player.h"
#include "engine/FontLoader.h"
#include "engine/AudioHandler.h"
void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers, FontHandler* fontHandler);
void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers, FontHandler* fontHandler, AudioHandler audioHandler);
#endif //GAME_MAIN_INCLUDED

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@ -1,5 +1,6 @@
#include "engine/ButtonActions.h"
#include "engine/GeneralState.h"
#include "engine/AudioHandler.h"
void action_none(P_Button* caller) {
@ -14,3 +15,14 @@ void action_setStateToMainMenu(P_Button* caller)
{
*((GeneralState*)caller->arg) = GS_MainMenu;
}
void action_muteSound(P_Button* caller)
{
//Mute sound -> Master Volume = 0
AudioHandler audioHandler = *((AudioHandler*)caller->arg);
changeMasterVol(&audioHandler,0);
//Change Icon -> Mute icon
//caller->texture = createTextureFromPath(renderer,"rsrc/img/MuteResized.png");
}

@ -3,8 +3,8 @@
#include <SDL2/SDL_ttf.h>
void freeCreateMenuLine(CreateMenuLine* line);
CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int xmax, TTF_Font* font, Player* player);
void createPlayersLines(SDL_Renderer* renderer, TTF_Font* font, int minx, int maxx, int miny,int nbPlayer, CreateMenuLine* lines);
CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int xmax, TTF_Font* font, Player* player, InputProcessor* inproc);
void createPlayersLines(SDL_Renderer* renderer, TTF_Font* font, int minx, int maxx, int miny,int nbPlayer, CreateMenuLine* lines, InputProcessor* inproc, Player players[]);
bool drawGameCreationMenu(SDL_Renderer* renderer, TextLabel** labels, int nbLabels, P_Button* buttons, int nbButtons, CreateMenuLine* lines, int nbPlayer, const SDL_Color* bg);
bool drawCreateMenuLine(SDL_Renderer* renderer, CreateMenuLine* line);
void changePlayerColor(P_Button* caller);
@ -24,14 +24,14 @@ void incrementNbPlayer(P_Button* caller)
return;
}
createPlayersLines(params->renderer, params->font, params->minx, params->maxx, params->lines[*nbPlayers-1].h+params->lines[*nbPlayers-1].y, 1, &params->lines[*nbPlayers]);
createPlayersLines(params->renderer, params->font, params->minx, params->maxx, params->lines[*nbPlayers-1].h+params->lines[*nbPlayers-1].y, 1, &params->lines[*nbPlayers], params->inproc, params->players);
drawCreateMenuLine(params->renderer, &params->lines[*nbPlayers]);
++(*nbPlayers);
char nbPlayerStr[2] = {*nbPlayers + 48, 0};
replaceTextAndTextureOfTextLabel(params->renderer, params->nbPlayersLbl, params->font, nbPlayerStr, params->bg);
drawTextLabel(params->renderer, params->nbPlayersLbl);
SDL_RenderPresent(params->renderer);
//SDL_RenderPresent(params->renderer);
}
void decrementNbPlayer(P_Button* caller)
{
@ -56,7 +56,7 @@ void decrementNbPlayer(P_Button* caller)
freeCreateMenuLine(&params->lines[*nbPlayers]);
drawTextLabel(params->renderer, params->nbPlayersLbl);
SDL_RenderPresent(params->renderer);
//SDL_RenderPresent(params->renderer);
SDL_DestroyTexture(bedSheet);
}
@ -64,14 +64,17 @@ void changePlayerColor(P_Button* caller)
{
ChangeColorParams* params = (ChangeColorParams*)caller->arg;
params->p->color = params->color;
printf("change color %d\n", params->p->color);
fflush(stdout);
}
bool drawGameCreationMenu(SDL_Renderer* renderer, TextLabel** labels, int nbLabels, P_Button* buttons, int nbButtons, CreateMenuLine* lines, int nbPlayer, const SDL_Color* bg)
{
//Draw everything
//Draw background (blue-ish)
SDL_SetRenderDrawColor(renderer, bg->r, bg->g, bg->b, bg->a);
SDL_RenderClear(renderer);
// Buttons
for(int i=0; i<nbButtons; ++i)
{
if(!drawButtonOnRenderer(renderer, &(buttons[i])))
@ -81,10 +84,12 @@ bool drawGameCreationMenu(SDL_Renderer* renderer, TextLabel** labels, int nbLabe
}
}
// TextLabels
for(int i=0; i<nbLabels; ++i)
{
drawTextLabel(renderer, labels[i]);
}
// Menu lines (1 for each player)
for(int i=0; i<nbPlayer; ++i)
{
drawCreateMenuLine(renderer, &lines[i]);
@ -94,17 +99,17 @@ bool drawGameCreationMenu(SDL_Renderer* renderer, TextLabel** labels, int nbLabe
}
void createPlayersLines(SDL_Renderer* renderer, TTF_Font* font, int minx, int maxx, int miny,int nbPlayer, CreateMenuLine* lines)
void createPlayersLines(SDL_Renderer* renderer, TTF_Font* font, int minx, int maxx, int miny,int nbPlayer, CreateMenuLine* lines, InputProcessor* inproc, Player players[])
{
Player players[nbPlayer];
for(int i=0; i<nbPlayer; ++i)
{
if(i==0)
{
lines[i] = createCreateMenuLine(renderer, minx, miny + 16, maxx,font, &players[i]);
// Position of first line is absolute
lines[i] = createCreateMenuLine(renderer, minx, miny + 16, maxx,font, &players[i], inproc);
}else{
lines[i] = createCreateMenuLine(renderer, minx, miny + 16 + 16 + i* lines[i-1].aiButton.rect.h, maxx,font, &players[i]);
// Position of other lines is relative to the first one (16 px (margin) + nb_lines_already_drawn * height of AI checkbox)
lines[i] = createCreateMenuLine(renderer, minx, miny + 16 + 16 + i* lines[i-1].aiButton.rect.h, maxx,font, &players[i], inproc);
}
}
@ -113,16 +118,19 @@ void createPlayersLines(SDL_Renderer* renderer, TTF_Font* font, int minx, int ma
bool drawCreateMenuLine(SDL_Renderer* renderer, CreateMenuLine* line)
{
// AI checkbox
drawButtonOnRenderer(renderer, &line->aiButton);
// Color chooser
for(int i=0; i<NB_COLORS; ++i)
{
drawButtonOnRenderer(renderer, &line->colorButtons[i]);
}
// TextInput
drawTextInputOnRenderer(renderer, &line->pseudoInput);
return true;
}
CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int xmax, TTF_Font* font, Player* player)
CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int xmax, TTF_Font* font, Player* player, InputProcessor* inproc)
{
int const wColorBtn = 32;
int const hColorBtn = 32;
@ -134,6 +142,7 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int
CreateMenuLine line = {.x=xmin, y};
// AI checkbox
SDL_Texture* aiTexture = createGenericButtonTexture("X", font, 16, COLOR_GENERIC_BUTTON_BACKGROUND, COLOR_GENERIC_BUTTON_BORDER, 4, 8, &(ai.rect.w), &(ai.rect.h), renderer);
SDL_Texture* aiTextureHovered = createGenericButtonTexture("X", font, 16, COLOR_GENERIC_BUTTON_BACKGROUND, COLOR_GENERIC_BUTTON_BACKGROUND, 4, 8, &ai.rect.w, &ai.rect.h, renderer);
line.h = ai.rect.h;
@ -142,9 +151,11 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int
SDL_Rect rect = {.x = xmin + ai.rect.x + ai.rect.w, .y = y, .h = TTF_FontHeight(font),.w = xmax - ai.rect.w - NB_COLORS * (wColorBtn + colorBtnXMargin*2)- 16};
// Text input of nickname
TextInput pseudoInput;
initTextInput(&pseudoInput, &rect, NULL, font);
// Color chooser
ChangeColorParams* params;
for(int i=0; i<NB_COLORS; ++i)
@ -158,13 +169,17 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int
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;
array_P_Button_AddElement(&inproc->tabButton, colorsBtn[i]);
}
// Filling struct
line.w = colorsBtn[0].rect.x + colorsBtn[0].rect.w;
line.aiButton=ai;
line.colorButtons=colorsBtn;
line.player=player;
line.pseudoInput=pseudoInput;
array_TextInput_AddElement(&inproc->tabTextInput, pseudoInput);
return line;
}
@ -180,7 +195,7 @@ void freeCreateMenuLine(CreateMenuLine* line)
}
}
bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Font* font, int width, int height, Player players[], int* nbPlayers)
bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioHandler* ah, TTF_Font* font, int width, int height, Player players[], int* nbPlayers)
{
*nbPlayers = 2;
int const nbLabels = 5;
@ -218,7 +233,6 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
if(btnHoveredTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create hover texture: %s\n", SDL_GetError());
return false;
}
decrementBtn.texture = btnTexture;
decrementBtn.hoverTexture = btnHoveredTexture;
@ -260,12 +274,11 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
if(btnHoveredTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create hover texture: %s\n", SDL_GetError());
return false;
}
incrementBtn.texture = btnTexture;
incrementBtn.hoverTexture = btnHoveredTexture;
// AI label
SDL_Point aiLabelPos = {.x=titleLabel.textZone.x, .y=decrementBtn.rect.y+ decrementBtn.rect.h + 16};
TextLabel aiLabel = createTextLabel(
"IA",
@ -278,6 +291,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
POSY_TOP
);
// Color label
SDL_Point colorLabelPos = {
.x=incrementBtn.rect.x+incrementBtn.rect.w,
decrementBtn.rect.y+ decrementBtn.rect.h + 16
@ -293,6 +307,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
POSY_TOP
);
// Pseudo input
SDL_Point pseudoLabelPos = {
.x= (titleLabel.textZone.x+
aiLabel.textZone.w+
@ -312,26 +327,35 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
);
createPlayersLines(renderer, font, titleLabelPos.x, incrementBtn.rect.x+incrementBtn.rect.w, colorLabel.textZone.y+colorLabel.textZone.h , *nbPlayers, lines);
// Filling TextLabel array
labels[0] = &titleLabel;
labels[1] = &nbPlayerLabel;
labels[2] = &aiLabel;
labels[3] = &pseudoLabel;
labels[4] = &colorLabel;
// Initializing InputProcessor
InputProcessor inputProcessor = createInputProcessor();
// Creating 2 player lines (lines with a AI checkbox, a text input for the nickname, and a color chooser)
createPlayersLines(renderer, font, titleLabelPos.x, incrementBtn.rect.x+incrementBtn.rect.w, colorLabel.textZone.y+colorLabel.textZone.h , *nbPlayers, lines, &inputProcessor, players);
DecrementParams dparams= {.nbPlayers=nbPlayers, .lines=lines, .renderer=renderer, .bg = &bg, .nbPlayersLbl=&nbPlayerLabel, .font=font};
decrementBtn.arg = &dparams;
IncrementParams iparams= {.nbPlayers=nbPlayers, .lines=lines, .minx=titleLabelPos.x, .maxx=incrementBtn.rect.x+incrementBtn.rect.w, .miny=colorLabelPos.y+colorLabel.textZone.h + 16, .font=font, .renderer=renderer, .nbPlayersLbl=&nbPlayerLabel, .bg=&bg};
IncrementParams iparams= {.nbPlayers=nbPlayers, .lines=lines, .minx=titleLabelPos.x, .maxx=incrementBtn.rect.x+incrementBtn.rect.w, .miny=colorLabelPos.y+colorLabel.textZone.h + 16, .font=font, .renderer=renderer, .nbPlayersLbl=&nbPlayerLabel, .bg=&bg, .inproc=&inputProcessor, .players = players};
incrementBtn.arg = &iparams;
buttons[0] = decrementBtn;
buttons[1] = incrementBtn;
InputProcessor inputProcessor = createInputProcessor();
array_P_Button_AddElement(&inputProcessor.tabButton, incrementBtn);
array_P_Button_AddElement(&inputProcessor.tabButton, decrementBtn);
// Displaying menu
drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg);
while(*generalState == GS_GameCreationMenu)
{
@ -358,7 +382,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
{
if(inputElement.data.buttonEvent.button == &incrementBtn || inputElement.data.buttonEvent.button == &decrementBtn)
{
nbPlayerLabel.text[0] = *nbPlayers + 48;
//nbPlayerLabel.text[0] = *nbPlayers + 48;
drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg);
}
@ -369,6 +393,12 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState,TTF_Fon
}
}
nbPlayerLabel.text[0] = *nbPlayers+48;
for (int i = 0; i < *nbPlayers; i++) {
drawTextInputOnRenderer(renderer, &inputProcessor.tabTextInput.elems[i]);
}
SDL_RenderPresent(renderer);
SDL_Delay(20);
}

@ -7,11 +7,14 @@
#include <engine/arrayTextLabel.h>
#include <engine/ButtonActions.h>
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState) {
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState, AudioHandler audioHandler) {
SDL_Color menuBorderColor= {0,0,255,255};
SDL_Color menuBackgroundColor = {0,255,0,255};
//SDL_Color menuBackgroundColor = {0,0,255,255};
//struct argsBouton
int sizex=20,sizey=20;
@ -19,11 +22,10 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHan
SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *settingsButtonTexture = createTextureFromPath(renderer,"rsrc/img/SettingsResized.png");
//SDL_Texture *settingsButtonTexture = createGenericButtonTexture("Settings", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *settingsButtonHoverTexture = createGenericButtonTexture("SettingsHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *muteButtonTexture = createTextureFromPath(renderer,"rsrc/img/SoundResized.png");
//SDL_Texture *muteButtonTexture = createGenericButtonTexture("Mute", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
//SDL_Texture *muteButtonTexture = createTextureFromPath(renderer,"rsrc/img/SoundResized.png");
SDL_Texture *muteButtonTexture = createTextureFromPath(renderer,"rsrc/img/NewSoundResized.png");
SDL_Texture *muteButtonHoverTexture = createGenericButtonTexture("MuteHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
struct array_P_Button buttons = array_P_Button_Create();
@ -31,10 +33,13 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHan
// Menu
array_P_Button_AddElement(&buttons, createButton(menuButtonTexture, menuButtonHoverTexture,20,20,100,50,&action_setStateToMainMenu)); //top left corner (rectangle)
array_P_Button_Last(&buttons)->arg = (void*)generalState;
// Settings
array_P_Button_AddElement(&buttons, createButton(settingsButtonTexture, settingsButtonHoverTexture, 750,10,50,50,&action_print)); //top right corner (square or circle)
// Mute/Unmute
array_P_Button_AddElement(&buttons, createButton(muteButtonTexture, muteButtonHoverTexture, 825,10,50,50,&action_print)); //top right cornre (square or circle)
array_P_Button_AddElement(&buttons, createButton(muteButtonTexture, muteButtonHoverTexture, 825,10,50,50,&action_muteSound)); //top right cornre (square or circle)
array_P_Button_Last(&buttons)->arg = (void*)&audioHandler;
return buttons;
}
@ -68,123 +73,3 @@ struct array_TextLabel createGameInterfaceLabels(SDL_Renderer* renderer, FontHan
}
void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler)
{
//DRAW MENU BUTTON (TOP RIGHT CORNER)
SDL_bool quit = SDL_FALSE;
SDL_Event event;
int sizex=20,sizey=20;
/*
if(TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'inistialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
TTF_Font* retroFont = NULL;
//load ttf
int fontSize = 100;
int size = fontSize*100/88;
retroFont=TTF_OpenFont("rsrc/font/retro/retro.TTF", size);
if(!retroFont) {
printf("TTF_OpenFont: %s\n", TTF_GetError());
// handle error
}
*/
//FontHandler fontHandler=loadFonts();
//Menu Button's colors
SDL_Color menuBorderColor= {0,0,255,255};
SDL_Color menuBackgroundColor = {0,255,0,255};
//Postion text label
SDL_Point positonNbTurnLabel = {.x=60, .y=800};
SDL_Point positionTimeLablel = {.x=770, .y=800};
//Color labal
SDL_Color colorLabel = {0, 255, 0, 255};
//Position label
PositionX_Type positionX = POSX_CENTER;
PositionY_Type positionY = POSY_CENTER;
//SDL_Texture *buttonTexture = createGenericButtonTexture("Menu", NULL, 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer);
SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBorderColor,24,5,&sizex,&sizey,renderer);
SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer);
//Buttons
P_Button menuButton = createButton(menuButtonTexture, menuButtonHoverTexture,20,20,100,50,&action_print); //top left corner (rectangle)
P_Button settingButton = createButton(menuButtonTexture, menuButtonHoverTexture, 750,10,50,50,&action_print); //top right corner (square or circle)
P_Button soundButton = createButton(menuButtonTexture, menuButtonHoverTexture, 825,10,50,50,&action_print); //top right cornre (square or circle)
//Labels
TextLabel nbTurnLabel = createTextLabel("Turn : ",&positonNbTurnLabel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY);
TextLabel timeLabel = createTextLabel("Time : ",&positionTimeLablel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY);
//bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button);
//P_Button createButton(SDL_Texture* texture, SDL_Texture* hoverTexture ,const int coordx, const int coordy, const int sizex, const int sizey, void (*onClick)(P_ButtonArg* arg));
//Create Button Texture
//SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int fontSize, SDL_Color border_color, SDL_Color background_color,int thickness, int padding, int* sizex, int* sizey, SDL_Renderer* renderer);
SDL_Texture* violetTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET,20,20);
SDL_SetRenderDrawColor(renderer, 150,75,200,255);
SDL_SetRenderTarget(renderer, violetTexture);
//SDL_RenderFillRect(renderer, &buttonRect);
SDL_SetRenderDrawColor(renderer,255,0,0,0);
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderClear(renderer);
while(!quit)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
quit = SDL_TRUE;
break;
case SDL_MOUSEBUTTONUP:
//if(isHover(&menuButton,event.button.x,event.button.y))
if(isHover(&menuButton))
menuButton.onClick(&menuButton);
break;
case SDL_MOUSEMOTION:
//on vérifie à chaque tour ou est la souris, drawButtonOnRenderer choisit la bonne texture à afficher
//isHover(&menuButton,event.motion.x,event.motion.y);
isHover(&menuButton);
break;
}
}
drawButtonOnRenderer(renderer,&menuButton);
drawButtonOnRenderer(renderer,&settingButton);
drawButtonOnRenderer(renderer,&soundButton);
drawTextLabel(renderer,&nbTurnLabel);
drawTextLabel(renderer,&timeLabel);
SDL_RenderPresent(renderer);
SDL_Delay(20);
}
}

@ -33,7 +33,7 @@ void redrawGameBoard(SDL_Renderer* renderer, const Player players[], const size_
}
}
void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers, FontHandler* fontHandler)
void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers, FontHandler* fontHandler, AudioHandler audioHandler)
{
if (*generalState != GS_Game) {
return;
@ -44,7 +44,7 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend
Game game = newGame(nbPlayers, players);
TextureHandler textureHandler = newTextureHandler(renderer);
inputProcessor.tabButton = createGameInterfaceButtons(renderer, fontHandler, generalState);
inputProcessor.tabButton = createGameInterfaceButtons(renderer, fontHandler, generalState,audioHandler);
struct array_TextLabel tabLabel = createGameInterfaceLabels(renderer,fontHandler);

@ -67,7 +67,9 @@ int testCreationMenu(void) {
SDL_GetWindowSize(window, &w, &h);
GeneralState generalState = GS_GameCreationMenu;
printf("%d/%d\n", w, h);
gameCreationMenu(renderer, &generalState, fontHandler.fonts[FONT_retro], w, h);
Player players[4];
int nbPlayers;
gameCreationMenu(renderer, &generalState, NULL, fontHandler.fonts[FONT_retro], w, h, players, &nbPlayers);
Quit:
freeFonts(fontHandler);

Loading…
Cancel
Save