Cleaned up the scrolling list code.

This commit is contained in:
Pieter Hulshoff 2017-06-30 11:41:25 +02:00
parent 1c155f710f
commit a7f50c9b03
4 changed files with 437 additions and 408 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@
*/ */
#pragma once #pragma once
#include <vector> #include <vector>
#include "Component.h" #include "Component.h"
#include "../Animate/Tween.h" #include "../Animate/Tween.h"
@ -24,75 +25,73 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
//todo: This scrolling implementation needs to be overhauled
// It needs to have a common interface to support different menu types
// (It was originally sandbox code that creeped into here)
class Configuration; class Configuration;
class Font; class Font;
class ScrollingList : public Component class ScrollingList : public Component
{ {
public: public:
ScrollingList(Configuration &c,
ScrollingList( Configuration &c,
Page &p, Page &p,
bool layoutMode, bool layoutMode,
float scaleX, float scaleX,
float scaleY, float scaleY,
Font *font, Font *font,
std::string layoutKey, std::string layoutKey,
std::string imageType); std::string imageType );
ScrollingList(const ScrollingList &copy); ScrollingList( const ScrollingList &copy );
virtual ~ScrollingList(); virtual ~ScrollingList( );
void triggerEnterEvent(); void triggerEnterEvent( );
void triggerExitEvent(); void triggerExitEvent( );
void triggerMenuEnterEvent(int menuIndex = -1); void triggerMenuEnterEvent( int menuIndex = -1 );
void triggerMenuExitEvent(int menuIndex = -1); void triggerMenuExitEvent( int menuIndex = -1 );
void triggerGameEnterEvent(int menuIndex = -1); void triggerGameEnterEvent( int menuIndex = -1 );
void triggerGameExitEvent(int menuIndex = -1); void triggerGameExitEvent( int menuIndex = -1 );
void triggerHighlightEnterEvent(int menuIndex = -1); void triggerHighlightEnterEvent( int menuIndex = -1 );
void triggerHighlightExitEvent(int menuIndex = -1); void triggerHighlightExitEvent( int menuIndex = -1 );
bool allocateTexture(unsigned int index, Item *i); bool allocateTexture( unsigned int index, Item *i );
void deallocateTexture(unsigned int index); void deallocateTexture( unsigned int index );
void setItems(std::vector<Item *> *items); void setItems( std::vector<Item *> *items );
void destroyItems(); void destroyItems( );
void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints); void setPoints( std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints );
unsigned int getSelectedIndex(); unsigned int getSelectedIndex( );
void setSelectedIndex(unsigned int index); void setSelectedIndex( unsigned int index );
unsigned int getSize(); unsigned int getSize( );
void pageUp(); void pageUp( );
void pageDown(); void pageDown( );
void letterUp(); void letterUp( );
void letterDown(); void letterDown( );
void letterChange(bool increment); void letterChange( bool increment );
void random(); void random( );
bool isIdle(); bool isIdle( );
unsigned int getScrollOffsetIndex(); unsigned int getScrollOffsetIndex( );
void setScrollOffsetIndex(unsigned int index); void setScrollOffsetIndex( unsigned int index );
void setSelectedIndex(int selectedIndex); void setSelectedIndex( int selectedIndex );
Item *getItemByOffset(int offset); Item *getItemByOffset( int offset );
Item *getSelectedItem(); Item *getSelectedItem( );
void allocateGraphicsMemory(); void allocateGraphicsMemory( );
void freeGraphicsMemory(); void freeGraphicsMemory( );
void update(float dt); void update( float dt );
void draw(); void draw( );
void draw(unsigned int layer); void draw( unsigned int layer );
void setScrollAcceleration(float value); void setScrollAcceleration( float value );
void setStartScrollTime(float value); void setStartScrollTime( float value );
bool horizontalScroll; bool horizontalScroll;
void deallocateSpritePoints(); void deallocateSpritePoints( );
void allocateSpritePoints(); void allocateSpritePoints( );
void resetScrollPeriod(); void resetScrollPeriod( );
void updateScrollPeriod(); void updateScrollPeriod( );
void scroll(bool forward); void scroll( bool forward );
private: private:
void resetTweens(Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime);
unsigned int loopIncrement(unsigned int offset, unsigned int i, unsigned int size); void resetTweens( Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime );
unsigned int loopDecrement(unsigned int offset, unsigned int i, unsigned int size); unsigned int loopIncrement( unsigned int offset, unsigned int i, unsigned int size );
unsigned int loopDecrement( unsigned int offset, unsigned int i, unsigned int size );
bool layoutMode_; bool layoutMode_;
std::vector<Component *> *spriteList_; std::vector<Component *> *spriteList_;
@ -100,7 +99,6 @@ private:
std::vector<AnimationEvents *> *tweenPoints_; std::vector<AnimationEvents *> *tweenPoints_;
unsigned int itemIndex_; unsigned int itemIndex_;
unsigned int componentIndex_;
unsigned int selectedOffsetIndex_; unsigned int selectedOffsetIndex_;
float scrollAcceleration_; float scrollAcceleration_;
@ -114,10 +112,7 @@ private:
std::string layoutKey_; std::string layoutKey_;
std::string imageType_; std::string imageType_;
std::vector<Item *> *items_; std::vector<Item *> *items_;
std::vector<Component *> components_; std::vector<Component *> components_;
}; };

View File

@ -529,11 +529,11 @@ void Page::selectRandom()
if(activeMenu_.size() > 0 && activeMenu_[0]) if(activeMenu_.size() > 0 && activeMenu_[0])
{ {
activeMenu_[0]->random(); activeMenu_[0]->random();
unsigned int index = activeMenu_[0]->getSelectedIndex(); unsigned int index = activeMenu_[0]->getScrollOffsetIndex();
for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
menu->setSelectedIndex(index); menu->setScrollOffsetIndex(index);
} }
} }
} }

View File

@ -21,7 +21,7 @@
std::string retrofe_version_major = "0"; std::string retrofe_version_major = "0";
std::string retrofe_version_minor = "8"; std::string retrofe_version_minor = "8";
std::string retrofe_version_build = "9"; std::string retrofe_version_build = "10";
std::string Version::getString( ) std::string Version::getString( )