From b37b127792e09cb7148200e0bccf294892e9a889 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 11 Jan 2015 01:42:56 +0100 Subject: remove or replace a lot of code for the initialization many structures or positions were not revelant anymore and thus have been removed. some positions were not relative to each other it is sometimes not meaningful to put surfaces in the global scope when they only need to be used once. Signed-off-by: Olivier Gayot --- menuchoixpersos.c | 64 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'menuchoixpersos.c') diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 90c36a4..3d55efd 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -156,6 +156,32 @@ struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team return team; } +static void Fchangersurlignage2(int Vchoix, SURFACES *surfaces, + SDL_Surface *text, POSITIONS *positions) +{ + SDL_Surface *surf; + + if (Vchoix == CLASS_PALADIN) { + surf = surfaces->Pchoixpaladin; + } else if (Vchoix == CLASS_PRIEST) { + surf = surfaces->Pchoixpretre; + } else if (Vchoix == CLASS_THIEF) { + surf = surfaces->Pchoixvoleur; + } else { + abort(); + } + + /* this surface fills the whole screen */ + SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); + + SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); + SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); + SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); + + SDL_BlitSurface(text, NULL, surfaces->screen, &positions->Vpositiontextemenu); + + SDL_Flip (surfaces->Pecran); +} void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { @@ -180,22 +206,27 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) "Please choose the class of your third character", }; + SDL_Surface *surf; + /* display the background with the selected text */ if (Vchoix == CLASS_PALADIN) { - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixpaladin; } else if (Vchoix == CLASS_PRIEST) { - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixpretre; } else if (Vchoix == CLASS_THIEF) { - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixvoleur; } else { abort(); } + SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); + /* display the string associated with the current character number (aka Please choose ...) */ - surfaces->Ptextechoixmenu = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert); + surf = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert); + + positions->Vpositiontextemenu.x = surfaces->screen->w / 2 - surf->w / 2; + SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->Vpositiontextemenu); - positions->Vpositiontextemenu.x = surfaces->screen->w / 2 - surfaces->Ptextechoixmenu->w / 2; - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); @@ -218,7 +249,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_THIEF; } - Fchangersurlignage2 (Vchoix,surfaces,positions); + Fchangersurlignage2(Vchoix, surfaces, surf, positions); break; case SDLK_RIGHT: @@ -228,7 +259,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_PALADIN; } - Fchangersurlignage2 (Vchoix,surfaces,positions); + Fchangersurlignage2(Vchoix, surfaces, surf, positions); break; case SDLK_RETURN: case SDLK_f: @@ -241,6 +272,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) break; } } + + SDL_FreeSurface(surf); } SDL_Flip(surfaces->Pecran); @@ -248,18 +281,3 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) enemy_team = new_enemy_team(surfaces, ally_team); Fmap(surfaces,positions, ally_team, enemy_team); } - -void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) -{ - if (Vchoix == CLASS_PALADIN) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix == CLASS_PRIEST) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix == CLASS_THIEF) - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); - SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); - SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); - SDL_Flip (surfaces->Pecran); -} -- cgit v1.2.3