Avoid having a single frame where the icon was not displayed on the top screen after selecting a different rom

This commit is contained in:
Gericom
2026-03-29 12:21:20 +02:00
parent 9ca3e38668
commit 53727e5fdd
15 changed files with 57 additions and 41 deletions

View File

@@ -13,9 +13,17 @@ class FileIcon
public: public:
virtual ~FileIcon() = 0; virtual ~FileIcon() = 0;
/// @brief Uploads the graphics of this icon to the specified \p vram address. /// @brief Sets the OBJ vram address and offset to use.
/// @param vram The vram address to load the graphics to. /// @param objVramAddress The OBJ vram address to use.
virtual void UploadGraphics(vu16* vram) = 0; /// @param objVramOffset The OBJ vram offset to use.
virtual void SetVramAddress(vu16* objVramAddress, u32 objVramOffset)
{
_vramAddress = objVramAddress;
_vramOffset = objVramOffset;
}
/// @brief Uploads the graphics of this icon to the vram address specified by SetVramAddress.
virtual void UploadGraphics() = 0;
/// @brief Updates this icon. /// @brief Updates this icon.
virtual void Update() { } virtual void Update() { }
@@ -25,10 +33,6 @@ public:
/// @param backgroundColor The color on which the icon is drawn. /// @param backgroundColor The color on which the icon is drawn.
virtual void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) = 0; virtual void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) = 0;
/// @brief Sets the OBJ vram offset of this icon.
/// @param offset The OBJ vram offset.
void SetObjVramOffset(u32 offset) { _vramOffset = offset; }
/// @brief Sets the icon animation frame. /// @brief Sets the icon animation frame.
/// @param frame The animation frame. /// @param frame The animation frame.
void SetAnimFrame(u32 frame) void SetAnimFrame(u32 frame)
@@ -50,6 +54,7 @@ public:
} }
protected: protected:
vu16* _vramAddress = nullptr;
u32 _vramOffset = 0; u32 _vramOffset = 0;
u32 _frame = 0; u32 _frame = 0;
Point _position; Point _position;

View File

@@ -38,14 +38,18 @@ NdsFileIcon::NdsFileIcon(const nds_banner_t* banner)
} }
} }
void NdsFileIcon::UploadGraphics(vu16* vram) void NdsFileIcon::SetVramAddress(vu16* objVramAddress, u32 objVramOffset)
{ {
_vramAddress = vram; FileIcon::SetVramAddress(objVramAddress, objVramOffset);
_currentVramSlot = 0; _currentVramSlot = 0;
_currentGfxIdx = -1; _currentGfxIdx = -1;
if (!_animated) }
void NdsFileIcon::UploadGraphics()
{
if (_vramAddress != nullptr && !_animated)
{ {
dma_ntrCopy32(3, _banner->iconGfx, vram, sizeof(_banner->iconGfx)); dma_ntrCopy32(3, _banner->iconGfx, _vramAddress, sizeof(_banner->iconGfx));
} }
} }

View File

@@ -8,7 +8,8 @@ class NdsFileIcon : public FileIcon
public: public:
explicit NdsFileIcon(const nds_banner_t* banner); explicit NdsFileIcon(const nds_banner_t* banner);
void UploadGraphics(vu16* vram) override; void SetVramAddress(vu16* objVramAddress, u32 objVramOffset) override;
void UploadGraphics() override;
void Update() override; void Update() override;
void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override; void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override;
@@ -16,13 +17,11 @@ private:
const nds_banner_t* _banner; const nds_banner_t* _banner;
bool _animated; bool _animated;
int _animTokenIdx; int _animTokenIdx;
// int _durationCounter;
u32 _lastAnimToken; u32 _lastAnimToken;
u32 _animLength; u32 _animLength;
u16 _tokenStartTimes[65]; u16 _tokenStartTimes[65];
bool _loop; bool _loop;
vu16* _vramAddress = nullptr;
int _currentVramSlot = 0; int _currentVramSlot = 0;
int _currentGfxIdx = -1; int _currentGfxIdx = -1;
}; };

View File

@@ -7,9 +7,12 @@
#include "gui/palette/DirectPalette.h" #include "gui/palette/DirectPalette.h"
#include "StaticIcon.h" #include "StaticIcon.h"
void StaticIcon::UploadGraphics(vu16* vram) void StaticIcon::UploadGraphics()
{ {
dma_ntrCopy32(3, _tileData, vram, 512); if (_vramAddress != nullptr)
{
dma_ntrCopy32(3, _tileData, _vramAddress, 512);
}
} }
void StaticIcon::Update() void StaticIcon::Update()

View File

@@ -7,7 +7,7 @@ public:
StaticIcon(const u8* tileData, const u16* paletteData) StaticIcon(const u8* tileData, const u16* paletteData)
: _tileData(tileData), _paletteData(paletteData) { } : _tileData(tileData), _paletteData(paletteData) { }
void UploadGraphics(vu16* vram) override; void UploadGraphics() override;
void Update() override; void Update() override;
void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override; void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override;

View File

@@ -119,7 +119,6 @@ void MaterialBannerListItemView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->SetPosition(6 + _position.x, 6 + _position.y); _icon->SetPosition(6 + _position.x, 6 + _position.y);
_icon->Draw(graphicsContext, frontColor); _icon->Draw(graphicsContext, frontColor);
} }

View File

@@ -24,23 +24,26 @@ MaterialFileIcon::MaterialFileIcon(const TCHAR* name, const MaterialColorScheme*
_displayName[i] = 0; _displayName[i] = 0;
} }
void MaterialFileIcon::UploadGraphics(vu16* vram) void MaterialFileIcon::UploadGraphics()
{ {
dma_ntrCopy32(3, GetIconTiles(), vram, 32 * 32 / 2); if (_vramAddress != nullptr)
{
dma_ntrCopy32(3, GetIconTiles(), _vramAddress, 32 * 32 / 2);
auto font = _fontRepository->GetFont(FontType::Medium11); auto font = _fontRepository->GetFont(FontType::Medium11);
u8 tileBuffer[32 * 16 / 2]; u8 tileBuffer[32 * 16 / 2];
memset(tileBuffer, 0, sizeof(tileBuffer)); memset(tileBuffer, 0, sizeof(tileBuffer));
u32 textWidth, textHeight; u32 textWidth, textHeight;
nft2_measureString(font, _displayName, textWidth, textHeight); nft2_measureString(font, _displayName, textWidth, textHeight);
nft2_string_render_params_t renderParams; nft2_string_render_params_t renderParams;
renderParams.x = ((int)32 - (int)textWidth) / 2; renderParams.x = ((int)32 - (int)textWidth) / 2;
renderParams.y = 0; renderParams.y = 0;
renderParams.width = 32; renderParams.width = 32;
renderParams.height = 16; renderParams.height = 16;
renderParams.a5i3 = false; renderParams.a5i3 = false;
nft2_renderString(font, _displayName, tileBuffer, 32, &renderParams); nft2_renderString(font, _displayName, tileBuffer, 32, &renderParams);
memcpy((u8*)vram + largeFolderIconTilesLen, tileBuffer, sizeof(tileBuffer)); memcpy((u8*)_vramAddress + largeFolderIconTilesLen, tileBuffer, sizeof(tileBuffer));
}
} }
void MaterialFileIcon::Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) void MaterialFileIcon::Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor)

View File

@@ -11,7 +11,7 @@ public:
MaterialFileIcon(const TCHAR* name, const MaterialColorScheme* materialColorScheme, MaterialFileIcon(const TCHAR* name, const MaterialColorScheme* materialColorScheme,
const IFontRepository* fontRepository); const IFontRepository* fontRepository);
void UploadGraphics(vu16* vram) override; void UploadGraphics() override;
void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override; void Draw(GraphicsContext& graphicsContext, const Rgb<8, 8, 8>& backgroundColor) override;
protected: protected:

View File

@@ -78,7 +78,6 @@ void MaterialFileInfoCardView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->Draw(graphicsContext, fgColor); _icon->Draw(graphicsContext, fgColor);
} }
} }

View File

@@ -47,7 +47,6 @@ void MaterialIconGridItemView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->SetPosition(6 + _position.x, 6 + _position.y); _icon->SetPosition(6 + _position.x, 6 + _position.y);
_icon->Draw(graphicsContext, frontColor); _icon->Draw(graphicsContext, frontColor);
} }

View File

@@ -117,7 +117,6 @@ void CustomBannerListItemView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->SetPosition(6 + _position.x, 6 + _position.y); _icon->SetPosition(6 + _position.x, 6 + _position.y);
_icon->Draw(graphicsContext, backgroundColor); _icon->Draw(graphicsContext, backgroundColor);
} }

View File

@@ -47,7 +47,6 @@ void CustomFileInfoView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->Draw(graphicsContext, _backgroundColor); _icon->Draw(graphicsContext, _backgroundColor);
} }
} }

View File

@@ -47,7 +47,6 @@ void CustomIconGridItemView::Draw(GraphicsContext& graphicsContext)
if (_icon) if (_icon)
{ {
_icon->SetObjVramOffset(_iconVramOffset);
_icon->SetPosition(6 + _position.x, 6 + _position.y); _icon->SetPosition(6 + _position.x, 6 + _position.y);
_icon->Draw(graphicsContext, Rgb<8, 8, 8>(200, 200, 200)); _icon->Draw(graphicsContext, Rgb<8, 8, 8>(200, 200, 200));
} }

View File

@@ -26,13 +26,17 @@ public:
void SetIcon(std::unique_ptr<FileIcon> icon) void SetIcon(std::unique_ptr<FileIcon> icon)
{ {
_icon = std::move(icon); _icon = std::move(icon);
if (_icon)
{
_icon->SetVramAddress(_iconVram, _iconVramOffset);
}
} }
void UploadIconGraphics() const void UploadIconGraphics() const
{ {
if (_icon) if (_icon)
{ {
_icon->UploadGraphics(_iconVram); _icon->UploadGraphics();
} }
} }

View File

@@ -27,13 +27,17 @@ public:
void SetIcon(std::unique_ptr<FileIcon> icon) void SetIcon(std::unique_ptr<FileIcon> icon)
{ {
_icon = std::move(icon); _icon = std::move(icon);
if (_icon)
{
_icon->SetVramAddress(_iconVram, _iconVramOffset);
}
} }
void UploadIconGraphics() const void UploadIconGraphics() const
{ {
if (_icon) if (_icon)
{ {
_icon->UploadGraphics(_iconVram); _icon->UploadGraphics();
} }
} }