313 lines
11 KiB
Plaintext
Raw Normal View History

2025-08-14 19:28:30 +08:00
--> Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--> Dependencies
local UIWindow = require(ReplicatedStorage.Base.UIWindow)
local UIEnums = require(ReplicatedStorage.Base.UIEnums)
--> Components
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)
2025-08-15 17:28:23 +08:00
local JsonItem = require(ReplicatedStorage.Json.ItemProp)
local JsonEquipment = require(ReplicatedStorage.Json.Equipment)
2025-08-14 19:28:30 +08:00
--> Events
local RE_RuneInlay = ReplicatedStorage.Events.RE_RuneInlay
--> Variables
local LocalPlayer = game.Players.LocalPlayer
2025-08-15 17:28:23 +08:00
--> 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"))
2025-08-24 22:50:04 +08:00
local RuneShow = require(CommonFolder:WaitForChild("RuneShow"))
2025-08-15 17:28:23 +08:00
--> Signals
local Signal = require(ReplicatedStorage.Tools.Signal)
local selectRuneInlayEquipmentSignal = Signal.new(Signal.ENUM.SELECT_RUNE_INLAY_EQUIPMENT)
2025-08-14 19:28:30 +08:00
--------------------------------------------------------------------------------
2025-08-15 00:45:18 +08:00
local RuneWindow = {}
RuneWindow.__index = RuneWindow
setmetatable(RuneWindow, {__index = UIWindow})
2025-08-14 19:28:30 +08:00
2025-08-15 00:45:18 +08:00
function RuneWindow:Init(UIManager: table, Data: table?)
2025-08-14 19:28:30 +08:00
local self = UIWindow:Init(UIManager, Data)
2025-08-15 00:45:18 +08:00
setmetatable(self, RuneWindow)
2025-08-14 19:28:30 +08:00
self.Variables = {
["_goRunePanel"] = 0,
["__listRunePackage"] = 0,
["__listRuneWearing"] = 0,
2025-08-15 17:28:23 +08:00
["_tmpName"] = 0,
["_tmpQuality"] = 0,
2025-08-14 19:28:30 +08:00
["_imgIcon"] = 0,
["_bgNowSelectFrame"] = 0,
["_imgNowRune"] = 0,
["_tmpNowRuneName"] = 0,
2025-08-15 17:28:23 +08:00
["_tmpMaxRuneEmpty"] = 0,
["_imgView"] = 0,
2025-08-14 19:28:30 +08:00
["_btnClose"] = 0,
["_btnBgClose"] = 0,
["_btnInlay"] = 0,
2025-08-15 17:28:23 +08:00
["_btnChangeEquipment"] = 0,
2025-08-14 19:28:30 +08:00
}
self.UIRootName = "ui_w_rune"
self.UIParentName = UIEnums.UIParent.UIRoot
self.ShowEquipmentId = nil
self.NowSelectRuneId = nil
2025-08-15 17:28:23 +08:00
self.NowMaxRuneNumber = 0
2025-08-14 19:28:30 +08:00
return self
end
2025-08-15 17:28:23 +08:00
function RuneWindow:ShowDetailData(uniqueId: number, orgId: number)
2025-08-14 19:28:30 +08:00
if uniqueId then
2025-08-15 17:28:23 +08:00
if self.NowMaxRuneNumber == 0 then warn("当前最大符文数量为0") return end
2025-08-14 19:28:30 +08:00
self.NowSelectRuneId = uniqueId
2025-08-15 17:28:23 +08:00
local runeData = Utils:GetIdDataFromJson(JsonRune, orgId)
2025-08-14 19:28:30 +08:00
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
2025-08-15 17:28:23 +08:00
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
2025-08-15 00:45:18 +08:00
function RuneWindow:WearRefresh(data: table)
2025-08-14 19:28:30 +08:00
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
2025-08-15 00:45:18 +08:00
function RuneWindow:UnwearRefresh(data: table)
2025-08-14 19:28:30 +08:00
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
2025-08-15 00:45:18 +08:00
function RuneWindow:InlayRune()
2025-08-14 19:28:30 +08:00
if self.NowSelectRuneId and self.ShowEquipmentId then
2025-08-15 19:24:17 +08:00
RE_RuneInlay:FireServer(self.NowSelectRuneId, self.ShowEquipmentId)
2025-08-14 19:28:30 +08:00
end
2025-08-15 17:28:23 +08:00
end
2025-08-14 19:28:30 +08:00
2025-08-15 00:45:18 +08:00
function RuneWindow:AddInstanceData(configInstance: Instance, Data: table?)
2025-08-14 19:28:30 +08:00
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
2025-08-15 00:45:18 +08:00
function RuneWindow:RemoveInstanceData(configInstance: Instance, Data: table?)
2025-08-14 19:28:30 +08:00
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
2025-08-15 17:28:23 +08:00
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
2025-08-15 00:45:18 +08:00
function RuneWindow:OnOpenWindow()
2025-08-14 19:28:30 +08:00
UIWindow.OnOpenWindow(self)
2025-08-15 00:45:18 +08:00
self.Variables["__listRunePackage"]:AddComponent(PackageShow)
2025-08-24 22:50:04 +08:00
self.Variables["__listRuneWearing"]:AddComponent(RuneShow)
2025-08-15 00:45:18 +08:00
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)
2025-08-14 19:28:30 +08:00
-- 找到当前穿戴的装备
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("没有找到当前穿戴的装备")
2025-08-15 17:28:23 +08:00
self.NowMaxRuneNumber = 0
2025-08-14 19:28:30 +08:00
return
end
-- 如果当前没有穿戴的装备,则默认使用第一个装备
if not self.ShowEquipmentId then
self.ShowEquipmentId = EquipmentFolder:GetChildren()[1].Name
end
2025-08-15 17:28:23 +08:00
self:ShowWearingSlot()
2025-08-14 19:28:30 +08:00
local addCon = DataFolder.ChildAdded:Connect(function(child)
2025-08-15 17:28:23 +08:00
local data, parentName = self:AddInstanceData(child, self.Data)
2025-08-14 19:28:30 +08:00
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")
2025-08-15 17:28:23 +08:00
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)
2025-08-14 19:28:30 +08:00
end
2025-08-15 00:45:18 +08:00
function RuneWindow:OnCloseWindow()
2025-08-14 19:28:30 +08:00
UIWindow.OnCloseWindow(self)
end
2025-08-15 00:45:18 +08:00
return RuneWindow