Skip to content

Commit d0c273b

Browse files
committed
fix(map): 地图预览竖直方向翻转修正
tiles[r] 中 r=0 是玩家视角最上行(行号最大),r=height-1 是最下行(行号1)。 旧渲染按错误的"row=0 最下面"假设翻转(y=(h-1-r)*cell),导致上下颠倒 (如 F5 应在上方却显示在下方)。 map_picker 渲染改 y=r*cell(不翻转),mousePressEvent 回算 r=y//cell。 convert_pos.py docstring 同步修正(删"row=0 最下面"的错误描述)。 验证:1-7 F5(r=2)→画面上方、F1(r=6)→最下;与 view.py 投影(用 r 直接)方向一致。
1 parent 5f45555 commit d0c273b

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

aao/core/geometry/convert_pos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""棋盘记号(如 D2)↔ 格子坐标 (row, col)。
22
33
prts-plus 约定:Pos 列 = 字母(A=0, B=1, ...),行 = 数字(从下往上)。
4-
row=0 是最下面一行,row=height-1 是最上面一行
5-
col=0 是最左边一列。
4+
row=0 是 tiles 第一行(玩家视角最上、行号最大),row=height-1 是最下行(行号1)
5+
即行号 = height - row。col=0 是最左边一列。
66
77
例如 7 行 10 列的地图中:
88
A1 → (row=6, col=0) G10 → (row=0, col=9)

aao/ui/map_picker.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
点关卡 → 选中格子 → 生成棋盘记号(如 D2)→ 确认回填到编辑面板。
44
区分可部署/不可部署(buildableType: 0=不可, 1=地面, 2=高台)。
55
6-
棋盘坐标与 convert_pos 一致:列=字母(A=0), 行=数字(从下往上, row=0 最下)。
7-
QGraphicsScene 里 y 向下,故渲染时 row 越大越靠上 → y = (height-1-row)*cell。
6+
tiles[r] 中 r=0 是玩家视角最上行(行号最大),r=height-1 是最下行(行号1)。
7+
QGraphicsScene y 向下,故 y = r*cell:r 小(行号大、玩家上方)→画面上方。
8+
棋盘记号由 tile_position_to_str 算(行号 = height - r)。
89
"""
910

1011
from __future__ import annotations
@@ -64,9 +65,10 @@ def __init__(self, map_data: dict):
6465
# 不可部署加深
6566
if tile.get("buildableType", 0) == 0 and key not in ("start", "end"):
6667
base = base.darker(150)
67-
# y 向下:row 大=靠上 → y 小
68+
# tiles[r] 中 r=0 是玩家视角最上行(行号最大),r=height-1 是最下行(行号1)。
69+
# QScene y 向下,故 y = r*cell(r 小=行号大=玩家上方→画面上方)。
6870
x = c * _CELL
69-
y = (self._height - 1 - r) * _CELL
71+
y = r * _CELL
7072
rect = QGraphicsRectItem(x, y, _CELL, _CELL)
7173
rect.setBrush(QBrush(base))
7274
rect.setPen(QPen(QColor("#000"), 1))
@@ -91,8 +93,7 @@ def mousePressEvent(self, event: QMouseEvent) -> None:
9193
# 点击的可能是被 label 覆盖,回退:按坐标算
9294
sp = self.mapToScene(event.pos())
9395
c = int(sp.x() // _CELL)
94-
y = int(sp.y() // _CELL)
95-
r = self._height - 1 - y
96+
r = int(sp.y() // _CELL) # y=r*cell 渲染,故 r=y
9697
if 0 <= c < self._width and 0 <= r < self._height:
9798
self._select(c, r)
9899
super().mousePressEvent(event)

0 commit comments

Comments
 (0)