Initial loot UI works to load an item by its world entity ID.
This commit is contained in:
parent
f208ca946e
commit
4b34de2109
6 changed files with 67 additions and 20 deletions
4
Makefile
4
Makefile
|
@ -26,7 +26,7 @@ tracy_build:
|
|||
meson compile -j 10 -C builddir
|
||||
|
||||
test: build
|
||||
./builddir/runtests
|
||||
./builddir/runtests "[loot]"
|
||||
|
||||
run: build test
|
||||
ifeq '$(OS)' 'Windows_NT'
|
||||
|
@ -49,7 +49,7 @@ clean:
|
|||
meson compile --clean -C builddir
|
||||
|
||||
debug_test: build
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[loot]"
|
||||
|
||||
win_installer:
|
||||
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
||||
|
|
15
gui/fsm.cpp
15
gui/fsm.cpp
|
@ -177,10 +177,19 @@ namespace gui {
|
|||
case TICK:
|
||||
// do nothing
|
||||
break;
|
||||
case LOOT_OPEN:
|
||||
case LOOT_OPEN: {
|
||||
dbc::log("IDLE LOOT OPEN!");
|
||||
Config items("assets/items.json");
|
||||
auto& data = items["TORCH_BAD"];
|
||||
auto torch = $level.world->entity();
|
||||
components::configure_entity(*$level.world, torch, data["components"]);
|
||||
$loot_ui.contents.push_back(torch);
|
||||
$loot_ui.update();
|
||||
$loot_ui.active = true;
|
||||
|
||||
state(State::LOOTING);
|
||||
break;
|
||||
|
||||
} break;
|
||||
default:
|
||||
dbc::sentinel("unhandled event in IDLE");
|
||||
}
|
||||
|
@ -384,7 +393,7 @@ namespace gui {
|
|||
System::collision($level);
|
||||
System::motion($level);
|
||||
System::lighting($level);
|
||||
System::death($level, $levels.$components);
|
||||
System::death($level);
|
||||
}
|
||||
|
||||
bool FSM::active() {
|
||||
|
|
|
@ -27,20 +27,6 @@ namespace gui {
|
|||
bg_color.a = 140;
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, bg_color});
|
||||
|
||||
// fill in 4 slots for prototype
|
||||
for(int i = 0; i < 4; i++) {
|
||||
auto id = $gui.entity("item_", i);
|
||||
|
||||
$gui.set<guecs::Rectangle>(id, {THEME.PADDING,
|
||||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||
|
||||
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
[=](auto, auto) { fmt::println("clicked button_{}", i); }
|
||||
});
|
||||
$gui.set<guecs::Sprite>(id, {"broken_yoyo"});
|
||||
}
|
||||
|
||||
auto close = $gui.entity("close");
|
||||
$gui.set<guecs::Rectangle>(close, {});
|
||||
$gui.set<guecs::Label>(close, {L"CLOSE"});
|
||||
|
@ -48,6 +34,34 @@ namespace gui {
|
|||
guecs::make_action(*$level.world, Events::GUI::LOOT_CLOSE));
|
||||
|
||||
$gui.init();
|
||||
update();
|
||||
}
|
||||
|
||||
void LootUI::update() {
|
||||
dbc::check(contents.size() < 16, "too many items in loot contents, must be < 16");
|
||||
for(int i = 0; i < 16; i++) {
|
||||
auto id = $gui.entity("item_", i);
|
||||
if($gui.has<guecs::Rectangle>(id)) {
|
||||
$gui.remove<guecs::Rectangle>(id);
|
||||
$gui.remove<guecs::Effect>(id);
|
||||
$gui.remove<guecs::Clickable>(id);
|
||||
$gui.remove<guecs::Sprite>(id);
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t item_i = 0; item_i < contents.size(); item_i++) {
|
||||
auto id = $gui.entity("item_", int(item_i));
|
||||
$gui.set_init<guecs::Rectangle>(id, {THEME.PADDING,
|
||||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||
$gui.set_init<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
[=](auto, auto) { fmt::println("clicked button"); }
|
||||
});
|
||||
|
||||
auto item = contents.at(item_i);
|
||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||
$gui.set_init<guecs::Sprite>(id, {sprite.name});
|
||||
}
|
||||
}
|
||||
|
||||
void LootUI::render(sf::RenderWindow& window) {
|
||||
|
|
|
@ -11,10 +11,12 @@ namespace gui {
|
|||
bool active = false;
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
std::vector<DinkyECS::Entity> contents;
|
||||
|
||||
LootUI(GameLevel level);
|
||||
|
||||
void init();
|
||||
void update();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
|
|
|
@ -138,8 +138,10 @@ executable('runtests', sources + [
|
|||
'tests/fsm.cpp',
|
||||
'tests/levelmanager.cpp',
|
||||
'tests/lighting.cpp',
|
||||
'tests/loot.cpp',
|
||||
'tests/map.cpp',
|
||||
'tests/matrix.cpp',
|
||||
'tests/mazes.cpp',
|
||||
'tests/pathing.cpp',
|
||||
'tests/rituals.cpp',
|
||||
'tests/shaders.cpp',
|
||||
|
@ -147,7 +149,6 @@ executable('runtests', sources + [
|
|||
'tests/spatialmap.cpp',
|
||||
'tests/stats.cpp',
|
||||
'tests/textures.cpp',
|
||||
'tests/mazes.cpp',
|
||||
],
|
||||
cpp_args: cpp_args,
|
||||
link_args: link_args,
|
||||
|
|
21
tests/loot.cpp
Normal file
21
tests/loot.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include "components.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace components;
|
||||
|
||||
TEST_CASE("test the loot ui", "[loot]") {
|
||||
Config items("assets/items.json");
|
||||
DinkyECS::World world;
|
||||
auto torch = world.entity();
|
||||
auto& data = items["TORCH_BAD"];
|
||||
|
||||
components::init();
|
||||
components::configure_entity(world, torch, data["components"]);
|
||||
|
||||
auto& torch_sprite = world.get<Sprite>(torch);
|
||||
REQUIRE(torch_sprite.name == "torch_horizontal_floor");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue