Moved the text attaching code to the arena.
This commit is contained in:
parent
f50e713179
commit
0d23cf9537
5 changed files with 43 additions and 15 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
22
boss/ui.cpp
22
boss/ui.cpp
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
23
scene.cpp
23
scene.cpp
|
|
@ -5,7 +5,7 @@
|
|||
const bool DEBUG=false;
|
||||
|
||||
namespace scene {
|
||||
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||
Element Engine::config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||
std::string sprite_name = config["sprite"];
|
||||
auto st = textures::get_sprite(sprite_name, duped);
|
||||
|
||||
|
|
@ -25,7 +25,9 @@ namespace scene {
|
|||
|
||||
bool at_mid = config["at_mid"];
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped};
|
||||
sf::Text text(*$ui.$font, "", 60);
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, text};
|
||||
}
|
||||
|
||||
Engine::Engine(components::AnimatedScene& scene) :
|
||||
|
|
@ -68,6 +70,16 @@ namespace scene {
|
|||
}
|
||||
}
|
||||
|
||||
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
||||
auto& element = actor_config(actor);
|
||||
element.text.setPosition(element.pos);
|
||||
element.text.setScale({element.scale_x, element.scale_y});
|
||||
element.text.setFillColor(sf::Color::Red);
|
||||
element.text.setOutlineThickness(2.0f);
|
||||
element.text.setOutlineColor(sf::Color::Black);
|
||||
element.text.setString(text);
|
||||
}
|
||||
|
||||
bool Engine::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $ui.mouse(x, y, mods);
|
||||
}
|
||||
|
|
@ -77,12 +89,15 @@ namespace scene {
|
|||
|
||||
for(auto& fixture : $fixtures) {
|
||||
window.draw(*fixture.st.sprite);
|
||||
window.draw(fixture.text);
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
window.draw(*actor.st.sprite);
|
||||
window.draw(actor.text);
|
||||
}
|
||||
|
||||
|
||||
if(DEBUG) $ui.debug_layout(window);
|
||||
}
|
||||
|
||||
|
|
@ -105,12 +120,16 @@ namespace scene {
|
|||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
||||
fixture.text.setPosition(fixture.pos);
|
||||
fixture.text.setScale({fixture.scale_x, fixture.scale_y});
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
if(actor.anim.playing) {
|
||||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||
actor.text.setPosition(actor.pos);
|
||||
actor.text.setScale({actor.scale_x, actor.scale_y});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ namespace scene {
|
|||
float y = 0;
|
||||
bool at_mid=false;
|
||||
bool flipped=false;
|
||||
sf::Text text;
|
||||
sf::Vector2f pos{0,0};
|
||||
};
|
||||
|
||||
|
|
@ -37,6 +38,8 @@ namespace scene {
|
|||
void init();
|
||||
void render(sf::RenderTarget& window);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void attach_text(const std::string& actor, const std::string& text);
|
||||
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped);
|
||||
|
||||
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue