hengyang_client/lua_probject/base_project/Game/View/Common/BaseView.lua

101 lines
2.2 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
--view 基类
--author--
---
--@type BaseView
BaseView = {
2025-04-15 17:55:51 +08:00
-- Id View ID
Id = 0,
-- View 是否被销毁
_is_destroy = false,
--关闭摧毁
_close_destroy = false,
2025-07-08 20:29:50 +08:00
--缩放全屏
_scale = false,
2025-04-15 17:55:51 +08:00
-- 全屏
_full = false,
--全屏偏移
_full_offset = true,
--view description
_view = nil,
2025-04-01 10:48:36 +08:00
}
local M = BaseView
local view_url = {
2025-04-15 17:55:51 +08:00
"ui://Common/Gcm_BaseView",
"ui://Common/Gcm_BaseView_Full"
2025-04-01 10:48:36 +08:00
}
2025-07-16 15:07:29 +08:00
local _views = {}
2025-04-01 10:48:36 +08:00
---
--@function [parent=#BaseView] InitView
--@param self
--@param #string url
function M:InitView(url)
2025-04-15 17:55:51 +08:00
self._root_view = UIPackage.CreateObjectFromURL(self._full and view_url[2] or view_url[1])
local contentPane = self._root_view:GetChild("contentPane")
self._view = UIPackage.CreateObjectFromURL(url)
2025-05-14 18:56:50 +08:00
printlog(self._view, url)
2025-04-15 17:55:51 +08:00
self._close_destroy = true
-- self._view.fairyBatching = true
self._view:AddRelation(contentPane, RelationType.Size)
contentPane:AddChild(self._view)
self._contentPane = contentPane
2025-07-16 15:07:29 +08:00
_views[self.class] = self
2025-04-01 10:48:36 +08:00
end
function M:Show()
2025-04-15 17:55:51 +08:00
self._root_view.visible = true
if not self._root_view.parent then
AddPanel(self._root_view)
if self._full then
local offset = get_offset(self._full_offset)
2025-04-01 10:48:36 +08:00
2025-04-15 17:55:51 +08:00
self._contentPane.width = GRoot.inst.width - (offset * 2)
self._contentPane.height = GRoot.inst.height
self._contentPane.x = offset
end
2025-07-08 20:29:50 +08:00
if self._scale then
local scaleY = GRoot.inst.height / self._contentPane.height
local scaleX = GRoot.inst.width / self._contentPane.width
self._contentPane:SetScale(scaleX, scaleY)
2025-08-06 21:44:48 +08:00
self._contentPane.x = 0
self._contentPane.y = 0
2025-07-08 20:29:50 +08:00
end
2025-04-15 17:55:51 +08:00
end
2025-04-01 10:48:36 +08:00
end
function M:Close()
self._root_view.visible = false
end
--游戏暂停
function M:OnApplicationPause()
2025-04-15 17:55:51 +08:00
2025-04-01 10:48:36 +08:00
end
--游戏暂停
function M:OnApplicationActive()
2025-04-15 17:55:51 +08:00
2025-04-01 10:48:36 +08:00
end
---
--@function [parent=#BaseView] Destroy
--@param self
function M:Destroy()
2025-08-28 19:15:06 +08:00
if self.Close then
self:Close()
end
2025-04-15 17:55:51 +08:00
self._is_destroy = true
self._root_view:Dispose()
2025-07-16 15:07:29 +08:00
_views[self.class] = nil
2025-04-15 17:55:51 +08:00
end
2025-07-16 15:07:29 +08:00
function BaseView.FindView(class)
return _views[class] or nil
2025-08-28 19:15:06 +08:00
end