Get the FSM for the GUIworked out and fix the rendering so it works right.
This commit is contained in:
parent
81cbc24064
commit
d81e127686
3 changed files with 95 additions and 61 deletions
|
|
@ -22,7 +22,6 @@ namespace gui {
|
||||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
||||||
$main_ui($window),
|
$main_ui($window),
|
||||||
$combat_ui(false),
|
$combat_ui(false),
|
||||||
$font{FONT_FILE_NAME},
|
|
||||||
$dnd_loot($status_ui, $loot_ui, $window, $router)
|
$dnd_loot($status_ui, $loot_ui, $window, $router)
|
||||||
{
|
{
|
||||||
$window.setVerticalSyncEnabled(VSYNC);
|
$window.setVerticalSyncEnabled(VSYNC);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ namespace gui {
|
||||||
StatusUI $status_ui;
|
StatusUI $status_ui;
|
||||||
MapViewUI $map_ui;
|
MapViewUI $map_ui;
|
||||||
LootUI $loot_ui;
|
LootUI $loot_ui;
|
||||||
sf::Font $font;
|
|
||||||
gui::routing::Router $router;
|
gui::routing::Router $router;
|
||||||
DNDLoot $dnd_loot;
|
DNDLoot $dnd_loot;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
struct UI {
|
namespace animator {
|
||||||
|
struct UI {
|
||||||
guecs::UI $ui;
|
guecs::UI $ui;
|
||||||
|
|
||||||
void init(const std::string& sprite_name) {
|
void init(const std::string& sprite_name) {
|
||||||
|
|
@ -46,7 +47,71 @@ struct UI {
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods) {
|
bool mouse(float x, float y, guecs::Modifiers mods) {
|
||||||
return $ui.mouse(x, y, mods);
|
return $ui.mouse(x, y, mods);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
START=__LINE__,
|
||||||
|
END=__LINE__,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FSM : public DeadSimpleFSM<State, game::Event> {
|
||||||
|
UI $ui;
|
||||||
|
gui::routing::Router $router;
|
||||||
|
sf::RenderWindow $window{sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Animation Crafting Tool"};
|
||||||
|
|
||||||
|
void init(const std::string &sprite_name) {
|
||||||
|
$ui.init(sprite_name);
|
||||||
|
$window.setVerticalSyncEnabled(VSYNC);
|
||||||
|
if(FRAME_LIMIT) $window.setFramerateLimit(FRAME_LIMIT);
|
||||||
|
$window.setPosition({0,0});
|
||||||
|
}
|
||||||
|
|
||||||
|
void event(game::Event ev, std::any data={}) {
|
||||||
|
switch($state) {
|
||||||
|
FSM_STATE(State, START, ev);
|
||||||
|
FSM_STATE(State, END, ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void START(game::Event ev) {
|
||||||
|
state(State::START);
|
||||||
|
}
|
||||||
|
|
||||||
|
void END(game::Event ev) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_keyboard_mouse() {
|
||||||
|
while(const auto ev = $window.pollEvent()) {
|
||||||
|
using enum game::Event;
|
||||||
|
auto gui_ev = $router.process_event(ev);
|
||||||
|
auto mouse_pos = $window.mapPixelToCoords($router.position);
|
||||||
|
|
||||||
|
switch(gui_ev) {
|
||||||
|
case MOUSE_CLICK:
|
||||||
|
$ui.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
||||||
|
break;
|
||||||
|
case MOUSE_MOVE:
|
||||||
|
$ui.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover});
|
||||||
|
break;
|
||||||
|
case QUIT:
|
||||||
|
state(State::END);
|
||||||
|
default:
|
||||||
|
break; // ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void render() {
|
||||||
|
$window.clear();
|
||||||
|
$ui.render($window);
|
||||||
|
$window.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool active() {
|
||||||
|
return !in_state(State::END);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
shaders::init();
|
shaders::init();
|
||||||
|
|
@ -59,44 +124,15 @@ int main(int argc, char* argv[]) {
|
||||||
dbc::check(argc == 2, "USAGE: animator <sprite>");
|
dbc::check(argc == 2, "USAGE: animator <sprite>");
|
||||||
std::string sprite_name{argv[1]};
|
std::string sprite_name{argv[1]};
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Animation Crafting Tool");
|
|
||||||
window.setVerticalSyncEnabled(VSYNC);
|
|
||||||
|
|
||||||
if(FRAME_LIMIT) window.setFramerateLimit(FRAME_LIMIT);
|
|
||||||
window.setPosition({0,0});
|
|
||||||
|
|
||||||
sound::mute(true);
|
sound::mute(true);
|
||||||
sound::play("ambient_1", true);
|
sound::play("ambient_1", true);
|
||||||
|
|
||||||
UI main{};
|
animator::FSM main;
|
||||||
main.init(sprite_name);
|
main.init(argv[1]);
|
||||||
gui::routing::Router router;
|
|
||||||
|
|
||||||
while(true) {
|
while(main.active()) {
|
||||||
while(const auto ev = window.pollEvent()) {
|
main.render();
|
||||||
using enum game::Event;
|
main.handle_keyboard_mouse();
|
||||||
auto gui_ev = router.process_event(ev);
|
|
||||||
auto mouse_pos = window.mapPixelToCoords(router.position);
|
|
||||||
|
|
||||||
switch(gui_ev) {
|
|
||||||
case MOUSE_CLICK:
|
|
||||||
main.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
|
||||||
break;
|
|
||||||
case MOUSE_MOVE:
|
|
||||||
main.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover});
|
|
||||||
break;
|
|
||||||
case QUIT:
|
|
||||||
return 0;
|
|
||||||
default:
|
|
||||||
break; // ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
window.clear();
|
|
||||||
main.render(window);
|
|
||||||
window.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(10ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue