249 lines
6.7 KiB
Lua
249 lines
6.7 KiB
Lua
local uiCtrl = require_ex('UI/Panels/Base/UICtrl')
|
|
local PANEL_ID = PanelId.ControllerNaviTarget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl = HL.Class('ControllerNaviTargetCtrl', uiCtrl.UICtrl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.s_messages = HL.StaticField(HL.Table) << {
|
|
[MessageConst.ON_CONTROLLER_NAVI_TARGET_CHANGED] = 'OnControllerNaviTargetChanged',
|
|
[MessageConst.ON_PANEL_ORDER_RECALCULATED] = 'OnPanelOrderRecalculated',
|
|
}
|
|
|
|
|
|
ControllerNaviTargetCtrl.m_lateTickKey = HL.Field(HL.Number) << -1
|
|
|
|
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnCreate = HL.Override(HL.Any) << function(self, arg)
|
|
self.view.hintRect.gameObject:SetActive(false)
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnShow = HL.Override() << function(self)
|
|
self:StartTick()
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnHide = HL.Override() << function(self)
|
|
self:StopTick()
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnClose = HL.Override() << function(self)
|
|
self:StopTick()
|
|
end
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnInputDeviceTypeChanged = HL.StaticMethod(HL.Opt(HL.Any)) << function(arg)
|
|
if DeviceInfo.usingController then
|
|
UIManager:AutoOpen(PANEL_ID)
|
|
else
|
|
local isOpen, ctrl = UIManager:IsOpen(PANEL_ID)
|
|
if isOpen then
|
|
ctrl:RecoverHintParent()
|
|
end
|
|
UIManager:Hide(PANEL_ID)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.RecoverHintParent = HL.Method() << function(self)
|
|
self.view.hintRect:SetParent(self.view.rectTransform)
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.StartTick = HL.Method() << function(self)
|
|
self:_SyncHintRect()
|
|
self.m_lateTickKey = LuaUpdate:Add("TailTick", function(deltaTime)
|
|
self:_SyncHintRect()
|
|
end)
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.StopTick = HL.Method() << function(self)
|
|
self.m_lateTickKey = LuaUpdate:Remove(self.m_lateTickKey)
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnPanelOrderRecalculated = HL.Method() << function(self)
|
|
self:_CalcCanvasOrder()
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl.OnControllerNaviTargetChanged = HL.Method() << function(self)
|
|
self:_CalcCanvasOrder()
|
|
self:_SyncHintRectTransformParent()
|
|
self:_SyncHintRect()
|
|
self:_PlayHintRectAnimation()
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl._CalcCanvasOrder = HL.Method() << function(self)
|
|
local target = InputManagerInst.controllerNaviManager.curTarget
|
|
if IsNull(target) then
|
|
return
|
|
end
|
|
local canvas = target.transform:GetComponentInParent(typeof(Unity.Canvas), true)
|
|
self:SetSortingOrder(canvas.sortingOrder + 1, false)
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl._SyncHintRect = HL.Method() << function(self)
|
|
local hint = self.view.hintRect
|
|
if not DeviceInfo.usingController then
|
|
hint.gameObject:SetActive(false)
|
|
return
|
|
end
|
|
|
|
local target = InputManagerInst.controllerNaviManager.curTarget
|
|
local selfIsActive = hint.gameObject.activeSelf
|
|
if IsNull(target) then
|
|
if selfIsActive then
|
|
hint.gameObject:SetActive(false)
|
|
end
|
|
return
|
|
end
|
|
|
|
local active = target.gameObject.activeInHierarchy and
|
|
InputManagerInst.controllerNaviManager:IsNavigationBindingEnabled() and
|
|
not target.hideNaviHint
|
|
if selfIsActive ~= active then
|
|
hint.gameObject:SetActive(active)
|
|
end
|
|
if not active then
|
|
return
|
|
end
|
|
|
|
local targetTransform = NotNull(target.overrideNaviHintRectTransform) and target.overrideNaviHintRectTransform or target.transform
|
|
if target.changeNaviHintParent then
|
|
hint.pivot = targetTransform.pivot
|
|
hint.anchorMin = targetTransform.anchorMin
|
|
hint.anchorMax = targetTransform.anchorMax
|
|
hint.position = targetTransform.position
|
|
hint.sizeDelta = targetTransform.sizeDelta
|
|
hint.rotation = targetTransform.rotation
|
|
self.view.animationNodeTrans.localScale = targetTransform.localScale * target.overrideNaviHintRectScale
|
|
else
|
|
local targetScreenRect = UIUtils.getTransformScreenRect(targetTransform, self.uiCamera)
|
|
local canvasSize = self.view.transform.rect.size
|
|
local targetScreenSize = targetScreenRect.size
|
|
hint.position = UIUtils.getRectTransformCenterPosition(targetTransform)
|
|
hint.sizeDelta = Vector2(targetScreenSize.x / Screen.width * canvasSize.x, targetScreenSize.y / Screen.height * canvasSize.y)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl._PlayHintRectAnimation = HL.Method() << function(self)
|
|
if not self.view.hintRect.gameObject.activeSelf then
|
|
return
|
|
end
|
|
self.view.hintRectAnim:ClearTween()
|
|
self.view.hintRectAnim:PlayInAnimation()
|
|
end
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl._SyncHintRectTransformParent = HL.Method() << function(self)
|
|
local hint = self.view.hintRect
|
|
local target = InputManagerInst.controllerNaviManager.curTarget
|
|
local targetValid = NotNull(target)
|
|
if targetValid and target.changeNaviHintParent then
|
|
local targetTransform = NotNull(target.overrideNaviHintRectTransform) and target.overrideNaviHintRectTransform or target.transform
|
|
hint:SetParent(targetTransform.parent)
|
|
hint:SetAsLastSibling()
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(targetTransform.parent)
|
|
else
|
|
hint:SetParent(self.view.rectTransform)
|
|
hint.rotation = Quaternion.identity
|
|
hint.pivot = Vector2(0.5, 0.5)
|
|
hint.anchorMin = Vector2(0.5, 0.5)
|
|
hint.anchorMax = Vector2(0.5, 0.5)
|
|
if targetValid then
|
|
self.view.animationNodeTrans.localScale = Vector3.one * target.overrideNaviHintRectScale
|
|
else
|
|
self.view.animationNodeTrans.localScale = Vector3.one
|
|
end
|
|
end
|
|
hint.localScale = Vector3.one
|
|
if targetValid then
|
|
self.view.hintRectConfirmKeyHint.gameObject:SetActive(target.needNaviConfirmKeyHint)
|
|
end
|
|
self.view.hintRectConfirmKeyHint.transform.localScale = Vector3.one / hint.localScale.x
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControllerNaviTargetCtrl._SyncHintArrow = HL.Method() << function(self)
|
|
local hint = self.view.hintArrow
|
|
if not DeviceInfo.usingController then
|
|
hint.gameObject:SetActiveIfNecessary(false)
|
|
return
|
|
end
|
|
local target = InputManagerInst.controllerNaviManager.curTarget
|
|
local selfIsActive = hint.gameObject.activeInHierarchy
|
|
if IsNull(target) then
|
|
if selfIsActive then
|
|
hint.gameObject:SetActive(false)
|
|
end
|
|
return
|
|
end
|
|
local active = target.gameObject.activeInHierarchy and InputManagerInst.controllerNaviManager:IsNavigationBindingEnabled()
|
|
if selfIsActive ~= active then
|
|
hint.gameObject:SetActive(active)
|
|
end
|
|
if not active then
|
|
return
|
|
end
|
|
local targetScreenRect = UIUtils.getTransformScreenRect(target.transform, self.uiCamera)
|
|
local canvasSize = self.view.transform.rect.size
|
|
hint.anchoredPosition = Vector2(targetScreenRect.xMin / Screen.width * canvasSize.x, - targetScreenRect.yMin / Screen.height * canvasSize.y)
|
|
end
|
|
|
|
|
|
|
|
|
|
HL.Commit(ControllerNaviTargetCtrl)
|