origin/fixingSettings
marouault 4 years ago
commit 3d9ccdc3bc

@ -40,12 +40,13 @@ int main(int argc, char const *argv[]) {
exit(2); exit(2);
} }
FontHandler fontHandler = loadFonts(); FontHandler fontHandler = loadFonts();
AudioHandler audioHandler = newAudioHandler(128, 128, 128);
generalState = GS_MainMenu; generalState = GS_MainMenu;
while(generalState != GS_Quit){ while(generalState != GS_Quit){
switch (generalState) { switch (generalState) {
case GS_MainMenu: case GS_MainMenu:
mainMenu(renderer,window,&generalState, fontHandler); mainMenu(renderer,window,&generalState, fontHandler, audioHandler);
break; break;
case GS_GameCreationMenu:{ case GS_GameCreationMenu:{
int windowW; int windowW;

@ -10,11 +10,12 @@
#include "../test/testConnectionMenu.c"*/ #include "../test/testConnectionMenu.c"*/
//#include "../test/testDrawMainMenu.c //#include "../test/testDrawMainMenu.c
//#include "../test/testSettingsView.c" //#include "../test/testSettingsView.c"
#include "../test/oldMain__ThisCanBeGameMain.c"
/* /*
This file is meant to be modified (used only to called other tests functions) This file is meant to be modified (used only to called other tests functions)
*/ */
int main(int argc, char *argv[]) { /*int main(int argc, char *argv[]) {
//testTextureLoader(); //testTextureLoader();
//testAudioHandler(); //testAudioHandler();
//testFontLoader(); //testFontLoader();
@ -22,11 +23,11 @@ int main(int argc, char *argv[]) {
//testTextInput(); //testTextInput();
//testButtonTextureLoader(); //testButtonTextureLoader();
//testConnectionMenu(); //testConnectionMenu();
testMenuEndGame(); //testMenuEndGame();
//testGameInterface(); //testGameInterface();
//testConnectionMenu(); //testConnectionMenu();
//testDrawMainMenu(); //testDrawMainMenu();
//testSettingsView(); //testSettingsView();
return 0; return 0;
} }*/

@ -31,7 +31,8 @@
* \sa #MACRO_FOR_ALL_MUSICS(M) * \sa #MACRO_FOR_ALL_MUSICS(M)
*/ */
#define MACRO_FOR_ALL_SFX(M) \ #define MACRO_FOR_ALL_SFX(M) \
M(testClick) M(testClick) \
M(menu_sound_effect)
/** /**
* Macro used to generate the entries for the musics in #EnumAudios. * Macro used to generate the entries for the musics in #EnumAudios.

@ -54,11 +54,18 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button);
/** /**
* \brief Test if a point is on a button * \brief Test if a point is on a button
* \param[in] button the button target * \param[in] button the button target
* \return true if the cursor is on the button
*/
bool isHover(P_Button* button);// dit si le bouton est survolé en donnant les coordonnées x,y
/**
* \brief Test if the cursor has just entered the button.
* \param[in] button the button target
* \param[in] x x of the point * \param[in] x x of the point
* \param[in] y y of the point * \param[in] y y of the point
* \return SDL_TRUE if the point is on the button * \return true if the cursor has juste entered the button.
*/ */
bool isHover(P_Button* button, int x,int y);// dit si le bouton est survolé en donnant les coordonnées x,y bool isButtonEntry(P_Button * button,const int x,const int y);
/** /**
* \brief Free the texture of a button. * \brief Free the texture of a button.

@ -47,7 +47,7 @@ typedef struct {
* \param[in] nbPlayers The number of players for this game * \param[in] nbPlayers The number of players for this game
* \return A struct representing the game * \return A struct representing the game
*/ */
Game newGame(const size_t nbPlayers, const char* pseudos[]); Game newGame(const size_t nbPlayers, const Player player[]);
/** /**
@ -189,4 +189,3 @@ bool rmBridge(Bridge bridge, Board* board);
struct array_Coord getInteractiveCases(const Game* const game, const Coord selectedCase); struct array_Coord getInteractiveCases(const Game* const game, const Coord selectedCase);
#endif //GAME_H #endif //GAME_H

@ -7,9 +7,10 @@
#include "engine/TextureLoader.h" #include "engine/TextureLoader.h"
#include "engine/FontLoader.h" #include "engine/FontLoader.h"
#include "engine/GeneralState.h" #include "engine/GeneralState.h"
#include "engine/AudioHandler.h"
P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize); P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize);
int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler); int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler);
#endif #endif

@ -2,7 +2,7 @@
// A channel represents the number of SFX we can play at the same time. // A channel represents the number of SFX we can play at the same time.
// We normally should use only 1 channel, and we add one for safety. // We normally should use only 1 channel, and we add one for safety.
#define NBCHANNELS 2 #define NBCHANNELS 10
// Local functions // Local functions
@ -196,4 +196,3 @@ void playSFX(EnumAudios sfx, AudioHandler audioHandler) {
return; return;
} }
} }

@ -27,12 +27,8 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button)
return true; return true;
} }
bool isHover(P_Button* button,const int x,const int y) bool isHover(P_Button* button)
{ {
SDL_Point coord;
coord.x = x;
coord.y = y;
button->hover = SDL_PointInRect(&coord,&(button->rect));
return button->hover && button->drawn; return button->hover && button->drawn;
} }
@ -60,3 +56,15 @@ void freeButton(P_Button * button){
SDL_DestroyTexture(button->texture); SDL_DestroyTexture(button->texture);
SDL_DestroyTexture(button->hoverTexture); SDL_DestroyTexture(button->hoverTexture);
} }
bool isButtonEntry(P_Button * button,const int x,const int y){
SDL_Point coord;
coord.x = x;
coord.y = y;
if(isHover(button)){
button->hover = SDL_PointInRect(&coord,&(button->rect));
return false;
}
button->hover = SDL_PointInRect(&coord,&(button->rect));
return button->hover;
}

@ -81,11 +81,10 @@ InputElement proccessGameInput(GameInputProcessor *gameInputProcessor, const SDL
{ {
for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) { for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) {
P_Button* b = &gameInputProcessor->tabButton.elems[i]; P_Button* b = &gameInputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y); isButtonEntry(b, event.motion.x, event.motion.y);
} }
} }
} }
return createInputElementNone(); return createInputElementNone();
} }

@ -39,7 +39,7 @@ InputElement proccessInput(InputProcessor *inputProcessor)
{ {
for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) { for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) {
P_Button* b = &inputProcessor->tabButton.elems[i]; P_Button* b = &inputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y); isButtonEntry(b, event.motion.x, event.motion.y);
} }
break; break;
} }
@ -47,4 +47,3 @@ InputElement proccessInput(InputProcessor *inputProcessor)
return createInputElementNone(); return createInputElementNone();
} }

@ -30,7 +30,7 @@ void applySpecificRulesFor2PlayersGame(Game* g)
} }
} }
Game newGame(const size_t nbPlayers, const char* pseudos[]) Game newGame(const size_t nbPlayers, const Player player[])
{ {
Game g = { // In Placement phase, the last player initialized is the 1st to play Game g = { // In Placement phase, the last player initialized is the 1st to play
.currentPlayerID = nbPlayers - 1, .currentPlayerID = nbPlayers - 1,
@ -40,13 +40,9 @@ Game newGame(const size_t nbPlayers, const char* pseudos[])
.nbPlayers = nbPlayers .nbPlayers = nbPlayers
}; };
// red, green, blue, yellow
// TODO meilleures couleurs (?)
SDL_Color colors[4] = { { 255, 0, 0, 255 }, { 0, 255, 0, 255 }, { 0, 0, 255, 255 }, { 255, 255, 0, 255 } };
for (size_t player_i = 0; player_i < nbPlayers; player_i++) for (size_t player_i = 0; player_i < nbPlayers; player_i++)
{ {
g.arrPlayers[player_i] = newPlayer(pseudos[player_i], colors[player_i]); g.arrPlayers[player_i] = player[player_i];
} }
if (nbPlayers == 2) if (nbPlayers == 2)

@ -63,7 +63,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns
return buttons; return buttons;
} }
int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler){ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler){
int statut = EXIT_FAILURE; int statut = EXIT_FAILURE;
char* path = "../rsrc/img/Lenna.png"; char* path = "../rsrc/img/Lenna.png";
//Initialisation //Initialisation
@ -92,17 +92,20 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general
*generalState = GS_Quit; *generalState = GS_Quit;
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if(isHover(buttons,event.button.x,event.button.y)) if(isHover(buttons))
printf("Nouvelle partie\n"); printf("Nouvelle partie\n");
if(isHover(&(buttons[2]),event.motion.x,event.motion.y)){ if(isHover(&(buttons[2]))){
buttons[2].onClick(&(buttons[2])); buttons[2].onClick(&(buttons[2]));
break; break;
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
isHover(&(buttons[0]),event.motion.x,event.motion.y); if(isButtonEntry(&(buttons[0]),event.motion.x,event.motion.y) ||
isHover(&(buttons[1]),event.motion.x,event.motion.y); isButtonEntry(&(buttons[1]),event.motion.x,event.motion.y) ||
isHover(&(buttons[2]),event.motion.x,event.motion.y); isButtonEntry(&(buttons[2]),event.motion.x,event.motion.y)){
playSFX(SFX_menu_sound_effect, audioHandler);
printf("True\n");
}
break; break;
default: default:
break; break;

Loading…
Cancel
Save