Skip to content

Commit

Permalink
overlay adjustments (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 authored Nov 1, 2023
1 parent 56344c2 commit 50f4310
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 41 deletions.
1 change: 1 addition & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ def clean_up():
shutil.copy("config/filter_aspects.yaml", f"{release_dir}/config/")
shutil.copy("README.md", f"{release_dir}/")
shutil.copytree("assets", f"{release_dir}/assets")
os.rename(f"{release_dir}/main.exe", f"{release_dir}/d4lf.exe")
clean_up()
4 changes: 2 additions & 2 deletions config/filter_affixes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# itemType must be any of:
# helm, armor, pants, gloves, boots, ring, amulet, axe, tow-handed axe,
# sword, two-handed sword, mace, two-handed mace, scythe, two-handed scythe,
# bow, bracers, crossbow, dagger, polarm, shield, stff, wand, offhand
# bow, bracers, crossbow, dagger, polarm, shield, stff, wand, offhand, totem


Filters:
Expand Down Expand Up @@ -48,7 +48,7 @@ Filters:

# Example take all boots and rings
- TakeAll:
itemType: [boots, ring]
itemType: [boots]
minPower: 0
affixPool:
minAffixCount: 0
2 changes: 1 addition & 1 deletion config/params.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[general]
; How many tabs should be checked for items in chest. Note: All 5 Tabs must be unlocked!
check_chest_tabs=3
check_chest_tabs=2

[char]
; Hotkey to open inventory
Expand Down
1 change: 1 addition & 0 deletions src/item/data/item_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ class ItemType(Enum):
Staff = "staff"
Wand = "wand"
Offhand = "offhand"
Totem = "totem"
36 changes: 18 additions & 18 deletions src/item/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ def should_keep(item: Item):

if matching_affix_count >= filter_min_affix_count:
affix_debug_msg = [affix.type for affix in item.affixes]
Logger.info(f"Matched with affix filter: {filter_name}: {affix_debug_msg}")
Logger.info(f"Matched {filter_name}: {affix_debug_msg}")
return True

if item.aspect:
for filter_data in filter_aspects:
filter_aspect_pool = [filter_data] if isinstance(filter_data, str) else filter_data
for aspect in filter_aspect_pool:
aspect_name, *rest = aspect if isinstance(aspect, list) else [aspect]
threshold = rest[0] if rest else None
condition = rest[1] if len(rest) > 1 else "larger"

if item.aspect.type == aspect_name:
if (
threshold is None
or item.aspect.value is None
or (condition == "larger" and item.aspect.value >= threshold)
or (condition == "smaller" and item.aspect.value <= threshold)
):
Logger.info(f"Matched with aspect filter: {filter_name}: {item.aspect.type}")
return True
if item.aspect:
for filter_data in filter_aspects:
filter_aspect_pool = [filter_data] if isinstance(filter_data, str) else filter_data
for aspect in filter_aspect_pool:
aspect_name, *rest = aspect if isinstance(aspect, list) else [aspect]
threshold = rest[0] if rest else None
condition = rest[1] if len(rest) > 1 else "larger"

if item.aspect.type == aspect_name:
if (
threshold is None
or item.aspect.value is None
or (condition == "larger" and item.aspect.value >= threshold)
or (condition == "smaller" and item.aspect.value <= threshold)
):
Logger.info(f"Matched: [{item.aspect.type}, {item.aspect.value}]")
return True

return False
11 changes: 8 additions & 3 deletions src/item/read_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def _closest_to(value, choices):
return min(choices, key=lambda x: abs(x - value))


def _find_number(s):
def _find_number(s, idx: int = 0):
matches = re.findall(r"[+-]?(\d+\.\d+|\.\d+|\d+\.?|\d+)\%?", s)
if "Up to a 5%" in s:
number = matches[1] if len(matches) > 1 else None
number = matches[0] if matches else None
else:
number = matches[idx] if matches and len(matches) > idx else None
if number is not None:
return float(number.replace("+", "").replace("%", ""))
return None
Expand Down Expand Up @@ -103,8 +104,11 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
crop_top = crop(img_item_descr, roi_top)
concatenated_str = image_to_text(crop_top).text.lower().replace("\n", " ")
idx = None
# TODO: Handle common mistakes nicer
if "item power" in concatenated_str:
idx = concatenated_str.index("item power")
elif "ttem power" in concatenated_str:
idx = concatenated_str.index("ttem power")
elif "item" in concatenated_str:
idx = concatenated_str.index("item")
if idx is not None:
Expand Down Expand Up @@ -218,7 +222,8 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
cleaned_str = _clean_str(concatenated_str)

found_key = _closest_match(cleaned_str, aspect_dict, min_score=77)
found_value = _find_number(concatenated_str)
idx = 1 if found_key in ["frostbitten_aspect"] else 0
found_value = _find_number(concatenated_str, idx)

if found_key is not None:
item.aspect = Aspect(found_key, concatenated_str, found_value)
Expand Down
4 changes: 2 additions & 2 deletions src/loot_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def check_items(inv: InventoryBase):
Logger.debug(f" Runtime (DetectItem): {time.time() - start_time:.2f}s")
# Hardcoded rarity filters
if rarity == ItemRarity.Unique:
Logger.info("Matched unique.")
Logger.info("Matched: unique")
continue
if rarity in [ItemRarity.Common, ItemRarity.Magic]:
Logger.info(f"Discard item of rarity: {rarity}")
Expand All @@ -61,7 +61,7 @@ def check_items(inv: InventoryBase):
# Detect contents of item descr
item_descr = read_descr(rarity, croped_descr)
if item_descr is None:
Logger.warning("Failed to read properties. Keeping it.")
Logger.warning("Failed to read properties. Keeping it")
continue
Logger.debug(f" Runtime (ReadItem): {time.time() - start_time_read:.2f}s")

Expand Down
53 changes: 40 additions & 13 deletions src/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,43 @@ def __init__(self):
self.is_minimized = True
self.root = tk.Tk()
self.root.title("LootFilter Overlay")
self.root.attributes("-alpha", 0.8)
self.root.attributes("-alpha", 0.89)
self.root.overrideredirect(True)
# self.root.wm_attributes("-transparentcolor", "white")
self.root.wm_attributes("-topmost", True)

self.screen_width = self.root.winfo_screenwidth()
self.screen_height = self.root.winfo_screenheight()
self.initial_height = int(30)
self.initial_width = int(self.screen_width * 0.18)
self.maximized_height = int(160)
self.initial_height = int(self.root.winfo_screenheight() * 0.027)
self.initial_width = int(self.screen_width * 0.05)
self.maximized_height = int(self.initial_height * 3.85)
self.maximized_width = int(self.initial_width * 6)

self.canvas = tk.Canvas(self.root, bg="black", height=self.initial_height, width=self.initial_width, highlightthickness=0)
self.root.geometry(f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+0")
self.root.geometry(
f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}"
)
self.canvas.pack()

self.toggle_button = tk.Button(self.root, text="toggle", bg="#222222", fg="#555555", borderwidth=0, command=self.toggle_size)
self.canvas.create_window(28, 15, window=self.toggle_button)
self.toggle_button = tk.Button(
self.root,
text="toggle",
bg="#222222",
fg="#555555",
borderwidth=0,
command=self.toggle_size,
)
self.canvas.create_window(int(self.initial_width * 0.3), self.initial_height // 2, window=self.toggle_button)

self.filter_button = tk.Button(self.root, text="filter", bg="#222222", fg="#555555", borderwidth=0, command=self.filter_items)
self.canvas.create_window(70, 15, window=self.filter_button)
self.filter_button = tk.Button(
self.root,
text="filter",
bg="#222222",
fg="#555555",
borderwidth=0,
command=self.filter_items,
)
self.canvas.create_window(int(self.initial_width * 0.73), self.initial_height // 2, window=self.filter_button)

self.terminal_listbox = tk.Listbox(
self.canvas,
Expand All @@ -58,7 +75,13 @@ def __init__(self):
borderwidth=0,
font=("Courier New", 9),
)
self.terminal_listbox.place(relx=0, rely=0, relwidth=1, relheight=1, y=30)
self.terminal_listbox.place(
relx=0,
rely=0,
relwidth=1,
relheight=1 - (self.initial_height / self.maximized_height),
y=self.initial_height,
)

# Setup the listbox logger handler
listbox_handler = ListboxHandler(self.terminal_listbox)
Expand All @@ -68,10 +91,14 @@ def __init__(self):
def toggle_size(self):
if not self.is_minimized:
self.canvas.config(height=self.initial_height, width=self.initial_width)
self.root.geometry(f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+0")
self.root.geometry(
f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}"
)
else:
self.canvas.config(height=self.maximized_height, width=self.initial_width)
self.root.geometry(f"{self.initial_width}x{self.maximized_height}+{self.screen_width//2 - self.initial_width//2}+0")
self.canvas.config(height=self.maximized_height, width=self.maximized_width)
self.root.geometry(
f"{self.maximized_width}x{self.maximized_height}+{self.screen_width//2 - self.maximized_width//2}+{self.screen_height - self.maximized_height}"
)
self.is_minimized = not self.is_minimized
move_window_to_foreground()

Expand Down
2 changes: 1 addition & 1 deletion src/ui/inventory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo
slot_img = crop(img, slot_roi)
hsv_image = cv2.cvtColor(slot_img, cv2.COLOR_BGR2HSV)
mean_value_of_high = np.mean(hsv_image[:, :, 2])
if mean_value_of_high > 40:
if mean_value_of_high > 53:
occupied_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi)))
else:
empty_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi)))
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.1.0"

0 comments on commit 50f4310

Please sign in to comment.