Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu for starting and quitting #32

Merged
merged 9 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
menu buttons
  • Loading branch information
helynranta committed Oct 28, 2022
commit 751ca91f898f85efd800f2495c8ac413d6b1f2c1
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ eol=lf
*.blend filter=lfs diff=lfs merge=lfs -text
*.gltf filter=lfs diff=lfs merge=lfs -text
*.glb filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
9 changes: 9 additions & 0 deletions assets/audio/MINIMALIST.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Universal UI Soundpack

Created and distributed by Nathan Gibson (https://nathangibson.myportfolio.com)
Creation date: 27/9/2021

License: Attribution 4.0 International (CC BY 4.0)
https://creativecommons.org/licenses/by/4.0/

Support me by crediting Nathan Gibson or https://nathangibson.myportfolio.com
Binary file added assets/audio/Minimalist2.wav
Binary file not shown.
Binary file added assets/audio/Minimalist7.wav
Binary file not shown.
8 changes: 8 additions & 0 deletions assets/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
{
"type": "file",
"filename": "fonts/honeyblot_caps.ttf"
},
{
"type": "file",
"filename": "audio/Minimalist2.wav"
},
{
"type": "file",
"filename": "audio/Minimalist7.wav"
}
]
}
10 changes: 9 additions & 1 deletion flappykarp.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"startup_scene":"fs1://scenes/game.scene",
"startup_scene":"fs1://scenes/load.scene",
"name": "flappy karp",
"version_string":"0.0.0",
"dynamic_libraries": ["flappykarp"],
Expand All @@ -13,5 +13,13 @@
"archive_path": "${binaryDir}/asset1.data",
"folder_path": "${projectDir}/assets/resources.json"
}
],
"fonts":
[
{
"name": "honeyblot",
"key": "fs1://fonts/honeyblot_caps.ttf",
"size": 64
}
]
}
2 changes: 2 additions & 0 deletions src/engine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include <component/transform.hpp>
#include <core/object_manager.hpp>
#include <core/scene.hpp>
#include <core/scene_orchestrator_state.hpp>
#include <core/system.hpp>
#include <core/view.hpp>
#include <imgui.hpp>
#include <engine/plugin.hpp>
#include <framework/audio_manager.hpp>
#include <plugin.hpp>
#include <resource/resource_loader.hpp>
#include <system/sdl_input_manager.hpp>
Expand Down
8 changes: 0 additions & 8 deletions src/scenes/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ namespace lerppana::flappykarp::scenes

void game::start()
{
if (!font_manager->fonts.contains("honeyblot"))
{
font_manager->add_font(
"honeyblot",
"fs1://fonts/honeyblot_caps.ttf",
64);
}

reset();
}

Expand Down
116 changes: 112 additions & 4 deletions src/scenes/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,117 @@

namespace lerppana::flappykarp::scenes
{
load::load() :
engine::core::scene("fs1://scenes/load.scene")
{}
void load::draw_exit_button()
{
auto loading = !resource_loader->idle();

void load::start() {}
auto font_size = loading ? 0.5f : 1.0f;

auto* font = font_manager->get_font("honeyblot");

ImGui::FontScope font_scope{font};
ImGui::SetWindowFontScale(font_size);

static auto width = 100.0f;
static auto padding = 70.f;
const auto font_height = ImGui::GetFontSize();
ImGui::SetCursorPos(ImVec2(
ImGui::GetWindowWidth() / 2 - width / 2,
ImGui::GetWindowHeight()/ 2 - font_height / 2 - padding));

ImGui::GroupScope text_group;
ImGui::StyleVar style(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.5f, 0.75f));

auto text = loading ? "Loading" : "Start";

if (loading)
{
ImGui::BeginDisabled();
}

if (ImGui::Button(text, ImVec2(250.f, 100.f)))
{
scene_orchestrator_state->request_scene_transition("fs1://scenes/game.scene");
audio_manager->play_clip("fs1://audio/Minimalist2.wav");
}

if (loading)
{
ImGui::EndDisabled();
}

static auto was_button_hovered = false;
auto is_hovered = ImGui::IsItemHovered();
if (!was_button_hovered && is_hovered && !loading)
{
audio_manager->play_clip("fs1://audio/Minimalist7.wav");
was_button_hovered = true;
}
else if (was_button_hovered && !is_hovered)
{
was_button_hovered = false;
}

width = ImGui::GetItemRectSize().x;
}

void load::draw_start_button()
{
auto* font = font_manager->get_font("honeyblot");
ImGui::SetWindowFontScale(1.0f);
ImGui::FontScope font_scope{font};

static auto width = 100.0f;
static auto padding = 70.f;

const auto font_height = ImGui::GetFontSize();
ImGui::SetCursorPos(ImVec2(
ImGui::GetWindowWidth() / 2 - width / 2,
ImGui::GetWindowHeight()/ 2 - font_height / 2 + padding));

ImGui::GroupScope text_group;
ImGui::StyleVar style(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.5f, 0.75f));
if (ImGui::Button("Quit", ImVec2(250.f, 100.f)))
{
scene_orchestrator_state->request_application_quit();
}

static auto was_button_hovered = false;
auto is_hovered = ImGui::IsItemHovered();
if (!was_button_hovered && is_hovered)
{
audio_manager->play_clip("fs1://audio/Minimalist7.wav");
was_button_hovered = true;
}
else if (was_button_hovered && !is_hovered)
{
was_button_hovered = false;
}

width = ImGui::GetItemRectSize().x;
}

void load::on_gui()
{
draw_start_button();
draw_exit_button();
}

void load::start()
{
resource_loader->request_load<resource::audio_resource>("fs1://audio/Minimalist2.wav");
resource_loader->request_load<resource::audio_resource>("fs1://audio/Minimalist7.wav");

resource_loader->request_load<resource::vk_mesh_resource>("fs1://models/ground.model.mesh");
resource_loader->request_load<resource::texture_resource>("fs1://textures/ground.png");

resource_loader->request_load<resource::vk_mesh_resource>("fs1://models/magikarp.model.mesh");
resource_loader->request_load<resource::vertex_bone_data_resource>("fs1://models/magikarp.skin.mesh");
resource_loader->request_load<resource::animation_resource>("fs1://models/magikarp.splash.anim");
resource_loader->request_load<resource::texture_resource>("fs1://textures/magikarp.png");

resource_loader->request_load<resource::vk_mesh_resource>("fs1://models/pipe.model.mesh");
resource_loader->request_load<resource::texture_resource>("fs1://textures/pipe.png");

}
}
24 changes: 23 additions & 1 deletion src/scenes/load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@ namespace lerppana::flappykarp::scenes
{
struct FLAPPYKARP_EXPORT load : engine::core::scene
{
explicit load();
explicit load(
std::shared_ptr<resource::resource_loader> resource_loader,
std::shared_ptr<vk::font_manager> font_manager,
std::shared_ptr<core::scene_orchestrator_state> scene_orchestrator_state,
std::shared_ptr<framework::audio_manager> audio_manager) :
engine::core::scene("fs1://scenes/load.scene"),
resource_loader(std::move(resource_loader)),
font_manager(std::move(font_manager)),
scene_orchestrator_state(std::move(scene_orchestrator_state)),
audio_manager(std::move(audio_manager))
{}

void draw_exit_button();

void draw_start_button();

void on_gui() final;

void start() final;

private:
std::shared_ptr<resource::resource_loader> resource_loader;
std::shared_ptr<vk::font_manager> font_manager;
std::shared_ptr<core::scene_orchestrator_state> scene_orchestrator_state;
std::shared_ptr<framework::audio_manager> audio_manager;
};
}
4 changes: 2 additions & 2 deletions vcpkg-registry/ports/reload-engine/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO lerppana/reload-engine
REF 90ac8993c6e4c09cd59d9cc7850d5b1ef21202c8
SHA512 46f6bba960f3d0340f38edb76b4019fb4d509239e995b70cb8d8def52ce42bd9fe964f268e568ab1f23e6991d28a02dc827d5341822bb267c9887a9514c66951
REF 08745fabeab574e9bd0defe5759bf4d611aa349e
SHA512 71bba0ba72e7b15dbff0307a985fead40a59c8ceb4abaf22e30b59bdae6e77d287dd5767fb32e5267c86f794e297801e99ebd6d72b650fccb0249908d4e8c50d
HEAD_REF master
AUTHORIZATION_TOKEN $ENV{GITHUB_AUTHORIZATION_TOKEN}
)
Expand Down
1 change: 1 addition & 0 deletions vcpkg-registry/ports/reload-engine/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"vulkan"
]
},
"sdl2-mixer",
{
"name": "bullet3",
"features": [
Expand Down