Use the new lel-geucs update process.
This commit is contained in:
parent
8f65e882ac
commit
cd475f8e02
14 changed files with 66 additions and 176 deletions
|
|
@ -140,11 +140,3 @@ executable('fragviewer',
|
|||
include_directories: inc_dirs,
|
||||
override_options: exe_defaults,
|
||||
dependencies: dependencies)
|
||||
|
||||
executable('multiscreen',
|
||||
[ 'tools/multiscreen.cpp' ],
|
||||
cpp_args: cpp_args,
|
||||
link_args: link_args,
|
||||
include_directories: inc_dirs,
|
||||
override_options: exe_defaults,
|
||||
dependencies: dependencies)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#define FSM_STATE(C, S, E, ...) case C::S: S(E, ##__VA_ARGS__); break
|
||||
#else
|
||||
static int last_event=-1;
|
||||
#define FSM_STATE(C, S, E, ...) case C::S: if(last_event != int(E)) { last_event = int(E); fmt::println(">> " #C " " #S " event={}, state={}", int(E), int($state));}; S(E, ##__VA_ARGS__); break
|
||||
#define FSM_STATE(C, S, E, ...) case C::S: if(last_event != int(E)) { last_event = int(E); fmt::println(">> [{}] " #C " " #S " event={}, state={}", __FILE__, int(E), int($state));}; S(E, ##__VA_ARGS__); break
|
||||
#endif
|
||||
|
||||
template<typename S, typename E>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace gui {
|
|||
auto gui_id = $gui.entity(key);
|
||||
|
||||
if(auto meter = $gui.get_if<Meter>(gui_id)) {
|
||||
meter->update_percent(float(value) / float(player_combat.max_hp));
|
||||
meter->percent = float(value) / float(player_combat.max_hp);
|
||||
|
||||
if(meter->percent < 0.2) {
|
||||
meter->color = sf::Color(220, 10, 10, 255);
|
||||
|
|
@ -67,8 +67,7 @@ namespace gui {
|
|||
meter->color = THEME.DARK_MID;
|
||||
}
|
||||
|
||||
// BUG: gross, make it stop
|
||||
meter->bar.shape->setFillColor(meter->color);
|
||||
meter->update();
|
||||
}
|
||||
|
||||
$gui.show_text(key, fmt::format(L"{}", guecs::to_wstring(key), value));
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#define FSM_DEBUG 1
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "gui/dnd_loot.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,17 +7,22 @@ namespace gui {
|
|||
using enum Event;
|
||||
using enum State;
|
||||
|
||||
game::Event Router::process_event(std::optional<sf::Event> ev) {
|
||||
std::pair<game::Event, guecs::Modifiers> Router::process_event(std::optional<sf::Event> ev) {
|
||||
$next_event = game::Event::TICK;
|
||||
|
||||
if(ev->is<sf::Event::Closed>()) {
|
||||
return game::Event::QUIT;
|
||||
return {game::Event::QUIT, guecs::NO_MODS};
|
||||
}
|
||||
|
||||
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
if(mouse->button == sf::Mouse::Button::Left || mouse->button == sf::Mouse::Button::Right) {
|
||||
left_button = mouse->button == sf::Mouse::Button::Left;
|
||||
position = mouse->position;
|
||||
if(left_button) {
|
||||
mouse_mods = {1 << guecs::ModBit::left};
|
||||
} else {
|
||||
mouse_mods = {1 << guecs::ModBit::right};
|
||||
}
|
||||
event(MOUSE_DOWN);
|
||||
}
|
||||
} else if(const auto* mouse = ev->getIf<sf::Event::MouseButtonReleased>()) {
|
||||
|
|
@ -25,10 +30,12 @@ namespace gui {
|
|||
if(mouse->button == sf::Mouse::Button::Left || mouse->button == sf::Mouse::Button::Right) {
|
||||
left_button = mouse->button == sf::Mouse::Button::Left;
|
||||
position = mouse->position;
|
||||
mouse_mods = guecs::NO_MODS;
|
||||
event(MOUSE_UP);
|
||||
}
|
||||
} else if(const auto* mouse = ev->getIf<sf::Event::MouseMoved>()) {
|
||||
position = mouse->position;
|
||||
mouse_mods = {1 << guecs::ModBit::hover};
|
||||
event(MOUSE_MOVE);
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +44,7 @@ namespace gui {
|
|||
event(KEY_PRESS);
|
||||
}
|
||||
|
||||
return $next_event;
|
||||
return {$next_event, mouse_mods};
|
||||
}
|
||||
|
||||
void Router::event(Event ev) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "events.hpp"
|
||||
#include "algos/simplefsm.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <guecs/ui.hpp>
|
||||
|
||||
namespace gui {
|
||||
namespace routing {
|
||||
|
|
@ -25,6 +26,7 @@ namespace gui {
|
|||
class Router : public DeadSimpleFSM<State, Event> {
|
||||
public:
|
||||
sf::Vector2i position;
|
||||
guecs::Modifiers mouse_mods = guecs::NO_MODS;
|
||||
sf::Keyboard::Scancode scancode;
|
||||
game::Event $next_event = game::Event::TICK;
|
||||
int move_count = 0;
|
||||
|
|
@ -39,7 +41,7 @@ namespace gui {
|
|||
void MOUSE_MOVING(Event ev);
|
||||
void MOUSE_DRAGGING(Event ev);
|
||||
|
||||
game::Event process_event(std::optional<sf::Event> ev);
|
||||
std::pair<game::Event, guecs::Modifiers> process_event(std::optional<sf::Event> ev);
|
||||
|
||||
void set_event(game::Event ev) {
|
||||
$next_event = ev;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#define FSM_DEBUG 1
|
||||
#include "gui/fsm.hpp"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
|
@ -27,20 +28,20 @@ namespace gui {
|
|||
|
||||
void FSM::event(Event ev, std::any data) {
|
||||
switch($state) {
|
||||
FSM_STATE(State, START, ev);
|
||||
FSM_STATE(State, INTRO, ev);
|
||||
FSM_STATE(State, SHOW_SCREEN, ev);
|
||||
FSM_STATE(State, MOVING, ev);
|
||||
FSM_STATE(State, START, ev, data);
|
||||
FSM_STATE(State, INTRO, ev, data);
|
||||
FSM_STATE(State, SHOW_SCREEN, ev, data);
|
||||
FSM_STATE(State, MOVING, ev, data);
|
||||
FSM_STATE(State, ATTACKING, ev, data);
|
||||
FSM_STATE(State, ROTATING, ev);
|
||||
FSM_STATE(State, ROTATING, ev, data);
|
||||
FSM_STATE(State, IDLE, ev, data);
|
||||
FSM_STATE(State, LOOTING, ev, data);
|
||||
FSM_STATE(State, END_QUIT, ev);
|
||||
FSM_STATE(State, END_NEW_GAME, ev);
|
||||
FSM_STATE(State, END_QUIT, ev, data);
|
||||
FSM_STATE(State, END_NEW_GAME, ev, data);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::START(Event ) {
|
||||
void FSM::START(Event ev, std::any data) {
|
||||
$main_ui.update_level();
|
||||
$main_ui.init();
|
||||
$loot_ui.init();
|
||||
|
|
@ -58,7 +59,7 @@ namespace gui {
|
|||
show_scene("STARTING");
|
||||
}
|
||||
|
||||
void FSM::INTRO(Event ev) {
|
||||
void FSM::INTRO(Event ev, std::any data) {
|
||||
dbc::check($story != nullptr, "you forgot the stroy");
|
||||
|
||||
if(ev == game::Event::MOUSE_CLICK) {
|
||||
|
|
@ -71,21 +72,16 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::SHOW_SCREEN(Event ev) {
|
||||
void FSM::SHOW_SCREEN(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
mouse_action({1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case START:
|
||||
close_scene();
|
||||
$story = std::make_shared<storyboard::UI>("intro_story");
|
||||
$story->init();
|
||||
state(State::INTRO);
|
||||
state(State::IDLE);
|
||||
//$story = std::make_shared<storyboard::UI>("intro_story");
|
||||
//$story->init();
|
||||
//state(State::INTRO);
|
||||
break;
|
||||
case NEW_GAME:
|
||||
close_scene();
|
||||
|
|
@ -97,7 +93,7 @@ namespace gui {
|
|||
state(State::IDLE);
|
||||
break;
|
||||
case QUIT:
|
||||
FSM::IDLE(ev, {});
|
||||
FSM::IDLE(ev, data);
|
||||
break;
|
||||
case TICK:
|
||||
break;
|
||||
|
|
@ -107,7 +103,7 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::MOVING(Event ) {
|
||||
void FSM::MOVING(Event ev, std::any data) {
|
||||
// this should be an optional that returns a point
|
||||
if(auto move_to = $main_ui.play_move()) {
|
||||
$systems.runMoving(*move_to);
|
||||
|
|
@ -125,7 +121,7 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::ROTATING(Event) {
|
||||
void FSM::ROTATING(Event ev, std::any data) {
|
||||
if(auto aim = $main_ui.play_rotate()) {
|
||||
auto& player_pos = GameDB::player_position();
|
||||
player_pos.aiming_at = *aim;
|
||||
|
|
@ -136,16 +132,9 @@ namespace gui {
|
|||
void FSM::LOOTING(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
case MOUSE_DRAG_START:
|
||||
case MOUSE_CLICK:
|
||||
case MOUSE_DROP:
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
default:
|
||||
if(!$dnd_loot.event(ev, data)) {
|
||||
state(State::IDLE);
|
||||
}
|
||||
if(!$dnd_loot.event(ev, data)) {
|
||||
dbc::log("!!!!!!!!!!!!!!!!!!!! dnd_lot said end");
|
||||
state(State::IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,12 +198,6 @@ namespace gui {
|
|||
$systems.runUseItem(slot_name);
|
||||
$status_ui.update();
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
mouse_action({1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case AIM_CLICK:
|
||||
$systems.runPickup();
|
||||
break;
|
||||
|
|
@ -244,11 +227,11 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::END_QUIT(Event ev) {
|
||||
void FSM::END_QUIT(Event ev, std::any data) {
|
||||
dbc::log($F("END_QUIT: received event after done: {}", int(ev)));
|
||||
}
|
||||
|
||||
void FSM::END_NEW_GAME(Event ev) {
|
||||
void FSM::END_NEW_GAME(Event ev, std::any data) {
|
||||
dbc::log($F("END_PLAYER_DIED: received event after done: {}", int(ev)));
|
||||
}
|
||||
|
||||
|
|
@ -256,27 +239,30 @@ namespace gui {
|
|||
return $window.mapPixelToCoords($router.position);
|
||||
}
|
||||
|
||||
void FSM::mouse_action(guecs::Modifiers mods) {
|
||||
void FSM::mouse_action() {
|
||||
sf::Vector2f pos = mouse_position();
|
||||
|
||||
if($screens.is_visible()) {
|
||||
$screens.mouse(pos.x, pos.y, mods);
|
||||
$screens.mouse(pos.x, pos.y, $router.mouse_mods);
|
||||
return;
|
||||
}
|
||||
|
||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, mods);
|
||||
$status_ui.mouse(pos.x, pos.y, mods);
|
||||
if($debug_ui.active) {
|
||||
$debug_ui.mouse(pos.x, pos.y, $router.mouse_mods);
|
||||
}
|
||||
|
||||
$status_ui.mouse(pos.x, pos.y, $router.mouse_mods);
|
||||
|
||||
if($loot_ui.active) {
|
||||
$loot_ui.mouse(pos.x, pos.y, mods);
|
||||
$loot_ui.mouse(pos.x, pos.y, $router.mouse_mods);
|
||||
} else {
|
||||
$main_ui.mouse(pos.x, pos.y, mods);
|
||||
$main_ui.mouse(pos.x, pos.y, $router.mouse_mods);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::handle_keyboard_mouse() {
|
||||
while(const auto ev = $window.pollEvent()) {
|
||||
auto gui_ev = $router.process_event(ev);
|
||||
auto [gui_ev, mouse_mods] = $router.process_event(ev);
|
||||
|
||||
if(gui_ev == Event::KEY_PRESS) {
|
||||
using KEY = sf::Keyboard::Scan;
|
||||
|
|
@ -335,7 +321,8 @@ namespace gui {
|
|||
break; // ignored
|
||||
}
|
||||
} else {
|
||||
event(gui_ev);
|
||||
// event(gui_ev, {mouse_mods});
|
||||
mouse_action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include "events.hpp"
|
||||
#include "gui/scene_ui.hpp"
|
||||
#include "gui/storyboard.hpp"
|
||||
#include "gui/uistack.hpp"
|
||||
#include <guecs/uistack.hpp>
|
||||
|
||||
namespace gui {
|
||||
enum class State {
|
||||
|
|
@ -55,21 +55,21 @@ namespace gui {
|
|||
|
||||
void event(game::Event ev, std::any data={});
|
||||
|
||||
void START(game::Event ev);
|
||||
void INTRO(game::Event ev);
|
||||
void SHOW_SCREEN(game::Event ev);
|
||||
void START(game::Event ev, std::any data);
|
||||
void INTRO(game::Event ev, std::any data);
|
||||
void SHOW_SCREEN(game::Event ev, std::any data);
|
||||
void IDLE(game::Event ev, std::any data);
|
||||
void MOVING(game::Event ev);
|
||||
void MOVING(game::Event ev, std::any data);
|
||||
void ATTACKING(game::Event ev, std::any data);
|
||||
void MAPPING(game::Event ev);
|
||||
void ROTATING(game::Event ev);
|
||||
void MAPPING(game::Event ev, std::any data);
|
||||
void ROTATING(game::Event ev, std::any data);
|
||||
void LOOTING(game::Event ev, std::any data);
|
||||
void END_QUIT(game::Event ev);
|
||||
void END_NEW_GAME(game::Event ev);
|
||||
void END_QUIT(game::Event ev, std::any data);
|
||||
void END_NEW_GAME(game::Event ev, std::any data);
|
||||
|
||||
void try_move(int dir, bool strafe);
|
||||
sf::Vector2f mouse_position();
|
||||
void mouse_action(guecs::Modifiers mods);
|
||||
void mouse_action();
|
||||
void handle_keyboard_mouse();
|
||||
void draw_gui();
|
||||
void update();
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ namespace gui {
|
|||
dbc::check(world->has<components::Sprite>(item),
|
||||
"item in inventory UI doesn't exist in world. New level?");
|
||||
auto& sprite = world->get<components::Sprite>(item);
|
||||
fmt::println("!!!!!!!!!!! trying to load {}", sprite.name);
|
||||
$gui.set_init<guecs::Icon>(id, {sprite.name});
|
||||
|
||||
guecs::GrabSource grabber{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ namespace gui {
|
|||
gui.set<Clickable>(area, {
|
||||
[=](auto) {
|
||||
auto world = GameDB::current_world();
|
||||
fmt::println("CLICK {}", name);
|
||||
world->send<game::Event>(game::Event::AIM_CLICK, area, {});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
#include <guecs/ui.hpp>
|
||||
#include "dbc.hpp"
|
||||
#include "constants.hpp"
|
||||
#include <flat_map>
|
||||
|
||||
namespace gui {
|
||||
template<typename SCREEN_TYPE>
|
||||
struct UIStack {
|
||||
using UIStackMap = std::flat_map<std::string, std::shared_ptr<SCREEN_TYPE>>;
|
||||
|
||||
UIStackMap screens{};
|
||||
bool visible = false;
|
||||
|
||||
UIStackMap::iterator $current{screens.begin()};
|
||||
SCREEN_TYPE* $active = nullptr;
|
||||
|
||||
void add(const std::string& name, std::shared_ptr<SCREEN_TYPE> screen) {
|
||||
screens.insert_or_assign(name, screen);
|
||||
update_active(screens.begin());
|
||||
}
|
||||
|
||||
void update_active(const UIStackMap::iterator& itr) {
|
||||
$current = itr;
|
||||
$active = (*$current).second.get();
|
||||
}
|
||||
|
||||
void set_active(const std::string& name) {
|
||||
dbc::check(screens.contains(name), $F("screen {} not in stack", name));
|
||||
update_active(screens.find(name));
|
||||
}
|
||||
|
||||
void set_visible(bool new_value) {
|
||||
visible = new_value;
|
||||
}
|
||||
|
||||
bool is_visible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
void render(sf::RenderTarget& target) {
|
||||
dbc::check($active != nullptr, "you didn't set active");
|
||||
$active->render(target);
|
||||
}
|
||||
|
||||
void update() {
|
||||
dbc::check($active != nullptr, "you didn't set active");
|
||||
$active->update();
|
||||
}
|
||||
|
||||
bool mouse(float x, float y, guecs::Modifiers mods = guecs::NO_MODS) {
|
||||
dbc::check($active != nullptr, "you didn't set active");
|
||||
return $active->mouse(x, y, mods);
|
||||
}
|
||||
|
||||
bool move(const UIStackMap::iterator& itr, const UIStackMap::iterator& avoid, const UIStackMap::iterator& result) {
|
||||
if(itr != avoid) {
|
||||
update_active(result);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool next() {
|
||||
return move($current + 1, screens.end(), $current + 1);
|
||||
}
|
||||
|
||||
bool prev() {
|
||||
return move($current, screens.begin(), $current - 1);
|
||||
}
|
||||
|
||||
void first() {
|
||||
update_active(screens.begin());
|
||||
}
|
||||
|
||||
void last() {
|
||||
update_active(screens.end() - 1);
|
||||
}
|
||||
|
||||
const std::string& active_name() {
|
||||
dbc::check($active != nullptr, "you didn't set active");
|
||||
return (*$current).first;
|
||||
}
|
||||
|
||||
std::shared_ptr<SCREEN_TYPE> active_ui() {
|
||||
dbc::check($active != nullptr, "you didn't set active");
|
||||
return (*$current).second;
|
||||
}
|
||||
|
||||
std::shared_ptr<SCREEN_TYPE> at(const std::string& name) {
|
||||
return screens.at(name);
|
||||
}
|
||||
|
||||
const UIStackMap::key_container_type& names() {
|
||||
return screens.keys();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
void play_game(std::shared_ptr<gui::FSM> main) {
|
||||
sound::play("ambient_1", true);
|
||||
sound::mute(false);
|
||||
main->event(game::Event::START);
|
||||
|
||||
while(main->active()) {
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ namespace animator {
|
|||
while(const auto ev = $window.pollEvent()) {
|
||||
using enum game::Event;
|
||||
using KEY = sf::Keyboard::Scan;
|
||||
auto gui_ev = $router.process_event(ev);
|
||||
auto [gui_ev, mouse_mods] = $router.process_event(ev);
|
||||
auto mouse_pos = $window.mapPixelToCoords($router.position);
|
||||
|
||||
switch(gui_ev) {
|
||||
|
|
@ -227,6 +227,7 @@ namespace animator {
|
|||
}
|
||||
|
||||
auto viewer = $ui.entity("viewer");
|
||||
|
||||
// BUG: this is some jank bullshit but it works
|
||||
$ui.set<guecs::Sprite>(viewer, {sprite_name, 0, false});
|
||||
$ui.init();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[wrap-git]
|
||||
directory=lel-guecs-0.7.1
|
||||
directory=lel-guecs-0.7.3
|
||||
url=https://git.zedshaw.games/games/lel-guecs.git
|
||||
revision=HEAD
|
||||
depth=1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue