Files
pico-launcher/arm9/source/romBrowser/views/cheats/CheatsAdapter.h
2026-02-28 17:32:40 +01:00

69 lines
2.0 KiB
C++

#pragma once
#include "gui/views/RecyclerAdapter.h"
#include "cheats/CheatCategory.h"
#include "cheats/Cheat.h"
#include "CheatListItemView.h"
class CheatsAdapter : public RecyclerAdapter
{
public:
CheatsAdapter(const ICheatCategory* cheatCategory, const MaterialColorScheme* materialColorScheme,
const IFontRepository* fontRepository, const CheatListItemView::VramOffsets& vramOffsets)
: _cheatCategory(cheatCategory), _materialColorScheme(materialColorScheme)
, _fontRepository(fontRepository), _vramOffsets(vramOffsets) { }
u32 GetItemCount() const override
{
u32 numberOfCategories = 0;
_cheatCategory->GetCategories(numberOfCategories);
u32 numberOfCheats = 0;
_cheatCategory->GetCheats(numberOfCheats);
return numberOfCategories + numberOfCheats;
}
void GetViewSize(int& width, int& height) const override
{
width = 224;
height = 24;
}
View* CreateView() const override
{
return new CheatListItemView(_vramOffsets, _materialColorScheme, _fontRepository);
}
void DestroyView(View* view) const override
{
delete (CheatListItemView*)view;
}
void BindView(View* view, int index) const override
{
auto listItemView = static_cast<CheatListItemView*>(view);
u32 numberOfCategories = 0;
auto categories = _cheatCategory->GetCategories(numberOfCategories);
if ((u32)index < numberOfCategories)
{
listItemView->SetCategory(&categories[index]);
}
else
{
index -= numberOfCategories;
u32 numberOfCheats = 0;
auto cheats = _cheatCategory->GetCheats(numberOfCheats);
listItemView->SetCheat(&cheats[index]);
}
}
void ReleaseView(View* view, int index) const override
{
// Nothing to do
}
private:
const ICheatCategory* _cheatCategory;
const MaterialColorScheme* _materialColorScheme;
const IFontRepository* _fontRepository;
CheatListItemView::VramOffsets _vramOffsets;
};