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

421 lines
16 KiB
Lua
Raw Normal View History

2025-03-14 11:58:20 +08:00
require("Base/BasePanel")
2023-09-13 14:57:48 +08:00
local equipConfig = ConfigManager.GetConfig(ConfigName.EquipConfig)
2024-09-06 10:38:56 +08:00
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local giftConfig = ConfigManager.GetConfig(ConfigName.GiftConfig)
2023-09-13 14:57:48 +08:00
PlayerGiftPanel = Inherit(BasePanel)
local isGonming = 0
2024-09-06 10:38:56 +08:00
local tableName = { Language[12684], Language[10228] }
2023-09-13 14:57:48 +08:00
local isUpZhen = false
local this = PlayerGiftPanel
2024-09-06 10:38:56 +08:00
local indexBtnNum = 0
local tabs = {}
local redTabs = {}
local curHeroData = nil
2023-09-13 14:57:48 +08:00
local teamHero
local v1
2024-09-06 10:38:56 +08:00
local allUpIds = {}
local upSuitId = {}
2023-09-13 14:57:48 +08:00
--初始化组件用于子类重写RoleEquipChangePopup
function PlayerGiftPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.bg2 = Util.GetGameObject(self.transform, "bg2")
screenAdapte(this.bg2)
2024-09-06 10:38:56 +08:00
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
2023-09-13 14:57:48 +08:00
this.btnBack = Util.GetGameObject(self.transform, "btnBack/btnBack")
for i = 1, 2 do
tabs[i] = Util.GetGameObject(self.transform, "Tabs/Btn" .. i)
2024-09-06 10:38:56 +08:00
local nameTxt = Util.GetGameObject(tabs[i], "Text"):GetComponent("Text")
2025-01-17 16:26:21 +08:00
nameTxt.fontSize = 40
2024-09-06 10:38:56 +08:00
nameTxt.text = tableName[i]
2023-09-13 14:57:48 +08:00
redTabs[i] = Util.GetGameObject(tabs[i], "red")
2024-09-06 10:38:56 +08:00
if i == 2 then
2023-09-13 14:57:48 +08:00
tabs[i]:SetActive(false)
end
--effectList[i] = Util.GetGameObject(self.transform, "bg/equipInfo/equip" .. i .. "/effect")
end
2024-09-06 10:38:56 +08:00
this.titleTxt = Util.GetGameObject(self.gameObject, "title"):GetComponent("Text")
2025-09-22 14:54:43 +08:00
this.titleTxt.text = Language[10985]
2023-09-13 14:57:48 +08:00
this.selectBtn = Util.GetGameObject(self.gameObject, "selectBtn")
this.btnPrant = Util.GetGameObject(self.gameObject, "Tabs")
this.btnPrant:SetActive(false)
2023-09-13 14:57:48 +08:00
this.equipPreList2 = {}
this.equipPreList = {}
this.equipPre = Util.GetGameObject(self.gameObject, "equipPre")
this.upItemPre = Util.GetGameObject(self.gameObject, "upItemPre")
this.selsectSkillImage = Util.GetGameObject(self.gameObject, "selsectSkillImage")
this.ScrollBar = Util.GetGameObject(self.gameObject, "listObj/bg/Scrollbar"):GetComponent("Scrollbar")
2023-09-13 14:57:48 +08:00
local v2 = Util.GetGameObject(self.gameObject, "scroll"):GetComponent("RectTransform").rect
2024-09-06 10:38:56 +08:00
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,
Util.GetGameObject(self.transform, "listObj/bg/scroll").transform,
this.equipPre, this.ScrollBar, Vector2.New(v2.width, v2.height), 1, 5, Vector2.New(25, 20))
2023-09-13 14:57:48 +08:00
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
v1 = Util.GetGameObject(self.gameObject, "upScroll"):GetComponent("RectTransform").rect
2024-09-06 10:38:56 +08:00
this.UpScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,
Util.GetGameObject(self.transform, "upScroll").transform, this.upItemPre, nil, Vector2.New(v1.width, v1.height),
2025-10-16 19:05:12 +08:00
1, 4, Vector2.New(50, 65))
2023-09-13 14:57:48 +08:00
this.UpScrollView.moveTween.MomentumAmount = 1
this.UpScrollView.moveTween.Strength = 1
2024-09-06 10:38:56 +08:00
-- Util.GetGameObject(self.transform, "powerBtn"):GetComponent("Image").sprite = this.spLoader:LoadSprite("t_tongyong-zhanli_zh")
2023-09-13 14:57:48 +08:00
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")
2024-09-06 10:38:56 +08:00
this.emptyObj = Util.GetGameObject(self.transform, "listObj/bg/emptyObj")
2023-09-13 14:57:48 +08:00
this.emptyObj.gameObject:SetActive(false)
this.mask = Util.GetGameObject(self.gameObject, "mask")
this.mask:SetActive(false)
2024-09-06 10:38:56 +08:00
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")
this.listObj = Util.GetGameObject(self.transform, "listObj")
this.listCloseBtn = Util.GetGameObject(self.transform, "listObj/bg/btn_close")
2024-09-06 10:38:56 +08:00
Util.GetGameObject(self.transform, "listObj/bg/title (1)"):GetComponent("Text").text = Language[12685]
this.proTitle = Util.GetGameObject(self.transform, "proTitle/name/text"):GetComponent("Text")
2025-09-22 14:54:43 +08:00
this.proTitle.text = Language[11823]
this.proGrid = Util.GetGameObject(self.transform, "pro")
2024-09-06 10:38:56 +08:00
this.proPre = Util.GetGameObject(self.transform, "pro/name")
this.tipInfo = Util.GetGameObject(self.transform, "tipInfo"):GetComponent("Text")
this.proEmptyObj = Util.GetGameObject(self.transform, "proEmptyObj")
2024-09-06 10:38:56 +08:00
Util.GetGameObject(self.transform, "proEmptyObj/TextImage/Text"):GetComponent("Text").text = Language[12687]
2023-09-13 14:57:48 +08:00
end
--绑定事件(用于子类重写)
function PlayerGiftPanel:BindEvent()
2024-09-06 10:38:56 +08:00
Util.AddClick(this.listCloseBtn, function()
this.listObj:SetActive(false)
end)
2024-09-06 10:38:56 +08:00
Util.AddClick(this.btn_help, function()
2025-10-23 16:12:18 +08:00
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Mingge, 0, 0)
end)
2024-09-06 10:38:56 +08:00
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)
2024-09-06 10:38:56 +08:00
Util.AddClick(this.btnBack, function()
2023-09-13 14:57:48 +08:00
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
for i = 1, 2 do
2024-09-06 10:38:56 +08:00
Util.AddClick(tabs[i], function()
2023-09-13 14:57:48 +08:00
-- 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
2024-09-06 10:38:56 +08:00
WarPower = WarPower + HeroPowerManager.GetHeroPower(k, FormationTypeDef.FORMATION_NORMAL)
end
2024-09-06 10:38:56 +08:00
WarPower = WarPower + PracticeManager.GetPracticeAddPower()
this.force.text = WarPower
end
2023-09-13 14:57:48 +08:00
--添加事件监听(用于子类重写)
function PlayerGiftPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.RefreshWindowData)
2024-09-06 10:38:56 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Formation.OnFormationPowerChange, this.ChangePowerValue)
2023-09-13 14:57:48 +08:00
end
--移除事件监听(用于子类重写)
function PlayerGiftPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.RefreshWindowData)
2024-09-06 10:38:56 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Formation.OnFormationPowerChange, this.ChangePowerValue)
2023-09-13 14:57:48 +08:00
end
--界面打开时调用(用于子类重写)
function PlayerGiftPanel:OnOpen(...)
2024-09-06 10:38:56 +08:00
local data = { ... }
this.listObj:SetActive(false)
2023-09-13 14:57:48 +08:00
end
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
function PlayerGiftPanel:OnShow()
teamHero = FormationManager.GetAllMainFormationHeroId()
this.RefreshWindowData()
end
function this:OnSortingOrderChange()
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
end
--右切换按钮点击
function this:RightBtnOnClick()
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
end
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
--左切换按钮点击
function this:LeftBtnOnClick()
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
end
2024-09-06 10:38:56 +08:00
local collectNum = 0
2023-09-13 14:57:48 +08:00
function this.RefreshWindowData()
2024-09-06 10:38:56 +08:00
collectNum = 0
this.ChangePowerValue()
2024-09-06 10:38:56 +08:00
--显示上面赠送的
local list = GiftManager.GetPlayerGifts()
LogError("#list=============================" .. #list)
2025-10-23 18:47:36 +08:00
local maxNum = 12
2024-09-06 10:38:56 +08:00
if #list > maxNum then
maxNum = #list + 4
end
local giftDatas = {}
allUpIds = {}
upSuitId = {}
for i = 1, maxNum do
local data = {}
data.type = 1
data.qua = 0
data.id = 0
data.isRed = false
if i <= #list then
data.id = list[i]
data.type = 2
data.qua = itemConfig[list[i]].Quantity
if equipConfig[data.id] then
2024-09-06 10:38:56 +08:00
collectNum = collectNum + equipConfig[data.id].Gift
LogError("equipConfig[data.id].Gift==" .. equipConfig[data.id].Gift)
end
2024-09-06 10:38:56 +08:00
table.insert(allUpIds, data.id)
table.insert(upSuitId, equipConfig[data.id].SuiteID)
else
data.isRed = GiftManager.CheckPlayerRedPoint()
end
2024-09-06 10:38:56 +08:00
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
2024-09-06 10:38:56 +08:00
return a.qua > b.qua
end
else
2024-09-06 10:38:56 +08:00
return a.type > b.type
end
2024-09-06 10:38:56 +08:00
end)
this.UpScrollView:SetData(giftDatas,
2023-09-13 14:57:48 +08:00
function(index, go)
this.SingleUpItemShow(go, giftDatas[index])
end
)
--显示收集度
2024-09-06 10:38:56 +08:00
local lv = 0
local maxValue = 0
2023-09-13 14:57:48 +08:00
for k, v in ConfigPairs(giftConfig) do
2024-09-06 10:38:56 +08:00
if collectNum >= v.Gift then
lv = v.Id
maxValue = v.Gift
2023-09-13 14:57:48 +08:00
else
2024-09-06 10:38:56 +08:00
maxValue = v.Gift
2023-09-13 14:57:48 +08:00
break
end
end
2024-09-06 10:38:56 +08:00
this.lvTxt.text = Language[12688] .. lv
this.barNum.text = collectNum .. "/" .. maxValue
this.barImg.fillAmount = collectNum / maxValue
2023-09-13 14:57:48 +08:00
--显示下面可赠送的
this:OnClickTabBtn(1)
2024-09-06 10:38:56 +08:00
local proList = IncarnationManager.GetproDesLst(GiftManager.GetPlayerGiftAddPro(), "00FF00")
table.insert(proList, string.format(Language[12689], GiftManager.GetPlayerGiftAddPotencyLv()))
table.insert(proList, string.format(Language[12187], GiftManager.GetPlayerGiftAdd()))
if proList and #proList > 0 then
this.proGrid:SetActive(true)
this.proEmptyObj:SetActive(false)
2024-09-06 10:38:56 +08:00
local len = this.proGrid.transform.childCount
local create = #proList - len
if create > 0 then
for i = 1, create do
newObjToParent(this.proPre, this.proGrid)
end
end
2024-09-06 10:38:56 +08:00
len = this.proGrid.transform.childCount
for i = 1, len do
if i <= #proList then
this.proGrid.transform:GetChild(i - 1).gameObject:SetActive(true)
this.proGrid.transform:GetChild(i - 1):GetComponent("Text").text = proList[i]
else
2024-09-06 10:38:56 +08:00
this.proGrid.transform:GetChild(i - 1).gameObject:SetActive(false)
end
end
else
this.proGrid:SetActive(false)
this.proEmptyObj:SetActive(true)
end
--this.tipInfo.text=string.format("全体神将潜能等级+%s",GiftManager.GetPlayerGiftAddPotencyLv())
2023-09-13 14:57:48 +08:00
end
--显示上面几个
2024-09-06 10:38:56 +08:00
function this.SingleUpItemShow(_go, data)
2023-09-13 14:57:48 +08:00
_go:SetActive(true)
_go.transform:SetAsFirstSibling()
2024-09-06 10:38:56 +08:00
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")
local red = Util.GetGameObject(_go, "red")
local starGrid = Util.GetGameObject(_go, "starGrid")
red:SetActive(data.isRed)
2024-09-06 10:38:56 +08:00
if data.id and data.id ~= 0 then
frame.sprite = this.spLoader:LoadSprite(GetQuantityImageByquality(itemConfig[data.id].Quantity))
2023-09-13 14:57:48 +08:00
icon.gameObject:SetActive(true)
name.gameObject:SetActive(true)
2024-04-10 18:50:38 +08:00
starGrid:SetActive(true)
2023-09-13 14:57:48 +08:00
add:SetActive(false)
2024-11-06 16:34:53 +08:00
name.text = SubString2(GetLanguageStrById(itemConfig[data.id].Name))
2024-09-06 10:38:56 +08:00
icon.sprite = this.spLoader:LoadSprite(GetResourcePath(itemConfig[data.id].ResourceID))
SetHeroStars(this.spLoader, starGrid, equipConfig[data.id].Star, 1, nil, -15)
Util.AddOnceClick(icon.gameObject, function()
BagManager.isBagPanel = false
UIManager.OpenPanel(UIName.RewardEquipSingleShowPopup2, this, data, 2, false, nil, nil, 4)
end
)
2023-09-13 14:57:48 +08:00
else
2024-04-10 18:50:38 +08:00
starGrid:SetActive(false)
2024-09-06 10:38:56 +08:00
frame.sprite = this.spLoader:LoadSprite("r_characterbg_blue")
2023-09-13 14:57:48 +08:00
icon.gameObject:SetActive(false)
name.gameObject:SetActive(false)
add:SetActive(true)
end
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(add, function()
this.listObj:SetActive(true)
end)
2023-09-13 14:57:48 +08:00
end
--点击装备按钮
function this:OnClickTabBtn(_index)
indexBtnNum = _index
this:SetSelectBtn()
local allEquip = BagManager.GetBagItemDataByItemType(ItemBaseType.PlayerGift)
-- this:SortEquipDatas(allEquip)
2024-09-06 10:38:56 +08:00
local count = 0
for i = 1, #allEquip do
count = count + 1
if CheckListIsContainValue1(allUpIds, allEquip[i].id) or CheckListIsContainValue1(upSuitId, equipConfig[allEquip[i].id].SuiteID) 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
2023-09-13 14:57:48 +08:00
else
2024-09-06 10:38:56 +08:00
return a.quality > b.quality
2023-09-13 14:57:48 +08:00
end
else
2024-09-06 10:38:56 +08:00
return a.isUp > b.isUp
2023-09-13 14:57:48 +08:00
end
2024-09-06 10:38:56 +08:00
end)
--"装备数量:"
this.itemNumText.text = Language[12690] .. count
this:SetItemData(allEquip)
2023-09-13 14:57:48 +08:00
--this.CheckRedTab()
end
2024-09-06 10:38:56 +08:00
function this:SetItemData(_itemDatas)
2023-09-13 14:57:48 +08:00
if LengthOfTable(_itemDatas) == 0 then
this.emptyObj.gameObject:SetActive(true)
else
this.emptyObj.gameObject:SetActive(false)
end
2024-09-06 10:38:56 +08:00
for k, v in pairs(this.equipPreList) do
2023-09-13 14:57:48 +08:00
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
2024-09-06 10:38:56 +08:00
this.equipPreList[_go] = SubUIManager.Open(SubUIConfig.ItemView, _go.transform)
2023-09-13 14:57:48 +08:00
end
local redPoint = Util.GetGameObject(_go.transform, "redPoint")
2024-09-06 10:38:56 +08:00
local tip = Util.GetGameObject(_go.transform, "tip")
tip:SetActive(_itemData.isUp == 1)
local isHave = CheckListIsContainValue1(allUpIds, _itemData.id) or
CheckListIsContainValue1(upSuitId, equipConfig[_itemData.id].SuiteID)
redPoint:SetActive(isHave == false)
2023-09-13 14:57:48 +08:00
this.equipPreList[_go].gameObject:SetActive(true)
this.equipPreList[_go].transform:SetAsFirstSibling()
--if itemConfig[_itemData.id].ItemType == ItemType.Equip then
2024-09-06 10:38:56 +08:00
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
2023-09-13 14:57:48 +08:00
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)
2025-01-17 16:26:21 +08:00
Util.GetGameObject(this.selectBtn.transform, "Text"):GetComponent("Text").text = GetCurLanguage() == -1 and
2024-09-06 10:38:56 +08:00
tableName[indexBtnNum] or
"<size=40>" ..
tableName[indexBtnNum] ..
"</size>" --typeTab[indexBtnNum]
2023-09-13 14:57:48 +08:00
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
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
--界面关闭时调用(用于子类重写)
function PlayerGiftPanel:OnClose()
2024-09-06 10:38:56 +08:00
BagManager.isBagPanel = false
2023-09-13 14:57:48 +08:00
end
--界面销毁时调用(用于子类重写)
function PlayerGiftPanel:OnDestroy()
2024-09-06 10:38:56 +08:00
2023-09-13 14:57:48 +08:00
end
2024-09-06 10:38:56 +08:00
return PlayerGiftPanel