221 lines
6.6 KiB
Lua
221 lines
6.6 KiB
Lua
Up_BaseClassOBJ = {}
|
||
-- 基类类型
|
||
Up_BaseClassOBJ.__index = Up_BaseClassOBJ
|
||
|
||
Up_BaseClassOBJ.__cname = "Up_BaseClassOBJ"
|
||
|
||
|
||
Up_BaseClassOBJ.xh = {}
|
||
Up_BaseClassOBJ.obj = {}
|
||
|
||
Up_BaseClassOBJ.UIfile = nil
|
||
|
||
Up_BaseClassOBJ.npcid = nil
|
||
---* 窗口创建
|
||
function Up_BaseClassOBJ:main(arg1, arg2, arg3, data)
|
||
local parent = GUI:Win_Create(self.__cname, 0, 0, 0, 0, false, false, true, false)
|
||
|
||
if data and data.npcid then
|
||
GUI:Win_BindNPC(parent, data.npcid)
|
||
self.npcid = data.npcid
|
||
end
|
||
|
||
if not self.UIfile then
|
||
return
|
||
end
|
||
|
||
if type(self.UIfile) == "table" then
|
||
GUI:LoadExport(parent, self.UIfile[data.npcid])
|
||
else
|
||
GUI:LoadExport(parent, self.UIfile)
|
||
end
|
||
|
||
self._parent = parent
|
||
self.ui = GUI:ui_delegate(parent)
|
||
|
||
--- 窗口初始化居中与动作
|
||
ssrUIManager:OpenAlgin(self)
|
||
|
||
--背景图关闭
|
||
GUI:addOnClickEvent(self.ui.bg_close, function()
|
||
GUI:Win_Close(self._parent)
|
||
end)
|
||
|
||
--关闭按钮背景板关闭
|
||
GUI:addOnClickEvent(self.ui.btn_close, function()
|
||
GUI:Win_Close(self._parent)
|
||
end)
|
||
|
||
---* 绑定事件
|
||
self:EventBind()
|
||
|
||
if data and data.cfg then
|
||
self.cfg = data.cfg
|
||
end
|
||
|
||
if data and data.other then
|
||
self.other = data.other
|
||
end
|
||
|
||
self.id = 1
|
||
|
||
if self.leftBtnImg and GUI:Win_IsNotNull(self.ui.Listbtn_ListView) then
|
||
self:initListBtn()
|
||
else
|
||
self:updata()
|
||
end
|
||
|
||
--模块内存数据(self.cfg / self.other)已填充且 updata 跑过一次,通知红点系统重算本模块名下的所有红点
|
||
--避免业务层在每个 updata 末尾重复写 RedDotMgr:refresh 兑底
|
||
if RedDotMgr and RedDotMgr.refreshByOwner then
|
||
RedDotMgr:refreshByOwner(self.__cname)
|
||
end
|
||
end
|
||
|
||
---* 初始化左侧按钮列表
|
||
function Up_BaseClassOBJ:initListBtn()
|
||
self.id = self.id or 1
|
||
local listview = self.ui.Listbtn_ListView
|
||
local imgDir = self.leftBtnImg
|
||
GUI:ListView_removeAllItems(listview)
|
||
for i = 1, self.leftNum do
|
||
local btnKey = string.format("list_btn_%d", i)
|
||
local isSelected = (self.id == i)
|
||
self.ui[btnKey] = GUI:Button_Create(listview, btnKey, 0, 0,
|
||
string.format("%s/%s.png", imgDir, isSelected and (i .. "a") or tostring(i)))
|
||
GUI:addOnClickEvent(self.ui[btnKey], function()
|
||
if self.id == i then return end --重复点击不刷新
|
||
local oldId = self.id
|
||
self.id = i
|
||
--还原旧选中按钮为普通态(只换 normal 贴图)
|
||
GUI:Button_loadTextures(self.ui[string.format("list_btn_%d", oldId)],
|
||
string.format("%s/%s.png", imgDir, oldId), "", "", 0)
|
||
--设置新按钮为选中态(只换 normal 贴图)
|
||
GUI:Button_loadTextures(self.ui[btnKey],
|
||
string.format("%s/%s.png", imgDir, i .. "a"), "", "", 0)
|
||
self:updata()
|
||
end)
|
||
end
|
||
self:updata()
|
||
end
|
||
|
||
|
||
----* 设置消耗展示
|
||
function Up_BaseClassOBJ:seIitemShow(sclae,interval)
|
||
---* 绑定事件
|
||
self:Up_EventBind()
|
||
|
||
if GUI:Win_IsNull(self.ui.xh_Layout) then
|
||
return false
|
||
end
|
||
|
||
if not self.xh then
|
||
return
|
||
end
|
||
|
||
GUI:removeAllChildren(self.ui.xh_Layout)
|
||
hk.SettingXhShow(self.ui, self.ui.xh_Layout, self.xh, nil, nil, nil, 0, nil, self.xh_interval or 20, self.xh_scale or 1, true)
|
||
end
|
||
|
||
---* 设置属性在控件中展示
|
||
function Up_BaseClassOBJ:setAttrShow(itemName, parent, fontsize)
|
||
local _index = SL:Get_ITEM_INDEX_BY_NAME(itemName)
|
||
local titleData = SL:Get_ITEM_DATA(_index)
|
||
local attr = hk.getequipAttribute(titleData.Attribute)
|
||
if attr then
|
||
GUI:ListView_removeAllItems(parent)
|
||
for i, v in ipairs(attr or {}) do
|
||
local list = string.format("list_att_%d", i)
|
||
self.ui[list] = GUI:RichTextFCOLOR_Create(parent, list, 100, 0, v, 600, fontsize and fontsize or 12,
|
||
"#28EF01", 5)
|
||
end
|
||
end
|
||
end
|
||
|
||
----* 设置奖励展示
|
||
function Up_BaseClassOBJ:setgiveItem()
|
||
if GUI:Win_IsNull(self.ui.give_Layout) then
|
||
return false
|
||
end
|
||
|
||
if not self.give then
|
||
return
|
||
end
|
||
|
||
GUI:removeAllChildren(self.ui.give_Layout)
|
||
hk.SettingXhShow(self.ui, self.ui.give_Layout, self.give, nil, nil, nil, 0, nil, 20, nil, false)
|
||
end
|
||
|
||
---* 设置掉落展示
|
||
function Up_BaseClassOBJ:setDropShow(sclae, gap)
|
||
if not self.drop then
|
||
return
|
||
end
|
||
if GUI:Win_IsNotNull(self.ui.drop_Layout) then
|
||
GUI:removeAllChildren(self.ui.drop_Layout)
|
||
hk.SettingXhShow(self.ui, self.ui.drop_Layout, self.drop, nil, nil, nil, 0, nil, gap and gap or 20,
|
||
sclae and sclae or nil, false)
|
||
else
|
||
for i, v in ipairs(self.drop) do
|
||
local parent = string.format("drop_item_%d", i)
|
||
if GUI:Win_IsNotNull(self.ui[parent]) then
|
||
hk.reloadItemShow(self.ui[parent], v, 1)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
---* 播放屏幕特效
|
||
function Up_BaseClassOBJ:screffects(id)
|
||
if GUI:Win_IsNotNull(self.ui.screffect) then
|
||
GUI:removeFromParent(self.ui.screffect)
|
||
end
|
||
local bg_size = GUI:getContentSize(self.ui.img_bg)
|
||
self.ui.screffect = GUI:Effect_Create(self.ui.img_bg, "screffect", 300, 450, 0, id, 0, 0,
|
||
0, 1)
|
||
-- GUI:setAnchorPoint(self.ui.screffect, 0.50, 0.50)
|
||
GUI:Effect_addOnCompleteEvent(self.ui.screffect, function()
|
||
GUI:removeFromParent(self.ui.screffect)
|
||
end)
|
||
end
|
||
|
||
function Up_BaseClassOBJ:new()
|
||
local instance = {}
|
||
setmetatable(instance, self)
|
||
return instance
|
||
end
|
||
|
||
---* 注册事件
|
||
function Up_BaseClassOBJ:Up_EventBind()
|
||
---* 背包 和 货币 物品变化
|
||
local function Up_BaseClassOBJ_REINLEVELCHANGE(data)
|
||
if GUI:Win_IsNotNull(self._parent) then
|
||
self:seIitemShow()
|
||
end
|
||
end
|
||
SL:RegisterLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, self.__cname, Up_BaseClassOBJ_REINLEVELCHANGE)
|
||
SL:RegisterLUAEvent(LUA_EVENT_MONEY_CHANGE, self.__cname, Up_BaseClassOBJ_REINLEVELCHANGE)
|
||
|
||
|
||
--关闭窗口
|
||
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "UP", function(widgetName)
|
||
self:UP_OnClose(widgetName)
|
||
end)
|
||
end
|
||
|
||
--关闭窗口
|
||
function Up_BaseClassOBJ:UP_OnClose(widgetName)
|
||
if widgetName == self.__cname then
|
||
self:UP_UnRegisterEvent()
|
||
end
|
||
end
|
||
|
||
function Up_BaseClassOBJ:UP_UnRegisterEvent()
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_MONEY_CHANGE, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "UP")
|
||
end
|
||
|
||
return Up_BaseClassOBJ
|