More progress.

This commit is contained in:
Steven Cherry 2013-08-22 19:46:30 -05:00
parent 761186ec4c
commit edcde85cee
5 changed files with 95 additions and 11 deletions

View file

@ -8,12 +8,9 @@
#include "Core/Config.h"
const static std::string CHEATS_DIR = "cheats";
static std::string activeCheatFile;
static int CheatEvent = -1;
std::string gameTitle;
static CWCheatEngine *cheatEngine;
void hleCheat(u64 userdata, int cyclesLate);
void trim2(std::string& str);
@ -23,7 +20,7 @@ void __CheatInit() {
// Cheats aren't working on Android yet - need to figure out the directory structure
#ifndef ANDROID
gameTitle = g_paramSFO.GetValueString("DISC_ID");
activeCheatFile = CHEATS_DIR + "/" + gameTitle +".ini";
activeCheatFile = CHEATS_DIR + "/" + gameTitle + ".ini";
File::CreateFullPath(CHEATS_DIR);
if (g_Config.bEnableCheats) {
@ -60,6 +57,7 @@ void hleCheat(u64 userdata, int cyclesLate) {
g_Config.bReloadCheats = false;
}
if (g_Config.bEnableCheats) {
cheatEngine->Run();
}
}

View file

@ -11,7 +11,7 @@
void __CheatInit();
void __CheatShutdown();
static std::string activeCheatFile;
std::vector<std::string> makeCodeParts(std::vector<std::string> CodesList);
class CWCheatEngine {
@ -24,7 +24,9 @@ public:
void Exit();
void Run();
std::vector<int> GetNextCode();
static std::string gActiveCheatFile;
void ActiveFileCopy();
private:
void SkipCodes(int count);

View file

@ -50,20 +50,20 @@
#include "UI/GameInfoCache.h"
#include "UI/MiscScreens.h"
#include "UI/CwCheatScreen.h"
#include "UI/view.h"
extern void DrawBackground(float alpha);
static CWCheatEngine *cheatEngine2;
std::vector<std::string> CwCheatScreen::CreateCodeList() {
std::vector<std::string> cheatList, formattedList;
cheatEngine2 = new CWCheatEngine();
cheatList = cheatEngine2->GetCodesList();
for (size_t i = 0; i < cheatList.size(); i++) {
if (cheatList[i].substr(0, 3) == "_C1") {
formattedList.push_back(cheatList[i].substr(3));
enableCheat[i] = true;
locations.push_back(i);
}
if (cheatList[i].substr(0, 3) == "_C0") {
formattedList.push_back(cheatList[i].substr(3));
@ -94,10 +94,50 @@ void CwCheatScreen::CreateViews() {
root_->Add(rightScroll);
rightColumn->Add(new ItemHeader(k->T("Cheats")));
for (size_t i = 0; i < formattedList.size(); i++) {
const char * name = formattedList[i].c_str();
rightColumn->Add(new CheckBox(&enableCheat[i], k->T(name)))->OnClick.Handle(this, &CwCheatScreen::OnCheckBox);;
name = formattedList[i].c_str();
rightColumn->Add(new CheatCheckBox(&enableCheat[i], k->T(name)))->OnClick.Handle(this, &CwCheatScreen::OnCheckBox);
}
}
UI::EventReturn CwCheatScreen::OnCheckBox(UI::EventParams &params) {
return UI::EVENT_DONE;
}
void CwCheatScreen::processFileOn(std::string activatedCheat) {
//visible test
//bool check;
//LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
//rightColumn->Add(new CheatCheckBox(&check, "name"));
is.open(activeCheatFile.c_str());
for (int i = 0; i < cheatList.size(); i++) {
if (cheatList[i].substr(4) == activatedCheat) {
cheatList[i] = "_C1 " + activatedCheat;
}
}
is.close();
os.open(activeCheatFile.c_str());
for (int j = 0; j < cheatList.size(); j++) {
os << cheatList[j];
}
os.close();
}
void CwCheatScreen::processFileOff(std::string deactivatedString) {
is.open(activeCheatFile.c_str());
}
void CheatCheckBox::Draw(UIContext &dc) {
ClickableItem::Draw(dc);
int paddingX = 12;
int paddingY = 8;
int image = *toggle_ ? dc.theme->checkOn : dc.theme->checkOff;
Style style = dc.theme->itemStyle;
if (!IsEnabled())
style = dc.theme->itemDisabledStyle;
dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER);
dc.Draw()->DrawImage(image, bounds_.x2() - paddingX, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER);
}

View file

@ -18,18 +18,60 @@
#include "base/functional.h"
#include "ui/view.h"
#include "ui/ui_screen.h"
#include "ui/ui_context.h"
#include "../Core/CwCheat.h"
#include "UI/MiscScreens.h"
using namespace UI;
class CwCheatScreen : public UIDialogScreenWithBackground {
public:
CwCheatScreen() {}
std::vector<std::string> CreateCodeList();
std::ifstream is;
std::ofstream os;
void processFileOn(std::string activatedCheat);
void processFileOff(std::string deactivatedCheat);
const char * name;
std::string activatedCheat, deactivatedCheat;
protected:
virtual void CreateViews();
private:
UI::EventReturn OnCheckBox(UI::EventParams &params);
bool enableCheat [64];
std::vector<std::string> cheatList, formattedList;
std::vector<int> locations;
};
class CheatCheckBox : public ClickableItem, public CwCheatScreen {
public:
CheatCheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0)
: ClickableItem(layoutParams), toggle_(toggle), text_(text) {
OnClick.Handle(this, &CheatCheckBox::OnClicked);
}
virtual void Draw(UIContext &dc);
EventReturn OnClicked(EventParams &e) {
if (toggle_) {
*toggle_ = !(*toggle_);
}
if (*toggle_ == true)
{
activatedCheat = text_;
processFileOn(activatedCheat);
}
if (*toggle_ == false)
{
deactivatedCheat = text_;
processFileOff(deactivatedCheat);
}
return EVENT_DONE;
}
private:
bool *toggle_;
std::string text_;
std::string smallText_;
};

View file

@ -686,7 +686,9 @@ void GamePauseScreen::CreateViews() {
rightColumnItems->Add(new Choice(i->T("Continue")))->OnClick.Handle(this, &GamePauseScreen::OnContinue);
rightColumnItems->Add(new Choice(i->T("Game Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings);
rightColumnItems->Add(new Choice(i->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat);
if (g_Config.bEnableCheats) {
rightColumnItems->Add(new Choice(i->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat);
}
rightColumnItems->Add(new Choice(i->T("Exit to menu")))->OnClick.Handle(this, &GamePauseScreen::OnExitToMenu);
UI::EventParams e;