persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UISystem Class Reference

#include <UISystem.hpp>

Inheritance diagram for UISystem:
Collaboration diagram for UISystem:

Public Member Functions

void init () override
void update (ae::q20_12_t) override
 Performs menu navigation logic.
void shutdown () override
 Unloads and cleans up all registered screens. Wrapper for cleanup.
void setSFXComponent (SFXComponent *sfx)
void on_receive (const Event::SwitchView &msg)
void on_receive (const Event::ResetUIResources &)
 ETL message handler to cleanup UISystem resources.
void on_receive (const Event::ConfigureUIScreen &config)
 ETL message handler to configure UIScreens.
void on_receive (const Event::ConfigureUIMenu &config)
 ETL message handler to configure UIMenus.
void on_receive (const Event::ShowMenu &msg)
 ETL message handler to switch to the specified menu.
void on_receive (const Event::HideAllMenus &)
 ETL message handler to hide all menus.
void on_receive (const Event::ShowScreen &msg)
 ETL message handler to switch to the specified screen.
void on_receive (const Event::HideAllScreens &)
 ETL message handler to hides all screens.
void on_receive (const Event::RenderUIText &)
 ETL message handler to render UI text.
void on_receive_unknown (const etl::imessage &msg)
 Fallback handler for unhandled ETL messages.

Private Member Functions

 UISystem ()
void lruUpdate (int id, bool isMain)
 Updates the order of lruBgSub/lruBgMain for the "least recently updated" id.
void registerScreen (UIScreen *screen)
 Registers screens to UISystem to have them pre-loaded before calling show.
void hideAllScreens ()
 hides all screens.
void cleanupScreens ()
 Unloads and cleans up all registered screens. Used to reset previous configs.
void cleanupMenus ()
 Unloads and cleans up all registered menus. Used to reset previous configs.
void cancelSFX ()
 Stops playing the current sound effect, if any.
void resetUIResources ()
 Cleans up UISystem related resources.
void applyPendingScreen ()
 Loads (if needed) and displays the pending screen, then clears it.

Private Attributes

UIManager & ui = UIManager::getInstance()
OamState * oamSub = nullptr
OamState * oamMain = nullptr
std::array< int, 3 > lruBgSub = {0, 0, 0}
 background ids. The order of the arrays matter. Front = least recently updated, back = last updated
std::array< int, 2 > lruBgMain = {0, 0}
std::array< int, 3 > hwBgSub = {0, 0, 0}
 original background ids (order doesn't change)
std::array< int, 2 > hwBgMain = {0, 0}
int screenMainCount = 0
 currently loaded screens (max 3 sub, 2 main)
int screenSubCount = 0
std::array< UIScreen *, 3 > loadedSub {nullptr, nullptr, nullptr}
std::array< UIScreen *, 2 > loadedMain = {nullptr, nullptr}
std::array< UIMenu *, 10 > menus = {}
UIMenu * activeMenu = nullptr
TextComponent * text = nullptr
SFXComponent * sfxCmpt = nullptr
bool renderUIText = false
UIScreen * pendingScreen = nullptr
 screen requested by ShowScreen, applied at the start of the next update

Friends

class Singleton< UISystem >

Detailed Description

Definition at line 26 of file UISystem.hpp.

Constructor & Destructor Documentation

◆ UISystem()

UISystem::UISystem ( )
inlineprivate

Definition at line 146 of file UISystem.hpp.

Member Function Documentation

◆ applyPendingScreen()

void UISystem::applyPendingScreen ( )
private

Loads (if needed) and displays the pending screen, then clears it.

display sprites on screen

display background on screen

text goes after the background is shown, so it does not extend the time with no background visible

Definition at line 258 of file UISystem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancelSFX()

void UISystem::cancelSFX ( )
private

Stops playing the current sound effect, if any.

Definition at line 554 of file UISystem.cpp.

Here is the caller graph for this function:

◆ cleanupMenus()

void UISystem::cleanupMenus ( )
private

Unloads and cleans up all registered menus. Used to reset previous configs.

Definition at line 573 of file UISystem.cpp.

Here is the caller graph for this function:

◆ cleanupScreens()

void UISystem::cleanupScreens ( )
private

Unloads and cleans up all registered screens. Used to reset previous configs.

Definition at line 514 of file UISystem.cpp.

Here is the caller graph for this function:

◆ hideAllScreens()

void UISystem::hideAllScreens ( )
private

hides all screens.

Definition at line 488 of file UISystem.cpp.

Here is the caller graph for this function:

◆ init()

void UISystem::init ( )
override

Definition at line 13 of file UISystem.cpp.

◆ lruUpdate()

void UISystem::lruUpdate ( int id,
bool isMain )
private

Updates the order of lruBgSub/lruBgMain for the "least recently updated" id.

The lruBgMain/lruBgSub arrays dynamically shuffle to track the Least Recently Used (LRU) hardware layer at index [0], ensuring the oldest visible screen is the one overwritten when capacity is reached.

Parameters
idthe background id
isMainflag indicating if the screen is to be rendered on the main (or sub) screen

Definition at line 390 of file UISystem.cpp.

Here is the caller graph for this function:

◆ on_receive() [1/9]

void UISystem::on_receive ( const Event::ConfigureUIMenu & config)

ETL message handler to configure UIMenus.

First, it resets any previous configs via cleanupMenus. Second, it sets all menus to be deactivated, and sets their text component pointer.

Note
Required to call in order to enable & use UIMenus
Parameters
configThe event payload containing the UIMenu configuration to apply.
Note
192px is the screen height. 1 row is reserved for the flashing text. Each line takes the font size height

Definition at line 218 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [2/9]

void UISystem::on_receive ( const Event::ConfigureUIScreen & config)

ETL message handler to configure UIScreens.

First, it resets any previous configs via cleanupScreens. Second, it sets the background pointers to render screens to. The arrays passed into setGraphics() must contain the actual libnds hardware background layer IDs (e.g., 0, 1, 2, 3). Third, it register screens via registerScreen to have them pre-loaded before calling show.

Note
Required to call in order to use UIScreens
Parameters
configThe event payload containing the UIScreen configuration to apply.

Definition at line 186 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [3/9]

void UISystem::on_receive ( const Event::HideAllMenus & )

ETL message handler to hide all menus.

Definition at line 375 of file UISystem.cpp.

◆ on_receive() [4/9]

void UISystem::on_receive ( const Event::HideAllScreens & )

ETL message handler to hides all screens.

Wrapper for hideAllScreens

Definition at line 342 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [5/9]

void UISystem::on_receive ( const Event::RenderUIText & )

ETL message handler to render UI text.

Definition at line 385 of file UISystem.cpp.

◆ on_receive() [6/9]

void UISystem::on_receive ( const Event::ResetUIResources & )

ETL message handler to cleanup UISystem resources.

Definition at line 181 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [7/9]

void UISystem::on_receive ( const Event::ShowMenu & msg)

ETL message handler to switch to the specified menu.

If another menu is already loaded & hidden, it deactivates that menu and activates the supplied menu pointer instead

Note
Cannot load multiple menus at one time.
Parameters
msgThe event payload containing the UIMenu to switch to.

Definition at line 347 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [8/9]

void UISystem::on_receive ( const Event::ShowScreen & msg)

ETL message handler to switch to the specified screen.

The switch is deferred: the screen is stored as pending and applied at the start of the next UISystem::update, so the VRAM writes happen inside VBlank. If the screen is already loaded & hidden, it displays screen. If the screen is not loaded, it loads and displays the screen.

Note
Cannot load the same UIScreen on both sub and main. Cannot load multiple UIScreens on the same physical screen (main or sub)
Parameters
msgThe event payload containing the UIScreen to switch to.

Definition at line 247 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive() [9/9]

void UISystem::on_receive ( const Event::SwitchView & msg)

Definition at line 175 of file UISystem.cpp.

Here is the call graph for this function:

◆ on_receive_unknown()

void UISystem::on_receive_unknown ( const etl::imessage & msg)
inline

Fallback handler for unhandled ETL messages.

Required by the ETL message router interface. Safely ignores any messages routed to the UISystem that do not have a specific handler.

Parameters
msgThe unhandled incoming message (unused).

Definition at line 140 of file UISystem.hpp.

◆ registerScreen()

void UISystem::registerScreen ( UIScreen * screen)
private

Registers screens to UISystem to have them pre-loaded before calling show.

When a screen is registered, it is assigned an available hardware bgId. Persistent = is always loaded into memory. Paged (swappable) = can be loaded/unloaded into memory.

Parameters
screenthe screen to register

Definition at line 440 of file UISystem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetUIResources()

void UISystem::resetUIResources ( )
private

Cleans up UISystem related resources.

Definition at line 562 of file UISystem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSFXComponent()

void UISystem::setSFXComponent ( SFXComponent * sfx)

Definition at line 170 of file UISystem.cpp.

◆ shutdown()

void UISystem::shutdown ( )
override

Unloads and cleans up all registered screens. Wrapper for cleanup.

Definition at line 165 of file UISystem.cpp.

Here is the call graph for this function:

◆ update()

void UISystem::update ( ae::q20_12_t dt)
override

Performs menu navigation logic.

Definition at line 19 of file UISystem.cpp.

Here is the call graph for this function:

◆ Singleton< UISystem >

friend class Singleton< UISystem >
friend

Definition at line 140 of file UISystem.hpp.

Member Data Documentation

◆ activeMenu

UIMenu* UISystem::activeMenu = nullptr
private

Definition at line 224 of file UISystem.hpp.

◆ hwBgMain

std::array<int, 2> UISystem::hwBgMain = {0, 0}
private

Definition at line 214 of file UISystem.hpp.

◆ hwBgSub

std::array<int, 3> UISystem::hwBgSub = {0, 0, 0}
private

original background ids (order doesn't change)

Definition at line 213 of file UISystem.hpp.

◆ loadedMain

std::array<UIScreen*, 2> UISystem::loadedMain = {nullptr, nullptr}
private

Definition at line 220 of file UISystem.hpp.

◆ loadedSub

std::array<UIScreen*, 3> UISystem::loadedSub {nullptr, nullptr, nullptr}
private

Definition at line 219 of file UISystem.hpp.

◆ lruBgMain

std::array<int, 2> UISystem::lruBgMain = {0, 0}
private

Definition at line 210 of file UISystem.hpp.

◆ lruBgSub

std::array<int, 3> UISystem::lruBgSub = {0, 0, 0}
private

background ids. The order of the arrays matter. Front = least recently updated, back = last updated

Definition at line 209 of file UISystem.hpp.

◆ menus

std::array<UIMenu*, 10> UISystem::menus = {}
private

Definition at line 223 of file UISystem.hpp.

◆ oamMain

OamState* UISystem::oamMain = nullptr
private

Definition at line 206 of file UISystem.hpp.

◆ oamSub

OamState* UISystem::oamSub = nullptr
private

Definition at line 205 of file UISystem.hpp.

◆ pendingScreen

UIScreen* UISystem::pendingScreen = nullptr
private

screen requested by ShowScreen, applied at the start of the next update

Definition at line 231 of file UISystem.hpp.

◆ renderUIText

bool UISystem::renderUIText = false
private

Definition at line 228 of file UISystem.hpp.

◆ screenMainCount

int UISystem::screenMainCount = 0
private

currently loaded screens (max 3 sub, 2 main)

Definition at line 217 of file UISystem.hpp.

◆ screenSubCount

int UISystem::screenSubCount = 0
private

Definition at line 218 of file UISystem.hpp.

◆ sfxCmpt

SFXComponent* UISystem::sfxCmpt = nullptr
private

Definition at line 226 of file UISystem.hpp.

◆ text

TextComponent* UISystem::text = nullptr
private

Definition at line 225 of file UISystem.hpp.

◆ ui

UIManager& UISystem::ui = UIManager::getInstance()
private

Definition at line 203 of file UISystem.hpp.


The documentation for this class was generated from the following files: