comparison libmlk-rpg/rpg/battle-bar.h @ 286:3991779aaba9

adventure: initial test of spawn
author David Demelier <markand@malikania.fr>
date Wed, 23 Dec 2020 15:37:48 +0100
parents 71b3b7036de7
children 9948e288925b
comparison
equal deleted inserted replaced
285:c43e39745cd8 286:3991779aaba9
17 */ 17 */
18 18
19 #ifndef MOLKO_RPG_BATTLE_BAR_H 19 #ifndef MOLKO_RPG_BATTLE_BAR_H
20 #define MOLKO_RPG_BATTLE_BAR_H 20 #define MOLKO_RPG_BATTLE_BAR_H
21 21
22 /** 22 /*
23 * \file battle-bar.h 23 * The bar is split into three individual pieces.
24 * \brief Battle status bar and menu.
25 * 24 *
26 * This module is a view and user input for the game battle. It is used by the 25 * +------------+--------+------------+
27 * \ref battle.h object. 26 * | Grid menu | Menu | Status |
27 * +------------+--------+------------+
28 *
29 *
30 * The left grid menu is only shown when member field state is set to \ref
31 * BATTLE_BAR_STATE_SUB, it is usually opened when user select a magic or an
32 * object.
33 *
34 * The menu in the middle is the main selection and contains the enumeration
35 * battle_bar_menu using top, right, bottom left edges for short selection.
36 *
37 * The last part on the right is the status pane where the team characters stats
38 * are listed.
39 *
40 * By itself, the bar never modify the battle object, it is the responsability
41 * of the battle object or the battle state to change the bar object and to
42 * track change on events. As such, the battle object is always passed as const
43 * parameter.
28 */ 44 */
29 45
30 #include <stdbool.h> 46 #include <stdbool.h>
31 47
32 #include <ui/frame.h> 48 #include <ui/frame.h>
35 struct battle; 51 struct battle;
36 struct character; 52 struct character;
37 53
38 union event; 54 union event;
39 55
40 /**
41 * \brief Main menu selection.
42 */
43 enum battle_bar_menu { 56 enum battle_bar_menu {
44 BATTLE_BAR_MENU_ATTACK = 0, /*!< Attack. */ 57 BATTLE_BAR_MENU_ATTACK = 0,
45 BATTLE_BAR_MENU_MAGIC = 1, /*!< Cast a spell. */ 58 BATTLE_BAR_MENU_MAGIC = 1,
46 BATTLE_BAR_MENU_OBJECTS = 2, /*!< Use an object*/ 59 BATTLE_BAR_MENU_OBJECTS = 2,
47 BATTLE_BAR_MENU_SPECIAL = 3 /*!< Use a special character action. */ 60 BATTLE_BAR_MENU_SPECIAL = 3
48 }; 61 };
49 62
50 /**
51 * \brief Bar state.
52 */
53 enum battle_bar_state { 63 enum battle_bar_state {
54 BATTLE_BAR_STATE_NONE, /*!< No state yet. */ 64 BATTLE_BAR_STATE_NONE,
55 BATTLE_BAR_STATE_MENU, /*!< Main menu selection. */ 65 BATTLE_BAR_STATE_MENU,
56 BATTLE_BAR_STATE_SUB /*!< Sub grid menu opened. */ 66 BATTLE_BAR_STATE_SUB
57 }; 67 };
58 68
59 /**
60 * \brief Battle bar.
61 *
62 * The bar is split into three individual pieces.
63 *
64 * ```
65 * +------------+--------+------------+
66 * | Grid menu | Menu | Status |
67 * +------------+--------+------------+
68 * ```
69 *
70 * The left grid menu is only shown when member field state is set to \ref
71 * BATTLE_BAR_STATE_SUB, it is usually opened when user select a magic or an
72 * object.
73 *
74 * The menu in the middle is the main selection and contains the enumeration
75 * \ref battle_bar_menu using top, right, bottom left edges for short selection.
76 *
77 * The last part on the right is the status pane where the team characters stats
78 * are listed.
79 *
80 * By itself, the bar never modify the battle object, it is the responsability
81 * of the battle object or the battle state to change the bar object and to
82 * track change on events. As such, the battle object is always passed as const
83 * parameter.
84 */
85 struct battle_bar { 69 struct battle_bar {
86 int x; /*!< (+) Position in x. */ 70 int x;
87 int y; /*!< (+) Position in y. */ 71 int y;
88 unsigned int w; /*!< (+) Width. */ 72 unsigned int w;
89 unsigned int h; /*!< (+) Height. */ 73 unsigned int h;
90 enum battle_bar_state state; /*!< (-) Current state. */ 74 enum battle_bar_state state;
91 75
92 /* Right status frame. */ 76 /* Right status frame. */
93 struct frame status_frame; /*!< (-) Right status frame. */ 77 struct frame status_frame;
94 78
95 /* Main menu selection. */ 79 /* Main menu selection. */
96 struct frame menu_frame; /*!< (-) Main menu frame. */ 80 struct frame menu_frame;
97 enum battle_bar_menu menu; /*!< (-) Main menu selection. */ 81 enum battle_bar_menu menu;
98 82
99 /* Sub menu selection (spells/objects). */ 83 /* Sub menu selection (spells/objects). */
100 struct gridmenu sub_grid; /*!< (-) Sub menu object. */ 84 struct gridmenu sub_grid;
101 }; 85 };
102 86
103 /**
104 * Repositionate every elements in the bar.
105 *
106 * Call this function at least once, when you have set the x, y, w and h fields
107 * of the bar.
108 *
109 * \pre bar != NULL
110 * \pre bt != NULL
111 * \param bar the bar to set
112 * \param bt the current battle
113 */
114 void 87 void
115 battle_bar_positionate(struct battle_bar *bar, const struct battle *bt); 88 battle_bar_positionate(struct battle_bar *bar, const struct battle *bt);
116 89
117 /**
118 * Handle an event.
119 *
120 * Depending on the current bar state, it will either update the main menu or
121 * the sub menu if opened. The function returns true if an element is considered
122 * activated (usually with the return key).
123 *
124 * You must not ignore the return value because the battle state should change.
125 *
126 * \pre bar != NULL
127 * \pre bt != NULL
128 * \pre ev != NULL
129 * \param bar this bar
130 * \param bt the current battle
131 * \param ev the current event
132 * \return True if an element has been activated.
133 */
134 bool 90 bool
135 battle_bar_handle(struct battle_bar *bar, 91 battle_bar_handle(struct battle_bar *bar,
136 const struct battle *bt, 92 const struct battle *bt,
137 const union event *ev); 93 const union event *ev);
138 94
139 /**
140 * Reset the battle bar selection, state and grid.
141 *
142 * Call this function each time a new player is selected.
143 *
144 * \pre bar != NULL
145 * \param bar the bar to reset
146 */
147 void 95 void
148 battle_bar_reset(struct battle_bar *bar); 96 battle_bar_reset(struct battle_bar *bar);
149 97
150 /**
151 * Open global menu.
152 *
153 * \pre bar != NULL
154 * \param bar the bar
155 */
156 void 98 void
157 battle_bar_open_menu(struct battle_bar *bar); 99 battle_bar_open_menu(struct battle_bar *bar);
158 100
159 /**
160 * Open the view to select a spell by opening the grid menu.
161 *
162 * \pre bar != NULL
163 * \pre bt != NULL
164 * \pre character_ok(ch)
165 * \param bar this bar
166 * \param bt the current battle
167 * \param ch the owner of spells
168 */
169 void 101 void
170 battle_bar_open_spells(struct battle_bar *bar, const struct battle *bt, struct character *ch); 102 battle_bar_open_spells(struct battle_bar *bar, const struct battle *bt, struct character *ch);
171 103
172 /** 104 void
173 * Draw the bar. 105 battle_bar_open_items(struct battle_bar *bar, const struct battle *bt);
174 * 106
175 * \pre bar != NULL
176 * \pre bt != NULL
177 * \param bar the bar to draw
178 * \param bt the current battle
179 */
180 void 107 void
181 battle_bar_draw(const struct battle_bar *bar, const struct battle *bt); 108 battle_bar_draw(const struct battle_bar *bar, const struct battle *bt);
182 109
183 /**
184 * Close internal resources if necessary.
185 *
186 * \pre bar != NULL
187 * \param bar the bar to clear
188 */
189 void 110 void
190 battle_bar_finish(struct battle_bar *bar); 111 battle_bar_finish(struct battle_bar *bar);
191 112
192 #endif /* !MOLKO_RPG_BATTLE_BAR_H */ 113 #endif /* !MOLKO_RPG_BATTLE_BAR_H */