All of the UIs should be cleared out, and that just leaves the tests.
This commit is contained in:
parent
d5ff57e025
commit
564f9842a2
23 changed files with 126 additions and 145 deletions
|
@ -4,12 +4,12 @@
|
|||
#include <fmt/xchar.h>
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "inventory.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
||||
CombatUI::CombatUI(GameLevel level) :
|
||||
$level(level)
|
||||
CombatUI::CombatUI()
|
||||
{
|
||||
$gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||
$gui.layout(
|
||||
|
@ -31,15 +31,16 @@ namespace gui {
|
|||
$gui.set<Sound>(button, {sound});
|
||||
$gui.set<Effect>(button, {.duration=0.5f, .name=effect_name});
|
||||
$gui.set<Clickable>(button,
|
||||
guecs::make_action($level, button, event, {action}));
|
||||
guecs::make_action(button, event, {action}));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
void CombatUI::init() {
|
||||
auto world = Game::current_world();
|
||||
using guecs::THEME;
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID});
|
||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||
auto& the_belt = world->get_the<ritual::Belt>();
|
||||
|
||||
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
||||
if(the_belt.has(slot)) {
|
||||
|
@ -67,7 +68,7 @@ namespace gui {
|
|||
auto hp_gauge = $gui.entity("hp_gauge");
|
||||
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
||||
$gui.set<Clickable>(hp_gauge,
|
||||
guecs::make_action($level, hp_gauge, Events::GUI::HP_STATUS, {}));
|
||||
guecs::make_action(hp_gauge, Events::GUI::HP_STATUS, {}));
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
@ -76,8 +77,7 @@ namespace gui {
|
|||
$gui.render(window);
|
||||
}
|
||||
|
||||
void CombatUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
void CombatUI::update_level() {
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <guecs/ui.hpp>
|
||||
|
@ -9,13 +8,12 @@ namespace gui {
|
|||
class CombatUI {
|
||||
public:
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
|
||||
CombatUI(GameLevel level);
|
||||
CombatUI();
|
||||
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
void update_level();
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
guecs::Entity make_button(std::string name, Events::GUI event,
|
||||
int action, const std::string &icon_name,
|
||||
|
|
18
gui/fsm.cpp
18
gui/fsm.cpp
|
@ -21,10 +21,6 @@ namespace gui {
|
|||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
||||
$debug_ui(Game::get_the_manager()),
|
||||
$main_ui($window),
|
||||
$combat_ui(Game::current()),
|
||||
$status_ui(Game::current()),
|
||||
$map_ui(Game::current()),
|
||||
$loot_ui(Game::current()),
|
||||
$font{FONT_FILE_NAME},
|
||||
$dnd_loot($status_ui, $loot_ui, $window, $router)
|
||||
{
|
||||
|
@ -47,8 +43,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::START(Event ) {
|
||||
auto& level = Game::current();
|
||||
$main_ui.update_level(level);
|
||||
$main_ui.update_level();
|
||||
$main_ui.init();
|
||||
$loot_ui.init();
|
||||
|
||||
|
@ -545,13 +540,10 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::next_level() {
|
||||
auto& level = Game::create_level();
|
||||
|
||||
$status_ui.update_level(level);
|
||||
$map_ui.update_level(level);
|
||||
$combat_ui.update_level(level);
|
||||
$main_ui.update_level(level);
|
||||
$loot_ui.update_level(level);
|
||||
$status_ui.update_level();
|
||||
$combat_ui.update_level();
|
||||
$main_ui.update_level();
|
||||
$loot_ui.update_level();
|
||||
|
||||
$boss_fight_ui = Game::create_bossfight();
|
||||
$boss_fight_ui->init();
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
#include "gui/guecstra.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace guecs {
|
||||
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event) {
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event) {
|
||||
return {[&, gui_id, event](auto){
|
||||
target.world->send<Events::GUI>(event, gui_id, {});
|
||||
auto world = Game::current_world();
|
||||
world->send<Events::GUI>(event, gui_id, {});
|
||||
}};
|
||||
}
|
||||
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data) {
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) {
|
||||
return {[&, event, data](auto){
|
||||
target.world->send<Events::GUI>(event, gui_id, data);
|
||||
auto world = Game::current_world();
|
||||
world->send<Events::GUI>(event, gui_id, data);
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
#include "events.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#include "textures.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
namespace guecs {
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event);
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data);
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event);
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data);
|
||||
|
||||
struct GrabSource {
|
||||
DinkyECS::Entity world_entity;
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "constants.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
#include "systems.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
||||
LootUI::LootUI(GameLevel level) :
|
||||
$level(level),
|
||||
$temp_loot($level.world->entity()),
|
||||
LootUI::LootUI() :
|
||||
$temp_loot(Game::current_world()->entity()),
|
||||
$target($temp_loot)
|
||||
{
|
||||
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200,
|
||||
|
@ -21,8 +21,9 @@ namespace gui {
|
|||
"[=item_12| =item_13|=item_14|=item_15 ]"
|
||||
"[ =take_all | =close| =destroy]");
|
||||
|
||||
$level.world->set<inventory::Model>($temp_loot, {});
|
||||
$level.world->make_constant($temp_loot);
|
||||
auto world = Game::current_world();
|
||||
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) {
|
||||
|
@ -31,7 +32,7 @@ namespace gui {
|
|||
$gui.set<guecs::Rectangle>(button, {});
|
||||
$gui.set<guecs::Text>(button, {label});
|
||||
$gui.set<guecs::Clickable>(button,
|
||||
guecs::make_action($level, button, event));
|
||||
guecs::make_action(button, event));
|
||||
}
|
||||
|
||||
void LootUI::init() {
|
||||
|
@ -52,7 +53,7 @@ namespace gui {
|
|||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||
$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() {
|
||||
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");
|
||||
|
||||
auto& contents = $level.world->get<inventory::Model>($target);
|
||||
auto& contents = world->get<inventory::Model>($target);
|
||||
|
||||
for(size_t i = 0; i < INV_SLOTS; i++) {
|
||||
auto id = $gui.entity("item_", int(i));
|
||||
|
@ -72,9 +75,9 @@ namespace gui {
|
|||
|
||||
if(contents.has(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?");
|
||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||
auto& sprite = world->get<components::Sprite>(item);
|
||||
$gui.set_init<guecs::Icon>(id, {sprite.name});
|
||||
|
||||
guecs::GrabSource grabber{
|
||||
|
@ -98,7 +101,7 @@ namespace gui {
|
|||
void LootUI::remove_slot(guecs::Entity slot_id) {
|
||||
auto& name = $gui.name_for(slot_id);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -107,7 +110,7 @@ namespace gui {
|
|||
$target, id, world_entity);
|
||||
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();
|
||||
return worked;
|
||||
}
|
||||
|
@ -116,13 +119,12 @@ namespace gui {
|
|||
$gui.render(window);
|
||||
}
|
||||
|
||||
void LootUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
void LootUI::update_level() {
|
||||
init();
|
||||
}
|
||||
|
||||
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);
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <guecs/ui.hpp>
|
||||
|
@ -12,11 +11,10 @@ namespace gui {
|
|||
public:
|
||||
bool active = false;
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
DinkyECS::Entity $temp_loot;
|
||||
DinkyECS::Entity $target;
|
||||
|
||||
LootUI(GameLevel level);
|
||||
LootUI();
|
||||
|
||||
void set_target(DinkyECS::Entity entity) {
|
||||
$target = entity;
|
||||
|
@ -25,7 +23,7 @@ namespace gui {
|
|||
void init();
|
||||
void update();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
void update_level();
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void make_button(const std::string &name, const std::wstring& label, Events::GUI event);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "easings.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
#include "constants.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
|
@ -20,7 +21,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::init() {
|
||||
auto& player_position = $level.world->get<Position>($level.player);
|
||||
auto& player_position = Game::player_position();
|
||||
auto player = player_position.location;
|
||||
|
||||
$rayview->init_shaders();
|
||||
|
@ -31,9 +32,10 @@ namespace gui {
|
|||
}
|
||||
|
||||
DinkyECS::Entity MainUI::camera_aim() {
|
||||
auto& level = Game::current();
|
||||
// what happens if there's two things at that spot
|
||||
if($level.collision->something_there($rayview->aiming_at)) {
|
||||
return $level.collision->get($rayview->aiming_at);
|
||||
if(level.collision->something_there($rayview->aiming_at)) {
|
||||
return level.collision->get($rayview->aiming_at);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -88,27 +90,26 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::dead_entity(DinkyECS::Entity entity) {
|
||||
// BUG: this is kind of weird, but I think when I switch to dead bodies for things
|
||||
// (see System::distribute_loot) then this can be fixed or improved
|
||||
if($level.world->has<components::Sprite>(entity)) {
|
||||
auto &sprite = $level.world->get<components::Sprite>(entity);
|
||||
auto world = Game::current_world();
|
||||
if(world->has<components::Sprite>(entity)) {
|
||||
auto &sprite = world->get<components::Sprite>(entity);
|
||||
$rayview->update_sprite(entity, sprite);
|
||||
}
|
||||
}
|
||||
|
||||
void MainUI::update_level(GameLevel level) {
|
||||
$level = level;
|
||||
auto& player_position = $level.world->get<Position>($level.player);
|
||||
void MainUI::update_level() {
|
||||
auto& level = Game::current();
|
||||
auto& player_position = Game::player_position();
|
||||
auto player = player_position.location;
|
||||
|
||||
$rayview->update_level($level);
|
||||
$rayview->update_level(level);
|
||||
$rayview->position_camera(player.x + 0.5, player.y + 0.5);
|
||||
|
||||
player_position.aiming_at = $rayview->aiming_at;
|
||||
|
||||
$compass_dir = 0;
|
||||
|
||||
$overlay_ui.update_level(level);
|
||||
$overlay_ui.update_level();
|
||||
dirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include "stats.hpp"
|
||||
|
@ -32,7 +31,7 @@ namespace gui {
|
|||
std::optional<components::Position> play_move();
|
||||
Point plan_move(int dir, bool strafe);
|
||||
void abort_plan();
|
||||
void update_level(GameLevel level);
|
||||
void update_level();
|
||||
DinkyECS::Entity camera_aim();
|
||||
|
||||
void init();
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <fmt/xchar.h>
|
||||
#include <fstream>
|
||||
#include "palette.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
constexpr const int MAP_WIDTH=13;
|
||||
constexpr const int MAP_HEIGHT=13;
|
||||
|
@ -20,18 +21,14 @@ namespace gui {
|
|||
using namespace components;
|
||||
using namespace guecs;
|
||||
|
||||
MapViewUI::MapViewUI(GameLevel &level) :
|
||||
$level(level),
|
||||
MapViewUI::MapViewUI() :
|
||||
$map_render(std::make_shared<sf::RenderTexture>()),
|
||||
$map_sprite($map_render->getTexture()),
|
||||
$map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT))
|
||||
{
|
||||
auto player = $level.world->get_the<Player>();
|
||||
$player_display = $level.world->get<Tile>(player.entity).display;
|
||||
}
|
||||
|
||||
void MapViewUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
auto world = Game::current_world();
|
||||
auto player = Game::the_player();
|
||||
$player_display = world->get<Tile>(player).display;
|
||||
}
|
||||
|
||||
void MapViewUI::init() {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include "textures.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#include <string>
|
||||
#include "dinkyecs.hpp"
|
||||
#include "map.hpp"
|
||||
|
||||
namespace gui {
|
||||
class MapViewUI {
|
||||
|
@ -13,15 +14,13 @@ namespace gui {
|
|||
DinkyECS::Entity $log_to;
|
||||
EntityGrid $entity_map;
|
||||
std::deque<std::wstring> $messages;
|
||||
GameLevel $level;
|
||||
std::shared_ptr<sf::RenderTexture> $map_render;
|
||||
sf::Sprite $map_sprite;
|
||||
matrix::Matrix $map_tiles;
|
||||
|
||||
MapViewUI(GameLevel &level);
|
||||
MapViewUI();
|
||||
void init();
|
||||
void render(sf::RenderWindow &window, int compass_dir);
|
||||
void update_level(GameLevel &level);
|
||||
void log(std::wstring msg);
|
||||
void update();
|
||||
};
|
||||
|
|
|
@ -14,17 +14,12 @@
|
|||
namespace gui {
|
||||
using namespace components;
|
||||
|
||||
MiniMapUI::MiniMapUI(GameLevel &level) :
|
||||
$map_grid{L"...", 45, {200, 200, 200, 100}, 10},
|
||||
$level(level)
|
||||
MiniMapUI::MiniMapUI() :
|
||||
$map_grid{L"...", 45, {200, 200, 200, 100}, 10}
|
||||
{
|
||||
$font = std::make_shared<sf::Font>(FONT_FILE_NAME);
|
||||
}
|
||||
|
||||
void MiniMapUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
}
|
||||
|
||||
void MiniMapUI::init(guecs::UI& overlay) {
|
||||
auto top_right = overlay.entity("top_right");
|
||||
auto cell = overlay.cell_for(top_right);
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include "textures.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace gui {
|
||||
class MiniMapUI {
|
||||
public:
|
||||
guecs::Text $map_grid;
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
shared_ptr<sf::Font> $font = nullptr;
|
||||
std::shared_ptr<sf::Font> $font = nullptr;
|
||||
|
||||
MiniMapUI(GameLevel &level);
|
||||
MiniMapUI();
|
||||
void init(guecs::UI& overlay);
|
||||
void render(sf::RenderWindow &window, int compass_dir);
|
||||
void update_level(GameLevel &level);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "constants.hpp"
|
||||
#include "events.hpp"
|
||||
#include <optional>
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
@ -17,21 +18,23 @@ namespace gui {
|
|||
$gui.init();
|
||||
}
|
||||
|
||||
inline void make_clickable_area(GameLevel& level, guecs::UI &gui, const std::string &name) {
|
||||
inline void make_clickable_area(std::shared_ptr<DinkyECS::World> world, guecs::UI &gui, const std::string &name) {
|
||||
auto area = gui.entity(name);
|
||||
|
||||
gui.set<Clickable>(area, {
|
||||
[&](auto) {
|
||||
level.world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
||||
world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void OverlayUI::init() {
|
||||
auto world = Game::current_world();
|
||||
|
||||
// gui.init is in the constructor
|
||||
make_clickable_area($level, $gui, "top");
|
||||
make_clickable_area($level, $gui, "middle");
|
||||
make_clickable_area($level, $gui, "bottom");
|
||||
make_clickable_area(world, $gui, "top");
|
||||
make_clickable_area(world, $gui, "middle");
|
||||
make_clickable_area(world, $gui, "bottom");
|
||||
}
|
||||
|
||||
void OverlayUI::render(sf::RenderWindow& window) {
|
||||
|
@ -55,8 +58,7 @@ namespace gui {
|
|||
$gui.close<Text>(region);
|
||||
}
|
||||
|
||||
void OverlayUI::update_level(GameLevel level) {
|
||||
$level = level;
|
||||
void OverlayUI::update_level() {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <guecs/ui.hpp>
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
namespace gui {
|
||||
using std::string;
|
||||
|
@ -10,12 +9,11 @@ namespace gui {
|
|||
class OverlayUI {
|
||||
public:
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
|
||||
OverlayUI();
|
||||
|
||||
void init();
|
||||
void update_level(GameLevel level);
|
||||
void update_level();
|
||||
|
||||
void render(sf::RenderWindow& window);
|
||||
void show_sprite(string region, string sprite_name);
|
||||
|
|
|
@ -6,15 +6,14 @@
|
|||
#include "rand.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "events.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace gui {
|
||||
namespace ritual {
|
||||
using namespace guecs;
|
||||
using std::any, std::any_cast, std::string, std::make_any;
|
||||
|
||||
UI::UI(GameLevel level) :
|
||||
$level(level)
|
||||
{
|
||||
UI::UI() {
|
||||
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
||||
$gui.layout(
|
||||
"[_]"
|
||||
|
@ -186,11 +185,14 @@ namespace gui {
|
|||
}
|
||||
|
||||
void UI::complete_combine() {
|
||||
auto world = Game::current_world();
|
||||
auto player = Game::the_player();
|
||||
|
||||
if($craft_state.is_combined()) {
|
||||
auto ritual = $ritual_engine.finalize($craft_state);
|
||||
auto& belt = $level.world->get_the<::ritual::Belt>();
|
||||
auto& belt = world->get_the<::ritual::Belt>();
|
||||
belt.equip(belt.next(), ritual);
|
||||
$level.world->send<Events::GUI>(Events::GUI::NEW_RITUAL, $level.player, {});
|
||||
world->send<Events::GUI>(Events::GUI::NEW_RITUAL, player, {});
|
||||
blanket().consume_crafting();
|
||||
clear_craft_result();
|
||||
|
||||
|
@ -240,14 +242,15 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void UI::update_level(GameLevel& level) {
|
||||
$level = level;
|
||||
}
|
||||
|
||||
void UI::clear_craft_result() {
|
||||
blanket().reset();
|
||||
$gui.close<Text>("result_text");
|
||||
$gui.close<Sprite>("result_image");
|
||||
}
|
||||
|
||||
::ritual::Blanket& UI::blanket() {
|
||||
auto world = Game::current_world();
|
||||
return world->get_the<::ritual::Blanket>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include "constants.hpp"
|
||||
#include <deque>
|
||||
#include "textures.hpp"
|
||||
|
@ -37,12 +36,11 @@ namespace gui {
|
|||
sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}};
|
||||
components::Animation $ritual_anim;
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
textures::SpriteTexture $ritual_ui;
|
||||
::ritual::Engine $ritual_engine;
|
||||
::ritual::CraftingState $craft_state;
|
||||
|
||||
UI(GameLevel level);
|
||||
UI();
|
||||
|
||||
void event(Event ev, std::any data={});
|
||||
void START(Event);
|
||||
|
@ -63,11 +61,7 @@ namespace gui {
|
|||
void run_crafting_engine();
|
||||
void complete_combine();
|
||||
void update_selection_state();
|
||||
void update_level(GameLevel &level);
|
||||
|
||||
::ritual::Blanket& blanket() {
|
||||
return $level.world->get_the<::ritual::Blanket>();
|
||||
}
|
||||
::ritual::Blanket& blanket();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
#include "gui/guecstra.hpp"
|
||||
#include "systems.hpp"
|
||||
#include "inventory.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
using std::any, std::any_cast, std::string, std::make_any;
|
||||
|
||||
StatusUI::StatusUI(GameLevel level) :
|
||||
$level(level), $ritual_ui(level)
|
||||
StatusUI::StatusUI()
|
||||
{
|
||||
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
||||
$gui.layout(
|
||||
|
@ -45,7 +46,7 @@ namespace gui {
|
|||
} else {
|
||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||
$gui.set<Clickable>(gui_id, {
|
||||
guecs::make_action($level, gui_id, Events::GUI::INV_SELECT, {gui_id})
|
||||
guecs::make_action(gui_id, Events::GUI::INV_SELECT, {gui_id})
|
||||
});
|
||||
$gui.set<DropTarget>(gui_id, {
|
||||
.commit=[&, gui_id](DinkyECS::Entity world_target) -> bool {
|
||||
|
@ -74,8 +75,9 @@ namespace gui {
|
|||
}
|
||||
|
||||
void StatusUI::update() {
|
||||
auto player = $level.world->get_the<components::Player>();
|
||||
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||
auto world = Game::current_world();
|
||||
auto player = world->get_the<components::Player>();
|
||||
auto& inventory = world->get<inventory::Model>(player.entity);
|
||||
|
||||
for(const auto& [slot, cell] : $gui.cells()) {
|
||||
|
||||
|
@ -83,7 +85,7 @@ namespace gui {
|
|||
auto gui_id = $gui.entity(slot);
|
||||
auto world_entity = inventory.get(slot);
|
||||
|
||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||
auto& sprite = world->get<components::Sprite>(world_entity);
|
||||
$gui.set_init<guecs::Icon>(gui_id, {sprite.name});
|
||||
guecs::GrabSource grabber{ world_entity,
|
||||
[&, gui_id]() { return remove_slot(gui_id); }};
|
||||
|
@ -106,18 +108,17 @@ namespace gui {
|
|||
$ritual_ui.render(window);
|
||||
}
|
||||
|
||||
void StatusUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
void StatusUI::update_level() {
|
||||
init();
|
||||
$ritual_ui.update_level(level);
|
||||
}
|
||||
|
||||
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
auto& level = Game::current();
|
||||
auto& slot_name = $gui.name_for(gui_id);
|
||||
auto& inventory = $level.world->get<inventory::Model>($level.player);
|
||||
auto& inventory = level.world->get<inventory::Model>(level.player);
|
||||
|
||||
if(inventory.add(slot_name, world_entity)) {
|
||||
$level.world->make_constant(world_entity);
|
||||
level.world->make_constant(world_entity);
|
||||
update();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -133,23 +134,25 @@ namespace gui {
|
|||
|
||||
// NOTE: do I need this or how does it relate to drop_item?
|
||||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||
auto player = Game::the_player();
|
||||
auto& slot_name = $gui.name_for(slot_id);
|
||||
System::remove_from_container(*$level.world, $level.player, slot_name);
|
||||
System::remove_from_container(player, slot_name);
|
||||
update();
|
||||
}
|
||||
|
||||
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
||||
if(gui_a != gui_b) {
|
||||
auto player = Game::the_player();
|
||||
auto& a_name = $gui.name_for(gui_a);
|
||||
auto& b_name = $gui.name_for(gui_b);
|
||||
System::inventory_swap($level.player, a_name, b_name);
|
||||
System::inventory_swap(player, a_name, b_name);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
bool StatusUI::occupied(guecs::Entity slot) {
|
||||
auto player = $level.world->get_the<components::Player>();
|
||||
return System::inventory_occupied(player.entity, $gui.name_for(slot));
|
||||
auto player = Game::the_player();
|
||||
return System::inventory_occupied(player, $gui.name_for(slot));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include "constants.hpp"
|
||||
#include <deque>
|
||||
#include "textures.hpp"
|
||||
|
@ -11,17 +10,16 @@ namespace gui {
|
|||
class StatusUI {
|
||||
public:
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
ritual::UI $ritual_ui;
|
||||
|
||||
explicit StatusUI(GameLevel level);
|
||||
explicit StatusUI();
|
||||
|
||||
StatusUI(const StatusUI& other) = delete;
|
||||
StatusUI(StatusUI&& other) = delete;
|
||||
~StatusUI() = default;
|
||||
|
||||
void select_ritual();
|
||||
void update_level(GameLevel &level);
|
||||
void update_level();
|
||||
void init();
|
||||
void render(sf::RenderWindow &window);
|
||||
void update();
|
||||
|
|
10
systems.cpp
10
systems.cpp
|
@ -470,8 +470,9 @@ void System::drop_item(Entity item) {
|
|||
}
|
||||
|
||||
// NOTE: I think pickup and this need to be different
|
||||
bool System::place_in_container(World& world, Entity cont_id, const std::string& name, Entity world_entity) {
|
||||
auto& container = world.get<inventory::Model>(cont_id);
|
||||
bool System::place_in_container(Entity cont_id, const std::string& name, Entity world_entity) {
|
||||
auto world = Game::current_world();
|
||||
auto& container = world->get<inventory::Model>(cont_id);
|
||||
|
||||
if(container.has(world_entity)) {
|
||||
fmt::println("container {} already has entity {}, skip", cont_id, world_entity);
|
||||
|
@ -489,8 +490,9 @@ bool System::place_in_container(World& world, Entity cont_id, const std::string&
|
|||
}
|
||||
}
|
||||
|
||||
void System::remove_from_container(World& world, Entity cont_id, const std::string& slot_id) {
|
||||
auto& container = world.get<inventory::Model>(cont_id);
|
||||
void System::remove_from_container(Entity cont_id, const std::string& slot_id) {
|
||||
auto world = Game::current_world();
|
||||
auto& container = world->get<inventory::Model>(cont_id);
|
||||
auto entity = container.get(slot_id);
|
||||
container.remove(entity);
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace System {
|
|||
|
||||
void pickup();
|
||||
|
||||
bool place_in_container(World& world, Entity cont_id, const string& name, Entity world_entity);
|
||||
bool place_in_container(Entity cont_id, const string& name, Entity world_entity);
|
||||
|
||||
void remove_from_container(World& world, Entity cont_id, const std::string& name);
|
||||
void remove_from_container(Entity cont_id, const std::string& name);
|
||||
void remove_from_world(Entity entity);
|
||||
void inventory_swap(Entity container_id, const std::string& a_name, const std::string &b_name);
|
||||
bool inventory_occupied(Entity container_id, const std::string& name);
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "systems.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include "systems.hpp."
|
||||
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
|
@ -84,9 +85,9 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
|||
TEST_CASE("map image test", "[map]") {
|
||||
components::init();
|
||||
textures::init();
|
||||
Game::init();
|
||||
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
GameLevel level = Game::current();
|
||||
Matrix map_tiles = matrix::make(7,7);
|
||||
EntityGrid entity_map;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include "sound.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue