100 lines
3.3 KiB
Lua
100 lines
3.3 KiB
Lua
DouLiShengJiOBJ = Up_BaseClassOBJ:new()
|
|
|
|
DouLiShengJiOBJ.__cname = "DouLiShengJiOBJ"
|
|
DouLiShengJiOBJ.cfg = {}
|
|
DouLiShengJiOBJ.UIfile = "game/B/DouLiShengJiUI"
|
|
DouLiShengJiOBJ.leftNum = 8
|
|
DouLiShengJiOBJ.id = 1
|
|
|
|
function DouLiShengJiOBJ:updata()
|
|
self.id = self.id or 1
|
|
local listview = self.ui.btn_ListView
|
|
local imgDir = "res/custom/44/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 DouLiShengJiOBJ: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", 500, 304,
|
|
{ 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)
|
|
|
|
for i = 1, 2 do
|
|
local costItem = self.ui[string.format("cost_ItemShow_%d", i)]
|
|
local costCfg = cfg.cost and cfg.cost[i]
|
|
if GUI:Win_IsNotNull(costItem) then
|
|
if costCfg then
|
|
GUI:ItemShow_updateItem(costItem, {
|
|
index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", costCfg.itemname),
|
|
count = costCfg.itemnum,
|
|
look = true,
|
|
bgVisible = false,
|
|
color = 255
|
|
})
|
|
GUI:setVisible(costItem, true)
|
|
else
|
|
GUI:setVisible(costItem, false)
|
|
end
|
|
end
|
|
end
|
|
|
|
GUI:Text_setString(self.ui.Text_success, string.format("成功率:%d%%", cfg.success or 0))
|
|
GUI:addOnClickEvent(self.ui.up_btn, function()
|
|
ssrMessage:SubLink(string.format("%s_%s", self.__cname, "up"), self.id)
|
|
end)
|
|
end
|
|
|
|
function DouLiShengJiOBJ:EventBind()
|
|
local function DouLiShengJiOBJ_EQUIP_CHANGE(data)
|
|
if GUI:Win_IsNotNull(self._parent) then
|
|
if data.Where == 13 then
|
|
self:updata()
|
|
end
|
|
end
|
|
end
|
|
SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.__cname, DouLiShengJiOBJ_EQUIP_CHANGE)
|
|
|
|
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
|
|
self:OnClose(widgetName)
|
|
end)
|
|
end
|
|
|
|
function DouLiShengJiOBJ:OnClose(widgetName)
|
|
if widgetName == self.__cname then
|
|
self:UnRegisterEvent()
|
|
end
|
|
end
|
|
|
|
function DouLiShengJiOBJ:UnRegisterEvent()
|
|
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.__cname)
|
|
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
|
|
end
|
|
|
|
return DouLiShengJiOBJ
|