Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 53 additions & 19 deletions src/ManualClient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
import time
import sys
from typing import Any
from typing import Any, Optional
import typing
from worlds import AutoWorldRegister, network_data_package
import json
Expand Down Expand Up @@ -192,11 +192,11 @@ def on_package(self, cmd: str, args: dict):
logger.info(f"Slot data: {args['slot_data']}")

self.ui.build_tracker_and_locations_table()
self.ui.update_tracker_and_locations_table(update_highlights=True)
self.ui.request_update_tracker_and_locations_table(update_highlights=True)
elif cmd in {"ReceivedItems"}:
self.ui.update_tracker_and_locations_table(update_highlights=True)
self.ui.request_update_tracker_and_locations_table(update_highlights=True)
elif cmd in {"RoomUpdate"}:
self.ui.update_tracker_and_locations_table(update_highlights=False)
self.ui.request_update_tracker_and_locations_table(update_highlights=False)

def on_deathlink(self, data: typing.Dict[str, typing.Any]) -> None:
super().on_deathlink(data)
Expand All @@ -206,12 +206,12 @@ def on_deathlink(self, data: typing.Dict[str, typing.Any]) -> None:

def on_tracker_updated(self, reachable_locations: list[str]):
self.tracker_reachable_locations = reachable_locations
self.ui.update_tracker_and_locations_table(update_highlights=True)
self.ui.request_update_tracker_and_locations_table(update_highlights=True)

def on_tracker_events(self, events: list[str]):
self.tracker_reachable_events = events
if events:
self.ui.update_tracker_and_locations_table(update_highlights=True)
self.ui.request_update_tracker_and_locations_table(update_highlights=True)

def run_gui(self):
"""Import kivy UI system from make_gui() and start running it as self.ui_task."""
Expand Down Expand Up @@ -282,6 +282,9 @@ class ManualManager(ui):
active_item_accordion = 0
active_location_accordion = 0

update_requested_time: Optional[float] = None
update_requested_highlights: bool = False

ctx: ManualContext

def __init__(self, ctx):
Expand Down Expand Up @@ -369,7 +372,7 @@ def update_hints(self):

if rebuild:
self.build_tracker_and_locations_table()
self.update_tracker_and_locations_table()
self.request_update_tracker_and_locations_table()

def build_tracker_and_locations_table(self):
self.tracker_and_locations_panel.clear_widgets()
Expand Down Expand Up @@ -438,6 +441,9 @@ def build_tracker_and_locations_table(self):
if not victory_categories:
victory_categories.add("(No Category)")

for category in self.listed_locations:
self.listed_locations[category].sort(key=self.ctx.location_names.lookup_in_game)

items_length = len(self.ctx.items_received)
tracker_panel_scrollable = TrackerLayoutScrollable(do_scroll=(False, True), bar_width=10)
tracker_panel = TreeView(root_options=dict(text="Items Received (%d)" % (items_length)), size_hint_y=None)
Expand Down Expand Up @@ -501,6 +507,19 @@ def build_tracker_and_locations_table(self):
self.tracker_and_locations_panel.add_widget(tracker_panel_scrollable)
self.tracker_and_locations_panel.add_widget(locations_panel_scrollable)

def check_for_requested_update(self):
current_time = time.time()

# wait 0.25 seconds before executing update, in case there are multiple update requests coming in
if self.update_requested_time and current_time - self.update_requested_time >= 0.25:
self.update_requested_time = None
self.update_tracker_and_locations_table(self.update_requested_highlights)
self.update_requested_highlights = False

def request_update_tracker_and_locations_table(self, update_highlights=False):
self.update_requested_time = time.time()
self.update_requested_highlights = update_highlights or self.update_requested_highlights # if any of the requests wanted highlights, do highlight

def update_tracker_and_locations_table(self, update_highlights=False):
items_length = len(self.ctx.items_received)
locations_length = len(self.ctx.missing_locations)
Expand Down Expand Up @@ -532,7 +551,10 @@ def update_tracker_and_locations_table(self, update_highlights=False):
category_count = 0
category_unique_name_count = 0

# Label (for existing item listings)
existing_item_labels = []
bold_item_labels = []

# for items that were already listed, determine if the qty changed. if it did, add them to the list to be bolded
for item in category_grid.children:
if type(item) is Label:
# Get the item name from the item Label, minus quantity, then do a lookup for count
Expand All @@ -544,28 +566,37 @@ def update_tracker_and_locations_table(self, update_highlights=False):
# Update the label quantity
item.text="%s (%s)" % (item_name, item_count)

if update_highlights:
item.bold = True if old_item_text != item.text else False
if update_highlights and (old_item_text != item.text):
bold_item_labels.append(item_name)

existing_item_labels.append(item_name)

# instead of reusing existing item listings, clear it all out and re-draw with the sorted list
category_grid.clear_widgets()
self.listed_items[category_name].clear()

if item_count > 0:
category_count += item_count
category_unique_name_count += 1
# Label (for all item listings)
sorted_items_received = sorted([
i.item for i in self.ctx.items_received
], key=self.ctx.item_names.lookup_in_game)

# Label (for new item listings)
for network_item in self.ctx.items_received:
item_name = self.ctx.item_names.lookup_in_game(network_item.item)
for network_item in sorted_items_received:
item_name = self.ctx.item_names.lookup_in_game(network_item)
item_data = self.ctx.get_item_by_name(item_name)

if "category" not in item_data or not item_data["category"]:
item_data["category"] = ["(No Category)"]

if category_name in item_data["category"] and network_item.item not in self.listed_items[category_name]:
item_count = len(list(i for i in self.ctx.items_received if i.item == network_item.item))
if category_name in item_data["category"] and network_item not in self.listed_items[category_name]:
item_count = len(list(i for i in self.ctx.items_received if i.item == network_item))
item_text = Label(text="%s (%s)" % (item_name, item_count),
size_hint=(None, None), height=30, width=400, bold=True)

# if the item was previously listed and was bold, or if it wasn't previously listed at all, make it bold
item_text.bold = (update_highlights and (item_name in bold_item_labels or item_name not in existing_item_labels))

category_grid.add_widget(item_text)
self.listed_items[category_name].append(network_item.item)
self.listed_items[category_name].append(network_item)

category_count += item_count
category_unique_name_count += 1
Expand Down Expand Up @@ -687,6 +718,9 @@ def victory_button_callback(self, button):

async def game_watcher_manual(ctx: ManualContext):
while not ctx.exit_event.is_set():
if ctx.ui:
ctx.ui.check_for_requested_update()

if ctx.syncing == True:
sync_msg = [{'cmd': 'Sync'}]
if ctx.locations_checked:
Expand Down
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def __init__(self, display_name: str, script_name: Optional[str] = None, func: O
self.version = version

def add_client_to_launcher() -> None:
version = 2024_11_03 # YYYYMMDD
version = 2024_11_22 # YYYYMMDD
found = False

if "manual" not in icon_paths:
Expand Down