87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
#include "boss/ui.hpp"
|
|
#include "constants.hpp"
|
|
|
|
namespace boss {
|
|
using namespace guecs;
|
|
|
|
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
|
$world(world),
|
|
$boss_id(boss_id),
|
|
$boss_sprite(textures::get_sprite("test_boss")),
|
|
$player_sprite(textures::get_sprite("test_player")),
|
|
$floor_sprite(textures::get_sprite("test_floor"))
|
|
{
|
|
}
|
|
|
|
void UI::init() {
|
|
$arena.position(SCREEN_WIDTH-BOSS_VIEW_WIDTH,0, BOSS_VIEW_WIDTH, SCREEN_HEIGHT);
|
|
$arena.set<Background>($arena.MAIN, {$arena.$parser, THEME.DARK_MID});
|
|
auto& background = $arena.get<Background>($arena.MAIN);
|
|
background.set_sprite("test_background", true);
|
|
|
|
$arena.layout(
|
|
"[a1|boss1|boss2|boss3|e1|f1]"
|
|
"[a2|b2|c2|d2|e2|f2]"
|
|
"[floor2|b3|c3|d3|e3|f3]"
|
|
"[a4|b4|c4|d4|e4|f4]"
|
|
"[floor1|player1|player2|player3|e5|f5]"
|
|
"[a6|b6|c6|d6|e6|f6]"
|
|
);
|
|
|
|
position_sprite($boss_sprite, "boss2", 0.7, true);
|
|
position_sprite($player_sprite, "player1", 0.5, true);
|
|
position_sprite($floor_sprite, "floor2", 1.0, false);
|
|
|
|
$arena.init();
|
|
|
|
$actions.position(0,0, SCREEN_WIDTH-BOSS_VIEW_WIDTH, SCREEN_HEIGHT);
|
|
$actions.layout(
|
|
"[action1|action2]"
|
|
"[action3|action4]"
|
|
"[action5|action6]"
|
|
"[*(200)dodge]"
|
|
"[*(200,300)stats]"
|
|
"[_]"
|
|
"[_]");
|
|
|
|
for(auto& [name, cell] : $actions.cells()) {
|
|
auto id = $actions.entity(name);
|
|
$actions.set<Rectangle>(id, {});
|
|
$actions.set<Text>(id, {guecs::to_wstring(name)});
|
|
|
|
if(name != "stats") {
|
|
$actions.set<Clickable>(id, {
|
|
[name](auto){ fmt::println("clicked {}", name); }
|
|
});
|
|
}
|
|
}
|
|
|
|
$actions.init();
|
|
}
|
|
|
|
void UI::position_sprite(textures::SpriteTexture& st, const std::string& name, float scale, bool at_mid) {
|
|
auto& cell = $arena.cell_for(name);
|
|
float x = float(at_mid ? cell.mid_x : cell.x);
|
|
float y = float(at_mid ? cell.mid_y : cell.y);
|
|
|
|
st.sprite->setPosition({x, y});
|
|
st.sprite->setScale({scale, scale});
|
|
}
|
|
|
|
void UI::render(sf::RenderWindow& window) {
|
|
$arena.render(window);
|
|
$actions.render(window);
|
|
window.draw(*$floor_sprite.sprite);
|
|
window.draw(*$boss_sprite.sprite);
|
|
window.draw(*$player_sprite.sprite);
|
|
// $arena.debug_layout(window);
|
|
}
|
|
|
|
bool UI::mouse(float x, float y, Modifiers mods) {
|
|
return $actions.mouse(x, y, mods);
|
|
}
|
|
|
|
bool UI::boss_dead() {
|
|
return false;
|
|
}
|
|
}
|