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",
ACT_TURNTABLE_DESC_5 = "ACT_TURNTABLE_DESC_5",
VALUE_DESC = "VALUE_DESC",
USING_DESC = "USING_DESC",
}
return LocalizationGlobalConst

View File

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

View File

@ -24,4 +24,27 @@ function ItemManager:rspRecoveryNtf(result)
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

View File

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

View File

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

View File

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