This commit is contained in:
puxuan 2025-10-24 11:04:35 +08:00
parent 8280343377
commit 741b918779
6 changed files with 169 additions and 134 deletions

View File

@ -937,6 +937,7 @@ local LocalizationGlobalConst =
FUNC_OPEN_STAGE_OR_SEVER = "FUNC_OPEN_STAGE_OR_SEVER", FUNC_OPEN_STAGE_OR_SEVER = "FUNC_OPEN_STAGE_OR_SEVER",
ACT_TURNTABLE_DESC_5 = "ACT_TURNTABLE_DESC_5", ACT_TURNTABLE_DESC_5 = "ACT_TURNTABLE_DESC_5",
VALUE_DESC = "VALUE_DESC", VALUE_DESC = "VALUE_DESC",
USING_DESC = "USING_DESC",
} }
return LocalizationGlobalConst return LocalizationGlobalConst

View File

@ -937,6 +937,7 @@ local localization_global =
["FUNC_OPEN_STAGE_OR_SEVER"] = "通关章节{0}或{1}/{2}天后解锁", ["FUNC_OPEN_STAGE_OR_SEVER"] = "通关章节{0}或{1}/{2}天后解锁",
["ACT_TURNTABLE_DESC_5"] = "跳过动画", ["ACT_TURNTABLE_DESC_5"] = "跳过动画",
["VALUE_DESC"] = "超值", ["VALUE_DESC"] = "超值",
["USING_DESC"] = "使用",
} }
return localization_global return localization_global

View File

@ -24,4 +24,27 @@ function ItemManager:rspRecoveryNtf(result)
end end
end end
--@region 协议
-- 宝箱奖励
BIReport.ITEM_GET_TYPE.BOX_REWARD = "box_reward"
BIReport.ITEM_GET_TYPE.SELECT_BOX_REWARD = "select_box_reward"
function ItemManager:reqOpenBoxReward(id, count, idx)
-- idx只有自选奖励才有
local bi = BIReport.ITEM_GET_TYPE.BOX_REWARD
if idx and idx > 0 then
bi = BIReport.ITEM_GET_TYPE.SELECT_BOX_REWARD
end
self:sendMessage(ProtoMsgType.FromMsgEnum.ItemUseReq, {id = id, count = count, index = idx}, self.rspOpenBoxReward, bi)
end
function ItemManager:rspOpenBoxReward(result)
if result.err_code ~= GConst.ERROR_STR.SUCCESS then
return
end
GFunc.showRewardBox(result.rewards)
DataManager.BagData.ItemData:setDirty()
end
--@endregion
return ItemManager return ItemManager

View File

@ -57,6 +57,10 @@ function BagMainUI:onLoadRootComplete()
end) end)
end) end)
self.scrollRectComp:clearCells() self.scrollRectComp:clearCells()
self:bind(DataManager.BagData.ItemData, "dirty", function()
self:onRefresh()
end)
end end
function BagMainUI:onRefresh() function BagMainUI:onRefresh()

View File

@ -1,15 +1,15 @@
local CommonBoxUI = class("CommonBoxUI", BaseUI) local CommonBoxUI = class("CommonBoxUI", BaseUI)
function CommonBoxUI:isFullScreen() function CommonBoxUI:isFullScreen()
return false return false
end end
function CommonBoxUI:showCommonBG() function CommonBoxUI:showCommonBG()
return false return false
end end
function CommonBoxUI:getPrefabPath() function CommonBoxUI:getPrefabPath()
return "assets/prefabs/ui/common/common_box_ui.prefab" return "assets/prefabs/ui/common/common_box_ui.prefab"
end end
function CommonBoxUI:onPressBackspace() function CommonBoxUI:onPressBackspace()
@ -20,158 +20,163 @@ function CommonBoxUI:onClose()
end end
function CommonBoxUI:ctor(params) function CommonBoxUI:ctor(params)
self.id = params.id self.id = params.id
self.showTips = params.showTips self.showTips = params.showTips
self.maxCount = DataManager.BagData.ItemData:getItemNumById(self.id) self.maxCount = DataManager.BagData.ItemData:getItemNumById(self.id)
self.itemType = ModuleManager.ItemManager:getItemType(self.id) self.itemType = ModuleManager.ItemManager:getItemType(self.id)
local cfg = ConfigManager:getConfig("item")[self.id] local cfg = ConfigManager:getConfig("item")[self.id]
if self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_RANDOM then if self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_RANDOM then
-- 随机宝箱 -- 随机宝箱
self.curCount = self.maxCount self.curCount = self.maxCount
self.rewards = cfg and cfg.box_drop self.rewards = cfg and cfg.box_drop
elseif self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT then elseif self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT then
-- 自选宝箱 -- 自选宝箱
self.curCount = 1 self.curCount = 1
self.rewards = cfg and cfg.box_select self.rewards = cfg and cfg.box_select
else else
self.curCount = 1 self.curCount = 1
self.rewards = cfg and cfg.box_drop self.rewards = cfg and cfg.box_drop
end end
if self.rewards == nil then if self.rewards == nil then
self:closeUI() self:closeUI()
end end
end end
function CommonBoxUI:onLoadRootComplete() function CommonBoxUI:onLoadRootComplete()
local uiMap = self.root:genAllChildren() local uiMap = self.root:genAllChildren()
self.mask = uiMap["common_box_ui.mask"] self.mask = uiMap["common_box_ui.mask"]
self.contentNode = uiMap["common_box_ui.content"] self.contentNode = uiMap["common_box_ui.content"]
self.btnClose = uiMap["common_box_ui.content.btn_close"] self.btnClose = uiMap["common_box_ui.content.btn_close"]
self.rewardCell = uiMap["common_box_ui.content.info_node.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL) self.rewardCell = uiMap["common_box_ui.content.info_node.reward_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.txName = uiMap["common_box_ui.content.info_node.tx_name"] self.txName = uiMap["common_box_ui.content.info_node.tx_name"]
self.txType = uiMap["common_box_ui.content.info_node.tx_type"] self.txType = uiMap["common_box_ui.content.info_node.tx_type"]
self.txCount = uiMap["common_box_ui.content.info_node.tx_count"] self.txCount = uiMap["common_box_ui.content.info_node.tx_count"]
self.txDesc = uiMap["common_box_ui.content.desc.tx_desc"] self.txDesc = uiMap["common_box_ui.content.desc.tx_desc"]
self.scrollrect = uiMap["common_box_ui.content.scrollrect"] self.scrollrect = uiMap["common_box_ui.content.scrollrect"]
self.selectNode = uiMap["common_box_ui.content.select"] self.selectNode = uiMap["common_box_ui.content.select"]
self.txSelect = uiMap["common_box_ui.content.select.tx_select"] self.txSelect = uiMap["common_box_ui.content.select.tx_select"]
self.btnSub = uiMap["common_box_ui.content.select.btn_sub"] self.btnSub = uiMap["common_box_ui.content.select.btn_sub"]
self.btnAdd = uiMap["common_box_ui.content.select.btn_add"] self.btnAdd = uiMap["common_box_ui.content.select.btn_add"]
self.btnMax = uiMap["common_box_ui.content.select.btn_max"] self.btnMax = uiMap["common_box_ui.content.select.btn_max"]
self.txMax = uiMap["common_box_ui.content.select.btn_max.tx_max"] self.btnMin = uiMap["common_box_ui.content.select.btn_min"]
self.btnUse = uiMap["common_box_ui.content.btn_use"] -- self.txMax = uiMap["common_box_ui.content.select.btn_max.tx_max"]
self.txUse = uiMap["common_box_ui.content.btn_use.tx_desc"] self.btnUse = uiMap["common_box_ui.content.btn_use"]
self.txUse = uiMap["common_box_ui.content.btn_use.tx_desc"]
self.txMax:setText(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_2)) -- self.txMax:setText(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_2))
self.txUse:setText(I18N:getGlobalText(I18N.GlobalConst.USING_DESC)) self.txUse:setText(I18N:getGlobalText(I18N.GlobalConst.USING_DESC))
self.btnSub:addClickListener(function() self.btnSub:addClickListener(function()
if self.curCount <= 1 then if self.curCount <= 1 then
return return
end end
self.curCount = self.curCount - 1 self.curCount = self.curCount - 1
self:onRefresh() self:onRefresh()
end) end)
self.btnAdd:addClickListener(function() self.btnAdd:addClickListener(function()
if self.curCount >= self.maxCount then if self.curCount >= self.maxCount then
return return
end end
self.curCount = self.curCount + 1 self.curCount = self.curCount + 1
self:onRefresh() self:onRefresh()
end) end)
self.btnMax:addClickListener(function() self.btnMax:addClickListener(function()
if self.curCount >= self.maxCount then if self.curCount >= self.maxCount then
return return
end end
self.curCount = self.maxCount self.curCount = self.maxCount
self:onRefresh() self:onRefresh()
end) end)
self.btnUse:addClickListener(function() self.btnMin:addClickListener(function()
if self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT and (self.curIndex == nil or self.curIndex <= 0) then self.curCount = 1
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_3)) self:onRefresh()
return end)
end self.btnUse:addClickListener(function()
ModuleManager.ItemManager:reqOpenBoxReward(self.id, self.curCount, self.curIndex) if self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT and (self.curIndex == nil or self.curIndex <= 0) then
self:closeUI() GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_3))
end) return
self.mask:addClickListener(function() end
self:closeUI() ModuleManager.ItemManager:reqOpenBoxReward(self.id, self.curCount, self.curIndex)
end) self:closeUI()
self.btnClose:addClickListener(function() end)
self:closeUI() self.mask:addClickListener(function()
end) self:closeUI()
end)
self.btnClose:addClickListener(function()
self:closeUI()
end)
end end
function CommonBoxUI:onRefresh() function CommonBoxUI:onRefresh()
self.rewardCell:refreshById(self.id) self.rewardCell:refreshById(self.id)
self.txName:setText(ModuleManager.ItemManager:getItemName(self.id)) self.txName:setText(ModuleManager.ItemManager:getItemName(self.id))
self.txType:setText(I18N:getGlobalText(I18N.GlobalConst["ITEM_TYPE_" .. ModuleManager.ItemManager:getItemType(self.id)])) self.txType:setText(I18N:getGlobalText(I18N.GlobalConst["ITEM_TYPE_" .. ModuleManager.ItemManager:getItemType(self.id)]))
self.txCount:setText(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_1, self.maxCount)) self.txCount:setText(I18N:getGlobalText(I18N.GlobalConst.ITEM_DESC_1, self.maxCount))
self.txDesc:setText(ModuleManager.ItemManager:getItemDesc(self.id)) self.txDesc:setText(ModuleManager.ItemManager:getItemDesc(self.id))
self.txSelect:setText(self.curCount) self.txSelect:setText(self.curCount)
if self.rewards then if self.rewards then
if self.scrollRect == nil then if self.scrollRect == nil then
self.scrollRect = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.scrollRect = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollRect:addInitCallback(function() self.scrollRect:addInitCallback(function()
return GConst.TYPEOF_LUA_CLASS.REWARD_CELL return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
end) end)
self.scrollRect:addRefreshCallback(function(index, cell) self.scrollRect:addRefreshCallback(function(index, cell)
cell:refreshByConfig(self.rewards[index]) cell:refreshByConfig(self.rewards[index])
cell:showSelect(index == self.curIndex) cell:showSelect(index == self.curIndex)
cell:setShowProbTag(self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_RANDOM, self:getRewardProb(index)) cell:setShowProbTag(self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_RANDOM, self:getRewardProb(index))
if index ~= self.curIndex and self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT then if index ~= self.curIndex and self.itemType == GConst.ItemConst.ITEM_TYPE.BOX_SELECT then
cell:addClickListener(function() cell:addClickListener(function()
self:onClickReward(index) self:onClickReward(index)
end) end)
else else
cell:clearClickListener() cell:clearClickListener()
end end
end) end)
end end
if self.scrollRect:getTotalCount() == nil or self.scrollRect:getTotalCount() <= 0 then if self.scrollRect:getTotalCount() == nil or self.scrollRect:getTotalCount() <= 0 then
self.scrollRect:refillCells(#self.rewards) self.scrollRect:refillCells(#self.rewards)
elseif self.scrollRect:getTotalCount() ~= #self.rewards then elseif self.scrollRect:getTotalCount() ~= #self.rewards then
self.scrollRect:clearCells() self.scrollRect:clearCells()
self.scrollRect:refillCells(#self.rewards) self.scrollRect:refillCells(#self.rewards)
else else
self.scrollRect:updateAllCell() self.scrollRect:updateAllCell()
end end
end end
if self.showTips then if self.showTips then
-- 展示宝箱tips -- 展示宝箱tips
self.selectNode:setActive(false) self.selectNode:setActive(false)
self.btnUse:setActive(false) self.btnUse:setActive(false)
self.contentNode:setSizeDeltaY(580) self.contentNode:setSizeDeltaY(580)
else else
-- 展示宝箱开奖励 -- 展示宝箱开奖励
self.selectNode:setActive(true) self.selectNode:setActive(true)
self.btnUse:setActive(true) self.btnUse:setActive(true)
self.contentNode:setSizeDeltaY(728) self.contentNode:setSizeDeltaY(728)
end end
end end
function CommonBoxUI:onClickReward(index) function CommonBoxUI:onClickReward(index)
self.curIndex = index self.curIndex = index
self:onRefresh() self:onRefresh()
end end
function CommonBoxUI:getRewardProb(index) function CommonBoxUI:getRewardProb(index)
if self.itemType ~= GConst.ItemConst.ITEM_TYPE.BOX_RANDOM then if self.itemType ~= GConst.ItemConst.ITEM_TYPE.BOX_RANDOM then
return return
end end
local total = 0 local total = 0
local weight = self.rewards[index].weight or 0 local weight = self.rewards[index].weight or 0
for i, reward in ipairs(self.rewards) do for i, reward in ipairs(self.rewards) do
total = total + (reward.weight or 0) total = total + (reward.weight or 0)
end end
return math.floor((weight / total) * 1000) / 10 return math.floor((weight / total) * 1000) / 10
end end
return CommonBoxUI return CommonBoxUI

View File

@ -63,6 +63,7 @@ function SummonShopCell:refreshHero()
self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO_2, tostring(heroInfo.icon)) self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO_2, tostring(heroInfo.icon))
self.nameTx:setText(ModuleManager.HeroManager:getHeroName(self.heroId)) self.nameTx:setText(ModuleManager.HeroManager:getHeroName(self.heroId))
self.maskImg:setActive(not self.isOwn) self.maskImg:setActive(not self.isOwn)
self.matchImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[heroInfo.position])
end end
function SummonShopCell:refreshItem() function SummonShopCell:refreshItem()