mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Improve cheats UX
This commit is contained in:
parent
8804c3c69f
commit
ac66deeb25
3 changed files with 63 additions and 19 deletions
|
@ -741,10 +741,10 @@ protected:
|
|||
std::string smallText_;
|
||||
ImageID image_; // Centered if no text, on the left if text.
|
||||
ImageID rightIconImage_ = ImageID::invalid(); // Shows in the right.
|
||||
float rightIconScale_;
|
||||
float rightIconRot_;
|
||||
bool rightIconFlipH_;
|
||||
bool rightIconKeepColor_;
|
||||
float rightIconScale_ = 0.0f;
|
||||
float rightIconRot_ = 0.0f;
|
||||
bool rightIconFlipH_ = false;
|
||||
bool rightIconKeepColor_ = false;
|
||||
Padding textPadding_;
|
||||
bool centered_ = false;
|
||||
float imgScale_ = 1.0f;
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
|
||||
static const int FILE_CHECK_FRAME_INTERVAL = 53;
|
||||
|
||||
static Path GetGlobalCheatFile() {
|
||||
return GetSysDirectory(DIRECTORY_CHEATS) / "cheat.db";
|
||||
}
|
||||
|
||||
CwCheatScreen::CwCheatScreen(const Path &gamePath)
|
||||
: UIDialogScreenWithGameBackground(gamePath) {
|
||||
}
|
||||
|
@ -53,7 +57,7 @@ void CwCheatScreen::LoadCheatInfo() {
|
|||
gameID = g_paramSFO.GenerateFakeID(gamePath_.ToString());
|
||||
}
|
||||
|
||||
if (engine_ == nullptr || gameID != gameID_) {
|
||||
if (!engine_ || gameID != gameID_) {
|
||||
gameID_ = gameID;
|
||||
delete engine_;
|
||||
engine_ = new CWCheatEngine(gameID_);
|
||||
|
@ -77,6 +81,7 @@ void CwCheatScreen::CreateViews() {
|
|||
using namespace UI;
|
||||
auto cw = GetI18NCategory("CwCheats");
|
||||
auto di = GetI18NCategory("Dialog");
|
||||
auto mm = GetI18NCategory("MainMenu");
|
||||
|
||||
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
||||
|
||||
|
@ -84,9 +89,15 @@ void CwCheatScreen::CreateViews() {
|
|||
Margins actionMenuMargins(50, -15, 15, 0);
|
||||
|
||||
LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(400, FILL_PARENT));
|
||||
leftColumn->Add(new ItemHeader(cw->T("Options")));
|
||||
//leftColumn->Add(new Choice(cw->T("Add Cheat")))->OnClick.Handle(this, &CwCheatScreen::OnAddCheat);
|
||||
leftColumn->Add(new Choice(cw->T("Import Cheats")))->OnClick.Handle(this, &CwCheatScreen::OnImportCheat);
|
||||
leftColumn->Add(new ItemHeader(cw->T("Import Cheats")));
|
||||
|
||||
Path cheatPath = GetGlobalCheatFile();
|
||||
|
||||
leftColumn->Add(new Choice(cheatPath.ToVisualString()))->OnClick.Handle(this, &CwCheatScreen::OnImportCheat);
|
||||
leftColumn->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN")))->OnClick.Handle(this, &CwCheatScreen::OnImportBrowse);
|
||||
|
||||
leftColumn->Add(new ItemHeader(cw->T("Options")));
|
||||
#if !defined(MOBILE_DEVICE)
|
||||
leftColumn->Add(new Choice(cw->T("Edit Cheat File")))->OnClick.Handle(this, &CwCheatScreen::OnEditCheatFile);
|
||||
#endif
|
||||
|
@ -141,6 +152,21 @@ void CwCheatScreen::onFinish(DialogResult result) {
|
|||
}
|
||||
}
|
||||
|
||||
void CwCheatScreen::sendMessage(const char *message, const char *value) {
|
||||
// Always call the base class method first to handle the most common messages.
|
||||
UIDialogScreenWithGameBackground::sendMessage(message, value);
|
||||
if (!strcmp(message, "browse_fileSelect")) {
|
||||
Path path(value);
|
||||
INFO_LOG(SYSTEM, "Attempting to load cheats from: '%s'", path.ToVisualString().c_str());
|
||||
if (ImportCheats(path)) {
|
||||
g_Config.bReloadCheats = true;
|
||||
} else {
|
||||
// Show an error message?
|
||||
}
|
||||
RecreateViews();
|
||||
}
|
||||
}
|
||||
|
||||
UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams ¶ms) {
|
||||
enableAllFlag_ = !enableAllFlag_;
|
||||
|
||||
|
@ -193,24 +219,39 @@ static char *GetLineNoNewline(char *temp, int sz, FILE *fp) {
|
|||
return line;
|
||||
}
|
||||
|
||||
UI::EventReturn CwCheatScreen::OnImportBrowse(UI::EventParams ¶ms) {
|
||||
System_SendMessage("browse_file", "");
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams ¶ms) {
|
||||
if (gameID_.length() != 9 || !engine_) {
|
||||
WARN_LOG(COMMON, "CWCHEAT: Incorrect ID(%s) - can't import cheats.", gameID_.c_str());
|
||||
if (!ImportCheats(GetGlobalCheatFile())) {
|
||||
// Show an error message?
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
std::vector<std::string> title;
|
||||
std::vector<std::string> newList;
|
||||
|
||||
Path cheatFile = GetSysDirectory(DIRECTORY_CHEATS) / "cheat.db";
|
||||
g_Config.bReloadCheats = true;
|
||||
RecreateViews();
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
bool CwCheatScreen::ImportCheats(const Path & cheatFile) {
|
||||
if (gameID_.length() != 9 || !engine_) {
|
||||
WARN_LOG(COMMON, "CWCHEAT: Incorrect ID(%s) - can't import cheats.", gameID_.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string gameID = StringFromFormat("_S %s-%s", gameID_.substr(0, 4).c_str(), gameID_.substr(4).c_str());
|
||||
|
||||
FILE *in = File::OpenCFile(cheatFile, "rt");
|
||||
|
||||
if (!in) {
|
||||
WARN_LOG(COMMON, "Unable to open %s\n", cheatFile.c_str());
|
||||
return UI::EVENT_SKIPPED;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> title;
|
||||
std::vector<std::string> newList;
|
||||
|
||||
char linebuf[2048]{};
|
||||
bool parseGameEntry = false;
|
||||
bool parseCheatEntry = false;
|
||||
|
@ -281,10 +322,7 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams ¶ms) {
|
|||
}
|
||||
}
|
||||
fclose(append);
|
||||
|
||||
g_Config.bReloadCheats = true;
|
||||
RecreateViews();
|
||||
return UI::EVENT_DONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
UI::EventReturn CwCheatScreen::OnCheckBox(int index) {
|
||||
|
|
|
@ -35,9 +35,12 @@ public:
|
|||
|
||||
UI::EventReturn OnAddCheat(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnImportCheat(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnImportBrowse(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnEditCheatFile(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnEnableAll(UI::EventParams ¶ms);
|
||||
|
||||
void sendMessage(const char *message, const char *value) override;
|
||||
|
||||
void update() override;
|
||||
void onFinish(DialogResult result) override;
|
||||
|
||||
|
@ -48,16 +51,19 @@ protected:
|
|||
|
||||
private:
|
||||
UI::EventReturn OnCheckBox(int index);
|
||||
bool ImportCheats(const Path &cheatFile);
|
||||
|
||||
enum { INDEX_ALL = -1 };
|
||||
bool HasCheatWithName(const std::string &name);
|
||||
bool RebuildCheatFile(int index);
|
||||
|
||||
UI::ScrollView *rightScroll_ = nullptr;
|
||||
UI::TextView *errorMessageView_ = nullptr;
|
||||
|
||||
CWCheatEngine *engine_ = nullptr;
|
||||
std::vector<CheatFileInfo> fileInfo_;
|
||||
std::string gameID_;
|
||||
int fileCheckCounter_ = 0;
|
||||
uint64_t fileCheckHash_;
|
||||
uint64_t fileCheckHash_ = 0;
|
||||
bool enableAllFlag_ = false;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue