You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
#include "combat_ui.hpp"
|
|
#include "constants.hpp"
|
|
#include "color.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(
|
|
"[*%(100,150)button_attack | *%(100,150)button_block | *%(100,150)button_evade | *%(100,150)button_heal]");
|
|
}
|
|
|
|
void CombatUI::make_button(std::string name, std::wstring label, Events::GUI event) {
|
|
auto button = $gui.entity(name);
|
|
$gui.set<Sprite>(button, {"leather_pouch-128"});
|
|
// $gui.set<Rectangle>(button, {});
|
|
$gui.set<Label>(button, {label});
|
|
$gui.set<Shader>(button, {.duration=0.2f});
|
|
$gui.set<Clickable>(button,
|
|
guecs::make_action(*$level.world, event));
|
|
}
|
|
|
|
void CombatUI::init() {
|
|
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
|
make_button("button_attack", L"Attack", Events::GUI::ATTACK);
|
|
make_button("button_block", L"Block", Events::GUI::BLOCK);
|
|
make_button("button_evade", L"Evade", Events::GUI::EVADE);
|
|
make_button("button_heal", L"Heal", Events::GUI::HEAL);
|
|
$gui.init();
|
|
}
|
|
|
|
void CombatUI::render(sf::RenderWindow& window) {
|
|
auto& player_combat = $level.world->get<components::Combat>($level.player);
|
|
set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
|
$gui.render(window);
|
|
}
|
|
|
|
void CombatUI::set_damage(float) {
|
|
}
|
|
|
|
void CombatUI::update_level(GameLevel &level) {
|
|
$level = level;
|
|
init();
|
|
}
|
|
|
|
bool CombatUI::mouse(float x, float y) {
|
|
return $gui.mouse(x, y);
|
|
}
|
|
}
|
|
|