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,
Page &p,
bool layoutMode,
float scaleX,
float scaleY,
Font *font,
std::string layoutKey,
std::string imageType);
ScrollingList(const ScrollingList &copy); ScrollingList( Configuration &c,
virtual ~ScrollingList(); Page &p,
void triggerEnterEvent(); bool layoutMode,
void triggerExitEvent(); float scaleX,
void triggerMenuEnterEvent(int menuIndex = -1); float scaleY,
void triggerMenuExitEvent(int menuIndex = -1); Font *font,
void triggerGameEnterEvent(int menuIndex = -1); std::string layoutKey,
void triggerGameExitEvent(int menuIndex = -1); std::string imageType );
void triggerHighlightEnterEvent(int menuIndex = -1);
void triggerHighlightExitEvent(int menuIndex = -1);
bool allocateTexture(unsigned int index, Item *i); ScrollingList( const ScrollingList &copy );
void deallocateTexture(unsigned int index); virtual ~ScrollingList( );
void setItems(std::vector<Item *> *items); void triggerEnterEvent( );
void destroyItems(); void triggerExitEvent( );
void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints); void triggerMenuEnterEvent( int menuIndex = -1 );
unsigned int getSelectedIndex(); void triggerMenuExitEvent( int menuIndex = -1 );
void setSelectedIndex(unsigned int index); void triggerGameEnterEvent( int menuIndex = -1 );
unsigned int getSize(); void triggerGameExitEvent( int menuIndex = -1 );
void pageUp(); void triggerHighlightEnterEvent( int menuIndex = -1 );
void pageDown(); void triggerHighlightExitEvent( int menuIndex = -1 );
void letterUp();
void letterDown(); bool allocateTexture( unsigned int index, Item *i );
void letterChange(bool increment); void deallocateTexture( unsigned int index );
void random(); void setItems( std::vector<Item *> *items );
bool isIdle(); void destroyItems( );
unsigned int getScrollOffsetIndex(); void setPoints( std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints );
void setScrollOffsetIndex(unsigned int index); unsigned int getSelectedIndex( );
void setSelectedIndex(int selectedIndex); void setSelectedIndex( unsigned int index );
Item *getItemByOffset(int offset); unsigned int getSize( );
Item *getSelectedItem(); void pageUp( );
void allocateGraphicsMemory(); void pageDown( );
void freeGraphicsMemory(); void letterUp( );
void update(float dt); void letterDown( );
void draw(); void letterChange( bool increment );
void draw(unsigned int layer); void random( );
void setScrollAcceleration(float value); bool isIdle( );
void setStartScrollTime(float value); unsigned int getScrollOffsetIndex( );
void setScrollOffsetIndex( unsigned int index );
void setSelectedIndex( int selectedIndex );
Item *getItemByOffset( int offset );
Item *getSelectedItem( );
void allocateGraphicsMemory( );
void freeGraphicsMemory( );
void update( float dt );
void draw( );
void draw( unsigned int layer );
void setScrollAcceleration( 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,24 +99,20 @@ 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_;
float startScrollTime_; float startScrollTime_;
float scrollPeriod_; float scrollPeriod_;
Configuration &config_; Configuration &config_;
float scaleX_; float scaleX_;
float scaleY_; float scaleY_;
Font *fontInst_; Font *fontInst_;
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( )