Buttons on screens work and most screens now have a continue/quit button.
This commit is contained in:
parent
532366091b
commit
17f05e7093
9 changed files with 165 additions and 17 deletions
|
|
@ -1,27 +1,53 @@
|
||||||
{
|
{
|
||||||
"DEATH": {
|
"DEATH": {
|
||||||
"layout": [
|
"layout": [
|
||||||
"[=text]"
|
"[_|_|_|_|_|_]",
|
||||||
|
"[_|_|_|*%(200,100)buttons|_|_]"
|
||||||
],
|
],
|
||||||
"background": "death_scene",
|
"background": "death_scene",
|
||||||
"actors": [
|
"actors": [
|
||||||
],
|
],
|
||||||
"fixtures": [
|
"fixtures": [
|
||||||
]
|
],
|
||||||
|
"buttons": {
|
||||||
|
"layout": [
|
||||||
|
"[_]",
|
||||||
|
"[_|=*%(300, 100)Restart|_|_|_]",
|
||||||
|
"[_|=*%(300, 100)Quit|_|_|_]",
|
||||||
|
"[_]"
|
||||||
|
],
|
||||||
|
"actions": {
|
||||||
|
"Restart": 43,
|
||||||
|
"Quit": 38
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"NEXT_LEVEL": {
|
"NEXT_LEVEL": {
|
||||||
"layout": [
|
"layout": [
|
||||||
"[=text]"
|
"[_|_|_|_|_|_]",
|
||||||
|
"[_|_|_|*%(200,100)buttons|_|_]"
|
||||||
],
|
],
|
||||||
"background": "next_level_scene",
|
"background": "next_level_scene",
|
||||||
"actors": [
|
"actors": [
|
||||||
],
|
],
|
||||||
"fixtures": [
|
"fixtures": [
|
||||||
]
|
],
|
||||||
|
"buttons": {
|
||||||
|
"layout": [
|
||||||
|
"[_]",
|
||||||
|
"[_|=*%(300, 100)Continue|_|_|_]",
|
||||||
|
"[_|=*%(300, 100)Quit|_|_|_]",
|
||||||
|
"[_]"
|
||||||
|
],
|
||||||
|
"actions": {
|
||||||
|
"Continue": 43,
|
||||||
|
"Quit": 38
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"STARTING": {
|
"STARTING": {
|
||||||
"layout": [
|
"layout": [
|
||||||
"[_|*%(200, 200)ag_bot|_|*%(200,100)speech|_|_]",
|
"[_|*%(200, 200)ag_bot|_|=*%(200,100)speech|_|_]",
|
||||||
"[_|_|_ |*%(200,100)buttons|_|_]"
|
"[_|_|_ |*%(200,100)buttons|_|_]"
|
||||||
],
|
],
|
||||||
"background": "starting_scene",
|
"background": "starting_scene",
|
||||||
|
|
@ -51,16 +77,43 @@
|
||||||
"at_mid": false,
|
"at_mid": false,
|
||||||
"flipped": false
|
"flipped": false
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"buttons": {
|
||||||
|
"layout": [
|
||||||
|
"[_]",
|
||||||
|
"[_|=*%(300, 100)Start|_|_|_]",
|
||||||
|
"[_|=*%(300, 100)About|_|_|_]",
|
||||||
|
"[_|=*%(300, 100)Quit|_|_|_]",
|
||||||
|
"[_]"
|
||||||
|
],
|
||||||
|
"actions": {
|
||||||
|
"Start": 43,
|
||||||
|
"About": 43,
|
||||||
|
"Quit": 38
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"WIN": {
|
"WIN": {
|
||||||
"layout": [
|
"layout": [
|
||||||
"[=text]"
|
"[_|_|_|_|_|_]",
|
||||||
|
"[_|_|_|*%(200,100)buttons|_|_]"
|
||||||
],
|
],
|
||||||
"background": "win_scene",
|
"background": "win_scene",
|
||||||
"actors": [
|
"actors": [
|
||||||
],
|
],
|
||||||
"fixtures": [
|
"fixtures": [
|
||||||
]
|
],
|
||||||
|
"buttons": {
|
||||||
|
"layout": [
|
||||||
|
"[_]",
|
||||||
|
"[_|=*%(300, 100)Restart|_|_|_]",
|
||||||
|
"[_|=*%(300, 100)Quit|_|_|_]",
|
||||||
|
"[_]"
|
||||||
|
],
|
||||||
|
"actions": {
|
||||||
|
"Restart": 43,
|
||||||
|
"Quit": 38
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 252 KiB After Width: | Height: | Size: 252 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 168 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 179 KiB |
|
|
@ -94,6 +94,7 @@ namespace components {
|
||||||
std::vector<std::string> layout;
|
std::vector<std::string> layout;
|
||||||
json actors;
|
json actors;
|
||||||
json fixtures;
|
json fixtures;
|
||||||
|
json buttons;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Storyboard {
|
struct Storyboard {
|
||||||
|
|
@ -168,7 +169,7 @@ namespace components {
|
||||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||||
|
|
||||||
ENROLL_COMPONENT(Tile, display, foreground, background);
|
ENROLL_COMPONENT(Tile, display, foreground, background);
|
||||||
ENROLL_COMPONENT(AnimatedScene, background, layout, actors, fixtures);
|
ENROLL_COMPONENT(AnimatedScene, background, layout, actors, fixtures, buttons);
|
||||||
ENROLL_COMPONENT(Sprite, name, scale);
|
ENROLL_COMPONENT(Sprite, name, scale);
|
||||||
ENROLL_COMPONENT(Curative, hp);
|
ENROLL_COMPONENT(Curative, hp);
|
||||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ namespace scene {
|
||||||
void update();
|
void update();
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||||
void attach_text(const std::string& actor, const std::string& text);
|
void attach_text(const std::string& actor, const std::string& text);
|
||||||
|
|
||||||
|
nlohmann::json& buttons() { return $scene.buttons; };
|
||||||
|
lel::Cell& button_cell() { return $ui.cell_for("buttons"); }
|
||||||
|
|
||||||
Element config_scene_element(nlohmann::json& config, bool duped);
|
Element config_scene_element(nlohmann::json& config, bool duped);
|
||||||
|
|
||||||
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,18 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
|
mouse_action(guecs::NO_MODS);
|
||||||
|
break;
|
||||||
|
case MOUSE_MOVE: {
|
||||||
|
mouse_action({1 << guecs::ModBit::hover});
|
||||||
|
} break;
|
||||||
|
case START:
|
||||||
close_scene();
|
close_scene();
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_MOVE: {
|
case QUIT:
|
||||||
} break;
|
FSM::IDLE(ev, {});
|
||||||
|
break;
|
||||||
case TICK:
|
case TICK:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -86,8 +93,17 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
show_scene("STARTING");
|
mouse_action(guecs::NO_MODS);
|
||||||
state(State::START_SCENE);
|
break;
|
||||||
|
case MOUSE_MOVE: {
|
||||||
|
mouse_action({1 << guecs::ModBit::hover});
|
||||||
|
} break;
|
||||||
|
case START:
|
||||||
|
close_scene();
|
||||||
|
state(State::IDLE);
|
||||||
|
break;
|
||||||
|
case QUIT:
|
||||||
|
FSM::IDLE(ev, {});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -99,8 +115,17 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
show_scene("STARTING");
|
mouse_action(guecs::NO_MODS);
|
||||||
state(State::START_SCENE);
|
break;
|
||||||
|
case MOUSE_MOVE: {
|
||||||
|
mouse_action({1 << guecs::ModBit::hover});
|
||||||
|
} break;
|
||||||
|
case START:
|
||||||
|
close_scene();
|
||||||
|
state(State::IDLE);
|
||||||
|
break;
|
||||||
|
case QUIT:
|
||||||
|
FSM::IDLE(ev, {});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -112,10 +137,18 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
next_level();
|
mouse_action(guecs::NO_MODS);
|
||||||
|
break;
|
||||||
|
case MOUSE_MOVE: {
|
||||||
|
mouse_action({1 << guecs::ModBit::hover});
|
||||||
|
} break;
|
||||||
|
case START:
|
||||||
close_scene();
|
close_scene();
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
|
case QUIT:
|
||||||
|
FSM::IDLE(ev, {});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +279,7 @@ namespace gui {
|
||||||
fmt::println("!!!!!!!!!!!!!! COMBAT START in IDLE");
|
fmt::println("!!!!!!!!!!!!!! COMBAT START in IDLE");
|
||||||
break;
|
break;
|
||||||
case COMBAT_STOP:
|
case COMBAT_STOP:
|
||||||
fmt::println("!!!!!!!!!!!!!!!! COMBAT STOP in IDLE");
|
fmt::println("!!!!!!!!!!!!!! COMBAT STOP in IDLE");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break; // ignore everything else
|
break; // ignore everything else
|
||||||
|
|
@ -278,6 +311,12 @@ namespace gui {
|
||||||
|
|
||||||
void FSM::mouse_action(guecs::Modifiers mods) {
|
void FSM::mouse_action(guecs::Modifiers mods) {
|
||||||
sf::Vector2f pos = mouse_position();
|
sf::Vector2f pos = mouse_position();
|
||||||
|
|
||||||
|
if($cur_scene != nullptr) {
|
||||||
|
$cur_scene->mouse(pos.x, pos.y, mods);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, mods);
|
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, mods);
|
||||||
$status_ui.mouse(pos.x, pos.y, mods);
|
$status_ui.mouse(pos.x, pos.y, mods);
|
||||||
|
|
||||||
|
|
@ -460,6 +499,9 @@ namespace gui {
|
||||||
show_scene("NEXT_LEVEL");
|
show_scene("NEXT_LEVEL");
|
||||||
state(State::NEXT_LEVEL_SCENE);
|
state(State::NEXT_LEVEL_SCENE);
|
||||||
break;
|
break;
|
||||||
|
case eGUI::START:
|
||||||
|
event(Event::START, data);
|
||||||
|
break;
|
||||||
case eGUI::DEATH: {
|
case eGUI::DEATH: {
|
||||||
$status_ui.update();
|
$status_ui.update();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,60 @@
|
||||||
#include "gui/scene_ui.hpp"
|
#include "gui/scene_ui.hpp"
|
||||||
#include "game/config.hpp"
|
#include "game/config.hpp"
|
||||||
|
#include "events.hpp"
|
||||||
|
#include "gui/guecstra.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
void SceneUI::init() {
|
void SceneUI::init() {
|
||||||
$view_sprite.setPosition({0,0});
|
$view_sprite.setPosition({0,0});
|
||||||
$scene.init();
|
$scene.init();
|
||||||
|
create_buttons($scene.buttons());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneUI::create_buttons(nlohmann::json& buttons) {
|
||||||
|
// buttons are optional
|
||||||
|
if(buttons.size() == 0) return;
|
||||||
|
|
||||||
|
// alright have buttons
|
||||||
|
has_buttons = true;
|
||||||
|
|
||||||
|
std::string layout{};
|
||||||
|
auto& actions = buttons["actions"];
|
||||||
|
|
||||||
|
for(auto& line : buttons["layout"]) {
|
||||||
|
layout.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& button_cell = $scene.button_cell();
|
||||||
|
|
||||||
|
$ui.position(button_cell.x, button_cell.y, button_cell.w, button_cell.h);
|
||||||
|
$ui.layout(layout);
|
||||||
|
|
||||||
|
for(auto& [name, cell] : $ui.cells()) {
|
||||||
|
auto ui_id = $ui.entity(name);
|
||||||
|
$ui.set<guecs::Text>(ui_id, {guecs::to_wstring(name)});
|
||||||
|
$ui.set<guecs::Rectangle>(ui_id, {});
|
||||||
|
$ui.set<guecs::Effect>(ui_id, {});
|
||||||
|
|
||||||
|
if(actions.contains(name)) {
|
||||||
|
auto event_id = actions[name];
|
||||||
|
$ui.set<guecs::Clickable>(ui_id, guecs::make_action(ui_id, event_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneUI::render(sf::RenderTarget &target) {
|
void SceneUI::render(sf::RenderTarget &target) {
|
||||||
$scene.render($view_texture);
|
$scene.render($view_texture);
|
||||||
target.draw($view_sprite);
|
target.draw($view_sprite);
|
||||||
|
|
||||||
|
if(has_buttons) {
|
||||||
|
$ui.render(target);
|
||||||
|
if(DEBUG) $ui.debug_layout(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneUI::update() {
|
void SceneUI::update() {
|
||||||
|
|
@ -19,6 +63,7 @@ namespace gui {
|
||||||
|
|
||||||
bool SceneUI::mouse(float x, float y, guecs::Modifiers mods) {
|
bool SceneUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||||
$scene.mouse(x, y, mods);
|
$scene.mouse(x, y, mods);
|
||||||
|
$ui.mouse(x, y, mods);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,11 @@ namespace gui {
|
||||||
sf::Sprite $view_sprite{$view_texture.getTexture()};
|
sf::Sprite $view_sprite{$view_texture.getTexture()};
|
||||||
AnimatedScene $scene_data{load_scene(name)};
|
AnimatedScene $scene_data{load_scene(name)};
|
||||||
scene::Engine $scene{$scene_data};
|
scene::Engine $scene{$scene_data};
|
||||||
|
bool has_buttons = false;
|
||||||
|
guecs::UI $ui;
|
||||||
|
|
||||||
AnimatedScene load_scene(const std::string& name);
|
AnimatedScene load_scene(const std::string& name);
|
||||||
|
void create_buttons(nlohmann::json& buttons);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void render(sf::RenderTarget &target);
|
void render(sf::RenderTarget &target);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue