Have an initial start screen and simple prototypes for other screens.
This commit is contained in:
parent
e113c0bc97
commit
d03020cfef
8 changed files with 139 additions and 53 deletions
|
|
@ -55,6 +55,8 @@ namespace scene {
|
|||
}
|
||||
|
||||
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.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
|
||||
auto& background = $ui.get<guecs::Background>($ui.MAIN);
|
||||
|
|
@ -106,6 +108,9 @@ namespace scene {
|
|||
|
||||
$camera.render(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) {
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@ namespace gui {
|
|||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
|
||||
$window.setPosition({0,0});
|
||||
|
||||
}
|
||||
|
||||
void FSM::event(Event ev, std::any data) {
|
||||
switch($state) {
|
||||
FSM_STATE(State, START, ev);
|
||||
FSM_STATE(State, START_SCREEN, ev);
|
||||
FSM_STATE(State, MOVING, ev);
|
||||
FSM_STATE(State, ATTACKING, ev, data);
|
||||
FSM_STATE(State, ROTATING, ev);
|
||||
|
|
@ -44,13 +46,39 @@ namespace gui {
|
|||
$main_ui.init();
|
||||
$loot_ui.init();
|
||||
|
||||
for(auto& [name, scene] : $scenes) {
|
||||
scene->init();
|
||||
}
|
||||
|
||||
// BUG: maybe this is a function on main_ui?
|
||||
auto cell = $main_ui.overlay_cell("left");
|
||||
$debug_ui.init(cell);
|
||||
$status_ui.init();
|
||||
run_systems();
|
||||
|
||||
state(State::IDLE);
|
||||
$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);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
} break;
|
||||
case TICK:
|
||||
break;
|
||||
default:
|
||||
dbc::log($F("unhandled event: {}", int(ev)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::MOVING(Event ) {
|
||||
|
|
@ -295,17 +323,22 @@ namespace gui {
|
|||
void FSM::draw_gui() {
|
||||
if($debug_ui.active) {
|
||||
debug_render();
|
||||
} else {
|
||||
$main_ui.render();
|
||||
}
|
||||
|
||||
$status_ui.render($window);
|
||||
if($loot_ui.active) $loot_ui.render($window);
|
||||
|
||||
if(in_state(State::LOOTING)) $dnd_loot.render();
|
||||
if($cur_scene != nullptr) {
|
||||
$cur_scene->render($window);
|
||||
} else {
|
||||
$main_ui.render();
|
||||
$status_ui.render($window);
|
||||
if($loot_ui.active) $loot_ui.render($window);
|
||||
if(in_state(State::LOOTING)) $dnd_loot.render();
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::update() {
|
||||
if($cur_scene != nullptr) {
|
||||
$cur_scene->update();
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::render() {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@
|
|||
#include "gui/event_router.hpp"
|
||||
#include "gui/dnd_loot.hpp"
|
||||
#include "events.hpp"
|
||||
#include "gui/scene_ui.hpp"
|
||||
|
||||
namespace gui {
|
||||
enum class State {
|
||||
START=__LINE__,
|
||||
START_SCREEN=__LINE__,
|
||||
MOVING=__LINE__,
|
||||
ATTACKING=__LINE__,
|
||||
ROTATING=__LINE__,
|
||||
|
|
@ -27,7 +29,6 @@ namespace gui {
|
|||
public:
|
||||
sf::RenderWindow $window;
|
||||
bool $draw_stats = false;
|
||||
bool autowalking = false;
|
||||
DebugUI $debug_ui;
|
||||
MainUI $main_ui;
|
||||
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;
|
||||
DNDLoot $dnd_loot;
|
||||
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();
|
||||
|
||||
void event(game::Event ev, std::any data={});
|
||||
|
||||
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 ATTACKING(game::Event ev, std::any data);
|
||||
void MAPPING(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 END(game::Event ev);
|
||||
|
||||
|
|
|
|||
29
src/gui/scene_ui.cpp
Normal file
29
src/gui/scene_ui.cpp
Normal 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
23
src/gui/scene_ui.hpp
Normal 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);
|
||||
};
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
// BUG: need to sort out how to deal with this in the FSM
|
||||
if(main.in_state(gui::State::IDLE)
|
||||
|| main.in_state(gui::State::START_SCREEN)
|
||||
|| main.in_state(gui::State::LOOTING))
|
||||
{
|
||||
main.handle_keyboard_mouse();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ sources = files(
|
|||
'gui/main_ui.cpp',
|
||||
'gui/overlay_ui.cpp',
|
||||
'gui/body_ui.cpp',
|
||||
'gui/scene_ui.cpp',
|
||||
|
||||
# graphics
|
||||
'graphics/animation.cpp',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue