2009-06-24 09:33:31 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-10-01 20:53:38 +02:00
|
|
|
#include <fat.h>
|
2009-06-24 09:33:31 +02:00
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
#include "libwiigui/gui_customoptionbrowser.h"
|
|
|
|
#include "prompts/PromptWindows.h"
|
|
|
|
#include "language/gettext.h"
|
2010-09-24 19:58:56 +02:00
|
|
|
#include "themes/CTheme.h"
|
2010-09-25 08:54:27 +02:00
|
|
|
#include "FileOperations/fileops.h"
|
2009-06-24 09:33:31 +02:00
|
|
|
#include "menu.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "gct.h"
|
2010-01-19 11:48:50 +01:00
|
|
|
|
2009-06-24 09:33:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* CheatMenu
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
int CheatMenu(const char * gameID)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
int choice = 0;
|
|
|
|
bool exit = false;
|
|
|
|
int ret = 1;
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
|
|
|
GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage settingsbackground(&settingsbg);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
GuiTrigger trigA;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
2010-09-19 01:16:05 +02:00
|
|
|
GuiTrigger trigB;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
|
|
|
GuiImage backBtnImg(&btnOutline);
|
2010-11-13 23:34:53 +01:00
|
|
|
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1);
|
2010-09-24 02:48:03 +02:00
|
|
|
backBtn.SetLabel(&backBtnTxt);
|
|
|
|
backBtn.SetTrigger(&trigB);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
|
|
|
|
GuiImage createBtnImg(&btnOutline);
|
2010-11-13 23:34:53 +01:00
|
|
|
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1);
|
2010-09-24 02:48:03 +02:00
|
|
|
createBtn.SetLabel(&createBtnTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
char txtfilename[55];
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
GCTCheats c;
|
2010-09-24 02:48:03 +02:00
|
|
|
int check = c.openTxtfile(txtfilename);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
int download = 0;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (check)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case -1:
|
2010-09-24 02:48:03 +02:00
|
|
|
WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" ));
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
2010-09-24 02:48:03 +02:00
|
|
|
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
|
|
|
|
if (download == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
download = CodeDownload(gameID);
|
|
|
|
if (download < 0 || c.openTxtfile(txtfilename) != 1) break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else break;
|
2010-09-19 01:16:05 +02:00
|
|
|
case 1:
|
|
|
|
int cntcheats = c.getCnt();
|
2010-10-31 10:30:53 +01:00
|
|
|
OptionList cheatslst;
|
2010-11-14 16:19:42 +01:00
|
|
|
GuiCustomOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
chtBrowser.SetPosition(0, 90);
|
|
|
|
chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
chtBrowser.SetClickable(true);
|
|
|
|
|
2010-10-31 10:30:53 +01:00
|
|
|
GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
|
2010-09-24 02:48:03 +02:00
|
|
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
|
|
|
|
titleTxt.SetPosition(12, 40);
|
|
|
|
|
2010-12-31 17:18:48 +01:00
|
|
|
for (int i = 0; i < cntcheats; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str());
|
|
|
|
cheatslst.SetName(i, "OFF");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiWindow w(screenwidth, screenheight);
|
|
|
|
w.Append(&settingsbackground);
|
|
|
|
w.Append(&titleTxt);
|
|
|
|
w.Append(&backBtn);
|
|
|
|
w.Append(&createBtn);
|
|
|
|
w.Append(&chtBrowser);
|
|
|
|
mainWindow->SetState(STATE_DISABLED);
|
|
|
|
mainWindow->ChangeFocus(&w);
|
|
|
|
mainWindow->Append(&w);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (!exit)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
VIDEO_WaitVSync();
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
ret = chtBrowser.GetClickedOption();
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret != -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
const char *strCheck = cheatslst.GetName(ret);
|
|
|
|
if (strncmp(strCheck, "ON", 2) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
cheatslst.SetName(ret, "%s", "OFF");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (strncmp(strCheck, "OFF", 3) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
cheatslst.SetName(ret, "%s", "ON");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (createBtn.GetState() == STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
createBtn.ResetState();
|
2010-09-24 02:48:03 +02:00
|
|
|
if (cntcheats > 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
int selectednrs[30];
|
|
|
|
int x = 0;
|
2010-12-31 17:18:48 +01:00
|
|
|
for (int i = 0; i < cntcheats; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
const char *strCheck = cheatslst.GetName(i);
|
|
|
|
if (strncmp(strCheck, "ON", 2) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
selectednrs[x] = i;
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (x == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" ));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-25 08:54:27 +02:00
|
|
|
CreateSubfolder(Settings.Cheatcodespath);
|
2010-09-19 01:16:05 +02:00
|
|
|
string chtpath = Settings.Cheatcodespath;
|
|
|
|
string gctfname = chtpath + c.getGameID() + ".gct";
|
2010-09-24 02:48:03 +02:00
|
|
|
c.createGCT(selectednrs, x, gctfname.c_str());
|
|
|
|
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
|
2010-09-19 01:16:05 +02:00
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (backBtn.GetState() == STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
backBtn.ResetState();
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->SetState(STATE_DEFAULT);
|
|
|
|
mainWindow->Remove(&w);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return choice;
|
2009-06-24 09:33:31 +02:00
|
|
|
}
|