|
|
@ -2,13 +2,13 @@ |
|
|
|
#include "constants.hpp" |
|
|
|
#include "constants.hpp" |
|
|
|
#include <fmt/xchar.h> |
|
|
|
#include <fmt/xchar.h> |
|
|
|
#include "systems.hpp" |
|
|
|
#include "systems.hpp" |
|
|
|
|
|
|
|
#include "game_level.hpp" |
|
|
|
|
|
|
|
|
|
|
|
namespace gui { |
|
|
|
namespace gui { |
|
|
|
using namespace guecs; |
|
|
|
using namespace guecs; |
|
|
|
|
|
|
|
|
|
|
|
LootUI::LootUI(GameLevel level) : |
|
|
|
LootUI::LootUI() : |
|
|
|
$level(level), |
|
|
|
$temp_loot(Game::current_world()->entity()), |
|
|
|
$temp_loot($level.world->entity()), |
|
|
|
|
|
|
|
$target($temp_loot) |
|
|
|
$target($temp_loot) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, |
|
|
|
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, |
|
|
@ -21,8 +21,9 @@ namespace gui { |
|
|
|
"[=item_12| =item_13|=item_14|=item_15 ]" |
|
|
|
"[=item_12| =item_13|=item_14|=item_15 ]" |
|
|
|
"[ =take_all | =close| =destroy]"); |
|
|
|
"[ =take_all | =close| =destroy]"); |
|
|
|
|
|
|
|
|
|
|
|
$level.world->set<inventory::Model>($temp_loot, {}); |
|
|
|
auto world = Game::current_world(); |
|
|
|
$level.world->make_constant($temp_loot); |
|
|
|
world->set<inventory::Model>($temp_loot, {}); |
|
|
|
|
|
|
|
world->make_constant($temp_loot); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LootUI::make_button(const std::string &name, const std::wstring& label, Events::GUI event) { |
|
|
|
void LootUI::make_button(const std::string &name, const std::wstring& label, Events::GUI event) { |
|
|
@ -31,7 +32,7 @@ namespace gui { |
|
|
|
$gui.set<guecs::Rectangle>(button, {}); |
|
|
|
$gui.set<guecs::Rectangle>(button, {}); |
|
|
|
$gui.set<guecs::Text>(button, {label}); |
|
|
|
$gui.set<guecs::Text>(button, {label}); |
|
|
|
$gui.set<guecs::Clickable>(button, |
|
|
|
$gui.set<guecs::Clickable>(button, |
|
|
|
guecs::make_action($level, button, event)); |
|
|
|
guecs::make_action(button, event)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LootUI::init() { |
|
|
|
void LootUI::init() { |
|
|
@ -52,7 +53,7 @@ namespace gui { |
|
|
|
THEME.TRANSPARENT, THEME.LIGHT_MID }); |
|
|
|
THEME.TRANSPARENT, THEME.LIGHT_MID }); |
|
|
|
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"}); |
|
|
|
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"}); |
|
|
|
$gui.set<guecs::Clickable>(id, { |
|
|
|
$gui.set<guecs::Clickable>(id, { |
|
|
|
guecs::make_action($level, id, Events::GUI::LOOT_SELECT, {id}) |
|
|
|
guecs::make_action(id, Events::GUI::LOOT_SELECT, {id}) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -61,10 +62,12 @@ namespace gui { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LootUI::update() { |
|
|
|
void LootUI::update() { |
|
|
|
dbc::check($level.world->has<inventory::Model>($target), |
|
|
|
auto world = Game::current_world(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbc::check(world->has<inventory::Model>($target), |
|
|
|
"update called but $target isn't in world"); |
|
|
|
"update called but $target isn't in world"); |
|
|
|
|
|
|
|
|
|
|
|
auto& contents = $level.world->get<inventory::Model>($target); |
|
|
|
auto& contents = world->get<inventory::Model>($target); |
|
|
|
|
|
|
|
|
|
|
|
for(size_t i = 0; i < INV_SLOTS; i++) { |
|
|
|
for(size_t i = 0; i < INV_SLOTS; i++) { |
|
|
|
auto id = $gui.entity("item_", int(i)); |
|
|
|
auto id = $gui.entity("item_", int(i)); |
|
|
@ -72,9 +75,9 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
|
|
if(contents.has(slot_name)) { |
|
|
|
if(contents.has(slot_name)) { |
|
|
|
auto item = contents.get(slot_name); |
|
|
|
auto item = contents.get(slot_name); |
|
|
|
dbc::check($level.world->has<components::Sprite>(item), |
|
|
|
dbc::check(world->has<components::Sprite>(item), |
|
|
|
"item in inventory UI doesn't exist in world. New level?"); |
|
|
|
"item in inventory UI doesn't exist in world. New level?"); |
|
|
|
auto& sprite = $level.world->get<components::Sprite>(item); |
|
|
|
auto& sprite = world->get<components::Sprite>(item); |
|
|
|
$gui.set_init<guecs::Icon>(id, {sprite.name}); |
|
|
|
$gui.set_init<guecs::Icon>(id, {sprite.name}); |
|
|
|
|
|
|
|
|
|
|
|
guecs::GrabSource grabber{ |
|
|
|
guecs::GrabSource grabber{ |
|
|
@ -98,7 +101,7 @@ namespace gui { |
|
|
|
void LootUI::remove_slot(guecs::Entity slot_id) { |
|
|
|
void LootUI::remove_slot(guecs::Entity slot_id) { |
|
|
|
auto& name = $gui.name_for(slot_id); |
|
|
|
auto& name = $gui.name_for(slot_id); |
|
|
|
fmt::println("LootUI remove slot inv::Model id={} slot={}", $target, name); |
|
|
|
fmt::println("LootUI remove slot inv::Model id={} slot={}", $target, name); |
|
|
|
System::remove_from_container(*$level.world, $target, name); |
|
|
|
System::remove_from_container($target, name); |
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -107,7 +110,7 @@ namespace gui { |
|
|
|
$target, id, world_entity); |
|
|
|
$target, id, world_entity); |
|
|
|
auto& name = $gui.name_for(id); |
|
|
|
auto& name = $gui.name_for(id); |
|
|
|
|
|
|
|
|
|
|
|
bool worked = System::place_in_container(*$level.world, $target, name, world_entity); |
|
|
|
bool worked = System::place_in_container($target, name, world_entity); |
|
|
|
if(worked) update(); |
|
|
|
if(worked) update(); |
|
|
|
return worked; |
|
|
|
return worked; |
|
|
|
} |
|
|
|
} |
|
|
@ -116,13 +119,12 @@ namespace gui { |
|
|
|
$gui.render(window); |
|
|
|
$gui.render(window); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LootUI::update_level(GameLevel &level) { |
|
|
|
void LootUI::update_level() { |
|
|
|
$level = level; |
|
|
|
|
|
|
|
init(); |
|
|
|
init(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LootUI::add_loose_item(DinkyECS::Entity entity) { |
|
|
|
void LootUI::add_loose_item(DinkyECS::Entity entity) { |
|
|
|
System::place_in_container(*$level.world, $temp_loot, "item_0", entity); |
|
|
|
System::place_in_container($temp_loot, "item_0", entity); |
|
|
|
set_target($temp_loot); |
|
|
|
set_target($temp_loot); |
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|