Add cheat documentation, enable input repeat for L and R, show cheat category name

This commit is contained in:
Gericom
2026-03-08 13:03:26 +01:00
parent 43b1bf7afa
commit 6c34d9324d
22 changed files with 189 additions and 67 deletions

View File

@@ -7,6 +7,7 @@
class MaterialColorScheme;
class IFontRepository;
/// @brief List item view for the cheats panel, representing a single cheat or cheat category.
class CheatListItemView : public ViewContainer
{
public:

View File

@@ -4,6 +4,7 @@
#include "cheats/Cheat.h"
#include "CheatListItemView.h"
/// @brief Recycler adapter for cheats.
class CheatsAdapter : public RecyclerAdapter
{
public:

View File

@@ -16,6 +16,9 @@
#define TITLE_LABEL_X 20
#define TITLE_LABEL_Y 16
#define CATEGORY_NAME_LABEL_X (TITLE_LABEL_X + 43)
#define CATEGORY_NAME_LABEL_Y (TITLE_LABEL_Y + 1)
#define NO_CHEATS_FOUND_LABEL_X 20
#define NO_CHEATS_FOUND_LABEL_Y 36
@@ -32,7 +35,7 @@ CheatsBottomSheetView::CheatsBottomSheetView(std::unique_ptr<CheatsViewModel> vi
FocusManager* focusManager)
: _viewModel(std::move(viewModel))
, _titleLabel(64, 16, 25, fontRepository->GetFont(FontType::Medium11))
, _noCheatsFoundLabel(96, 16, 25, fontRepository->GetFont(FontType::Regular10))
, _secondaryLabel(177, 16, 64, fontRepository->GetFont(FontType::Regular10))
, _descriptionLabel(224, 16, 256, fontRepository->GetFont(FontType::Medium7_5))
, _cheatListRecycler(std::make_unique<RecyclerView>(
LIST_X, LIST_Y, LIST_WIDTH, LIST_HEIGHT, RecyclerView::Mode::VerticalList))
@@ -41,11 +44,12 @@ CheatsBottomSheetView::CheatsBottomSheetView(std::unique_ptr<CheatsViewModel> vi
, _focusManager(focusManager)
{
_titleLabel.SetText(u"Cheats");
_noCheatsFoundLabel.SetText(u"No cheats found.");
_secondaryLabel.SetText(u"No cheats found.");
_secondaryLabel.SetEllipsisStyle(LabelView::EllipsisStyle::Ellipsis);
_descriptionLabel.SetEllipsisStyle(LabelView::EllipsisStyle::Marquee);
_descriptionLabel.SetText("");
AddChildTail(&_titleLabel);
AddChildTail(&_noCheatsFoundLabel);
AddChildTail(&_secondaryLabel);
AddChildTail(&_descriptionLabel);
AddChildTail(_cheatListRecycler.get());
}
@@ -80,7 +84,14 @@ void CheatsBottomSheetView::InitVram(const VramContext& vramContext)
void CheatsBottomSheetView::Update()
{
_titleLabel.SetPosition(TITLE_LABEL_X, _position.y + TITLE_LABEL_Y);
_noCheatsFoundLabel.SetPosition(NO_CHEATS_FOUND_LABEL_X, _position.y + NO_CHEATS_FOUND_LABEL_Y);
if (_viewModel->GetState() == CheatsViewModel::State::DisplayCheats)
{
_secondaryLabel.SetPosition(CATEGORY_NAME_LABEL_X, _position.y + CATEGORY_NAME_LABEL_Y);
}
else
{
_secondaryLabel.SetPosition(NO_CHEATS_FOUND_LABEL_X, _position.y + NO_CHEATS_FOUND_LABEL_Y);
}
_descriptionLabel.SetPosition(DESCRIPTION_LABEL_X, _position.y + DESCRIPTION_LABEL_Y);
_cheatListRecycler->SetPosition(LIST_X, _position.y + LIST_Y);
if (_viewModel->GetState() == CheatsViewModel::State::DisplayCheats)
@@ -168,11 +179,12 @@ void CheatsBottomSheetView::Draw(GraphicsContext& graphicsContext)
_titleLabel.SetForegroundColor(_materialColorScheme->onSurface);
_titleLabel.Draw(graphicsContext);
if (_viewModel->GetState() == CheatsViewModel::State::NoCheats)
if (_viewModel->GetState() == CheatsViewModel::State::NoCheats ||
_viewModel->ShouldShowCategoryName())
{
_noCheatsFoundLabel.SetBackgroundColor(backColor);
_noCheatsFoundLabel.SetForegroundColor(_materialColorScheme->onSurface);
_noCheatsFoundLabel.Draw(graphicsContext);
_secondaryLabel.SetBackgroundColor(backColor);
_secondaryLabel.SetForegroundColor(_materialColorScheme->onSurfaceVariant);
_secondaryLabel.Draw(graphicsContext);
}
_descriptionLabel.SetBackgroundColor(backColor);
@@ -190,9 +202,10 @@ bool CheatsBottomSheetView::HandleInput(const InputProvider& inputProvider, Focu
if (focusManager.IsFocusInside(_cheatListRecycler.get()))
{
auto oldCategory = _viewModel->GetCurrentCheatCategory();
_viewModel->ItemActivated();
_viewModel->ActivateSelectedItem();
if (oldCategory != _viewModel->GetCurrentCheatCategory())
{
_secondaryLabel.SetText(_viewModel->GetCurrentCheatCategory()->GetName());
UpdateCheatList();
}
@@ -202,8 +215,8 @@ bool CheatsBottomSheetView::HandleInput(const InputProvider& inputProvider, Focu
else if (inputProvider.Triggered(InputKey::B))
{
auto oldCategory = _viewModel->GetCurrentCheatCategory();
_viewModel->Back();
if (oldCategory != _viewModel->GetCurrentCheatCategory())
if (_viewModel->NavigateUp() &&
oldCategory != _viewModel->GetCurrentCheatCategory())
{
UpdateCheatList();
}

View File

@@ -11,6 +11,7 @@ class MaterialColorScheme;
class IFontRepository;
class IVramManager;
/// @brief Bottom sheet for browsing and enabling/disabling cheats.
class CheatsBottomSheetView : public BottomSheetView
{
public:
@@ -40,7 +41,7 @@ public:
private:
std::unique_ptr<CheatsViewModel> _viewModel;
Label2DView _titleLabel;
Label2DView _noCheatsFoundLabel;
Label2DView _secondaryLabel;
Label2DView _descriptionLabel;
std::unique_ptr<RecyclerView> _cheatListRecycler;
CheatsAdapter* _cheatsAdapter = nullptr;