Bugfix: Some NPC's don't open to misc tab (#642)
* init * cleanup * clean * cleanup
This commit is contained in:
BIN
assets/templates/inventory/tab_indicator.png
Normal file
BIN
assets/templates/inventory/tab_indicator.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -132,6 +132,7 @@ npc_dialogue=458,4,21,140
|
||||
bind_skill=516,619,251,29
|
||||
quest_skill_btn=284,455,710,121
|
||||
left_inventory_tabs=31,62,385,28
|
||||
tab_indicator=31,82,385,14
|
||||
deposit_btn=454,365,186,43
|
||||
|
||||
[path]
|
||||
|
||||
@@ -9,11 +9,11 @@ from ui_manager import detect_screen_object, ScreenObjects, center_mouse, is_vis
|
||||
from utils.misc import wait, trim_black, color_filter, cut_roi
|
||||
from inventory import consumables, personal
|
||||
from ui import view
|
||||
from screen import grab
|
||||
from screen import convert_screen_to_monitor, grab
|
||||
from dataclasses import dataclass
|
||||
from logger import Logger
|
||||
from ocr import Ocr
|
||||
|
||||
from template_finder import TemplateMatch
|
||||
|
||||
@dataclass
|
||||
class BoxInfo:
|
||||
@@ -244,6 +244,44 @@ def left_inventory_ready(img = np.ndarray):
|
||||
return any(np.sum(i) > 0 for i in [text, red, blue])
|
||||
return False
|
||||
|
||||
def tab_properties(idx: int = 0) -> dict[int, int, tuple]:
|
||||
tab_width = round(int(Config().ui_roi["tab_indicator"][2]) / 4)
|
||||
x_start = int(Config().ui_roi["tab_indicator"][0])
|
||||
left = idx * tab_width + x_start
|
||||
right = (idx + 1) * tab_width + x_start
|
||||
x_center = (left + right) / 2
|
||||
y_center = int(Config().ui_roi["tab_indicator"][1]) - 5
|
||||
return {
|
||||
"left": round(left),
|
||||
"right": round(right),
|
||||
"center": (x_center, y_center)
|
||||
}
|
||||
|
||||
def indicator_location_to_tab_count(pos: tuple) -> int:
|
||||
for i in range(3):
|
||||
tab = tab_properties(i)
|
||||
if tab["left"] <= pos[0] < tab["right"]:
|
||||
return i
|
||||
|
||||
def get_active_tab(indicator: TemplateMatch = None) -> int:
|
||||
indicator = detect_screen_object(ScreenObjects.TabIndicator) if indicator is None else indicator
|
||||
if indicator.valid:
|
||||
return indicator_location_to_tab_count(indicator.center)
|
||||
else:
|
||||
Logger.error("common/get_active_tab(): Error finding tab indicator")
|
||||
return False
|
||||
|
||||
def select_tab(idx: int):
|
||||
# stash or vendor must be open
|
||||
# indices start from 0
|
||||
if not get_active_tab() == idx:
|
||||
tab = tab_properties(idx)
|
||||
pos = convert_screen_to_monitor(tab["center"])
|
||||
mouse.move(*pos)
|
||||
wait(0.2, 0.3)
|
||||
mouse.click("left")
|
||||
wait(0.2, 0.3)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
import keyboard
|
||||
@@ -255,8 +293,9 @@ if __name__ == "__main__":
|
||||
print("Move to d2r window and press f11")
|
||||
keyboard.wait("f11")
|
||||
|
||||
color = Config().colors["tab_text"]
|
||||
#select_tab(0)
|
||||
|
||||
color = Config().colors["tab_text"]
|
||||
while 1:
|
||||
# img = cv2.imread("")
|
||||
img = grab()
|
||||
|
||||
@@ -98,6 +98,7 @@ class TownManager:
|
||||
if self._acts[curr_act].can_buy_pots():
|
||||
new_loc = self._acts[curr_act].open_trade_menu(curr_loc)
|
||||
if not (new_loc and common.wait_for_left_inventory()): return False, items
|
||||
common.select_tab(3)
|
||||
img=grab()
|
||||
# Buy HP pots
|
||||
if consumables.get_needs("health") > 0:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from cv2 import norm
|
||||
import keyboard
|
||||
import os
|
||||
import numpy as np
|
||||
@@ -266,6 +265,11 @@ class ScreenObjects:
|
||||
use_grayscale=True,
|
||||
roi="quest_skill_btn"
|
||||
)
|
||||
TabIndicator=ScreenObject(
|
||||
ref="TAB_INDICATOR",
|
||||
roi="tab_indicator",
|
||||
normalize_monitor=False
|
||||
)
|
||||
DepositBtn=ScreenObject(
|
||||
ref=["DEPOSIT_BTN", "DEPOSIT_BTN_BRIGHT"],
|
||||
threshold=0.8,
|
||||
@@ -342,7 +346,6 @@ if __name__ == "__main__":
|
||||
print("Go to D2R window and press f11 to start game")
|
||||
keyboard.wait("f11")
|
||||
from config import Config
|
||||
# while 1:
|
||||
# print(list_visible_objects())
|
||||
# time.sleep(1)
|
||||
print(f"res = {wait_until_visible(ScreenObjects.BeltExpandable, 7)}")
|
||||
while 1:
|
||||
print(list_visible_objects())
|
||||
time.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user