Remove redundancy and make control flow a bit simpler

This commit is contained in:
Tobias Loose
2013-12-07 09:04:24 +01:00
parent 31b353c5ec
commit 2b0f50bb88
3 changed files with 18 additions and 32 deletions
-1
View File
@@ -35,7 +35,6 @@ public:
private: private:
InOutQuadEasing mScrollOffset; //[-1,1]. defines the current rotation of the cards InOutQuadEasing mScrollOffset; //[-1,1]. defines the current rotation of the cards
InOutQuadEasing mSlide; //[-1,1]. defines, the y-offset of the cards InOutQuadEasing mSlide; //[-1,1]. defines, the y-offset of the cards
int mScrollTarget; //0 <= mScrollTarget < mCards.size(). defines where to scroll to if the current animation is a scroll animation
}; };
#endif //_CAROUSEL_DECK_VIEW_H_ #endif //_CAROUSEL_DECK_VIEW_H_
+3 -8
View File
@@ -3,7 +3,7 @@
const float CarouselDeckView::slide_animation_duration = 0.6f; const float CarouselDeckView::slide_animation_duration = 0.6f;
CarouselDeckView::CarouselDeckView() : CarouselDeckView::CarouselDeckView() :
DeckView(10), mScrollOffset(0), mSlide(0), mScrollTarget(2) DeckView(10), mScrollOffset(0), mSlide(0)
{ {
} }
@@ -16,20 +16,17 @@ void CarouselDeckView::UpdateViewState(float dt)
{ {
mScrollOffset.update(dt); mScrollOffset.update(dt);
if(mScrollTarget < 2 && mScrollOffset.value <= -1.0f) if(mScrollOffset.value <= -1.0f)
{ {
mScrollOffset.translate(1.0f); mScrollOffset.translate(1.0f);
deck()->prev(); deck()->prev();
reloadIndexes(); reloadIndexes();
mScrollTarget += 1;
} }
else if(mScrollOffset.value >= 1.0f)
if(mScrollTarget > 2 && mScrollOffset.value >= 1.0f)
{ {
mScrollOffset.translate(-1.0f); mScrollOffset.translate(-1.0f);
deck()->next(); deck()->next();
reloadIndexes(); reloadIndexes();
mScrollTarget -= 1;
} }
dirtyCardPos = true; dirtyCardPos = true;
@@ -76,7 +73,6 @@ void CarouselDeckView::Reset()
{ {
mScrollOffset = 0; mScrollOffset = 0;
mSlide = 0; mSlide = 0;
mScrollTarget = 2;
DeckView::Reset(); DeckView::Reset();
} }
@@ -144,7 +140,6 @@ MTGCard * CarouselDeckView::Click(int x, int y)
void CarouselDeckView::changePosition(int offset) void CarouselDeckView::changePosition(int offset)
{ {
mScrollTarget = 2 + offset;
mScrollOffset.start(offset, 0.3f*abs(offset)); mScrollOffset.start(offset, 0.3f*abs(offset));
last_user_activity = 0; last_user_activity = 0;
+7 -15
View File
@@ -30,24 +30,23 @@ void GridDeckView::UpdateViewState(float dt)
{ {
mScrollOffset.update(dt); mScrollOffset.update(dt);
if(mScrollOffset.finished()) if(mScrollOffset.value <= -1.0f)
{
if(mScrollOffset.start_value > mScrollOffset.value)
{ {
deck()->next(); deck()->next();
deck()->next(); deck()->next();
mScrollOffset.translate(1.0f);
reloadIndexes();
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1; mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
} }
else if(mScrollOffset.start_value < mScrollOffset.value) else if(mScrollOffset.value >= 1.0f)
{ {
deck()->prev(); deck()->prev();
deck()->prev(); deck()->prev();
mScrollOffset.translate(-1.0f);
reloadIndexes();
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1; mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
} }
reloadIndexes();
mScrollOffset.value = 0;
}
dirtyCardPos = true; dirtyCardPos = true;
} }
@@ -179,14 +178,7 @@ MTGCard * GridDeckView::Click(int x, int y)
void GridDeckView::changePosition(int offset) void GridDeckView::changePosition(int offset)
{ {
if(offset < 0) mScrollOffset.start(-1.0f * offset, scroll_animation_duration * abs(offset));
{
mScrollOffset.start( 1.0f, scroll_animation_duration);
}
else if(offset > 0)
{
mScrollOffset.start(-1.0f, scroll_animation_duration);
}
last_user_activity = 0; last_user_activity = 0;
} }