142 lines
4.3 KiB
Plaintext
Raw Normal View History

2025-07-22 01:56:56 +08:00
--> Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--> Dependencies
local UIWindow = require(ReplicatedStorage.Base.UIWindow)
local UIEnums = require(ReplicatedStorage.Base.UIEnums)
--> Components
local WearingShow = require(script.WearingShow)
local PackageShow = require(script.PackageShow)
--> Dependencies
local Utils = require(ReplicatedStorage.Tools.Utils)
--> Json
local JsonAttributesUpgrade = require(ReplicatedStorage.Json.AttributesUpgrade)
--> Variables
local LocalPlayer = game.Players.LocalPlayer
--------------------------------------------------------------------------------
local ChaWindow = {}
ChaWindow.__index = ChaWindow
setmetatable(ChaWindow, {__index = UIWindow})
function ChaWindow:Init(UIManager: table, Data: table?)
local self = UIWindow:Init(UIManager, Data)
setmetatable(self, ChaWindow)
self.Variables = {
["__listWeaponPackage"] = 0,
["__listWeaing"] = 0,
["_tmpCombatValue"] = 0,
["_imgIcon"] = 0,
["_btnClose"] = 0,
["_btnBgClose"] = 0,
}
self.UIRootName = "ui_w_cha"
self.UIParentName = UIEnums.UIParent.UIRoot
return self
end
function ChaWindow:ShowDetailData(uniqueId: number)
local data = {
EquipmentUniqueId = uniqueId,
}
self.UIManager:OpenWindow("EquipmentDetailWindow", data)
end
function ChaWindow:AddInstanceData(configInstance: Instance, Data: table?)
local data = self.Data
if Data then data = Data end
local attributes = configInstance:GetAttributes()
-- 归类是否是穿戴的装备
local parentName = "Package"
if attributes.wearing ~= 0 then parentName = "Wearing" end
data[parentName][configInstance.Name] = {}
for attributeKey, attributeValue in attributes do
data[parentName][configInstance.Name][attributeKey] = attributeValue
end
return data[parentName][configInstance.Name], parentName
end
function ChaWindow:OnOpenWindow()
UIWindow.OnOpenWindow(self)
-- 自己进行数据处理
local DataFolder = Utils:GetPlayerDataFolder(LocalPlayer):FindFirstChild("Equipment")
local data = {
Wearing = {},
Package = {},
}
for _, child in DataFolder:GetChildren() do
self:AddInstanceData(child, data)
end
self:SetData(data)
local maxSlotNumber = Utils:GetIdDataFromJson(JsonAttributesUpgrade, 10).maxLv
for i = 1, maxSlotNumber do
local isExist = false
for k, data in pairs(self.Data.Wearing) do
if data.wearing == i then
isExist = true
break
end
end
if not isExist then
self.Data.Wearing["slot" .. i] = {
wearing = i,
}
end
end
local addCon = DataFolder.ChildAdded:Connect(function(child)
local data, parentName = self:AddInstanceData(child, data)
if parentName == "Wearing" then
self.Variables["__listWeaing"]:AddData(data)
else
self.Variables["__listWeaponPackage"]:AddData(data)
end
end)
local removeCon = DataFolder.ChildRemoved:Connect(function(child)
local parentName = self:RemoveInstanceData(child, data)
if parentName == "Wearing" then
local removeIndex = self.Variables["__listWeaing"]:RemoveData(data)
self.Data.Wearing[removeIndex] = {}
else
local removeIndex = self.Variables["__listWeaponPackage"]:RemoveData(data)
self.Data.Package[removeIndex] = {}
end
end)
local bgCloseCon = self.Variables["_btnBgClose"].Activated:Connect(function()
self.UIManager:CloseWindow(script.Name)
end)
local closeCon = self.Variables["_btnClose"].Activated:Connect(function()
self.UIManager:CloseWindow(script.Name)
end)
table.insert(self.Connections, addCon)
table.insert(self.Connections, removeCon)
table.insert(self.Connections, bgCloseCon)
table.insert(self.Connections, closeCon)
self.Variables["__listWeaponPackage"]:AddComponent(PackageShow)
self.Variables["__listWeaing"]:AddComponent(WearingShow)
self.Variables["__listWeaponPackage"]:SetData(self.Data.Package)
self.Variables["__listWeaing"]:SetData(self.Data.Wearing)
self.Variables["__listWeaing"]:SetLayoutOrder("wearing")
end
function ChaWindow:OnCloseWindow()
UIWindow.OnCloseWindow(self)
end
return ChaWindow