improvements to optionbrowser

This commit is contained in:
dborth 2009-07-27 22:23:55 +00:00
parent 3e79990a07
commit 05206863e1
3 changed files with 257 additions and 292 deletions

View File

@ -58,7 +58,7 @@ extern FreeTypeGX *fontSystem[];
#define PAGESIZE 8
#define SAVELISTSIZE 6
#define MAX_SAVES 20
#define MAX_OPTIONS 30
#define MAX_OPTIONS 150
#define MAX_KEYBOARD_DISPLAY 32
typedef void (*UpdateCallback)(void * e);
@ -800,11 +800,13 @@ class GuiOptionBrowser : public GuiElement
void ResetState();
void SetFocus(int f);
void Draw();
void TriggerUpdate();
void Update(GuiTrigger * t);
GuiText * optionVal[PAGESIZE];
protected:
int selectedItem;
int listOffset;
bool listChanged;
OptionList * options;
int optionIndex[PAGESIZE];

View File

@ -20,6 +20,7 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
options = l;
selectable = true;
listOffset = this->FindMenuItem(-1, 1);
listChanged = true; // trigger an initial list update
selectedItem = 0;
focus = 0; // allow focus
@ -76,7 +77,7 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
for(int i=0; i<PAGESIZE; i++)
{
optionTxt[i] = new GuiText(options->name[i], 22, (GXColor){0, 0, 0, 0xff});
optionTxt[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionTxt[i]->SetPosition(8,0);
@ -228,6 +229,11 @@ void GuiOptionBrowser::Draw()
this->UpdateEffects();
}
void GuiOptionBrowser::TriggerUpdate()
{
listChanged = true;
}
void GuiOptionBrowser::Update(GuiTrigger * t)
{
if(state == STATE_DISABLED || !t)
@ -240,6 +246,9 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
next = listOffset;
if(listChanged)
{
listChanged = false;
for(int i=0; i<PAGESIZE; i++)
{
if(next >= 0)
@ -260,7 +269,11 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
optionBtn[i]->SetVisible(false);
optionBtn[i]->SetState(STATE_DISABLED);
}
}
}
for(int i=0; i<PAGESIZE; i++)
{
if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
optionBtn[i]->ResetState();
else if(focus && i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
@ -292,6 +305,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
listChanged = true;
}
else if(optionBtn[selectedItem+1]->IsVisible())
{
@ -312,6 +326,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
{
// move list up by 1
listOffset = prev;
listChanged = true;
}
else
{

View File

@ -1965,95 +1965,6 @@ static int MenuGameSettings()
return menu;
}
/****************************************************************************
* MenuGameCheats
*
* Displays a list of cheats available, and allows the user to enable/disable
* them.
***************************************************************************/
/*static int MenuGameCheats()
{
int menu = MENU_NONE;
int ret;
u16 i = 0;
OptionList options;
for(i=0; i < Cheat.num_cheats; i++)
sprintf (options.name[i], "%s", Cheat.c[i].name);
options.length = i;
GuiText titleTxt("Cheats", 28, (GXColor){255, 255, 255, 255});
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
titleTxt.SetPosition(50,50);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
GuiSound btnSoundClick(button_click_pcm, button_click_pcm_size, SOUND_PCM);
GuiImageData btnOutline(button_png);
GuiImageData btnOutlineOver(button_over_png);
GuiTrigger trigA;
if(GCSettings.WiimoteOrientation)
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
else
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiTrigger trigHome;
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
GuiText backBtnTxt("Go Back", 24, (GXColor){0, 0, 0, 255});
GuiImage backBtnImg(&btnOutline);
GuiImage backBtnImgOver(&btnOutlineOver);
GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
backBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
backBtn.SetPosition(50, -35);
backBtn.SetLabel(&backBtnTxt);
backBtn.SetImage(&backBtnImg);
backBtn.SetImageOver(&backBtnImgOver);
backBtn.SetSoundOver(&btnSoundOver);
backBtn.SetSoundClick(&btnSoundClick);
backBtn.SetTrigger(&trigA);
backBtn.SetEffectGrow();
GuiOptionBrowser optionBrowser(552, 248, &options);
optionBrowser.SetPosition(0, 108);
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
HaltGui();
GuiWindow w(screenwidth, screenheight);
w.Append(&backBtn);
mainWindow->Append(&optionBrowser);
mainWindow->Append(&w);
mainWindow->Append(&titleTxt);
ResumeGui();
while(menu == MENU_NONE)
{
usleep(THREAD_SLEEP);
for(i=0; i < Cheat.num_cheats; i++)
sprintf (options.value[i], "%s", Cheat.c[i].enabled == true ? "On" : "Off");
ret = optionBrowser.GetClickedOption();
if(Cheat.c[ret].enabled)
S9xDisableCheat(ret);
else
S9xEnableCheat(ret);
if(backBtn.GetState() == STATE_CLICKED)
{
menu = MENU_GAMESETTINGS;
}
}
HaltGui();
mainWindow->Remove(&optionBrowser);
mainWindow->Remove(&w);
mainWindow->Remove(&titleTxt);
return menu;
}*/
/****************************************************************************
* MenuSettingsMappings
***************************************************************************/
@ -2389,6 +2300,7 @@ static int MenuSettingsMappingsMap()
{
int menu = MENU_NONE;
int ret,i,j;
bool firstRun = true;
OptionList options;
char menuTitle[100];
@ -2480,6 +2392,18 @@ static int MenuSettingsMappingsMap()
{
usleep(THREAD_SLEEP);
ret = optionBrowser.GetClickedOption();
if(ret >= 0)
{
// get a button selection from user
btnmap[mapMenuCtrl][ret] = ButtonMappingWindow();
}
if(ret >= 0 || firstRun)
{
firstRun = false;
for(i=0; i < options.length; i++)
{
for(j=0; j < ctrlr_def[mapMenuCtrl].num_btns; j++)
@ -2497,13 +2421,7 @@ static int MenuSettingsMappingsMap()
}
}
}
ret = optionBrowser.GetClickedOption();
if(ret >= 0)
{
// get a button selection from user
btnmap[mapMenuCtrl][ret] = ButtonMappingWindow();
optionBrowser.TriggerUpdate();
}
if(backBtn.GetState() == STATE_CLICKED)
@ -2744,6 +2662,7 @@ static int MenuSettingsVideo()
int menu = MENU_NONE;
int ret;
int i = 0;
bool firstRun = true;
OptionList options;
sprintf(options.name[i++], "Rendering");
@ -2807,6 +2726,54 @@ static int MenuSettingsVideo()
{
usleep(THREAD_SLEEP);
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.render++;
if (GCSettings.render > 2)
GCSettings.render = 1;
break;
case 1:
GCSettings.scaling++;
if (GCSettings.scaling > 3)
GCSettings.scaling = 0;
// disable Widescreen correction in Wii mode - determined automatically
#ifdef HW_RVL
if(GCSettings.scaling == 3)
GCSettings.scaling = 0;
#endif
break;
case 2:
ScreenZoomWindow();
break;
case 3:
ScreenPositionWindow();
break;
case 4:
GCSettings.videomode++;
if(GCSettings.videomode > 4)
GCSettings.videomode = 0;
break;
case 5:
GCSettings.colorize ^= 1;
break;
case 6:
menu = MENU_GAMESETTINGS_PALETTE;
break;
}
if(ret >= 0 || firstRun)
{
firstRun = false;
if (GCSettings.render == 0)
sprintf (options.value[0], "Original");
else if (GCSettings.render == 1)
@ -2851,48 +2818,7 @@ static int MenuSettingsVideo()
else
sprintf(options.value[6], "Default");
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.render++;
if (GCSettings.render > 2)
GCSettings.render = 1;
break;
case 1:
GCSettings.scaling++;
if (GCSettings.scaling > 3)
GCSettings.scaling = 0;
// disable Widescreen correction in Wii mode - determined automatically
#ifdef HW_RVL
if(GCSettings.scaling == 3)
GCSettings.scaling = 0;
#endif
break;
case 2:
ScreenZoomWindow();
break;
case 3:
ScreenPositionWindow();
break;
case 4:
GCSettings.videomode++;
if(GCSettings.videomode > 4)
GCSettings.videomode = 0;
break;
case 5:
GCSettings.colorize ^= 1;
break;
case 6:
menu = MENU_GAMESETTINGS_PALETTE;
break;
optionBrowser.TriggerUpdate();
}
if(backBtn.GetState() == STATE_CLICKED)
@ -3084,6 +3010,7 @@ static int MenuSettingsFile()
int menu = MENU_NONE;
int ret;
int i = 0;
bool firstRun = true;
OptionList options;
sprintf(options.name[i++], "Load Device");
sprintf(options.name[i++], "Save Device");
@ -3145,6 +3072,51 @@ static int MenuSettingsFile()
{
usleep(THREAD_SLEEP);
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.LoadMethod++;
break;
case 1:
GCSettings.SaveMethod++;
break;
case 2:
OnScreenKeyboard(GCSettings.LoadFolder, MAXPATHLEN);
break;
case 3:
OnScreenKeyboard(GCSettings.SaveFolder, MAXPATHLEN);
break;
case 4:
OnScreenKeyboard(GCSettings.CheatFolder, MAXPATHLEN);
break;
case 5:
GCSettings.AutoLoad++;
if (GCSettings.AutoLoad > 2)
GCSettings.AutoLoad = 0;
break;
case 6:
GCSettings.AutoSave++;
if (GCSettings.AutoSave > 3)
GCSettings.AutoSave = 0;
break;
case 7:
GCSettings.VerifySaves ^= 1;
break;
}
if(ret >= 0 || firstRun)
{
firstRun = false;
// some load/save methods are not implemented - here's where we skip them
// they need to be skipped in the order they were enumerated in snes9xGX.h
@ -3217,45 +3189,7 @@ static int MenuSettingsFile()
sprintf (options.value[7], "%s", GCSettings.VerifySaves == true ? "On" : "Off");
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.LoadMethod++;
break;
case 1:
GCSettings.SaveMethod++;
break;
case 2:
OnScreenKeyboard(GCSettings.LoadFolder, MAXPATHLEN);
break;
case 3:
OnScreenKeyboard(GCSettings.SaveFolder, MAXPATHLEN);
break;
case 4:
OnScreenKeyboard(GCSettings.CheatFolder, MAXPATHLEN);
break;
case 5:
GCSettings.AutoLoad++;
if (GCSettings.AutoLoad > 2)
GCSettings.AutoLoad = 0;
break;
case 6:
GCSettings.AutoSave++;
if (GCSettings.AutoSave > 3)
GCSettings.AutoSave = 0;
break;
case 7:
GCSettings.VerifySaves ^= 1;
break;
optionBrowser.TriggerUpdate();
}
if(backBtn.GetState() == STATE_CLICKED)
@ -3278,6 +3212,7 @@ static int MenuSettingsMenu()
int menu = MENU_NONE;
int ret;
int i = 0;
bool firstRun = true;
OptionList options;
sprintf(options.name[i++], "Exit Action");
@ -3335,6 +3270,38 @@ static int MenuSettingsMenu()
{
usleep(THREAD_SLEEP);
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.ExitAction++;
if(GCSettings.ExitAction > 3)
GCSettings.ExitAction = 0;
break;
case 1:
GCSettings.WiimoteOrientation ^= 1;
break;
case 2:
GCSettings.MusicVolume += 10;
if(GCSettings.MusicVolume > 100)
GCSettings.MusicVolume = 0;
bgMusic->SetVolume(GCSettings.MusicVolume);
break;
case 3:
GCSettings.SFXVolume += 10;
if(GCSettings.SFXVolume > 100)
GCSettings.SFXVolume = 0;
break;
case 4:
GCSettings.Rumble ^= 1;
break;
}
if(ret >= 0 || firstRun)
{
firstRun = false;
#ifdef HW_RVL
if (GCSettings.ExitAction == 1)
sprintf (options.value[0], "Return to Wii Menu");
@ -3378,32 +3345,7 @@ static int MenuSettingsMenu()
else
sprintf (options.value[4], "Disabled");
ret = optionBrowser.GetClickedOption();
switch (ret)
{
case 0:
GCSettings.ExitAction++;
if(GCSettings.ExitAction > 3)
GCSettings.ExitAction = 0;
break;
case 1:
GCSettings.WiimoteOrientation ^= 1;
break;
case 2:
GCSettings.MusicVolume += 10;
if(GCSettings.MusicVolume > 100)
GCSettings.MusicVolume = 0;
bgMusic->SetVolume(GCSettings.MusicVolume);
break;
case 3:
GCSettings.SFXVolume += 10;
if(GCSettings.SFXVolume > 100)
GCSettings.SFXVolume = 0;
break;
case 4:
GCSettings.Rumble ^= 1;
break;
optionBrowser.TriggerUpdate();
}
if(backBtn.GetState() == STATE_CLICKED)
@ -3427,6 +3369,7 @@ static int MenuSettingsNetwork()
#ifdef HW_RVL
int ret;
int i = 0;
bool firstRun = true;
OptionList options;
sprintf(options.name[i++], "SMB Share IP");
sprintf(options.name[i++], "SMB Share Name");
@ -3482,11 +3425,6 @@ static int MenuSettingsNetwork()
{
usleep(THREAD_SLEEP);
strncpy (options.value[0], GCSettings.smbip, 15);
strncpy (options.value[1], GCSettings.smbshare, 19);
strncpy (options.value[2], GCSettings.smbuser, 19);
strncpy (options.value[3], GCSettings.smbpwd, 19);
ret = optionBrowser.GetClickedOption();
switch (ret)
@ -3508,6 +3446,16 @@ static int MenuSettingsNetwork()
break;
}
if(ret >= 0 || firstRun)
{
firstRun = false;
strncpy (options.value[0], GCSettings.smbip, 15);
strncpy (options.value[1], GCSettings.smbshare, 19);
strncpy (options.value[2], GCSettings.smbuser, 19);
strncpy (options.value[3], GCSettings.smbpwd, 19);
optionBrowser.TriggerUpdate();
}
if(backBtn.GetState() == STATE_CLICKED)
{
menu = MENU_SETTINGS;