feat: expose fudai region coordinates in gui

This commit is contained in:
Your Name committed 2026-06-03 20:29:10 +08:00
1 parent bcc4d1151f
commit 4797fa046e
17 files changed
+1044 -119

No files matched your search

+77
View File
@@ -27,6 +27,69 @@ from .config_io_helpers import (
write_logging_to_cfg,
)
_REGION_CONFIG_SPECS = (
("fudai_detail_regions", "legacy", "content"),
("fudai_detail_regions", "legacy", "value"),
("fudai_detail_regions", "legacy", "countdown_full"),
("fudai_detail_regions", "legacy", "task_list"),
("fudai_detail_regions", "legacy", "task_count"),
("fudai_detail_regions", "legacy", "participants"),
("fudai_detail_regions", "legacy", "button"),
("fudai_detail_regions", "legacy", "live_title"),
("fudai_detail_regions", "v2_0_two_task", "content"),
("fudai_detail_regions", "v2_0_two_task", "value"),
("fudai_detail_regions", "v2_0_two_task", "countdown_full"),
("fudai_detail_regions", "v2_0_two_task", "task_list"),
("fudai_detail_regions", "v2_0_two_task", "task_count"),
("fudai_detail_regions", "v2_0_two_task", "participants"),
("fudai_detail_regions", "v2_0_two_task", "button"),
("fudai_detail_regions", "v2_0_two_task", "live_title"),
("fudai_detail_regions", "v2_0_one_task", "content"),
("fudai_detail_regions", "v2_0_one_task", "value"),
("fudai_detail_regions", "v2_0_one_task", "countdown_full"),
("fudai_detail_regions", "v2_0_one_task", "info_line"),
("fudai_detail_regions", "v2_0_one_task", "task_list"),
("fudai_detail_regions", "v2_0_one_task", "task_count"),
("fudai_detail_regions", "v2_0_one_task", "participants"),
("fudai_detail_regions", "v2_0_one_task", "button"),
("fudai_detail_regions", "v2_0_one_task", "live_title"),
("pixel_regions", "lottery_result", "button"),
("pixel_regions", "lottery_result", "pixel"),
("pixel_regions", "lottery_result", "click"),
("pixel_regions", "attend_button", None),
("pixel_regions", "fansclub_join", None),
("pixel_regions", "coupon_popup", None),
("pixel_regions", "shopping_redpacket", None),
("pixel_regions", "fudai_detail_body", None),
("pixel_regions", "live_room_icon_bbox", None),
)
def _deep_get(obj: dict, *parts: str):
cur = obj
for part in parts:
if not isinstance(cur, dict) or part not in cur:
return None
cur = cur[part]
return cur
def _deep_set(obj: dict, parts: tuple[str, ...], value) -> None:
cur = obj
for part in parts[:-1]:
if part not in cur or not isinstance(cur[part], dict):
cur[part] = {}
cur = cur[part]
cur[parts[-1]] = value
def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) -> str:
if name:
return f"{root}_{scope}_{name}_{axis}_var"
return f"{root}_{scope}_{axis}_var"
def load_config_to_ui(
*,
vars_: Dict[str, tk.Variable],
@@ -258,6 +321,13 @@ def load_config_to_ui(
float(cfg.get("fansclub_manual_wait_seconds", 3.0) or 3.0)
)
vars_["skip_lt_seconds_var"].set(int(cfg.get("skip_if_countdown_lt_seconds", 10) or 10))
for root, scope, name in _REGION_CONFIG_SPECS:
raw = _deep_get(cfg, root, scope, name) if name else _deep_get(cfg, root, scope)
values = list(raw) if isinstance(raw, (list, tuple)) else [0, 0, 0, 0]
if len(values) < 4:
values = [0, 0, 0, 0]
for idx, axis in enumerate(("x1", "y1", "x2", "y2")):
vars_[_make_region_var_key(root, scope, name, axis)].set(int(values[idx] or 0))
apply_debug_captures_from_cfg(vars_, cfg)
apply_logging_from_cfg(vars_, cfg)
@@ -516,6 +586,13 @@ def save_ui_to_config(
vars_["fansclub_manual_wait_var"].get() or 3.0
)
cfg2["skip_if_countdown_lt_seconds"] = int(vars_["skip_lt_seconds_var"].get() or 10)
for root, scope, name in _REGION_CONFIG_SPECS:
values = [
int(vars_[_make_region_var_key(root, scope, name, axis)].get() or 0)
for axis in ("x1", "y1", "x2", "y2")
]
target_parts = (root, scope, name) if name else (root, scope)
_deep_set(cfg2, target_parts, values)
write_debug_captures_to_cfg(cfg2, vars_)
write_logging_to_cfg(cfg2, vars_)
+64
View File
@@ -10,6 +10,59 @@ import tkinter as tk
from typing import Dict
_REGION_CONFIG_SPECS = (
("fudai_detail_regions", "legacy", "content"),
("fudai_detail_regions", "legacy", "value"),
("fudai_detail_regions", "legacy", "countdown_full"),
("fudai_detail_regions", "legacy", "task_list"),
("fudai_detail_regions", "legacy", "task_count"),
("fudai_detail_regions", "legacy", "participants"),
("fudai_detail_regions", "legacy", "button"),
("fudai_detail_regions", "legacy", "live_title"),
("fudai_detail_regions", "v2_0_two_task", "content"),
("fudai_detail_regions", "v2_0_two_task", "value"),
("fudai_detail_regions", "v2_0_two_task", "countdown_full"),
("fudai_detail_regions", "v2_0_two_task", "task_list"),
("fudai_detail_regions", "v2_0_two_task", "task_count"),
("fudai_detail_regions", "v2_0_two_task", "participants"),
("fudai_detail_regions", "v2_0_two_task", "button"),
("fudai_detail_regions", "v2_0_two_task", "live_title"),
("fudai_detail_regions", "v2_0_one_task", "content"),
("fudai_detail_regions", "v2_0_one_task", "value"),
("fudai_detail_regions", "v2_0_one_task", "countdown_full"),
("fudai_detail_regions", "v2_0_one_task", "info_line"),
("fudai_detail_regions", "v2_0_one_task", "task_list"),
("fudai_detail_regions", "v2_0_one_task", "task_count"),
("fudai_detail_regions", "v2_0_one_task", "participants"),
("fudai_detail_regions", "v2_0_one_task", "button"),
("fudai_detail_regions", "v2_0_one_task", "live_title"),
("pixel_regions", "lottery_result", "button"),
("pixel_regions", "lottery_result", "pixel"),
("pixel_regions", "lottery_result", "click"),
("pixel_regions", "attend_button", None),
("pixel_regions", "fansclub_join", None),
("pixel_regions", "coupon_popup", None),
("pixel_regions", "shopping_redpacket", None),
("pixel_regions", "fudai_detail_body", None),
("pixel_regions", "live_room_icon_bbox", None),
)
def _deep_get(obj: dict, *parts: str):
cur = obj
for part in parts:
if not isinstance(cur, dict) or part not in cur:
return None
cur = cur[part]
return cur
def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) -> str:
if name:
return f"{root}_{scope}_{name}_{axis}_var"
return f"{root}_{scope}_{axis}_var"
def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
"""从 cfg 构建所有 tk Var 实例,返回名→Var 字典。"""
y_var = tk.IntVar(value=int(cfg.get("y_pianyi", 0) or 0))
@@ -451,6 +504,16 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
skip_lt_seconds_var = tk.IntVar(
value=int(cfg.get("skip_if_countdown_lt_seconds", 10) or 10)
)
region_vars: Dict[str, tk.Variable] = {}
for root, scope, name in _REGION_CONFIG_SPECS:
raw = _deep_get(cfg, root, scope, name) if name else _deep_get(cfg, root, scope)
values = list(raw) if isinstance(raw, (list, tuple)) else []
if len(values) < 4:
values = [0, 0, 0, 0]
for idx, axis in enumerate(("x1", "y1", "x2", "y2")):
region_vars[_make_region_var_key(root, scope, name, axis)] = tk.IntVar(
value=int(values[idx] or 0)
)
return {
"y_var": y_var,
@@ -603,4 +666,5 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
"gui_realtime_refresh_interval_ms_var": gui_realtime_refresh_interval_ms_var,
"gui_realtime_tail_items_var": gui_realtime_tail_items_var,
"skip_lt_seconds_var": skip_lt_seconds_var,
**region_vars,
}
+88
View File
@@ -14,6 +14,86 @@ from tkinter.constants import LEFT, BOTH, X
from typing import Dict
_REGION_SECTIONS = (
(
"legacy OCR",
(
("fudai_detail_regions", "legacy", "content", "内容"),
("fudai_detail_regions", "legacy", "value", "价值"),
("fudai_detail_regions", "legacy", "countdown_full", "倒计时"),
("fudai_detail_regions", "legacy", "task_list", "任务列表"),
("fudai_detail_regions", "legacy", "task_count", "任务数量"),
("fudai_detail_regions", "legacy", "participants", "人数"),
("fudai_detail_regions", "legacy", "button", "按钮"),
("fudai_detail_regions", "legacy", "live_title", "直播间标题"),
),
),
(
"v2_0 two task OCR",
(
("fudai_detail_regions", "v2_0_two_task", "content", "内容"),
("fudai_detail_regions", "v2_0_two_task", "value", "价值"),
("fudai_detail_regions", "v2_0_two_task", "countdown_full", "倒计时"),
("fudai_detail_regions", "v2_0_two_task", "task_list", "任务列表"),
("fudai_detail_regions", "v2_0_two_task", "task_count", "任务数量"),
("fudai_detail_regions", "v2_0_two_task", "participants", "人数"),
("fudai_detail_regions", "v2_0_two_task", "button", "按钮"),
("fudai_detail_regions", "v2_0_two_task", "live_title", "直播间标题"),
),
),
(
"v2_0 one task OCR",
(
("fudai_detail_regions", "v2_0_one_task", "content", "内容"),
("fudai_detail_regions", "v2_0_one_task", "value", "价值"),
("fudai_detail_regions", "v2_0_one_task", "countdown_full", "倒计时"),
("fudai_detail_regions", "v2_0_one_task", "info_line", "信息行"),
("fudai_detail_regions", "v2_0_one_task", "task_list", "任务列表"),
("fudai_detail_regions", "v2_0_one_task", "task_count", "任务数量"),
("fudai_detail_regions", "v2_0_one_task", "participants", "人数"),
("fudai_detail_regions", "v2_0_one_task", "button", "按钮"),
("fudai_detail_regions", "v2_0_one_task", "live_title", "直播间标题"),
),
),
(
"像素检测区域",
(
("pixel_regions", "lottery_result", "button", "开奖按钮"),
("pixel_regions", "lottery_result", "pixel", "开奖像素"),
("pixel_regions", "lottery_result", "click", "开奖点击"),
("pixel_regions", "attend_button", None, "参与按钮"),
("pixel_regions", "fansclub_join", None, "粉丝团"),
("pixel_regions", "coupon_popup", None, "优惠券"),
("pixel_regions", "shopping_redpacket", None, "购物红包"),
("pixel_regions", "fudai_detail_body", None, "详情主体"),
("pixel_regions", "live_room_icon_bbox", None, "直播间图标bbox"),
),
),
)
def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) -> str:
if name:
return f"{root}_{scope}_{name}_{axis}_var"
return f"{root}_{scope}_{axis}_var"
def _add_region_editor(parent: ttk.Frame, *, root: str, scope: str, name: str | None, label: str, vars_: Dict[str, tk.Variable]) -> None:
row = ttk.Frame(parent)
row.pack(fill=X, padx=10, pady=(0, 4))
ttk.Label(row, text=f"{label}:", width=14).pack(side=LEFT)
for axis in ("x1", "y1", "x2", "y2"):
ttk.Label(row, text=f"{axis}").pack(side=LEFT, padx=(4, 2))
ttk.Spinbox(
row,
from_=-9999,
to=9999,
increment=1,
textvariable=vars_[_make_region_var_key(root, scope, name, axis)],
width=6,
).pack(side=LEFT)
def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> ttk.Frame:
debug_tab = ttk.Frame(parent)
@@ -303,6 +383,14 @@ def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> t
row4c, text="(0.0~1.0,默认0.8,多边形区域白色像素比例>=此值判定为在直播间)"
).pack(side=LEFT, padx=(6, 0))
region_box = ttk.LabelFrame(debug_container, text="福袋坐标配置")
region_box.pack(fill=X, padx=10, pady=(0, 10))
for section_title, items in _REGION_SECTIONS:
section = ttk.LabelFrame(region_box, text=section_title)
section.pack(fill=X, padx=10, pady=(8, 6))
for root, scope, name, label in items:
_add_region_editor(section, root=root, scope=scope, name=name, label=label, vars_=vars_)
# 鼠标配置
mouse_config_box = ttk.LabelFrame(debug_container, text="鼠标配置")
mouse_config_box.pack(fill=X, padx=10, pady=(0, 10))