Skip to content

Commit

Permalink
Fixed a bug where the menu was not getting reset properly when gettin…
Browse files Browse the repository at this point in the history
…g on another game
  • Loading branch information
ClementDreptin committed Oct 3, 2021
1 parent 819608d commit 0351f16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Hayzen/src/Core/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ Menu Game::s_Menu;
Option Game::s_RootOption;


//--------------------------------------------------------------------------------------
// Name: ~Game()
// Desc: Stop the menu and cleanup the root option when the game is destroyed.
//--------------------------------------------------------------------------------------
Game::~Game()
{
s_Menu.Stop();
s_RootOption.Cleanup();
}


//--------------------------------------------------------------------------------------
// Name: Init()
// Desc: Common initialization behavior to all games.
Expand Down
2 changes: 1 addition & 1 deletion Hayzen/src/Core/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Game
{
public:
virtual ~Game() {}
virtual ~Game();

virtual VOID Init() = 0;

Expand Down
13 changes: 13 additions & 0 deletions Hayzen/src/Core/Option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ VOID Option::OnClick(Menu* pMenu)
if (!m_Children.empty())
pMenu->SetCurrentOption(this);
}


//--------------------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Reset the members.
//--------------------------------------------------------------------------------------
VOID Option::Cleanup()
{
m_uiIndex = 0;
m_fnCallback = nullptr;
m_pParent = nullptr;
m_Children.clear();
}
2 changes: 2 additions & 0 deletions Hayzen/src/Core/Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Option : public Text
Option* GetParent() CONST { return m_pParent; }

CONST std::vector<std::shared_ptr<Option>>& GetChildren() CONST { return m_Children; }

VOID Cleanup();
private:
UINT m_uiIndex;
Callback m_fnCallback;
Expand Down

0 comments on commit 0351f16

Please sign in to comment.