136 lines
4.4 KiB
Lua
136 lines
4.4 KiB
Lua
----- 装备批量出售 -----
|
||
local this = {}
|
||
--传入父脚本模块
|
||
local parent
|
||
--传入特效层级
|
||
local sortingOrder=0
|
||
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local count = 0
|
||
local id = 0
|
||
local a = 0
|
||
local b = 0
|
||
local c = 0
|
||
local d = 0
|
||
local lv = 0
|
||
local itemlist = {}
|
||
local templv = 0
|
||
function this:InitComponent(gameObject)
|
||
this.bodyText=Util.GetGameObject(gameObject,"BodyText"):GetComponent("Text")
|
||
this.rewardGroup=Util.GetGameObject(gameObject,"scroll/grid")
|
||
this.confirmBtn=Util.GetGameObject(gameObject,"ConfirmBtn")
|
||
this.addBtn=Util.GetGameObject(gameObject,"GameObject/add")
|
||
this.reduceBtn=Util.GetGameObject(gameObject,"GameObject/reduce")
|
||
this.slider=Util.GetGameObject(gameObject,"GameObject/Slider"):GetComponent("Slider")
|
||
this.tip=Util.GetGameObject(gameObject,"GameObject/tip"):GetComponent("Text")
|
||
this.num=Util.GetGameObject(gameObject,"GameObject/total/num"):GetComponent("Text")
|
||
this.icon=Util.GetGameObject(gameObject,"GameObject/total/icon"):GetComponent("Image")
|
||
this.cancelBtn = Util.GetGameObject(gameObject,"BG/BackBtn")
|
||
end
|
||
|
||
function this:BindEvent()
|
||
Util.AddClick(this.cancelBtn,function()
|
||
parent:ClosePanel()
|
||
end)
|
||
Util.AddClick(this.confirmBtn,function()
|
||
LogBlue("点击了购买等级的按钮")
|
||
NetManager.RequestBuyTreasureLevel(templv, function(msg)
|
||
Timer.New(function()
|
||
PopupTipPanel.ShowTip("等级购买成功")
|
||
parent:ClosePanel()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.TreasureOfHeaven.BuyQinglongSerectLevelSuccess)
|
||
end,1):Start()
|
||
end)
|
||
end)
|
||
Util.AddClick(this.addBtn,function()
|
||
this:SetCount(count + 1)
|
||
end)
|
||
Util.AddClick(this.reduceBtn,function()
|
||
this:SetCount(count - 1)
|
||
end)
|
||
end
|
||
|
||
function this:SetCount(value)
|
||
count = value
|
||
this.slider.value = value
|
||
templv = lv + count
|
||
this.tip.text = string.format("购买%s级,升至%s级",count,templv)
|
||
this.num.text = a * count ^ 3 + b * count ^ 2 + c * count + d
|
||
local tempCount = this:Caculate(templv)
|
||
this.bodyText.text=string.format("升至%s级,可立即解锁%s件奖励",templv,tempCount)
|
||
end
|
||
function this:Caculate(templv)
|
||
local rewardData = QinglongSerectTreasureManager.GetAllRewardData()
|
||
local direct = {}
|
||
local treasureState = QinglongSerectTreasureManager.GetTreasureState()
|
||
for i = 1, #rewardData do
|
||
local reward = rewardData[i]
|
||
if reward.level > lv and reward.level <= templv then
|
||
for j=1,#reward.Reward do
|
||
local id = reward.Reward[j].item[1]
|
||
local num = reward.Reward[j].item[2]
|
||
if reward.Reward[j].type == 1 then
|
||
if not direct[id] then
|
||
direct[id] = 0
|
||
end
|
||
direct[id] = direct[id] + num
|
||
elseif reward.Reward[j].type == 2 and treasureState > 0 then
|
||
if not direct[id] then
|
||
direct[id] = 0
|
||
end
|
||
direct[id] = direct[id] + num
|
||
end
|
||
end
|
||
end
|
||
end
|
||
for i=1,#itemlist do
|
||
itemlist[i].gameObject:SetActive(false)
|
||
end
|
||
local index = 1
|
||
for k,v in pairs(direct) do
|
||
if not itemlist[index] then
|
||
itemlist[index] = SubUIManager.Open(SubUIConfig.ItemView,this.rewardGroup.transform)
|
||
end
|
||
itemlist[index].gameObject:SetActive(true)
|
||
itemlist[index]:OnOpen(false, {k,v}, 1,false)
|
||
index = index + 1
|
||
end
|
||
return LengthOfTable(direct)
|
||
end
|
||
|
||
function this:AddListener()
|
||
end
|
||
|
||
function this:RemoveListener()
|
||
end
|
||
|
||
function this:OnShow(_parent,...)
|
||
parent=_parent
|
||
sortingOrder =_parent.sortingOrder
|
||
parent.BG:SetActive(false)
|
||
local config = ConfigManager.GetConfigData(ConfigName.SpecialConfig,18)
|
||
local strs = string.split(config.Value,"|")
|
||
local id =tonumber(strs[1])
|
||
strs = string.split(strs[2],"#")
|
||
count = 1
|
||
a = tonumber(strs[1])
|
||
b = tonumber(strs[2])
|
||
c = tonumber(strs[3])
|
||
d = tonumber(strs[4])
|
||
lv = QinglongSerectTreasureManager.GetLevel()
|
||
this.slider.maxValue = 50 - lv
|
||
this:SetCount(1)
|
||
this.icon.sprite = SetIcon(id)
|
||
this.slider.onValueChanged:AddListener(function()
|
||
this:SetCount(this.slider.value)
|
||
end)
|
||
end
|
||
|
||
function this:OnClose()
|
||
|
||
end
|
||
|
||
function this:OnDestroy()
|
||
itemlist = {}
|
||
end
|
||
|
||
return this |