mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Implement cheat search on mobile
This commit is contained in:
1 parent
691c1f3251
commit
71d04bfcae
5 files changed
+47
-5
No files matched your search
@@ -332,12 +332,12 @@ void PopupCallbackScreen::CreatePopupContents(ViewGroup *parent) {
|
||||
AlignPopup(parent);
|
||||
}
|
||||
|
||||
std::string ChopTitle(const std::string &title) {
|
||||
static std::string ChopTitle(std::string_view title) {
|
||||
size_t pos = title.find('\n');
|
||||
if (pos != title.npos) {
|
||||
return title.substr(0, pos);
|
||||
return std::string(title.substr(0, pos));
|
||||
}
|
||||
return title;
|
||||
return std::string(title);
|
||||
}
|
||||
|
||||
PopupMultiChoice::PopupMultiChoice(int *value, std::string_view text, const char **choices, int minVal, int numChoices,
|
||||
@@ -785,6 +785,31 @@ void SliderFloatPopupScreen::OnCompleted(DialogResult result) {
|
||||
}
|
||||
}
|
||||
|
||||
// General utility, if you don't want to use a choice with a string.
|
||||
void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *sourceView, std::string_view title, std::function<void(const std::string &, bool)> callback) {
|
||||
// Choose method depending on platform capabilities.
|
||||
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) {
|
||||
System_InputBoxGetString(token, title, "", false, [callback](const std::string &enteredValue, int) {
|
||||
callback(SanitizeString(StripSpaces(enteredValue), StringRestriction::None, 0, 0), true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
TextEditPopupScreen *popupScreen = new TextEditPopupScreen(nullptr, "", ChopTitle(title), -1);
|
||||
if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) {
|
||||
popupScreen->SetAlignTop(true);
|
||||
}
|
||||
popupScreen->OnChange.Add([callback, sourceView](EventParams &e) {
|
||||
callback(SanitizeString(StripSpaces(*(std::string *)e.v), StringRestriction::None, 0, 0), true);
|
||||
if (sourceView) {
|
||||
SetFocusedView(sourceView);
|
||||
}
|
||||
});
|
||||
if (sourceView)
|
||||
popupScreen->SetPopupOrigin(sourceView);
|
||||
screenManager->push(popupScreen);
|
||||
}
|
||||
|
||||
PopupTextInputChoice::PopupTextInputChoice(RequesterToken token, std::string *value, std::string_view title, std::string_view placeholder, int maxLen, ScreenManager *screenManager, LayoutParams *layoutParams)
|
||||
: AbstractChoiceWithValueDisplay(title, layoutParams), screenManager_(screenManager), value_(value), placeHolder_(placeholder), maxLen_(maxLen), token_(token), restriction_(StringRestriction::None) {
|
||||
OnClick.Handle(this, &PopupTextInputChoice::HandleClick);
|
||||
|
||||
@@ -545,6 +545,8 @@ private:
|
||||
StringRestriction restriction_;
|
||||
};
|
||||
|
||||
void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *sourceView, std::string_view title, std::function<void(const std::string &, bool)> callback);
|
||||
|
||||
class ChoiceWithValueDisplay : public AbstractChoiceWithValueDisplay {
|
||||
public:
|
||||
ChoiceWithValueDisplay(int *value, std::string_view text, LayoutParams *layoutParams = 0)
|
||||
|
||||
@@ -114,6 +114,17 @@ void CwCheatScreen::CreateSettingsViews(UI::ViewGroup *leftColumn) {
|
||||
leftColumn->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN")))->OnClick.Handle(this, &CwCheatScreen::OnImportBrowse);
|
||||
|
||||
leftColumn->Add(new ItemHeader(di->T("Options")));
|
||||
Choice *searchChoice = leftColumn->Add(new Choice(di->T("Search"), ImageID("I_SEARCH")));
|
||||
searchChoice->OnClick.Add([this, searchChoice, screenManager = screenManager(), token = GetRequesterToken()](UI::EventParams &) {
|
||||
auto di = GetI18NCategory(I18NCat::DIALOG);
|
||||
AskForInput(screenManager, token, searchChoice, di->T("Search"), [this](const std::string &text, bool success) {
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
search_.searchFilter = text;
|
||||
search_.ApplySearchFilter(cheatList_, false);
|
||||
});
|
||||
});
|
||||
#if !defined(MOBILE_DEVICE)
|
||||
leftColumn->Add(new Choice(cw->T("Edit Cheat File")))->OnClick.Handle(this, &CwCheatScreen::OnEditCheatFile);
|
||||
#endif
|
||||
@@ -130,6 +141,10 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) {
|
||||
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)));
|
||||
search_.searchBar->OnCancel.Add([this](UI::EventParams &) {
|
||||
search_.searchFilter.clear();
|
||||
search_.ApplySearchFilter(cheatList_, false);
|
||||
});
|
||||
|
||||
UI::ScrollView *rightScroll = rightSide->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)));
|
||||
rightScroll->SetTag("CwCheats");
|
||||
|
||||
+1
-1
@@ -489,7 +489,7 @@ public:
|
||||
pinned_ = pin;
|
||||
}
|
||||
|
||||
std::string DescribeText() const {
|
||||
std::string DescribeText() const override {
|
||||
return std::string(Button::GetText()); // From Button
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -427,8 +427,8 @@ void ViewSearch::ApplySearchFilter(UI::ViewGroup *viewGroup, bool setKeyboardFoc
|
||||
if (firstMatch) {
|
||||
if (setKeyboardFocus) {
|
||||
UI::EnableFocusMovement(true);
|
||||
UI::SetFocusedView(firstMatch);
|
||||
}
|
||||
UI::SetFocusedView(firstMatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user