From bbee7397a9b702469149a1130147e40f3391c797 Mon Sep 17 00:00:00 2001 From: thmaillarb Date: Mon, 14 Feb 2022 09:03:16 +0100 Subject: [PATCH 1/4] Added input loop in settings --- Pontu/src/view/Settings.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Pontu/src/view/Settings.c b/Pontu/src/view/Settings.c index 092fabe..ba440ba 100644 --- a/Pontu/src/view/Settings.c +++ b/Pontu/src/view/Settings.c @@ -102,6 +102,8 @@ void settingsView(SDL_Window* parent, AudioHandler* ah, const FontHandler* fh) { SDL_Rect title_area = {0,0,300,50}; RetValues retValues; struct array_P_Button array_buttons; + bool stayInLoop = true; + SDL_Event event; if (0 != SDL_CreateWindowAndRenderer(300,600,SDL_WINDOW_SHOWN, &window, &renderer)) { fprintf(stderr,"Error when trying to create window or renderer: %s\n", SDL_GetError()); @@ -127,7 +129,40 @@ void settingsView(SDL_Window* parent, AudioHandler* ah, const FontHandler* fh) { drawTextLabel(renderer, &retValues.arr_textLabel[i]); } - - SDL_RenderPresent(renderer); + while (stayInLoop) { + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_CLOSE: + stayInLoop = false; + printf("Quit\n"); + fflush(stdout); + break; + default: + break; + } + break; + case SDL_MOUSEBUTTONUP: + printf("MOUSEBUTTONUP\n"); + for (int i = 0; i < NB_BUTTONS; i++) { + printf("%d\n",i); + if (isButtonInteractWithCursor(&(retValues.arr_buttons.elems[i]),event.button.x,event.button.y)) { + printf("isHover\n"); + retValues.arr_buttons.elems[i].onClick(&(retValues.arr_buttons.elems[i])); + fflush(stdout); + break; + } + } + break; + default: + break; + } + + } + + SDL_RenderPresent(renderer); + SDL_Delay(20); + } } From 2ea7834b35fd72d3dc0a857a4ce4db20a61f78ec Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 14 Feb 2022 09:03:27 +0100 Subject: [PATCH 2/4] In GameInterface, add the function createGameInterfaceLabels --- Pontu/include/view/GameInterface.h | 27 ++++++++++++++------------- Pontu/src/view/GameInterface.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Pontu/include/view/GameInterface.h b/Pontu/include/view/GameInterface.h index 98a018a..5d7649a 100644 --- a/Pontu/include/view/GameInterface.h +++ b/Pontu/include/view/GameInterface.h @@ -14,27 +14,28 @@ #include "engine/arrayButton.h" -//move pion - -//delete pion - -//draw menu Ponton (top left corner) /** * \brief Draw different buttons on the game interface : menu, setting, sound, nbTurn, and timers * param Renderer */ void drawButtons(SDL_Renderer* renderer,FontHandler fontHandler); -//draw setting button (top right corner) - -//draw sound button (top right corner) - -//draw nbTurn (bottom left corner) - -//draw timer (bottom right corner) - +/** + * \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); +/** + * \brief Create an array of TextLabel for the game interface + * \param renderer The renderer on which we create TextLabel + * \param fontHandler The fontHandler to apply + * \return an array of TextLabel to draw on the renderer + */ +struct array_TextLabel createGameInterfaceLabels(SDL_Renderer* renderer, FontHandler* fontHandler); + #endif diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index fec635c..2a558ee 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -32,6 +32,35 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHan return buttons; } +struct array_TextLabel createGameInterfaceLabels(SDL_Renderer* renderer, FontHandler* fontHandler) { + //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; + + struct array_TextLabel labels = array_TextLabel_Create(); + + // Label : Nb Turn + TextLabel nbTurnLabel = createTextLabel("Turn : ",&positonNbTurnLabel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + // Label : Time of the game + TextLabel timeLabel = createTextLabel("Time : ",&positionTimeLablel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + + //Add TextLabel to the array + array_TextLabel_AddElement(&labels, nbTurnLabel); + array_TextLabel_AddElement(&labels, timeLabel); + + return labels; + + +} + void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) { //DRAW MENU BUTTON (TOP RIGHT CORNER) From d6d95a8a22b6950e8e7bcd1b12e12a4a5850fff8 Mon Sep 17 00:00:00 2001 From: thmaillarb Date: Mon, 14 Feb 2022 09:14:52 +0100 Subject: [PATCH 3/4] Made AudioHandler volumes more consistent + added tests to avoid weird settings --- Pontu/entryPoints/test.c | 8 ++++---- Pontu/src/engine/AudioHandler.c | 14 ++++++++++---- Pontu/test/testAudioHandler.c | 6 +++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index 2f04bfa..c1881d6 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -1,11 +1,11 @@ // #include "../test/testTextureLoader.c" // #include "../test/testFontLoader.c" -// #include "../test/testAudioHandler.c" + #include "../test/testAudioHandler.c" // #include "../test/testGenerateurTexture.c" //#include "../test/testGameInterface.c" //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c -#include "../test/testSettingsView.c" +//#include "../test/testSettingsView.c" //#include "../test/testCreationMenu.c" //#include "../test/testGameInterface.c" //#include "../test/testConnectionMenu.c" @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { //testTextureLoader(); - //testAudioHandler(); + testAudioHandler(); //testFontLoader(); //testGenerateurTexture(); //testTextInput(); @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { //testConnectionMenu(); //testDrawMainMenu(); //testCreationMenu(); - testSettingsView(); + // testSettingsView(); return 0; } diff --git a/Pontu/src/engine/AudioHandler.c b/Pontu/src/engine/AudioHandler.c index eb10c0a..bffb735 100644 --- a/Pontu/src/engine/AudioHandler.c +++ b/Pontu/src/engine/AudioHandler.c @@ -92,19 +92,25 @@ AudioHandler newAudioHandler(int masterVol, int volMusic, int volSFX) { } void changeMusicVol(AudioHandler* ah, int volMusic) { + if (volMusic > 10) volMusic = 10; + if (volMusic < 0) volMusic = 0; ah->volMusic = volMusic; - Mix_VolumeMusic(ah->volMusic * ah->masterVol * 0.1); + Mix_VolumeMusic(ah->volMusic * ah->masterVol); } void changeSFXVol(AudioHandler* ah, int volSFX) { + if (volSFX > 10) volSFX = 10; + if (volSFX < 0) volSFX = 0; ah->volSFX = volSFX; - Mix_Volume(-1, ah->volSFX * ah->masterVol * 0.1); + Mix_Volume(-1, ah->volSFX * ah->masterVol); } void changeMasterVol(AudioHandler* ah, int masterVol) { + if (masterVol > 10) masterVol = 10; + if (masterVol < 0) masterVol = 0; ah->masterVol = masterVol; - Mix_VolumeMusic(ah->volMusic * ah->masterVol * 0.1); - Mix_Volume(-1, ah->volSFX * ah->masterVol * 0.1); + Mix_VolumeMusic(ah->volMusic * ah->masterVol); + Mix_Volume(-1, ah->volSFX * ah->masterVol); } void freeAudioHandler(AudioHandler* audioHandler) { diff --git a/Pontu/test/testAudioHandler.c b/Pontu/test/testAudioHandler.c index 150e276..973caac 100644 --- a/Pontu/test/testAudioHandler.c +++ b/Pontu/test/testAudioHandler.c @@ -10,7 +10,7 @@ void testAudioHandler(void) { exit(errno); } - AudioHandler ah = newAudioHandler(100, 100); + AudioHandler ah = newAudioHandler(10, 10, 10); if (ah.canPlayAudio == false) { perror("AudioHandler"); SDL_Quit(); @@ -61,13 +61,13 @@ void testAudioHandler(void) { printf("Playing louder (vol = 128) the SFX, testing with SFX_testClick\n"); - changeSFXVol(128); + changeSFXVol(&ah, 128); playSFX(SFX_testClick, ah); SDL_Delay(2000); printf("Playing quieter (vol = 10) the SFX, testing with SFX_testClick\n"); - changeSFXVol(10); + changeSFXVol(&ah, 1); playSFX(SFX_testClick, ah); SDL_Delay(2000); From 332ce97feec7be3a18193f15fb37933f6c5e1aac Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 14 Feb 2022 09:20:58 +0100 Subject: [PATCH 4/4] Add the missing include in GameInterface and the GGameMain --- Pontu/src/view/GameInterface.c | 2 ++ Pontu/src/view/GameMain.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index 2a558ee..e98f63a 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include //void action boutton diff --git a/Pontu/src/view/GameMain.c b/Pontu/src/view/GameMain.c index 0dc182e..a6fff35 100644 --- a/Pontu/src/view/GameMain.c +++ b/Pontu/src/view/GameMain.c @@ -3,6 +3,8 @@ #include "engine/GameInputProcessor.h" #include "engine/InputElement.h" #include "engine/TextureHandler.h" +#include "engine/arrayButton.h" +#include "engine/arrayTextLabel.h" #include "model/Game.h" #include "model/arrayCoord.h" @@ -43,6 +45,8 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend TextureHandler textureHandler = newTextureHandler(renderer); inputProcessor.tabButton = createGameInterfaceButtons(renderer, fontHandler); + struct array_TextLabel tabLabel = createGameInterfaceLabels(renderer,fontHandler); + SDL_Rect windowRect = {0,0,0,0}; SDL_GetWindowSize(window, &windowRect.w, &windowRect.h);