160 lines
5.5 KiB
Python
160 lines
5.5 KiB
Python
# -*- coding: utf-8 -*-
|
||
import ui
|
||
import math
|
||
import player
|
||
import net
|
||
import app
|
||
import wndMgr
|
||
import touch
|
||
import constInfo
|
||
import ui_mobile_widgets as widgets
|
||
import ui_mobile_autohunt
|
||
|
||
class MobileCombatWheel(ui.Window):
|
||
"""
|
||
移动端战斗轮盘(屏幕右下角)
|
||
- 大攻击键:按下由原生触摸分流器判定(touch.SetAttackButton),按住等同键盘攻击键;
|
||
本窗口只画圆框并显示按下状态
|
||
- 攻击键外两圈共 8 个快捷格 = 当前快捷页的 8 格(PC 任务栏 1-4 / F1-F4 同一份数据),
|
||
第 4 页留给底部药水栏,所以这里只在第 1-3 页间切换
|
||
- 小按钮:快捷页切换、上下马(原版 Ctrl+G 的 /ride)、拾取(原版 ` / Z 键)
|
||
- AUTO 键(第 6 步自动狩猎,ui_mobile_autohunt.py):轻点开关,长按设置
|
||
"""
|
||
ATTACK_RADIUS = 60
|
||
SLOT_DIAMETER = 50
|
||
SMALL_DIAMETER = 44
|
||
AUTO_DIAMETER = 46
|
||
# (半径, 角度):角度从 +x 逆时针,内外圈各 4 格,外圈错开半格;相邻格间距大于格子直径
|
||
SLOT_LAYOUT = [(108, 90), (108, 120), (108, 150), (108, 180),
|
||
(172, 97.5), (172, 122.5), (172, 147.5), (172, 172.5)]
|
||
RING_PAGE_COUNT = 3
|
||
WINDOW_EXTENT = 200
|
||
|
||
def __init__(self, origin_x=None, origin_y=None):
|
||
ui.Window.__init__(self)
|
||
self.SetWindowName("MobileCombatWheel")
|
||
# 轮盘容器不拦截触摸,否则会盖住攻击键热区和世界点击;子按钮仍可点
|
||
self.AddFlag("not_pick")
|
||
|
||
sw = wndMgr.GetScreenWidth()
|
||
sh = wndMgr.GetScreenHeight()
|
||
# 安全区(刘海/圆角/手势条)内缩,桌面为 0
|
||
safe_l, safe_t, safe_r, safe_b = touch.GetSafeArea()
|
||
if origin_x is None:
|
||
origin_x = sw - safe_r - 120
|
||
if origin_y is None:
|
||
origin_y = sh - safe_b - 120
|
||
self.origin_x = origin_x
|
||
self.origin_y = origin_y
|
||
|
||
# 窗口左上角 = 圆心 - WINDOW_EXTENT;右下留出攻击键与小按钮
|
||
ext = self.WINDOW_EXTENT
|
||
self.SetPosition(origin_x - ext, origin_y - ext)
|
||
self.SetSize(ext + 120, ext + 120)
|
||
cx = cy = ext
|
||
|
||
# 1. 攻击键
|
||
r = self.ATTACK_RADIUS
|
||
self.attack_disc = widgets.MakeDisc(self, cx - r, cy - r, r * 2, widgets.STYLE_ATTACK)
|
||
self.attack_icon = ui.ExpandedImageBox()
|
||
self.attack_icon.SetParent(self)
|
||
self.attack_icon.AddFlag("not_pick")
|
||
try:
|
||
self.attack_icon.LoadImage("d:/ymir work/ui/game/taskbar/mouse_button_attack_01.sub")
|
||
self.attack_icon.SetScale(2.0, 2.0)
|
||
self.attack_icon.SetPosition(cx - self.attack_icon.GetWidth() / 2, cy - self.attack_icon.GetHeight() / 2)
|
||
self.attack_icon.Show()
|
||
except:
|
||
pass
|
||
self.aim_marker = widgets.MakeDisc(self, 0, 0, 44, widgets.STYLE_JOY_KNOB)
|
||
self.aim_marker.Hide()
|
||
self.attack_pressed = False
|
||
touch.SetAttackButton(origin_x, origin_y, r)
|
||
|
||
# 2. 快捷格
|
||
self.slots = []
|
||
half = self.SLOT_DIAMETER / 2
|
||
for i, (radius, angle) in enumerate(self.SLOT_LAYOUT):
|
||
rad = math.radians(angle)
|
||
x = int(cx + radius * math.cos(rad)) - half
|
||
y = int(cy - radius * math.sin(rad)) - half
|
||
slot = widgets.QuickSlotDisc(self.SLOT_DIAMETER, localIndex=i)
|
||
slot.SetParent(self)
|
||
slot.SetPosition(x, y)
|
||
slot.Show()
|
||
self.slots.append(slot)
|
||
|
||
# 3. 小按钮(攻击键左下 / 右上)
|
||
d = self.SMALL_DIAMETER
|
||
self.page_button = self.__MakeSmall(cx - 150 - d / 2, cy + 40 - d / 2, ui.__mem_func__(self.__OnNextPage))
|
||
self.page_button.SetLabel("1")
|
||
self.mount_button = self.__MakeSmall(cx + 62 - d / 2, cy - 92 - d / 2, ui.__mem_func__(self.__OnMount))
|
||
self.mount_button.SetLabel("Ride")
|
||
self.pickup_button = self.__MakeSmall(cx - 86 - d / 2, cy + 82 - d / 2, ui.__mem_func__(self.__OnPickUp))
|
||
self.pickup_button.SetLabel("Pick")
|
||
self.auto_button = ui_mobile_autohunt.AutoHuntButton(self.AUTO_DIAMETER)
|
||
self.auto_button.SetParent(self)
|
||
self.auto_button.SetPosition(cx + 70 - self.AUTO_DIAMETER / 2, cy - 160 - self.AUTO_DIAMETER / 2)
|
||
self.auto_button.Show()
|
||
|
||
self.page = -1
|
||
self.lastRefresh = 0
|
||
self.Refresh()
|
||
|
||
def __del__(self):
|
||
ui.Window.__del__(self)
|
||
|
||
def __MakeSmall(self, x, y, event):
|
||
button = widgets.RoundButton(self.SMALL_DIAMETER)
|
||
button.SetParent(self)
|
||
button.SetPosition(x, y)
|
||
button.SetEvent(event)
|
||
button.Show()
|
||
return button
|
||
|
||
def __OnNextPage(self):
|
||
# game.__SelectQuickPage 同一路径(player.SetQuickPage)
|
||
player.SetQuickPage((player.GetQuickPage() + 1) % self.RING_PAGE_COUNT)
|
||
self.Refresh()
|
||
|
||
def __OnMount(self):
|
||
net.SendChatPacket("/ride")
|
||
|
||
def __OnPickUp(self):
|
||
game = constInfo.GetGameInstance()
|
||
if game:
|
||
game.PickUpItem()
|
||
else:
|
||
player.PickCloseItem()
|
||
|
||
def Refresh(self):
|
||
page = player.GetQuickPage()
|
||
if page >= self.RING_PAGE_COUNT:
|
||
# 第 4 页是药水栏,PC 端切到那里时轮盘回到第 1 页
|
||
player.SetQuickPage(0)
|
||
page = 0
|
||
if page != self.page:
|
||
self.page = page
|
||
self.page_button.label.SetText(str(page + 1))
|
||
for slot in self.slots:
|
||
slot.Refresh()
|
||
|
||
def OnUpdate(self):
|
||
active, ox, oy, x, y = touch.GetSkillAim()
|
||
if active and math.hypot(x - ox, y - oy) > 14:
|
||
px, py = self.GetGlobalPosition()
|
||
self.aim_marker.SetPosition(int(x - px - 22), int(y - py - 22))
|
||
self.aim_marker.Show()
|
||
else:
|
||
self.aim_marker.Hide()
|
||
pressed = touch.IsAttackPressed()
|
||
if pressed != self.attack_pressed:
|
||
self.attack_pressed = pressed
|
||
self.attack_disc.SetStyle(widgets.STYLE_ATTACK_DOWN if pressed else widgets.STYLE_ATTACK)
|
||
self.auto_button.OnUpdate()
|
||
|
||
# 与 uitaskbar.TaskBar.OnUpdate 相同的 500 ms 刷新(冷却、数量、激活状态)
|
||
if app.GetGlobalTime() - self.lastRefresh > 500:
|
||
self.lastRefresh = app.GetGlobalTime()
|
||
self.Refresh()
|