bayuMIR/client/dev/GUILayout/game/GotoMap/NPCGotoMapOBJ.lua

203 lines
6.5 KiB
Lua

NPCGotoMapOBJ = Up_BaseClassOBJ:new()
NPCGotoMapOBJ.__cname = "NPCGotoMapOBJ"
-- UI文件
NPCGotoMapOBJ.UIfile = {}
---* 获取所有gotomapUI文件
for i, v in ipairs(SL:GetFilesByPath("GUIExport/game/GotoMap") or {}) do
-- for _, flie in ipairs(SL:GetFilesByPath(game_file) or {}) do
local file_name = tonumber(SL:Split(v, ".")[1])
local game_file = string.format("game/GotoMap/%d", file_name)
if file_name then
NPCGotoMapOBJ.UIfile[file_name] = game_file
end
end
-- 配置文件
NPCGotoMapOBJ.cfg = {}
NPCGotoMapOBJ.other = nil
NPCGotoMapOBJ.s_btn = false
function NPCGotoMapOBJ:updata()
self.id = self.id or 1
self.bossId = 1
if #self.cfg > 1 and not self.s_btn then
self:setbtn()
end
local cfg = self.cfg[self.id]
---* 设置标题名称
GUI:Text_setString(self.ui.name_Text, cfg.name)
---* 设置小地图展示
if cfg.minimap and GUI:Win_IsNotNull(self.ui.mini_map_img) then
GUI:Image_loadTexture(self.ui.mini_map_img, string.format("res/uiminimap/%d.png", cfg.minimap))
GUI:setContentSize(self.ui.mini_map_img, 280, 214)
end
---* 设置boss展示
if cfg.BOSS then
GUI:setVisible(self.ui.BOSS_Layout, true)
self:bossshow()
else
GUI:setVisible(self.ui.BOSS_Layout, false)
end
if self.cfg[1].drop then
self.drop = self.cfg[1].drop
self:setDropShow(1, 6)
end
if cfg.zstz then
self:setText()
end
if cfg.ps and GUI:Win_IsNotNull(self.ui.Text) then
GUI:Text_setString(self.ui.Text, cfg.ps)
end
if cfg.BOSSvar and GUI:Win_IsNotNull(self.ui.boss_name) then
local _str = hk.getvalue("GLOBAL(" .. cfg.BOSSvar .. ")")
if _str ~= "" then
GUI:setVisible(self.ui.BOSS_ICON, true)
GUI:Text_setString(self.ui.boss_name, _str)
else
GUI:setVisible(self.ui.BOSS_ICON, false)
end
end
if cfg.reloadvar and GUI:Win_IsNotNull(self.ui.var_Text) then
local _value = tonumber(hk.getvalue(string.format("HUMAN(%s)", cfg.reloadvar[1]))) or 0
GUI:Text_setString(self.ui.var_Text, string.format("%d/%d", _value, cfg.reloadvar[2]))
if _value >= cfg.reloadvar[2] then
GUI:Text_setTextColor(self.ui.var_Text, "#ff0000")
else
GUI:Text_setTextColor(self.ui.var_Text, "#00ff00")
end
if cfg.reloadvar[1] == "INT_灵魂祭坛每日次数" then
local cc = SL:Get_EQUIPBYPOS(12)
if cc and cc == "九秘珠" then
GUI:setVisible(self.ui.Text_1, false)
GUI:setVisible(self.ui.var_Text, false)
end
end
end
GUI:addOnClickEvent(self.ui.up_btn, function()
ssrMessage:SubLink(self.__cname .. "_up", { npcid = cfg.npcid, id = self.id })
end)
end
--- *展示条件文本
function NPCGotoMapOBJ:setText()
local textCfg = self.cfg[self.id].zstz
if type(textCfg) == "table" then
GUI:ListView_removeAllItems(self.ui.Text_ListView)
for i, v in ipairs(textCfg) do
local text_list_layout = string.format("text_list_layout_%d", i)
self.ui[text_list_layout] = GUI:Layout_Create(self.ui.Text_ListView, text_list_layout, 0, 0, 220, 30, false)
local text_list = string.format("text_list_%d", i)
self.ui[text_list] = GUI:Text_Create(self.ui[text_list_layout], text_list, 0, 15, 16, "#ffffff", v)
GUI:setAnchorPoint(self.ui[text_list], 0.00, 0.50)
end
else
self.ui.checkText = GUI:Text_Create(self.ui.Text_Layout, "checkText", 201, 51, 16, "#ffffff", textCfg)
GUI:setAnchorPoint(self.ui.checkText, 0.50, 0.50)
end
end
---* boss展示
function NPCGotoMapOBJ:bossshow()
local cfg = self.cfg[self.id]
self.bossId = self.bossId or 1
GUI:removeAllChildren(self.ui.boss_effect_Layout)
local bossCfg = cfg.BOSS[self.bossId]
self.ui.boss_effect = GUI:Effect_Create(self.ui.boss_effect_Layout, "boss_effect", bossCfg[3], bossCfg[4], 2,
bossCfg[1], 0, bossCfg[6] and bossCfg[6] or 0, bossCfg[2], 1)
GUI:setScale(self.ui.boss_effect, bossCfg[5])
if #cfg.BOSS > 1 then
GUI:setVisible(self.ui.up_boss, true)
GUI:setVisible(self.ui.down_boss, true)
---* 上一页
GUI:addOnClickEvent(self.ui.up_boss, function()
self.bossId = self.bossId > 1 and self.bossId - 1 or 1
self:bossshow()
end)
GUI:addOnClickEvent(self.ui.down_boss, function()
self.bossId = self.bossId < #cfg.BOSS and self.bossId + 1 or #cfg.BOSS
self:bossshow()
end)
else
GUI:setVisible(self.ui.up_boss, false)
GUI:setVisible(self.ui.down_boss, false)
end
end
function NPCGotoMapOBJ:setbtn()
if GUI:Win_IsNotNull(self.ui.Listbtn_ListView) then
local file_id = self.cfg[1].npcid
GUI:ListView_removeAllItems(self.ui.Listbtn_ListView)
for i, v in ipairs(self.cfg or {}) do
local list_btn = string.format("list_btn_%d", i)
self.ui[list_btn] = GUI:Button_Create(self.ui.Listbtn_ListView, list_btn, 0, 0,
string.format("%s/%d/%s.png", "res/custom/map/btn", file_id, self.id ~= i and tostring(i) or i .. "a"))
GUI:addOnClickEvent(self.ui[list_btn], function()
GUI:Button_loadTextureNormal(self.ui[string.format("list_btn_%d", self.id)],
string.format("%s/%d/%s.png", "res/custom/map/btn", file_id, self.id))
GUI:Button_loadTextureNormal(self.ui[list_btn],
string.format("%s/%d/%s.png", "res/custom/map/btn", file_id, i .. "a"))
self.id = i
self:updata()
end)
end
end
self.s_btn = true
end
---* 注册事件
function NPCGotoMapOBJ:EventBind()
local function NPCGotoMapOBJ_bag_del_Reload(data)
if GUI:Win_IsNotNull(self._parent) then
self:updata()
end
end
SL:RegisterLUAEvent(LUA_EVENT_REINLEVEL_CHANGE, self.__cname, NPCGotoMapOBJ_bag_del_Reload)
--关闭窗口
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
self:OnClose(widgetName)
end)
end
--关闭窗口
function NPCGotoMapOBJ:OnClose(widgetName)
if widgetName == self.__cname then
self:UnRegisterEvent()
end
end
function NPCGotoMapOBJ:UnRegisterEvent()
self.cfg = {}
NPCGotoMapOBJ.s_btn = false
SL:UnRegisterLUAEvent(LUA_EVENT_REINLEVEL_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
end
return NPCGotoMapOBJ