annotate src/libmlk-rpg/rpg/battle-bar-default.c @ 395:ef2fc4442ed5

ui: don't use fixed size arrays
author David Demelier <markand@malikania.fr>
date Fri, 18 Feb 2022 16:02:01 +0100
parents 7d5032755b7d
children 14ce7c4871e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 * battle-bar-default.c -- default battle status bar and menu implementation
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 *
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
4 * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 *
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 *
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
18
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
19 #include <assert.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
20 #include <stdio.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
21 #include <stdlib.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 #include <string.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
23
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
24 #include <core/alloc.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
25 #include <core/event.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
26 #include <core/font.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
27 #include <core/sprite.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
28 #include <core/trace.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
29 #include <core/util.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
30 #include <core/window.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
31
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
32 #include <ui/align.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
33 #include <ui/theme.h>
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
34
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
35 #include "battle-bar-default.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
36 #include "battle-bar.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
37 #include "battle-state-item.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
38 #include "battle-state-selection.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
39 #include "battle.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 #include "character.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 #include "inventory.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
42 #include "item.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 #include "rpg_p.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
44 #include "spell.h"
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
45
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
46 struct self {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
47 struct battle_bar_default data;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
48 struct battle_bar bar;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
49 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
50
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
52 * The following validate_* functions are called when the user has validated a
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
53 * selection depending on the current menu (e.g. Magic, Items).
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
54 *
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
55 * They change the battle state to the appropriate one.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
56 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
57
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
58 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
59 validate_attack(struct battle_bar_default *bar, struct battle *bt, const struct selection *sel)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
60 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
61 (void)bar;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
62
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
63 struct character *target;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
64
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
65 if (sel->index_side == 0)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
66 target = bt->enemies[sel->index_character].ch;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
67 else
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
68 target = bt->team[sel->index_character].ch;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
69
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
70 battle_attack(bt, bt->order_cur->ch, target);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
71 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
72
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
73 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
74 validate_magic(struct battle_bar_default *bar, struct battle *bt, const struct selection *sel)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
75 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
76 struct character *source = bt->order_cur->ch;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
77 const struct spell *spell = source->spells[bar->sub_grid.selected];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
78
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
79 battle_cast(bt, source, spell, sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
80 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
81
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
82 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
83 validate_item(struct battle_bar_default *bar, struct battle *bt, const struct selection *sel)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
84 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
85 struct inventory_slot *slot;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
86 struct battle_entity *source, *target;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
87
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
88 if (bar->sub_grid.selected >= INVENTORY_ITEM_MAX)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
89 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
90 if (!(slot = &bt->inventory->items[bar->sub_grid.selected]))
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
91 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
92
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
93 source = bt->order_cur;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
94 target = sel->index_side == 0
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
95 ? &bt->enemies[sel->index_character]
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
96 : &bt->team[sel->index_character];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
97
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
98 /* TODO: battle_use? */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
99 battle_state_item(bt, source, target, slot);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
100 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
101
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
102 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
103 * The following functions are used to switch to the battle selection state
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
104 * using the appropriate selector algorithm. For example, an item can only be
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
105 * used on a unique target while a spell can have multiple choices.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
106 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
107
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
108 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
109 switch_selection_attack(struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
110 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
111 struct selection sel = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
112 .allowed_kinds = SELECTION_KIND_ONE,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
113 .allowed_sides = SELECTION_SIDE_ENEMY,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
114 .index_side = 0
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
115 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
116
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
117 /* Just make sure */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
118
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
119 selection_first(&sel, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
120 battle_state_selection(bt, &sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
121 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
122
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
123 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
124 switch_selection_spell(struct battle_bar_default *bar, struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
125 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
126 const struct character *ch = bt->order_cur->ch;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
127 const struct spell *sp = ch->spells[bar->sub_grid.selected];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
128 struct selection sel = {0};
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
129
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
130 if (bar->sub_grid.selected > CHARACTER_SPELL_MAX)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
131 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
132 if (!(sp = ch->spells[bar->sub_grid.selected]) || sp->mp > (unsigned int)(ch->mp))
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
133 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
134
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
135 /* Use the spell selection algorithm to fill default values. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
136 spell_select(sp, bt, &sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
137 battle_state_selection(bt, &sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
138
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
139 /* A cursor should be present. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
140 if (!sprite_ok(BATTLE_THEME(bt)->sprites[THEME_SPRITE_CURSOR]))
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
141 tracef("battle: no cursor sprite in theme");
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
142 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
143
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
144 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
145 switch_selection_item(struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
146 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
147 const struct selection slt = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
148 .allowed_kinds = SELECTION_KIND_ONE,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
149 .allowed_sides = SELECTION_SIDE_TEAM | SELECTION_SIDE_ENEMY,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
150 .index_side = 1,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
151 .index_character = bt->order_curindex
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
152 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
153
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
154 battle_state_selection(bt, &slt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
155 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
156
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
157 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
158 * The following functions actually draw the bar and their components depending
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
159 * on the current selected menu.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
160 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
161
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
162 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
163 draw_help(const struct battle_bar_default *bar, const struct battle *bt, const char *what)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
164 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
165 struct label label = {0};
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
166 unsigned int lw = 0, lh = 0;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
167
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
168 label.flags = LABEL_FLAGS_SHADOW;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
169 label.text = what;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
170 label_query(&label, &lw, &lh);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
171 label.x = bar->sub_grid.x + (bar->sub_grid.w / 2) - (lw / 2);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
172 label.y = bar->sub_grid.y - lh - BATTLE_THEME(bt)->padding;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
173 label_draw(&label);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
174 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
175
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
176 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
177 draw_spell_help(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
178 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
179 const struct character *ch = bt->order_cur->ch;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
180 const struct spell *sp;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
181
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
182 if (bar->sub_grid.selected >= CHARACTER_SPELL_MAX)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
183 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
184 if (!(sp = ch->spells[bar->sub_grid.selected]))
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
185 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
186
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
187 draw_help(bar, bt, sp->description);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
188 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
189
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
190 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
191 draw_item_help(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
192 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
193 const struct inventory_slot *slot;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
194
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
195 if (bar->sub_grid.selected >= INVENTORY_ITEM_MAX)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
196 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
197
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
198 slot = &bt->inventory->items[bar->sub_grid.selected];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
199
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
200 if (!slot->item)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
201 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
202
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
203 draw_help(bar, bt, slot->item->description);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
204 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
205
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
206 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
207 draw_status_character_stats(const struct battle *bt,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
208 const struct character *ch,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
209 int x,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
210 int y,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
211 unsigned int w,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
212 unsigned int h)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
213 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
214 struct theme *theme = BATTLE_THEME(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
215 struct label label;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
216 unsigned int spacing, lw, lh;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
217 char line[64];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
218
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
219 /* Compute spacing between elements. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
220 spacing = h - (font_height(theme->fonts[THEME_FONT_INTERFACE]) * 3);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
221 spacing /= 4;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
222
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
223 /* Reuse the same label. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
224 label.theme = theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
225 label.text = line;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
226 label.flags = LABEL_FLAGS_SHADOW;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
227
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
228 /* HP. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
229 snprintf(line, sizeof (line), "%d/%u", ch->hp, ch->hpmax);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
230 label_query(&label, &lw, &lh);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
231 label.x = x + w - lw - theme->padding;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
232 label.y = y + spacing;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
233 label_draw(&label);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
234
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
235 /* MP. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
236 snprintf(line, sizeof (line), "%d/%u", ch->mp, ch->mpmax);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
237 label_query(&label, &lw, &lh);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
238 label.x = x + w - lw - theme->padding;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
239 label.y = label.y + lh + spacing;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
240 label_draw(&label);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
241
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
242 /* Status. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
243 /* TODO: list all status. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
244 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
245
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
246 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
247 draw_status_character(const struct battle_bar_default *bar,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
248 const struct battle *bt,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
249 const struct character *ch,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
250 unsigned int index)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
251 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
252 int x, y;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
253 unsigned int w, h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
254
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
255 /* Compute bounding box for rendering. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
256 w = bar->status_frame.w / BATTLE_TEAM_MAX;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
257 h = bar->status_frame.h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
258 x = bar->status_frame.x + (index * w);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
259 y = bar->status_frame.y;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
260
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
261 draw_status_character_stats(bt, ch, x, y, w, h);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
262 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
263
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
264 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
265 draw_status_characters(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
266 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
267 const struct battle_entity *et;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
268 unsigned int index = 0;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
269
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
270 BATTLE_TEAM_FOREACH(bt, et) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
271 if (character_ok(et->ch))
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
272 draw_status_character(bar, bt, et->ch, index);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
273
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
274 ++index;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
275 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
276 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
277
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
278 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
279 draw_status(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
280 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
281 frame_draw(&bar->status_frame);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
282 draw_status_characters(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
283 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
284
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
285 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
286 draw_menu(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
287 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
288 struct {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
289 unsigned int w, h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
290 enum align align;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
291 struct label label;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
292 } buttons[] = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
293 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
294 .align = ALIGN_TOP,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
295 .label = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
296 .text = _("Attack"),
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
297 .flags = LABEL_FLAGS_SHADOW
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
298 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
299 },
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
300 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
301 .align = ALIGN_RIGHT,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
302 .label = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
303 .text = _("Magic"),
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
304 .flags = LABEL_FLAGS_SHADOW
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
305 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
306 },
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
307 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
308 .align = ALIGN_BOTTOM,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
309 .label = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
310 .text = _("Objects"),
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
311 .flags = LABEL_FLAGS_SHADOW
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
312 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
313 },
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
314 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
315 .align = ALIGN_LEFT,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
316 .label = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
317 .text = _("Special"),
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
318 .flags = LABEL_FLAGS_SHADOW
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
319 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
320 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
321 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
322
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
323 struct theme theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
324 int bx, by;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
325 unsigned int bw, bh;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
326
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
327 /* Copy theme according to menu selection. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
328 theme_shallow(&theme, bt->theme);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
329
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
330 /* Compute bounding box with margins removed. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
331 bx = bar->menu_frame.x + theme.padding;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
332 by = bar->menu_frame.y + theme.padding;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
333 bw = bar->menu_frame.w - theme.padding * 2;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
334 bh = bar->menu_frame.h - theme.padding * 2;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
335
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
336 /* Draw menu frame. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
337 frame_draw(&bar->menu_frame);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
338
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
339 for (size_t i = 0; i < UTIL_SIZE(buttons); ++i) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
340 buttons[i].label.theme = &theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
341
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
342 label_query(&buttons[i].label, &buttons[i].w, &buttons[i].h);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
343
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
344 /* Change theme if it's selected. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
345 if ((size_t)bar->menu == i /*&& bar->state != BATTLE_BAR_DEFAULT_STATE_NONE*/)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
346 theme.colors[THEME_COLOR_NORMAL] = BATTLE_THEME(bt)->colors[THEME_COLOR_SELECTED];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
347 else
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
348 theme.colors[THEME_COLOR_NORMAL] = BATTLE_THEME(bt)->colors[THEME_COLOR_NORMAL];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
349
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
350 align(buttons[i].align,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
351 &buttons[i].label.x, &buttons[i].label.y, buttons[i].w, buttons[i].h,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
352 bx, by, bw, bh);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
353 label_draw(&buttons[i].label);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
354 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
355 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
356
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
357 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
358 * This function is called only in the first level of the bar menu: selecting
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
359 * one of the Attack, Magic, Item and Special items.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
360 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
361 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
362 handle_keydown_menu(struct battle_bar_default *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
363 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
364 (void)bt;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
365
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
366 switch (ev->key.key) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
367 case KEY_UP:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
368 bar->menu = BATTLE_BAR_DEFAULT_MENU_ATTACK;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
369 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
370 case KEY_RIGHT:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
371 bar->menu = BATTLE_BAR_DEFAULT_MENU_MAGIC;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
372 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
373 case KEY_DOWN:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
374 bar->menu = BATTLE_BAR_DEFAULT_MENU_ITEM;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
375 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
376 case KEY_LEFT:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
377 bar->menu = BATTLE_BAR_DEFAULT_MENU_SPECIAL;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
378 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
379 case KEY_ENTER:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
380 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
381 * At this step, attack does not require opening the sub menu so
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
382 * we change selection state immediately if needed.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
383 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
384 switch (bar->menu) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
385 case BATTLE_BAR_DEFAULT_MENU_ATTACK:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
386 switch_selection_attack(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
387 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
388 case BATTLE_BAR_DEFAULT_MENU_ITEM:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
389 battle_bar_default_open_item(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
390 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
391 case BATTLE_BAR_DEFAULT_MENU_MAGIC:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
392 battle_bar_default_open_magic(bar, bt, bt->order_cur->ch);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
393 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
394 default:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
395 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
396 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
397 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
398 default:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
399 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
400 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
401 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
402
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
403 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
404 * This function is called when we're selecting a submenu entry from Items
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
405 * and Magic.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
406 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
407 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
408 handle_keydown_grid(struct battle_bar_default *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
409 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
410 /* Go back to main menu if I press escape. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
411 if (ev->key.key == KEY_ESCAPE) {
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
412 //gridmenu_reset(&bar->sub_grid);
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
413 bar->state = BATTLE_BAR_DEFAULT_STATE_MENU;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
414 return;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
415 }
386
7d5032755b7d rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents: 385
diff changeset
416
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
417 gridmenu_handle(&bar->sub_grid, ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
418
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
419 #if 0
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
420 if (bar->sub_grid.state == GRIDMENU_STATE_ACTIVATED) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
421 gridmenu_reset(&bar->sub_grid);
386
7d5032755b7d rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents: 385
diff changeset
422
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
423 switch (bar->menu) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
424 case BATTLE_BAR_DEFAULT_MENU_MAGIC:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
425 switch_selection_spell(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
426 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
427 case BATTLE_BAR_DEFAULT_MENU_ITEM:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
428 switch_selection_item(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
429 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
430 default:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
431 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
432 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
433 }
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
434 #endif
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
435 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
436
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
437 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
438 handle_keydown(struct battle_bar_default *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
439 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
440 assert(ev->type == EVENT_KEYDOWN);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
441
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
442 static void (*handlers[])(struct battle_bar_default *, struct battle *, const union event *) = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
443 [BATTLE_BAR_DEFAULT_STATE_MENU] = handle_keydown_menu,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
444 [BATTLE_BAR_DEFAULT_STATE_GRID] = handle_keydown_grid
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
445 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
446
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
447 handlers[bar->state](bar, bt, ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
448 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
449
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
450 #if 0
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
451
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
452 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
453 handle_clickdown(struct battle_bar_default *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
454 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
455 (void)bar;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
456 (void)bt;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
457 (void)ev;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
458 assert(ev->type == EVENT_CLICKDOWN);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
459
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
460 switch (bar->state) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
461 case BATTLE_BAR_DEFAULT_STATE_MENU:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
462 /* We are selecting a main menu entry. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
463 /* TODO: implement click here too. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
464 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
465 case BATTLE_BAR_DEFAULT_STATE_SUB:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
466 /* We are in the sub menu (objects/spells). */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
467 gridmenu_handle(&bar->sub_grid, ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
468
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
469 if (bar->sub_grid.state == GRIDMENU_STATE_ACTIVATED)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
470 default:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
471 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
472 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
473
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
474 return 0;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
475 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
476
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
477 #endif
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
478
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
479 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
480 init_gridmenu(struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
481 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
482 bar->sub_grid.x = bar->x;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
483 bar->sub_grid.y = bar->menu_frame.y;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
484 bar->sub_grid.w = bar->status_frame.w;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
485 bar->sub_grid.h = bar->h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
486 bar->sub_grid.theme = bt->theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
487 bar->sub_grid.nrows = 3;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
488 bar->sub_grid.ncols = 4;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
489
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
490 //memset(bar->sub_grid.menu, 0, sizeof (bar->sub_grid.menu));
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
491 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
492
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
493 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
494 start(struct battle_bar *bar, struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
495 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
496 (void)bt;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
497
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
498 battle_bar_default_start(bar->data);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
499 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
500
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
501 static void
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
502 self_select(struct battle_bar *bar, struct battle *bt, const struct selection *sel)
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
503 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
504 battle_bar_default_select(bar->data, bt, sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
505 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
506
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
507 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
508 handle(struct battle_bar *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
509 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
510 battle_bar_default_handle(bar->data, bt, ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
511 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
512
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
513 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
514 draw(const struct battle_bar *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
515 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
516 battle_bar_default_draw(bar->data, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
517 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
518
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
519 static void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
520 finish(struct battle_bar *bar, struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
521 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
522 (void)bt;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
523
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
524 battle_bar_default_finish(bar->data);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
525 free(bar->data);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
526 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
527
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
528 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
529 battle_bar_default_positionate(struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
530 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
531 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
532 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
533
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
534 bar->w = window.w;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
535 bar->h = window.h * 0.12;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
536 bar->x = 0;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
537 bar->y = window.h - bar->h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
538
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
539 /* Menu in the middle of the bar (take 20%). */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
540 bar->menu_frame.w = bar->w * 0.2;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
541 bar->menu_frame.h = bar->h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
542 bar->menu_frame.x = bar->x + (bar->w / 2) - (bar->menu_frame.w / 2);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
543 bar->menu_frame.y = window.h - bar->h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
544 bar->menu_frame.theme = bt->theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
545
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
546 /* Status bar on the right. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
547 bar->status_frame.x = bar->menu_frame.x + bar->menu_frame.w;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
548 bar->status_frame.y = bar->menu_frame.y;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
549 bar->status_frame.w = (bar->w - bar->menu_frame.w) / 2;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
550 bar->status_frame.h = bar->h;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
551 bar->status_frame.theme = bt->theme;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
552 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
553
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
554 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
555 battle_bar_default_open_magic(struct battle_bar_default *bar, const struct battle *bt, struct character *ch)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
556 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
557 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
558 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
559 assert(ch);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
560
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
561 #if 0
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
562 init_gridmenu(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
563
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
564 for (size_t i = 0; i < CHARACTER_SPELL_MAX; ++i)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
565 if (ch->spells[i])
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
566 bar->sub_grid.menu[i] = ch->spells[i]->name;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
567
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
568 gridmenu_repaint(&bar->sub_grid);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
569
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
570 bar->state = BATTLE_BAR_DEFAULT_STATE_GRID;
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
571 #endif
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
572 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
573
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
574 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
575 battle_bar_default_open_item(struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
576 {
386
7d5032755b7d rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents: 385
diff changeset
577 assert(bar);
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
578 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
579
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
580 #if 0
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
581
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
582 init_gridmenu(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
583
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
584 for (size_t i = 0; i < INVENTORY_ITEM_MAX; ++i) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
585 if (bt->inventory->items[i].item) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
586 snprintf(bar->sub_items[i], sizeof (bar->sub_items[i]), "%-16s %u",
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
587 bt->inventory->items[i].item->name, bt->inventory->items[i].amount);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
588 bar->sub_grid.menu[i] = bar->sub_items[i];
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
589 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
590 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
591
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
592 gridmenu_repaint(&bar->sub_grid);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
593
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
594 bar->state = BATTLE_BAR_DEFAULT_STATE_GRID;
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
595 #endif
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
596 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
597
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
598 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
599 battle_bar_default_start(struct battle_bar_default *bar)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
600 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
601 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
602
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
603 //gridmenu_reset(&bar->sub_grid);
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
604
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
605 bar->menu = BATTLE_BAR_DEFAULT_MENU_ATTACK;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
606 bar->state = BATTLE_BAR_DEFAULT_STATE_MENU;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
607 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
608
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
609 /*
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
610 * Apply the battle selection for the current menu item. This function is called
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
611 * from the battle-state-selection state when the user validated the selection.
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
612 */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
613 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
614 battle_bar_default_select(struct battle_bar_default *bar, struct battle *bt, const struct selection *sel)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
615 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
616 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
617 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
618 assert(sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
619
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
620 static void (*validate[])(struct battle_bar_default *, struct battle *, const struct selection *) = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
621 [BATTLE_BAR_DEFAULT_MENU_ATTACK] = validate_attack,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
622 [BATTLE_BAR_DEFAULT_MENU_ITEM] = validate_item,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
623 [BATTLE_BAR_DEFAULT_MENU_MAGIC] = validate_magic,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
624 [BATTLE_BAR_DEFAULT_MENU_SPECIAL] = NULL
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
625 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
626
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
627 if (validate[bar->menu])
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
628 validate[bar->menu](bar, bt, sel);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
629 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
630
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
631 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
632 battle_bar_default_handle(struct battle_bar_default *bar, struct battle *bt, const union event *ev)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
633 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
634 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
635 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
636 assert(ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
637
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
638 static void (*handlers[])(struct battle_bar_default *, struct battle *, const union event *) = {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
639 [EVENT_KEYDOWN] = handle_keydown,
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
640 [EVENT_NUM] = NULL
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
641 };
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
642
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
643 if (handlers[ev->type])
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
644 handlers[ev->type](bar, bt, ev);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
645 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
646
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
647 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
648 battle_bar_default_draw(const struct battle_bar_default *bar, const struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
649 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
650 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
651 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
652
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
653 draw_status(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
654 draw_menu(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
655
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
656 if (bar->state == BATTLE_BAR_DEFAULT_STATE_GRID) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
657 switch (bar->menu) {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
658 case BATTLE_BAR_DEFAULT_MENU_MAGIC:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
659 draw_spell_help(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
660 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
661 case BATTLE_BAR_DEFAULT_MENU_ITEM:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
662 draw_item_help(bar, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
663 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
664 default:
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
665 break;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
666 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
667 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
668
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
669 /* Sub menu is only shown if state is set to it. */
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
670 if (bar->state == BATTLE_BAR_DEFAULT_STATE_GRID)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
671 gridmenu_draw(&bar->sub_grid);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
672 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
673
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
674 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
675 battle_bar_default_finish(struct battle_bar_default *bar)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
676 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
677 assert(bar);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
678
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
679 //gridmenu_finish(&bar->sub_grid);
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
680
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
681 memset(bar, 0, sizeof (*bar));
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
682 }
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
683
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
684 void
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
685 battle_bar_default(struct battle *bt)
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
686 {
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
687 assert(bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
688
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
689 struct self *self;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
690
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
691 self = alloc_new0(sizeof (*self));
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
692 self->bar.data = self;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
693 self->bar.start = start;
395
ef2fc4442ed5 ui: don't use fixed size arrays
David Demelier <markand@malikania.fr>
parents: 386
diff changeset
694 self->bar.select = self_select;
385
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
695 self->bar.handle = handle;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
696 self->bar.draw = draw;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
697 self->bar.finish = finish;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
698
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
699 battle_bar_default_positionate(&self->data, bt);
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
700
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
701 bt->bar = &self->bar;
3f13dc6c0e37 rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff changeset
702 }