improve scrollbars, add confirmation prompts, save preferences when closing game settings

This commit is contained in:
dborth 2009-04-27 06:58:23 +00:00
parent 4a2fd0d76f
commit 5c351075b0
5 changed files with 39 additions and 94 deletions

View File

@ -796,7 +796,6 @@ class GuiOptionBrowser : public GuiElement
GuiButton * arrowUpBtn; GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn; GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * bgOptionsImg; GuiImage * bgOptionsImg;
GuiImage * scrollbarImg; GuiImage * scrollbarImg;
@ -804,8 +803,6 @@ class GuiOptionBrowser : public GuiElement
GuiImage * arrowDownOverImg; GuiImage * arrowDownOverImg;
GuiImage * arrowUpImg; GuiImage * arrowUpImg;
GuiImage * arrowUpOverImg; GuiImage * arrowUpOverImg;
GuiImage * scrollbarBoxImg;
GuiImage * scrollbarBoxOverImg;
GuiImageData * bgOptions; GuiImageData * bgOptions;
GuiImageData * bgOptionsEntry; GuiImageData * bgOptionsEntry;
@ -814,8 +811,6 @@ class GuiOptionBrowser : public GuiElement
GuiImageData * arrowDownOver; GuiImageData * arrowDownOver;
GuiImageData * arrowUp; GuiImageData * arrowUp;
GuiImageData * arrowUpOver; GuiImageData * arrowUpOver;
GuiImageData * scrollbarBox;
GuiImageData * scrollbarBoxOver;
GuiSound * btnSoundOver; GuiSound * btnSoundOver;
GuiSound * btnSoundClick; GuiSound * btnSoundClick;
@ -860,15 +855,12 @@ class GuiSaveBrowser : public GuiElement
GuiButton * arrowUpBtn; GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn; GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * scrollbarImg; GuiImage * scrollbarImg;
GuiImage * arrowDownImg; GuiImage * arrowDownImg;
GuiImage * arrowDownOverImg; GuiImage * arrowDownOverImg;
GuiImage * arrowUpImg; GuiImage * arrowUpImg;
GuiImage * arrowUpOverImg; GuiImage * arrowUpOverImg;
GuiImage * scrollbarBoxImg;
GuiImage * scrollbarBoxOverImg;
GuiImageData * gameSave; GuiImageData * gameSave;
GuiImageData * gameSaveOver; GuiImageData * gameSaveOver;
@ -878,8 +870,6 @@ class GuiSaveBrowser : public GuiElement
GuiImageData * arrowDownOver; GuiImageData * arrowDownOver;
GuiImageData * arrowUp; GuiImageData * arrowUp;
GuiImageData * arrowUpOver; GuiImageData * arrowUpOver;
GuiImageData * scrollbarBox;
GuiImageData * scrollbarBoxOver;
GuiSound * btnSoundOver; GuiSound * btnSoundOver;
GuiSound * btnSoundClick; GuiSound * btnSoundClick;

View File

@ -92,7 +92,7 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarBoxBtn->SetMinY(0); scrollbarBoxBtn->SetMinY(0);
scrollbarBoxBtn->SetMaxY(304); scrollbarBoxBtn->SetMaxY(136);
scrollbarBoxBtn->SetSelectable(false); scrollbarBoxBtn->SetSelectable(false);
scrollbarBoxBtn->SetClickable(false); scrollbarBoxBtn->SetClickable(false);
scrollbarBoxBtn->SetHoldable(true); scrollbarBoxBtn->SetHoldable(true);
@ -148,8 +148,8 @@ GuiFileBrowser::~GuiFileBrowser()
delete btnSoundOver; delete btnSoundOver;
delete btnSoundClick; delete btnSoundClick;
delete trigA;
delete trigHeldA; delete trigHeldA;
delete trigA;
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; i++)
{ {
@ -216,7 +216,8 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(state == STATE_DISABLED || !t) if(state == STATE_DISABLED || !t)
return; return;
int position; int position = 0;
int positionWiimote = 0;
arrowUpBtn->Update(t); arrowUpBtn->Update(t);
arrowDownBtn->Update(t); arrowDownBtn->Update(t);
@ -230,14 +231,14 @@ void GuiFileBrowser::Update(GuiTrigger * t)
) )
{ {
scrollbarBoxBtn->SetPosition(0,0); scrollbarBoxBtn->SetPosition(0,0);
position = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop(); positionWiimote = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop();
if(position < scrollbarBoxBtn->GetMinY()) if(positionWiimote < scrollbarBoxBtn->GetMinY())
position = scrollbarBoxBtn->GetMinY(); positionWiimote = scrollbarBoxBtn->GetMinY();
else if(position > scrollbarBoxBtn->GetMaxY()) else if(positionWiimote > scrollbarBoxBtn->GetMaxY())
position = scrollbarBoxBtn->GetMaxY(); positionWiimote = scrollbarBoxBtn->GetMaxY();
browser.pageIndex = (position * browser.numEntries)/136.0 - selectedItem; browser.pageIndex = (positionWiimote * browser.numEntries)/136.0 - selectedItem;
if(browser.pageIndex <= 0) if(browser.pageIndex <= 0)
{ {
@ -250,6 +251,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
selectedItem = PAGESIZE-1; selectedItem = PAGESIZE-1;
} }
listChanged = true; listChanged = true;
focus = false;
} }
if(arrowDownBtn->GetState() == STATE_HELD && arrowDownBtn->GetStateChan() == t->chan) if(arrowDownBtn->GetState() == STATE_HELD && arrowDownBtn->GetStateChan() == t->chan)
@ -375,11 +377,12 @@ void GuiFileBrowser::Update(GuiTrigger * t)
} }
// update the location of the scroll box based on the position in the file list // update the location of the scroll box based on the position in the file list
if(listChanged) if(positionWiimote > 0)
{ position = positionWiimote; // follow wiimote cursor
else
position = 136*(browser.pageIndex + selectedItem) / browser.numEntries; position = 136*(browser.pageIndex + selectedItem) / browser.numEntries;
scrollbarBoxBtn->SetPosition(0,position+36); scrollbarBoxBtn->SetPosition(0,position+36);
}
listChanged = false; listChanged = false;

View File

@ -54,10 +54,6 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
arrowUpImg = new GuiImage(arrowUp); arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png); arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png);
arrowUpOverImg = new GuiImage(arrowUpOver); arrowUpOverImg = new GuiImage(arrowUpOver);
scrollbarBox = new GuiImageData(scrollbar_box_png);
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = new GuiImageData(scrollbar_box_over_png);
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this); arrowUpBtn->SetParent(this);
@ -79,13 +75,6 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l)
arrowDownBtn->SetSoundOver(btnSoundOver); arrowDownBtn->SetSoundOver(btnSoundOver);
arrowDownBtn->SetSoundClick(btnSoundClick); arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; i++)
{ {
optionTxt[i] = new GuiText(options->name[i], 22, (GXColor){0, 0, 0, 0xff}); optionTxt[i] = new GuiText(options->name[i], 22, (GXColor){0, 0, 0, 0xff});
@ -116,7 +105,6 @@ GuiOptionBrowser::~GuiOptionBrowser()
{ {
delete arrowUpBtn; delete arrowUpBtn;
delete arrowDownBtn; delete arrowDownBtn;
delete scrollbarBoxBtn;
delete bgOptionsImg; delete bgOptionsImg;
delete scrollbarImg; delete scrollbarImg;
@ -124,8 +112,6 @@ GuiOptionBrowser::~GuiOptionBrowser()
delete arrowDownOverImg; delete arrowDownOverImg;
delete arrowUpImg; delete arrowUpImg;
delete arrowUpOverImg; delete arrowUpOverImg;
delete scrollbarBoxImg;
delete scrollbarBoxOverImg;
delete bgOptions; delete bgOptions;
delete bgOptionsEntry; delete bgOptionsEntry;
@ -134,8 +120,6 @@ GuiOptionBrowser::~GuiOptionBrowser()
delete arrowDownOver; delete arrowDownOver;
delete arrowUp; delete arrowUp;
delete arrowUpOver; delete arrowUpOver;
delete scrollbarBox;
delete scrollbarBoxOver;
delete trigA; delete trigA;
delete btnSoundOver; delete btnSoundOver;
@ -241,7 +225,6 @@ void GuiOptionBrowser::Draw()
scrollbarImg->Draw(); scrollbarImg->Draw();
arrowUpBtn->Draw(); arrowUpBtn->Draw();
arrowDownBtn->Draw(); arrowDownBtn->Draw();
scrollbarBoxBtn->Draw();
this->UpdateEffects(); this->UpdateEffects();
} }
@ -253,17 +236,8 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
int next, prev; int next, prev;
// update the location of the scroll box based on the position in the option list
int position = 136*(listOffset+selectedItem)/options->length;
if(position > 130)
position = 136;
scrollbarBoxBtn->SetPosition(0,position+36);
arrowUpBtn->Update(t); arrowUpBtn->Update(t);
arrowDownBtn->Update(t); arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t);
next = listOffset; next = listOffset;

View File

@ -58,10 +58,6 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a)
arrowUpImg = new GuiImage(arrowUp); arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png); arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png);
arrowUpOverImg = new GuiImage(arrowUpOver); arrowUpOverImg = new GuiImage(arrowUpOver);
scrollbarBox = new GuiImageData(scrollbar_box_png);
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = new GuiImageData(scrollbar_box_over_png);
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this); arrowUpBtn->SetParent(this);
@ -83,13 +79,6 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a)
arrowDownBtn->SetSoundOver(btnSoundOver); arrowDownBtn->SetSoundOver(btnSoundOver);
arrowDownBtn->SetSoundClick(btnSoundClick); arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
for(int i=0; i<SAVELISTSIZE; i++) for(int i=0; i<SAVELISTSIZE; i++)
{ {
saveDate[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff}); saveDate[i] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff});
@ -135,15 +124,12 @@ GuiSaveBrowser::~GuiSaveBrowser()
{ {
delete arrowUpBtn; delete arrowUpBtn;
delete arrowDownBtn; delete arrowDownBtn;
delete scrollbarBoxBtn;
delete scrollbarImg; delete scrollbarImg;
delete arrowDownImg; delete arrowDownImg;
delete arrowDownOverImg; delete arrowDownOverImg;
delete arrowUpImg; delete arrowUpImg;
delete arrowUpOverImg; delete arrowUpOverImg;
delete scrollbarBoxImg;
delete scrollbarBoxOverImg;
delete gameSave; delete gameSave;
delete gameSaveOver; delete gameSaveOver;
@ -153,8 +139,6 @@ GuiSaveBrowser::~GuiSaveBrowser()
delete arrowDownOver; delete arrowDownOver;
delete arrowUp; delete arrowUp;
delete arrowUpOver; delete arrowUpOver;
delete scrollbarBox;
delete scrollbarBoxOver;
delete btnSoundOver; delete btnSoundOver;
delete btnSoundClick; delete btnSoundClick;
@ -226,7 +210,6 @@ void GuiSaveBrowser::Draw()
scrollbarImg->Draw(); scrollbarImg->Draw();
arrowUpBtn->Draw(); arrowUpBtn->Draw();
arrowDownBtn->Draw(); arrowDownBtn->Draw();
scrollbarBoxBtn->Draw();
this->UpdateEffects(); this->UpdateEffects();
} }
@ -238,21 +221,9 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
int i, len; int i, len;
char savetext[50]; char savetext[50];
// update the location of the scroll box based on the position in the option list
int position;
if(action == 0)
position = 136*(listOffset+selectedItem)/saves->length;
else
position = 136*(listOffset+selectedItem+2)/saves->length;
if(position > 130)
position = 136;
scrollbarBoxBtn->SetPosition(0,position+36);
arrowUpBtn->Update(t); arrowUpBtn->Update(t);
arrowDownBtn->Update(t); arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t);
// pad/joystick navigation // pad/joystick navigation
if(!focus) if(!focus)

View File

@ -1377,15 +1377,20 @@ static int MenuGame()
menu = MENU_GAME_LOAD; menu = MENU_GAME_LOAD;
} }
else if(resetBtn.GetState() == STATE_CLICKED) else if(resetBtn.GetState() == STATE_CLICKED)
{
if (WindowPrompt("Reset Game", "Are you sure that you want to reset this game? Any unsaved progress will be lost.", "OK", "Cancel"))
{ {
S9xSoftReset (); S9xSoftReset ();
menu = MENU_EXIT; menu = MENU_EXIT;
} }
}
else if(gameSettingsBtn.GetState() == STATE_CLICKED) else if(gameSettingsBtn.GetState() == STATE_CLICKED)
{ {
menu = MENU_GAMESETTINGS; menu = MENU_GAMESETTINGS;
} }
else if(mainmenuBtn.GetState() == STATE_CLICKED) else if(mainmenuBtn.GetState() == STATE_CLICKED)
{
if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))
{ {
if(gameScreenImg) if(gameScreenImg)
{ {
@ -1404,6 +1409,7 @@ static int MenuGame()
#endif #endif
menu = MENU_GAMESELECTION; menu = MENU_GAMESELECTION;
} }
}
else if(closeBtn.GetState() == STATE_CLICKED) else if(closeBtn.GetState() == STATE_CLICKED)
{ {
menu = MENU_EXIT; menu = MENU_EXIT;
@ -1895,6 +1901,7 @@ static int MenuGameSettings()
else if(closeBtn.GetState() == STATE_CLICKED) else if(closeBtn.GetState() == STATE_CLICKED)
{ {
menu = MENU_EXIT; menu = MENU_EXIT;
SavePrefs(NOTSILENT);
exitSound->Play(); exitSound->Play();
bgTopImg->SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 15); bgTopImg->SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 15);