Mercurial > molko
annotate src/libmlk-rpg/rpg/battle-bar-default.c @ 386:7d5032755b7d
rpg: cleanup leftovers
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 15 Feb 2022 16:01:29 +0100 |
parents | 3f13dc6c0e37 |
children | ef2fc4442ed5 |
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 /* Don't forget to reset the gridmenu state. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
131 gridmenu_reset(&bar->sub_grid); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
132 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
133 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
|
134 return; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
135 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
|
136 return; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
137 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
138 /* 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
|
139 spell_select(sp, bt, &sel); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
140 battle_state_selection(bt, &sel); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
141 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
142 /* A cursor should be present. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
143 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
|
144 tracef("battle: no cursor sprite in theme"); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
145 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
148 switch_selection_item(struct battle *bt) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
149 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
150 const struct selection slt = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
151 .allowed_kinds = SELECTION_KIND_ONE, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
152 .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
|
153 .index_side = 1, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
154 .index_character = bt->order_curindex |
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 battle_state_selection(bt, &slt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
158 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
159 |
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 * 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
|
162 * on the current selected menu. |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
163 */ |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
166 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
|
167 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
168 struct label label = {0}; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
169 unsigned int lw = 0, lh = 0; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
170 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
171 label.flags = LABEL_FLAGS_SHADOW; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
172 label.text = what; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
173 label_query(&label, &lw, &lh); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
174 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
|
175 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
|
176 label_draw(&label); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
177 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
180 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
|
181 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
182 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
|
183 const struct spell *sp; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
184 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
185 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
|
186 return; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
187 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
|
188 return; |
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 draw_help(bar, bt, sp->description); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
191 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
194 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
|
195 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
196 const struct inventory_slot *slot; |
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 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
|
199 return; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
200 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
201 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
|
202 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
203 if (!slot->item) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
204 return; |
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 draw_help(bar, bt, slot->item->description); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
207 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
208 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
209 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
210 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
|
211 const struct character *ch, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
212 int x, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
213 int y, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
214 unsigned int w, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
215 unsigned int h) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
216 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
217 struct theme *theme = BATTLE_THEME(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
218 struct label label; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
219 unsigned int spacing, lw, lh; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
220 char line[64]; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
221 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
222 /* Compute spacing between elements. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
223 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
|
224 spacing /= 4; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
225 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
226 /* Reuse the same label. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
227 label.theme = theme; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
228 label.text = line; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
229 label.flags = LABEL_FLAGS_SHADOW; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
230 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
231 /* HP. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
232 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
|
233 label_query(&label, &lw, &lh); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
234 label.x = x + w - lw - theme->padding; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
235 label.y = y + spacing; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
236 label_draw(&label); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
237 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
238 /* MP. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
239 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
|
240 label_query(&label, &lw, &lh); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
241 label.x = x + w - lw - theme->padding; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
242 label.y = label.y + lh + spacing; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
243 label_draw(&label); |
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 /* Status. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
246 /* TODO: list all status. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
247 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
248 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
249 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
250 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
|
251 const struct battle *bt, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
252 const struct character *ch, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
253 unsigned int index) |
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 int x, y; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
256 unsigned int w, h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
257 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
258 /* Compute bounding box for rendering. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
259 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
|
260 h = bar->status_frame.h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
261 x = bar->status_frame.x + (index * w); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
262 y = bar->status_frame.y; |
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 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
|
265 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
268 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
|
269 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
270 const struct battle_entity *et; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
271 unsigned int index = 0; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
272 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
273 BATTLE_TEAM_FOREACH(bt, et) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
274 if (character_ok(et->ch)) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
275 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
|
276 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
277 ++index; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
278 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
279 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
282 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
|
283 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
284 frame_draw(&bar->status_frame); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
285 draw_status_characters(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
286 } |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
289 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
|
290 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
291 struct { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
292 unsigned int w, h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
293 enum align align; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
294 struct label label; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
295 } buttons[] = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
296 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
297 .align = ALIGN_TOP, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
298 .label = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
299 .text = _("Attack"), |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
300 .flags = LABEL_FLAGS_SHADOW |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
301 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
302 }, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
303 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
304 .align = ALIGN_RIGHT, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
305 .label = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
306 .text = _("Magic"), |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
307 .flags = LABEL_FLAGS_SHADOW |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
308 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
309 }, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
310 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
311 .align = ALIGN_BOTTOM, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
312 .label = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
313 .text = _("Objects"), |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
314 .flags = LABEL_FLAGS_SHADOW |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
315 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
316 }, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
317 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
318 .align = ALIGN_LEFT, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
319 .label = { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
320 .text = _("Special"), |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
321 .flags = LABEL_FLAGS_SHADOW |
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 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
324 }; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
325 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
326 struct theme theme; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
327 int bx, by; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
328 unsigned int bw, bh; |
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 /* Copy theme according to menu selection. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
331 theme_shallow(&theme, bt->theme); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
332 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
333 /* Compute bounding box with margins removed. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
334 bx = bar->menu_frame.x + theme.padding; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
335 by = bar->menu_frame.y + theme.padding; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
336 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
|
337 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
|
338 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
339 /* Draw menu frame. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
340 frame_draw(&bar->menu_frame); |
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 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
|
343 buttons[i].label.theme = &theme; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
344 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
345 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
|
346 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
347 /* Change theme if it's selected. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
348 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
|
349 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
|
350 else |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
351 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
|
352 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
353 align(buttons[i].align, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
354 &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
|
355 bx, by, bw, bh); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
356 label_draw(&buttons[i].label); |
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 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
359 |
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 * 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
|
362 * 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
|
363 */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
364 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
365 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
|
366 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
367 (void)bt; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
368 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
369 switch (ev->key.key) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
370 case KEY_UP: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
371 bar->menu = BATTLE_BAR_DEFAULT_MENU_ATTACK; |
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_RIGHT: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
374 bar->menu = BATTLE_BAR_DEFAULT_MENU_MAGIC; |
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_DOWN: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
377 bar->menu = BATTLE_BAR_DEFAULT_MENU_ITEM; |
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_LEFT: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
380 bar->menu = BATTLE_BAR_DEFAULT_MENU_SPECIAL; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
381 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
382 case KEY_ENTER: |
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 * 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
|
385 * we change selection state immediately if needed. |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
386 */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
387 switch (bar->menu) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
388 case BATTLE_BAR_DEFAULT_MENU_ATTACK: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
389 switch_selection_attack(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_ITEM: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
392 battle_bar_default_open_item(bar, bt); |
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 case BATTLE_BAR_DEFAULT_MENU_MAGIC: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
395 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
|
396 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
397 default: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
398 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
399 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
400 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
401 default: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
402 break; |
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 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
405 |
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 * 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
|
408 * and Magic. |
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 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
411 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
|
412 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
413 /* 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
|
414 if (ev->key.key == KEY_ESCAPE) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
415 gridmenu_reset(&bar->sub_grid); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
416 bar->state = BATTLE_BAR_DEFAULT_STATE_MENU; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
417 return; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
418 } |
386
7d5032755b7d
rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents:
385
diff
changeset
|
419 |
385
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
420 gridmenu_handle(&bar->sub_grid, ev); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
421 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
422 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
|
423 gridmenu_reset(&bar->sub_grid); |
386
7d5032755b7d
rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents:
385
diff
changeset
|
424 |
385
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
425 switch (bar->menu) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
426 case BATTLE_BAR_DEFAULT_MENU_MAGIC: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
427 switch_selection_spell(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
428 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
429 case BATTLE_BAR_DEFAULT_MENU_ITEM: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
430 switch_selection_item(bt); |
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 default: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
433 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
434 } |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
438 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
439 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
|
440 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
441 assert(ev->type == EVENT_KEYDOWN); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
442 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
443 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
|
444 [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
|
445 [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
|
446 }; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
447 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
448 handlers[bar->state](bar, bt, ev); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
451 #if 0 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
452 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
453 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
454 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
|
455 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
456 (void)bar; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
457 (void)bt; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
458 (void)ev; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
459 assert(ev->type == EVENT_CLICKDOWN); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
460 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
461 switch (bar->state) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
462 case BATTLE_BAR_DEFAULT_STATE_MENU: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
463 /* We are selecting a main menu entry. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
464 /* TODO: implement click here too. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
465 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
466 case BATTLE_BAR_DEFAULT_STATE_SUB: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
467 /* 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
|
468 gridmenu_handle(&bar->sub_grid, ev); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
469 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
470 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
|
471 default: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
472 break; |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
475 return 0; |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
478 #endif |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
479 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
480 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
481 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
|
482 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
483 bar->sub_grid.x = bar->x; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
484 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
|
485 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
|
486 bar->sub_grid.h = bar->h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
487 bar->sub_grid.theme = bt->theme; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
488 bar->sub_grid.nrows = 3; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
489 bar->sub_grid.ncols = 4; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
490 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
491 memset(bar->sub_grid.menu, 0, sizeof (bar->sub_grid.menu)); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
494 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
495 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
|
496 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
497 (void)bt; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
498 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
499 battle_bar_default_start(bar->data); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
502 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
503 select(struct battle_bar *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
|
504 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
505 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
|
506 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
507 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
508 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
509 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
|
510 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
511 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
|
512 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
513 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
514 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
515 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
|
516 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
517 battle_bar_default_draw(bar->data, bt); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
520 static void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
521 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
|
522 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
523 (void)bt; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
524 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
525 battle_bar_default_finish(bar->data); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
526 free(bar->data); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
529 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
530 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
|
531 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
532 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
533 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
534 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
535 bar->w = window.w; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
536 bar->h = window.h * 0.12; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
537 bar->x = 0; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
538 bar->y = window.h - bar->h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
539 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
540 /* 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
|
541 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
|
542 bar->menu_frame.h = bar->h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
543 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
|
544 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
|
545 bar->menu_frame.theme = bt->theme; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
546 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
547 /* Status bar on the right. */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 bar->status_frame.h = bar->h; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
552 bar->status_frame.theme = bt->theme; |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
555 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
556 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
|
557 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
558 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
559 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
560 assert(ch); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
561 |
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; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
571 } |
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 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
574 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
|
575 { |
386
7d5032755b7d
rpg: cleanup leftovers
David Demelier <markand@malikania.fr>
parents:
385
diff
changeset
|
576 assert(bar); |
385
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
577 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
578 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
579 init_gridmenu(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
580 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
581 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
|
582 if (bt->inventory->items[i].item) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
587 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
588 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
589 gridmenu_repaint(&bar->sub_grid); |
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 bar->state = BATTLE_BAR_DEFAULT_STATE_GRID; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
592 } |
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 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
595 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
|
596 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
597 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
598 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
599 gridmenu_reset(&bar->sub_grid); |
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 bar->menu = BATTLE_BAR_DEFAULT_MENU_ATTACK; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
602 bar->state = BATTLE_BAR_DEFAULT_STATE_MENU; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
603 } |
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 /* |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
606 * 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
|
607 * 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
|
608 */ |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
609 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
610 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
|
611 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
612 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
613 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
614 assert(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 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
|
617 [BATTLE_BAR_DEFAULT_MENU_ATTACK] = validate_attack, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
618 [BATTLE_BAR_DEFAULT_MENU_ITEM] = validate_item, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
619 [BATTLE_BAR_DEFAULT_MENU_MAGIC] = validate_magic, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
620 [BATTLE_BAR_DEFAULT_MENU_SPECIAL] = NULL |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
621 }; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
622 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
623 if (validate[bar->menu]) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
624 validate[bar->menu](bar, bt, sel); |
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 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
628 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
|
629 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
630 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
631 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
632 assert(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 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
|
635 [EVENT_KEYDOWN] = handle_keydown, |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
636 [EVENT_NUM] = NULL |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
639 if (handlers[ev->type]) |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
640 handlers[ev->type](bar, bt, ev); |
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 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
644 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
|
645 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
646 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
647 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
648 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
649 draw_status(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
650 draw_menu(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
651 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
652 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
|
653 switch (bar->menu) { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
654 case BATTLE_BAR_DEFAULT_MENU_MAGIC: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
655 draw_spell_help(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
656 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
657 case BATTLE_BAR_DEFAULT_MENU_ITEM: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
658 draw_item_help(bar, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
659 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
660 default: |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
661 break; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
662 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
663 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
664 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
665 /* 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
|
666 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
|
667 gridmenu_draw(&bar->sub_grid); |
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 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
670 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
671 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
|
672 { |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
673 assert(bar); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
674 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
675 gridmenu_finish(&bar->sub_grid); |
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 memset(bar, 0, sizeof (*bar)); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
678 } |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
679 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
680 void |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
681 battle_bar_default(struct battle *bt) |
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 assert(bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
684 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
685 struct self *self; |
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 self = alloc_new0(sizeof (*self)); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
688 self->bar.data = self; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
689 self->bar.start = start; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
690 self->bar.select = select; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
691 self->bar.handle = handle; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
692 self->bar.draw = draw; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
693 self->bar.finish = finish; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
694 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
695 battle_bar_default_positionate(&self->data, bt); |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
696 |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
697 bt->bar = &self->bar; |
3f13dc6c0e37
rpg: separate battle and the bar, closes #2522
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
698 } |