--> 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) local Localization = require(ReplicatedStorage.Tools.Localization) --> Json local JsonRune = require(ReplicatedStorage.Json.Rune) local JsonItem = require(ReplicatedStorage.Json.ItemProp) local JsonEquipment = require(ReplicatedStorage.Json.Equipment) --> Events local RE_RuneInlay = ReplicatedStorage.Events.RE_RuneInlay --> Variables local LocalPlayer = game.Players.LocalPlayer --> Prefabs local FolderEquipmentPrefabs = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") local EquipmentFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Equipment") local DataFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Rune") local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) --> Signals local Signal = require(ReplicatedStorage.Tools.Signal) local selectRuneInlayEquipmentSignal = Signal.new(Signal.ENUM.SELECT_RUNE_INLAY_EQUIPMENT) -------------------------------------------------------------------------------- local RuneWindow = {} RuneWindow.__index = RuneWindow setmetatable(RuneWindow, {__index = UIWindow}) function RuneWindow:Init(UIManager: table, Data: table?) local self = UIWindow:Init(UIManager, Data) setmetatable(self, RuneWindow) self.Variables = { ["_goRunePanel"] = 0, ["__listRunePackage"] = 0, ["__listRuneWearing"] = 0, ["_tmpName"] = 0, ["_tmpQuality"] = 0, ["_imgIcon"] = 0, ["_bgNowSelectFrame"] = 0, ["_imgNowRune"] = 0, ["_tmpNowRuneName"] = 0, ["_tmpMaxRuneEmpty"] = 0, ["_imgView"] = 0, ["_btnClose"] = 0, ["_btnBgClose"] = 0, ["_btnInlay"] = 0, ["_btnChangeEquipment"] = 0, } self.UIRootName = "ui_w_rune" self.UIParentName = UIEnums.UIParent.UIRoot self.ShowEquipmentId = nil self.NowSelectRuneId = nil self.NowMaxRuneNumber = 0 return self end function RuneWindow:ShowDetailData(uniqueId: number, orgId: number) if uniqueId then if self.NowMaxRuneNumber == 0 then warn("当前最大符文数量为0") return end self.NowSelectRuneId = uniqueId local runeData = Utils:GetIdDataFromJson(JsonRune, orgId) self.Variables["_tmpNowRuneName"].Text = Localization:GetLanguageData(runeData.nameId) self.Variables["_imgNowRune"].Image = Localization:GetImageData(runeData.icon) self.Variables["_imgNowRune"].BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality) self.Variables["_imgNowRune"].Transparency = 0 else self.NowSelectRuneId = nil self.Variables["_tmpNowRuneName"].Text = "" self.Variables["_imgNowRune"].Image = "" self.Variables["_imgNowRune"].BackgroundColor3 = Color3.fromRGB(0, 0, 0) self.Variables["_imgNowRune"].Transparency = 1 end end function RuneWindow:RefreshEquipmentName() if self.ShowEquipmentId then local equipmentInstance = EquipmentFolder:FindFirstChild(self.ShowEquipmentId) local itemData = Utils:GetIdDataFromJson(JsonItem, equipmentInstance:GetAttribute("orgId")) self.Variables["_tmpName"].Text = Localization:GetLanguageData(itemData.nameId) self.Variables["_tmpQuality"].Text = Localization:GetColoredEquipmentQualityDesc(equipmentInstance:GetAttribute("quality")) else self.Variables["_tmpName"].Text = "" self.Variables["_tmpQuality"].Text = "" end end function RuneWindow:WearRefresh(data: table) local newSlot = data.instance:GetAttribute("wearing") self.Variables["__listRuneWearing"]:RemoveData("slot"..newSlot) self.Variables["__listRunePackage"]:RemoveData(tostring(data.id)) -- 更新穿戴数据,要不再点击前端就不好使了 data.wearing = newSlot self.Variables["__listRuneWearing"]:AddData("slot"..newSlot, data) -- 穿戴后,如果当前穿戴的符文是当前选中的符文,则刷新当前选中的符文为空 if data.id == self.NowSelectRuneId then self:ShowDetailData() end end function RuneWindow:UnwearRefresh(data: table) local oldSlot = data.wearing self.Variables["__listRuneWearing"]:RemoveData("slot"..oldSlot) data.wearing = 0 self.Variables["__listRunePackage"]:AddData(tostring(data.id), data) self.Data.Wearing["slot"..oldSlot] = { wearing = oldSlot, } self.Variables["__listRuneWearing"]:AddData("slot"..oldSlot, self.Data.Wearing["slot"..oldSlot]) end function RuneWindow:InlayRune() if self.NowSelectRuneId and self.ShowEquipmentId then RE_RuneInlay:FireClient(self.NowSelectRuneId, self.ShowEquipmentId) end end function RuneWindow:AddInstanceData(configInstance: Instance, Data: table?) local data = self.Data if Data then data = Data end local attributes = configInstance:GetAttributes() -- 归类是否是穿戴的装备 local parentName, secondName = "PackageRune", configInstance.Name if attributes.wearing == self.ShowEquipmentId then parentName = "WearingRune" secondName = "slot"..attributes.wearingSlot 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 RuneWindow:RemoveInstanceData(configInstance: Instance, Data: table?) for key, data in pairs(self.Data.WearingRune) do if data.instance == configInstance then return tostring(key), "WearingRune" end end for key, data in pairs(self.Data.PackageRune) do if data.instance == configInstance then return tostring(key), "PackageRune" end end return nil end function RuneWindow:ShowWearingSlot() -- 清除旧数据 if self.Data then if self.Data.WearingRune then self.Data.WearingRune = nil end if self.Data.PackageRune then self.Data.PackageRune = nil end end self.Data = { WearingRune = {}, PackageRune = {}, } local equipmentInstance = EquipmentFolder:FindFirstChild(self.ShowEquipmentId) local maxRuneNumber = equipmentInstance:GetAttribute("maxRuneNumber") self.NowMaxRuneNumber = maxRuneNumber self:RefreshEquipmentName() -- 模型展示 EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], equipmentInstance:GetAttribute("orgId"), false) -- 如果当前最大槽位数为0,刷新至空显示 if maxRuneNumber <= 0 then self:ShowDetailData() self.Variables["_bgNowSelectFrame"].Visible = false self.Variables["_tmpMaxRuneEmpty"].Text = Localization:GetLanguageData(1200) self.Variables["_tmpMaxRuneEmpty"].Visible = true else self.Variables["_bgNowSelectFrame"].Visible = true self.Variables["_tmpMaxRuneEmpty"].Visible = false end -- 补充空槽位 for i = 1, self.NowMaxRuneNumber do local isExist = false for k, data in pairs(self.Data.WearingRune) do if data.wearingSlot == i then isExist = true break end end if not isExist then self.Data.WearingRune["slot" .. i] = { wearingSlot = i, } end end -- 添加符文数据 for _, child in DataFolder:GetChildren() do self:AddInstanceData(child, self.Data) end self:SetData(self.Data) self.Variables["__listRunePackage"]:SetData(self.Data.PackageRune) self.Variables["__listRuneWearing"]:SetData(self.Data.WearingRune) end function RuneWindow:OnOpenWindow() UIWindow.OnOpenWindow(self) self.Variables["__listRunePackage"]:AddComponent(PackageShow) self.Variables["__listRuneWearing"]:AddComponent(WearingShow) 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, bgCloseCon) table.insert(self.Connections, closeCon) -- 找到当前穿戴的装备 for _, child in EquipmentFolder:GetChildren() do if child:GetAttribute("wearing") ~= 0 then self.ShowEquipmentId = child.Name break end end -- 如果当前没有穿戴的装备,并且没有装备,则报错提示, 并返回内容 if not self.ShowEquipmentId and #EquipmentFolder:GetChildren() == 0 then warn("没有找到当前穿戴的装备") self.NowMaxRuneNumber = 0 return end -- 如果当前没有穿戴的装备,则默认使用第一个装备 if not self.ShowEquipmentId then self.ShowEquipmentId = EquipmentFolder:GetChildren()[1].Name end self:ShowWearingSlot() local addCon = DataFolder.ChildAdded:Connect(function(child) local data, parentName = self:AddInstanceData(child, self.Data) if parentName == "WearingRune" then self.Variables["__listRuneWearing"]:AddData("slot"..data.wearingSlot, data) else self.Variables["__listRunePackage"]:AddData(child.Name, data) end end) local removeCon = DataFolder.ChildRemoved:Connect(function(child) -- TODO: 这里清除逻辑不清晰,之后优化 local key, parentName = self:RemoveInstanceData(child, self.Data) if parentName == "WearingRune" then local removeIndex = self.Variables["__listRuneWearing"]:RemoveData(key) else local removeIndex = self.Variables["__listRunePackage"]:RemoveData(key) end end) table.insert(self.Connections, addCon) table.insert(self.Connections, removeCon) self.Variables["__listRuneWearing"]:SetLayoutOrder("wearingSlot") local inlayCon = self.Variables["_btnInlay"].Activated:Connect(function() self:InlayRune() end) table.insert(self.Connections, inlayCon) local changeEquipmentCon = self.Variables["_btnChangeEquipment"].Activated:Connect(function() self.UIManager:OpenWindow("SelectEquipmentWindow", { ExpectIds = {tostring(self.ShowEquipmentId)}, }) end) table.insert(self.Connections, changeEquipmentCon) local selectRuneInlayEquipmentCon = selectRuneInlayEquipmentSignal:Connect(function(id) self.ShowEquipmentId = id self:RefreshEquipmentName() self:ShowWearingSlot() end) table.insert(self.Connections, selectRuneInlayEquipmentCon) end function RuneWindow:OnCloseWindow() UIWindow.OnCloseWindow(self) end return RuneWindow