|
|
@ -31,14 +31,58 @@ namespace gui { |
|
|
|
auto button = $gui.entity(name); |
|
|
|
auto button = $gui.entity(name); |
|
|
|
$gui.set<Rectangle>(button, {}); |
|
|
|
$gui.set<Rectangle>(button, {}); |
|
|
|
$gui.set<Textual>(button, {""}); |
|
|
|
$gui.set<Textual>(button, {""}); |
|
|
|
$gui.set<Clickable>(button, |
|
|
|
$gui.set<ActionData>(button, {std::make_any<std::string>(name)}); |
|
|
|
guecs::make_action(*$level.world, Events::GUI::NOOP)); |
|
|
|
$gui.set<Clickable>(button, { |
|
|
|
|
|
|
|
[&](auto ent, auto data){ select_slot(ent, data); } |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$gui.init(); |
|
|
|
$gui.init(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusUI::select_slot(DinkyECS::Entity ent, std::any) { |
|
|
|
|
|
|
|
auto cn = $gui.get<CellName>(ent); |
|
|
|
|
|
|
|
auto world = $level.world; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(world->has<components::Inventory>($level.player)) { |
|
|
|
|
|
|
|
auto& inventory = world->get<components::Inventory>($level.player); |
|
|
|
|
|
|
|
for(size_t i = 0; i < inventory.count(); i++) { |
|
|
|
|
|
|
|
if($slots[i] == cn.name) { |
|
|
|
|
|
|
|
auto& player_combat = world->get<components::Combat>($level.player); |
|
|
|
|
|
|
|
auto& item = inventory.get(i); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(item.count == 0) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(item.data["id"] == "SWORD_RUSTY") { |
|
|
|
|
|
|
|
auto weapon = components::get<components::Weapon>(item.data); |
|
|
|
|
|
|
|
player_combat.damage = weapon.damage; |
|
|
|
|
|
|
|
inventory.decrease(i, 1); |
|
|
|
|
|
|
|
log("You equip a new sword."); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if(item.data["id"] == "POTION_HEALING_SMALL") { |
|
|
|
|
|
|
|
auto cure = components::get<components::Curative>(item.data); |
|
|
|
|
|
|
|
int prev_hp = player_combat.hp; |
|
|
|
|
|
|
|
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp); |
|
|
|
|
|
|
|
log(fmt::format("Healed player from {} to {}", prev_hp, player_combat.hp)); |
|
|
|
|
|
|
|
inventory.decrease(i, 1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if(item.data["id"] == "TORCH_BAD") { |
|
|
|
|
|
|
|
auto new_light = components::get<components::LightSource>(item.data); |
|
|
|
|
|
|
|
world->set<components::LightSource>($level.player, new_light); |
|
|
|
|
|
|
|
inventory.light = new_light; |
|
|
|
|
|
|
|
inventory.decrease(i, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("You are using a new torch."); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* WARNING: This is really not the greatest way to do this. */ |
|
|
|
/* WARNING: This is really not the greatest way to do this. */ |
|
|
|
void StatusUI::update() { |
|
|
|
void StatusUI::update() { |
|
|
|
if($gui.has<Textual>($log_to)) { |
|
|
|
if($gui.has<Textual>($log_to)) { |
|
|
@ -62,11 +106,17 @@ namespace gui { |
|
|
|
auto& item = inventory.get(i); |
|
|
|
auto& item = inventory.get(i); |
|
|
|
auto comp_sprite = components::get<components::Sprite>(item.data); |
|
|
|
auto comp_sprite = components::get<components::Sprite>(item.data); |
|
|
|
$gui.set_init<guecs::Sprite>(slot, {comp_sprite.name}); |
|
|
|
$gui.set_init<guecs::Sprite>(slot, {comp_sprite.name}); |
|
|
|
|
|
|
|
std::string count_label = fmt::format("{}", item.count); |
|
|
|
std::string count_label = item.count > 1 ? fmt::format("{}", item.count): ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& label = $gui.get<Textual>(slot); |
|
|
|
auto& label = $gui.get<Textual>(slot); |
|
|
|
label.text->setString(count_label); |
|
|
|
label.text->setString(count_label); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& sprite = $gui.get<guecs::Sprite>(slot); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(item.count == 0) { |
|
|
|
|
|
|
|
sprite.sprite->setColor({125, 125, 125}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sprite.sprite->setColor({255, 255, 255}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|