From 5c351075b089acb40bd3a26f5eaebb0d904ff350 Mon Sep 17 00:00:00 2001 From: dborth Date: Mon, 27 Apr 2009 06:58:23 +0000 Subject: [PATCH] improve scrollbars, add confirmation prompts, save preferences when closing game settings --- source/ngc/gui/gui.h | 10 ------- source/ngc/gui/gui_filebrowser.cpp | 29 +++++++++++---------- source/ngc/gui/gui_optionbrowser.cpp | 26 ------------------- source/ngc/gui/gui_savebrowser.cpp | 29 --------------------- source/ngc/menu.cpp | 39 ++++++++++++++++------------ 5 files changed, 39 insertions(+), 94 deletions(-) diff --git a/source/ngc/gui/gui.h b/source/ngc/gui/gui.h index 7e4604e..6bdbe5d 100644 --- a/source/ngc/gui/gui.h +++ b/source/ngc/gui/gui.h @@ -796,7 +796,6 @@ class GuiOptionBrowser : public GuiElement GuiButton * arrowUpBtn; GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; GuiImage * bgOptionsImg; GuiImage * scrollbarImg; @@ -804,8 +803,6 @@ class GuiOptionBrowser : public GuiElement GuiImage * arrowDownOverImg; GuiImage * arrowUpImg; GuiImage * arrowUpOverImg; - GuiImage * scrollbarBoxImg; - GuiImage * scrollbarBoxOverImg; GuiImageData * bgOptions; GuiImageData * bgOptionsEntry; @@ -814,8 +811,6 @@ class GuiOptionBrowser : public GuiElement GuiImageData * arrowDownOver; GuiImageData * arrowUp; GuiImageData * arrowUpOver; - GuiImageData * scrollbarBox; - GuiImageData * scrollbarBoxOver; GuiSound * btnSoundOver; GuiSound * btnSoundClick; @@ -860,15 +855,12 @@ class GuiSaveBrowser : public GuiElement GuiButton * arrowUpBtn; GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; GuiImage * scrollbarImg; GuiImage * arrowDownImg; GuiImage * arrowDownOverImg; GuiImage * arrowUpImg; GuiImage * arrowUpOverImg; - GuiImage * scrollbarBoxImg; - GuiImage * scrollbarBoxOverImg; GuiImageData * gameSave; GuiImageData * gameSaveOver; @@ -878,8 +870,6 @@ class GuiSaveBrowser : public GuiElement GuiImageData * arrowDownOver; GuiImageData * arrowUp; GuiImageData * arrowUpOver; - GuiImageData * scrollbarBox; - GuiImageData * scrollbarBoxOver; GuiSound * btnSoundOver; GuiSound * btnSoundClick; diff --git a/source/ngc/gui/gui_filebrowser.cpp b/source/ngc/gui/gui_filebrowser.cpp index a01795a..c1737ed 100644 --- a/source/ngc/gui/gui_filebrowser.cpp +++ b/source/ngc/gui/gui_filebrowser.cpp @@ -92,7 +92,7 @@ GuiFileBrowser::GuiFileBrowser(int w, int h) scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); scrollbarBoxBtn->SetMinY(0); - scrollbarBoxBtn->SetMaxY(304); + scrollbarBoxBtn->SetMaxY(136); scrollbarBoxBtn->SetSelectable(false); scrollbarBoxBtn->SetClickable(false); scrollbarBoxBtn->SetHoldable(true); @@ -148,8 +148,8 @@ GuiFileBrowser::~GuiFileBrowser() delete btnSoundOver; delete btnSoundClick; - delete trigA; delete trigHeldA; + delete trigA; for(int i=0; iUpdate(t); arrowDownBtn->Update(t); @@ -230,14 +231,14 @@ void GuiFileBrowser::Update(GuiTrigger * t) ) { scrollbarBoxBtn->SetPosition(0,0); - position = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop(); + positionWiimote = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop(); - if(position < scrollbarBoxBtn->GetMinY()) - position = scrollbarBoxBtn->GetMinY(); - else if(position > scrollbarBoxBtn->GetMaxY()) - position = scrollbarBoxBtn->GetMaxY(); + if(positionWiimote < scrollbarBoxBtn->GetMinY()) + positionWiimote = scrollbarBoxBtn->GetMinY(); + else if(positionWiimote > 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) { @@ -250,6 +251,7 @@ void GuiFileBrowser::Update(GuiTrigger * t) selectedItem = PAGESIZE-1; } listChanged = true; + focus = false; } 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 - if(listChanged) - { + if(positionWiimote > 0) + position = positionWiimote; // follow wiimote cursor + else position = 136*(browser.pageIndex + selectedItem) / browser.numEntries; - scrollbarBoxBtn->SetPosition(0,position+36); - } + + scrollbarBoxBtn->SetPosition(0,position+36); listChanged = false; diff --git a/source/ngc/gui/gui_optionbrowser.cpp b/source/ngc/gui/gui_optionbrowser.cpp index 8499175..082f889 100644 --- a/source/ngc/gui/gui_optionbrowser.cpp +++ b/source/ngc/gui/gui_optionbrowser.cpp @@ -54,10 +54,6 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l) arrowUpImg = new GuiImage(arrowUp); arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png); 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->SetParent(this); @@ -79,13 +75,6 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l) arrowDownBtn->SetSoundOver(btnSoundOver); 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; iname[i], 22, (GXColor){0, 0, 0, 0xff}); @@ -116,7 +105,6 @@ GuiOptionBrowser::~GuiOptionBrowser() { delete arrowUpBtn; delete arrowDownBtn; - delete scrollbarBoxBtn; delete bgOptionsImg; delete scrollbarImg; @@ -124,8 +112,6 @@ GuiOptionBrowser::~GuiOptionBrowser() delete arrowDownOverImg; delete arrowUpImg; delete arrowUpOverImg; - delete scrollbarBoxImg; - delete scrollbarBoxOverImg; delete bgOptions; delete bgOptionsEntry; @@ -134,8 +120,6 @@ GuiOptionBrowser::~GuiOptionBrowser() delete arrowDownOver; delete arrowUp; delete arrowUpOver; - delete scrollbarBox; - delete scrollbarBoxOver; delete trigA; delete btnSoundOver; @@ -241,7 +225,6 @@ void GuiOptionBrowser::Draw() scrollbarImg->Draw(); arrowUpBtn->Draw(); arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); this->UpdateEffects(); } @@ -253,17 +236,8 @@ void GuiOptionBrowser::Update(GuiTrigger * t) 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); arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); next = listOffset; diff --git a/source/ngc/gui/gui_savebrowser.cpp b/source/ngc/gui/gui_savebrowser.cpp index c951a16..4140a10 100644 --- a/source/ngc/gui/gui_savebrowser.cpp +++ b/source/ngc/gui/gui_savebrowser.cpp @@ -58,10 +58,6 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) arrowUpImg = new GuiImage(arrowUp); arrowUpOver = new GuiImageData(scrollbar_arrowup_over_png); 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->SetParent(this); @@ -83,13 +79,6 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) arrowDownBtn->SetSoundOver(btnSoundOver); 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; iDraw(); arrowUpBtn->Draw(); arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); this->UpdateEffects(); } @@ -238,21 +221,9 @@ void GuiSaveBrowser::Update(GuiTrigger * t) int i, len; 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); arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); // pad/joystick navigation if(!focus) diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index a7a163e..047f6ac 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -1378,8 +1378,11 @@ static int MenuGame() } else if(resetBtn.GetState() == STATE_CLICKED) { - S9xSoftReset (); - menu = MENU_EXIT; + if (WindowPrompt("Reset Game", "Are you sure that you want to reset this game? Any unsaved progress will be lost.", "OK", "Cancel")) + { + S9xSoftReset (); + menu = MENU_EXIT; + } } else if(gameSettingsBtn.GetState() == STATE_CLICKED) { @@ -1387,22 +1390,25 @@ static int MenuGame() } else if(mainmenuBtn.GetState() == STATE_CLICKED) { - if(gameScreenImg) + if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel")) { - mainWindow->Remove(gameScreenImg); - delete gameScreenImg; - gameScreenImg = NULL; + if(gameScreenImg) + { + mainWindow->Remove(gameScreenImg); + delete gameScreenImg; + gameScreenImg = NULL; + } + if(gameScreenTex) + { + free(gameScreenTex); + gameScreenTex = NULL; + } + bgImg->SetVisible(true); + #ifndef NO_SOUND + bgMusic->Play(); // startup music + #endif + menu = MENU_GAMESELECTION; } - if(gameScreenTex) - { - free(gameScreenTex); - gameScreenTex = NULL; - } - bgImg->SetVisible(true); - #ifndef NO_SOUND - bgMusic->Play(); // startup music - #endif - menu = MENU_GAMESELECTION; } else if(closeBtn.GetState() == STATE_CLICKED) { @@ -1895,6 +1901,7 @@ static int MenuGameSettings() else if(closeBtn.GetState() == STATE_CLICKED) { menu = MENU_EXIT; + SavePrefs(NOTSILENT); exitSound->Play(); bgTopImg->SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 15);