miduo_client/Assets/ManagedResources/~Lua/Modules/Harmony/View/HarmonyScrllow.lua

499 lines
16 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={}
this.tab=ConfigManager.GetConfig(ConfigName.Hongmeng)
local Gold =0;
local DemonCrystal = 0
local HeroList = {}
local tempData = nil
local TempItem = nil
local ItemList = {}
local Box = 0
local OpenBox = 0
local HeroCount
function this:AwakeLength()
HeroCount = 0
Box = #HarmonyManager.hongmengHeroInfos;
OpenBox = #HarmonyManager.hongmengHeroInfos+2
for i = 1, #HarmonyManager.hongmengHeroInfos do
-- body
if HarmonyManager.hongmengHeroInfos[i].heroId~="" then
-- body
HeroCount = HeroCount + 1
end
end
if self.stage == 1 then
-- body
this.NumText.text = string.format("%d/%d",HeroCount,Box)
else
local count = 0
for i = 1, #HarmonyManager.hongmengGuards do
-- body
if HarmonyManager.hongmengGuards[i].heroId ~= "" then
count = count + 1
-- body
end
end
this.NumText.text = string.format("%d/%d",HeroCount + count,Box + #HarmonyManager.hongmengGuards)
end
end
function this:InitComponent(gameObject,Golds,DemonCrystals,stage)
Gold = Golds
DemonCrystal = DemonCrystals
self.stage = stage
-- item预制件
this.item = Util.GetGameObject(gameObject , "HarmonyPanel/item")
--btn组件
this.addBtn = Util.GetGameObject(gameObject,"HarmonyPanel/AddBtn")
this.GongMingMsgBtn = Util.GetGameObject(gameObject,"HarmonyPanel/KnowGongMing")
this.scrollbar = Util.GetGameObject(gameObject,"HarmonyPanel/Scrollbar"):GetComponent("Scrollbar")
local scrollParent = Util.GetGameObject(gameObject, "HarmonyPanel/scroll"):GetComponent("RectTransform").rect
this.NumText = Util.GetGameObject(gameObject,"HarmonyPanel/itemNumText"):GetComponent("Text")
this.ScrollView=SubUIManager.Open(SubUIConfig.ScrollCycleView,Util.GetGameObject(gameObject,"HarmonyPanel/scroll").transform,
this.item,this.scrollbar,Vector2.New(-scrollParent.x*2,-scrollParent.y*2),1,5,Vector2.New(35,15))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
-- for key, value in ConfigPairs(this.tab) do
-- print("key:",key,"value",value.Id)
-- end
this.BoxList=0;
this:AwakeLength()
this:InitBox()
--this.RunTimerFun()
end
local TextList = {}
local BoxList = {}
function this:InitBox()
--
local keys = GameDataBase.SheetBase.GetKeys(this.tab) --获取数据长度
this.ScrollView:SetData(keys,function (index, go)
local key = keys[index]
this.SingleBoxDataShow(go, this.tab[key], index)
ItemList[go] = index
local TimerText = Util.GetGameObject(go.transform,"Box/Empty/Image/Text"):GetComponent("Text")
TextList[index] = TimerText
local Empty = Util.GetGameObject(go.transform,"Box/Empty")
BoxList[index] = Empty
end)
end
function this.RunTimerFun()
local refreshFunc = function()
for key, value in pairs(ItemList) do
if value <= #HarmonyManager.hongmengHeroInfos then
TextList[value].text = ""
-- print("倒计时开启 .."..HarmonyManager.hongmengHeroInfos[value].time - GetTimeStamp())
if HarmonyManager.hongmengHeroInfos[value].time - GetTimeStamp() > 0 then
if BoxList[value].activeSelf == false then
-- body
BoxList[value]:SetActive(true)
end
local time_content = TimeToFelaxible(HarmonyManager.hongmengHeroInfos[value].time - GetTimeStamp())
TextList[value].text = string.format("<color=#ffbc22>%s</color>\n<color=#bd922a>后恢复</color>",time_content)
else
HarmonyManager.hongmengHeroInfos[value].time = 0
TextList[value].text = ""
end
else
end
end
end
this.timerEffect = Timer.New(refreshFunc, 1, -1, true)
this.timerEffect:Start()
refreshFunc()
end
function this.SingleBoxDataShow(go,boxData,index)
-- body
local mask = Util.GetGameObject(go.transform,"Box/Empty/lock/mask");
local lock = Util.GetGameObject(go.transform,"Box/Empty/lock");
local Empty = Util.GetGameObject(go.transform,"Box/Empty")
local TimerText = Util.GetGameObject(go.transform,"Box/Empty/Image/Text"):GetComponent("Text")
local redPoint = Util.GetGameObject(go.transform,"Box/Empty/redPoint")
Empty:SetActive(true)
mask:SetActive(true)
lock:SetActive(true)
redPoint:SetActive(false)
Util.SetGray(lock,true)
local gridData = HarmonyManager.hongmengHeroInfos[boxData.Id]
if gridData then
if gridData.gridId <= Box then
if gridData.heroId ~= "" then
Empty:SetActive(false)
local data = HeroManager.GetSingleHeroData(gridData.heroId)
if data then
this.SingleItemDataShow(go, data)
else
LogError("error: no hero data")
end
else
if gridData.time == 0 then
-- body
TimerText.text = ""
else
end
Empty:SetActive(true)
mask:SetActive(false)
lock:SetActive(false)
redPoint:SetActive(false)
end
else
end
elseif index == Box + 1 then
mask:SetActive(false)
Util.SetGray(lock,false)
tempData = boxData
if HarmonyManager.RefreshOpenBoxPoint() then
-- body
CheckRedPointStatus(RedPointType.HongMeng_OpenBox)
redPoint:SetActive(true)
else
end
else
TimerText.text = ""
end
Util.AddOnceClick(go,function()
if gridData then
-- body
if gridData.heroId ~= "" then
-- body
TempItem = index
HarmonyManager:SetMingListIndexData(boxData.Id)
HarmonyManager.UnLoadGongMing = boxData.Id--发往服务器
UIManager.OpenPanel(UIName.HongMengUnLoadPanel)
else
if gridData.time == 0 then
-- body
UIManager.OpenPanel(UIName.HongMengChooseHeroPanel,false)
TempItem = index
HarmonyManager.GongMingBox = boxData.Id
print(" 添加等级 ",HarmonyManager.GongMingBox)
else
local content = ""
local money = (HarmonyManager.hongmengHeroInfos[boxData.Id].time - GetTimeStamp()) / 432
content =string.format("是否花费%d妖晶直接恢复",money)
MsgPanel.ShowTwo(content,function ()
MsgPanel.Hide()
end,function ()
if DemonCrystal < money then
PopupTipPanel.ShowTip("妖晶不足")
MsgPanel.Hide()
return
end
--向服务器 发消息
NetManager.UnlockGrid(boxData.Id,1,function ()
-- body
for i = 1, #HarmonyManager.hongmengHeroInfos do
-- body
if HarmonyManager.hongmengHeroInfos[i].gridId ==boxData.Id then
HarmonyManager.hongmengHeroInfos[i].time = 0
print("清除数据")
end
end
TimerText.text = ""
end,"取消","确认")
end)
end
end
else
if mask.activeSelf then
-- body
PopupTipPanel.ShowTip("请先解锁前一个格子")
else
if lock.activeSelf then
-- body
this:AddBoxFun(boxData)
end
end
end
end)
end
--卸载刷新
function this:UpdateItemShow(go,boxData,msg)
end
function this:AddBoxFun(boxData)
local content = ""
if Gold >= boxData.PropPrice[2] then
content =string.format("是否花费%d玄黄之气解锁共鸣位置",boxData.PropPrice[2])
elseif Gold < boxData.PropPrice[2] and DemonCrystal >= boxData.MoneyPrice[2] then
-- body
content=string.format("玄黄之气不足%d是否直接花费%d妖晶解锁共鸣位置",boxData.PropPrice[2],boxData.MoneyPrice[2])
else
content = "妖晶不足!"
end
MsgPanel.ShowTwo(content,function ()
end,function ()
if Gold < boxData.PropPrice[2] and DemonCrystal < boxData.MoneyPrice[2] then
return
end
--向服务器请求消息
NetManager.HongMengRequset(boxData.Id,function()
--
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.RereshNumText,boxData.Id)
end)
end,"取消","确认")
end
function this:BindEvent()
end
function this:OnOpen()
this:AwakeLength()
this.RunTimerFun()
this.timerEffect:Start()
end
function this.SingleItemDataShow(clone,Itemdata)
--LogGreen(clone.name.."||"..Itemdata.heroConfig.Id)
--Util.GetGameObject(clone.transform, "Box/Empty"):SetActive(false)
Util.GetGameObject(clone.transform, "GameObject/frame"):GetComponent("Image").sprite = Util.LoadSprite(GetHeroQuantityImageByquality(Itemdata.heroConfig.Quality,Itemdata.star))
Util.GetGameObject(clone.transform, "GameObject/lv/Text"):GetComponent("Text").text = string.format("<color=#0f0>%d</color>",Itemdata.lv)
Util.GetGameObject(clone.transform, "GameObject/icon"):GetComponent("Image").sprite = Util.LoadSprite(Itemdata.icon)
--Util.GetGameObject(clone.transform, "GameObject/posIcon"):SetActive(false)--:GetComponent("Image").sprite = Util.LoadSprite(heroData.professionIcon)
Util.GetGameObject(clone.transform, "GameObject/proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(Itemdata.heroConfig.PropertyName))
local starGrid = Util.GetGameObject(clone.transform, "GameObject/star")
SetHeroStars(starGrid, Itemdata.star,1,nil,nil,Vector2.New(0,1))
end
function this:Refesh(id)
-- body
Box = Box + 1
OpenBox = OpenBox + 1
Gold = BagManager.GetTotalItemNum(UpViewRechargeType.XuanHuangZhiQi)
DemonCrystal = BagManager.GetTotalItemNum(UpViewRechargeType.DemonCrystal)
if self.stage == 1 then
-- body
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount,Box})
else
local count = 0
for i = 1, #HarmonyManager.hongmengGuards do
-- body
if HarmonyManager.hongmengGuards[i].heroId ~= "" then
count = count + 1
-- body
end
end
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount + count,Box + #HarmonyManager.hongmengGuards})
end
LogGreen(Box)
local data = {}
data.gridId = id
data.heroId = ""
data.time = 0
table.insert(HarmonyManager.hongmengHeroInfos,data)
local keys = GameDataBase.SheetBase.GetKeys(this.tab) --获取数据长度
this.ScrollView:SetData(keys,function (index, go)
local key = keys[index]
this.SingleBoxDataShow(go, this.tab[key],index)
ItemList[go] = index
local TimerText = Util.GetGameObject(go.transform,"Box/Empty/Image/Text"):GetComponent("Text")
TextList[index] = TimerText
local Empty = Util.GetGameObject(go.transform,"Box/Empty")
BoxList[index] = Empty
end)
end
function this:OpenBoxFun()
this:AddBoxFun(tempData)
end
function this:UpdateHero(Herodata)
for i = 1, #HarmonyManager.hongmengHeroInfos do
-- body
if HarmonyManager.GongMingBox ==HarmonyManager.hongmengHeroInfos[i].gridId then
-- body
HarmonyManager.hongmengHeroInfos[i].heroId = Herodata.dynamicId
HarmonyManager.hongmengHeroInfos[i].time = 0
break
end
end
HeroCount = HeroCount + 1
if self.stage == 1 then
-- body
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount,Box})
else
local count = 0
for i = 1, #HarmonyManager.hongmengGuards do
-- body
if HarmonyManager.hongmengGuards[i].heroId~="" then
count = count + 1
-- body
end
end
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount + count,Box + #HarmonyManager.hongmengGuards})
end
--Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount,Box, 1})
--this.NumText.text = string.format("%d/%d",HeroCount,Box)
local keys = GameDataBase.SheetBase.GetKeys(this.tab) --获取数据长度
--刷新选择英雄界面的 数据
HarmonyManager:SetInitList()
this.ScrollView:SetData(keys,function (index, go)
local key = keys[index]
this.SingleBoxDataShow(go, this.tab[key],index)
ItemList[go] = index
local TimerText = Util.GetGameObject(go.transform,"Box/Empty/Image/Text"):GetComponent("Text")
TextList[index] = TimerText
local Empty = Util.GetGameObject(go.transform,"Box/Empty")
BoxList[index] = Empty
end)
end
function this:GetItemList(index)
-- body
for key, value in pairs(ItemList) do
-- body
if value == index then
-- body
return key
end
end
end
function this:UnLoadFun(msg)
HeroCount = HeroCount - 1
for key, value in pairs(ItemList) do
if value == TempItem then
-- body
HarmonyManager.hongmengHeroInfos[value].time = msg.leftTime + GetTimeStamp()
HarmonyManager.hongmengHeroInfos[value].heroId = ""
end
end
--刷新选择英雄界面的 数据
HarmonyManager:SetInitList()
if self.stage == 1 then
-- body
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount,Box, 1})
else
local count = 0
for i = 1, #HarmonyManager.hongmengGuards do
-- body
if HarmonyManager.hongmengGuards[i].heroId ~= "" then
count = count + 1
-- body
end
end
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount + count,Box + #HarmonyManager.hongmengGuards})
end
-- Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OnlyRefeshText,{HeroCount,Box, 1})
--this.NumText.text = string.format("%d/%d",HeroCount,Box)
local keys = GameDataBase.SheetBase.GetKeys(this.tab) --获取数据长度
this.ScrollView:SetData(keys,function (index, go)
local key = keys[index]
this.SingleBoxDataShow(go, this.tab[key],index)
ItemList[go] = index
local TimerText = Util.GetGameObject(go.transform,"Box/Empty/Image/Text"):GetComponent("Text")
TextList[index] = TimerText
local Empty = Util.GetGameObject(go.transform,"Box/Empty")
BoxList[index] = Empty
end)
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
if this.timerEffect then
-- body
this.timerEffect:Stop()
end
end
function this:AddListener()
-- body
Game.GlobalEvent:AddEvent(GameEvent.HongMeng.RereshNumText,self.Refesh,self)
Game.GlobalEvent:AddEvent(GameEvent.HongMeng.OpenBoxTips,self.OpenBoxFun,self)
Game.GlobalEvent:AddEvent(GameEvent.HongMeng.ChooseData,self.UpdateHero,self)
Game.GlobalEvent:AddEvent(GameEvent.HongMeng.UnLoadData,self.UnLoadFun,self)
end
function this:RemoveListener()
-- body
Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.RereshNumText,self.Refesh,self)
Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.OpenBoxTips,self.OpenBoxFun,self)
Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.ChooseData,self.UpdateHero,self)
Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.UnLoadData,self.UnLoadFun,self)
end
function this:OnShow(...)
-- body
end
return this