diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-09 22:06:21 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-09 22:21:33 +0100 |
commit | c25e1d6fd68f1f85af9e7f6dd0d35c725000014f (patch) | |
tree | efb7cb8a1d1919877c3b218a1510140935d43ec3 | |
parent | 8c37dc0c5e6f4e588d37f5900764125716bc7f77 (diff) |
allow to display a multiple selection
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | blits.c | 55 | ||||
-rw-r--r-- | blits.h | 2 | ||||
-rw-r--r-- | jouer.c | 28 |
3 files changed, 58 insertions, 27 deletions
@@ -125,7 +125,7 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct char TTF_CloseFont (police); } -static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) +static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) { SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; TTF_Font *font = TTF_OpenFont("times.ttf", 20); @@ -135,18 +135,22 @@ static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struc /* display the information frame */ SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible); - /* display the name of the character */ - surf_name = TTF_RenderText_Blended(font, chr->name, color); + if (target->is_chr) { + /* display the name of the character */ + surf_name = TTF_RenderText_Blended(font, target->chr->name, color); - pos_name.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; - pos_name.y = positions->Vpositioncadrecible.y + 10; + /* display the affinities of the character */ + blit_character_affinities(surfaces, positions, target->chr); - /* display the affinities of the character */ - blit_character_affinities(surfaces, positions, chr); + /* display its HP / MP */ + Fblitterpvcible (surfaces,positions, target->chr); + Fblitterpmcible (surfaces,positions, target->chr); + } else { + surf_name = TTF_RenderText_Blended(font, target->team->name, color); + } - /* display its HP / MP */ - Fblitterpvcible (surfaces,positions, chr); - Fblitterpmcible (surfaces,positions, chr); + pos_name.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; + pos_name.y = positions->Vpositioncadrecible.y + 10; SDL_BlitSurface(surf_name, NULL, surfaces->Pecran, &pos_name); @@ -154,25 +158,40 @@ static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struc TTF_CloseFont(font); } -void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) { /* clear cursor */ SDL_BlitSurface(surfaces->Pfondjeu, &positions->last_cursor, surfaces->Pecran, &positions->last_cursor); - if (chr == NULL) { + if (target == NULL) { /* clear the target informations frame */ SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositioncadrecible, surfaces->Pecran, &positions->Vpositioncadrecible); } else { /* display the new cursor */ - positions->last_cursor.x = chr->pos_curs.x; - positions->last_cursor.y = chr->pos_curs.y; + if (target->is_chr) { + positions->last_cursor.x = target->chr->pos_curs.x; + positions->last_cursor.y = target->chr->pos_curs.y; - positions->last_cursor.w = chr->curs->w; - positions->last_cursor.h = chr->curs->h; + positions->last_cursor.w = target->chr->curs->w; + positions->last_cursor.h = target->chr->curs->h; - SDL_BlitSurface(chr->curs, NULL, surfaces->Pecran, &chr->pos_curs); + SDL_BlitSurface(target->chr->curs, NULL, surfaces->Pecran, &target->chr->pos_curs); + + } else { + for (int i = 0; i < target->team->chr_cnt; ++i) { + struct character_t *chr = &target->team->chrs[i]; + + positions->last_cursor.x = chr->pos_curs.x; + positions->last_cursor.y = chr->pos_curs.y; + + positions->last_cursor.w = chr->curs->w; + positions->last_cursor.h = chr->curs->h; + + SDL_BlitSurface(chr->curs, NULL, surfaces->Pecran, &chr->pos_curs); + } + } - display_target_infos(surfaces, positions, chr); + display_target_infos(surfaces, positions, target); } } @@ -10,7 +10,7 @@ void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t * void blit_team(SURFACES *surfaces, struct team_t *team); void blit_character(SURFACES *surfaces, struct character_t *chr); -void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr); +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct target_t *target); void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected); #endif /* BLITS_H */ @@ -127,10 +127,11 @@ enum action_state_t select_target(struct action_params_t *params, void *data, struct character_t *new_selection; SDL_Event event; + /* TODO update to reflect the selection preferences */ target.is_chr = true; target.chr = params->src; - update_selected_target(surfaces, positions, target.chr); + update_selected_target(surfaces, positions, &target); SDL_Flip(surfaces->Pecran); for (;;) { @@ -147,36 +148,47 @@ enum action_state_t select_target(struct action_params_t *params, void *data, return ACTION_CANCELED; case SDLK_UP: case SDLK_k: + if (!target.is_chr) + continue; + new_selection = find_prev_team_member(target.chr); if (new_selection->idx == target.chr->idx) continue; target.chr = new_selection; - update_selected_target(surfaces, positions, target.chr); + update_selected_target(surfaces, positions, &target); SDL_Flip(surfaces->Pecran); break; case SDLK_DOWN: case SDLK_j: + if (!target.is_chr) + continue; + new_selection = find_next_team_member(target.chr); if (new_selection->idx == target.chr->idx) continue; target.chr = new_selection; - update_selected_target(surfaces, positions, target.chr); + update_selected_target(surfaces, positions, &target); SDL_Flip(surfaces->Pecran); break; case SDLK_LEFT: case SDLK_h: case SDLK_RIGHT: case SDLK_l: - new_selection = get_first_alive_character((target.chr->team == params->t1) ? params->t2 : params->t1); - if (new_selection == NULL) - continue; + if (target.is_chr) { + new_selection = get_first_alive_character((target.chr->team == params->t1) ? params->t2 : params->t1); + if (new_selection == NULL) + continue; + + target.chr = new_selection; + } else { + target.team = (target.team == params->t1) ? params->t2 : params->t1; + } - target.chr = new_selection; - update_selected_target(surfaces, positions, target.chr); + update_selected_target(surfaces, positions, &target); SDL_Flip(surfaces->Pecran); break; case SDLK_RETURN: |