miduo_client/Assets/ManagedResources/~Lua/Modules/RoleInfo/PlayerGiftPanel.lua

359 lines
13 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.

require("Base/BasePanel")
local equipConfig = ConfigManager.GetConfig(ConfigName.EquipConfig)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local giftConfig=ConfigManager.GetConfig(ConfigName.GiftConfig)
PlayerGiftPanel = Inherit(BasePanel)
local isGonming = 0
local tableName={ "礼物","碎片"}
local isUpZhen = false
local this = PlayerGiftPanel
local indexBtnNum=0
local tabs={}
local redTabs={}
local curHeroData=nil
local teamHero
local v1
local allUpIds={}
--初始化组件用于子类重写RoleEquipChangePopup
function PlayerGiftPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.bg2 = Util.GetGameObject(self.transform, "bg2")
screenAdapte(this.bg2)
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, {showType = UpViewOpenType.ShowLeft})
this.btnBack = Util.GetGameObject(self.transform, "btnBack/btnBack")
for i = 1, 2 do
tabs[i] = Util.GetGameObject(self.transform, "Tabs/Btn" .. i)
local nameTxt=Util.GetGameObject(tabs[i], "Text"):GetComponent("Text")
nameTxt.fontSize = GetCurLanguage() == 0 and 48 or 40
nameTxt.text=tableName[i]
redTabs[i] = Util.GetGameObject(tabs[i], "red")
if i==2 then
tabs[i]:SetActive(false)
end
--effectList[i] = Util.GetGameObject(self.transform, "bg/equipInfo/equip" .. i .. "/effect")
end
this.titleTxt=Util.GetGameObject(self.gameObject, "title"):GetComponent("Text")
this.titleTxt.text="主角礼物"
this.selectBtn = Util.GetGameObject(self.gameObject, "selectBtn")
this.btnPrant = Util.GetGameObject(self.gameObject, "Tabs")
this.equipPreList2 = {}
this.equipPreList = {}
this.equipPre = Util.GetGameObject(self.gameObject, "equipPre")
this.upItemPre = Util.GetGameObject(self.gameObject, "upItemPre")
this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
this.selsectSkillImage = Util.GetGameObject(self.gameObject, "selsectSkillImage")
this.ScrollBar = Util.GetGameObject(self.gameObject, "Scrollbar"):GetComponent("Scrollbar")
local v2 = Util.GetGameObject(self.gameObject, "scroll"):GetComponent("RectTransform").rect
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(self.transform, "scroll").transform,
this.equipPre, this.ScrollBar,Vector2.New(v2.width, v2.height),1 , 5, Vector2.New(40, 15))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
v1 = Util.GetGameObject(self.gameObject, "upScroll"):GetComponent("RectTransform").rect
this.UpScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(self.transform, "upScroll").transform,this.upItemPre, nil,Vector2.New(v1.width,v1.height),1 ,4, Vector2.New(50,42))
this.UpScrollView.moveTween.MomentumAmount = 1
this.UpScrollView.moveTween.Strength = 1
Util.GetGameObject(self.transform, "powerBtn"):GetComponent("Image").sprite = this.spLoader:LoadSprite("UI_hz_shenjiang_15_zh")
this.force = Util.GetGameObject(self.transform, "powerBtn/value"):GetComponent("Text")
this.itemNumText = Util.GetGameObject(self.transform, "itemNumText"):GetComponent("Text")
this.upLvEffect = Util.GetGameObject(self.transform, "powerBtn/effect")
this.emptyObj = Util.GetGameObject(self.transform, "emptyObj")
this.emptyObj.gameObject:SetActive(false)
this.mask = Util.GetGameObject(self.gameObject, "mask")
this.mask:SetActive(false)
this.lvTxt=Util.GetGameObject(self.gameObject, "collectLv"):GetComponent("Text")
this.collectImg=Util.GetGameObject(self.gameObject, "collectImg"):GetComponent("Image")
--this.collectImg.sprite=this.spLoader:LoadSprite("gh_tt_8")
this.barImg=Util.GetGameObject(self.gameObject, "progressbar/progress1"):GetComponent("Image")
this.barNum=Util.GetGameObject(self.gameObject, "progressbar/num"):GetComponent("Text")
this.btn_help=Util.GetGameObject(self.gameObject, "btn_help")
end
--绑定事件(用于子类重写)
function PlayerGiftPanel:BindEvent()
Util.AddClick(this.btn_help,function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Gift,0,0)
end)
Util.AddClick(this.collectImg.gameObject,function()
local data = {}
local singData = {}
singData.title = "当前礼物总加成"
singData.pro = IncarnationManager.GetproDesLst(GiftManager.GetPlayerGiftAddPro(),"00FF00")
singData.tip ="" --"总加成包括化身之力提供的属性"
table.insert(data,singData)
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.IncarnationDes,data)
end)
Util.AddClick(this.btnBack,function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
for i = 1, 2 do
Util.AddClick(tabs[i],function()
-- isPlayAnim = true
if i == indexBtnNum then
return
end
indexBtnNum = i
this:OnClickTabBtn(indexBtnNum)
end)
end
end
function this.ChangePowerValue()
local WarPower = 0
for k, v in pairs(teamHero) do
WarPower = WarPower+ HeroPowerManager.GetHeroPower(k,FormationTypeDef.FORMATION_NORMAL)
end
WarPower=WarPower+PracticeManager.GetPracticeAddPower()
this.force.text = WarPower
end
--添加事件监听(用于子类重写)
function PlayerGiftPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.RefreshWindowData)
Game.GlobalEvent:AddEvent(GameEvent.Formation.OnFormationPowerChange,this.ChangePowerValue)
end
--移除事件监听(用于子类重写)
function PlayerGiftPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.RefreshWindowData)
Game.GlobalEvent:RemoveEvent(GameEvent.Formation.OnFormationPowerChange,this.ChangePowerValue)
end
--界面打开时调用(用于子类重写)
function PlayerGiftPanel:OnOpen(...)
local data = {...}
end
function PlayerGiftPanel:OnShow()
teamHero = FormationManager.GetAllMainFormationHeroId()
this.RefreshWindowData()
end
function this:OnSortingOrderChange()
end
--右切换按钮点击
function this:RightBtnOnClick()
end
--左切换按钮点击
function this:LeftBtnOnClick()
end
local collectNum=0
function this.RefreshWindowData()
collectNum=0
this.ChangePowerValue()
--显示上面赠送的
local list=GiftManager.GetPlayerGifts()
local maxNum=16
if #list>maxNum then
maxNum=#list+4
end
local giftDatas={}
allUpIds={}
for i=1,maxNum do
local data={}
data.type=1
data.qua=0
data.id=0
if i<=#list then
data.id=list[i]
data.type=2
data.qua=itemConfig[list[i]].Quantity
if equipConfig[data.id] then
collectNum=collectNum + equipConfig[data.id].Gift
LogError("equipConfig[data.id].Gift=="..equipConfig[data.id].Gift)
end
table.insert(allUpIds,data.id)
end
table.insert(giftDatas,data)
end
table.sort(giftDatas,function(a,b)
if a.type==b.type then
if a.qua and a.qua==b.qua then
return a.id<b.id
else
return a.qua>b.qua
end
else
return a.type>b.type
end
end)
this.UpScrollView:SetData(giftDatas,
function(index, go)
this.SingleUpItemShow(go, giftDatas[index])
end
)
--显示收集度
local lv=0
local maxValue=0
for k, v in ConfigPairs(giftConfig) do
if collectNum>=v.Gift then
lv=v.Id
maxValue=v.Gift
else
maxValue=v.Gift
break
end
end
this.lvTxt.text="收集值等级 "..lv
this.barNum.text=collectNum.."/"..maxValue
this.barImg.fillAmount=collectNum/maxValue
--显示下面可赠送的
this:OnClickTabBtn(1)
end
--显示上面几个
function this.SingleUpItemShow(_go,data)
_go:SetActive(true)
_go.transform:SetAsFirstSibling()
local frame=_go:GetComponent("Image")
local icon=Util.GetGameObject(_go,"icon"):GetComponent("Image")
local name=Util.GetGameObject(_go,"name"):GetComponent("Text")
local add=Util.GetGameObject(_go,"add")
if data.id and data.id~=0 then
frame.sprite=this.spLoader:LoadSprite(GetQuantityImageByquality(itemConfig[data.id].Quantity))
icon.gameObject:SetActive(true)
name.gameObject:SetActive(true)
add:SetActive(false)
name.text=itemConfig[data.id].Name
icon.sprite=this.spLoader:LoadSprite(GetResourcePath(itemConfig[data.id].ResourceID))
Util.AddOnceClick(icon.gameObject,function()
BagManager.isBagPanel=false
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2,this,data,0,false,nil,nil,4)
end
)
else
frame.sprite=this.spLoader:LoadSprite("r_characterbg_blue")
icon.gameObject:SetActive(false)
name.gameObject:SetActive(false)
add:SetActive(true)
end
end
--点击装备按钮
function this:OnClickTabBtn(_index)
indexBtnNum = _index
this:SetSelectBtn()
local allEquip = BagManager.GetBagItemDataByItemType(ItemBaseType.PlayerGift)
-- this:SortEquipDatas(allEquip)
local count = 0
for i=1,#allEquip do
count = count + 1
if CheckListIsContainValue1(allUpIds,allEquip[i].id) then
allEquip[i].isUp=1
else
allEquip[i].isUp=2
end
end
table.sort(allEquip,function(a,b)
if a.isUp==b.isUp then
if a.quality==b.quality then
return a.id<b.id
else
return a.quality>b.quality
end
else
return a.isUp>b.isUp
end
end)
--"装备数量:"
this.itemNumText.text = "礼物种类:" .. count
this:SetItemData(allEquip)
--this.CheckRedTab()
end
function this:SetItemData(_itemDatas)
if LengthOfTable(_itemDatas) == 0 then
this.emptyObj.gameObject:SetActive(true)
else
this.emptyObj.gameObject:SetActive(false)
end
for k,v in pairs(this.equipPreList) do
v.gameObject:SetActive(false)
end
this.ScrollView:SetData(
_itemDatas,
function(index, go)
this.SingleItemDataShow(go, _itemDatas[index])
end
)
end
function this.SingleItemDataShow(_go, _itemData)
if not itemConfig[_itemData.id] then
return
end
if not this.equipPreList[_go] then
this.equipPreList[_go] = SubUIManager.Open(SubUIConfig.ItemView,_go.transform)
end
local redPoint = Util.GetGameObject(_go.transform, "redPoint")
local tip=Util.GetGameObject(_go.transform, "tip")
tip:SetActive(_itemData.isUp==1)
local isHave=CheckListIsContainValue1(allUpIds,_itemData.id)
redPoint:SetActive(isHave==false)
this.equipPreList[_go].gameObject:SetActive(true)
this.equipPreList[_go].transform:SetAsFirstSibling()
--if itemConfig[_itemData.id].ItemType == ItemType.Equip then
this.equipPreList[_go]:OnOpen(false,{_itemData.id,_itemData.num}, 1.1, true, false, false, this.sortingOrder+1,_itemData.idDyn)
-- 0.查看属性 1.穿戴 2.卸下 3.交换
--宝物界面
Util.AddOnceClick(Util.GetGameObject(_go.transform, "mask"),function()
BagManager.isBagPanel=true
if isHave then
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2,this,_itemData,6,false,nil,curHeroData,4)
else
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2,this,_itemData,3,false,nil,curHeroData,4)
end
end
)
--end
end
function this:SetSelectBtn()
this.selectBtn:SetActive(true)
this.selectBtn.transform:SetParent(tabs[indexBtnNum].transform)
this.selectBtn:GetComponent("RectTransform").anchoredPosition3D = Vector3(-12.28, 1.08, 0)
this.selectBtn.transform:SetSiblingIndex(1)
Util.GetGameObject(this.selectBtn.transform, "Text"):GetComponent("Text").text = GetCurLanguage() == 0 and tableName[indexBtnNum] or "<size=40>"..tableName[indexBtnNum].."</size>"--typeTab[indexBtnNum]
end
--选择图片设置父级
function this.SelectImageSetParent(_objPoint)
this.selsectSkillImage:SetActive(false)
this.selsectSkillImage.transform:SetParent(_objPoint.transform)
this.selsectSkillImage.transform.localScale = Vector3.one
this.selsectSkillImage.transform.localPosition = Vector3.zero
end
--界面关闭时调用(用于子类重写)
function PlayerGiftPanel:OnClose()
BagManager.isBagPanel=false
end
--界面销毁时调用(用于子类重写)
function PlayerGiftPanel:OnDestroy()
end
return PlayerGiftPanel