105 lines
3.5 KiB
Lua
105 lines
3.5 KiB
Lua
local MopUpUI = class("MopUpUI", BaseUI)
|
|
|
|
function MopUpUI:isFullScreen()
|
|
return false
|
|
end
|
|
|
|
function MopUpUI:getPrefabPath()
|
|
return "assets/prefabs/ui/common/mop_up_ui.prefab"
|
|
end
|
|
|
|
function MopUpUI:ctor(params)
|
|
self.customtitleTx = params.customtitleTx
|
|
self.rewards = params.rewards
|
|
self.remainCount = params.remainCount
|
|
self.callback = params.callback
|
|
|
|
---- 有目标的扫荡
|
|
self.target = params.target
|
|
end
|
|
|
|
function MopUpUI:onLoadRootComplete()
|
|
self:_display()
|
|
self:_addListeners()
|
|
end
|
|
|
|
function MopUpUI:_display()
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["mop_up_ui.bg.title_text"]:setText(self.customtitleTx or I18N:getGlobalText(I18N.GlobalConst.MOP_UP_DESC_1))
|
|
uiMap["mop_up_ui.bg.tx_none"]:setText(I18N:getGlobalText(I18N.GlobalConst.GET_REWARDS_DESC))
|
|
uiMap["mop_up_ui.bg.ok_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.MOP_UP_DESC_2))
|
|
|
|
local remianTxObj = uiMap["mop_up_ui.bg.remain_tx"]
|
|
if self.remainCount then
|
|
remianTxObj:setVisible(true)
|
|
remianTxObj:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_21, self.remainCount))
|
|
else
|
|
remianTxObj:setVisible(false)
|
|
end
|
|
|
|
self:refreshTarget()
|
|
self:refreshScrollrect()
|
|
end
|
|
|
|
function MopUpUI:_addListeners()
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["mop_up_ui.bg.close_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
end)
|
|
|
|
uiMap["mop_up_ui.bg.ok_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
if self.callback then
|
|
self.callback()
|
|
end
|
|
end)
|
|
end
|
|
|
|
function MopUpUI:refreshScrollrect()
|
|
if not self.scrollRect then
|
|
local uiMap = self.root:genAllChildren()
|
|
self.scrollRect = uiMap["mop_up_ui.bg.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
|
|
self.scrollRect:addInitCallback(function()
|
|
return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
|
|
end)
|
|
self.scrollRect:addRefreshCallback(function(index, cell)
|
|
cell:refresh(self.rewards[index])
|
|
end)
|
|
end
|
|
self.scrollRect:refillCells(#self.rewards)
|
|
end
|
|
|
|
function MopUpUI:refreshTarget()
|
|
local uiMap = self.root:genAllChildren()
|
|
local bg = uiMap["mop_up_ui.bg"]
|
|
local node = uiMap["mop_up_ui.bg.item_node"]
|
|
if not self.target then
|
|
node:setVisible(false)
|
|
bg:setSizeDeltaY(518)
|
|
return
|
|
end
|
|
bg:setSizeDeltaY(632)
|
|
node:setVisible(true)
|
|
|
|
if not self.rewardCell then
|
|
self.rewardCell = CellManager:addCellComp(uiMap["mop_up_ui.bg.item_node.reward_cell"], GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
|
|
end
|
|
|
|
self.rewardCell:refreshItemById(self.target.id)
|
|
self.rewardCell:hideCountTx()
|
|
|
|
local curProgress = DataManager.BagData.ItemData:getItemNumById(self.target.id) or 0
|
|
local itemNameTx = GFunc.getRewardName(GConst.REWARD_TYPE.ITEM, self.target.id)
|
|
local progressTx
|
|
if curProgress >= self.target.value then
|
|
progressTx = string.format("<color=#49FF49>%s</color>/%s", curProgress, self.target.value)
|
|
else
|
|
itemNameTx = itemName .. "<color=#FF4949>(" .. I18N:getGlobalText(I18N.GlobalConst.MOP_UP_DESC_3) .. ")</color>"
|
|
progressTx = string.format("<color=#FF4949>%s</color>/%s", curProgress, self.target.value)
|
|
end
|
|
uiMap["mop_up_ui.bg.item_node.desc_1"]:setText(itemNameTx)
|
|
uiMap["mop_up_ui.bg.item_node.desc_2"]:setText(progressTx)
|
|
uiMap["mop_up_ui.bg.item_node.progress_slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = curProgress / self.target.value
|
|
end
|
|
|
|
return MopUpUI |