From 65701c58c1e8fc19571d964248949f50bdcc3fc6 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 13 Oct 2012 15:05:43 -0500 Subject: [PATCH] Added some more menu sound theming tags. Menu scroll sound now also applies to the fast select menu. --- THEMES.md | 8 +++++++- changelog.txt | 4 ++++ src/components/GuiFastSelect.cpp | 16 +++++++++++----- src/components/GuiFastSelect.h | 7 +++++-- src/components/GuiGameList.cpp | 14 +++++++++++++- src/components/GuiTheme.cpp | 11 ++++++++++- src/components/GuiTheme.h | 5 ++++- 7 files changed, 54 insertions(+), 11 deletions(-) diff --git a/THEMES.md b/THEMES.md index 08353f00f..6c6748239 100644 --- a/THEMES.md +++ b/THEMES.md @@ -103,7 +103,13 @@ Audio Themes can also define menu sounds. Sounds should be in the .wav format. -`` - path to the sound to play when the game list is scrolling. +`` - path to the sound to play when the game list or fast select menu is scrolling. + +`` - path to the sound to play when the user selects something from the game list. + +`` - path to the sound to play when the user "goes up" from a folder in the game list. + +`` - path to the sound to play when the user opens a menu (either the "main menu" or the fast select menu). List of variables diff --git a/changelog.txt b/changelog.txt index adcf3f3cc..4962ee839 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +October 13 +-Added sound support through SDL_mixer. +-Added new theme tags for defining menu sounds. See THEMES.md for details. + October 10 -Added a theming tag for the Fast Select box's text. -Fixed GuiBox background being positioned wrong. diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index 5f9423b89..03064a91e 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -6,7 +6,7 @@ const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int GuiFastSelect::SCROLLSPEED = 100; const int GuiFastSelect::SCROLLDELAY = 507; -GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor) +GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound) { mLetterID = LETTERS.find(toupper(startLetter)); if(mLetterID == std::string::npos) @@ -17,6 +17,7 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, cha mParent = parent; mList = list; + mScrollSound = scrollsound; mScrolling = false; mScrollTimer = 0; @@ -25,7 +26,6 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, cha unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); mBox = new GuiBox(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6); mBox->setData(data); - //addChild(mBox); mTextColor = textcolor; @@ -58,14 +58,14 @@ void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown) { if(button == InputManager::UP && keyDown) { - setLetterID(mLetterID - 1); mScrollOffset = -1; + scroll(); } if(button == InputManager::DOWN && keyDown) { - setLetterID(mLetterID + 1); mScrollOffset = 1; + scroll(); } if((button == InputManager::UP || button == InputManager::DOWN) && !keyDown) @@ -98,11 +98,17 @@ void GuiFastSelect::onTick(int deltaTime) if(mScrolling && mScrollTimer >= SCROLLSPEED) { mScrollTimer = 0; - setLetterID(mLetterID + mScrollOffset); + scroll(); } } } +void GuiFastSelect::scroll() +{ + setLetterID(mLetterID + mScrollOffset); + mScrollSound->play(); +} + void GuiFastSelect::setLetterID(int id) { while(id < 0) diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h index c0be2b8bb..f63afec8e 100644 --- a/src/components/GuiFastSelect.h +++ b/src/components/GuiFastSelect.h @@ -4,13 +4,14 @@ #include "../GuiComponent.h" #include "../SystemData.h" #include "../FolderData.h" +#include "../Sound.h" #include "GuiList.h" #include "GuiBox.h" class GuiFastSelect : GuiComponent { public: - GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor); + GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound); ~GuiFastSelect(); void onRender(); @@ -22,7 +23,7 @@ private: static const int SCROLLDELAY; void setListPos(); - + void scroll(); void setLetterID(int id); GuiList* mList; @@ -35,6 +36,8 @@ private: int mScrollTimer, mScrollOffset; bool mScrolling; + + Sound* mScrollSound; }; #endif diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index 5864312cd..2d0954802 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -113,6 +113,9 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) { if(!keyDown) { + //play select sound + mTheme->getMenuSelectSound()->play(); + FileData* file = mList->getSelectedObject(); if(file->isFolder()) //if you selected a folder, add this directory to the stack, and use the selected one { @@ -120,6 +123,9 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) mFolder = (FolderData*)file; updateList(); }else{ + //wait for the sound to finish or we'll never hear it... + while(mTheme->getMenuSelectSound()->isPlaying()); + mSystem->launchGame((GameData*)file); } } @@ -132,6 +138,9 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) mFolderStack.pop(); updateList(); updateDetailData(); + + //play the back sound + mTheme->getMenuBackSound()->play(); } //only allow switching systems if more than one exists (otherwise it'll reset your position when you switch and it's annoying) @@ -147,14 +156,16 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) } } + //open the "start menu" if(button == InputManager::MENU && keyDown) { new GuiMenu(this); } + //open the fast select menu if(button == InputManager::SELECT && keyDown) { - new GuiFastSelect(this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getFastSelectColor()); + new GuiFastSelect(this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getFastSelectColor(), mTheme->getMenuScrollSound()); } if(mDetailed) @@ -232,6 +243,7 @@ void GuiGameList::updateDetailData() //these are called when the menu opens/closes void GuiGameList::onPause() { + mTheme->getMenuOpenSound()->play(); InputManager::unregisterComponent(this); } diff --git a/src/components/GuiTheme.cpp b/src/components/GuiTheme.cpp index dc64f68f3..58f515a7c 100644 --- a/src/components/GuiTheme.cpp +++ b/src/components/GuiTheme.cpp @@ -25,6 +25,9 @@ int GuiTheme::getSelectedTextColor() { return mListSelectedColor; } GuiBoxData GuiTheme::getBoxData() { return mBoxData; } Sound* GuiTheme::getMenuScrollSound() { return &mMenuScrollSound; } +Sound* GuiTheme::getMenuSelectSound() { return &mMenuSelectSound; } +Sound* GuiTheme::getMenuBackSound() { return &mMenuBackSound; } +Sound* GuiTheme::getMenuOpenSound() { return &mMenuOpenSound; } GuiTheme::GuiTheme(std::string path) { @@ -64,6 +67,9 @@ void GuiTheme::setDefaults() mBoxData.cornerPath = ""; mMenuScrollSound.loadFile(""); + mMenuSelectSound.loadFile(""); + mMenuBackSound.loadFile(""); + mMenuOpenSound.loadFile(""); } void GuiTheme::deleteComponents() @@ -132,7 +138,10 @@ void GuiTheme::readXML(std::string path) mListTextOffsetX = strToFloat(root.child("listTextOffsetX").text().get(), mListTextOffsetX); //sounds - mMenuScrollSound.loadFile(root.child("menuScrollSound").text().get()); + mMenuScrollSound.loadFile(expandPath(root.child("menuScrollSound").text().get())); + mMenuSelectSound.loadFile(expandPath(root.child("menuSelectSound").text().get())); + mMenuBackSound.loadFile(expandPath(root.child("menuBackSound").text().get())); + mMenuOpenSound.loadFile(expandPath(root.child("menuOpenSound").text().get())); //recursively create children for all with proper parenting createComponentChildren(root, this); diff --git a/src/components/GuiTheme.h b/src/components/GuiTheme.h index ff243114a..43305569e 100644 --- a/src/components/GuiTheme.h +++ b/src/components/GuiTheme.h @@ -32,6 +32,9 @@ public: GuiBoxData getBoxData(); Sound* getMenuScrollSound(); + Sound* getMenuSelectSound(); + Sound* getMenuBackSound(); + Sound* getMenuOpenSound(); private: void setDefaults(); void deleteComponents(); @@ -54,7 +57,7 @@ private: GuiBoxData mBoxData; - Sound mMenuScrollSound; + Sound mMenuScrollSound, mMenuSelectSound, mMenuBackSound, mMenuOpenSound; }; #endif