Moved the text attaching code to the arena.

This commit is contained in:
Zed A. Shaw 2025-12-24 00:58:38 -05:00
parent f50e713179
commit 0d23cf9537
5 changed files with 43 additions and 15 deletions

View file

@ -128,11 +128,14 @@ namespace boss {
case BattleHostState::disagree: {
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
$ui.move_actor("player", player_move);
if(result.player_did > 0) $ui.animate_actor("player");
$ui.damage("boss", result.player_did);
} break;
case BattleHostState::not_host: {
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
$ui.move_actor("boss", boss_move);
if(result.enemy_did > 0) $ui.animate_actor("boss");
$ui.damage("player", result.enemy_did);
} break;
case BattleHostState::out_of_ap:
@ -154,7 +157,7 @@ namespace boss {
void Fight::render(sf::RenderWindow& window) {
$ui.play_animations();
$ui.render(window);
$ui.render();
}
bool Fight::handle_mouse(game::Event ev) {
@ -196,6 +199,7 @@ namespace boss {
void Fight::set_window(sf::RenderWindow* window) {
$window = window;
$ui.set_window(window);
}
bool Fight::handle_keyboard_mouse() {

View file

@ -71,14 +71,18 @@ namespace boss {
$actions.show_text("stats", status);
}
void UI::render(sf::RenderWindow& window) {
$actions.render(window);
$combat_ui.render(window);
void UI::set_window(sf::RenderWindow* window) {
$window = window;
}
void UI::render() {
$actions.render(*$window);
$combat_ui.render(*$window);
$arena.render($view_texture);
$camera.render($view_texture);
$view_texture.display();
window.draw($view_sprite);
$window->draw($view_sprite);
}
bool UI::mouse(float x, float y, Modifiers mods) {
@ -105,16 +109,12 @@ namespace boss {
}
void UI::damage(const std::string& actor, int amount) {
auto& config = $arena.actor_config(actor);
// BUG: the $arena should really do this
if(amount == 0) {
$arena.$ui.show_text(config.cell,
fmt::format(L"{} MISSED!", guecs::to_wstring(actor)));
$arena.attach_text(actor, "MISS!");
} else {
$arena.$ui.show_text(config.cell,
fmt::format(L"{} HIT {}!", guecs::to_wstring(actor), amount));
$arena.attach_text(actor, "HIT!");
}
}
void UI::zoom(const std::string &cell_name, double ratio) {

View file

@ -18,6 +18,7 @@ namespace boss {
using std::shared_ptr;
struct UI {
sf::RenderWindow* $window = nullptr;
shared_ptr<DinkyECS::World> $world = nullptr;
DinkyECS::Entity $boss_id = DinkyECS::NONE;
DinkyECS::Entity $player_id = DinkyECS::NONE;
@ -31,7 +32,8 @@ namespace boss {
UI(shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, DinkyECS::Entity player_id);
void init();
void render(sf::RenderWindow& window);
void set_window(sf::RenderWindow* window);
void render();
bool mouse(float x, float y, guecs::Modifiers mods);
void status(const std::wstring& msg, const std::wstring &button_msg);
void move_actor(const std::string& actor, const std::string& cell_name);