Have an initial start screen and simple prototypes for other screens.

This commit is contained in:
Zed A. Shaw 2026-04-01 15:31:36 -04:00
parent e113c0bc97
commit d03020cfef
8 changed files with 139 additions and 53 deletions

View file

@ -1,7 +1,5 @@
{ {
"DEATH": { "DEATH": {
"components": [
{"_type": "AnimatedScene",
"layout": [ "layout": [
"[=text]" "[=text]"
], ],
@ -10,12 +8,8 @@
], ],
"fixtures": [ "fixtures": [
] ]
}
]
}, },
"NEXT_LEVEL": { "NEXT_LEVEL": {
"components": [
{"_type": "AnimatedScene",
"layout": [ "layout": [
"[=text]" "[=text]"
], ],
@ -24,12 +18,8 @@
], ],
"fixtures": [ "fixtures": [
] ]
}
]
}, },
"STARTING": { "STARTING": {
"components": [
{"_type": "AnimatedScene",
"layout": [ "layout": [
"[=text]" "[=text]"
], ],
@ -38,12 +28,8 @@
], ],
"fixtures": [ "fixtures": [
] ]
}
]
}, },
"WIN": { "WIN": {
"components": [
{"_type": "AnimatedScene",
"layout": [ "layout": [
"[=text]" "[=text]"
], ],
@ -53,6 +39,4 @@
"fixtures": [ "fixtures": [
] ]
} }
]
}
} }

View file

@ -55,6 +55,8 @@ namespace scene {
} }
void Engine::init() { void Engine::init() {
dbc::log($F("initialized scene with background {}", $scene.background));
$ui.position(SCENE_VIEW_X, SCENE_VIEW_Y, SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT); $ui.position(SCENE_VIEW_X, SCENE_VIEW_Y, SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT);
$ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT}); $ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
auto& background = $ui.get<guecs::Background>($ui.MAIN); auto& background = $ui.get<guecs::Background>($ui.MAIN);
@ -106,6 +108,9 @@ namespace scene {
$camera.render(view); $camera.render(view);
if(DEBUG) $ui.debug_layout(view); if(DEBUG) $ui.debug_layout(view);
// BUG: should I do this here or let the caller do it?
view.display();
} }
Element& Engine::actor_config(const std::string& actor) { Element& Engine::actor_config(const std::string& actor) {

View file

@ -25,11 +25,13 @@ namespace gui {
$window.setVerticalSyncEnabled(VSYNC); $window.setVerticalSyncEnabled(VSYNC);
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT); if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
$window.setPosition({0,0}); $window.setPosition({0,0});
} }
void FSM::event(Event ev, std::any data) { void FSM::event(Event ev, std::any data) {
switch($state) { switch($state) {
FSM_STATE(State, START, ev); FSM_STATE(State, START, ev);
FSM_STATE(State, START_SCREEN, ev);
FSM_STATE(State, MOVING, ev); FSM_STATE(State, MOVING, ev);
FSM_STATE(State, ATTACKING, ev, data); FSM_STATE(State, ATTACKING, ev, data);
FSM_STATE(State, ROTATING, ev); FSM_STATE(State, ROTATING, ev);
@ -44,13 +46,39 @@ namespace gui {
$main_ui.init(); $main_ui.init();
$loot_ui.init(); $loot_ui.init();
for(auto& [name, scene] : $scenes) {
scene->init();
}
// BUG: maybe this is a function on main_ui? // BUG: maybe this is a function on main_ui?
auto cell = $main_ui.overlay_cell("left"); auto cell = $main_ui.overlay_cell("left");
$debug_ui.init(cell); $debug_ui.init(cell);
$status_ui.init(); $status_ui.init();
run_systems(); run_systems();
$cur_scene = $scenes["STARTING"];
dbc::check($cur_scene != nullptr, "No STARTING scene?!");
state(State::START_SCREEN);
}
void FSM::START_SCREEN(Event ev) {
using enum Event;
switch(ev) {
case MOUSE_CLICK:
dbc::log("CLICK!");
$cur_scene = nullptr;
state(State::IDLE); state(State::IDLE);
break;
case MOUSE_MOVE: {
} break;
case TICK:
break;
default:
dbc::log($F("unhandled event: {}", int(ev)));
break;
}
} }
void FSM::MOVING(Event ) { void FSM::MOVING(Event ) {
@ -295,17 +323,22 @@ namespace gui {
void FSM::draw_gui() { void FSM::draw_gui() {
if($debug_ui.active) { if($debug_ui.active) {
debug_render(); debug_render();
} else {
$main_ui.render();
} }
if($cur_scene != nullptr) {
$cur_scene->render($window);
} else {
$main_ui.render();
$status_ui.render($window); $status_ui.render($window);
if($loot_ui.active) $loot_ui.render($window); if($loot_ui.active) $loot_ui.render($window);
if(in_state(State::LOOTING)) $dnd_loot.render(); if(in_state(State::LOOTING)) $dnd_loot.render();
} }
}
void FSM::update() { void FSM::update() {
if($cur_scene != nullptr) {
$cur_scene->update();
}
} }
void FSM::render() { void FSM::render() {

View file

@ -11,10 +11,12 @@
#include "gui/event_router.hpp" #include "gui/event_router.hpp"
#include "gui/dnd_loot.hpp" #include "gui/dnd_loot.hpp"
#include "events.hpp" #include "events.hpp"
#include "gui/scene_ui.hpp"
namespace gui { namespace gui {
enum class State { enum class State {
START=__LINE__, START=__LINE__,
START_SCREEN=__LINE__,
MOVING=__LINE__, MOVING=__LINE__,
ATTACKING=__LINE__, ATTACKING=__LINE__,
ROTATING=__LINE__, ROTATING=__LINE__,
@ -27,7 +29,6 @@ namespace gui {
public: public:
sf::RenderWindow $window; sf::RenderWindow $window;
bool $draw_stats = false; bool $draw_stats = false;
bool autowalking = false;
DebugUI $debug_ui; DebugUI $debug_ui;
MainUI $main_ui; MainUI $main_ui;
StatusUI $status_ui{STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT}; StatusUI $status_ui{STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT};
@ -35,17 +36,26 @@ namespace gui {
gui::routing::Router $router; gui::routing::Router $router;
DNDLoot $dnd_loot; DNDLoot $dnd_loot;
System::Registry $systems; System::Registry $systems;
std::unordered_map<std::string, std::shared_ptr<gui::SceneUI>> $scenes{
{"STARTING", std::make_shared<gui::SceneUI>("STARTING")},
{"DEATH", std::make_shared<gui::SceneUI>("DEATH")},
{"WIN", std::make_shared<gui::SceneUI>("WIN")},
{"NEXT_LEVEL", std::make_shared<gui::SceneUI>("NEXT_LEVEL")},
};
std::shared_ptr<gui::SceneUI> $cur_scene = nullptr;
FSM(); FSM();
void event(game::Event ev, std::any data={}); void event(game::Event ev, std::any data={});
void START(game::Event ev); void START(game::Event ev);
void START_SCREEN(game::Event ev);
void IDLE(game::Event ev, std::any data);
void MOVING(game::Event ev); void MOVING(game::Event ev);
void ATTACKING(game::Event ev, std::any data); void ATTACKING(game::Event ev, std::any data);
void MAPPING(game::Event ev); void MAPPING(game::Event ev);
void ROTATING(game::Event ev); void ROTATING(game::Event ev);
void IDLE(game::Event ev, std::any data);
void LOOTING(game::Event ev, std::any data); void LOOTING(game::Event ev, std::any data);
void END(game::Event ev); void END(game::Event ev);

29
src/gui/scene_ui.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "gui/scene_ui.hpp"
#include "game/config.hpp"
namespace gui {
void SceneUI::init() {
$view_sprite.setPosition({0,0});
$scene.init();
}
void SceneUI::render(sf::RenderTarget &target) {
$scene.render($view_texture);
target.draw($view_sprite);
}
void SceneUI::update() {
$scene.update();
}
bool SceneUI::mouse(float x, float y, guecs::Modifiers mods) {
$scene.mouse(x, y, mods);
return false;
}
AnimatedScene SceneUI::load_scene(const std::string& name) {
auto scene_config = settings::get("scenes")[name];
return components::convert<AnimatedScene>(scene_config);
}
}

23
src/gui/scene_ui.hpp Normal file
View file

@ -0,0 +1,23 @@
#pragma once
#include <guecs/ui.hpp>
#include "graphics/scene.hpp"
namespace gui {
using namespace components;
class SceneUI {
public:
std::string name;
sf::RenderTexture $view_texture{{SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT}};
sf::Sprite $view_sprite{$view_texture.getTexture()};
AnimatedScene $scene_data{load_scene(name)};
scene::Engine $scene{$scene_data};
AnimatedScene load_scene(const std::string& name);
void init();
void render(sf::RenderTarget &target);
void update();
bool mouse(float x, float y, guecs::Modifiers mods);
};
}

View file

@ -33,6 +33,7 @@ int main(int argc, char* argv[]) {
// BUG: need to sort out how to deal with this in the FSM // BUG: 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::START_SCREEN)
|| main.in_state(gui::State::LOOTING)) || main.in_state(gui::State::LOOTING))
{ {
main.handle_keyboard_mouse(); main.handle_keyboard_mouse();

View file

@ -20,6 +20,7 @@ sources = files(
'gui/main_ui.cpp', 'gui/main_ui.cpp',
'gui/overlay_ui.cpp', 'gui/overlay_ui.cpp',
'gui/body_ui.cpp', 'gui/body_ui.cpp',
'gui/scene_ui.cpp',
# graphics # graphics
'graphics/animation.cpp', 'graphics/animation.cpp',