mirror of
https://github.com/DragonMinded/jubeatmenu.git
synced 2025-02-25 21:58:38 +01:00
Clean up a few things.
Allow multiple inputs to be queued for scrolling. Fix freezing animations if clock goes backwards. Refactor display Tick() to be less messy.
This commit is contained in:
parent
935aba2000
commit
c6fa4d43b1
@ -18,7 +18,7 @@ Animation::~Animation()
|
|||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::Animate(int animationOffset, int animationDistance, double pixelsPerSecond)
|
void Animation::Animate(int animationOffset, int animationDistance, double pixelsPerSecond, bool allowDeceleration)
|
||||||
{
|
{
|
||||||
if (isAnimating) { return; }
|
if (isAnimating) { return; }
|
||||||
|
|
||||||
@ -26,8 +26,9 @@ void Animation::Animate(int animationOffset, int animationDistance, double pixel
|
|||||||
location = 0.0;
|
location = 0.0;
|
||||||
offset = animationOffset;
|
offset = animationOffset;
|
||||||
speed = pixelsPerSecond / (1000.0);
|
speed = pixelsPerSecond / (1000.0);
|
||||||
|
originalSpeed = speed;
|
||||||
speedChangeLocation = (double)abs(animationDistance) * SPEED_REDUCE_LOCATION;
|
speedChangeLocation = (double)abs(animationDistance) * SPEED_REDUCE_LOCATION;
|
||||||
speedChanges = 0;
|
speedChanges = allowDeceleration ? 0 : MAX_SPEED_CHANGES;
|
||||||
isAnimating = true;
|
isAnimating = true;
|
||||||
lastMilliseconds = CurrentMilliseconds();
|
lastMilliseconds = CurrentMilliseconds();
|
||||||
}
|
}
|
||||||
@ -37,6 +38,14 @@ bool Animation::IsAnimating()
|
|||||||
return isAnimating;
|
return isAnimating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::CancelDeceleration()
|
||||||
|
{
|
||||||
|
if (!isAnimating) { return; }
|
||||||
|
|
||||||
|
speed = originalSpeed;
|
||||||
|
speedChanges = MAX_SPEED_CHANGES;
|
||||||
|
}
|
||||||
|
|
||||||
int Animation::Position()
|
int Animation::Position()
|
||||||
{
|
{
|
||||||
int position = (unsigned int)location;
|
int position = (unsigned int)location;
|
||||||
@ -54,8 +63,15 @@ LONG Animation::CurrentMilliseconds()
|
|||||||
void Animation::Tick()
|
void Animation::Tick()
|
||||||
{
|
{
|
||||||
LONG currentMilliseconds = CurrentMilliseconds();
|
LONG currentMilliseconds = CurrentMilliseconds();
|
||||||
if (currentMilliseconds - lastMilliseconds > 0)
|
if (currentMilliseconds - lastMilliseconds != 0)
|
||||||
{
|
{
|
||||||
|
if (currentMilliseconds - lastMilliseconds < 0)
|
||||||
|
{
|
||||||
|
// We went backwards?
|
||||||
|
lastMilliseconds = currentMilliseconds;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate how much we should have moved
|
// Calculate how much we should have moved
|
||||||
location += speed * (double)(currentMilliseconds - lastMilliseconds);
|
location += speed * (double)(currentMilliseconds - lastMilliseconds);
|
||||||
if (location >= abs(distance))
|
if (location >= abs(distance))
|
||||||
|
@ -10,7 +10,8 @@ public:
|
|||||||
Animation();
|
Animation();
|
||||||
~Animation();
|
~Animation();
|
||||||
|
|
||||||
void Animate(int animationOffset, int animationDistance, double pixelsPerSecond);
|
void Animate(int animationOffset, int animationDistance, double pixelsPerSecond, bool allowDeceleration);
|
||||||
|
void CancelDeceleration();
|
||||||
bool IsAnimating();
|
bool IsAnimating();
|
||||||
void Tick();
|
void Tick();
|
||||||
int Position();
|
int Position();
|
||||||
@ -24,5 +25,6 @@ private:
|
|||||||
int speedChanges;
|
int speedChanges;
|
||||||
int offset;
|
int offset;
|
||||||
double speed;
|
double speed;
|
||||||
|
double originalSpeed;
|
||||||
LONG lastMilliseconds;
|
LONG lastMilliseconds;
|
||||||
};
|
};
|
||||||
|
@ -368,6 +368,8 @@ Display::Display(HINSTANCE hInstance, IO *ioInst, Menu *mInst)
|
|||||||
selected = 0;
|
selected = 0;
|
||||||
newPage = -1;
|
newPage = -1;
|
||||||
lastLocation = 0;
|
lastLocation = 0;
|
||||||
|
leftPresses = 0;
|
||||||
|
rightPresses = 0;
|
||||||
|
|
||||||
// Register the callback
|
// Register the callback
|
||||||
WNDCLASS wc = { };
|
WNDCLASS wc = { };
|
||||||
@ -405,37 +407,74 @@ Display::~Display()
|
|||||||
delete globalAnimation;
|
delete globalAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Display::InvalidateOnUpdates()
|
||||||
|
{
|
||||||
|
unsigned int buttonsHeld = io->ButtonsHeld();
|
||||||
|
bool update = false;
|
||||||
|
|
||||||
|
if (globalButtonsHeld != buttonsHeld)
|
||||||
|
{
|
||||||
|
globalButtonsHeld = buttonsHeld;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (globalSelected != selected)
|
||||||
|
{
|
||||||
|
globalSelected = selected;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (lastLocation != globalAnimation->Position())
|
||||||
|
{
|
||||||
|
lastLocation = globalAnimation->Position();
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (globalPage != page)
|
||||||
|
{
|
||||||
|
globalPage = page;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (globalSeconds != menu->SecondsLeft())
|
||||||
|
{
|
||||||
|
globalSeconds = menu->SecondsLeft();
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update)
|
||||||
|
{
|
||||||
|
InvalidateRect(hwnd, NULL, FALSE);
|
||||||
|
UpdateWindow(hwnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Display::Tick(void)
|
void Display::Tick(void)
|
||||||
{
|
{
|
||||||
/* Don't handle input while animating */
|
/* Make sure animations happen */
|
||||||
unsigned int buttonsHeld = io->ButtonsHeld();
|
|
||||||
globalAnimation->Tick();
|
globalAnimation->Tick();
|
||||||
|
|
||||||
|
/* Make sure we respect multiple inputs while animating */
|
||||||
|
unsigned int max_pages = ((menu->NumberOfEntries() - GAMES_PER_PAGE) + 2) / 3;
|
||||||
|
if (io->ButtonPressed(BUTTON_13))
|
||||||
|
{
|
||||||
|
leftPresses ++;
|
||||||
|
if (page < (max_pages - 1))
|
||||||
|
{
|
||||||
|
/* We're not at the last page, so quick-scroll the current animation */
|
||||||
|
globalAnimation->CancelDeceleration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (io->ButtonPressed(BUTTON_14))
|
||||||
|
{
|
||||||
|
rightPresses ++;
|
||||||
|
if (page > 0)
|
||||||
|
{
|
||||||
|
/* We're not at the last page, so quick-scroll the current animation */
|
||||||
|
globalAnimation->CancelDeceleration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't handle game select input while animating */
|
||||||
if (globalAnimation->IsAnimating())
|
if (globalAnimation->IsAnimating())
|
||||||
{
|
{
|
||||||
bool update = false;
|
InvalidateOnUpdates();
|
||||||
|
|
||||||
if (globalButtonsHeld != buttonsHeld)
|
|
||||||
{
|
|
||||||
globalButtonsHeld = buttonsHeld;
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (lastLocation != globalAnimation->Position())
|
|
||||||
{
|
|
||||||
lastLocation = globalAnimation->Position();
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (globalSeconds != menu->SecondsLeft())
|
|
||||||
{
|
|
||||||
globalSeconds = menu->SecondsLeft();
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update)
|
|
||||||
{
|
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
|
||||||
UpdateWindow(hwnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageHandler();
|
MessageHandler();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -444,12 +483,9 @@ void Display::Tick(void)
|
|||||||
if (newPage >= 0)
|
if (newPage >= 0)
|
||||||
{
|
{
|
||||||
page = newPage;
|
page = newPage;
|
||||||
globalPage = page;
|
|
||||||
newPage = -1;
|
newPage = -1;
|
||||||
globalButtonsHeld = buttonsHeld;
|
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
|
||||||
UpdateWindow(hwnd);
|
|
||||||
|
|
||||||
|
InvalidateOnUpdates();
|
||||||
MessageHandler();
|
MessageHandler();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -460,25 +496,46 @@ void Display::Tick(void)
|
|||||||
/* Figure out actions */
|
/* Figure out actions */
|
||||||
if (menu->NumberOfEntries() > GAMES_PER_PAGE)
|
if (menu->NumberOfEntries() > GAMES_PER_PAGE)
|
||||||
{
|
{
|
||||||
unsigned int max_pages = ((menu->NumberOfEntries() - GAMES_PER_PAGE) + 2) / 3;
|
|
||||||
|
|
||||||
/* Activate page left/right buttons */
|
/* Activate page left/right buttons */
|
||||||
if (io->ButtonPressed(BUTTON_13))
|
if (leftPresses > 0)
|
||||||
{
|
{
|
||||||
/* Scroll left */
|
/* Scroll left */
|
||||||
|
if (page < (max_pages - 1))
|
||||||
|
{
|
||||||
|
/* We have more pages we can animate scrolling to */
|
||||||
|
leftPresses --;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Next page is the end, we should decelerate */
|
||||||
|
leftPresses = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (page < max_pages)
|
if (page < max_pages)
|
||||||
{
|
{
|
||||||
globalAnimation->Animate(0, -BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED);
|
globalAnimation->Animate(0, -BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED, leftPresses == 0);
|
||||||
lastLocation = globalAnimation->Position();
|
lastLocation = globalAnimation->Position();
|
||||||
newPage = page + 1;
|
newPage = page + 1;
|
||||||
moved = true;
|
moved = true;
|
||||||
}
|
}
|
||||||
} else if (io->ButtonPressed(BUTTON_14))
|
}
|
||||||
|
else if (rightPresses > 0)
|
||||||
{
|
{
|
||||||
/* Scroll right */
|
/* Scroll right */
|
||||||
|
if (page > 1)
|
||||||
|
{
|
||||||
|
/* We have more pages we can animate scrolling to */
|
||||||
|
rightPresses --;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Next page is the end, we should decelerate */
|
||||||
|
rightPresses = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (page > 0)
|
if (page > 0)
|
||||||
{
|
{
|
||||||
globalAnimation->Animate(-BUTTON_HORIZONTAL_STRIDE, BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED);
|
globalAnimation->Animate(-BUTTON_HORIZONTAL_STRIDE, BUTTON_HORIZONTAL_STRIDE, ANIMATION_SPEED, rightPresses == 0);
|
||||||
lastLocation = globalAnimation->Position();
|
lastLocation = globalAnimation->Position();
|
||||||
page--;
|
page--;
|
||||||
newPage = page;
|
newPage = page;
|
||||||
@ -503,34 +560,7 @@ void Display::Tick(void)
|
|||||||
|
|
||||||
/* Update the screen to show any button presses or selection
|
/* Update the screen to show any button presses or selection
|
||||||
changes. */
|
changes. */
|
||||||
bool update = false;
|
InvalidateOnUpdates();
|
||||||
if (globalButtonsHeld != buttonsHeld)
|
|
||||||
{
|
|
||||||
globalButtonsHeld = buttonsHeld;
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (globalSelected != selected)
|
|
||||||
{
|
|
||||||
globalSelected = selected;
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (globalPage != page)
|
|
||||||
{
|
|
||||||
globalPage = page;
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (globalSeconds != menu->SecondsLeft())
|
|
||||||
{
|
|
||||||
globalSeconds = menu->SecondsLeft();
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update)
|
|
||||||
{
|
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
|
||||||
UpdateWindow(hwnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageHandler();
|
MessageHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ public:
|
|||||||
unsigned int GetSelectedItem();
|
unsigned int GetSelectedItem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InvalidateOnUpdates();
|
||||||
|
|
||||||
HINSTANCE inst;
|
HINSTANCE inst;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
|
|
||||||
@ -57,4 +59,6 @@ private:
|
|||||||
unsigned int page;
|
unsigned int page;
|
||||||
unsigned int selected;
|
unsigned int selected;
|
||||||
int lastLocation;
|
int lastLocation;
|
||||||
|
unsigned int leftPresses;
|
||||||
|
unsigned int rightPresses;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user