diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-11 01:42:56 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-11 01:44:54 +0100 |
commit | b37b127792e09cb7148200e0bccf294892e9a889 (patch) | |
tree | f2dcf5e465428fd8aa65d5b738987fc712ed8946 /menuchoixpersos.c | |
parent | 46c4037c905598cc0e41ac5464492384331aa57c (diff) |
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 <duskcoder@gmail.com>
Diffstat (limited to 'menuchoixpersos.c')
-rw-r--r-- | menuchoixpersos.c | 64 |
1 files changed, 41 insertions, 23 deletions
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); -} |