Remove redundancy and make control flow a bit simpler
This commit is contained in:
@@ -35,7 +35,6 @@ public:
|
||||
private:
|
||||
InOutQuadEasing mScrollOffset; //[-1,1]. defines the current rotation 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_
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const float CarouselDeckView::slide_animation_duration = 0.6f;
|
||||
|
||||
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);
|
||||
|
||||
if(mScrollTarget < 2 && mScrollOffset.value <= -1.0f)
|
||||
if(mScrollOffset.value <= -1.0f)
|
||||
{
|
||||
mScrollOffset.translate(1.0f);
|
||||
deck()->prev();
|
||||
reloadIndexes();
|
||||
mScrollTarget += 1;
|
||||
}
|
||||
|
||||
if(mScrollTarget > 2 && mScrollOffset.value >= 1.0f)
|
||||
else if(mScrollOffset.value >= 1.0f)
|
||||
{
|
||||
mScrollOffset.translate(-1.0f);
|
||||
deck()->next();
|
||||
reloadIndexes();
|
||||
mScrollTarget -= 1;
|
||||
}
|
||||
|
||||
dirtyCardPos = true;
|
||||
@@ -76,7 +73,6 @@ void CarouselDeckView::Reset()
|
||||
{
|
||||
mScrollOffset = 0;
|
||||
mSlide = 0;
|
||||
mScrollTarget = 2;
|
||||
DeckView::Reset();
|
||||
}
|
||||
|
||||
@@ -144,7 +140,6 @@ MTGCard * CarouselDeckView::Click(int x, int y)
|
||||
|
||||
void CarouselDeckView::changePosition(int offset)
|
||||
{
|
||||
mScrollTarget = 2 + offset;
|
||||
mScrollOffset.start(offset, 0.3f*abs(offset));
|
||||
|
||||
last_user_activity = 0;
|
||||
|
||||
@@ -30,24 +30,23 @@ void GridDeckView::UpdateViewState(float dt)
|
||||
{
|
||||
mScrollOffset.update(dt);
|
||||
|
||||
if(mScrollOffset.finished())
|
||||
if(mScrollOffset.value <= -1.0f)
|
||||
{
|
||||
if(mScrollOffset.start_value > mScrollOffset.value)
|
||||
{
|
||||
deck()->next();
|
||||
deck()->next();
|
||||
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
|
||||
}
|
||||
else if(mScrollOffset.start_value < mScrollOffset.value)
|
||||
{
|
||||
deck()->prev();
|
||||
deck()->prev();
|
||||
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
|
||||
}
|
||||
deck()->next();
|
||||
deck()->next();
|
||||
mScrollOffset.translate(1.0f);
|
||||
reloadIndexes();
|
||||
|
||||
mScrollOffset.value = 0;
|
||||
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
|
||||
}
|
||||
else if(mScrollOffset.value >= 1.0f)
|
||||
{
|
||||
deck()->prev();
|
||||
deck()->prev();
|
||||
mScrollOffset.translate(-1.0f);
|
||||
reloadIndexes();
|
||||
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
|
||||
}
|
||||
|
||||
dirtyCardPos = true;
|
||||
}
|
||||
|
||||
@@ -179,14 +178,7 @@ MTGCard * GridDeckView::Click(int x, int y)
|
||||
|
||||
void GridDeckView::changePosition(int offset)
|
||||
{
|
||||
if(offset < 0)
|
||||
{
|
||||
mScrollOffset.start( 1.0f, scroll_animation_duration);
|
||||
}
|
||||
else if(offset > 0)
|
||||
{
|
||||
mScrollOffset.start(-1.0f, scroll_animation_duration);
|
||||
}
|
||||
mScrollOffset.start(-1.0f * offset, scroll_animation_duration * abs(offset));
|
||||
last_user_activity = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user