comparison libmlk-rpg/mlk/rpg/battle-bar-default.c @ 505:6100c643dba0

ui: finally ditch theme
author David Demelier <markand@malikania.fr>
date Wed, 01 Mar 2023 16:24:07 +0100
parents 52a305833381
children
comparison
equal deleted inserted replaced
504:52a305833381 505:6100c643dba0
28 #include <mlk/core/trace.h> 28 #include <mlk/core/trace.h>
29 #include <mlk/core/util.h> 29 #include <mlk/core/util.h>
30 #include <mlk/core/window.h> 30 #include <mlk/core/window.h>
31 31
32 #include <mlk/ui/align.h> 32 #include <mlk/ui/align.h>
33 #include <mlk/ui/theme.h>
34 33
35 #include "battle-bar-default.h" 34 #include "battle-bar-default.h"
36 #include "battle-bar.h" 35 #include "battle-bar.h"
37 #include "battle-state-item.h" 36 #include "battle-state-item.h"
38 #include "battle-state-selection.h" 37 #include "battle-state-selection.h"
139 } 138 }
140 139
141 static void 140 static void
142 switch_selection_spell(struct battle_bar_default *bar, struct battle *bt) 141 switch_selection_spell(struct battle_bar_default *bar, struct battle *bt)
143 { 142 {
143 #if 0
144 const struct character *ch = battle_current(bt)->ch; 144 const struct character *ch = battle_current(bt)->ch;
145 const struct spell *sp = ch->spells[bar->grid.selected]; 145 const struct spell *sp = ch->spells[bar->grid.selected];
146 struct selection sel = {0}; 146 struct selection sel = {0};
147 147
148 if (bar->grid.selected > CHARACTER_SPELL_MAX) 148 if (bar->grid.selected > CHARACTER_SPELL_MAX)
155 battle_state_selection(bt, &sel); 155 battle_state_selection(bt, &sel);
156 156
157 /* A cursor should be present. */ 157 /* A cursor should be present. */
158 if (!mlk_sprite_ok(BATTLE_THEME(bt)->sprites[MLK_THEME_SPRITE_CURSOR])) 158 if (!mlk_sprite_ok(BATTLE_THEME(bt)->sprites[MLK_THEME_SPRITE_CURSOR]))
159 mlk_tracef("battle: no cursor sprite in theme"); 159 mlk_tracef("battle: no cursor sprite in theme");
160 #endif
160 } 161 }
161 162
162 static void 163 static void
163 switch_selection_item(struct battle *bt) 164 switch_selection_item(struct battle *bt)
164 { 165 {
166 #if 0
165 const struct selection slt = { 167 const struct selection slt = {
166 .allowed_kinds = SELECTION_KIND_ONE, 168 .allowed_kinds = SELECTION_KIND_ONE,
167 .allowed_sides = SELECTION_SIDE_TEAM | SELECTION_SIDE_ENEMY, 169 .allowed_sides = SELECTION_SIDE_TEAM | SELECTION_SIDE_ENEMY,
168 .index_side = 1, 170 .index_side = 1,
169 .index_character = battle_index(bt) 171 .index_character = battle_index(bt)
170 }; 172 };
171 173
172 battle_state_selection(bt, &slt); 174 battle_state_selection(bt, &slt);
175 #endif
173 } 176 }
174 177
175 /* 178 /*
176 * The following functions actually draw the bar and their components depending 179 * The following functions actually draw the bar and their components depending
177 * on the current selected menu. 180 * on the current selected menu.
178 */ 181 */
179 182
180 static void 183 static void
181 draw_help(const struct battle_bar_default *bar, const char *what) 184 draw_help(const struct battle_bar_default *bar, const char *what)
182 { 185 {
186 #if 0
183 struct mlk_label label = {0}; 187 struct mlk_label label = {0};
184 unsigned int lw = 0, lh = 0; 188 unsigned int lw = 0, lh = 0;
185 189
186 label.flags = MLK_LABEL_FLAGS_SHADOW;
187 label.text = what; 190 label.text = what;
188 mlk_label_query(&label, &lw, &lh); 191 mlk_label_query(&label, &lw, &lh);
189 label.x = bar->grid.x + (bar->grid.w / 2) - (lw / 2); 192 label.x = bar->grid.x + (bar->grid.w / 2) - (lw / 2);
190 label.y = bar->grid.y - lh - THEME(bar)->padding; 193 label.y = bar->grid.y - lh - THEME(bar)->padding;
191 mlk_label_draw(&label); 194 mlk_label_draw(&label);
195 #endif
192 } 196 }
193 197
194 static void 198 static void
195 draw_spell_help(const struct battle_bar_default *bar, const struct battle *bt) 199 draw_spell_help(const struct battle_bar_default *bar, const struct battle *bt)
196 { 200 {
226 const struct character *ch, 230 const struct character *ch,
227 int x, 231 int x,
228 int y, 232 int y,
229 unsigned int h) 233 unsigned int h)
230 { 234 {
235 #if 0
231 const struct mlk_theme *theme = THEME(bar); 236 const struct mlk_theme *theme = THEME(bar);
232 struct mlk_label label; 237 struct mlk_label label;
233 unsigned int spacing, lw, lh; 238 unsigned int spacing, lw, lh;
234 char line[64]; 239 char line[64];
235 240
262 label.y = label.y + lh + spacing; 267 label.y = label.y + lh + spacing;
263 mlk_label_draw(&label); 268 mlk_label_draw(&label);
264 269
265 /* Status. */ 270 /* Status. */
266 /* TODO: list all status. */ 271 /* TODO: list all status. */
272 #endif
267 } 273 }
268 274
269 static void 275 static void
270 draw_status_character(const struct battle_bar_default *bar, 276 draw_status_character(const struct battle_bar_default *bar,
271 const struct battle *bt, 277 const struct battle *bt,
315 } 321 }
316 322
317 static void 323 static void
318 draw_menu(const struct battle_bar_default *bar, const struct geo *geo) 324 draw_menu(const struct battle_bar_default *bar, const struct geo *geo)
319 { 325 {
326 #if 0
320 struct { 327 struct {
321 unsigned int w, h; 328 unsigned int w, h;
322 enum mlk_align align; 329 enum mlk_align align;
323 struct mlk_label label; 330 struct mlk_label label;
324 } buttons[] = { 331 } buttons[] = {
325 { 332 {
326 .align = MLK_ALIGN_TOP, 333 .align = MLK_ALIGN_TOP,
327 .label = { 334 .label = {
328 .text = "Attack", 335 .text = "Attack",
329 .flags = MLK_LABEL_FLAGS_SHADOW
330 } 336 }
331 }, 337 },
332 { 338 {
333 .align = MLK_ALIGN_RIGHT, 339 .align = MLK_ALIGN_RIGHT,
334 .label = { 340 .label = {
335 .text = "Magic", 341 .text = "Magic",
336 .flags = MLK_LABEL_FLAGS_SHADOW
337 } 342 }
338 }, 343 },
339 { 344 {
340 .align = MLK_ALIGN_BOTTOM, 345 .align = MLK_ALIGN_BOTTOM,
341 .label = { 346 .label = {
342 .text = "Objects", 347 .text = "Objects",
343 .flags = MLK_LABEL_FLAGS_SHADOW
344 } 348 }
345 }, 349 },
346 { 350 {
347 .align = MLK_ALIGN_LEFT, 351 .align = MLK_ALIGN_LEFT,
348 .label = { 352 .label = {
349 .text = "Special", 353 .text = "Special",
350 .flags = MLK_LABEL_FLAGS_SHADOW
351 } 354 }
352 } 355 }
353 }; 356 };
354 357
355 const struct mlk_theme *theme = THEME(bar); 358 const struct mlk_theme *theme = THEME(bar);
384 mlk_align(buttons[i].align, 387 mlk_align(buttons[i].align,
385 &buttons[i].label.x, &buttons[i].label.y, buttons[i].w, buttons[i].h, 388 &buttons[i].label.x, &buttons[i].label.y, buttons[i].w, buttons[i].h,
386 bx, by, bw, bh); 389 bx, by, bw, bh);
387 mlk_label_draw(&buttons[i].label); 390 mlk_label_draw(&buttons[i].label);
388 } 391 }
392 #endif
389 } 393 }
390 394
391 /* 395 /*
392 * This function is called only in the first level of the bar menu: selecting 396 * This function is called only in the first level of the bar menu: selecting
393 * one of the Attack, Magic, Item and Special items. 397 * one of the Attack, Magic, Item and Special items.
526 } 530 }
527 531
528 void 532 void
529 battle_bar_default_init(struct battle_bar_default *bar) 533 battle_bar_default_init(struct battle_bar_default *bar)
530 { 534 {
535 #if 0
531 assert(bar); 536 assert(bar);
532 537
533 struct geo geo[2]; 538 struct geo geo[2];
534 539
535 memset(bar, 0, sizeof (*bar)); 540 memset(bar, 0, sizeof (*bar));
542 dimensions(geo, bar); 547 dimensions(geo, bar);
543 548
544 mlk_gridmenu_init(&bar->grid, 2, 2, NULL, 0); 549 mlk_gridmenu_init(&bar->grid, 2, 2, NULL, 0);
545 mlk_gridmenu_resize(&bar->grid, bar->x, geo[0].y, geo[1].w, bar->h); 550 mlk_gridmenu_resize(&bar->grid, bar->x, geo[0].y, geo[1].w, bar->h);
546 bar->grid.theme = bar->theme; 551 bar->grid.theme = bar->theme;
552 #endif
547 } 553 }
548 554
549 void 555 void
550 battle_bar_default_open_magic(struct battle_bar_default *bar, const struct battle *bt, struct character *ch) 556 battle_bar_default_open_magic(struct battle_bar_default *bar, const struct battle *bt, struct character *ch)
551 { 557 {