ShenJiaRongHeOBJ = Up_BaseClassOBJ:new() ShenJiaRongHeOBJ.__cname = "ShenJiaRongHeOBJ" -- 配置文件 ShenJiaRongHeOBJ.cfg = {} ShenJiaRongHeOBJ.UIfile = "game/B/ShenJiaRongHeUI" ShenJiaRongHeOBJ.leftNum = 8 ShenJiaRongHeOBJ.id = 1 --当前选中按钮 id function ShenJiaRongHeOBJ:updata() self.id = self.id or 1 local listview = self.ui.btn_ListView local imgDir = "res/custom/41/btn/" 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 tostring(i) or (i .. "a"))) GUI:addOnClickEvent(self.ui[btnKey], function() if self.id == i then return end --重复点击不刷新 local oldId = self.id self.id = i --旧按钮换为非选中态 GUI:Button_loadTextures(self.ui[string.format("list_btn_%d", oldId)], string.format("%s%s.png", imgDir, oldId .. "a"), "", "", 0) --新按钮换为选中态 GUI:Button_loadTextures(self.ui[btnKey], string.format("%s%s.png", imgDir, tostring(i)), "", "", 0) self:init() end) end self:init() end function ShenJiaRongHeOBJ:init() local cfg = self.cfg[self.id] if not cfg then return end if GUI:Win_IsNotNull(self.ui.ItemShow) then GUI:removeFromParent(self.ui.ItemShow) end self.ui.ItemShow = GUI:ItemShow_Create(self.ui.img_bg, "ItemShow", 470, 290, { index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", cfg.name), count = 1, look = true, bgVisible = false, color = 255 }) GUI:setAnchorPoint(self.ui.ItemShow, 0.50, 0.50) GUI:removeAllChildren(self.ui.cost_Layout) for i, v in ipairs(cfg.cost or {}) do local costItemBg = string.format("costItemBg_%d", i) self.ui[costItemBg] = GUI:Image_Create(self.ui.cost_Layout, costItemBg, 0, 0, "res/public/1900000651_1.png") GUI:Win_SetParam(self.ui[costItemBg], i) local bg_size = GUI:getContentSize(self.ui[costItemBg]) local costItem = string.format("costItem_%d", i) self.ui[costItem] = GUI:ItemShow_Create(self.ui[costItemBg], costItem, bg_size.width / 2, bg_size.height / 2, { index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", v.itemname), count = v.itemnum, look = true, bgVisible = false, color = 255 }) GUI:setAnchorPoint(self.ui[costItem], 0.50, 0.50) end GUI:UserUILayout(self.ui.cost_Layout, { dir = 2, addDir = 2, interval = 1, gap = { x = 30 }, sortfunc = function(lists) table.sort(lists, function(a, b) return (GUI:Win_GetParam(a) or 0) > (GUI:Win_GetParam(b) or 0) end) end }) GUI:Text_setString(self.ui.Text_success, string.format("成功率:%d%%", cfg.success)) GUI:addOnClickEvent(self.ui.up_btn, function() ssrMessage:SubLink(string.format("%s_%s", self.__cname, "up"), self.id) end) end ---* 注册事件 function ShenJiaRongHeOBJ:EventBind() local function ShenJiaRongHeOBJ_EQUIP_CHANGE(data) if GUI:Win_IsNotNull(self._parent) then if data.Where == 16 then self:updata() end end end SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.__cname, ShenJiaRongHeOBJ_EQUIP_CHANGE) --关闭窗口 SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName) self:OnClose(widgetName) end) end --关闭窗口 function ShenJiaRongHeOBJ:OnClose(widgetName) if widgetName == self.__cname then self:UnRegisterEvent() end end function ShenJiaRongHeOBJ:UnRegisterEvent() SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.__cname) SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname) end return ShenJiaRongHeOBJ