From 170962a59c7c39bd18f2a20cb1cf93354e12ec48 Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 7 Mar 2022 08:12:01 +0100 Subject: [PATCH 01/13] Fixe error with audioHandler in parameter of playSFX function --- Pontu/entryPoints/main.c | 2 +- Pontu/src/view/MainMenu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index f737847..0addca0 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { switch (generalState) { case GS_MainMenu: mainMenu(renderer,window,&generalState, fontHandler, audioHandler); - playSFX(SFX_validate_sound, audioHandler); + playSFX(SFX_validate_sound, &audioHandler); break; case GS_GameCreationMenu:{ int windowW; diff --git a/Pontu/src/view/MainMenu.c b/Pontu/src/view/MainMenu.c index 92db391..4f7fa11 100644 --- a/Pontu/src/view/MainMenu.c +++ b/Pontu/src/view/MainMenu.c @@ -117,7 +117,7 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general switch (isButtonInteractWithCursor(&(buttons[i]),event.motion.x,event.motion.y)) { case 1: drawButtonOnRenderer(renderer,&(buttons[i])); - playSFX(SFX_menu_sound_effect, audioHandler); + playSFX(SFX_menu_sound_effect, &audioHandler); drawSomething = true; break; case 2: From e70260e91c355682969471e74f9ae6465f2f1da2 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 08:56:39 +0100 Subject: [PATCH 02/13] modified gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f811cd5..e92e1aa 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,8 @@ _deps ### binaries ### bin/ +build_debug/ +build_release/ Documentation/doxygen/ From 216d8fe2059707b52c4d874ee131bdb97571cead Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 08:57:33 +0100 Subject: [PATCH 03/13] CMakeLists updated, less gcc options set directly --- Pontu/CMakeLists.txt | 24 +++++++++--------------- Pontu/include/engine/ArrayUtils.h | 23 ++++++++++++----------- Pontu/src/debug/CMakeLists.txt | 16 ++++++++++++++++ Pontu/src/engine/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ Pontu/src/model/CMakeLists.txt | 23 +++++++++++++++++++++++ Pontu/src/model/Game.c | 2 +- Pontu/src/view/CMakeLists.txt | 24 ++++++++++++++++++++++++ Pontu/src/view/GameDrawer.c | 26 -------------------------- 8 files changed, 115 insertions(+), 53 deletions(-) create mode 100644 Pontu/src/debug/CMakeLists.txt create mode 100644 Pontu/src/engine/CMakeLists.txt create mode 100644 Pontu/src/model/CMakeLists.txt create mode 100644 Pontu/src/view/CMakeLists.txt delete mode 100644 Pontu/src/view/GameDrawer.c diff --git a/Pontu/CMakeLists.txt b/Pontu/CMakeLists.txt index 70ee688..aed6eea 100644 --- a/Pontu/CMakeLists.txt +++ b/Pontu/CMakeLists.txt @@ -4,9 +4,8 @@ SET(PROJECT_NAME Pontu) project(${PROJECT_NAME}) -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c) -add_executable(${PROJECT_NAME} ${MY_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/main.c) -add_executable(Test ${MY_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/test.c) +add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/main.c) +add_executable(Test ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/test.c) @@ -18,21 +17,11 @@ find_package(SDL2_ttf REQUIRED) find_package(SDL2_image REQUIRED) find_package(SDL2_mixer REQUIRED) - target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIR}) target_include_directories(Test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIR}) -SET(OptionGCC -Wall -Wextra -pedantic -Wconversion -std=c17 -Og -g) - -if (MINGW) - target_link_options(${PROJECT_NAME} PRIVATE -lmingw32 -lSDL2main -lSDL2 -mwindows) - target_compile_options(${PROJECT_NAME} PRIVATE ${OptionGCC} -Dmain=SDL_main -fdiagnostics-color=always) - target_link_options(Test PRIVATE -lmingw32 -lSDL2main -lSDL2 -mwindows) - target_compile_options(Test PRIVATE ${OptionGCC} -Dmain=SDL_main -fdiagnostics-color=always) -elseif(UNIX) - target_compile_options(${PROJECT_NAME} PRIVATE ${OptionGCC} -D_REENTRANT) - target_compile_options(Test PRIVATE ${OptionGCC} -D_REENTRANT) -endif() +set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) +set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) target_link_libraries(${PROJECT_NAME} SDL2::Main) target_link_libraries(Test SDL2::Main) @@ -42,3 +31,8 @@ target_link_libraries(${PROJECT_NAME} SDL2::Mixer) target_link_libraries(Test SDL2::Mixer) target_link_libraries(${PROJECT_NAME} SDL2::TTF) target_link_libraries(Test SDL2::TTF) + +add_subdirectory(src/debug) +add_subdirectory(src/engine) +add_subdirectory(src/model) +add_subdirectory(src/view) diff --git a/Pontu/include/engine/ArrayUtils.h b/Pontu/include/engine/ArrayUtils.h index e1438f3..1513441 100644 --- a/Pontu/include/engine/ArrayUtils.h +++ b/Pontu/include/engine/ArrayUtils.h @@ -23,6 +23,7 @@ * Functions in header must be marked as inline * Don't forget antislashes */ + #define GENERATE_DYNAMIC_ARRAY(T) \ struct array_##T { \ T* elems; \ @@ -30,14 +31,14 @@ struct array_##T { \ size_t space; \ }; \ \ -/*Contruct an empty array*/\ -inline struct array_##T array_##T##_Create() { \ +/*Contruct an empty array*/ \ +static struct array_##T array_##T##_Create() { \ struct array_##T array = {.elems=NULL, .size=0, .space=0}; \ return array; \ } \ \ /*Free an array*/ \ -inline void array_##T##_Free(struct array_##T* array) { \ +static void array_##T##_Free(struct array_##T* array) { \ free(array->elems); \ array->elems = NULL; \ array->size = 0; \ @@ -45,7 +46,7 @@ inline void array_##T##_Free(struct array_##T* array) { \ } \ \ /*Reserve space for an array*/\ -inline void array_##T##_Reserve(struct array_##T* array, const size_t space) { \ +static void array_##T##_Reserve(struct array_##T* array, const size_t space) { \ array->space = space; \ array->elems = realloc(array->elems, sizeof(T)*(array->space)); \ if (array->elems == NULL) { \ @@ -54,7 +55,7 @@ inline void array_##T##_Reserve(struct array_##T* array, const size_t space) { \ } \ \ /*Fit space to size for an array*/\ -inline void array_##T##_FitToSize(struct array_##T* array) { \ +static void array_##T##_FitToSize(struct array_##T* array) { \ array->space = array->size; \ array->elems = realloc(array->elems, sizeof(T)*(array->space)); \ if (array->elems == NULL) { \ @@ -63,7 +64,7 @@ inline void array_##T##_FitToSize(struct array_##T* array) { \ } \ \ /*Add an element to an array*/\ -inline void array_##T##_AddElement(struct array_##T* array, const T element) { \ +static void array_##T##_AddElement(struct array_##T* array, const T element) { \ ++(array->size); \ if (array->size > array->space) { \ ++(array->space); \ @@ -77,7 +78,7 @@ inline void array_##T##_AddElement(struct array_##T* array, const T element) { \ } \ \ /*Remove an element from an array*/\ -inline bool array_##T##_RemoveElement(struct array_##T* array, const T element, bool (*areEqual)(const T, const T)) { \ +static bool array_##T##_RemoveElement(struct array_##T* array, const T element, bool (*areEqual)(const T, const T)) { \ for (size_t i=0; isize; ++i) { \ if (areEqual(array->elems[i], element)) { \ for (;isize-1; ++i) { \ @@ -91,7 +92,7 @@ inline bool array_##T##_RemoveElement(struct array_##T* array, const T element, } \ \ /*Check if an array contains an element*/\ -inline bool array_##T##_Contains(const struct array_##T* const array, const T element, bool (*areEqual)(const T, const T)) { \ +static bool array_##T##_Contains(const struct array_##T* const array, const T element, bool (*areEqual)(const T, const T)) { \ for (size_t i = 0; i < array->size; i++) { \ if (areEqual(array->elems[i], element)) { \ return true; \ @@ -101,19 +102,19 @@ inline bool array_##T##_Contains(const struct array_##T* const array, const T el }\ \ /*Apply a function to each element in the array*/\ -inline void array_##T##_Foreach(const struct array_##T* const array, void (*func)(const T)) { \ +static void array_##T##_Foreach(const struct array_##T* const array, void (*func)(const T)) { \ for(size_t i = 0; isize; ++i) { \ func(array->elems[i]);\ }\ }\ \ /*Return last element*/\ -inline T* array_##T##_First(const struct array_##T* const array) {\ +static T* array_##T##_First(const struct array_##T* const array) {\ return &array->elems[0];\ }\ \ /*Return last element*/\ -inline T* array_##T##_Last(const struct array_##T* const array) {\ +static T* array_##T##_Last(const struct array_##T* const array) {\ return &array->elems[array->size-1];\ }\ diff --git a/Pontu/src/debug/CMakeLists.txt b/Pontu/src/debug/CMakeLists.txt new file mode 100644 index 0000000..dc44040 --- /dev/null +++ b/Pontu/src/debug/CMakeLists.txt @@ -0,0 +1,16 @@ + +set(SOURCES + printer.c +) + +target_sources( + ${PROJECT_NAME} + PUBLIC + ${SOURCES} +) + +target_sources( + Test + PUBLIC + ${SOURCES} +) diff --git a/Pontu/src/engine/CMakeLists.txt b/Pontu/src/engine/CMakeLists.txt new file mode 100644 index 0000000..707152a --- /dev/null +++ b/Pontu/src/engine/CMakeLists.txt @@ -0,0 +1,30 @@ + +set(SOURCES + AudioHandler.c + Button.c + ButtonActions.c + ColorPicker.c + Colors.c + FontLoader.c + FontUtils.c + GameInputProcessor.c + InputElement.c + InputProcessor.c + TextInput.c + TextLabel.c + TextureHandler.c + TextureLoader.c + UIElementUtils.c +) + +target_sources( + ${PROJECT_NAME} + PUBLIC + ${SOURCES} +) + +target_sources( + Test + PUBLIC + ${SOURCES} +) diff --git a/Pontu/src/model/CMakeLists.txt b/Pontu/src/model/CMakeLists.txt new file mode 100644 index 0000000..9fef3d8 --- /dev/null +++ b/Pontu/src/model/CMakeLists.txt @@ -0,0 +1,23 @@ + +set(SOURCES + Board.c + Coord.c + Game.c + Island.c + IslandOrBridge.c + Piece.c + Player.c + PlayersColors.c +) + +target_sources( + ${PROJECT_NAME} + PUBLIC + ${SOURCES} +) + +target_sources( + Test + PUBLIC + ${SOURCES} +) diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index d63a881..2d763a5 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -1,6 +1,6 @@ #include "model/Game.h" #include "model/IslandOrBridge.h" -#include "engine/ArrayUtils.h" +#include "model/arrayCoord.h" #include // Not defined in header to not pollute inferface diff --git a/Pontu/src/view/CMakeLists.txt b/Pontu/src/view/CMakeLists.txt new file mode 100644 index 0000000..4e555c8 --- /dev/null +++ b/Pontu/src/view/CMakeLists.txt @@ -0,0 +1,24 @@ + +set(SOURCES + BoardDrawer.c + GameCreationMenu.c + GameInterface.c + GameMain.c + MainMenu.c + MenuEndGame.c + PiecesDrawer.c + Settings.c + ToRect.c +) + +target_sources( + ${PROJECT_NAME} + PUBLIC + ${SOURCES} +) + +target_sources( + Test + PUBLIC + ${SOURCES} +) diff --git a/Pontu/src/view/GameDrawer.c b/Pontu/src/view/GameDrawer.c deleted file mode 100644 index f14b094..0000000 --- a/Pontu/src/view/GameDrawer.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "view/GameDrawer.h" -#include "view/BoardDrawer.h" -#include "view/PiecesDrawer.h" - -bool drawGame(SDL_Renderer* renderer, const SDL_Rect* windowSize, const SDL_Rect* boardRect, const Game* game,TextureHandler* textureHandler) -{ - //SDL_Texture* menuTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 50, 70); - - /*SDL_SetRenderTarget(renderer, menuTexture); - SDL_SetRenderDrawColor(renderer, 150, 243, 59, 255); - SDL_Rect buttonRect = {.x = 0,.y = 0,.w = 50,.h = 70}; - SDL_RenderFillRect(renderer, &buttonRect); - SDL_SetRenderTarget(renderer, NULL);*/ - - //P_Button menu = createButton(menuTexture, NULL, (windowSize->w*5)/100, (windowSize->h*5)/100, 50, 70, NULL); - //P_Button menu = createButton(menuTexture, NULL, 10, 10, 50, 70, NULL); - - - //drawBoard(renderer, boardRect, &(game->board), textureHandler->textures[TEXTURE_Island], textureHandler->textures[TEXTURE_Bridge], textureHandler->textures[TEXTURE_Water]); - - - /*drawPiecesPlayer(renderer, boardRect, game->board.arrPieces, game->board.nbPieces, 0, textureHandler->textures[TEXTURE_PieceRed]); - drawPiecesPlayer(renderer, boardRect, game->board.arrPieces, game->board.nbPieces, 1, textureHandler->textures[TEXTURE_PieceViolet]); -*/ - return true; -} From d46ebc19c8b895f3d4fe92537db22b97a6ad7a7b Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 08:02:51 +0000 Subject: [PATCH 04/13] Update README.md --- README.md | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4926cad..626ab96 100644 --- a/README.md +++ b/README.md @@ -22,33 +22,20 @@ Nous développerons successivement les versions suivantes : ## Comment télécharger, compiler et executer Pontu -### Sur Linux: +Utiliser l'option -DCMAKE_BUILD_TYPE=Debug pour build en debug + -DCMAKE_BUILD_TYPE=Release pour build en release ```BASH git clone [urlToThisRepo] cd [thisRepo]/Pontu git submodule init git submodule update -mkdir bin +mkdir bin #ou un autre nom de fichier comme "build_debug" ou "build_release" cd bin cmake .. -make +make # ou mingw32-make avec Mingw cd .. #Se mettre dans le dossier Pontu ./bin/Pontu ``` -### Sur Windows: - -```BASH -git clone [urlToThisRepo] -cd [thisRepo]/Pontu -git submodule init -git submodule update -mkdir bin -cd bin -cmake .. -mingw32-make -cd .. #Se mettre dans le dossier Pontu -./bin/Pontu.exe -``` From aa944f434b2d5d735e5b3d7728fca747dbecb315 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 10:23:23 +0100 Subject: [PATCH 05/13] Change Cmake to readd warnings --- Pontu/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Pontu/CMakeLists.txt b/Pontu/CMakeLists.txt index aed6eea..74fe749 100644 --- a/Pontu/CMakeLists.txt +++ b/Pontu/CMakeLists.txt @@ -23,6 +23,14 @@ target_include_directories(Test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SD set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) +if(MSVC) +target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +target_compile_options(Test PRIVATE /W4 /WX) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic) + target_compile_options(Test PRIVATE -Wall -Wextra -Wpedantic) +endif() + target_link_libraries(${PROJECT_NAME} SDL2::Main) target_link_libraries(Test SDL2::Main) target_link_libraries(${PROJECT_NAME} SDL2::Image) From 8417404aa44324af5b3d44a7cce4371f4b4c103c Mon Sep 17 00:00:00 2001 From: thmaillarb Date: Mon, 7 Mar 2022 10:28:23 +0100 Subject: [PATCH 06/13] did stuff that apparently made the gamechangedview faster --- Pontu/src/engine/InputProcessor.c | 1 + Pontu/src/view/GameCreationMenu.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index d4ff544..d190aa5 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -34,6 +34,7 @@ InputElement proccessInput(InputProcessor *inputProcessor) P_Button* b = &inputProcessor->tabButton.elems[i]; if (isHover(b)) { b->onClick(b); + break; } } bool textInputClicked = false; diff --git a/Pontu/src/view/GameCreationMenu.c b/Pontu/src/view/GameCreationMenu.c index 7cd225a..7bbd683 100644 --- a/Pontu/src/view/GameCreationMenu.c +++ b/Pontu/src/view/GameCreationMenu.c @@ -26,7 +26,7 @@ void incrementNbPlayer(P_Button* caller) return; } ++(*nbPlayers); - *params->viewChanged = true; + *params->viewChanged = true; } void decrementNbPlayer(P_Button* caller) { @@ -38,7 +38,7 @@ void decrementNbPlayer(P_Button* caller) return; } --(*nbPlayers); - *params->viewChanged = true; + *params->viewChanged = true; } void changePlayerColor(P_Button* caller) @@ -102,7 +102,7 @@ bool drawCreateMenuLine(SDL_Renderer* renderer, CreateMenuLine* line) // AI checkbox drawButtonOnRenderer(renderer, &line->aiButton); // Color chooser - drawColorPicker(renderer, line->colorPicker); + drawColorPicker(renderer, line->colorPicker); // TextInput drawTextInputOnRenderer(renderer, &line->pseudoInput); return true; @@ -146,13 +146,13 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int // Color chooser ChangeColorParams* params; - ColorPicker picker; + ColorPicker picker; for(int i=0; icolor=playersColors[i]; - picker.colorButtons[i] = createButton(NULL, NULL, xmax-wColorBtn*(i+1), y, wColorBtn, hColorBtn, changePlayerColor); + params->color=playersColors[i]; + picker.colorButtons[i] = createButton(NULL, NULL, xmax-wColorBtn*(i+1), y, wColorBtn, hColorBtn, changePlayerColor); picker.colorButtons[i].arg = params; 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); @@ -378,6 +378,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH array_P_Button_AddElement(&inputProcessor.tabButton, validateBtn); array_P_Button_AddElement(&inputProcessor.tabButton, cancelBtn); + // Displaying menu drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg); while(*generalState == GS_GameCreationMenu) @@ -415,7 +416,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg); viewChanged=false; } - SDL_Delay(20); + SDL_Delay(5); } From 9c7853072ac9b5a0f720554e7f9256f22fc7cfab Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 10:33:25 +0100 Subject: [PATCH 07/13] Input element launch textinput event --- Pontu/include/engine/InputElement.h | 7 ++++++- Pontu/src/engine/InputElement.c | 9 +++++++++ Pontu/src/engine/InputProcessor.c | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Pontu/include/engine/InputElement.h b/Pontu/include/engine/InputElement.h index 1ff9aed..1762258 100644 --- a/Pontu/include/engine/InputElement.h +++ b/Pontu/include/engine/InputElement.h @@ -11,13 +11,14 @@ #include "model/Coord.h" #include "engine/Button.h" +#include "engine/TextInput.h" /** * \enum InputType * \brief Different types for input */ -typedef enum {InputType_None, InputType_ClickGame, InputType_MoveGame, InputType_ActivateUI, InputType_Window_Resize, InputType_ButtonChanged} InputType; +typedef enum {InputType_None, InputType_ClickGame, InputType_MoveGame, InputType_ActivateUI, InputType_Window_Resize, InputType_ButtonChanged, InputType_TextInput} InputType; /** * \enum UIAction @@ -55,6 +56,8 @@ typedef struct { ButtonEvent event; } buttonEvent; + TextInput* textInput; + } data; ///< Informations about the input InputType type; ///< Type of input @@ -97,4 +100,6 @@ InputElement createInputElementResizeWindow(); InputElement createInputElementButtonClicked(P_Button* button, const ButtonEvent event); +InputElement createInputElementTextInput(TextInput* textInput); + #endif // INPUT_ELEMENT_INCLUDED diff --git a/Pontu/src/engine/InputElement.c b/Pontu/src/engine/InputElement.c index e0a2e13..48764c2 100644 --- a/Pontu/src/engine/InputElement.c +++ b/Pontu/src/engine/InputElement.c @@ -38,3 +38,12 @@ InputElement createInputElementButtonClicked(P_Button* button, const ButtonEvent }; return i; } + + +InputElement createInputElementTextInput(TextInput* textInput) { + InputElement i = { + .type = InputType_TextInput, + .data.textInput=textInput + }; + return i; +} diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index d4ff544..625fcec 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -79,13 +79,16 @@ InputElement proccessInput(InputProcessor *inputProcessor) break; case SDL_TEXTINPUT: addStringToInputTextValueAtCursor(inputProcessor->selectedTextInput, event.text.text); + return createInputElementTextInput(inputProcessor->selectedTextInput); break; case SDL_TEXTEDITING: inputProcessor->selectedTextInput->cursorPosition = event.edit.start; + return createInputElementTextInput(inputProcessor->selectedTextInput); break; case SDL_KEYDOWN: if (inputProcessor->selectedTextInput != NULL && event.key.keysym.sym == SDLK_BACKSPACE) { removeCharacterToInputTextValueAtCursor(inputProcessor->selectedTextInput); + return createInputElementTextInput(inputProcessor->selectedTextInput); } break; } From 4a0b4eb13119ebcdfbdcfc53a5d2a2cfac09f5d8 Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 7 Mar 2022 10:35:09 +0100 Subject: [PATCH 08/13] Mute and unmute button works --- Pontu/include/engine/ButtonActions.h | 12 +++++++++++- Pontu/src/engine/ButtonActions.c | 19 ++++++++++++++++--- Pontu/src/view/GameInterface.c | 10 ++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Pontu/include/engine/ButtonActions.h b/Pontu/include/engine/ButtonActions.h index 4943b36..c373c07 100644 --- a/Pontu/include/engine/ButtonActions.h +++ b/Pontu/include/engine/ButtonActions.h @@ -2,7 +2,17 @@ #define BUTTON_ACTION_INCLUDED #include "engine/Button.h" +#include "engine/AudioHandler.h" +#include +/** + * @brief Args for the SoundButton + */ +typedef struct +{ + AudioHandler audio; //Audio from which we change masterVolume + SDL_Renderer* renderer; +}argsSoundButton; void action_none(P_Button* caller); @@ -15,7 +25,7 @@ void action_print(P_Button* caller); void action_setStateToMainMenu(P_Button* caller); /** - * @brief Button handle wich mute the sound + * @brief Button handle wich mute and unmute the master volume * @param caller The button clicked */ void action_muteSound(P_Button* caller); diff --git a/Pontu/src/engine/ButtonActions.c b/Pontu/src/engine/ButtonActions.c index e04f732..19ef827 100644 --- a/Pontu/src/engine/ButtonActions.c +++ b/Pontu/src/engine/ButtonActions.c @@ -2,6 +2,7 @@ #include "engine/GeneralState.h" #include "engine/AudioHandler.h" +int soundMuted=0; void action_none(P_Button* caller) { //return nothing @@ -19,9 +20,21 @@ void action_setStateToMainMenu(P_Button* caller) void action_muteSound(P_Button* caller) { - //Mute sound -> Master Volume = 0 - AudioHandler audioHandler = *((AudioHandler*)caller->arg); - changeMasterVol(&audioHandler,0); + argsSoundButton argsSoundB = *(argsSoundButton*)caller->arg; + AudioHandler audioHandler = argsSoundB.audio; + + //fprintf(stderr,"Sound muted = %d\n",soundMuted); + + if(!soundMuted) + { + changeMasterVol(&audioHandler,0); + soundMuted=1; + } + else + { + changeMasterVol(&audioHandler,10); + soundMuted=0; + } //Change Icon -> Mute icon //caller->texture = createTextureFromPath(renderer,"rsrc/img/MuteResized.png"); diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index 992bb3a..3be3fb2 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -10,12 +10,10 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState, AudioHandler audioHandler) { - SDL_Color menuBorderColor= {0,0,255,255}; + + 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; SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer); @@ -38,9 +36,9 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHan array_P_Button_AddElement(&buttons, createButton(settingsButtonTexture, settingsButtonHoverTexture, 750,10,50,50,&action_print)); //top right corner (square or circle) // Mute/Unmute + argsSoundButton argsSoundButt = {audioHandler, renderer}; 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; - + array_P_Button_Last(&buttons)->arg = (void*)&argsSoundButt; return buttons; } From 5beb6b31d8b6d04de7c4164802987bcd7c833781 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 11:01:50 +0100 Subject: [PATCH 09/13] patch textInput et textinput processor --- Pontu/entryPoints/test.c | 8 ++++---- Pontu/include/engine/TextInput.h | 2 ++ Pontu/src/engine/InputProcessor.c | 2 +- Pontu/src/engine/TextInput.c | 18 ++++++++++++++++++ Pontu/test/testTextInputWithProcessor.c | 5 +++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index f7b47c0..8af4de1 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -6,11 +6,11 @@ //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c //#include "../test/testSettingsView.c" -#include "../test/testCreationMenu.c" +//#include "../test/testCreationMenu.c" //#include "../test/testGameInterface.c" //#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" -//#include "../test/testTextInputWithProcessor.c" +#include "../test/testTextInputWithProcessor.c" //#include "../test/oldMain__ThisCanBeGameMain.c" /* This file is meant to be modified (used only to called other tests functions) @@ -21,14 +21,14 @@ int main(int argc, char *argv[]) { //testAudioHandler(); //testFontLoader(); //testGenerateurTexture(); - //testTextInputProcessor(); + testTextInputProcessor(); //testButtonTextureLoader(); //testConnectionMenu(); //testMenuEndGame(); //testButton(); //testGameInterface(); //testDrawMainMenu(); - testCreationMenu(); + //testCreationMenu(); //testSettingsView(); return 0; diff --git a/Pontu/include/engine/TextInput.h b/Pontu/include/engine/TextInput.h index 67e1e29..3e790d4 100644 --- a/Pontu/include/engine/TextInput.h +++ b/Pontu/include/engine/TextInput.h @@ -35,6 +35,8 @@ typedef struct TTF_Font* textFont; }TextInput; +bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd); + /** * \brief Add a character on the right place on the textInput * \param[in,out] textInput Memmory address of the TextInput to modify diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index edd9626..8c4f9ee 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -79,7 +79,7 @@ InputElement proccessInput(InputProcessor *inputProcessor) } break; case SDL_TEXTINPUT: - addStringToInputTextValueAtCursor(inputProcessor->selectedTextInput, event.text.text); + addStringToInputTextValue(inputProcessor->selectedTextInput, event.text.text); return createInputElementTextInput(inputProcessor->selectedTextInput); break; case SDL_TEXTEDITING: diff --git a/Pontu/src/engine/TextInput.c b/Pontu/src/engine/TextInput.c index ac9899c..ca41910 100644 --- a/Pontu/src/engine/TextInput.c +++ b/Pontu/src/engine/TextInput.c @@ -1,5 +1,23 @@ #include "engine/TextInput.h" +bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd) { + if(textInput == NULL) + { + fprintf(stderr, "WARNING: Can't add text to NULL textInput\n"); + return false; + } + + const size_t lenText = strlen(textInput->value); + const size_t lenStrToAdd = strlen(strToAdd); + char* lastValue = textInput->value; + + textInput->value = (char*) realloc(textInput->value, sizeof(char) * (lenText+lenStrToAdd+1)); + strcpy(textInput->value, lastValue); + strcat(textInput->value, strToAdd); + textInput->cursorPosition += lenStrToAdd; + return true; +} + bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAdd) { if(textInput == NULL) diff --git a/Pontu/test/testTextInputWithProcessor.c b/Pontu/test/testTextInputWithProcessor.c index 59f3c5d..e89d009 100644 --- a/Pontu/test/testTextInputWithProcessor.c +++ b/Pontu/test/testTextInputWithProcessor.c @@ -94,6 +94,9 @@ void testTextInputProcessor() { break; } + case InputType_TextInput: + drawTextInputOnRenderer(renderer, inputElement.data.textInput); + needToPresent = true; default: break; } @@ -101,8 +104,6 @@ void testTextInputProcessor() { } - drawTextInputOnRenderer(renderer, textInput); - needToPresent = true; if (needToPresent) { SDL_RenderPresent(renderer); From 27bdd421ede95457f58cbe9154927c1768020b32 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 11:08:46 +0100 Subject: [PATCH 10/13] remove unused function warning --- Pontu/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pontu/CMakeLists.txt b/Pontu/CMakeLists.txt index 74fe749..fadbcc4 100644 --- a/Pontu/CMakeLists.txt +++ b/Pontu/CMakeLists.txt @@ -27,8 +27,8 @@ if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) target_compile_options(Test PRIVATE /W4 /WX) else() - target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic) - target_compile_options(Test PRIVATE -Wall -Wextra -Wpedantic) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Wno-unused-function) + target_compile_options(Test PRIVATE -Wall -Wextra -Wpedantic -Wno-unused-function) endif() target_link_libraries(${PROJECT_NAME} SDL2::Main) From 666833c670d81d6befc9d6f28d9156966aca3ba4 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 11:10:11 +0100 Subject: [PATCH 11/13] Start debian pkg --- package_linux/pontu/DEBIAN/control | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 package_linux/pontu/DEBIAN/control diff --git a/package_linux/pontu/DEBIAN/control b/package_linux/pontu/DEBIAN/control new file mode 100644 index 0000000..0989b04 --- /dev/null +++ b/package_linux/pontu/DEBIAN/control @@ -0,0 +1,9 @@ +Package: pontu-game +Description: A board game by Grain de créa on your computer +Version: 0.8 +Maintainer: Théotime "LR06" Maillarbaux, Érina Point, Ms Hater, Martin Rouault MANM, Jack Thomas +Architecture: all +Depends: libsdl2-2.0-0, libsdl2-mixer-2.0-0, libsdl2-ttf-2.0-0, libsdl2-image-2.0-0 +Built-Using: gcc-8.3.0 (= 8.3.0-6) +Section: games + From 401228a37946390199aee54b2aa81858d5ff0137 Mon Sep 17 00:00:00 2001 From: thmaillarb Date: Mon, 7 Mar 2022 11:12:48 +0100 Subject: [PATCH 12/13] TextInputs in GameCreationMenu now functionnal(ish) --- Pontu/entryPoints/test.c | 8 ++++---- Pontu/src/view/GameCreationMenu.c | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index 8af4de1..af8cd92 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -6,11 +6,11 @@ //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c //#include "../test/testSettingsView.c" -//#include "../test/testCreationMenu.c" +#include "../test/testCreationMenu.c" //#include "../test/testGameInterface.c" //#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" -#include "../test/testTextInputWithProcessor.c" +//#include "../test/testTextInputWithProcessor.c" //#include "../test/oldMain__ThisCanBeGameMain.c" /* This file is meant to be modified (used only to called other tests functions) @@ -21,14 +21,14 @@ int main(int argc, char *argv[]) { //testAudioHandler(); //testFontLoader(); //testGenerateurTexture(); - testTextInputProcessor(); + //testTextInputProcessor(); //testButtonTextureLoader(); //testConnectionMenu(); //testMenuEndGame(); //testButton(); //testGameInterface(); //testDrawMainMenu(); - //testCreationMenu(); + testCreationMenu(); //testSettingsView(); return 0; diff --git a/Pontu/src/view/GameCreationMenu.c b/Pontu/src/view/GameCreationMenu.c index 7bbd683..767212a 100644 --- a/Pontu/src/view/GameCreationMenu.c +++ b/Pontu/src/view/GameCreationMenu.c @@ -402,6 +402,10 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH break; } break; + case InputType_TextInput: + drawTextInputOnRenderer(renderer, inputElement.data.textInput); + SDL_RenderPresent(renderer); + break; default: break; } From 042682d6c889420800927213b98e0f08025ca864 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Mar 2022 11:22:25 +0100 Subject: [PATCH 13/13] TextInput draw bug corrected --- Pontu/src/engine/TextInput.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Pontu/src/engine/TextInput.c b/Pontu/src/engine/TextInput.c index ca41910..d337b3a 100644 --- a/Pontu/src/engine/TextInput.c +++ b/Pontu/src/engine/TextInput.c @@ -9,10 +9,8 @@ bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd) { const size_t lenText = strlen(textInput->value); const size_t lenStrToAdd = strlen(strToAdd); - char* lastValue = textInput->value; textInput->value = (char*) realloc(textInput->value, sizeof(char) * (lenText+lenStrToAdd+1)); - strcpy(textInput->value, lastValue); strcat(textInput->value, strToAdd); textInput->cursorPosition += lenStrToAdd; return true; @@ -117,7 +115,7 @@ bool drawTextInputOnRenderer(SDL_Renderer* renderer, const TextInput* textInput) fprintf(stderr, "WARNING: Can't create TextInput texture: %s\n", SDL_GetError()); return false; } - char textValue[strlen(textInput->value)+1]; + char textValue[strlen(textInput->value)+2]; SDL_Rect size = {.x=0, .y=0, .w=textInput->size.w, .h=textInput->size.h}; if(textInput->textFont == NULL) {