comparison src/libmlk-rpg/rpg/battle-state-sub.c @ 385:3f13dc6c0e37

rpg: separate battle and the bar, closes #2522
author David Demelier <markand@malikania.fr>
date Tue, 15 Feb 2022 14:45:11 +0100
parents c458441ff472
children
comparison
equal deleted inserted replaced
384:c458441ff472 385:3f13dc6c0e37
36 #include "battle-state.h" 36 #include "battle-state.h"
37 #include "battle.h" 37 #include "battle.h"
38 #include "character.h" 38 #include "character.h"
39 #include "spell.h" 39 #include "spell.h"
40 40
41 static void
42 start_select_spell(struct battle *bt)
43 {
44 const struct character *ch = bt->order_cur->ch;
45 const struct spell *sp = ch->spells[bt->bar.sub_grid.selected];
46 struct selection slt = {0};
47
48 /* Don't forget to reset the gridmenu state. */
49 gridmenu_reset(&bt->bar.sub_grid);
50
51 if (bt->bar.sub_grid.selected > CHARACTER_SPELL_MAX)
52 return;
53 if (!(sp = ch->spells[bt->bar.sub_grid.selected]) || sp->mp > (unsigned int)(ch->mp))
54 return;
55
56 spell_select(sp, bt, &slt);
57 battle_state_selection(bt, &slt);
58
59 /* A cursor should be present. */
60 if (!sprite_ok(BATTLE_THEME(bt)->sprites[THEME_SPRITE_CURSOR]))
61 tracef("battle: no cursor sprite in theme");
62 }
63
64 static void
65 start_select_object(struct battle *bt)
66 {
67 const struct selection slt = {
68 .allowed_kinds = SELECTION_KIND_ONE,
69 .allowed_sides = SELECTION_SIDE_TEAM | SELECTION_SIDE_ENEMY,
70 .index_side = 1,
71 .index_character = bt->order_curindex
72 };
73
74 battle_state_selection(bt, &slt);
75 }
76
77 static void
78 draw_help(const struct battle *bt, const char *what)
79 {
80 struct label label = {0};
81 unsigned int lw = 0, lh = 0;
82
83 label.flags = LABEL_FLAGS_SHADOW;
84 label.text = what;
85 label_query(&label, &lw, &lh);
86 label.x = bt->bar.sub_grid.x + (bt->bar.sub_grid.w / 2) - (lw / 2);
87 label.y = bt->bar.sub_grid.y - lh - BATTLE_THEME(bt)->padding;
88 label_draw(&label);
89 }
90
91 static void
92 draw_spell_help(const struct battle *bt)
93 {
94 const struct character *ch = bt->order_cur->ch;
95 const struct spell *sp;
96
97 if (bt->bar.sub_grid.selected >= CHARACTER_SPELL_MAX)
98 return;
99 if ((sp = ch->spells[bt->bar.sub_grid.selected]))
100 return;
101
102 draw_help(bt, sp->description);
103 }
104
105 static void
106 draw_object_help(const struct battle *bt)
107 {
108 const struct inventory_slot *slot;
109
110 if (bt->bar.sub_grid.selected >= INVENTORY_ITEM_MAX)
111 return;
112
113 slot = &bt->inventory->items[bt->bar.sub_grid.selected];
114
115 if (!slot->item)
116 return;
117
118 draw_help(bt, slot->item->description);
119 }
120 41
121 static void 42 static void
122 handle(struct battle_state *st, struct battle *bt, const union event *ev) 43 handle(struct battle_state *st, struct battle *bt, const union event *ev)
123 { 44 {
124 (void)st; 45 (void)st;