Skip to content

Commit

Permalink
memory maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumanvienna committed Oct 5, 2024
1 parent 49e0578 commit 8c3357b
Show file tree
Hide file tree
Showing 69 changed files with 386 additions and 349 deletions.
43 changes: 21 additions & 22 deletions application/lucre/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,41 @@

namespace LucreApp
{
std::unique_ptr<SCREEN_ScreenManager> UI::m_ScreenManager = nullptr;
std::shared_ptr<Texture> UI::m_FontAtlasTexture;
std::shared_ptr<Texture> UI::m_SpritesheetTexture;
std::shared_ptr<Common> UI::m_Common;
SCREEN_ScreenManager* UI::g_ScreenManager{nullptr};
Common* UI::g_Common{nullptr};

UI::UI(const std::string& name) : Layer(name) {}

UI::~UI()
{
g_ScreenManager = nullptr;
g_Common = nullptr;
}

void UI::OnAttach()
{
auto renderer = Engine::m_Engine->GetRenderer();
m_Spritesheet = Lucre::m_Spritesheet;
m_ScreenManager = std::make_unique<SCREEN_ScreenManager>(renderer, m_Spritesheet);
g_ScreenManager = m_ScreenManager.get();

m_FontAtlasTexture = ResourceSystem::GetTextureFromMemory("/images/atlas/fontAtlas.png", IDB_FONTS_RETRO, "PNG");
m_SpritesheetTexture = m_Spritesheet->GetTexture();
m_Common = std::make_unique<Common>();
g_Common = m_Common.get();

m_MainScreen = new MainScreen(m_Spritesheet);
m_MainScreen->OnAttach();
m_ScreenManager->push(m_MainScreen);

m_UIStarIcon = new UIStarIcon(false, "UI star icon");
Engine::m_Engine->PushOverlay(m_UIStarIcon);
m_UIStarIcon = std::make_unique<UIStarIcon>(false, "UI star icon");
Engine::m_Engine->PushOverlay(m_UIStarIcon.get());

m_UIControllerAnimation = new ControllerSetupAnimation("controller animation");
Engine::m_Engine->PushOverlay(m_UIControllerAnimation);
m_UIControllerAnimation = std::make_unique<ControllerSetupAnimation>("controller animation");
Engine::m_Engine->PushOverlay(m_UIControllerAnimation.get());
}

void UI::OnDetach()
{
m_MainScreen->OnDetach();
m_ScreenManager.reset();
m_FontAtlasTexture.reset();
m_SpritesheetTexture.reset();

delete m_MainScreen;
delete m_UIStarIcon;
}
void UI::OnDetach() { m_MainScreen->OnDetach(); }

void UI::OnUpdate(const Timestep& timestep)
{
Expand Down Expand Up @@ -251,10 +250,10 @@ namespace LucreApp
{
// draw health bar
Sprite whiteSprite = m_Spritesheet->GetSprite(I_WHITE);
float x1 = 32.0f * UI::m_Common->m_ScaleAll;
float y1 = 8.0f * UI::m_Common->m_ScaleAll;
float x2 = 132.0f * UI::m_Common->m_ScaleAll;
float y2 = 50.0f * UI::m_Common->m_ScaleAll;
float x1 = 32.0f * UI::g_Common->m_ScaleAll;
float y1 = 8.0f * UI::g_Common->m_ScaleAll;
float x2 = 132.0f * UI::g_Common->m_ScaleAll;
float y2 = 50.0f * UI::g_Common->m_ScaleAll;
Color colorForeground = 0xFF442a28;
Color colorBackground = 0xC0000000;

Expand Down
17 changes: 10 additions & 7 deletions application/lucre/UI/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace LucreApp
{

public:
UI(const std::string& name = "UI") : Layer(name) {}
UI(const std::string& name = "UI");
virtual ~UI() override;

void OnAttach() override;
void OnDetach() override;
Expand All @@ -52,20 +53,22 @@ namespace LucreApp
void Health(const float health);
SCREEN_DrawBuffer* Draw() const { return m_ScreenManager->getUIContext()->Draw(); }

static std::unique_ptr<SCREEN_ScreenManager> m_ScreenManager;
static std::shared_ptr<Texture> m_FontAtlasTexture;
static std::shared_ptr<Texture> m_SpritesheetTexture;
static std::shared_ptr<Common> m_Common;
static SCREEN_ScreenManager* g_ScreenManager;
static Common* g_Common;

private:
bool Touch(int flags, float x, float y, int deviceID);
void Key(int keyFlag, int keyCode, int deviceID);
void Axis();

private:
std::unique_ptr<SCREEN_ScreenManager> m_ScreenManager;
std::unique_ptr<Common> m_Common;
MainScreen* m_MainScreen{nullptr};
UIStarIcon* m_UIStarIcon{nullptr};
ControllerSetupAnimation* m_UIControllerAnimation = nullptr;
std::unique_ptr<UIStarIcon> m_UIStarIcon;
std::unique_ptr<ControllerSetupAnimation> m_UIControllerAnimation;
std::shared_ptr<Texture> m_FontAtlasTexture;
std::shared_ptr<Texture> m_SpritesheetTexture;

SpriteSheet* m_Spritesheet;
};
Expand Down
3 changes: 3 additions & 0 deletions application/lucre/UI/UIControllerIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

namespace LucreApp
{
UIControllerIcon::UIControllerIcon(bool indent, const std::string& name) : Layer(name), m_Indent(indent) {}

UIControllerIcon::~UIControllerIcon() {}

void UIControllerIcon::OnAttach()
{
Expand Down
3 changes: 2 additions & 1 deletion application/lucre/UI/UIControllerIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace LucreApp
{

public:
UIControllerIcon(bool indent, const std::string& name = "UIControllerIcon") : Layer(name), m_Indent(indent) {}
UIControllerIcon(bool indent, const std::string& name = "UIControllerIcon");
virtual ~UIControllerIcon();

void OnAttach() override;
void OnDetach() override;
Expand Down
82 changes: 41 additions & 41 deletions application/lucre/UI/mainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ namespace LucreApp

m_MainInfo = new InfoMessage(
ALIGN_CENTER | FLAG_WRAP_TEXT,
new SCREEN_UI::AnchorLayoutParams(UI::m_Common->m_AvailableWidth - UI::m_Common->m_MarginLeftRight * 3 -
2 * UI::m_Common->m_IconWidth - UI::m_Common->m_IconSpacer,
SCREEN_UI::WRAP_CONTENT, UI::m_Common->m_MarginLeftRight, 0.0f,
new SCREEN_UI::AnchorLayoutParams(UI::g_Common->m_AvailableWidth - UI::g_Common->m_MarginLeftRight * 3 -
2 * UI::g_Common->m_IconWidth - UI::g_Common->m_IconSpacer,
SCREEN_UI::WRAP_CONTENT, UI::g_Common->m_MarginLeftRight, 0.0f,
SCREEN_UI::NONE, SCREEN_UI::NONE));
// root_->Add(m_MainInfo);

verticalLayout->Add(new SCREEN_UI::Spacer(UI::m_Common->m_MarginLeftRight));
verticalLayout->Add(new SCREEN_UI::Spacer(UI::g_Common->m_MarginLeftRight));

// top line
SCREEN_UI::LinearLayout* topline =
Expand All @@ -112,9 +112,9 @@ namespace LucreApp
topline->SetTag("topLine");
verticalLayout->Add(topline);

topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_MarginLeftRight, 0.0f));
float horizontalSpacerTopline = UI::m_Common->m_AvailableWidth - 6 * UI::m_Common->m_IconWidth -
4 * UI::m_Common->m_IconSpacer - 2 * UI::m_Common->m_MarginLeftRight;
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_MarginLeftRight, 0.0f));
float horizontalSpacerTopline = UI::g_Common->m_AvailableWidth - 6 * UI::g_Common->m_IconWidth -
4 * UI::g_Common->m_IconSpacer - 2 * UI::g_Common->m_MarginLeftRight;

Sprite2D icon;
Sprite2D icon_active;
Expand All @@ -124,111 +124,111 @@ namespace LucreApp
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetScene1Button.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetScene1Button.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetScene1Button.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_Scene1Button = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_Scene1Button = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
m_Scene1Button->OnClick.Handle(this, &MainScreen::Scene1Click);
topline->Add(m_Scene1Button);
topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_IconSpacer, 0.0f));
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_IconSpacer, 0.0f));

// scene 2 button
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetScene2Button.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetScene2Button.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetScene2Button.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_Scene2Button = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_Scene2Button = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
m_Scene2Button->OnClick.Handle(this, &MainScreen::Scene2Click);
topline->Add(m_Scene2Button);
topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_IconSpacer, 0.0f));
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_IconSpacer, 0.0f));

// scene 3 button
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetScene3Button.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetScene3Button.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetScene3Button.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_Scene3Button = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_Scene2Button = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
m_Scene3Button->OnClick.Handle(this, &MainScreen::Scene3Click);
topline->Add(m_Scene3Button);
topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_IconSpacer, 0.0f));
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_IconSpacer, 0.0f));

// scene 4 button
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetScene4Button.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetScene4Button.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetScene4Button.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_Scene4Button = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_Scene2Button = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
m_Scene4Button->OnClick.Handle(this, &MainScreen::Scene4Click);
topline->Add(m_Scene4Button);
topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_IconSpacer, 0.0f));
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_IconSpacer, 0.0f));

// scene 5 button
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetScene5Button.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetScene5Button.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetScene5Button.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_Scene5Button = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_Scene5Button = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
m_Scene5Button->OnClick.Handle(this, &MainScreen::Scene5Click);
Expand All @@ -238,19 +238,19 @@ namespace LucreApp
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetSettings.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetSettings.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetSettings.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);

m_SettingsButton = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_GEAR));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_SettingsButton = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()));
}

Expand All @@ -266,7 +266,7 @@ namespace LucreApp
return SCREEN_UI::EVENT_CONTINUE;
});
topline->Add(m_SettingsButton);
topline->Add(new SCREEN_UI::Spacer(UI::m_Common->m_IconSpacer, 0.0f));
topline->Add(new SCREEN_UI::Spacer(UI::g_Common->m_IconSpacer, 0.0f));
if (m_SetFocus)
{
root_->SetDefaultFocusView(m_SettingsButton);
Expand All @@ -276,18 +276,18 @@ namespace LucreApp
if (CoreSettings::m_UITheme == THEME_RETRO)
{
icon = Sprite2D(m_SpritesheetOff.GetSprite(BUTTON_4_STATES_NOT_FOCUSED));
icon.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_active = Sprite2D(m_SpritesheetOff.GetSprite(BUTTON_4_STATES_FOCUSED));
icon_active.SetScale(UI::m_Common->m_IconScaleRetro * 0.5f);
icon_active.SetScale(UI::g_Common->m_IconScaleRetro * 0.5f);
icon_depressed = Sprite2D(m_SpritesheetOff.GetSprite(BUTTON_4_STATES_FOCUSED_DEPRESSED));
icon_depressed.SetScale(UI::m_Common->m_IconScaleRetro);
icon_depressed.SetScale(UI::g_Common->m_IconScaleRetro);
m_OffButton = new SCREEN_UI::Choice(icon, icon_active, icon_depressed,
new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()), true);
}
else
{
icon = Sprite2D(m_Spritesheet->GetSprite(I_OFF));
icon.SetScale(UI::m_Common->m_IconScale);
icon.SetScale(UI::g_Common->m_IconScale);
m_OffButton = new SCREEN_UI::Choice(icon, new SCREEN_UI::LayoutParams(icon.GetWidth(), icon.GetHeight()), true);
}
m_OffButton->OnClick.Handle(this, &MainScreen::OffClick);
Expand Down Expand Up @@ -318,7 +318,7 @@ namespace LucreApp
settingsScreen->OnAttach();
SceneChangedEvent event(GameState::State::SETTINGS);
Lucre::m_Application->OnAppEvent(event);
UI::m_ScreenManager->push(settingsScreen);
UI::g_ScreenManager->push(settingsScreen);

return SCREEN_UI::EVENT_DONE;
}
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/UI/offDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace LucreApp
Choice* cancelButton;

LinearLayout* items = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
float scale = UI::m_Common->m_ScaleAll;
float scale = UI::g_Common->m_ScaleAll;

if (CoreSettings::m_UITheme == THEME_RETRO)
{
Expand Down
Loading

0 comments on commit 8c3357b

Please sign in to comment.