Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Menus refacto (#107)
Browse files Browse the repository at this point in the history
* refacto: Replaced game state by game current menu

* ThePURGE class cleanup

* Re-implemented old menus

Co-authored-by: yanis fourel <yanis.fourel@epitech.eu>
  • Loading branch information
yanis-fourel and yanis-fourel committed Nov 26, 2020
1 parent b049c7e commit 47dad95
Show file tree
Hide file tree
Showing 25 changed files with 722 additions and 732 deletions.
6 changes: 3 additions & 3 deletions src/Application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ add_library(
src/factory/SpellFactory.cpp
src/factory/ParticuleFactory.cpp
src/DataConfigLoader.cpp
src/widgets/console/DebugConsole.cpp
src/widgets/console/ConsoleCommands.cpp
src/widgets/debug/console/DebugConsole.cpp
src/widgets/debug/console/ConsoleCommands.cpp
src/models/SpellDatabase.cpp
src/models/ClassDatabase.cpp)
src/models/ClassDatabase.cpp "include/menu/AMenu.hpp" "src/menu/AMenu.cpp" "src/menu/MainMenu.cpp" "include/menu/UpgradePanel.hpp" "src/menu/UpgradePanel.cpp" "src/menu/GameOver.cpp" "src/widgets/GameHUD.cpp")

target_link_libraries(ThePURGE PRIVATE engine_core) # note : should be engine_api or something ..

Expand Down
8 changes: 6 additions & 2 deletions src/Application/include/GameLogic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ class GameLogic {

std::uint32_t m_nextFloorSeed;

public: // signals // note : should be only related to input (elapsed time / keyboard / joysticks ...)
public: // signals

// note : should have only one signal : onUserMove, or something like that
// entt::sigh<void(entt::registry &, entt::entity &, const engine::d2::Acceleration &)> joystickMovement;
entt::sigh<void(entt::registry &, entt::entity &, const Direction &dir, bool is_pressed)> onMovement;

entt::sigh<void(entt::registry &)> onGameStart;
Expand All @@ -51,6 +50,8 @@ class GameLogic {

entt::sigh<void(entt::registry &, entt::entity player)> onPlayerLevelUp;

entt::sigh<void(entt::registry &, const engine::Event &e)> onEvent;

entt::sigh<void(entt::registry &, const engine::TimeElapsed &)> onGameUpdate;
entt::sigh<void(entt::registry &, const engine::TimeElapsed &)> onGameUpdateAfter;

Expand Down Expand Up @@ -78,6 +79,9 @@ class GameLogic {
decltype(onPlayerLevelUp)::sink_type sinkOnPlayerLevelUp{onPlayerLevelUp};
auto slots_level_up(entt::registry &, entt::entity) -> void;

decltype(onEvent)::sink_type sinkOnEvent{onEvent};
auto slots_on_event(entt::registry &, const engine::Event &) -> void;

decltype(onGameUpdate)::sink_type sinkGameUpdated{onGameUpdate};
auto slots_update_player_movement(entt::registry &, const engine::TimeElapsed &) -> void;
auto slots_update_ai_movement(entt::registry &, const engine::TimeElapsed &) -> void;
Expand Down
41 changes: 16 additions & 25 deletions src/Application/include/ThePURGE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include "component/all.hpp"

#include "widgets/console/DebugConsole.hpp"
#include "widgets/debug/console/DebugConsole.hpp"

#include "menu/AMenu.hpp"

#include "level/MapGenerator.hpp"
#include "GameLogic.hpp"
Expand All @@ -24,13 +26,6 @@ class ThePURGE : public engine::api::Game {
public:
ThePURGE();

enum class State {
LOADING,
IN_GAME,
IN_INVENTORY,
GAME_OVER,
};

auto onCreate(entt::registry &world) -> void final;

auto onUpdate(entt::registry &world, const engine::Event &e) -> void final;
Expand All @@ -39,14 +34,16 @@ class ThePURGE : public engine::api::Game {

auto drawUserInterface(entt::registry &world) -> void final;

entt::entity player; // note : should not require to keep it like that
void setMenu(std::unique_ptr<AMenu> &&menu)
{
m_currentMenu = std::move(menu);
}

auto setState(State new_state) noexcept { m_state = new_state; }

// constexpr // note : C++20 but not supported by MSVC yet
// TODO DELETEME : useless, we never get to see the background color
auto getBackgroundColor() const noexcept -> glm::vec3 final
{
return m_state == State::GAME_OVER ? glm::vec3{0.35f, 0.45f, 0.50f} : glm::vec3{0.45f, 0.55f, 0.60f};
return glm::vec3{0.45f, 0.55f, 0.60f};
}

auto getLogics() -> GameLogic & { return *m_logics; }
Expand All @@ -57,25 +54,19 @@ class ThePURGE : public engine::api::Game {

auto logics() const noexcept -> const std::unique_ptr<GameLogic> & { return m_logics; }

private:
// auto goToNextFloor(entt::registry &world) -> void;

auto displaySoundDebugGui() -> void;

State m_state{State::LOADING};

FloorGenParam m_map_generation_params;
std::uint32_t m_nextFloorSeed;

engine::Camera m_camera; // note : should be in engine::Core
public:
entt::entity player; // note : should not require to keep it like that

private:
std::unique_ptr<GameLogic> m_logics;

std::shared_ptr<engine::Sound> m_dungeonMusic;
classes::Database m_classDatabase;

engine::Camera m_camera; // note : should be in engine::Core
std::unique_ptr<DebugConsole> m_debugConsole;
std::shared_ptr<engine::Sound> m_dungeonMusic;

classes::Database m_classDatabase;
std::unique_ptr<AMenu> m_currentMenu;
};

} // namespace game
47 changes: 47 additions & 0 deletions src/Application/include/menu/AMenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <glm/vec2.hpp>
#include <entt/entt.hpp>

#include <Engine/Event/Event.hpp>

namespace game {

class ThePURGE;

class AMenu {

public:
AMenu();

void onEvent(entt::registry &world, ThePURGE &game, const engine::Event &e);
void onDraw(entt::registry &world, ThePURGE &game);

protected:
virtual void event(entt::registry &, ThePURGE &, const engine::Event &) {};
virtual void draw(entt::registry &, ThePURGE &) {};

bool up() const noexcept { return m_up; }
bool down() const noexcept { return m_down; }
bool right() const noexcept { return m_right; }
bool left() const noexcept { return m_left; }

private:
static constexpr float kRecoveryThreshold = 0.4f;
static constexpr float kTriggerThreshold = 0.6f;

glm::vec2 m_prevLeftJoystick;

bool m_up = false;
bool m_down = false;
bool m_left = false;
bool m_right = false;


bool m_recoveringUp = false;
bool m_recoveringDown = false;
bool m_recoveringRight = false;
bool m_recoveringLeft = false;
};

}
16 changes: 16 additions & 0 deletions src/Application/include/menu/GameOver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <entt/entt.hpp>

#include "AMenu.hpp"

namespace game::menu {

class GameOver : public AMenu {
public:
void draw(entt::registry &world, ThePURGE &game) override;
void event(entt::registry &world, ThePURGE &game, const engine::Event &e) override;

};

} // namespace game
18 changes: 18 additions & 0 deletions src/Application/include/menu/MainMenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <entt/entt.hpp>

#include "AMenu.hpp"

namespace game::menu {

class MainMenu : public AMenu {
public:
void draw(entt::registry &world, ThePURGE &game) override;
void event(entt::registry &world, ThePURGE &game, const engine::Event &e) override;

private:

};

} // namespace game
18 changes: 18 additions & 0 deletions src/Application/include/menu/UpgradePanel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <entt/entt.hpp>

#include "AMenu.hpp"

namespace game::menu {

class UpgradePanel : public AMenu {
public:
void draw(entt::registry &world, ThePURGE &game) override;
void event(entt::registry &world, ThePURGE &game, const engine::Event &e) override;

private:

};

} // namespace game
29 changes: 0 additions & 29 deletions src/Application/include/screen/GameOverMenu.hpp

This file was deleted.

26 changes: 0 additions & 26 deletions src/Application/include/screen/MainMenu.hpp

This file was deleted.

83 changes: 0 additions & 83 deletions src/Application/include/widgets/DebugAudio.hpp

This file was deleted.

Loading

0 comments on commit 47dad95

Please sign in to comment.