-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFChangeSkinUI.lua
More file actions
278 lines (250 loc) · 8.55 KB
/
FChangeSkinUI.lua
File metadata and controls
278 lines (250 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
--[[
换炮台
]]
local UIBase = require_ex("ui.base.UIBase")
local M = class("FChangeSkinUI", UIBase)
-- 栏目数量
local TabCount = 2
local OutLine={
select = "871f17",
normal = "173987"
}
local TAB_LIST = {
["qgame"] = 2,
["mgame"] = 2,
}
local function _getVipSkinIds(list)
local ret = {}
local ids = BYCannonSkinConfig.getIds()
for _, id in ipairs(ids) do
local cfg = BYCannonSkinConfig[id]
if cfg.type == CannonType.vip or cfg.type == CannonType.laser then
local time = 0
local forever = false
if list[id] then
time = list[id].valid_day or 0
forever = list[id].forever or false
end
table.insert(ret, {idx = id, valid_time = time,forever=forever})
end
end
table.sort(ret, function(a, b)
local a1, b1 = a.idx, b.idx
local e1 = BYCannonSkinConfig[a1]
local e2 = BYCannonSkinConfig[b1]
if a.forever ~= b.forever then
return a.forever
elseif a.valid_time ~= b.valid_time then
return a.valid_time > b.valid_time
elseif e1.type == e2.type then
return e1.lv < e2.lv or (e1.lv == e2.lv and e1.id < e2.id)
else
return e1.type > e2.type
end
end)
return ret
end
function M:ctor(useSkin)
self._useSkin = useSkin
self.effDark = true
self.effRipple = true
UIBase.ctor(self)
self._currTab = TAB_LIST[AppName] or 1 --1:基础炮台 2:付费炮台
self:init()
end
function M:registerListenEvent()
self:listenCustomEvent(GEvent("ON_RECHARGE_FINISH"), handler(self,self.onPayFinish))
self:listenCustomEvent(GEvent("FISH","UPD_SKIN_DATA"), handler(self,self.onPayFinish))
end
function M:init()
self._BindWidget = {
["panel_touch"] = {handle = handler(self, self.onClose)},
["btn_close"] = {handle = handler(self, self.onClose)},
["lv_list"] = {},
["temp_cannon"] = {hide=true},
["panel_tab/cb1"] = {key = "cb_tab1", tag = 1},
["panel_tab/cb2"] = {key = "cb_tab2", tag = 2},
}
self:initViews()
end
function M:initViews()
local uiNode = createCsbNode("subgame/catchFish/barter.csb")
self:addChild(uiNode, 1)
self._rootNode = uiNode
bindWidgetList(uiNode, self._BindWidget, self._widgets)
-- self:initList()
self:refresh()
local cbs = {}
for i=1,TabCount do
local cb = self._widgets["cb_tab"..i]
if cb then
local args = {
parent = self._rootNode,
txtNormal = cb:getChildByName("txt"),
txtSelected = cb:getChildByName("txt_forcus"),
}
cbs[#cbs+1] = require_ex("lib.UICheckBoxEx").new(cb, args)
end
end
local args = {default = self._currTab, clickCallback = handler(self, self.onTab)}
require_ex("lib.UIRadioGroupEx").new(cbs, args)
if Game:funcIsOpen("code_animate") then
Game:doEffectList(EffType.bubble, self._widgets.lv_list, true, 0.05, 1.05, 0.5)
end
end
function M:initList()
self._itemList = {}
self._widgets.lv_list:removeAllItems()
self._skinList = Game.fishDB:getSkinData()
local ids = _getVipSkinIds(self._skinList)
ids = self:checkType(ids)
for i, id in ipairs(ids) do
local item = self._widgets.temp_cannon:clone()
self:initItem(item, id)
self._widgets.lv_list:pushBackCustomItem(item)
self._itemList[i] = item
end
end
function M:initItem(item, id)
local cfg = BYCannonSkinConfig[id]
local loop = false
if TAB_LIST[AppName] then
loop = not Assist.isEmpty(cfg.icon[3]) or false
else
loop = cfg.type==CannonType.laser or (not Assist.isEmpty(cfg.icon[3]))
end
local BindWidget = {
["img_no_get"] = {},
["img_get"] = {},
["txt_name"] = {},
["txt_desc"] = {zorder=2},
["img_icon"] = {},
["btn_useing"] = {},
["txt_time"] = {key = "txt_time",hide=true},
["btn_change"] = {handle = handler(self,self.onBtnChooseItem)},
["btn_equipGain"] = {handle = handler(self,self.onBtnGetItem)},
}
bindWidgetList(item, BindWidget, item)
Assist.showCannonAnim(item.img_icon, cfg.icon, 2, 1, 1, loop)
fitIconSize(item.txt_name, cfg.icon_name)
item:setVisible(true)
item.id = id
item.btn_change.id = id
item.btn_equipGain.id = id
end
--[[
检测激光炮台有效性
]]
function M:checkCannonType(cannonId)
local cannonInfo = self._skinList[cannonId]
if not cannonInfo then
Log.w("can't find cannon info:"..cannonId,"FChangeSkinUI")
end
return cannonInfo or {}
end
function M:checkType(ids)
local list = {}
for _,id in ipairs(ids) do
if self._currTab == 1 then
if BYCannonSkinConfig.type(id.idx) == CannonType.vip then
table.insert(list, id.idx)
end
else
if BYCannonSkinConfig.type(id.idx) == CannonType.laser then
table.insert(list, id.idx)
end
end
end
return list
end
function M:refresh(skin)
self:initList()
skin = skin or self._useSkin
self._skinList = Game.fishDB:getSkinData()
local vip = Game:doPluginAPI("get", "playerVIP")
-- local itemList = self:checkType()
for _, item in ipairs(self._itemList) do
local cfg = BYCannonSkinConfig[item.id]
local color = skin == cfg.id and OutLine.select or OutLine.normal
item.btn_useing:setVisible(skin==cfg.id)
item.btn_equipGain:setVisible(skin~=cfg.id)
item.img_get:setVisible(skin==cfg.id)
item.img_no_get:setVisible(skin~=cfg.id)
item.btn_change:setVisible(false)
if item.txt_desc then
item.txt_desc:enableOutline(Assist.colorFromString(color),2)
setRichText(item.txt_desc,cfg.desc)
end
local cannonInfo = self:checkCannonType(cfg.id)
local valid_time = cannonInfo.valid_day or 0
local change = valid_time > 0 or cannonInfo.forever
if valid_time > 0 and not cannonInfo.forever then
item.txt_time:setVisible(true)
item.txt_time:setString(Timer:formatDayCD(valid_time,Config.localize("cannon_use_time"),false,true))
end
if skin ~= cfg.id then
if cfg.type == CannonType.laser then --激光武器
item.btn_change:setVisible(change)
item.btn_equipGain:setVisible(not item.btn_change:isVisible())
item.btn_equipGain:setTitleString(Config.localize("title_need_get"))
else
local key = vip>=cfg.lv and "title_equip_enable" or "title_need_get"
item.btn_equipGain:setTitleString(Config.localize(key))
item.btn_change:setVisible(vip>=cfg.lv)
item.btn_equipGain:setVisible(not item.btn_change:isVisible())
end
end
end
end
----------------------------------
function M:onTab(tabIdx)
if self._currTab ~= tabIdx then
self._currTab = tabIdx
self:refresh()
end
end
-- 交互及回调
function M:onBtnChooseItem(btn)
Game.fishCom:reqChangeSkin(btn.id,handlerSafe(self,self.onChooseCallback))
end
function M:onChooseCallback(info)
if info.code == 0 then
Game:tipMsg(Config.localize("fish_change_skill_succ"))
self._useSkin = info.skin
self:refresh(info.skin)
end
end
function M:onBtnGetItem(btn)
local args = BYCannonSkinConfig.func_args(btn.id)
local params = {}
if BYCannonSkinConfig.params then --todo 同步字段到追龙、全民
params = BYCannonSkinConfig.params(btn.id) or {}
end
if args == "cannonShop" then
Game:doPluginAPI("enter", "cannonShop", btn.id, function()
local pInfo = Game.fishDB:getPlayer()
self._useSkin = pInfo.skin
self:refresh(pInfo.skin)
end)
elseif args == "activity" and not Assist.isEmpty(params) then
if Game:doPluginAPI("get", "activity", params[1], true) then
Game:doPluginAPI("exit", "fish",function()
Game:performDelay(function()
Game:doPluginAPI("enter",args,unpack(params))
end,0.5)
end)
else
Game:tipMsg(Config.localize("cannon_jump_fail"))
end
elseif not Assist.isEmpty(args) then
Game:doPluginAPI("enter",args,unpack(params))
end
end
function M:onPayFinish()
self:performWithDelay(function()
local pInfo = Game.fishDB:getPlayer()
self._useSkin = pInfo.skin
self:refresh(pInfo.skin)
end,1)
end
return M