Skip to content

Commit

Permalink
Add top up animation
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasHalse committed Feb 28, 2025
1 parent c852df2 commit 49123e9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:kivy 2.1.0

<PurchaseCompletedPopup>:
<CreditsAnimationPopup>:
size_hint: (0.8, 0.5)
auto_dismiss: True
GridLayout:
Expand All @@ -22,13 +22,14 @@
orientation: "vertical"
size_hint: (1, .9)
Label:
id: titleLabel
text_size: self.size
padding: 10
halign: 'center'
valign: 'middle'
font_size: 42
bold: True
text: 'Thank you for your purchase!'
text: 'TITLE'

Label:
id: creditsLabel
Expand Down
2 changes: 1 addition & 1 deletion GuiApp/kv/main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#:include kv/editUserScreen.kv
#:include kv/historyScreen.kv
#:include kv/editSnackScreen.kv
#:include kv/purchaseCompletedPopup.kv
#:include kv/creditsAnimationPopup.kv
#:include kv/clickableTable.kv
#:include kv/purchaseSummaryPopup.kv
#:include kv/editSummaryPopup.kv
Expand Down
9 changes: 5 additions & 4 deletions GuiApp/widgets/buyScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from widgets.customScreenManager import CustomScreenManager
from widgets.headerBodyLayout import HeaderBodyScreen
from widgets.popups.purchaseCompletedPopup import PurchaseCompletedPopup
from widgets.popups.creditsAnimationPopup import CreditsAnimationPopup
from widgets.popups.errorMessagePopup import ErrorMessagePopup
from widgets.clickableTable import ClickableTable
from widgets.settingsManager import SettingName
Expand Down Expand Up @@ -223,9 +223,10 @@ def onBuy(self):
# Update current patron with new data
self.screenManager.refreshCurrentPatron()

PurchaseCompletedPopup(
creditsBeforePurchase=creditsBeforePurchase,
creditsAfterPurchase=creditsAfterPurchase,
CreditsAnimationPopup(
title="Thank you for your purchase!",
creditsBefore=creditsBeforePurchase,
creditsAfter=creditsAfterPurchase,
).open()

if self.screenManager.settingsManager.get_setting_value(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
from kivy.clock import Clock


class PurchaseCompletedPopup(ModalView):
def __init__(
self, creditsBeforePurchase: float, creditsAfterPurchase: float, **kwargs
):
class CreditsAnimationPopup(ModalView):
def __init__(self, title: str, creditsBefore: float, creditsAfter: float, **kwargs):
super().__init__(**kwargs)
self.creditsBeforePurchase = creditsBeforePurchase
self.creditsAfterPurchase = creditsAfterPurchase
self.creditsBefore = creditsBefore
self.creditsAfter = creditsAfter
self.animationStartDelay = 1.0
self.animationTime = 2.0
self.postAnimationTime = 2.0
self.postAnimationTime = 1.0
self.timeOfStart = time() + self.animationStartDelay
self.ids["creditsLabel"].text = f"Your credits: \n{creditsBeforePurchase:.2f}"
self.ids["creditsLabel"].text = f"Your credits: \n{creditsBefore:.2f}"
self.ids["titleLabel"].text = title
# 60 FPS update
Clock.schedule_interval(self.updateCredits, 0.01666)

Expand All @@ -27,13 +26,11 @@ def updateCredits(self, dt):
if timeElapsed < self.animationTime:
animationTimeProgress = timeElapsed / self.animationTime
animationState = AnimationTransition.in_out_circ(animationTimeProgress)
creditsAnimation = self.creditsBeforePurchase + (
self.creditsAfterPurchase - self.creditsBeforePurchase
creditsAnimation = self.creditsBefore + (
self.creditsAfter - self.creditsBefore
) * (animationState)
self.ids["creditsLabel"].text = f"Your credits: \n{creditsAnimation:.2f}"
else:
self.ids[
"creditsLabel"
].text = f"Your credits: \n{self.creditsAfterPurchase:.2f}"
self.ids["creditsLabel"].text = f"Your credits: \n{self.creditsAfter:.2f}"
Clock.unschedule(self.updateCredits)
Clock.schedule_once(self.dismiss, self.postAnimationTime)
7 changes: 7 additions & 0 deletions GuiApp/widgets/topUpPaymentScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from widgets.customScreenManager import CustomScreenManager
from widgets.headerBodyLayout import HeaderBodyScreen
from widgets.settingsManager import SettingName
from widgets.popups.creditsAnimationPopup import CreditsAnimationPopup
from database import addCredits, addTopUpTransaction


Expand Down Expand Up @@ -43,6 +44,12 @@ def onConfirm(self, *largs):
# Update current patron with new data
self.screenManager.refreshCurrentPatron()

CreditsAnimationPopup(
title="Thank you for your top-up!",
creditsBefore=self.userData.totalCredits,
creditsAfter=self.userData.totalCredits + self.amountToBePayed,
).open()

self.screenManager.transitionToScreen(
"mainUserPage", transitionDirection="right"
)
Expand Down

0 comments on commit 49123e9

Please # to comment.