Merge branch 'master' of gitlab.iut-clermont.uca.fr:/maribemont/projet-tut

origin/fixingSettings
Mathis RIBEMONT 3 years ago
commit 428df9b219

@ -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;
}

@ -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

@ -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) {

@ -3,6 +3,8 @@
#include <SDL2/SDL_ttf.h>
#include <engine/FontLoader.h>
#include <engine/TextLabel.h>
#include <engine/arrayButton.h>
#include <engine/arrayTextLabel.h>
//void action boutton
@ -32,6 +34,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)

@ -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);

@ -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]);
}
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);
}
}

@ -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);

Loading…
Cancel
Save