Merge pull request #90 from gizmo98/patch-2
[libretro-ppsspp.git] / UI / CwCheatScreen.h
blobd08e6e160fd11e748abc128f43f5d7527f89132b
1 // Copyright (c) 2013- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18 #include <deque>
19 #include "Common/FileUtil.h"
21 #include "base/functional.h"
22 #include "ui/view.h"
23 #include "ui/ui_screen.h"
24 #include "ui/ui_context.h"
25 #include "../Core/CwCheat.h"
26 #include "UI/MiscScreens.h"
27 #include "UI/GameSettingsScreen.h"
29 extern std::string activeCheatFile;
30 extern std::string gameTitle;
32 class CwCheatScreen : public UIDialogScreenWithBackground {
33 public:
34 CwCheatScreen() {}
35 void CreateCodeList();
36 void processFileOn(std::string activatedCheat);
37 void processFileOff(std::string deactivatedCheat);
38 const char * name;
39 std::string activatedCheat, deactivatedCheat;
40 UI::EventReturn OnBack(UI::EventParams &params);
41 UI::EventReturn OnAddCheat(UI::EventParams &params);
42 UI::EventReturn OnImportCheat(UI::EventParams &params);
43 UI::EventReturn OnEditCheatFile(UI::EventParams &params);
44 UI::EventReturn OnEnableAll(UI::EventParams &params);
46 virtual void onFinish(DialogResult result);
47 protected:
48 virtual void CreateViews();
50 private:
51 UI::EventReturn OnCheckBox(UI::EventParams &params);
52 std::vector<std::string> formattedList_;
53 bool anythingChanged_;
56 // TODO: Instead just hook the OnClick event on a regular checkbox.
57 class CheatCheckBox : public UI::ClickableItem, public CwCheatScreen {
58 public:
59 CheatCheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", UI::LayoutParams *layoutParams = 0)
60 : UI::ClickableItem(layoutParams), toggle_(toggle), text_(text) {
61 OnClick.Handle(this, &CheatCheckBox::OnClicked);
64 virtual void Draw(UIContext &dc);
66 UI::EventReturn OnClicked(UI::EventParams &e) {
67 bool temp = false;
68 if (toggle_) {
69 *toggle_ = !(*toggle_);
70 temp = *toggle_;
72 if (temp) {
73 activatedCheat = text_;
74 processFileOn(activatedCheat);
75 } else {
76 deactivatedCheat = text_;
77 processFileOff(deactivatedCheat);
79 return UI::EVENT_DONE;
82 private:
83 bool *toggle_;
84 std::string text_;
85 std::string smallText_;