101 lines
2.8 KiB
C++
101 lines
2.8 KiB
C++
#include "constants.hpp"
|
|
#include "rituals.hpp"
|
|
#include <fmt/xchar.h>
|
|
#include "gui/guecstra.hpp"
|
|
#include "game_level.hpp"
|
|
#include "gui/combat_ui.hpp"
|
|
|
|
namespace gui {
|
|
using guecs::THEME;
|
|
using namespace guecs;
|
|
|
|
CombatUI::CombatUI(bool boss_style) :
|
|
$boss_style(boss_style)
|
|
{
|
|
}
|
|
|
|
guecs::Entity CombatUI::make_button(
|
|
guecs::Entity button,
|
|
Events::GUI event,
|
|
int action,
|
|
const std::string &icon_name,
|
|
const std::string &sound,
|
|
const std::string &effect_name)
|
|
{
|
|
$gui.set<Sprite>(button, {icon_name});
|
|
$gui.set<Sound>(button, {sound});
|
|
$gui.set<Effect>(button, {.duration=0.5f, .name=effect_name});
|
|
$gui.set<Clickable>(button,
|
|
guecs::make_action(button, event, {action}));
|
|
|
|
return button;
|
|
}
|
|
|
|
void CombatUI::init(int x, int y, int w, int h) {
|
|
$gui.position(x, y, w, h);
|
|
|
|
if($boss_style) {
|
|
$gui.layout(
|
|
"[action0|action1]"
|
|
"[action2|action3]"
|
|
"[action4|action5]"
|
|
"[action6|action7]");
|
|
} else {
|
|
$gui.layout(
|
|
"[action0 | action1 | action2 | action3"
|
|
"|action4 | action5 | action6 | action7 | =hp_gauge ]");
|
|
}
|
|
|
|
auto world = GameDB::current_world();
|
|
$gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID});
|
|
auto& the_belt = world->get_the<ritual::Belt>();
|
|
|
|
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
|
fmt::println("combat ui belt slot {}", slot);
|
|
if(the_belt.has(slot)) {
|
|
auto button = $gui.entity("action", slot);
|
|
fmt::println("combat ui has belt slot {} with id {}", slot, button);
|
|
|
|
auto& ritual = the_belt.get(slot);
|
|
|
|
using enum ritual::Element;
|
|
|
|
switch(ritual.element) {
|
|
case FIRE:
|
|
make_button(button, Events::GUI::ATTACK,
|
|
slot, "broken_yoyo", "fireball_01", "flame");
|
|
break;
|
|
case LIGHTNING:
|
|
make_button(button, Events::GUI::ATTACK,
|
|
slot, "pocket_watch", "electric_shock_01", "lightning");
|
|
break;
|
|
default:
|
|
make_button(button, Events::GUI::ATTACK,
|
|
slot, "severed_finger", "punch_cartoony", "ui_shader");
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$boss_style) {
|
|
auto hp_gauge = $gui.entity("hp_gauge");
|
|
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
|
$gui.set<Clickable>(hp_gauge,
|
|
guecs::make_action(hp_gauge, Events::GUI::HP_STATUS, {}));
|
|
}
|
|
|
|
$gui.init();
|
|
}
|
|
|
|
void CombatUI::render(sf::RenderWindow& window) {
|
|
$gui.render(window);
|
|
// $gui.debug_layout(window);
|
|
}
|
|
|
|
void CombatUI::update_level() {
|
|
init(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
|
}
|
|
|
|
bool CombatUI::mouse(float x, float y, guecs::Modifiers mods) {
|
|
return $gui.mouse(x, y, mods);
|
|
}
|
|
}
|