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

310 lines
13 KiB
Lua

require("Base/BasePanel")
local FightAreaRewardPopup = Inherit(BasePanel)
local this = FightAreaRewardPopup
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local _ProductList = {}
local _ItemList = {}
local _RewardList = {}
local _ExtraRewardList = {}
--初始化组件(用于子类重写)
function FightAreaRewardPopup:InitComponent()
this.spLoader = SpriteLoader.New()
this.btnBack = Util.GetGameObject(self.transform, "mask")
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")
this.onhookTxt=Util.GetGameObject(self.transform, "showMopUp/scroller/onhookTxt"):GetComponent("Text")
this.btn_get=Util.GetGameObject(self.transform, "btn_get")
Util.GetGameObject(self.transform, "btn_get/Text"):GetComponent("Text").text="领取奖励"
Util.GetGameObject(self.transform, "btn_skip/Text"):GetComponent("Text").text="极速探索"
Util.GetGameObject(self.transform, "btn_skip/info"):GetComponent("Text").text="立即获得两小时挂机收益"
this.btn_skip=Util.GetGameObject(self.transform, "btn_skip")
this.btn_skip:SetActive(false)
end
--绑定事件(用于子类重写)
function FightAreaRewardPopup:BindEvent()
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
Util.AddClick(this.btn_get, function()
this:ClosePanel()
local boxState = this.GetBoxShowState(AdventureManager.stateTime)
if boxState > 0 then
local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. "mazeTreasureMax")
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
local mazeTreasureMax = ConfigManager.GetConfigData(ConfigName.PlayerLevelConfig,PlayerManager.level).MazeTreasureMax
local str = Language[10597]..BagManager.GetItemCountById(FindTreasureManager.materialItemId).."/"..mazeTreasureMax..
Language[10598]..GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,FindTreasureManager.materialItemId).Name)..
Language[10623]
if BagManager.GetItemCountById(FindTreasureManager.materialItemId) >= mazeTreasureMax and isPopUp ~= currentTime then
MsgPanel.ShowTwo(str, nil, function(isShow)
if (isShow) then
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .."mazeTreasureMax", currentTime)
end
FightPointPassManager.isBeginFight = true
AdventureManager.GetAventureRewardRequest(2, false, false)
end,nil,nil,nil,true)
else
FightPointPassManager.isBeginFight = true
AdventureManager.GetAventureRewardRequest(2, false, false)
end
else
PopupTipPanel.ShowTip(Language[10624])
end
end)
Util.AddClick(this.btn_skip, function()
this:ClosePanel()
FightPointPassManager.isBeginFight = true
UIManager.OpenPanel(UIName.FastExploreInfoPopup)
end)
end
function this.GetBoxShowState(hangupTime)
-- Log("挂机时长 hangupTime " .. hangupTime)
local state = 0
if hangupTime < AdventureManager.adventureRefresh then
state = 0
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[1] then
state = 1
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[2] then
state = 2
else
state = 3
end
FightPointPassManager.SetBoxState(state)
if hangupTime > (AdventureManager.adventureOffline*3600) then
hangupTime = AdventureManager.adventureOffline*3600
end
if hangupTime < 0 then
hangupTime = 0
end
--this.rewardBoxTime.text = TimeToHM(hangupTime)
return state
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()
-- LogError("FightPointPassManager.soldierLayerId==============================="..FightPointPassManager.soldierLayerId)
--LogError("curFightId======================="..curFightId)
local hours = AdventureManager.adventureOffline --gameSetting[1].AdventureOffline
local time = AdventureManager.stateTime >= hours * 60 * 60 and hours * 60 * 60 or AdventureManager.stateTime
this.onhookTxt.text = Language[10038] .. TimeToHMS(time)
local config =ConfigManager.GetConfigData(ConfigName.SoldierStageConfig,FightPointPassManager.soldierLayerId)
local mainLvConfig=ConfigManager.GetConfigData(ConfigName.MainLevelConfig, curFightId)
if config then
--LogError("config.id============================"..config.Id)
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
--LogError("item[1]============"..item[1].." item[2]==========="..item[2])
this.ItemAdapter(_ProductList[index], item)
end
end
local randReward = {}
if mainLvConfig.RewardShow and #mainLvConfig.RewardShow > 0 then
for j = 1, #mainLvConfig.RewardShow do
randReward[#randReward + 1] = mainLvConfig.RewardShow[j]
end
end
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)
end
end
local vipLv = VipManager.GetVipLevel()
local totalCurNum,totalLv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1)
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
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..""
local prolist = LikabilityManager.GetPrivilageProData(1,-1,totalLv)
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
data.type = 1
this.PriAdapter(num,data)
num = num + 1
end
if vipLv > 0 then
local data = {}
data.sprite = "r_zjm_tequanpaizi"
data.iconText = "特权"
data.lv = vipLv..""
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
end
end
--屏蔽好感度加成
this.extraReward.gameObject:SetActive(false)
ForceRebuildLayout(this.scroller.transform)
ForceRebuildLayout(this.extraRewardGrid.transform)
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")
_ExtraRewardList[num].iconText = Util.GetGameObject(_ExtraRewardList[num].icon.transform, "Text"):GetComponent("Text")
end
_ExtraRewardList[num].go.gameObject:SetActive(true)
_ExtraRewardList[num].icon.sprite = this.spLoader:LoadSprite(data.sprite)
_ExtraRewardList[num].icon:SetNativeSize()
if data.type == 1 then
_ExtraRewardList[num].icon.transform:GetComponent("RectTransform").sizeDelta = Vector2.New(71,65)
end
_ExtraRewardList[num].lv.text = data.lv
_ExtraRewardList[num].content.text = data.content
_ExtraRewardList[num].iconText.text = data.iconText
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
LogError("data[1]============="..data[1])
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])
-- 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)
local baseValue = string.format(Language[10603], data[2])
if addValue - 1 <= 0 then
txt.text = baseValue
else
local valueShow = math.round((addValue - 1) * data[2])
txt.text = string.format("%s\n<color=#1CC853>(+%s)</color>",baseValue,valueShow)
end
end
--界面关闭时调用(用于子类重写)
function FightAreaRewardPopup:OnClose()
end
--界面销毁时调用(用于子类重写)
function FightAreaRewardPopup:OnDestroy()
this.spLoader:Destroy()
_ProductList = {}
for _, node in ipairs(_ItemList) do
SubUIManager.Close(node)
end
_ItemList = {}
for _, node in ipairs(_RewardList) do
SubUIManager.Close(node)
end
_RewardList = {}
_ExtraRewardList = {}
end
return FightAreaRewardPopup