mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-01 02:03:47 +01:00
Implement type-to-search in cheats dialog
This commit is contained in:
1 parent
2d90058421
commit
f02624ba32
4 files changed
+47
-5
No files matched your search
+29
-3
@@ -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;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Common/UI/Context.h"
|
||||
#include "UI/BaseScreens.h"
|
||||
#include "UI/SimpleDialogScreen.h"
|
||||
#include "UI/MiscViews.h"
|
||||
|
||||
struct CheatFileInfo;
|
||||
class CWCheatEngine;
|
||||
@@ -44,6 +45,7 @@ public:
|
||||
void OnDisableAll(UI::EventParams ¶ms);
|
||||
|
||||
void update() override;
|
||||
bool key(const KeyInput &input) override;
|
||||
void onFinish(DialogResult result) override;
|
||||
|
||||
const char *tag() const override { return "CwCheat"; }
|
||||
@@ -73,4 +75,7 @@ private:
|
||||
std::string errorMessage_;
|
||||
NoticeLevel errorLevel_ = NoticeLevel::ERROR;
|
||||
std::string errorDetails_;
|
||||
|
||||
UI::ViewGroup *cheatList_ = nullptr;
|
||||
ViewSearch search_;
|
||||
};
|
||||
+12
-2
@@ -428,7 +428,7 @@ bool ViewSearch::Key(UI::ViewGroup *viewGroup, const KeyInput &input) {
|
||||
// Only one is visible at a time, so we can just grab all Char input.
|
||||
if (input.flags & KeyInputFlags::CHAR) {
|
||||
const int unichar = input.keyCode;
|
||||
if (unichar >= 0x20) {
|
||||
if (unichar >= 0x20 && unichar != 127) { // 127 gets produced from Ctrl+Backspace on Windows for some reason.
|
||||
// TODO: Save focus state here.
|
||||
|
||||
// Insert it! (todo: do it with a string insert)
|
||||
@@ -441,7 +441,17 @@ bool ViewSearch::Key(UI::ViewGroup *viewGroup, const KeyInput &input) {
|
||||
} else if (input.flags & KeyInputFlags::DOWN) {
|
||||
if (input.keyCode == NKCODE_DEL) {
|
||||
if (!searchFilter.empty()) {
|
||||
searchFilter.pop_back();
|
||||
if (input.flags & KeyInputFlags::MOD_CTRL) {
|
||||
// Ctrl+Backspace deletes the last word. Delete until the last space.
|
||||
size_t pos = searchFilter.find_last_of(' ');
|
||||
if (pos != searchFilter.npos) {
|
||||
searchFilter.erase(pos);
|
||||
} else {
|
||||
searchFilter.clear();
|
||||
}
|
||||
} else {
|
||||
searchFilter.pop_back();
|
||||
}
|
||||
ApplySearchFilter(viewGroup, true);
|
||||
retval = true;
|
||||
if (searchFilter.empty()) {
|
||||
|
||||
@@ -93,6 +93,7 @@ protected:
|
||||
class SettingHint : public UI::TextView {
|
||||
public:
|
||||
SettingHint(std::string_view text, UI::View *setting);
|
||||
std::string DescribeText() const override { return setting_ ? setting_->DescribeText() : ""; } // So that descriptions show up in searches under their parent views
|
||||
void Draw(UIContext &dc) override;
|
||||
private:
|
||||
UI::View *setting_;
|
||||
|
||||
Reference in new issue
Block a user