summaryrefslogtreecommitdiff
path: root/jouer.c
diff options
context:
space:
mode:
Diffstat (limited to 'jouer.c')
-rw-r--r--jouer.c129
1 files changed, 71 insertions, 58 deletions
diff --git a/jouer.c b/jouer.c
index 04e7188..1d14e0f 100644
--- a/jouer.c
+++ b/jouer.c
@@ -5,6 +5,8 @@
#include "constantes.h"
#include "prototypes.h"
+#include "priv_entries.h"
+
static inline void highlight_current_character(struct team_t *team)
{
struct character_t *chr = &team->chrs[team->chr_cur];
@@ -61,19 +63,62 @@ static void update_current_character(struct team_t *ally, bool *ally_turn)
}
}
+enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, struct action_params_t *params)
+{
+ SDL_Event event;
+ const struct entry_t *target;
+ int selection = 0;
+
+ update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection);
+
+ for (;;) {
+ SDL_WaitEvent(&event);
+
+ if (event.type != SDL_KEYDOWN)
+ continue;
+
+ switch (event.key.keysym.sym) {
+ case SDLK_a:
+ case SDLK_ESCAPE:
+ update_list_entries(params->surfaces, params->positions, NULL, 0, -1);
+ return ACTION_CANCELED;
+ case SDLK_k:
+ case SDLK_UP:
+ selection = (selection > 0) ? selection - 1 : cnt_entries - 1;
+ update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection);
+ break;
+ case SDLK_j:
+ case SDLK_DOWN:
+ selection = (selection < cnt_entries - 1) ? selection + 1 : 0;
+ update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection);
+ break;
+ case SDLK_f:
+ case SDLK_RETURN:
+ target = &entries[selection];
+ if (!target->children_cnt) {
+ return target->f(params->surfaces, params->positions, params->t1, params->t2, target->data);
+ }
+
+ if (dig_entry(target->children, target->children_cnt, params) == ACTION_PERFORMED)
+ return ACTION_PERFORMED;
+
+ update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection);
+ default:
+ break;
+ }
+ }
+}
+
int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
unsigned int continuer=1;
- int selection=0;
int i;
- SDL_Event event;
int Vtourennemi=0;
int Vtour;
int Vnbennemis=0;
- int page=0;
- int nbactions=5;
unsigned int gagne,perdu;
+
if(surfaces->Pfondjeu!=NULL)
{
SDL_FreeSurface(surfaces->Pfondjeu);
@@ -94,10 +139,22 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struc
blit_team(surfaces, ally);
blit_team(surfaces, enemy);
+ SDL_Flip(surfaces->Pecran);
+
while (continuer)
{
if(Vtour==ALLIE) //si un player joue
{
+ struct action_params_t params = {
+ .surfaces = surfaces,
+ .positions = positions,
+
+ .t1 = ally,
+ .t2 = enemy,
+ };
+
+ enum action_state_t state;
+
while (!ally->chrs[ally->chr_cur].alive) //si le perso selectionné est mort
{
if (ally->chr_cur < ally->chr_cnt) // si ce n'est pas le dernier
@@ -105,62 +162,18 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struc
else // sinon si c'est le dernier
ally->chr_cur = 0; // on reprend le 1er
}
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS);
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.unicode)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- continuer=0;
- break;
- }
- switch (event.key.keysym.sym)
- {
- case SDLK_UP:
- case SDLK_k:
- if (selection!=0)
- selection--;
- else
- selection=nbactions-1;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS);
- break;
- case SDLK_DOWN:
- case SDLK_j:
- if (selection!=nbactions-1)
- selection++;
- else
- selection=0;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS);
+
+ state = dig_entry(action_entries_g, countof(action_entries_g), &params);
+ switch (state) {
+ case ACTION_CANCELED:
+ continuer = 0;
break;
- case SDLK_RETURN:
- case SDLK_f:
- {
- enum action_state_t (*actionp)(SURFACES *, POSITIONS *, struct team_t *ally, struct team_t *enemy) = NULL;
-
- switch (selection) {
- case ATTAQUE: actionp = Fattaquer; break;
- case MAGIE_BLANCHE: actionp = Fselectionnermagieblanche; break;
- case MAGIE_NOIRE: actionp = Fselectionnermagienoire; break;
- case TECHNIQUES: break;
- case OBJETS: actionp = Fselectionnerobjet; break;
- default: abort(); break;
- }
-
- if (actionp && (*actionp)(surfaces,positions, ally, enemy) == ACTION_PERFORMED) {
- update_current_character(ally, (bool *)&Vtour);
- blit_team(surfaces, ally);
- }
- }
+ case ACTION_PERFORMED:
+ update_current_character(ally, (bool *)&Vtour);
+ blit_team(surfaces, ally);
break;
- default:
+ default:
break;
- }
- break;
}
}
else if(Vtour==ENNEMI) // sinon si c'est le cpu qui joue
@@ -172,7 +185,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struc
Vtourennemi = 0;
}
}
-/* TODO reactivate */
+ /* TODO reactivate */
#if 0
Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie);
#else