aram-mayhem-dsh 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,16 +78,16 @@ powershell -ExecutionPolicy Bypass -File .\scripts\package_share.ps1
78
78
 
79
79
  ## 桌面图标
80
80
 
81
- - 默认折叠为 68×68 的六边形图标,**收起时自动贴右边界**(距右 14px、距上 96px),不会停在屏幕中间;绿色圆点表示 LCU 已连接。
82
- - 点击展开:英雄 / 推荐海克斯 / 出装三个页签。
83
- - 点标题栏「收起」、按 `Esc`,或点击游戏/其他窗口时自动缩回小图标,不会一直挡着游戏。
81
+ - 默认停靠主屏右边缘并**半隐藏**:只露出约 45% 宽度,透明度约 0.45;鼠标移入平滑滑出完整图标,移出 400ms 后缩回。
82
+ - 点击展开:英雄 / 推荐海克斯 / 出装三个页签;功能菜单打开或主面板展开时不会缩回。
83
+ - 点标题栏「收起」、按 `Esc`,或点击游戏/其他窗口时自动缩回半隐藏图标,减少对视野的遮挡。
84
84
  - **游戏必须使用「无边框」或「窗口化」**:独占全屏会盖住所有 Windows 置顶窗口,图标和 OCR 都无法显示/截图。游戏内按 Esc → 视频 → 窗口模式 → 无边框。
85
- - 展开后可以拖动标题栏移动;收起时仍会归位到右边界。
85
+ - 展开后可以拖动标题栏移动;拖到左/右边缘会吸附,收起后回到右边缘半隐藏。
86
86
  - 海克斯品质使用官方配色:**棱彩**为青→紫→金的虹彩渐变,**黄金**为金色,**白银**为银灰;页面和桌面图标保持一致。
87
87
  - 游戏中如果服务是在选人结束后才启动,会通过 **Live Client Data API** 读取当前英雄,不要求重新进选人。
88
88
  - 关闭图标或页面开关会退出进程并记住「关闭」,下次插件加载不会再自动弹出;点页面开关或调用 `aram_overlay open` 可重新打开。
89
89
  - 关闭 **「服务」** 会终止 Python 进程,并同时关闭桌面图标;下次使用时需重新点「服务 开」。
90
- - 页面右上角的 **「桌面图标 开/关」** 开关会立即启动/关闭图标,并把偏好保存到 `config/overlay_pref.json`;关闭后即使重载插件也不会自动弹出。
90
+ - 页面右上角的 **「桌面图标 开/关」** 开关会立即启动/关闭图标;关闭后即使重载插件也不会自动弹出。
91
91
 
92
92
  ## 页面
93
93
 
@@ -101,12 +101,24 @@ powershell -ExecutionPolicy Bypass -File .\scripts\package_share.ps1
101
101
 
102
102
  ### 对局内 OCR
103
103
 
104
- - 用 `mss` 截取游戏客户区,RapidOCR 纯 CPU 识别中文卡牌标题。
105
- - 默认关闭自动扫描;开启后只在「推荐海克斯」页签打开时每 6 秒扫描一次,也可点「立即扫描」。
106
- - 建议游戏使用**无边框/窗口化**;独占全屏可能截到黑屏。
107
- - 识别区域由 `config/settings.json` 的 `vision.region` 控制;默认 `[0.06, 0.12, 0.88, 0.76]`(相对客户区)。
104
+ - 用 `mss` 截取游戏客户区,按 **16:9 居中安全区**换算坐标,超宽屏不会把卡排拉伸到侧边。
105
+ - 只扫描一条 `vision.augment_title_strip` 横向标题带,默认 `[0.08, 0.38, 0.84, 0.055]`,避开图标和技能描述。
106
+ - 预处理为 HSV 亮度/饱和度掩码 + 局部自适应阈值(不使用全局 Otsu),2x 双三次放大,白底黑字加 16px 白边。
107
+ - 通过 X 轴墨迹投影自动分卡,原生兼容 **3 卡/4 卡**及长名称折行;再用拼音 + 字形闭集纠错(`pypinyin` + `rapidfuzz`)还原同音/误识字。
108
+ - 默认轮询约 250ms;连续 2 帧结果一致才刷新,避免画面粒子导致闪烁。
109
+ - 游戏建议使用**无边框/窗口化**;独占全屏可能截到黑屏。
110
+ - `vision.region` 仍保留作为无标题带配置时的兼容回退区域;`vision.card_merge_gap_ratio` 控制同卡合并间距,`vision.ocr_closed_threshold` 控制纠错阈值。
108
111
  - OCR 只读屏幕,不注入游戏、不自动点击卡片。
109
112
 
113
+ ### F9 视觉调试
114
+
115
+ - 在 DSH 图标上按 **F9**,或调用 `aram_scan` 并传 `debug=true`,会把调试包写到 `debug_output/<时间>/`:
116
+ - `annotated_strip.png`:蓝色标题带、绿色分卡框和序号;
117
+ - `title_strip_raw.png` / `title_strip_processed.png`;
118
+ - `game_fullscreen.png`(如果可用);
119
+ - `ocr_log.txt`:卡片数量、原始 OCR、匹配置信度、最终海克斯名。
120
+ - legacy 入口也支持 `python src/main.py --debug-vision` 和 F9。`vision.debug_vision=true` 可让每次扫描都导出(只建议排查时开启)。
121
+
110
122
  **注意**:桌面图标是真正的 Windows 置顶悬浮窗;DSH 页面位于 Harness 窗口内,适合副屏。原来的 PySide 完整桌面版仍保留在 `src/main.py`,作为可选 legacy 入口。
111
123
 
112
124
  ## Agent 工具
@@ -9,14 +9,18 @@
9
9
  "opacity": 0.97,
10
10
  "always_on_top": true,
11
11
  "mini": false,
12
- "click_through": false
12
+ "click_through": false,
13
+ "edge_hide": true,
14
+ "edge_hide_ratio": 0.55,
15
+ "edge_hover_delay_ms": 400
13
16
  },
14
17
  "hotkeys": {
15
18
  "enabled": true,
16
19
  "toggle_visible": "Ctrl+Shift+H",
17
20
  "toggle_mini": "Ctrl+Shift+M",
18
21
  "rescan_augments": "Ctrl+Shift+R",
19
- "toggle_click_through": "Ctrl+Shift+L"
22
+ "toggle_click_through": "Ctrl+Shift+L",
23
+ "debug_vision": "F9"
20
24
  },
21
25
  "lcu": {
22
26
  "enabled": true,
@@ -27,13 +31,22 @@
27
31
  },
28
32
  "vision": {
29
33
  "enabled": true,
30
- "interval": 1.5,
34
+ "interval": 0.25,
31
35
  "region": [
32
36
  0.06,
33
37
  0.12,
34
38
  0.88,
35
39
  0.76
36
40
  ],
41
+ "augment_title_strip": [
42
+ 0.08,
43
+ 0.38,
44
+ 0.84,
45
+ 0.055
46
+ ],
47
+ "card_merge_gap_ratio": 0.025,
48
+ "ocr_closed_threshold": 0.65,
49
+ "debug_vision": false,
37
50
  "ocr_min_confidence": 0.45,
38
51
  "match_threshold": 0.72,
39
52
  "min_matches": 2,
package/index.js CHANGED
@@ -413,10 +413,11 @@ export function apply(ctx, config = {}) {
413
413
  + 'Use only when the user is in an ARAM: Mayhem game and asks about the current cards.',
414
414
  parameters: objectSchema({
415
415
  champion: { type: 'string', description: 'Optional champion name/ID; omit to use the champion detected in champ select.' },
416
+ debug: { type: 'boolean', description: 'Write annotated strip, preprocessed image and OCR log to debug_output/.' },
416
417
  }, []),
417
418
  output: { schema: { type: 'string' }, render: (_args, value) => asText(value) },
418
419
  execute: async args => {
419
- const data = await post('/scan', { champion: args?.champion || undefined })
420
+ const data = await post('/scan', { champion: args?.champion || undefined, debug: !!args?.debug })
420
421
  if (!data.ok) return `识别失败:${data.error || '未知原因'}`
421
422
  if (!data.matches?.length) return '没有识别到海克斯卡片。请确认游戏使用无边框/窗口化,并调整识别区域。'
422
423
  const lines = [`识别到 ${data.matches.length} 张卡片:${data.matches.map(item => `${item.name}(${Math.round(item.confidence * 100)}%)`).join(' / ')}`]
@@ -425,6 +426,7 @@ export function apply(ctx, config = {}) {
425
426
  lines.push('', '按当前英雄推荐:')
426
427
  data.evaluations.forEach((item, index) => lines.push(`${index + 1}. ${fmtEval(item)}`))
427
428
  }
429
+ if (args?.debug) lines.push('', '调试截图与 OCR 日志已写入 debug_output/。')
428
430
  lines.push('', await dataNote())
429
431
  return lines.join('\n')
430
432
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aram-mayhem-dsh",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "ARAM: Mayhem companion for DSH: an on-demand local service, screen-top desktop icon, sidebar page with LCU state, champion/augment statistics, builds and screen OCR, with nine agent tools.",
6
6
  "license": "MIT",
@@ -3,6 +3,9 @@ psutil>=5.9,<8
3
3
  websockets>=13,<18
4
4
  mss>=9,<11
5
5
  rapidocr_onnxruntime>=1.2.3,<2
6
+ pypinyin>=0.53,<1
7
+ rapidfuzz>=3.9,<4
8
+ opencv-python>=4.9,<6
6
9
  Pillow>=10,<13
7
10
  numpy>=1.26,<3
8
11
  PySide6>=6.7,<7
@@ -19,7 +19,19 @@ from pathlib import Path
19
19
  from typing import Any
20
20
  from urllib.parse import quote
21
21
 
22
- from PySide6.QtCore import QEvent, QLockFile, QPoint, QRectF, Qt, QTimer, QUrl, Signal
22
+ from PySide6.QtCore import (
23
+ QEasingCurve,
24
+ QEvent,
25
+ QLockFile,
26
+ QParallelAnimationGroup,
27
+ QPoint,
28
+ QPropertyAnimation,
29
+ QRectF,
30
+ Qt,
31
+ QTimer,
32
+ QUrl,
33
+ Signal,
34
+ )
23
35
  from PySide6.QtGui import (
24
36
  QColor,
25
37
  QFont,
@@ -355,6 +367,8 @@ class IconWidget(QWidget):
355
367
  if event.button() == Qt.MouseButton.LeftButton:
356
368
  if not self._moved:
357
369
  self.clicked.emit()
370
+ else:
371
+ self._overlay._on_icon_drag_release()
358
372
  self._press = None
359
373
  super().mouseReleaseEvent(event)
360
374
 
@@ -438,6 +452,11 @@ class FloatingOverlay(QWidget):
438
452
  self._expanded_at = 0.0
439
453
  self._signature: Any = None
440
454
  self._search_busy = False
455
+ self._peeked = False
456
+ self._hide_timer = QTimer(self)
457
+ self._hide_timer.setSingleShot(True)
458
+ self._hide_timer.timeout.connect(self._hide_peek)
459
+ self._icon_animation: QParallelAnimationGroup | None = None
441
460
  self._state_path = root / "config" / "overlay_state.json"
442
461
  self._pid_path = root / "data" / "cache" / "overlay.pid"
443
462
  self._lock_path = root / "data" / "cache" / "overlay.lock"
@@ -480,6 +499,11 @@ class FloatingOverlay(QWidget):
480
499
  self._top_timer.setInterval(1200)
481
500
  self._top_timer.timeout.connect(self._raise_topmost)
482
501
  self._top_timer.start()
502
+ self._f9_down = False
503
+ self._f9_timer = QTimer(self)
504
+ self._f9_timer.setInterval(80)
505
+ self._f9_timer.timeout.connect(self._poll_f9)
506
+ self._f9_timer.start()
483
507
  QTimer.singleShot(120, self._api.get_snapshot)
484
508
  if start_expanded:
485
509
  QTimer.singleShot(200, self.expand)
@@ -591,6 +615,11 @@ class FloatingOverlay(QWidget):
591
615
  self.expanded = expanded
592
616
  if expanded:
593
617
  self._expanded_at = time.monotonic()
618
+ self._hide_timer.stop()
619
+ if self._icon_animation is not None:
620
+ self._icon_animation.stop()
621
+ self._icon_animation = None
622
+ self.setWindowOpacity(1.0)
594
623
  self.stack.setCurrentIndex(1)
595
624
  self.setMinimumSize(350, 480)
596
625
  self.setMaximumSize(500, 900)
@@ -604,21 +633,96 @@ class FloatingOverlay(QWidget):
604
633
  self.setMinimumSize(68, 68)
605
634
  self.setMaximumSize(68, 68)
606
635
  self.resize(68, 68)
607
- self._snap_right()
636
+ self._hide_timer.stop()
637
+ self._peeked = True
638
+ self._snap_icon(peek=True, animate=False)
639
+ self.setWindowOpacity(0.45)
608
640
  self._raise_topmost()
609
641
 
642
+ def _edge_x(self, peek: bool) -> int:
643
+ screen = self.screen() or QApplication.primaryScreen()
644
+ if screen is None:
645
+ return self.x()
646
+ area = screen.availableGeometry()
647
+ if peek:
648
+ ratio = 0.55
649
+ visible = max(16, round(self.width() * (1.0 - ratio)))
650
+ return area.right() - visible
651
+ return area.right() - self.width() + 1
652
+
610
653
  def _snap_right(self) -> None:
611
- """Collapsed icon always hugs the right edge, never the middle."""
654
+ """Backward-compatible alias for the half-hidden right edge."""
655
+
656
+ self._snap_icon(peek=True, animate=False)
657
+
658
+ def _snap_icon(self, *, peek: bool, animate: bool) -> None:
612
659
  screen = self.screen() or QApplication.primaryScreen()
613
660
  if screen is None:
614
661
  return
615
662
  area = screen.availableGeometry()
616
- margin = 14
617
- top_offset = 96
618
- x = area.right() - self.width() - margin
619
- y = area.top() + top_offset
620
- y = max(area.top() + margin, min(y, area.bottom() - self.height() - margin))
621
- self.move(x, y)
663
+ target_x = self._edge_x(peek)
664
+ target_y = self.y()
665
+ target_y = max(area.top() + 12, min(target_y, area.bottom() - self.height() - 12))
666
+ target = QPoint(target_x, target_y)
667
+ self._peeked = peek
668
+ if not animate or not self.isVisible():
669
+ self.move(target)
670
+ self.setWindowOpacity(0.45 if peek else 1.0)
671
+ return
672
+ if self._icon_animation is not None:
673
+ self._icon_animation.stop()
674
+ group = QParallelAnimationGroup(self)
675
+ move = QPropertyAnimation(self, b"pos", group)
676
+ move.setDuration(180)
677
+ move.setStartValue(self.pos())
678
+ move.setEndValue(target)
679
+ move.setEasingCurve(QEasingCurve.Type.OutCubic)
680
+ fade = QPropertyAnimation(self, b"windowOpacity", group)
681
+ fade.setDuration(180)
682
+ fade.setStartValue(float(self.windowOpacity()))
683
+ fade.setEndValue(0.45 if peek else 1.0)
684
+ fade.setEasingCurve(QEasingCurve.Type.OutCubic)
685
+ group.addAnimation(move)
686
+ group.addAnimation(fade)
687
+ group.finished.connect(lambda: setattr(self, "_icon_animation", None))
688
+ self._icon_animation = group
689
+ group.start()
690
+
691
+ def _reveal_icon(self) -> None:
692
+ if self.expanded:
693
+ return
694
+ self._hide_timer.stop()
695
+ self._snap_icon(peek=False, animate=True)
696
+
697
+ def _hide_peek(self) -> None:
698
+ if self.expanded or self.underMouse():
699
+ return
700
+ self._snap_icon(peek=True, animate=True)
701
+
702
+ def enterEvent(self, event):
703
+ self._hide_timer.stop()
704
+ if not self.expanded:
705
+ self._reveal_icon()
706
+ super().enterEvent(event)
707
+
708
+ def leaveEvent(self, event):
709
+ if not self.expanded:
710
+ self._hide_timer.start(400)
711
+ super().leaveEvent(event)
712
+
713
+ def _on_icon_drag_release(self) -> None:
714
+ if self.expanded:
715
+ return
716
+ screen = self.screen() or QApplication.primaryScreen()
717
+ if screen is None:
718
+ return
719
+ area = screen.availableGeometry()
720
+ if self.x() + self.width() >= area.right() - 20 or self.x() <= area.left() + 20:
721
+ self._snap_icon(peek=True, animate=True)
722
+ else:
723
+ self._peeked = False
724
+ self.setWindowOpacity(1.0)
725
+ self._save_position()
622
726
 
623
727
  def showEvent(self, event):
624
728
  super().showEvent(event)
@@ -657,7 +761,6 @@ class FloatingOverlay(QWidget):
657
761
  self._apply_mode(True)
658
762
  self.raise_()
659
763
  self.activateWindow()
660
-
661
764
  def collapse(self) -> None:
662
765
  if not self.expanded:
663
766
  return
@@ -1103,7 +1206,7 @@ class FloatingOverlay(QWidget):
1103
1206
  self.content_layout.addLayout(row)
1104
1207
 
1105
1208
  # --------------------------------------------------------------- actions
1106
- def _scan(self) -> None:
1209
+ def _scan(self, *, debug: bool = False) -> None:
1107
1210
  if self.scanning:
1108
1211
  return
1109
1212
  active = self._active()
@@ -1114,7 +1217,18 @@ class FloatingOverlay(QWidget):
1114
1217
  self.scanning = True
1115
1218
  self.scan_error = ""
1116
1219
  self._rebuild(force=True)
1117
- self._api.scan(champion)
1220
+ self._api.scan(champion, debug=debug)
1221
+
1222
+ def _poll_f9(self) -> None:
1223
+ if os.name != "nt":
1224
+ return
1225
+ try:
1226
+ down = bool(ctypes.windll.user32.GetAsyncKeyState(0x78) & 0x8000)
1227
+ except OSError:
1228
+ return
1229
+ if down and not self._f9_down:
1230
+ self._scan(debug=True)
1231
+ self._f9_down = down
1118
1232
 
1119
1233
  def _search_champion(self) -> None:
1120
1234
  if self._search_busy:
@@ -1182,11 +1296,11 @@ class ApiClient(QWidget):
1182
1296
  finally:
1183
1297
  reply.deleteLater()
1184
1298
 
1185
- def scan(self, champion_id: int | None) -> None:
1299
+ def scan(self, champion_id: int | None, *, debug: bool = False) -> None:
1186
1300
  if self._scan_pending:
1187
1301
  return
1188
1302
  self._scan_pending = True
1189
- reply = self._request("/scan", "post", {"champion": champion_id})
1303
+ reply = self._request("/scan", "post", {"champion": champion_id, "debug": debug})
1190
1304
  reply.finished.connect(lambda: self._scan_done(reply))
1191
1305
 
1192
1306
  def _scan_done(self, reply: QNetworkReply) -> None:
@@ -65,7 +65,7 @@ from src.lcu.listener import parse_champ_select, parse_queue_info
65
65
  log = logging.getLogger("aram-dsh-service")
66
66
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
67
67
 
68
- VERSION = "0.3.3"
68
+ VERSION = "0.4.1"
69
69
  IN_GAME_PHASES = {"InProgress", "Reconnect"}
70
70
 
71
71
 
@@ -586,7 +586,7 @@ class AramService:
586
586
  }
587
587
 
588
588
  # -------------------------------------------------------------------- scan
589
- def scan(self, champion_query: str | int | None = None) -> dict[str, Any]:
589
+ def scan(self, champion_query: str | int | None = None, *, debug: bool = False) -> dict[str, Any]:
590
590
  with self._scan_lock:
591
591
  try:
592
592
  from src.vision.capture import CaptureError, ScreenCapture
@@ -612,7 +612,7 @@ class AramService:
612
612
  if self._ocr is None:
613
613
  self._ocr = RapidOCREngine(min_confidence=vision.ocr_min_confidence)
614
614
  detector = AugmentDetector(capture, self._ocr, self.matcher, vision)
615
- result = detector.detect_once(force=True)
615
+ result = detector.detect_once(force=True, debug=debug)
616
616
  matches = list(result.matches)
617
617
  evaluations = (
618
618
  self.matcher.evaluate_detected(champion.id, matches)
@@ -631,10 +631,14 @@ class AramService:
631
631
  "confidence": match.confidence,
632
632
  "match_score": match.match_score,
633
633
  "raw_text": match.raw_text,
634
+ "x_center_ratio": match.x_center_ratio,
634
635
  }
635
636
  for match in matches
636
637
  ],
637
638
  "evaluations": [_evaluation_json(item) for item in evaluations],
639
+ "card_count": result.card_count,
640
+ "stable": result.stable,
641
+ "ocr_texts": list(result.ocr_texts),
638
642
  "ocr_lines": result.ocr_lines,
639
643
  "elapsed": result.elapsed,
640
644
  "image_size": list(result.image_size),
@@ -931,7 +935,7 @@ def _handler_for(service: AramService):
931
935
  try:
932
936
  body = self._body()
933
937
  if path == "/scan":
934
- return self._send(200, service.scan(body.get("champion")))
938
+ return self._send(200, service.scan(body.get("champion"), debug=bool(body.get("debug"))))
935
939
  if path == "/refresh":
936
940
  return self._send(200, {"ok": True, "meta": service.refresh(str(body.get("url") or ""))})
937
941
  if path == "/overlay/start":
package/src/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """ARAM: Mayhem real-time assistant."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.4.0"
package/src/app.py CHANGED
@@ -153,6 +153,8 @@ class AssistantApp(QObject):
153
153
  self._setup_hotkeys()
154
154
  if self.demo_mode or self.args.screenshot:
155
155
  QTimer.singleShot(250, self._start_demo)
156
+ if getattr(self.args, "debug_vision", False) and self.scanner is not None:
157
+ QTimer.singleShot(1200, self.scanner.request_debug)
156
158
  if self.args.screenshot:
157
159
  QTimer.singleShot(2800, self._capture_screenshot)
158
160
  self.args.quit_after = max(3.2, float(self.args.quit_after or 0))
@@ -199,6 +201,7 @@ class AssistantApp(QObject):
199
201
  "toggle_mini": cfg.toggle_mini,
200
202
  "rescan_augments": cfg.rescan_augments,
201
203
  "toggle_click_through": cfg.toggle_click_through,
204
+ "debug_vision": cfg.debug_vision,
202
205
  }
203
206
  self.hotkeys.start()
204
207
  for name, combo in mapping.items():
@@ -310,6 +313,7 @@ class AssistantApp(QObject):
310
313
  self._last_detection = result
311
314
  matches = list(result.matches)
312
315
  if not matches:
316
+ self.window.augment_panel.set_waiting("画面已回到对局,等待下一次海克斯出现")
313
317
  return
314
318
  champion = self._my_summary.champion if self._my_summary else None
315
319
  if champion is not None:
@@ -353,6 +357,9 @@ class AssistantApp(QObject):
353
357
  self.rescan()
354
358
  elif name == "toggle_click_through":
355
359
  self.window.toggle_click_through()
360
+ elif name == "debug_vision" and self.scanner is not None:
361
+ self.scanner.request_debug()
362
+ self.window.show_toast("正在导出 F9 视觉调试包…")
356
363
 
357
364
  # ------------------------------------------------------------------- demo
358
365
  def _start_demo(self) -> None:
@@ -28,15 +28,9 @@ class WindowSettings:
28
28
  always_on_top: bool = True
29
29
  mini: bool = False
30
30
  click_through: bool = False
31
-
32
-
33
- @dataclass
34
- class HotkeySettings:
35
- enabled: bool = True
36
- toggle_visible: str = "Ctrl+Shift+H"
37
- toggle_mini: str = "Ctrl+Shift+M"
38
- rescan_augments: str = "Ctrl+Shift+R"
39
- toggle_click_through: str = "Ctrl+Shift+L"
31
+ edge_hide: bool = True
32
+ edge_hide_ratio: float = 0.55
33
+ edge_hover_delay_ms: int = 400
40
34
 
41
35
 
42
36
  @dataclass
@@ -48,11 +42,25 @@ class LCUSettings:
48
42
  request_timeout: float = 3.0
49
43
 
50
44
 
45
+ @dataclass
46
+ class HotkeySettings:
47
+ enabled: bool = True
48
+ toggle_visible: str = "Ctrl+Shift+H"
49
+ toggle_mini: str = "Ctrl+Shift+M"
50
+ rescan_augments: str = "Ctrl+Shift+R"
51
+ toggle_click_through: str = "Ctrl+Shift+L"
52
+ debug_vision: str = "F9"
53
+
54
+
51
55
  @dataclass
52
56
  class VisionSettings:
53
57
  enabled: bool = True
54
- interval: float = 1.5
58
+ interval: float = 0.25
55
59
  region: list[float] = field(default_factory=lambda: [0.06, 0.12, 0.88, 0.76])
60
+ augment_title_strip: list[float] = field(default_factory=lambda: [0.08, 0.38, 0.84, 0.055])
61
+ card_merge_gap_ratio: float = 0.025
62
+ ocr_closed_threshold: float = 0.65
63
+ debug_vision: bool = False
56
64
  ocr_min_confidence: float = 0.45
57
65
  match_threshold: float = 0.72
58
66
  min_matches: int = 2
@@ -134,6 +142,8 @@ class Settings:
134
142
  w.height = max(320, min(1400, int(w.height)))
135
143
  w.min_width = max(300, min(w.width, int(w.min_width)))
136
144
  w.opacity = max(0.35, min(1.0, float(w.opacity)))
145
+ w.edge_hide_ratio = max(0.25, min(0.8, float(w.edge_hide_ratio)))
146
+ w.edge_hover_delay_ms = max(100, min(1500, int(w.edge_hover_delay_ms)))
137
147
  if w.x is not None:
138
148
  w.x = int(w.x)
139
149
  if w.y is not None:
@@ -143,23 +153,29 @@ class Settings:
143
153
  self.lcu.reconnect_interval = max(1.0, min(60.0, float(self.lcu.reconnect_interval)))
144
154
  self.lcu.request_timeout = max(1.0, min(30.0, float(self.lcu.request_timeout)))
145
155
 
146
- self.vision.interval = max(0.5, min(15.0, float(self.vision.interval)))
156
+ self.vision.interval = max(0.15, min(15.0, float(self.vision.interval)))
147
157
  self.vision.ocr_min_confidence = max(0.0, min(0.99, float(self.vision.ocr_min_confidence)))
148
158
  self.vision.match_threshold = max(0.4, min(1.0, float(self.vision.match_threshold)))
159
+ self.vision.ocr_closed_threshold = max(0.4, min(1.0, float(self.vision.ocr_closed_threshold)))
160
+ self.vision.card_merge_gap_ratio = max(0.005, min(0.12, float(self.vision.card_merge_gap_ratio)))
149
161
  self.vision.min_matches = max(1, min(6, int(self.vision.min_matches)))
150
162
  self.vision.cooldown = max(0.0, min(120.0, float(self.vision.cooldown)))
151
163
 
152
- region = self.vision.region
153
- if not isinstance(region, (list, tuple)) or len(region) != 4:
154
- warnings.append("vision.region 无效,已恢复默认区域")
155
- self.vision.region = [0.06, 0.12, 0.88, 0.76]
156
- else:
164
+ for attr, default in (
165
+ ("region", [0.06, 0.12, 0.88, 0.76]),
166
+ ("augment_title_strip", [0.08, 0.38, 0.84, 0.055]),
167
+ ):
168
+ region = getattr(self.vision, attr)
169
+ if not isinstance(region, (list, tuple)) or len(region) != 4:
170
+ warnings.append(f"vision.{attr} 无效,已恢复默认区域")
171
+ setattr(self.vision, attr, default)
172
+ continue
157
173
  x, y, width, height = (float(v) for v in region)
158
174
  x = max(0.0, min(0.99, x))
159
175
  y = max(0.0, min(0.99, y))
160
176
  width = max(0.05, min(1.0 - x, width))
161
- height = max(0.05, min(1.0 - y, height))
162
- self.vision.region = [round(x, 4), round(y, 4), round(width, 4), round(height, 4)]
177
+ height = max(0.005, min(1.0 - y, height))
178
+ setattr(self.vision, attr, [round(x, 4), round(y, 4), round(width, 4), round(height, 4)])
163
179
 
164
180
  self.data.refresh_hours = max(0.25, min(24 * 30, float(self.data.refresh_hours)))
165
181
  return warnings
@@ -14,6 +14,17 @@ import re
14
14
  import threading
15
15
  import unicodedata
16
16
  from collections.abc import Iterable, Sequence
17
+ from functools import lru_cache
18
+
19
+ try:
20
+ from pypinyin import lazy_pinyin
21
+ except Exception: # pragma: no cover - optional at import time
22
+ lazy_pinyin = None
23
+
24
+ try:
25
+ from rapidfuzz import fuzz as rapid_fuzz
26
+ except Exception: # pragma: no cover - optional at import time
27
+ rapid_fuzz = None
17
28
 
18
29
  from .models import (
19
30
  Augment,
@@ -214,6 +225,36 @@ def _similarity(left: str, right: str) -> float:
214
225
  return difflib.SequenceMatcher(None, left, right, autojunk=False).ratio()
215
226
 
216
227
 
228
+ @lru_cache(maxsize=4096)
229
+ def _pinyin_key(text: str) -> str:
230
+ if not text:
231
+ return ""
232
+ if lazy_pinyin is None:
233
+ return text
234
+ try:
235
+ return "".join(lazy_pinyin(text, errors="ignore"))
236
+ except Exception:
237
+ return text
238
+
239
+
240
+ def closed_text_score(left: str, right: str) -> float:
241
+ """0–1 score combining glyph similarity and pinyin similarity."""
242
+
243
+ if not left or not right:
244
+ return 0.0
245
+ if left == right:
246
+ return 1.0
247
+ if rapid_fuzz is not None:
248
+ glyph = rapid_fuzz.ratio(left, right) / 100.0
249
+ pinyin = rapid_fuzz.ratio(_pinyin_key(left), _pinyin_key(right)) / 100.0
250
+ else:
251
+ glyph = difflib.SequenceMatcher(None, left, right, autojunk=False).ratio()
252
+ pinyin = difflib.SequenceMatcher(
253
+ None, _pinyin_key(left), _pinyin_key(right), autojunk=False
254
+ ).ratio()
255
+ return 0.6 * glyph + 0.4 * pinyin
256
+
257
+
217
258
  class NameMatcher:
218
259
  """Generic normalized-name index with conservative fuzzy fallback."""
219
260
 
@@ -257,6 +298,30 @@ class NameMatcher:
257
298
  return best
258
299
  return None
259
300
 
301
+ def closed_match(self, text: str, *, threshold: float = 0.65) -> tuple[int, str, float] | None:
302
+ """Closed-set OCR correction with glyph + pinyin similarity."""
303
+
304
+ normalized = normalize_text(text)
305
+ if len(normalized) < 2:
306
+ return None
307
+ candidates = text_variants(text)
308
+ if not candidates:
309
+ return None
310
+ best: tuple[int, str, float] | None = None
311
+ for key, name, variants in self._entries:
312
+ for candidate in candidates:
313
+ for variant in variants:
314
+ if len(variant) < 2:
315
+ continue
316
+ score = closed_text_score(candidate, variant)
317
+ if best is None or score > best[2]:
318
+ best = (key, name, score)
319
+ if score >= 0.999:
320
+ return best
321
+ if best is not None and best[2] >= threshold:
322
+ return best
323
+ return None
324
+
260
325
  def __len__(self) -> int:
261
326
  return len(self._entries)
262
327
 
@@ -347,6 +412,30 @@ class StatsMatcher:
347
412
  match_score=found[2],
348
413
  )
349
414
 
415
+ def match_augment_closed(
416
+ self,
417
+ text: str,
418
+ *,
419
+ confidence: float = 1.0,
420
+ threshold: float = 0.65,
421
+ center_x: float = 0.0,
422
+ center_y: float = 0.0,
423
+ ) -> AugmentMatch | None:
424
+ found = self.augment_matcher.closed_match(text, threshold=threshold)
425
+ if not found:
426
+ return None
427
+ augment = self.repo.get_augment(found[0])
428
+ if not augment:
429
+ return None
430
+ return AugmentMatch(
431
+ augment=augment,
432
+ raw_text=text,
433
+ confidence=max(0.0, min(1.0, confidence)),
434
+ match_score=found[2],
435
+ center_x=center_x,
436
+ center_y=center_y,
437
+ )
438
+
350
439
  def match_augment_lines(
351
440
  self,
352
441
  lines: Iterable[OCRLine],
@@ -281,6 +281,7 @@ class AugmentMatch:
281
281
  match_score: float
282
282
  center_x: float = 0.0
283
283
  center_y: float = 0.0
284
+ x_center_ratio: float = 0.0
284
285
 
285
286
  @property
286
287
  def key(self) -> int: