1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
| import json import os import queue import threading import time import tkinter as tk from tkinter import ttk, scrolledtext from typing import List, Optional
import cv2 import numpy as np import win32api from PIL import Image, ImageTk
from window_capture import capture_window, window_from_point from hp_monitor import HPMonitor, CONFIG_FILE from auto_potion import AutoPotion from detector import Detector from target_selector import TargetSelector
VK_LBUTTON = 0x01 VK_ESCAPE = 0x1B
POTION_KEYS = ["F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"] PREVIEW_W, PREVIEW_H = 200, 130
class SharedState: """執行緒安全的共享資料容器""" def __init__(self): self._lock = threading.Lock() self.hp = 1.0 self.mp = 1.0 self.hwnd = None self.running = False self.detections = [] self.target = None self.preview = None
def update(self, **kwargs): with self._lock: for k, v in kwargs.items(): setattr(self, k, v)
def get(self, *keys): with self._lock: if len(keys) == 1: return getattr(self, keys[0]) return tuple(getattr(self, k) for k in keys)
def monitor_loop(state: SharedState, monitor: HPMonitor, log_q: queue.Queue, frame_q: queue.Queue, potion: Optional[AutoPotion] = None): hwnd = state.get("hwnd") log_q.put(f"監控執行緒啟動,hwnd={hwnd}")
try: while state.get("running"): try: frame = capture_window(hwnd) if frame is None: time.sleep(0.2) continue hp, mp = monitor.read(frame) state.update(hp=hp, mp=mp) if potion is not None: potion.check(hp, mp)
try: frame_q.put_nowait(frame) except queue.Full: try: frame_q.get_nowait() except queue.Empty: pass frame_q.put_nowait(frame)
time.sleep(0.2) except Exception as e: log_q.put(f"⚠️ 監控迴圈錯誤:{type(e).__name__}: {e}") time.sleep(0.5) finally: state.update(running=False) log_q.put("監控執行緒結束")
def detection_loop(state: SharedState, log_q: queue.Queue, frame_q: queue.Queue, get_detector, get_selector): """ Thread 2 常駐;get_detector/get_selector 皆為 lambda,支援執行中熱換: - 模型未載入/停用:丟棄該幀、順便清空 target - 有 selector 才做目標選擇;否則只畫一般 bbox """ log_q.put("偵測執行緒啟動")
try: while state.get("running"): try: frame = frame_q.get(timeout=1.0) except queue.Empty: continue
detector = get_detector() if detector is None or not detector.enabled: state.update(target=None) continue
try: detections = detector.detect(frame) selector = get_selector() h, w = frame.shape[:2] target = (selector.select(detections, frame_center=(w // 2, h // 2)) if selector is not None else None) preview = detector.render(frame, detections, target=target) state.update(detections=detections, target=target, preview=preview) except Exception as e: log_q.put(f"⚠️ 偵測迴圈錯誤:{type(e).__name__}: {e}") time.sleep(0.5) finally: log_q.put("偵測執行緒結束")
class LineageAssistant: BG = "#1a1a2e" FG = "#e0e0e0" RED = "#e94560" BLUE = "#4fc3f7" GREEN = "#00ff99" AMBER = "#f5a623" AMBER_HOVER = "#ffc857" MUTED = "#555577"
def __init__(self): self.state = SharedState() self.monitor = HPMonitor() self.log_q = queue.Queue() self.frame_q = queue.Queue(maxsize=2) self.t_monitor = None self.t_detection = None self.potion = None self.detector = None self.selector = None self._tk_img = None self._build_ui() self._autoload_detector() self._poll() self.root.mainloop()
def _make_icon_btn(self, parent, text, cmd, font): btn = tk.Button( parent, text=text, bg=self.BG, fg=self.AMBER, activebackground=self.BG, activeforeground=self.AMBER_HOVER, disabledforeground=self.MUTED, font=font, relief="flat", bd=0, cursor="hand2", command=cmd)
def on_enter(_): if btn["state"] != "disabled": btn.config(fg=self.AMBER_HOVER)
def on_leave(_): if btn["state"] != "disabled": btn.config(fg=self.AMBER)
btn.bind("<Enter>", on_enter) btn.bind("<Leave>", on_leave) return btn
def _build_ui(self): self.root = tk.Tk() self.root.title("天堂私服輔助 v0.4") self.root.configure(bg=self.BG) self.root.resizable(False, False)
tk.Label(self.root, text="⚔ 天堂私服輔助", bg=self.BG, fg=self.FG, font=("Consolas", 16, "bold")).pack(pady=8)
toolbar = tk.Frame(self.root, bg=self.BG) toolbar.pack(padx=20, pady=(0, 4), fill="x")
self.btn_pick = self._make_icon_btn( toolbar, "🎯 選取視窗", self._pick_window, font=("Consolas", 11, "bold")) self.btn_pick.pack(side="left")
self.btn_calib = self._make_icon_btn( toolbar, "⚙ 校準血條", self._calibrate, font=("Consolas", 11, "bold")) self.btn_calib.pack(side="right")
self.target_var = tk.StringVar(value="目標視窗:未選擇") tk.Label(self.root, textvariable=self.target_var, bg=self.BG, fg=self.FG, font=("Consolas", 10), anchor="w" ).pack(padx=20, pady=(0, 6), fill="x")
bar_frame = tk.Frame(self.root, bg=self.BG) bar_frame.pack(padx=20, fill="x")
style = ttk.Style() style.theme_use("default") style.configure("Red.Horizontal.TProgressbar", troughcolor="#330000", background="#e94560") style.configure("Blue.Horizontal.TProgressbar", troughcolor="#001133", background="#4fc3f7")
tk.Label(bar_frame, text="HP", bg=self.BG, fg=self.RED, font=("Consolas", 11, "bold"), width=4 ).grid(row=0, column=0, sticky="w") self.hp_var = tk.DoubleVar(value=1.0) ttk.Progressbar(bar_frame, variable=self.hp_var, maximum=1.0, length=280, style="Red.Horizontal.TProgressbar" ).grid(row=0, column=1, padx=5, pady=3) self.hp_lbl = tk.Label(bar_frame, text="100%", bg=self.BG, fg=self.FG, font=("Consolas", 10), width=6) self.hp_lbl.grid(row=0, column=2)
tk.Label(bar_frame, text="MP", bg=self.BG, fg=self.BLUE, font=("Consolas", 11, "bold"), width=4 ).grid(row=1, column=0, sticky="w") self.mp_var = tk.DoubleVar(value=1.0) ttk.Progressbar(bar_frame, variable=self.mp_var, maximum=1.0, length=280, style="Blue.Horizontal.TProgressbar" ).grid(row=1, column=1, padx=5, pady=3) self.mp_lbl = tk.Label(bar_frame, text="100%", bg=self.BG, fg=self.FG, font=("Consolas", 10), width=6) self.mp_lbl.grid(row=1, column=2)
pot_frame = tk.LabelFrame(self.root, text=" 自動補藥設定 ", bg=self.BG, fg="#aaaaaa", font=("Consolas", 9)) pot_frame.pack(padx=12, pady=4, fill="x")
self.potion_enabled = tk.BooleanVar(value=True) tk.Checkbutton(pot_frame, text="啟用自動補藥", variable=self.potion_enabled, command=self._on_potion_toggle, bg=self.BG, fg=self.FG, selectcolor=self.BG, font=("Consolas", 9) ).grid(row=0, column=0, columnspan=5, sticky="w", padx=6, pady=2)
tk.Label(pot_frame, text="HP 觸發 %", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=1, column=0, sticky="w", padx=6) self.hp_thresh = tk.IntVar(value=60) ttk.Scale(pot_frame, from_=10, to=90, variable=self.hp_thresh, orient="horizontal", length=120 ).grid(row=1, column=1, padx=4) self.hp_thresh_lbl = tk.Label(pot_frame, text="60%", bg=self.BG, fg=self.RED, font=("Consolas", 9), width=5) self.hp_thresh_lbl.grid(row=1, column=2) tk.Label(pot_frame, text="鍵", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=1, column=3, padx=2) self.hp_key_var = tk.StringVar(value="F5") ttk.Combobox(pot_frame, textvariable=self.hp_key_var, values=POTION_KEYS, state="readonly", width=4, font=("Consolas", 10) ).grid(row=1, column=4, padx=4)
tk.Label(pot_frame, text="MP 觸發 %", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=2, column=0, sticky="w", padx=6) self.mp_thresh = tk.IntVar(value=40) ttk.Scale(pot_frame, from_=10, to=90, variable=self.mp_thresh, orient="horizontal", length=120 ).grid(row=2, column=1, padx=4) self.mp_thresh_lbl = tk.Label(pot_frame, text="40%", bg=self.BG, fg=self.BLUE, font=("Consolas", 9), width=5) self.mp_thresh_lbl.grid(row=2, column=2) tk.Label(pot_frame, text="鍵", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=2, column=3, padx=2) self.mp_key_var = tk.StringVar(value="F6") ttk.Combobox(pot_frame, textvariable=self.mp_key_var, values=POTION_KEYS, state="readonly", width=4, font=("Consolas", 10) ).grid(row=2, column=4, padx=4)
det_frame = tk.LabelFrame(self.root, text=" 怪物偵測設定 ", bg=self.BG, fg="#aaaaaa", font=("Consolas", 9)) det_frame.pack(padx=12, pady=4, fill="x")
self.detect_enabled = tk.BooleanVar(value=True) tk.Checkbutton(det_frame, text="啟用怪物偵測", variable=self.detect_enabled, command=self._on_detect_toggle, bg=self.BG, fg=self.FG, selectcolor=self.BG, font=("Consolas", 9) ).grid(row=0, column=0, columnspan=3, sticky="w", padx=6, pady=2)
tk.Label(det_frame, text="模型路徑", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=1, column=0, sticky="w", padx=6) self.model_path_var = tk.StringVar(value="models/lineage_detector.pt") tk.Entry(det_frame, textvariable=self.model_path_var, width=26, bg="#0d0d1a", fg=self.FG, font=("Consolas", 9), insertbackground="white" ).grid(row=1, column=1, padx=4, pady=2) self.btn_load_model = self._make_icon_btn( det_frame, "🔄 載入", self._load_detector, font=("Consolas", 10, "bold")) self.btn_load_model.grid(row=1, column=2, padx=4)
tk.Label(det_frame, text="信心度閾值", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=2, column=0, sticky="w", padx=6) self.conf_thresh = tk.IntVar(value=50) ttk.Scale(det_frame, from_=10, to=90, variable=self.conf_thresh, orient="horizontal", length=120 ).grid(row=2, column=1, padx=4) self.conf_lbl = tk.Label(det_frame, text="50%", bg=self.BG, fg=self.GREEN, font=("Consolas", 9), width=5) self.conf_lbl.grid(row=2, column=2)
tk.Label(det_frame, text="優先類別", bg=self.BG, fg=self.FG, font=("Consolas", 9)).grid(row=3, column=0, sticky="w", padx=6) self.priority_var = tk.StringVar(value="orc,troll,zombie") tk.Entry(det_frame, textvariable=self.priority_var, width=26, bg="#0d0d1a", fg="#ffe082", font=("Consolas", 9), insertbackground="white" ).grid(row=3, column=1, columnspan=2, padx=4, pady=2) tk.Label(det_frame, text="(逗號分隔,靠左優先;未列出的排最後)", bg=self.BG, fg="#666666", font=("Consolas", 8) ).grid(row=4, column=0, columnspan=3, sticky="w", padx=6, pady=(0, 4))
preview_frame = tk.LabelFrame(self.root, text=" 偵測預覽 ", bg=self.BG, fg="#aaaaaa", font=("Consolas", 9)) preview_frame.pack(padx=12, pady=4, fill="x")
mode_row = tk.Frame(preview_frame, bg=self.BG) mode_row.pack(fill="x", padx=6, pady=(2, 0)) self.preview_mode = tk.StringVar(value="live") for val, txt in [("live", "即時畫面"), ("grid", "格子地圖")]: tk.Radiobutton(mode_row, text=txt, variable=self.preview_mode, value=val, command=self._on_preview_mode, bg=self.BG, fg=self.FG, selectcolor=self.BG, activebackground=self.BG, activeforeground=self.FG, font=("Consolas", 9) ).pack(side="left", padx=6)
blank = np.zeros((PREVIEW_H, PREVIEW_W, 3), dtype=np.uint8) self._tk_img = ImageTk.PhotoImage(Image.fromarray(blank)) self.preview_lbl = tk.Label(preview_frame, image=self._tk_img, bg=self.BG) self.preview_lbl.pack(padx=4, pady=4)
info_row = tk.Frame(preview_frame, bg=self.BG) info_row.pack(fill="x", padx=6, pady=(0, 4)) self.det_count_lbl = tk.Label(info_row, text="偵測數:0", bg=self.BG, fg=self.GREEN, font=("Consolas", 9)) self.det_count_lbl.pack(side="left") self.target_lbl = tk.Label(info_row, text="目標:—", bg=self.BG, fg=self.RED, font=("Consolas", 9, "bold")) self.target_lbl.pack(side="right")
btn_frame = tk.Frame(self.root, bg=self.BG) btn_frame.pack(pady=8)
self.btn_toggle = self._make_icon_btn( btn_frame, "▶ 啟動", self._toggle, font=("Consolas", 13, "bold")) self.btn_toggle.pack()
self.status_var = tk.StringVar(value="就緒") tk.Label(self.root, textvariable=self.status_var, bg=self.BG, fg="#888888", font=("Consolas", 9)).pack()
self.log_box = scrolledtext.ScrolledText( self.root, width=52, height=8, state="disabled", bg="#0d0d1a", fg=self.GREEN, font=("Consolas", 9), insertbackground="white") self.log_box.pack(padx=10, pady=(5, 10))
def _log(self, msg: str): self.log_q.put(msg)
def _flush_log(self): while not self.log_q.empty(): msg = self.log_q.get_nowait() ts = time.strftime("%H:%M:%S") self.log_box.config(state="normal") self.log_box.insert("end", f"{ts} {msg}\n") self.log_box.see("end") self.log_box.config(state="disabled")
def _parse_priority(self) -> List[str]: raw = self.priority_var.get() return [s.strip() for s in raw.split(",") if s.strip()]
def _pick_window(self): if self.state.get("running"): self._log("請先停止監控再重選目標視窗") return self._log("🎯 請點擊目標遊戲視窗(ESC 可取消)") for btn in (self.btn_pick, self.btn_calib, self.btn_load_model, self.btn_toggle): btn.config(state="disabled") self.root.config(cursor="crosshair") self._poll_pick()
def _poll_pick(self): if win32api.GetAsyncKeyState(VK_ESCAPE) & 0x8000: self._reset_pick() self._log("已取消選擇視窗") return if win32api.GetAsyncKeyState(VK_LBUTTON) & 0x8000: x, y = win32api.GetCursorPos() hwnd, title, pid = window_from_point(x, y) self._reset_pick() if hwnd: self.state.update(hwnd=hwnd) label = title or "<無標題>" short = label if len(label) <= 30 else label[:28] + "…" self.target_var.set(f"目標:{short} (pid={pid})") self._log(f"已鎖定:{label} hwnd={hwnd} pid={pid}") else: self._log("未取得有效視窗,請再試一次") return self.root.after(30, self._poll_pick)
def _reset_pick(self): self.root.config(cursor="") for btn in (self.btn_pick, self.btn_calib, self.btn_load_model, self.btn_toggle): btn.config(state="normal")
def _calibrate(self): if self.state.get("running"): self._log("請先停止監控再校準") return hwnd = self.state.get("hwnd") if not hwnd: self._log("請先按「🎯 選取視窗」選取目標視窗") return
frame = capture_window(hwnd) if frame is None: self._log("擷取失敗,視窗可能被最小化") return
self._log("框選 HP 血條(紅色),Enter 確認") hp = cv2.selectROI("校準 HP 血條(Enter 確認 / C 重選)", frame, fromCenter=False, showCrosshair=True) cv2.destroyAllWindows()
self._log("框選 MP 魔力條(藍色),Enter 確認") mp = cv2.selectROI("校準 MP 魔力條(Enter 確認 / C 重選)", frame, fromCenter=False, showCrosshair=True) cv2.destroyAllWindows()
if hp[2] == 0 or mp[2] == 0: self._log("校準已取消(未框選有效範圍)") return
self.monitor.hp_roi = tuple(hp) self.monitor.mp_roi = tuple(mp) self._save_config() self._log(f"✅ 校準完成:HP={hp}, MP={mp}")
def _save_config(self): cfg = { "hp_roi": list(self.monitor.hp_roi), "mp_roi": list(self.monitor.mp_roi), } with open(CONFIG_FILE, "w") as f: json.dump(cfg, f, indent=2) self._log(f"已寫入 {CONFIG_FILE}")
def _toggle(self): if self.state.get("running"): self._stop() else: self._start()
def _on_potion_toggle(self): if self.potion is not None: self.potion.enabled = self.potion_enabled.get() self._log(f"自動補藥:{'啟用' if self.potion_enabled.get() else '停用'}")
def _on_detect_toggle(self): want = self.detect_enabled.get() if self.detector is None: if want: self._log("尚未載入模型,請先填入路徑並按「🔄 載入」") return self.detector.enabled = want self._log(f"怪物偵測:{'啟用' if want else '停用'}")
def _on_preview_mode(self): mode = self.preview_mode.get() if self.detector is not None: self.detector.mode = mode self._log(f"預覽模式:{'即時畫面' if mode == 'live' else '格子地圖'}")
def _autoload_detector(self): path = self.model_path_var.get().strip() if path and os.path.exists(path): self._load_detector() else: self._log( f"找不到預設模型:{path or '(未設定)'}," f"請把 best.pt 放到該路徑,或改路徑後按「🔄 載入」" )
def _load_detector(self): path = self.model_path_var.get().strip() if not path: self._log("請先填入模型路徑") return self._log(f"載入模型中:{path} ...") try: new_det = Detector(model_path=path, conf=self.conf_thresh.get() / 100) new_det.enabled = self.detect_enabled.get() new_det.mode = self.preview_mode.get() self.detector = new_det self._log( f"✅ 已載入模型:{path}" f"(conf≥{self.conf_thresh.get()}%," f"{'啟用' if new_det.enabled else '停用'})" ) except Exception as e: self._log(f"⚠️ 載入模型失敗:{type(e).__name__}: {e}")
def _start(self): hwnd = self.state.get("hwnd") if not hwnd: self._log("請先按「🎯 選取視窗」選取目標視窗") return
self.potion = AutoPotion( hwnd = hwnd, hp_threshold = self.hp_thresh.get() / 100, mp_threshold = self.mp_thresh.get() / 100, hp_key = self.hp_key_var.get().lower(), mp_key = self.mp_key_var.get().lower(), cooldown = 1.5, enabled = self.potion_enabled.get(), log_fn = self._log, ) self._log( f"補藥設定:HP<{self.hp_thresh.get()}% 按{self.hp_key_var.get()}," f"MP<{self.mp_thresh.get()}% 按{self.mp_key_var.get()}" f"({'啟用' if self.potion_enabled.get() else '停用'})" )
self.selector = TargetSelector( priority_classes = self._parse_priority(), min_conf = 0.0, log_fn = self._log, ) self._log(f"優先類別:{self.selector.priority or '(未設定,採用距離排序)'}")
if self.detector is None and self.detect_enabled.get(): self._log("提示:目前尚無模型,可調整路徑後按「🔄 載入」再繼續")
self.state.update(running=True)
self.t_monitor = threading.Thread( target=monitor_loop, args=(self.state, self.monitor, self.log_q, self.frame_q, self.potion), daemon=True) self.t_monitor.start()
self.t_detection = threading.Thread( target=detection_loop, args=(self.state, self.log_q, self.frame_q, lambda: self.detector, lambda: self.selector), daemon=True) self.t_detection.start()
self.btn_toggle.config(text="■ 停止") self.status_var.set("運行中...")
def _stop(self): self.state.update(running=False) self.btn_toggle.config(text="▶ 啟動") self.status_var.set("已停止") self._log("使用者手動停止")
def _poll(self): """每 200ms 將 SharedState 同步到 UI;順便把面板設定即時推到背景模組""" hp, mp, detections, target, preview = self.state.get( "hp", "mp", "detections", "target", "preview")
self.hp_var.set(hp) self.mp_var.set(mp) self.hp_lbl.config(text=f"{hp * 100:.0f}%") self.mp_lbl.config(text=f"{mp * 100:.0f}%") self.hp_thresh_lbl.config(text=f"{self.hp_thresh.get()}%") self.mp_thresh_lbl.config(text=f"{self.mp_thresh.get()}%") self.conf_lbl.config(text=f"{self.conf_thresh.get()}%")
if preview is not None: img_rgb = cv2.cvtColor( cv2.resize(preview, (PREVIEW_W, PREVIEW_H)), cv2.COLOR_BGR2RGB) self._tk_img = ImageTk.PhotoImage(Image.fromarray(img_rgb)) self.preview_lbl.config(image=self._tk_img) self.det_count_lbl.config(text=f"偵測數:{len(detections)}")
if target: self.target_lbl.config( text=f"目標:{target['name']} ({target['conf']:.2f})") else: self.target_lbl.config(text="目標:—")
workers_alive = any( t is not None and t.is_alive() for t in (self.t_monitor, self.t_detection)) if (not workers_alive and self.btn_toggle.cget("text").startswith("■")): self.state.update(running=False) self.btn_toggle.config(text="▶ 啟動") self.status_var.set("背景執行緒已停止(請看日誌)")
if self.potion is not None: self.potion.hp_threshold = self.hp_thresh.get() / 100 self.potion.mp_threshold = self.mp_thresh.get() / 100 self.potion.hp_key = self.hp_key_var.get().lower() self.potion.mp_key = self.mp_key_var.get().lower() if self.detector is not None: self.detector.conf = self.conf_thresh.get() / 100 if self.selector is not None: self.selector.priority = self._parse_priority()
self._flush_log() self.root.after(200, self._poll)
if __name__ == "__main__": LineageAssistant()
|