--> 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:WearRefresh(data: table) local newSlot = data.instance:GetAttribute("wearing") self.Variables["__listWeaing"]:RemoveData("slot"..newSlot) self.Variables["__listWeaponPackage"]:RemoveData(tostring(data.id)) -- 更新穿戴数据,要不再点击前端就不好使了 data.wearing = newSlot self.Variables["__listWeaing"]:AddData("slot"..newSlot, data) -- 关闭装备详情窗口 self.UIManager:CloseWindow("EquipmentDetailWindow") end function ChaWindow:UnwearRefresh(data: table) local oldSlot = data.wearing self.Variables["__listWeaing"]:RemoveData("slot"..oldSlot) data.wearing = 0 self.Variables["__listWeaponPackage"]:AddData(tostring(data.id), data) self.Data.Wearing["slot"..oldSlot] = { wearing = oldSlot, } self.Variables["__listWeaing"]:AddData("slot"..oldSlot, self.Data.Wearing["slot"..oldSlot]) -- 关闭装备详情窗口 self.UIManager:CloseWindow("EquipmentDetailWindow") end function ChaWindow:AddInstanceData(configInstance: Instance, Data: table?) local data = self.Data if Data then data = Data end local attributes = configInstance:GetAttributes() -- 归类是否是穿戴的装备 local parentName, secondName = "Package", configInstance.Name if attributes.wearing ~= 0 then parentName = "Wearing" secondName = "slot"..attributes.wearing end data[parentName][secondName] = {} for attributeKey, attributeValue in attributes do data[parentName][secondName][attributeKey] = attributeValue end data[parentName][secondName].instance = configInstance return data[parentName][secondName], 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("slot"..data.wearing, data) else self.Variables["__listWeaponPackage"]:AddData(child.Name, 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