Implement type-to-search in cheats dialog

This commit is contained in:
Henrik Rydgård committed 2026-05-03 18:08:00 +02:00
1 parent 2d90058421
commit f02624ba32
4 files changed
+47 -5

No files matched your search

+29 -3
View File
@@ -86,6 +86,15 @@ void CwCheatScreen::BeforeCreateViews() {
TryLoadCheatInfo(); // in case the info is already in cache.
}
bool CwCheatScreen::key(const KeyInput &input) {
if (search_.Key(cheatList_, input)) {
// This will eat up the ESC key, which is used to cancel searches.
return true;
}
return UITwoPaneBaseDialogScreen::key(input);
}
void CwCheatScreen::CreateSettingsViews(UI::ViewGroup *leftColumn) {
using namespace UI;
auto cw = GetI18NCategory(I18NCat::CWCHEATS);
@@ -118,7 +127,11 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) {
auto di = GetI18NCategory(I18NCat::DIALOG);
auto mm = GetI18NCategory(I18NCat::MAINMENU);
UI::ScrollView *rightScroll = parent->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f)));
UI::LinearLayout *rightSide = parent->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f)));
search_.searchFilter.clear();
search_.searchBar = rightSide->Add(new SearchBar(new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
UI::ScrollView *rightScroll = rightSide->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)));
rightScroll->SetTag("CwCheats");
rightScroll->RememberPosition(&g_Config.fCwCheatScrollPosition);
@@ -126,6 +139,8 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) {
rightColumn->SetSpacing(0.0f);
rightScroll->Add(rightColumn);
cheatList_ = rightColumn;
if (!errorMessage_.empty()) {
rightColumn->Add(new NoticeView(errorLevel_, errorMessage_, errorDetails_));
rightColumn->Add(new Spacer(8.0f));
@@ -134,6 +149,7 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) {
rightColumn->Add(new ItemHeader(cw->T("Cheats")));
bool prevIsTitle = false;
View *prev = nullptr;
for (size_t i = 0; i < fileInfo_.size(); ++i) {
std::string_view text;
if (fileInfo_[i].IsTitle(&text)) {
@@ -141,17 +157,20 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) {
TextView *titleView = rightColumn->Add(new TextView(text, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, UI::Margins(8, 8, 8, 0))));
titleView->SetTextSize(UI::TextSize::Big);
prevIsTitle = true;
prev = nullptr;
} else if (fileInfo_[i].IsPostComment(&text)) {
rightColumn->Add(new SettingHint(text, nullptr));
rightColumn->Add(new SettingHint(text, prev));
prevIsTitle = false;
} else {
// Regular cheat code.
if (!prevIsTitle) {
rightColumn->Add(new Spacer(8.0f));
}
rightColumn->Add(new CheckBox(&fileInfo_[i].enabled, fileInfo_[i].name))->OnClick.Add([=](UI::EventParams &) {
CheckBox *checkBox = rightColumn->Add(new CheckBox(&fileInfo_[i].enabled, fileInfo_[i].name));
checkBox->OnClick.Add([=](UI::EventParams &) {
OnCheckBox((int)i);
});
prev = checkBox;
prevIsTitle = false;
}
}
@@ -456,6 +475,13 @@ bool CwCheatScreen::RebuildCheatFile(int index) {
}
fclose(out);
// Don't force an auto-reload, though.
std::string str;
if (File::ReadTextFileToString(engine_->CheatFilename(), &str)) {
uint64_t newHash = XXH3_64bits(str.c_str(), str.size());
fileCheckHash_ = newHash;
}
// Cheats will need to be reparsed now.
g_Config.bReloadCheats = true;
return true;