miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/View/GeneralPopup_RecruitReward.lua

158 lines
6.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local this = {}
local parent
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
local data = {}
local listPre = {}
local itemPreList = {}
local curtimes = 0
local intervalDatas={}
local curActivityId = 0
local curActivityType = 0
local singleRecruit = nil
local tenRecruit = nil
local sortingOrder = 0
function this:InitComponent(gameObject)
this.itemGrid = Util.GetGameObject(gameObject, "itemGrid")
this.itemPre = Util.GetGameObject(gameObject, "itemprefab")
this.slider = Util.GetGameObject(gameObject, "Background/Fill"):GetComponent("Image")
this.sliderWidth = Util.GetGameObject(gameObject, "Background"):GetComponent("RectTransform").sizeDelta.x
this.curtimes = Util.GetGameObject(gameObject, "tip1"):GetComponent("Text")
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:BindEvent()
end
function this:OnShow(_parent,...)
parent=_parent
sortingOrder = _parent.sortingOrder
--不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参
local _args = {...}
curActivityType = _args[1]
curActivityId = _args[2]
local heroId=_args[3]
--不知道干什么用的,下面没引用 注释了 by 王振兴 2021/5/27 心愿祈福活动修改
-- local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting,"ActivityId",curActivityId)
-- singleRecruit = array[1]
-- tenRecruit = array[2]
-- local maxtimesId = lotterySetting[singleRecruit.Id].MaxTimes
curtimes = OperatingManager.TimeLimitedTimes
local reward=nil
data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", curActivityId)
local wishConfig=ConfigManager.TryGetConfigDataByKey(ConfigName.WishActivityUp,"ActivityId", curActivityId)
if wishConfig then
LogError("curActivityId=="..curActivityId.." heroId=="..heroId)
for i = 1,#wishConfig.UpList do
if wishConfig.UpList[i][1]==heroId then
reward=wishConfig.RewardList[i]
end
end
--替换奖励数据
for i = 1, #data do
data[i].Reward[1][1]=reward[i]
end
end
this:RefreshRewarid()
this.curtimes.text = "当前已招募次数:" .. curtimes
this.slider.fillAmount = this:CalculateInterval(curtimes)
end
function this:RefreshRewarid()
local tmp = 0
--间隔的总次数 比如30 60 120 210 300 count=60-30+ 120 - 60+ 210 - 120+ 300 - 210= 300 - 30 =270
local count = 0
-- for n,m in ipairs(data) do
-- if n~=1 then
-- count = count + m.Values[1][1]-tmp
-- end
-- tmp = m.Values[1][1]
-- --this.slider.fillAmount = curtimes / m.Values[1][1]
-- end
count = data[#data].Values[1][1]
tmp = 0
local position = 0
local width = this.itemPre:GetComponent("RectTransform").sizeDelta.x
local interval = this.itemGrid:GetComponent("RectTransform").sizeDelta.x - (width * #data)
if (not listPre) then
listPre = {}
end
if (not itemPreList) then
itemPreList = {}
end
local index = 1
for n, m in ipairs(data) do
if m then
if not listPre[n] then
listPre[n] = newObjToParent(this.itemPre, this.itemGrid)
end
listPre[n].gameObject:SetActive(true)
if not itemPreList[n] then
itemPreList[n] = SubUIManager.Open(SubUIConfig.ItemView, listPre[n].transform)
end
itemPreList[n]:OnOpen(false, {m.Reward[1][1], m.Reward[1][2]}, 1.1, true,false,false,sortingOrder)
itemPreList[n].gameObject:SetActive(true)
Util.GetGameObject(listPre[n].gameObject, "progress"):GetComponent("Text").text = m.Values[1][1]
local tempinterval = (m.Values[1][1] - tmp) / count * interval
if n == 1 then
position = tempinterval
else
position = tempinterval + width + position
end
--LogBlue("position:"..position)
listPre[n].transform:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(position, 0, 0)
--LogBlue(string.format("%.2f", (position + width)/(2*this.sliderWidth)))
intervalDatas[index] =tonumber(string.format("%.2f", (position + width / 2) / this.sliderWidth))
index = index + 1
tmp = m.Values[1][1]
end
end
end
function this:CalculateInterval(count)
local width = this.itemPre.transform:GetComponent("RectTransform").sizeDelta.x
if not data or #data < 1 then
data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", curActivityId)
end
local interval = 0
if count >= data[5].Values[1][1] then
interval = intervalDatas[5] + (curtimes - data[5].Values[1][1]) * (1-intervalDatas[5])/(500-data[5].Values[1][1])
if interval > 1 then
interval = 1
end
elseif count >= data[4].Values[1][1] then
interval = intervalDatas[4] +(count - data[4].Values[1][1]) * (intervalDatas[5] - intervalDatas[4]) / (data[5].Values[1][1] - data[4].Values[1][1])
elseif count >= data[3].Values[1][1] then
interval = intervalDatas[3] + (count - data[3].Values[1][1]) * (intervalDatas[4] - intervalDatas[3]) / (data[4].Values[1][1] - data[3].Values[1][1])
elseif count >= data[2].Values[1][1] then
interval = intervalDatas[2] + (count - data[2].Values[1][1]) * (intervalDatas[3] - intervalDatas[2]) / (data[3].Values[1][1] - data[2].Values[1][1])
elseif count >= data[1].Values[1][1] then
interval = intervalDatas[1] + (count - data[1].Values[1][1]) * (intervalDatas[2] - intervalDatas[1]) / (data[2].Values[1][1] - data[1].Values[1][1])
else
interval = count * intervalDatas[1] / data[1].Values[1][1]
end
return interval
end
function this:OnClose()
for k,v in ipairs(itemPreList) do
SubUIManager.Close(v)
end
itemPreList = {}
end
function this:OnDestroy()
for k,v in ipairs(itemPreList) do
SubUIManager.Close(v)
end
itemPreList = {}
listPre = {}--item重复利用
end
return this