2020-08-25 15:46:38 +08:00
|
|
|
|
local RewardPreview = quick_class("RewardPreview")
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
|
|
|
|
|
local data = {}
|
|
|
|
|
local listPre = {}
|
|
|
|
|
local curtimes = 0
|
|
|
|
|
local intervalDatas={}
|
2020-06-28 17:48:49 +08:00
|
|
|
|
function RewardPreview:ctor(gameObject)
|
|
|
|
|
self.gameObject = gameObject
|
|
|
|
|
self:InitComponent(gameObject)
|
|
|
|
|
self:BindEvent()
|
|
|
|
|
self:OnShow()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:InitComponent(gameObject)
|
2020-07-08 21:19:34 +08:00
|
|
|
|
self.closeBtn = Util.GetGameObject(self.gameObject, "close")
|
|
|
|
|
self.itemGrid = Util.GetGameObject(self.gameObject, "itemGrid")
|
|
|
|
|
self.itemPre = Util.GetGameObject(self.gameObject, "itemprefab")
|
|
|
|
|
self.curtimes = Util.GetGameObject(self.gameObject, "tip1"):GetComponent("Text")
|
|
|
|
|
self.sliderWidth = Util.GetGameObject(self.gameObject, "Background"):GetComponent("RectTransform").sizeDelta.x
|
|
|
|
|
self.slider = Util.GetGameObject(self.gameObject, "Background/Fill"):GetComponent("Image")
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:BindEvent()
|
2020-07-08 21:19:34 +08:00
|
|
|
|
Util.AddClick(
|
|
|
|
|
self.closeBtn.gameObject,
|
|
|
|
|
function()
|
|
|
|
|
self:OnHide()
|
|
|
|
|
end
|
|
|
|
|
)
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:OnShow()
|
2020-07-08 21:19:34 +08:00
|
|
|
|
self.gameObject:SetActive(true)
|
|
|
|
|
local maxtimesId = lotterySetting[RecruitType.TimeLimitSingle].MaxTimes
|
2020-07-09 10:04:20 +08:00
|
|
|
|
curtimes = OperatingManager.TimeLimitedTimes
|
2020-07-08 21:19:34 +08:00
|
|
|
|
self:RefreshRewarid()
|
|
|
|
|
self.curtimes.text = Language[12181] .. curtimes
|
|
|
|
|
self.slider.fillAmount = self:CalculateInterval(curtimes)
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:RefreshRewarid()
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local curActivityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
|
|
|
|
|
data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", curActivityId)
|
|
|
|
|
local tmp = 0
|
2020-07-08 16:19:46 +08:00
|
|
|
|
--间隔的总次数 比如:30 60 120 210 300 count=(60-30)+ (120 - 60)+ (210 - 120)+ (300 - 210)= 300 - 30 =270
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local count = 0
|
|
|
|
|
-- for n,m in ipairs(data) do
|
|
|
|
|
-- if n~=1 then
|
2020-07-08 16:19:46 +08:00
|
|
|
|
-- count = count + m.Values[1][1]-tmp
|
|
|
|
|
-- end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
-- tmp = m.Values[1][1]
|
|
|
|
|
-- --self.slider.fillAmount = curtimes / m.Values[1][1]
|
|
|
|
|
-- end
|
2020-07-08 16:19:46 +08:00
|
|
|
|
count = data[#data].Values[1][1]
|
2020-07-08 21:19:34 +08:00
|
|
|
|
tmp = 0
|
|
|
|
|
local position = 0
|
2020-06-28 17:48:49 +08:00
|
|
|
|
local width = self.itemPre.transform:GetComponent("RectTransform").sizeDelta.x
|
|
|
|
|
local interval = self.itemGrid.transform:GetComponent("RectTransform").sizeDelta.x - (width * #data)
|
2020-07-08 21:19:34 +08:00
|
|
|
|
if (not listPre) then
|
|
|
|
|
listPre = {}
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local index = 1
|
|
|
|
|
for n, m in ipairs(data) do
|
|
|
|
|
if m then
|
|
|
|
|
if not listPre[n] then
|
|
|
|
|
listPre[n] = newObjToParent(self.itemPre, self.itemGrid)
|
2020-06-28 17:48:49 +08:00
|
|
|
|
listPre[n].gameObject:SetActive(true)
|
|
|
|
|
end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local o = SubUIManager.Open(SubUIConfig.ItemView, listPre[n].transform)
|
2020-06-28 17:48:49 +08:00
|
|
|
|
o:OnOpen(false, {m.Reward[1][1], m.Reward[1][2]}, 1.1, true)
|
|
|
|
|
o.gameObject:SetActive(true)
|
2020-07-08 21:19:34 +08:00
|
|
|
|
Util.GetGameObject(listPre[n].gameObject, "progress"):GetComponent("Text").text = m.Values[1][1]
|
2020-07-08 16:19:46 +08:00
|
|
|
|
local tempinterval = (m.Values[1][1] - tmp) / count * interval
|
2020-07-08 21:19:34 +08:00
|
|
|
|
if n == 1 then
|
|
|
|
|
position = tempinterval
|
|
|
|
|
else
|
|
|
|
|
position = tempinterval + width + position
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
--LogBlue("position:"..position)
|
|
|
|
|
listPre[n].transform:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(position, 0, 0)
|
|
|
|
|
--LogBlue(string.format("%.2f", (position + width)/(2*self.sliderWidth)))
|
|
|
|
|
intervalDatas[index] =tonumber(string.format("%.2f", (position + width / 2) / self.sliderWidth))
|
|
|
|
|
index = index + 1
|
|
|
|
|
tmp = m.Values[1][1]
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
end
|
2020-07-08 16:19:46 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:CalculateInterval(count)
|
2020-07-08 21:19:34 +08:00
|
|
|
|
local width = self.itemPre.transform:GetComponent("RectTransform").sizeDelta.x
|
|
|
|
|
if not data or #data < 1 then
|
|
|
|
|
local curActivityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
|
|
|
|
|
data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", curActivityId)
|
|
|
|
|
end
|
|
|
|
|
-- LogBlue(#intervalDatas)
|
|
|
|
|
-- for n,m in ipairs(intervalDatas) do
|
|
|
|
|
-- LogBlue(m)
|
|
|
|
|
-- end
|
|
|
|
|
local interval = 0
|
|
|
|
|
if count >= data[5].Values[1][1] then
|
2020-07-10 18:29:38 +08:00
|
|
|
|
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
|
2020-07-08 21:19:34 +08:00
|
|
|
|
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])
|
2020-07-08 16:19:46 +08:00
|
|
|
|
else
|
2020-07-08 21:19:34 +08:00
|
|
|
|
interval = count * intervalDatas[1] / data[1].Values[1][1]
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
2020-07-08 21:19:34 +08:00
|
|
|
|
return interval
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:OnHide()
|
2020-07-08 21:19:34 +08:00
|
|
|
|
self.gameObject:SetActive(false)
|
|
|
|
|
data = {}
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RewardPreview:OnDestroy()
|
2020-07-08 21:19:34 +08:00
|
|
|
|
listPre = nil
|
|
|
|
|
data = nil
|
2020-06-28 17:48:49 +08:00
|
|
|
|
end
|
|
|
|
|
|
2020-07-10 19:13:29 +08:00
|
|
|
|
return RewardPreview
|