Simple Loot UI started.
This commit is contained in:
parent
8a3046e141
commit
8545b8cf1d
23 changed files with 139 additions and 29 deletions
86
gui/combat_ui.cpp
Normal file
86
gui/combat_ui.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "gui/combat_ui.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "color.hpp"
|
||||
#include "rituals.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
#include "guecstra.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
||||
CombatUI::CombatUI(GameLevel level) :
|
||||
$level(level)
|
||||
{
|
||||
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||
$gui.layout(
|
||||
"[button_0 | button_1 | button_2 | button_3"
|
||||
"|button_4 | button_5 | button_6 | hp_gauge ]"
|
||||
);
|
||||
}
|
||||
|
||||
DinkyECS::Entity CombatUI::make_button(
|
||||
std::string name,
|
||||
Events::GUI event,
|
||||
int action,
|
||||
const std::string &icon_name,
|
||||
const std::string &sound,
|
||||
const std::string &effect_name)
|
||||
{
|
||||
auto button = $gui.entity(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(*$level.world, event, {action}));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
void CombatUI::init() {
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID});
|
||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||
|
||||
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
||||
if(the_belt.has(slot)) {
|
||||
std::string name = fmt::format("button_{}", slot);
|
||||
auto& ritual = the_belt.get(slot);
|
||||
|
||||
using enum ritual::Element;
|
||||
|
||||
switch(ritual.element) {
|
||||
case FIRE:
|
||||
make_button(name, Events::GUI::ATTACK,
|
||||
slot, "broken_yoyo-64", "fireball_01", "flame");
|
||||
break;
|
||||
case LIGHTNING:
|
||||
make_button(name, Events::GUI::ATTACK,
|
||||
slot, "pocket_watch-64", "electric_shock_01", "lightning");
|
||||
break;
|
||||
default:
|
||||
make_button(name, Events::GUI::ATTACK,
|
||||
slot, "severed_finger-64", "punch_cartoony", "ui_shader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto hp_gauge = $gui.entity("hp_gauge");
|
||||
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed-64"});
|
||||
$gui.set<Clickable>(hp_gauge,
|
||||
guecs::make_action(*$level.world, Events::GUI::HP_STATUS, {}));
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void CombatUI::render(sf::RenderWindow& window) {
|
||||
$gui.render(window);
|
||||
}
|
||||
|
||||
void CombatUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
init();
|
||||
}
|
||||
|
||||
bool CombatUI::mouse(float x, float y, bool hover) {
|
||||
return $gui.mouse(x, y, hover);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue