mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 00:56:55 +02:00
Remember selected index when returning from cheat category
This commit is contained in:
@@ -6,13 +6,13 @@
|
||||
CheatsViewModel::CheatsViewModel(const FileInfo& romFileInfo, IRomBrowserController* romBrowserController)
|
||||
: _romFileInfo(romFileInfo), _romBrowserController(romBrowserController)
|
||||
{
|
||||
_categoryStack.fill(nullptr);
|
||||
_categoryStack.fill({ nullptr, 0 });
|
||||
_loadCheatsTask = _romBrowserController->GetIoTaskQueue()->Enqueue([this] (const vu8& cancelRequested)
|
||||
{
|
||||
_cheats = _romBrowserController->GetCheatRepository().GetCheatsForGame(_romFileInfo.GetFastFileRef());
|
||||
if (_cheats)
|
||||
{
|
||||
_categoryStack[0] = _cheats.get();
|
||||
_categoryStack[0] = { _cheats.get(), 0 };
|
||||
_state = State::DisplayCheats;
|
||||
}
|
||||
else
|
||||
@@ -37,7 +37,8 @@ void CheatsViewModel::ItemActivated()
|
||||
// Category activated
|
||||
if (_categoryStackLevel + 1 != _categoryStack.size())
|
||||
{
|
||||
_categoryStack[++_categoryStackLevel] = &categories[_selectedItem];
|
||||
_categoryStack[++_categoryStackLevel] = { &categories[_selectedItem], (u32)_selectedItem };
|
||||
_selectedItem = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -65,7 +66,8 @@ void CheatsViewModel::Back()
|
||||
}
|
||||
else
|
||||
{
|
||||
_categoryStack[_categoryStackLevel--] = nullptr;
|
||||
_selectedItem = _categoryStack[_categoryStackLevel].index;
|
||||
_categoryStack[_categoryStackLevel--] = { nullptr, 0 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,18 @@ public:
|
||||
void Close();
|
||||
|
||||
State GetState() const { return _state; }
|
||||
const ICheatCategory* GetCurrentCheatCategory() const { return _categoryStack[_categoryStackLevel]; }
|
||||
const ICheatCategory* GetCurrentCheatCategory() const { return _categoryStack[_categoryStackLevel].cheatCategory; }
|
||||
|
||||
constexpr int GetSelectedItem() const { return _selectedItem; }
|
||||
void SetSelectedItem(int selectedItem) { _selectedItem = selectedItem; }
|
||||
|
||||
private:
|
||||
struct CategoryStackEntry
|
||||
{
|
||||
const ICheatCategory* cheatCategory;
|
||||
u32 index;
|
||||
};
|
||||
|
||||
FileInfo _romFileInfo;
|
||||
IRomBrowserController* _romBrowserController;
|
||||
QueueTask<void> _loadCheatsTask;
|
||||
@@ -38,5 +44,5 @@ private:
|
||||
int _selectedItem = -1;
|
||||
bool _changed = false;
|
||||
u32 _categoryStackLevel = 0;
|
||||
std::array<const ICheatCategory*, 8> _categoryStack;
|
||||
std::array<CategoryStackEntry, 8> _categoryStack;
|
||||
};
|
||||
|
||||
@@ -175,8 +175,9 @@ bool CheatsBottomSheetView::HandleInput(const InputProvider& inputProvider, Focu
|
||||
void CheatsBottomSheetView::UpdateCheatList()
|
||||
{
|
||||
auto oldAdapter = _cheatsAdapter;
|
||||
_cheatsAdapter = new CheatsAdapter(_viewModel->GetCurrentCheatCategory(), _materialColorScheme, _fontRepository, _vramOffsets);
|
||||
_cheatListRecycler->SetAdapter(_cheatsAdapter);
|
||||
_cheatsAdapter = new CheatsAdapter(
|
||||
_viewModel->GetCurrentCheatCategory(), _materialColorScheme, _fontRepository, _vramOffsets);
|
||||
_cheatListRecycler->SetAdapter(_cheatsAdapter, _viewModel->GetSelectedItem());
|
||||
delete oldAdapter;
|
||||
|
||||
// Ugly hack
|
||||
|
||||
Reference in New Issue
Block a user