Simple Loot UI started.

master
Zed A. Shaw 4 days ago
parent 8a3046e141
commit 8545b8cf1d
  1. 2
      autowalker.cpp
  2. 2
      autowalker.hpp
  3. 2
      gui/boss_fight_ui.cpp
  4. 0
      gui/boss_fight_ui.hpp
  5. 2
      gui/combat_ui.cpp
  6. 0
      gui/combat_ui.hpp
  7. 2
      gui/debug_ui.cpp
  8. 0
      gui/debug_ui.hpp
  9. 30
      gui/gui_fsm.cpp
  10. 17
      gui/gui_fsm.hpp
  11. 51
      gui/loot_ui.cpp
  12. 22
      gui/loot_ui.hpp
  13. 2
      gui/main_ui.cpp
  14. 6
      gui/main_ui.hpp
  15. 2
      gui/overlay_ui.cpp
  16. 0
      gui/overlay_ui.hpp
  17. 2
      gui/ritual_ui.cpp
  18. 0
      gui/ritual_ui.hpp
  19. 2
      gui/status_ui.cpp
  20. 2
      gui/status_ui.hpp
  21. 2
      levelmanager.hpp
  22. 3
      main.cpp
  23. 17
      meson.build

@ -1,7 +1,7 @@
#include "autowalker.hpp" #include "autowalker.hpp"
#include "inventory.hpp" #include "inventory.hpp"
#include "ai_debug.hpp" #include "ai_debug.hpp"
#include "ritual_ui.hpp" #include "gui/ritual_ui.hpp"
template<typename Comp> template<typename Comp>
int number_left(gui::FSM& fsm) { int number_left(gui::FSM& fsm) {

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "ai.hpp" #include "ai.hpp"
#include "gui_fsm.hpp" #include "gui/gui_fsm.hpp"
struct InventoryStats; struct InventoryStats;

@ -1,4 +1,4 @@
#include "boss_fight_ui.hpp" #include "gui/boss_fight_ui.hpp"
#include "easings.hpp" #include "easings.hpp"
#include "sound.hpp" #include "sound.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>

@ -1,4 +1,4 @@
#include "combat_ui.hpp" #include "gui/combat_ui.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "color.hpp" #include "color.hpp"
#include "rituals.hpp" #include "rituals.hpp"

@ -1,4 +1,4 @@
#include "debug_ui.hpp" #include "gui/debug_ui.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "color.hpp" #include "color.hpp"
#include "events.hpp" #include "events.hpp"

@ -23,6 +23,7 @@ namespace gui {
$status_ui($level), $status_ui($level),
$map_ui($level), $map_ui($level),
$mini_map($level), $mini_map($level),
$loot_ui($level),
$font{FONT_FILE_NAME} $font{FONT_FILE_NAME}
{ {
} }
@ -37,6 +38,7 @@ namespace gui {
FSM_STATE(State, IN_COMBAT, ev); FSM_STATE(State, IN_COMBAT, ev);
FSM_STATE(State, COMBAT_ROTATE, ev); FSM_STATE(State, COMBAT_ROTATE, ev);
FSM_STATE(State, NEXT_LEVEL, ev); FSM_STATE(State, NEXT_LEVEL, ev);
FSM_STATE(State, LOOTING, ev);
FSM_STATE(State, END, ev); FSM_STATE(State, END, ev);
} }
} }
@ -46,6 +48,7 @@ namespace gui {
$main_ui.update_level($level); $main_ui.update_level($level);
$level.world->set_the<Debug>({}); $level.world->set_the<Debug>({});
$main_ui.init(); $main_ui.init();
$loot_ui.init();
// BUG: maybe this is a function on main_ui? // BUG: maybe this is a function on main_ui?
auto cell = $main_ui.$overlay_ui.$gui.cell_for("left"); auto cell = $main_ui.$overlay_ui.$gui.cell_for("left");
@ -110,6 +113,22 @@ namespace gui {
} }
} }
void FSM::LOOTING(Event ev) {
using enum Event;
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(State::IDLE);
break;
case TICK:
// do nothing
break;
default:
state(State::LOOTING);
}
}
void FSM::IDLE(Event ev) { void FSM::IDLE(Event ev) {
using enum Event; using enum Event;
@ -161,6 +180,10 @@ namespace gui {
case TICK: case TICK:
// do nothing // do nothing
break; break;
case LOOT_OPEN:
$loot_ui.active = true;
state(State::LOOTING);
break;
default: default:
dbc::sentinel("unhandled event in IDLE"); dbc::sentinel("unhandled event in IDLE");
} }
@ -248,6 +271,7 @@ namespace gui {
$combat_ui.mouse(pos.x, pos.y, false); $combat_ui.mouse(pos.x, pos.y, false);
$status_ui.mouse(pos.x, pos.y, false); $status_ui.mouse(pos.x, pos.y, false);
$main_ui.mouse(pos.x, pos.y, false); $main_ui.mouse(pos.x, pos.y, false);
if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, false);
} }
} }
} else if(const auto* mouse = ev->getIf<sf::Event::MouseMoved>()) { } else if(const auto* mouse = ev->getIf<sf::Event::MouseMoved>()) {
@ -303,6 +327,9 @@ namespace gui {
case KEY::L: case KEY::L:
event(Event::STAIRS_DOWN); event(Event::STAIRS_DOWN);
break; break;
case KEY::X:
event(Event::LOOT_OPEN);
break;
default: default:
break; // ignored break; // ignored
} }
@ -322,6 +349,8 @@ namespace gui {
$status_ui.render($window); $status_ui.render($window);
$combat_ui.render($window); $combat_ui.render($window);
if($loot_ui.active) $loot_ui.render($window);
if($map_open) { if($map_open) {
$map_ui.render($window, $main_ui.$compass_dir); $map_ui.render($window, $main_ui.$compass_dir);
} else { } else {
@ -442,6 +471,7 @@ namespace gui {
$mini_map.update_level($level); $mini_map.update_level($level);
$combat_ui.update_level($level); $combat_ui.update_level($level);
$main_ui.update_level($level); $main_ui.update_level($level);
$loot_ui.update_level($level);
$boss_fight_ui = $levels.create_bossfight($level.world); $boss_fight_ui = $levels.create_bossfight($level.world);
$boss_fight_ui->init(); $boss_fight_ui->init();

@ -3,11 +3,12 @@
#include "stats.hpp" #include "stats.hpp"
#include "levelmanager.hpp" #include "levelmanager.hpp"
#include "fsm.hpp" #include "fsm.hpp"
#include "debug_ui.hpp" #include "gui/debug_ui.hpp"
#include "main_ui.hpp" #include "gui/main_ui.hpp"
#include "combat_ui.hpp" #include "gui/combat_ui.hpp"
#include "status_ui.hpp" #include "gui/status_ui.hpp"
#include "boss_fight_ui.hpp" #include "gui/loot_ui.hpp"
#include "gui/boss_fight_ui.hpp"
#include "map_view.hpp" #include "map_view.hpp"
#include "mini_map.hpp" #include "mini_map.hpp"
@ -20,6 +21,7 @@ namespace gui {
ATTACKING, ATTACKING,
ROTATING, ROTATING,
NEXT_LEVEL, NEXT_LEVEL,
LOOTING,
IDLE, IDLE,
END END
}; };
@ -39,7 +41,8 @@ namespace gui {
START_COMBAT = 11, START_COMBAT = 11,
STOP_COMBAT = 12, STOP_COMBAT = 12,
STAIRS_DOWN = 13, STAIRS_DOWN = 13,
QUIT = 14 LOOT_OPEN=14,
QUIT = 15
}; };
class FSM : public DeadSimpleFSM<State, Event> { class FSM : public DeadSimpleFSM<State, Event> {
@ -58,6 +61,7 @@ namespace gui {
StatusUI $status_ui; StatusUI $status_ui;
MapViewUI $map_ui; MapViewUI $map_ui;
MiniMapUI $mini_map; MiniMapUI $mini_map;
LootUI $loot_ui;
sf::Font $font; sf::Font $font;
FSM(); FSM();
@ -75,6 +79,7 @@ namespace gui {
void IN_COMBAT(Event ev); void IN_COMBAT(Event ev);
void COMBAT_ROTATE(Event ev); void COMBAT_ROTATE(Event ev);
void NEXT_LEVEL(Event ev); void NEXT_LEVEL(Event ev);
void LOOTING(Event ev);
void END(Event ev); void END(Event ev);
void try_move(int dir, bool strafe); void try_move(int dir, bool strafe);

@ -0,0 +1,51 @@
#include "gui/loot_ui.hpp"
#include "constants.hpp"
#include "color.hpp"
#include <fmt/xchar.h>
#include "guecstra.hpp"
namespace gui {
using namespace guecs;
LootUI::LootUI(GameLevel level) :
$level(level)
{
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200,
RAY_VIEW_Y+RAY_VIEW_HEIGHT/2-200, 400, 400);
$gui.layout(
"[button_0 | button_1|button_2 | button_3]"
"[button_4 | button_5|button_6 | button_7]"
"[button_8 | button_9|button_10 | button_11]"
"[button_12 | button_13|button_14 | button_15]"
);
}
void LootUI::init() {
$gui.set<Background>($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID});
for(auto [name, cell] : $gui.cells()) {
auto id = $gui.entity(name);
$gui.set<guecs::Rectangle>(id, {});
if(id < 4) {
$gui.set<guecs::Clickable>(id, {
[=](auto, auto) { fmt::println("clicked {}", name); }
});
$gui.set<guecs::Sprite>(id, {"broken_yoyo-64"});
}
}
$gui.init();
}
void LootUI::render(sf::RenderWindow& window) {
$gui.render(window);
}
void LootUI::update_level(GameLevel &level) {
$level = level;
init();
}
bool LootUI::mouse(float x, float y, bool hover) {
return $gui.mouse(x, y, hover);
}
}

@ -0,0 +1,22 @@
#pragma once
#include "levelmanager.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Font.hpp>
#include <guecs/ui.hpp>
#include "events.hpp"
namespace gui {
class LootUI {
public:
bool active = false;
guecs::UI $gui;
GameLevel $level;
LootUI(GameLevel level);
void init();
void render(sf::RenderWindow& window);
void update_level(GameLevel &level);
bool mouse(float x, float y, bool hover);
};
}

@ -1,4 +1,4 @@
#include "main_ui.hpp" #include "gui/main_ui.hpp"
#include "components.hpp" #include "components.hpp"
#include "easings.hpp" #include "easings.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>

@ -3,12 +3,12 @@
#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp> #include <SFML/System/Clock.hpp>
#include "stats.hpp" #include "stats.hpp"
#include "overlay_ui.hpp" #include <guecs/ui.hpp>
#include "debug_ui.hpp" #include "gui/overlay_ui.hpp"
#include "gui/debug_ui.hpp"
#include "raycaster.hpp" #include "raycaster.hpp"
#include "camera.hpp" #include "camera.hpp"
#include <optional> #include <optional>
#include <guecs/ui.hpp>
namespace gui { namespace gui {

@ -1,4 +1,4 @@
#include "overlay_ui.hpp" #include "gui/overlay_ui.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "color.hpp" #include "color.hpp"
#include "events.hpp" #include "events.hpp"

@ -1,4 +1,4 @@
#include "ritual_ui.hpp" #include "gui/ritual_ui.hpp"
#include "components.hpp" #include "components.hpp"
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include "rand.hpp" #include "rand.hpp"

@ -1,4 +1,4 @@
#include "status_ui.hpp" #include "gui/status_ui.hpp"
#include "components.hpp" #include "components.hpp"
#include "inventory.hpp" #include "inventory.hpp"
#include "color.hpp" #include "color.hpp"

@ -4,7 +4,7 @@
#include <deque> #include <deque>
#include "textures.hpp" #include "textures.hpp"
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include "ritual_ui.hpp" #include "gui/ritual_ui.hpp"
namespace gui { namespace gui {
class StatusUI { class StatusUI {

@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include "spatialmap.hpp" #include "spatialmap.hpp"
#include "components.hpp" #include "components.hpp"
#include "boss_fight_ui.hpp" #include "gui/boss_fight_ui.hpp"
using std::shared_ptr; using std::shared_ptr;

@ -1,4 +1,4 @@
#include "gui_fsm.hpp" #include "gui/gui_fsm.hpp"
#include "textures.hpp" #include "textures.hpp"
#include "sound.hpp" #include "sound.hpp"
#include "autowalker.hpp" #include "autowalker.hpp"
@ -33,6 +33,7 @@ int main(int argc, char* argv[]) {
// ZED: need to sort out how to deal with this in the FSM // ZED: need to sort out how to deal with this in the FSM
if(main.in_state(gui::State::IDLE) if(main.in_state(gui::State::IDLE)
|| main.in_state(gui::State::NEXT_LEVEL) || main.in_state(gui::State::NEXT_LEVEL)
|| main.in_state(gui::State::LOOTING)
|| main.in_state(gui::State::IN_COMBAT)) || main.in_state(gui::State::IN_COMBAT))
{ {
if(main.autowalking) { if(main.autowalking) {

@ -86,32 +86,25 @@ sources = [
'autowalker.cpp', 'autowalker.cpp',
'backend.cpp', 'backend.cpp',
'battle.cpp', 'battle.cpp',
'boss_fight_ui.cpp',
'camera.cpp', 'camera.cpp',
'combat.cpp', 'combat.cpp',
'combat_ui.cpp',
'components.cpp', 'components.cpp',
'config.cpp', 'config.cpp',
'dbc.cpp', 'dbc.cpp',
'debug_ui.cpp',
'devices.cpp', 'devices.cpp',
'goap.cpp', 'goap.cpp',
'guecstra.cpp', 'guecstra.cpp',
'gui_fsm.cpp',
'inventory.cpp', 'inventory.cpp',
'levelmanager.cpp', 'levelmanager.cpp',
'lights.cpp', 'lights.cpp',
'main_ui.cpp',
'map.cpp', 'map.cpp',
'map_view.cpp', 'map_view.cpp',
'matrix.cpp', 'matrix.cpp',
'matrix.cpp', 'matrix.cpp',
'mini_map.cpp', 'mini_map.cpp',
'overlay_ui.cpp',
'pathing.cpp', 'pathing.cpp',
'rand.cpp', 'rand.cpp',
'raycaster.cpp', 'raycaster.cpp',
'ritual_ui.cpp',
'rituals.cpp', 'rituals.cpp',
'save.cpp', 'save.cpp',
'shaders.cpp', 'shaders.cpp',
@ -119,10 +112,18 @@ sources = [
'sound.cpp', 'sound.cpp',
'spatialmap.cpp', 'spatialmap.cpp',
'stats.cpp', 'stats.cpp',
'status_ui.cpp',
'systems.cpp', 'systems.cpp',
'textures.cpp', 'textures.cpp',
'tilemap.cpp', 'tilemap.cpp',
'gui/boss_fight_ui.cpp',
'gui/loot_ui.cpp',
'gui/combat_ui.cpp',
'gui/debug_ui.cpp',
'gui/gui_fsm.cpp',
'gui/main_ui.cpp',
'gui/overlay_ui.cpp',
'gui/ritual_ui.cpp',
'gui/status_ui.cpp',
'worldbuilder.cpp', 'worldbuilder.cpp',
] ]

Loading…
Cancel
Save