diff --git a/RetroFE/Source/CMakeLists.txt b/RetroFE/Source/CMakeLists.txt index 3d288bc..c793aba 100644 --- a/RetroFE/Source/CMakeLists.txt +++ b/RetroFE/Source/CMakeLists.txt @@ -122,7 +122,6 @@ set(RETROFE_HEADERS "${RETROFE_DIR}/Source/Graphics/Font.h" "${RETROFE_DIR}/Source/Graphics/FontCache.h" "${RETROFE_DIR}/Source/Graphics/PageBuilder.h" - "${RETROFE_DIR}/Source/Graphics/MenuNotifierInterface.h" "${RETROFE_DIR}/Source/Graphics/Page.h" "${RETROFE_DIR}/Source/Sound/Sound.h" "${RETROFE_DIR}/Source/Utility/Log.h" diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index d49e0a0..8fd55a0 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -18,7 +18,6 @@ #include #include "../../SDL.h" -#include "../MenuNotifierInterface.h" #include "../Page.h" #include "../ViewInfo.h" #include "../Animate/Tween.h" diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index fd5f7e3..3d7033f 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -51,12 +51,9 @@ ScrollingList::ScrollingList(Configuration &c, , spriteList_(NULL) , scrollPoints_(NULL) , tweenPoints_(NULL) - , focus_(false) , itemIndex_(0) , componentIndex_(0) , selectedOffsetIndex_(0) - , scrollStopRequested_(true) - , notifyAllRequested_(false) , currentScrollDirection_(ScrollDirectionIdle) , requestedScrollDirection_(ScrollDirectionIdle) , currentScrollState_(ScrollStateIdle) @@ -77,12 +74,9 @@ ScrollingList::ScrollingList(const ScrollingList ©) : Component(copy) , horizontalScroll(copy.horizontalScroll) , spriteList_(NULL) - , focus_(false) , itemIndex_(0) , componentIndex_(0) , selectedOffsetIndex_(copy.selectedOffsetIndex_) - , scrollStopRequested_(true) - , notifyAllRequested_(false) , currentScrollDirection_(ScrollDirectionIdle) , requestedScrollDirection_(ScrollDirectionIdle) , currentScrollState_(ScrollStateIdle) @@ -122,8 +116,6 @@ void ScrollingList::setItems(std::vector *items) } allocateSpritePoints(); - - notifyAllRequested_ = true; } unsigned int ScrollingList::loopIncrement(unsigned int offset, unsigned int i, unsigned int size) @@ -242,6 +234,15 @@ Item *ScrollingList::getItemByOffset(int offset) return items_->at(index); } + +Item *ScrollingList::getSelectedItem() +{ + if(!items_ || items_->size() == 0) return NULL; + unsigned index = loopIncrement(itemIndex_, selectedOffsetIndex_, items_->size()); + return items_->at(index); +} + + void ScrollingList::click(double nextScrollTime) { if(currentScrollDirection_ == ScrollDirectionBack) @@ -277,8 +278,6 @@ void ScrollingList::click(double nextScrollTime) void ScrollingList::pageUp() { - notifyAllRequested_ = true; - if(components_.size() == 0) return; deallocateSpritePoints(); @@ -290,8 +289,6 @@ void ScrollingList::pageUp() void ScrollingList::pageDown() { - notifyAllRequested_ = true; - if(components_.size() == 0) return; deallocateSpritePoints(); @@ -305,8 +302,6 @@ void ScrollingList::random() { if(!items_ || items_->size() == 0) return; - notifyAllRequested_ = true; - deallocateSpritePoints(); itemIndex_ = rand() % items_->size(); allocateSpritePoints(); @@ -324,7 +319,6 @@ void ScrollingList::letterDown() void ScrollingList::letterChange(bool increment) { - notifyAllRequested_ = true; deallocateSpritePoints(); std::string startname = items_->at((itemIndex_+selectedOffsetIndex_)%items_->size())->lowercaseFullTitle(); @@ -383,9 +377,6 @@ void ScrollingList::freeGraphicsMemory() void ScrollingList::triggerEnterEvent() { - focus_ = true; - notifyAllRequested_ = true; - for(unsigned int i = 0; i < components_.size(); ++i) { Component *c = components_.at(i); @@ -395,9 +386,6 @@ void ScrollingList::triggerEnterEvent() void ScrollingList::triggerExitEvent() { - focus_ = false; - notifyAllRequested_ = true; - for(unsigned int i = 0; i < components_.size(); ++i) { Component *c = components_.at(i); @@ -407,9 +395,6 @@ void ScrollingList::triggerExitEvent() void ScrollingList::triggerMenuEnterEvent( int menuIndex ) { - focus_ = true; - notifyAllRequested_ = true; - for(unsigned int i = 0; i < components_.size(); ++i) { Component *c = components_.at(i); @@ -419,9 +404,6 @@ void ScrollingList::triggerMenuEnterEvent( int menuIndex ) void ScrollingList::triggerMenuExitEvent( int menuIndex ) { - focus_ = false; - notifyAllRequested_ = true; - for(unsigned int i = 0; i < components_.size(); ++i) { Component *c = components_.at(i); @@ -531,31 +513,13 @@ void ScrollingList::update(float dt) } - if(scrollStopped || (notifyAllRequested_ && focus_)) + if(scrollStopped) { - Item *item = NULL; - unsigned index = loopIncrement(itemIndex_, selectedOffsetIndex_, items_->size()); - item = items_->at(index); - - for(std::vector::iterator it = notificationComponents_.begin(); - it != notificationComponents_.end(); - it++) - { - MenuNotifierInterface *c = *it; - - if(c && item) - { - c->onNewItemSelected(item); - } - } - if(currentScrollState_ == ScrollStatePageChange) { currentScrollState_ = ScrollStateIdle; } } - - notifyAllRequested_ = false; } unsigned int ScrollingList::getSelectedIndex() @@ -720,29 +684,9 @@ void ScrollingList::draw(unsigned int layer) void ScrollingList::setScrollDirection(ScrollDirection direction) { requestedScrollDirection_ = direction; - - scrollStopRequested_ = (direction == ScrollDirectionIdle); } -void ScrollingList::addComponentForNotifications(MenuNotifierInterface *c) -{ - notificationComponents_.push_back(c); -} -void ScrollingList::removeComponentForNotifications(MenuNotifierInterface *c) -{ - for(std::vector::iterator it = notificationComponents_.begin(); - it != notificationComponents_.end(); - it++) - { - if(c == *it) - { - notificationComponents_.erase(it); - break; - } - } -} - bool ScrollingList::isIdle() { if(!Component::isIdle() || currentScrollState_ != ScrollStateIdle) return false; diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index 4c92204..9059e77 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -19,7 +19,6 @@ #include "Component.h" #include "../Animate/Tween.h" #include "../Page.h" -#include "../MenuNotifierInterface.h" #include "../ViewInfo.h" #include "../../Database/Configuration.h" #include @@ -77,8 +76,7 @@ public: void setScrollOffsetIndex(unsigned int index); void setSelectedIndex(int selectedIndex); Item *getItemByOffset(int offset); - void addComponentForNotifications(MenuNotifierInterface *c); - void removeComponentForNotifications(MenuNotifierInterface *c); + Item *getSelectedItem(); void freeGraphicsMemory(); void update(float dt); void draw(); @@ -107,16 +105,11 @@ private: std::vector *spriteList_; std::vector *scrollPoints_; std::vector *tweenPoints_; - std::vector notificationComponents_; - bool focus_; unsigned int itemIndex_; unsigned int componentIndex_; unsigned int selectedOffsetIndex_; - bool scrollStopRequested_; - bool notifyAllRequested_; - ScrollDirection currentScrollDirection_; ScrollDirection requestedScrollDirection_; ScrollState currentScrollState_; diff --git a/RetroFE/Source/Graphics/MenuNotifierInterface.h b/RetroFE/Source/Graphics/MenuNotifierInterface.h deleted file mode 100644 index 21c105d..0000000 --- a/RetroFE/Source/Graphics/MenuNotifierInterface.h +++ /dev/null @@ -1,26 +0,0 @@ -/* This file is part of RetroFE. - * - * RetroFE is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * RetroFE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with RetroFE. If not, see . - */ -#pragma once - -#include "../Collection/Item.h" - -class MenuNotifierInterface -{ -public: - virtual ~MenuNotifierInterface() {} - virtual void onNewItemSelected(Item *) = 0; -}; - diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index e5cbd26..3a47525 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -52,7 +52,6 @@ void Page::DeInitialize() while(it != menus_.end()) { ScrollingList *menu = *it; - menu->removeComponentForNotifications(this); menus_.erase(it); delete menu; it = menus_.begin(); @@ -132,9 +131,9 @@ void Page::setSelectSound(Sound *chunk) } -void Page::onNewItemSelected(Item *item) +void Page::onNewItemSelected() { - selectedItem_ = item; + selectedItem_ = activeMenu_->getSelectedItem(); for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) { @@ -156,11 +155,6 @@ void Page::onNewItemSelected(Item *item) void Page::pushMenu(ScrollingList *s) { menus_.push_back(s); - - if(s) - { - s->addComponentForNotifications(this); - } } unsigned int Page::getMenuDepth() @@ -282,26 +276,6 @@ void Page::stop() } -void Page::setNewItemSelected() -{ - - if(activeMenu_) - { - activeMenu_->setNewItemSelected(); - } - - for(unsigned int i = 0; i < NUM_LAYERS; ++i) - { - for(std::vector::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it) - { - (*it)->setNewItemSelected(); - } - } - - return; -} - - Item *Page::getSelectedItem() { return selectedItem_; diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 3581ab8..94e6090 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -15,7 +15,6 @@ */ #pragma once -#include "MenuNotifierInterface.h" #include "../Collection/CollectionInfo.h" #include @@ -30,7 +29,7 @@ class Text; class Item; class Sound; -class Page : public MenuNotifierInterface +class Page { public: enum ScrollDirection @@ -44,7 +43,7 @@ public: Page(Configuration &c); virtual ~Page(); void DeInitialize(); - virtual void onNewItemSelected(Item *); + virtual void onNewItemSelected(); bool pushCollection(CollectionInfo *collection); bool popCollection(); void enterMenu(); @@ -70,7 +69,6 @@ public: void setScrolling(ScrollDirection direction); bool isHorizontalScroll(); unsigned int getMenuDepth(); - void setNewItemSelected(); Item *getSelectedItem(); Item *getSelectedItem(int offset); void removeSelectedItem(); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 2e57696..c8c13bd 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -289,7 +289,7 @@ void RetroFE::run() } currentPage_->stop(); - state = RETROFE_EXIT; + state = RETROFE_SPLASH_EXIT; } break; @@ -301,7 +301,7 @@ void RetroFE::run() } break; - case RETROFE_EXIT: + case RETROFE_SPLASH_EXIT: if(currentPage_->isIdle()) { // delete the splash screen and use the standard menu @@ -324,6 +324,7 @@ void RetroFE::run() mp.buildMenuItems(info, menuSort); currentPage_->pushCollection(info); + currentPage_->onNewItemSelected(); currentPage_->start(); state = RETROFE_ENTER; @@ -343,6 +344,7 @@ void RetroFE::run() case RETROFE_HIGHLIGHT_EXIT: if (currentPage_->isIdle()) { + currentPage_->onNewItemSelected(); currentPage_->highlightEnter(); state = RETROFE_HIGHLIGHT_ENTER; } @@ -407,7 +409,7 @@ void RetroFE::run() } currentPage_->resetMenuItems(); - currentPage_->setNewItemSelected(); + currentPage_->onNewItemSelected(); currentPage_->enterMenu(); state = RETROFE_NEXT_PAGE_MENU_ENTER; @@ -459,7 +461,7 @@ void RetroFE::run() } config_.setProperty("currentCollection", currentPage_->getCollectionName()); currentPage_->resetMenuItems(); - currentPage_->setNewItemSelected(); + currentPage_->onNewItemSelected(); currentPage_->enterMenu(); state = RETROFE_BACK_MENU_ENTER; } @@ -592,22 +594,27 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page) if (input_.keystate(UserInput::KeyCodePageUp)) { page->pageScroll(Page::ScrollDirectionBack); + state = RETROFE_HIGHLIGHT_REQUEST; } if (input_.keystate(UserInput::KeyCodePageDown)) { page->pageScroll(Page::ScrollDirectionForward); + state = RETROFE_HIGHLIGHT_REQUEST; } if (input_.keystate(UserInput::KeyCodeLetterUp)) { page->letterScroll(Page::ScrollDirectionBack); + state = RETROFE_HIGHLIGHT_REQUEST; } if (input_.keystate(UserInput::KeyCodeLetterDown)) { page->letterScroll(Page::ScrollDirectionForward); + state = RETROFE_HIGHLIGHT_REQUEST; } if(input_.newKeyPressed(UserInput::KeyCodeNextPlaylist)) { page->nextPlaylist(); + state = RETROFE_HIGHLIGHT_REQUEST; } if(input_.newKeyPressed(UserInput::KeyCodeRemovePlaylist)) { @@ -620,6 +627,7 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page) if(input_.keystate(UserInput::KeyCodeRandom)) { page->selectRandom(); + state = RETROFE_HIGHLIGHT_REQUEST; } } @@ -685,10 +693,6 @@ Page *RetroFE::loadPage() { Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not create page"); } - else - { - page->start(); - } return page; } diff --git a/RetroFE/Source/RetroFE.h b/RetroFE/Source/RetroFE.h index 13f3a15..3e33e4c 100644 --- a/RetroFE/Source/RetroFE.h +++ b/RetroFE/Source/RetroFE.h @@ -53,7 +53,7 @@ private: { RETROFE_IDLE, RETROFE_ENTER, - RETROFE_EXIT, + RETROFE_SPLASH_EXIT, RETROFE_HIGHLIGHT_REQUEST, RETROFE_HIGHLIGHT_EXIT, RETROFE_HIGHLIGHT_ENTER,