miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/RewardPreview.lua

124 lines
4.6 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 RewardPreview= quick_class("RewardPreview")
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local data={}
local listPre={}
local curtimes=0
function RewardPreview:ctor(gameObject)
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
self:OnShow()
end
function RewardPreview:InitComponent(gameObject)
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.slider=Util.GetGameObject(self.gameObject,"Background/Fill"):GetComponent("Image")
end
function RewardPreview:BindEvent()
Util.AddClick(self.closeBtn.gameObject,function() self:OnHide() end)
end
function RewardPreview:OnShow()
self.gameObject:SetActive(true)
local maxtimesId=lotterySetting[RecruitType.TimeLimitSingle].MaxTimes;
curtimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
self.slider.fillAmount =self: CalculateInterval(curtimes)
self: RefreshRewarid()
self.curtimes.text=Language[12181]..curtimes
end
function RewardPreview:RefreshRewarid()
local curActivityId=ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",curActivityId)
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]
-- --self.slider.fillAmount = curtimes / m.Values[1][1]
-- end
count = data[#data].Values[1][1]
tmp=0
local position = 0
local width = self.itemPre.transform:GetComponent("RectTransform").sizeDelta.x
local interval = self.itemGrid.transform:GetComponent("RectTransform").sizeDelta.x - (width * #data)
if(not listPre) then
listPre={}
end
for n,m in ipairs(data) do
if m then
if not listPre[n] then
listPre[n]=newObjToParent(self.itemPre,self.itemGrid)
listPre[n].gameObject:SetActive(true)
end
local o= SubUIManager.Open(SubUIConfig.ItemView,listPre[n].transform)
o:OnOpen(false, {m.Reward[1][1], m.Reward[1][2]}, 1.1, true)
o.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
listPre[n].transform:GetComponent("RectTransform").anchoredPosition3D=Vector3.New(position,0,0)
tmp=m.Values[1][1]
end
end
end
function RewardPreview:CalculateInterval(count)
local curActivityId=ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
local data= ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",curActivityId)
local interval = 0
LogBlue(#data)
for n,m in ipairs(data) do
LogBlue(n.." "..m.Values[1][1])
end
if count>=data[1].Values[1][1] then
interval=0.099
if count>=data[2].Values[1][1] then
interval=0.3
if count>=data[3].Values[1][1] then
interval=0.54
if count>=data[4].Values[1][1] then
interval=0.75
if count>=data[5].Values[1][1] then
interval=1
else
interval = 0.75+ (count - data[4].Values[1][1]) * (1-0.75)/(data[5].Values[1][1]-data[4].Values[1][1])
end
else
interval = 0.54+ (count -data[3].Values[1][1])*(0.75-0.54)/(data[4].Values[1][1]-data[3].Values[1][1])
end
else
interval = 0.3+ (count -data[2].Values[1][1])*(0.54-0.3)/(data[3].Values[1][1]-data[2].Values[1][1])
end
else
interval = 0.099+ (count -data[1].Values[1][1])*(0.3-0.099)/(data[2].Values[1][1]-data[1].Values[1][1])
end
else
interval = count*0.001
end
return interval
end
function RewardPreview:OnHide()
self.gameObject:SetActive(false)
data={}
end
function RewardPreview:OnDestroy()
listPre=nil
data=nil
end
return RewardPreview