|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#include "status_ui.hpp" |
|
|
|
|
#include "components.hpp" |
|
|
|
|
#include "inventory.hpp" |
|
|
|
|
#include "color.hpp" |
|
|
|
|
#include "guecs.hpp" |
|
|
|
|
#include "rand.hpp" |
|
|
|
@ -12,35 +13,25 @@ namespace gui { |
|
|
|
|
{ |
|
|
|
|
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); |
|
|
|
|
$gui.layout( |
|
|
|
|
"[button1 | button2 | button3]" |
|
|
|
|
"[button4 | button5 | button6]" |
|
|
|
|
"[button7 | button8 | button9]" |
|
|
|
|
"[slot1 | slot2 | slot3]" |
|
|
|
|
"[slot4 | slot5 | slot6]" |
|
|
|
|
"[slot7 | slot8 | slot9]" |
|
|
|
|
"[*%(100,300)log_view]" |
|
|
|
|
"[_]" |
|
|
|
|
"[_]"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatusUI::render() { |
|
|
|
|
auto& world = $gui.world(); |
|
|
|
|
|
|
|
|
|
std::vector<std::string> fake_items{ |
|
|
|
|
"cinqueda", "healing_potion_small", |
|
|
|
|
"torch_crappy", "barrel_small"}; |
|
|
|
|
|
|
|
|
|
for(auto& [name, cell] : $gui.cells()) { |
|
|
|
|
if(name == "log_view") { |
|
|
|
|
$log_to = $gui.entity("log_view"); |
|
|
|
|
world.set<Rectangle>($log_to, {}); |
|
|
|
|
world.set<Textual>($log_to, {"Welcome to the Game!", 20}); |
|
|
|
|
$gui.set<Rectangle>($log_to, {}); |
|
|
|
|
$gui.set<Textual>($log_to, {"Welcome to the Game!", 20}); |
|
|
|
|
} else { |
|
|
|
|
size_t selected_item = Random::uniform<size_t>(0, fake_items.size() - 1); |
|
|
|
|
fmt::println("fake items {} but size {}", selected_item, fake_items.size()); |
|
|
|
|
auto& fake_item = fake_items[selected_item]; |
|
|
|
|
|
|
|
|
|
auto button = $gui.entity(name); |
|
|
|
|
world.set<Rectangle>(button, {}); |
|
|
|
|
world.set<Sprite>(button, {fake_item}); |
|
|
|
|
world.set<Clickable>(button, |
|
|
|
|
$gui.set<Rectangle>(button, {}); |
|
|
|
|
$gui.set<Textual>(button, {""}); |
|
|
|
|
$gui.set<Clickable>(button, |
|
|
|
|
guecs::make_action(*$level.world, Events::GUI::NOOP)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -48,14 +39,40 @@ namespace gui { |
|
|
|
|
$gui.init(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatusUI::draw(sf::RenderWindow &window) { |
|
|
|
|
auto &world = $gui.world(); |
|
|
|
|
auto &text = world.get<Textual>($log_to); |
|
|
|
|
/* WARNING: This is really not the greatest way to do this. */ |
|
|
|
|
void StatusUI::update() { |
|
|
|
|
if($gui.has<Textual>($log_to)) { |
|
|
|
|
auto& text = $gui.get<Textual>($log_to); |
|
|
|
|
std::string log; |
|
|
|
|
for(auto msg : $messages) { |
|
|
|
|
log += msg + "\n"; |
|
|
|
|
} |
|
|
|
|
text.update(log); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto world = $level.world; |
|
|
|
|
if(world->has<components::Inventory>($level.player)) { |
|
|
|
|
auto& inventory = world->get<components::Inventory>($level.player); |
|
|
|
|
|
|
|
|
|
if(inventory.count() > 0) { |
|
|
|
|
size_t limit = std::min(inventory.count(), $slots.size()); |
|
|
|
|
|
|
|
|
|
for(size_t i = 0; i < limit; i++) { |
|
|
|
|
auto slot = $gui.entity($slots[i]); |
|
|
|
|
auto& item = inventory.get(i); |
|
|
|
|
auto comp_sprite = components::get<components::Sprite>(item.data); |
|
|
|
|
$gui.set_init<guecs::Sprite>(slot, {comp_sprite.name}); |
|
|
|
|
|
|
|
|
|
std::string count_label = item.count > 1 ? fmt::format("{}", item.count): ""; |
|
|
|
|
|
|
|
|
|
auto& label = $gui.get<Textual>(slot); |
|
|
|
|
label.text->setString(count_label); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StatusUI::draw(sf::RenderWindow &window) { |
|
|
|
|
$gui.render(window); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|