Display separate start and end times for drops which start after their campaign starts, or end before their campaign ends
This commit is contained in:
1 parent
c951f000b0
commit
66c361103f
1 file changed
+32
-24
@@ -1304,7 +1304,7 @@ class InventoryOverview:
|
|||||||
self._canvas.bind("<Leave>", lambda e: self._canvas.unbind_all("<MouseWheel>"))
|
self._canvas.bind("<Leave>", lambda e: self._canvas.unbind_all("<MouseWheel>"))
|
||||||
self._canvas.create_window(0, 0, anchor="nw", window=self._main_frame)
|
self._canvas.create_window(0, 0, anchor="nw", window=self._main_frame)
|
||||||
self._campaigns: dict[DropsCampaign, CampaignDisplay] = {}
|
self._campaigns: dict[DropsCampaign, CampaignDisplay] = {}
|
||||||
self._drops: dict[str, MouseOverLabel] = {}
|
self._drops: dict[str, ttk.Label] = {}
|
||||||
|
|
||||||
def _update_visibility(self, campaign: DropsCampaign):
|
def _update_visibility(self, campaign: DropsCampaign):
|
||||||
# True if the campaign is supposed to show, False makes it hidden.
|
# True if the campaign is supposed to show, False makes it hidden.
|
||||||
@@ -1470,7 +1470,7 @@ class InventoryOverview:
|
|||||||
image=image, # type: ignore[arg-type]
|
image=image, # type: ignore[arg-type]
|
||||||
compound="bottom",
|
compound="bottom",
|
||||||
).grid(column=i, row=0, padx=5)
|
).grid(column=i, row=0, padx=5)
|
||||||
self._drops[drop.id] = label = MouseOverLabel(drop_frame)
|
self._drops[drop.id] = label = ttk.Label(drop_frame, justify=tk.CENTER)
|
||||||
self.update_progress(drop, label)
|
self.update_progress(drop, label)
|
||||||
label.grid(column=0, row=1)
|
label.grid(column=0, row=1)
|
||||||
if self._manager.tabs.current_tab() == 1:
|
if self._manager.tabs.current_tab() == 1:
|
||||||
@@ -1483,11 +1483,8 @@ class InventoryOverview:
|
|||||||
self._drops.clear()
|
self._drops.clear()
|
||||||
self._campaigns.clear()
|
self._campaigns.clear()
|
||||||
|
|
||||||
def update_progress(self, drop: TimedDrop, label: MouseOverLabel) -> None:
|
def update_progress(self, drop: TimedDrop, label: ttk.Label) -> None:
|
||||||
# Returns: main text, alt text, text color
|
|
||||||
alt_text: str = ''
|
|
||||||
progress_text: str
|
progress_text: str
|
||||||
reverse: bool = False
|
|
||||||
progress_color: str = ''
|
progress_color: str = ''
|
||||||
if drop.is_claimed:
|
if drop.is_claimed:
|
||||||
progress_color = "green"
|
progress_color = "green"
|
||||||
@@ -1500,25 +1497,26 @@ class InventoryOverview:
|
|||||||
percent=f"{drop.progress:3.1%}",
|
percent=f"{drop.progress:3.1%}",
|
||||||
minutes=drop.required_minutes,
|
minutes=drop.required_minutes,
|
||||||
)
|
)
|
||||||
|
if drop.ends_at < drop.campaign.ends_at:
|
||||||
|
# this drop becomes unavailable earlier than the campaign ends
|
||||||
|
progress_text += '\n' + _("gui", "inventory", "ends").format(
|
||||||
|
time=drop.ends_at.astimezone().replace(microsecond=0, tzinfo=None)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
progress_text = _("gui", "inventory", "minutes_progress").format(
|
progress_text = _("gui", "inventory", "minutes_progress").format(
|
||||||
minutes=drop.required_minutes
|
minutes=drop.required_minutes
|
||||||
)
|
)
|
||||||
if datetime.now(timezone.utc) < drop.starts_at > drop.campaign.starts_at:
|
if datetime.now(timezone.utc) < drop.starts_at > drop.campaign.starts_at:
|
||||||
# this drop can only be earned later than the campaign start
|
# this drop can only be earned later than the campaign start
|
||||||
alt_text = _("gui", "inventory", "starts").format(
|
progress_text += '\n' + _("gui", "inventory", "starts").format(
|
||||||
time=drop.starts_at.astimezone().replace(microsecond=0, tzinfo=None)
|
time=drop.starts_at.astimezone().replace(microsecond=0, tzinfo=None)
|
||||||
)
|
)
|
||||||
reverse = True
|
|
||||||
elif drop.ends_at < drop.campaign.ends_at:
|
elif drop.ends_at < drop.campaign.ends_at:
|
||||||
# this drop becomes unavailable earlier than the campaign ends
|
# this drop becomes unavailable earlier than the campaign ends
|
||||||
alt_text = _("gui", "inventory", "ends").format(
|
progress_text += '\n' + _("gui", "inventory", "ends").format(
|
||||||
time=drop.ends_at.astimezone().replace(microsecond=0, tzinfo=None)
|
time=drop.ends_at.astimezone().replace(microsecond=0, tzinfo=None)
|
||||||
)
|
)
|
||||||
reverse = True
|
label.config(text=progress_text, foreground=progress_color)
|
||||||
label.config(
|
|
||||||
text=progress_text, alt_text=alt_text, reverse=reverse, foreground=progress_color
|
|
||||||
)
|
|
||||||
|
|
||||||
def update_drop(self, drop: TimedDrop) -> None:
|
def update_drop(self, drop: TimedDrop) -> None:
|
||||||
label = self._drops.get(drop.id)
|
label = self._drops.get(drop.id)
|
||||||
@@ -2354,7 +2352,7 @@ if __name__ == "__main__":
|
|||||||
td = total_drops
|
td = total_drops
|
||||||
cm = current_minutes
|
cm = current_minutes
|
||||||
tm = total_minutes
|
tm = total_minutes
|
||||||
ref_stamp = datetime.now(timezone.utc).replace(minute=0, second=0)
|
ref_stamp = datetime.now(timezone.utc)
|
||||||
image_url = (
|
image_url = (
|
||||||
"https://static-cdn.jtvnw.net/twitch-drops-assets-prod/"
|
"https://static-cdn.jtvnw.net/twitch-drops-assets-prod/"
|
||||||
"BENEFIT-81ab5665-b2f4-4179-96e6-74da5a82da28.jpeg"
|
"BENEFIT-81ab5665-b2f4-4179-96e6-74da5a82da28.jpeg"
|
||||||
@@ -2379,6 +2377,7 @@ if __name__ == "__main__":
|
|||||||
timed_drops={},
|
timed_drops={},
|
||||||
claimed_drops=cd,
|
claimed_drops=cd,
|
||||||
total_drops=td,
|
total_drops=td,
|
||||||
|
required_minutes=tm,
|
||||||
remaining_drops=td - cd,
|
remaining_drops=td - cd,
|
||||||
progress=(cd * tm + cm) / (td * tm),
|
progress=(cd * tm + cm) / (td * tm),
|
||||||
remaining_minutes=(td - cd) * tm - cm,
|
remaining_minutes=(td - cd) * tm - cm,
|
||||||
@@ -2390,6 +2389,8 @@ if __name__ == "__main__":
|
|||||||
preconditions=True,
|
preconditions=True,
|
||||||
benefits=benefits,
|
benefits=benefits,
|
||||||
rewards_text=lambda: ', '.join(b.name for b in benefits),
|
rewards_text=lambda: ', '.join(b.name for b in benefits),
|
||||||
|
starts_at=ref_stamp + timedelta(seconds=2),
|
||||||
|
ends_at=ref_stamp + timedelta(days=7) - timedelta(seconds=2),
|
||||||
progress=cm/tm,
|
progress=cm/tm,
|
||||||
current_minutes=cm,
|
current_minutes=cm,
|
||||||
required_minutes=tm,
|
required_minutes=tm,
|
||||||
@@ -2406,7 +2407,6 @@ if __name__ == "__main__":
|
|||||||
tray=False,
|
tray=False,
|
||||||
priority=[],
|
priority=[],
|
||||||
proxy=URL(),
|
proxy=URL(),
|
||||||
autostart=False,
|
|
||||||
language="English",
|
language="English",
|
||||||
autostart_tray=False,
|
autostart_tray=False,
|
||||||
exclude={"Lit Game"},
|
exclude={"Lit Game"},
|
||||||
@@ -2449,7 +2449,7 @@ if __name__ == "__main__":
|
|||||||
channel = create_channel(
|
channel = create_channel(
|
||||||
name="Traitus", status=1, game=None, drops=False, viewers=0, points=0, acl_based=True
|
name="Traitus", status=1, game=None, drops=False, viewers=0, points=0, acl_based=True
|
||||||
)
|
)
|
||||||
gui.channels.display(channel, add=True,)
|
gui.channels.display(channel, add=True)
|
||||||
gui.channels.set_watching(channel)
|
gui.channels.set_watching(channel)
|
||||||
gui.channels.display(
|
gui.channels.display(
|
||||||
create_channel(
|
create_channel(
|
||||||
@@ -2479,7 +2479,7 @@ if __name__ == "__main__":
|
|||||||
gui.channels.get_selection()
|
gui.channels.get_selection()
|
||||||
# Inventory overview
|
# Inventory overview
|
||||||
drop = create_drop(
|
drop = create_drop(
|
||||||
"Wardrobe Cleaning", "Cleaning Masters", ["Fancy Pants"], 2, 7, 239, 240
|
"Wardrobe Cleaning", "Cleaning Masters", ["Fancy Pants"], 2, 7, 0, 240
|
||||||
)
|
)
|
||||||
campaign = drop.campaign
|
campaign = drop.campaign
|
||||||
await gui.inv.add_campaign(campaign)
|
await gui.inv.add_campaign(campaign)
|
||||||
@@ -2500,26 +2500,34 @@ if __name__ == "__main__":
|
|||||||
# Drop progress
|
# Drop progress
|
||||||
gui.display_drop(drop, countdown=False)
|
gui.display_drop(drop, countdown=False)
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
|
|
||||||
gui.progress.start_timer()
|
gui.progress.start_timer()
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
gui.clear_drop()
|
gui.clear_drop()
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
gui.display_drop(drop)
|
|
||||||
|
|
||||||
|
campaign.can_earn = lambda: True
|
||||||
|
gui.inv.update_drop(drop)
|
||||||
|
gui.display_drop(drop)
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
|
drop.current_minutes = 239
|
||||||
|
drop.remaining_minutes = 1
|
||||||
|
drop.progress = 239/240
|
||||||
|
campaign.remaining_minutes -= 1
|
||||||
|
gui.inv.update_drop(drop)
|
||||||
|
gui.display_drop(drop)
|
||||||
await asyncio.sleep(63)
|
await asyncio.sleep(63)
|
||||||
|
|
||||||
drop.current_minutes = 240
|
drop.current_minutes = 240
|
||||||
drop.remaining_minutes = 0
|
drop.remaining_minutes = 0
|
||||||
drop.progress = 1.0
|
drop.progress = 1.0
|
||||||
campaign = drop.campaign
|
|
||||||
campaign.remaining_minutes -= 1
|
campaign.remaining_minutes -= 1
|
||||||
campaign.progress = 3/7
|
campaign.progress = 3/7
|
||||||
campaign.claimed_drops = 3
|
campaign.claimed_drops = 3
|
||||||
campaign.remaining_drops = 4
|
campaign.remaining_drops = 4
|
||||||
gui.display_drop(drop)
|
gui.inv.update_drop(drop)
|
||||||
await asyncio.sleep(10)
|
|
||||||
drop.current_minutes = 0
|
|
||||||
drop.remaining_minutes = 240
|
|
||||||
drop.progress = 0.0
|
|
||||||
gui.display_drop(drop)
|
gui.display_drop(drop)
|
||||||
|
|
||||||
def main_exit(task: asyncio.Task[None]) -> None:
|
def main_exit(task: asyncio.Task[None]) -> None:
|
||||||
|
|||||||
Reference in new issue
Block a user