miduo_client/Assets/ManagedResources/~Lua/Modules/Fight/FightAreaRewardPopup.lua

233 lines
8.9 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
local FightAreaRewardPopup = Inherit(BasePanel)
local this = FightAreaRewardPopup
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local _ProductList = {}
local _ItemList = {}
local _RewardList = {}
2021-09-26 20:23:08 +08:00
local _ExtraRewardList = {}
2020-05-09 13:31:21 +08:00
--初始化组件(用于子类重写)
function FightAreaRewardPopup:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-09 13:31:21 +08:00
this.btnBack = Util.GetGameObject(self.transform, "mask")
2021-09-26 20:23:08 +08:00
this.scroller = Util.GetGameObject(self.transform, "showMopUp/scroller")
this.itemRoot = Util.GetGameObject(self.transform, "showMopUp/scroller/reward")
this.itemRootTitle = Util.GetGameObject(this.itemRoot, "title")
this.item = Util.GetGameObject(this.itemRoot, "scroll/grid/item")
this.itemGrid = Util.GetGameObject(this.itemRoot, "scroll/grid")
this.rewardBox = Util.GetGameObject(self.transform, "showMopUp/scroller/rateReward")
this.rewardBoxTitle = Util.GetGameObject(this.rewardBox, "title")
this.rewardBoxItem = Util.GetGameObject(this.rewardBox, "scroll/grid/item")
this.rewardBoxGrid = Util.GetGameObject(this.rewardBox, "scroll/grid")
this.extraReward = Util.GetGameObject(self.transform, "extraReward")
this.extraRewardTitle = Util.GetGameObject(this.extraReward, "title")
this.extraRewardItem = Util.GetGameObject(this.extraReward, "scroll/grid/item")
this.extraRewardGrid = Util.GetGameObject(this.extraReward, "scroll/grid")
2020-05-09 13:31:21 +08:00
end
--绑定事件(用于子类重写)
function FightAreaRewardPopup:BindEvent()
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function FightAreaRewardPopup:AddListener()
end
--移除事件监听(用于子类重写)
function FightAreaRewardPopup:RemoveListener()
end
--界面打开时调用(用于子类重写)
function FightAreaRewardPopup:OnOpen(...)
end
--
local orginLayer = -1
function this:OnSortingOrderChange()
-- Util.AddParticleSortLayer(this.privilegeEffect, this.sortingOrder - orginLayer)
orginLayer = self.sortingOrder
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function FightAreaRewardPopup:OnShow()
local curFightId = FightPointPassManager.GetCurFightId()
local config = ConfigManager.GetConfigData(ConfigName.MainLevelConfig, curFightId)
2021-09-26 20:23:08 +08:00
if config then
if not config.RewardShowMin or #config.RewardShowMin < 1 then
this.itemRoot.gameObject:SetActive(false)
else
this.itemRoot.gameObject:SetActive(true)
-- 固定奖励
for index, item in ipairs(config.RewardShowMin) do
if not _ProductList[index] then
_ProductList[index] = newObjToParent(this.item, this.itemGrid.transform)
end
this.ItemAdapter(_ProductList[index], item)
end
2020-05-09 13:31:21 +08:00
end
2021-09-26 20:23:08 +08:00
local randReward = {}
if config.RewardShow and #config.RewardShow > 0 then
for j = 1, #config.RewardShow do
randReward[#randReward + 1] = config.RewardShow[j]
end
2020-05-15 16:52:35 +08:00
end
2021-09-26 20:23:08 +08:00
local open, extral = FightPointPassManager.GetExtralReward()
if open > 0 then
for k = 1, #extral do
randReward[#randReward + 1] = extral[k]
end
end
if #randReward > 1 then
this.rewardBox.gameObject:SetActive(true)
table.sort(randReward, function (a, b)
return ItemConfig[a[1]].Quantity > ItemConfig[b[1]].Quantity
end)
for index, reward in ipairs(randReward) do
if not _RewardList[index] then
_RewardList[index] = SubUIManager.Open(SubUIConfig.ItemView, this.rewardBoxGrid.transform)
end
local rdata = {reward[1], 0} -- 不显示数量
_RewardList[index]:OnOpen(false, rdata, 1, true)
end
else
this.rewardBox.gameObject:SetActive(false)
2020-05-09 13:31:21 +08:00
end
end
2021-09-26 20:23:08 +08:00
local vipLv = VipManager.GetVipLevel()
local totalCurNum,totalLv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1)
2021-09-27 17:46:43 +08:00
local Vipvalue = 0
local config = ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig,1)
for i = 1,#config.Condition do
if config.Condition[i][1] == vipLv then
Vipvalue = config.Condition[i][2]
end
end
if (vipLv < 1 or (Vipvalue - 10000)<= 0) and (totalLv < 1) then
2021-09-26 20:23:08 +08:00
this.extraReward.gameObject:SetActive(false)
else
local num = 1
this.extraReward.gameObject:SetActive(true)
for i = 1,#_ExtraRewardList do
_ExtraRewardList[i].go.gameObject:SetActive(false)
end
if totalLv > 0 then
local data = {}
data.sprite = "h_haogandu_aixin"
data.iconText = ""
data.lv = totalLv..""
2021-10-09 14:53:22 +08:00
local prolist = LikabilityManager.GetPrivilageProData(1,-1,totalLv)
2021-09-26 20:23:08 +08:00
local str1 = ""
for k,v in pairs(prolist) do
local config = ConfigManager.GetConfigDataByKey(ConfigName.PrivilegeTypeConfig,"PrivilegeType",k)
str1 = str1 .. string.format(config.Name,GetPropertyFormatStrOne(config.IfFloat, v))
end
data.content = str1
2021-09-26 21:32:04 +08:00
data.type = 1
2021-09-26 20:23:08 +08:00
this.PriAdapter(num,data)
num = num + 1
end
if vipLv > 0 then
local data = {}
2021-09-26 21:32:04 +08:00
data.sprite = "r_zjm_tequanpaizi"
2021-09-26 20:23:08 +08:00
data.iconText = "特权"
data.lv = vipLv..""
2021-09-27 17:46:43 +08:00
if Vipvalue - 10000 > 0 then
data.content = string.format(config.Name,GetPropertyFormatStrOne(config.IfFloat, Vipvalue - 10000))
data.type = 2
this.PriAdapter(num,data)
num = num + 1
end
2020-05-09 13:31:21 +08:00
end
end
2022-12-06 11:07:34 +08:00
--屏蔽好感度加成
this.extraReward.gameObject:SetActive(false)
2021-09-26 20:23:08 +08:00
ForceRebuildLayout(this.scroller.transform)
2021-09-26 21:32:04 +08:00
ForceRebuildLayout(this.extraRewardGrid.transform)
2021-09-26 20:23:08 +08:00
end
function this.PriAdapter(num,data)
if not _ExtraRewardList[num] then
_ExtraRewardList[num] = {}
_ExtraRewardList[num].go = newObjToParent(this.extraRewardItem,this.extraRewardGrid)
_ExtraRewardList[num].icon = Util.GetGameObject(_ExtraRewardList[num].go, "icon"):GetComponent("Image")
_ExtraRewardList[num].lv = Util.GetGameObject(_ExtraRewardList[num].go, "lv"):GetComponent("Text")
_ExtraRewardList[num].content = Util.GetGameObject(_ExtraRewardList[num].go, "content"):GetComponent("Text")
2021-09-26 21:32:04 +08:00
_ExtraRewardList[num].iconText = Util.GetGameObject(_ExtraRewardList[num].icon.transform, "Text"):GetComponent("Text")
2021-09-26 20:23:08 +08:00
end
_ExtraRewardList[num].go.gameObject:SetActive(true)
_ExtraRewardList[num].icon.sprite = this.spLoader:LoadSprite(data.sprite)
_ExtraRewardList[num].icon:SetNativeSize()
2021-09-26 21:32:04 +08:00
if data.type == 1 then
_ExtraRewardList[num].icon.transform:GetComponent("RectTransform").sizeDelta = Vector2.New(71,65)
end
2021-09-26 20:23:08 +08:00
_ExtraRewardList[num].lv.text = data.lv
_ExtraRewardList[num].content.text = data.content
_ExtraRewardList[num].iconText.text = data.iconText
2020-05-09 13:31:21 +08:00
end
-- 物体数据匹配
function this.ItemAdapter(node, data)
-- 创建一个物体
local root = Util.GetGameObject(node, "root")
if not _ItemList[node] then
_ItemList[node] = SubUIManager.Open(SubUIConfig.ItemView, root.transform)
end
local rdata = {data[1], 0} -- 不显示数量
_ItemList[node]:OnOpen(false, rdata, 1.1)
--
local txt = Util.GetGameObject(node, "context"):GetComponent("Text")
local addValue = FightPointPassManager.GetItemVipValue(data[1])
2022-03-10 17:04:37 +08:00
-- local totalCurNum,totalLv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1)
-- local prolist = {}
-- LogGreen("addValue:"..addValue)
-- if totalLv > 0 then
-- prolist = LikabilityManager.GetPrivilageProData(1,-1,totalLv)
-- local priId = _ItemIdToVipPrivilege[data[1]]
-- if prolist[priId] then
-- addValue = addValue + (prolist[priId]/10000)
-- end
-- end
-- LogGreen("addValue:"..addValue)
2021-09-26 20:23:08 +08:00
local baseValue = string.format(Language[10603], data[2])
2020-05-09 13:31:21 +08:00
if addValue - 1 <= 0 then
2021-09-26 20:23:08 +08:00
txt.text = baseValue
2020-05-09 13:31:21 +08:00
else
local valueShow = math.round((addValue - 1) * data[2])
2021-09-29 16:19:29 +08:00
txt.text = string.format("%s\n<color=#00FF00>(+%s)</color>",baseValue,valueShow)
2020-05-09 13:31:21 +08:00
end
end
--界面关闭时调用(用于子类重写)
function FightAreaRewardPopup:OnClose()
end
--界面销毁时调用(用于子类重写)
function FightAreaRewardPopup:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-05-09 13:31:21 +08:00
_ProductList = {}
for _, node in ipairs(_ItemList) do
SubUIManager.Close(node)
end
_ItemList = {}
for _, node in ipairs(_RewardList) do
SubUIManager.Close(node)
end
_RewardList = {}
2021-09-26 20:23:08 +08:00
_ExtraRewardList = {}
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return FightAreaRewardPopup