136 lines
3.7 KiB
C++
136 lines
3.7 KiB
C++
#include "boss/ui.hpp"
|
|
#include "scene.hpp"
|
|
#include "constants.hpp"
|
|
#include "components.hpp"
|
|
#include "animation.hpp"
|
|
#include <fmt/xchar.h>
|
|
#include "game_level.hpp"
|
|
|
|
namespace boss {
|
|
using namespace guecs;
|
|
using namespace DinkyECS;
|
|
|
|
UI::UI(shared_ptr<World> world, Entity boss_id, Entity player_id) :
|
|
$world(world),
|
|
$boss_id(boss_id),
|
|
$player_id(player_id),
|
|
$combat_ui(true),
|
|
$arena(world->get<components::AnimatedScene>($boss_id)),
|
|
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
|
|
$view_sprite($view_texture.getTexture())
|
|
{
|
|
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
|
|
$camera.style("shake");
|
|
}
|
|
|
|
void UI::init() {
|
|
$arena.init();
|
|
|
|
$actions.position(0,0, SCREEN_WIDTH-BOSS_VIEW_WIDTH, SCREEN_HEIGHT);
|
|
$actions.layout(
|
|
"[*(200,400)combat|_]"
|
|
"[_|_]"
|
|
"[_|_]"
|
|
"[_|_]"
|
|
"[*(200,300)stats]"
|
|
"[_]"
|
|
"[_]");
|
|
|
|
auto stats = $actions.entity("stats");
|
|
$actions.set<Rectangle>(stats, {});
|
|
update_stats();
|
|
|
|
$actions.init();
|
|
|
|
auto& cell = $actions.cell_for("combat");
|
|
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
|
|
}
|
|
|
|
void UI::update_stats() {
|
|
auto& player_combat = $world->get<components::Combat>($player_id);
|
|
auto& boss_combat = $world->get<components::Combat>($boss_id);
|
|
|
|
std::wstring status = fmt::format(
|
|
L"--PLAYER--\nHP:{}/{}\nAP:{}/{}\n\n--BOSS--\nHP:{}/{}\nAP:{}/{}\n----\n",
|
|
player_combat.hp, player_combat.max_hp,
|
|
player_combat.ap, player_combat.max_ap,
|
|
boss_combat.hp, boss_combat.max_hp,
|
|
boss_combat.ap, boss_combat.max_ap);
|
|
|
|
if($world->has_event<Events::GUI>()) {
|
|
auto [evt, entity, data] = $world->recv<Events::GUI>();
|
|
auto result = std::any_cast<Events::Combat>(data);
|
|
auto& player_is = $arena.$actors.at($arena.$actor_name_ids.at("player"));
|
|
auto& boss_is = $arena.$actors.at($arena.$actor_name_ids.at("boss"));
|
|
|
|
if(result.player_did > 0) {
|
|
status += L"\nYOU HIT!";
|
|
} else {
|
|
status += L"\nYOU MISSED!";
|
|
}
|
|
|
|
if(result.enemy_did > 0) {
|
|
status += L"\nBOSS HIT!";
|
|
} else {
|
|
status += L"\nBOSS MISSED!";
|
|
}
|
|
|
|
/*
|
|
if(result.player_did > 0) {
|
|
zoom("boss14", 1.8);
|
|
} else if(result.enemy_did > 0) {
|
|
zoom(player_is.cell, 2.0);
|
|
} else {
|
|
zoom("", 0.0);
|
|
}
|
|
*/
|
|
}
|
|
|
|
$actions.show_text("stats", status);
|
|
}
|
|
|
|
void UI::render(sf::RenderWindow& window) {
|
|
$actions.render(window);
|
|
$combat_ui.render(window);
|
|
|
|
$arena.render($view_texture);
|
|
$camera.render($view_texture);
|
|
$view_texture.display();
|
|
window.draw($view_sprite);
|
|
}
|
|
|
|
bool UI::mouse(float x, float y, Modifiers mods) {
|
|
// BUG: arena is getting the _window_ coordinates, not the rendertexture
|
|
return $combat_ui.mouse(x, y, mods)
|
|
|| $actions.mouse(x, y, mods) || $arena.mouse(x, y, mods);
|
|
}
|
|
|
|
void UI::status(const std::wstring& msg) {
|
|
$arena.$ui.show_text("status", msg);
|
|
}
|
|
|
|
void UI::move_actor(const std::string& actor, const std::string& cell_name) {
|
|
$arena.move_actor(actor, cell_name);
|
|
}
|
|
|
|
void UI::animate_actor(const std::string& actor) {
|
|
$arena.animate_actor(actor);
|
|
}
|
|
|
|
void UI::play_animations() {
|
|
$arena.play_animations();
|
|
}
|
|
|
|
void UI::zoom(const std::string &cell_name, double ratio) {
|
|
if(cell_name == "") {
|
|
dbc::log("!!!!!!!!! you should add this to guecs");
|
|
$camera.reset($view_texture, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT);
|
|
} else {
|
|
auto& cell = $arena.$ui.cell_for(cell_name);
|
|
|
|
$camera.resize(double(BOSS_VIEW_WIDTH)/ratio, double(BOSS_VIEW_HEIGHT)/ratio);
|
|
$camera.move(float(cell.mid_x), float(cell.mid_y));
|
|
$camera.play();
|
|
}
|
|
}
|
|
}
|