diff --git a/assets/config.json b/assets/config.json index 487730d..981fe8f 100644 --- a/assets/config.json +++ b/assets/config.json @@ -83,8 +83,13 @@ "frame_width": 1920, "frame_height": 1080 }, - "test_story": - {"path": "assets/stories/test_storyboard.png", + "intro_story": + {"path": "assets/stories/intro_story.png", + "frame_width": 1280, + "frame_height": 720 + }, + "win_story": + {"path": "assets/stories/win_story.png", "frame_width": 1280, "frame_height": 720 } @@ -119,6 +124,6 @@ }, "game_play": { "levels_to_win": 4, - "help_text": "WASD moves\nQE rotates\nSpace attacks\nESC close\nRight-Click to heal\nClick on Ladders\nDev Tools:\nP: Debug\nZ: Mind Reader\nN: Next Level\nK: Die\nH/F1: Help\nF5: Screenshot\nReach Level 5 to Win\nAttack to Get Gud\nGet Hit to Get Tuff" + "help_text": "WASD moves\nQE rotates\nSpace attacks\nESC close\nRight-Click to heal\nClick on Ladders\nDev Tools:\nP: Debug\nZ: Mind Reader\nN: Next Level\nK: Die\nH/F1: Help\nF5: Screenshot\nExit Level 5 to Win\nAttack to Get Gud\nGet Hit to Get Tuff" } } diff --git a/assets/scenes.json b/assets/scenes.json index 48a7f78..da7274d 100644 --- a/assets/scenes.json +++ b/assets/scenes.json @@ -24,8 +24,10 @@ }, "NEXT_LEVEL": { "layout": [ - "[_|_|_|_|_|_]", - "[_|_|_|*%(200,100)buttons|_|_]" + "[_]", + "[_|_|_|*%(200,100)text|_|_]", + "[_|_|_|*%(200,200)buttons|_|_]", + "[_]" ], "background": "next_level_scene", "actors": [ @@ -47,22 +49,11 @@ }, "STARTING": { "layout": [ - "[_|*%(200, 200)ag_bot|_|=*%(200,100)speech|_|_]", - "[_|_|_ |*%(200,100)buttons|_|_]" + "[_|_|_|_|_|_]", + "[_|_|_|*%(200,100)buttons|_|_]" ], "background": "starting_scene", "actors": [ - { - "name": "ag_bot", - "sprite": "ag_bot", - "cell": "ag_bot", - "scale_x": 0.65, - "scale_y": 0.65, - "x": -40, - "y": 70, - "at_mid": false, - "flipped": false - } ], "fixtures": [ ], @@ -70,7 +61,6 @@ "layout": [ "[_]", "[_|=*%(300, 100)Start|_|_|_]", - "[_|=*%(300, 100)About|_|_|_]", "[_|=*%(300, 100)Quit|_|_|_]", "[_]" ], diff --git a/assets/stories.json b/assets/stories.json index 9f4d7bc..e662743 100644 --- a/assets/stories.json +++ b/assets/stories.json @@ -1,7 +1,7 @@ { "intro_story": {"_type": "Storyboard", - "image": "test_story", + "image": "intro_story", "audio": "test_story", "layout": [ "[a|b|c1]", @@ -22,5 +22,19 @@ ["00:13", "i","shake", "60"], ["00:14", "i","bounce", "60"] ] + }, + "win_story": + {"_type": "Storyboard", + "image": "win_story", + "audio": "test_story", + "layout": [ + "[a|b|c1]", + "[d|e|c2]", + "[g|h|i]" + ], + "beats": [ + ["00:00", "a","pan", "60"], + ["00:01", "b","shake", "30"] + ] } } diff --git a/assets/stories/intro_story.png b/assets/stories/intro_story.png new file mode 100644 index 0000000..2c049ad Binary files /dev/null and b/assets/stories/intro_story.png differ diff --git a/assets/stories/win_story.png b/assets/stories/win_story.png new file mode 100644 index 0000000..2c049ad Binary files /dev/null and b/assets/stories/win_story.png differ diff --git a/src/graphics/scene.cpp b/src/graphics/scene.cpp index c237d27..cde8434 100644 --- a/src/graphics/scene.cpp +++ b/src/graphics/scene.cpp @@ -31,7 +31,7 @@ namespace scene { bool at_mid = config["at_mid"]; - sf::Text text(*$ui.$font, "", 60); + sf::Text text(*$gui.$font, "", 60); return {name, st, anim, cell, {scale_x, scale_y}, {x, y}, at_mid, flipped, nullptr, text}; } @@ -60,12 +60,12 @@ 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($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT}); - auto& background = $ui.get($ui.MAIN); + $gui.position(SCENE_VIEW_X, SCENE_VIEW_Y, SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT); + $gui.set($gui.MAIN, {$gui.$parser, guecs::THEME.TRANSPARENT}); + auto& background = $gui.get($gui.MAIN); background.set_sprite($scene.background, true); - $ui.layout($layout); + $gui.layout($layout); for(auto& actor : $actors) { actor.pos = position_sprite(actor.st, actor.cell, @@ -76,6 +76,17 @@ namespace scene { fixture.pos = position_sprite(fixture.st, fixture.cell, fixture.scale, fixture.at_mid, fixture.pos.x, fixture.pos.y); } + + if($gui.contains("text")) { + auto text_id = $gui.entity("text"); + auto bg_color = guecs::THEME.DARK_DARK; + bg_color.a = 100; + // BUG: guecs should initialize anything added if it needs it + $gui.set(text_id, {0, bg_color}); + $gui.set(text_id, {L"", 55}); + } + + $gui.init(); } void Engine::apply_effect(const std::string& actor, const std::string& shader) { @@ -94,11 +105,11 @@ namespace scene { } bool Engine::mouse(float x, float y, guecs::Modifiers mods) { - return $ui.mouse(x, y, mods); + return $gui.mouse(x, y, mods); } void Engine::render(sf::RenderTexture& view) { - $ui.render(view); + $gui.render(view); for(auto& fixture : $fixtures) { view.draw(*fixture.st.sprite, fixture.effect.get()); @@ -110,7 +121,7 @@ namespace scene { } $camera.render(view); - if(DEBUG) $ui.debug_layout(view); + if(DEBUG) $gui.debug_layout(view); // BUG: should I do this here or let the caller do it? view.display(); @@ -158,7 +169,7 @@ namespace scene { } sf::Vector2f Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff, float y_diff) { - auto& cell = $ui.cell_for(cell_name); + auto& cell = $gui.cell_for(cell_name); float x = float(at_mid ? cell.mid_x : cell.x); float y = float(at_mid ? cell.mid_y : cell.y); @@ -203,4 +214,11 @@ namespace scene { void Engine::reset(sf::RenderTexture& view) { $camera.reset(view); } + + void Engine::set_text(const std::string& content) { + if($gui.contains("text")) { + auto el = $gui.get_if($gui.entity("text")); + el->text->setString(guecs::to_wstring(content)); + } + } } diff --git a/src/graphics/scene.hpp b/src/graphics/scene.hpp index d6ad2bd..15d29d3 100644 --- a/src/graphics/scene.hpp +++ b/src/graphics/scene.hpp @@ -29,7 +29,7 @@ namespace scene { struct Engine { sf::Clock $clock; - guecs::UI $ui; + guecs::UI $gui; components::AnimatedScene& $scene; std::string $layout; std::unordered_map $actor_name_ids; @@ -46,7 +46,7 @@ namespace scene { 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"); } + lel::Cell& button_cell() { return $gui.cell_for("buttons"); } Element config_scene_element(nlohmann::json& config, bool duped); @@ -60,5 +60,6 @@ namespace scene { void zoom(float mid_x, float mid_y, const std::string& style, float scale); void reset(sf::RenderTexture& view); void set_end_cb(std::function cb); + void set_text(const std::string& content); }; } diff --git a/src/gui/fsm.cpp b/src/gui/fsm.cpp index ab7a984..9d67031 100644 --- a/src/gui/fsm.cpp +++ b/src/gui/fsm.cpp @@ -592,8 +592,9 @@ namespace gui { auto config = settings::get("config"); size_t levels_to_win = config["game_play"]["levels_to_win"]; - if(level.index <= levels_to_win) { + if(level.index < levels_to_win) { show_scene("NEXT_LEVEL"); + $cur_scene->set_text(fmt::format("ENTERING\nLEVEL\n{}", level.index+2)); state(State::NEXT_LEVEL_SCENE); } else { show_scene("WIN"); diff --git a/src/gui/scene_ui.cpp b/src/gui/scene_ui.cpp index baed9af..46e67ed 100644 --- a/src/gui/scene_ui.cpp +++ b/src/gui/scene_ui.cpp @@ -29,22 +29,26 @@ namespace gui { auto& button_cell = $scene.button_cell(); - $ui.position(button_cell.x, button_cell.y, button_cell.w, button_cell.h); - $ui.layout(layout); + $gui.position(button_cell.x, button_cell.y, button_cell.w, button_cell.h); + $gui.layout(layout); - for(auto& [name, cell] : $ui.cells()) { - auto ui_id = $ui.entity(name); - $ui.set(ui_id, {guecs::to_wstring(name)}); - $ui.set(ui_id, {}); - $ui.set(ui_id, {}); + for(auto& [name, cell] : $gui.cells()) { + auto ui_id = $gui.entity(name); + $gui.set(ui_id, {guecs::to_wstring(name)}); + $gui.set(ui_id, {5, guecs::THEME.DARK_MID}); + $gui.set(ui_id, {}); if(actions.contains(name)) { auto event_id = actions[name]; - $ui.set(ui_id, guecs::make_action(ui_id, event_id)); + $gui.set(ui_id, guecs::make_action(ui_id, event_id)); } } - $ui.init(); + $gui.init(); + } + + void SceneUI::set_text(const std::string& text) { + $scene.set_text(text); } void SceneUI::render(sf::RenderTarget &target) { @@ -52,8 +56,8 @@ namespace gui { target.draw($view_sprite); if(has_buttons) { - $ui.render(target); - if(DEBUG) $ui.debug_layout(target); + $gui.render(target); + if(DEBUG) $gui.debug_layout(target); } } @@ -63,7 +67,7 @@ namespace gui { bool SceneUI::mouse(float x, float y, guecs::Modifiers mods) { $scene.mouse(x, y, mods); - $ui.mouse(x, y, mods); + $gui.mouse(x, y, mods); return false; } diff --git a/src/gui/scene_ui.hpp b/src/gui/scene_ui.hpp index 32bdbb2..2ae6aaf 100644 --- a/src/gui/scene_ui.hpp +++ b/src/gui/scene_ui.hpp @@ -13,7 +13,7 @@ namespace gui { AnimatedScene $scene_data{load_scene(name)}; scene::Engine $scene{$scene_data}; bool has_buttons = false; - guecs::UI $ui; + guecs::UI $gui; AnimatedScene load_scene(const std::string& name); void create_buttons(nlohmann::json& buttons); @@ -22,5 +22,6 @@ namespace gui { void render(sf::RenderTarget &target); void update(); bool mouse(float x, float y, guecs::Modifiers mods); + void set_text(const std::string& text); }; } diff --git a/src/gui/status_ui.cpp b/src/gui/status_ui.cpp index 8d63a0e..d6d133c 100644 --- a/src/gui/status_ui.cpp +++ b/src/gui/status_ui.cpp @@ -32,12 +32,16 @@ namespace gui { for(auto& [name, cell] : $gui.cells()) { auto gui_id = $gui.entity(name); - $gui.set(gui_id, {guecs::to_wstring(name)}); if(name.starts_with("body_")) { auto& cell = $gui.cell_for(name); $body_ui.init(cell.x, cell.y, cell.w, cell.h); } else { + // don't show inventory names + if(!name.starts_with("inv")) { + $gui.set(gui_id, {guecs::to_wstring(name)}); + } + $gui.set(gui_id, {}); $gui.set(gui_id, { guecs::make_action(gui_id, game::Event::INV_SELECT, {gui_id})