153 lines
5.4 KiB
Lua
153 lines
5.4 KiB
Lua
require("Base/BasePanel")
|
||
HelpPopup = Inherit(BasePanel)
|
||
local this = HelpPopup
|
||
|
||
this.Rect = {}
|
||
this.value = nil
|
||
this.value0 = nil
|
||
this.value1 = nil
|
||
this.contentrootRect = nil
|
||
this.configData = {}
|
||
this.helpBtnPosX = 0 --传入帮助按钮位置,暂时用上X
|
||
this.helpBtnPosY = 0
|
||
|
||
--初始化组件(用于子类重写)
|
||
function HelpPopup:InitComponent()
|
||
this.spLoader = SpriteLoader.New()
|
||
this.mask = Util.GetGameObject(self.gameObject, "mask")
|
||
|
||
this.RContentroot = Util.GetGameObject(self.gameObject, "RContentroot")
|
||
this.RContentrootRect = Util.GetGameObject(self.transform, "RContentroot"):GetComponent("RectTransform") --位置
|
||
this.RContent = Util.GetGameObject(self.transform, "RContentroot/bg/RContent"):GetComponent("Text") --内容
|
||
|
||
this.LContentroot = Util.GetGameObject(self.gameObject, "LContentroot")
|
||
this.LContentrootRect = Util.GetGameObject(self.transform, "LContentroot"):GetComponent("RectTransform")
|
||
this.LContent = Util.GetGameObject(self.transform, "LContentroot/bg/LContent"):GetComponent("Text")
|
||
|
||
this.MContentroot = Util.GetGameObject(self.gameObject, "MContentroot")
|
||
this.MContentrootRect = Util.GetGameObject(self.transform, "MContentroot"):GetComponent("RectTransform")
|
||
this.MContent = Util.GetGameObject(self.transform, "MContentroot/bg/MContent"):GetComponent("Text")
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function HelpPopup:BindEvent()
|
||
Util.AddOnceClick(this.mask, function()
|
||
this:ClosePanel()
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function HelpPopup:AddListener()
|
||
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function HelpPopup:RemoveListener()
|
||
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function HelpPopup:OnOpen(_QAConfigID, posX, poxY, func)
|
||
this.QAConfigID = _QAConfigID
|
||
this.Rect = Util.GetGameObject(self.transform, "HelpPopup"):GetComponent("RectTransform")
|
||
this.helpBtnPosX = posX
|
||
this.helpBtnPosY = poxY
|
||
|
||
if posX > 0 then
|
||
this.contentrootRect = this.RContentrootRect
|
||
this.value = 1
|
||
else
|
||
this.contentrootRect = this.LContentrootRect
|
||
this.value = -1
|
||
end
|
||
--ogErrorTrace(this.value)
|
||
this.func = func
|
||
local update
|
||
update = function()
|
||
if Input.GetMouseButtonDown(0) then
|
||
local v2 = Input.mousePosition
|
||
--Log("鼠标点击坐标"..v2.x.." "..v2.y)
|
||
this.value0, this.value1 = RectTransformUtility.ScreenPointToLocalPointInRectangle(this.Rect, v2,
|
||
UIManager.camera, nil)
|
||
--Log("对应UI坐标"..this.value1.x.." "..this.value1.y)
|
||
--Log("面板位置坐标"..this.contentrootRect.localPosition.x.." "..this.contentrootRect.localPosition.y)
|
||
--Log("面板大小"..this.contentrootRect.sizeDelta.x.." "..this.contentrootRect.sizeDelta.y)
|
||
|
||
if CheckLOrR(this.value) == 0 then
|
||
return
|
||
end
|
||
this:ClosePanel()
|
||
UpdateBeat:Remove(update, this)
|
||
end
|
||
end
|
||
-- UpdateBeat:Add(update, this)--2020/10/29界面优化取消左右QA,全部具中
|
||
end
|
||
|
||
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
||
function HelpPopup:OnShow()
|
||
this.RContentroot:SetActive(false)
|
||
this.LContentroot:SetActive(false)
|
||
|
||
this.configData = ConfigManager.TryGetConfigData(ConfigName.QAConfig, this.QAConfigID)
|
||
if not this.configData then
|
||
LogError("不存在的QA,id:" .. tostring(this.QAConfigID))
|
||
this:ClosePanel()
|
||
return
|
||
end
|
||
local str = GetLanguageStrById(this.configData.content)
|
||
str = string.gsub(str, "{", "<color=#D48A07>")
|
||
str = string.gsub(str, "}", "</color>")
|
||
str = string.gsub(str, "|", "\n") --换行
|
||
if this.helpBtnPosX > 0 then
|
||
--Log("右")
|
||
-- this.RContentroot:SetActive(true)--2020/10/29界面优化取消左右QA,全部具中
|
||
this.RContentrootRect.anchoredPosition = Vector3.New(this.helpBtnPosX - 30, this.helpBtnPosY)
|
||
this.RContent.text = str
|
||
else
|
||
--Log("左")
|
||
-- this.LContentroot:SetActive(true)--2020/10/29界面优化取消左右QA,全部具中
|
||
this.LContentrootRect.anchoredPosition = Vector3.New(this.helpBtnPosX + 30, this.helpBtnPosY)
|
||
this.LContent.text = str
|
||
end
|
||
this.MContent.text = str
|
||
end
|
||
|
||
--界面关闭时调用(用于子类重写)
|
||
function HelpPopup:OnClose()
|
||
if this.func then
|
||
this.func()
|
||
end
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function HelpPopup:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
end
|
||
|
||
function CheckLOrR(index)
|
||
--右
|
||
if index == 1 then
|
||
if this.value1.x > this.RContentrootRect.localPosition.x - this.contentrootRect.sizeDelta.x and
|
||
this.value1.x < this.RContentrootRect.localPosition.x and
|
||
this.value1.y < this.contentrootRect.localPosition.y and
|
||
this.value1.y > this.contentrootRect.localPosition.y - this.contentrootRect.sizeDelta.y then
|
||
--Log("执行右")
|
||
return 0
|
||
end
|
||
end
|
||
--左
|
||
if index == -1 then
|
||
if this.value1.x > this.LContentrootRect.localPosition.x and
|
||
this.value1.x < this.LContentrootRect.localPosition.x + this.contentrootRect.sizeDelta.x and
|
||
this.value1.y < this.contentrootRect.localPosition.y and
|
||
this.value1.y > this.contentrootRect.localPosition.y - this.contentrootRect.sizeDelta.y then
|
||
--Log("执行左")
|
||
return 0
|
||
end
|
||
end
|
||
|
||
return 1
|
||
end
|
||
|
||
return HelpPopup
|