2025-07-22 01:56:56 +08:00
|
|
|
local WearingShow = {}
|
|
|
|
WearingShow.__index = WearingShow
|
|
|
|
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
|
|
|
|
local Utils = require(ReplicatedStorage.Tools.Utils)
|
|
|
|
local Localization = require(ReplicatedStorage.Tools.Localization)
|
|
|
|
local JsonEquipment = require(ReplicatedStorage.Json.Equipment)
|
|
|
|
local JsonItemProp = require(ReplicatedStorage.Json.ItemProp)
|
|
|
|
|
2025-08-03 23:58:55 +08:00
|
|
|
local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments")
|
|
|
|
|
2025-07-22 01:56:56 +08:00
|
|
|
function WearingShow:Init(data: table)
|
|
|
|
local self = {}
|
|
|
|
self.Data = data
|
|
|
|
self.Variables = {
|
|
|
|
["_btnClick"] = 0,
|
2025-08-03 23:58:55 +08:00
|
|
|
["_imgBg"] = 0,
|
2025-07-22 01:56:56 +08:00
|
|
|
["_imgIcon"] = 0,
|
|
|
|
["_tmpQuality"] = 0,
|
2025-08-03 23:58:55 +08:00
|
|
|
["_tmpName"] = 0,
|
|
|
|
["_imgView"] = 0,
|
2025-07-22 01:56:56 +08:00
|
|
|
}
|
|
|
|
self.Connections = {}
|
|
|
|
|
|
|
|
setmetatable(self, WearingShow)
|
|
|
|
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
function WearingShow:Refresh()
|
|
|
|
-- 槽位为空
|
|
|
|
if self.Data.id == nil then
|
|
|
|
self.Variables._imgIcon.Image = ""
|
2025-08-03 23:58:55 +08:00
|
|
|
self.Variables._imgBg.Visible = true
|
2025-07-22 01:56:56 +08:00
|
|
|
self.Variables._tmpQuality.Text = ""
|
2025-08-03 23:58:55 +08:00
|
|
|
self.Variables._tmpName.Text = ""
|
2025-07-22 01:56:56 +08:00
|
|
|
else
|
|
|
|
-- 槽位有装备
|
|
|
|
local itemData = Utils:GetIdDataFromJson(JsonItemProp, self.Data.orgId)
|
|
|
|
self.Variables._imgIcon.Image = Localization:GetImageData(itemData.iconId)
|
2025-08-03 23:58:55 +08:00
|
|
|
self.Variables._imgBg.Visible = false
|
|
|
|
self.Variables._tmpQuality.Text = Localization:GetColoredEquipmentQualityDesc(self.Data.quality)
|
|
|
|
self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId)
|
|
|
|
|
|
|
|
|
|
|
|
local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, self.Data.orgId)
|
|
|
|
-- 模型
|
|
|
|
local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone()
|
|
|
|
part.Handle.Position = Vector3.new(0, 0, 0)
|
|
|
|
part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0)
|
|
|
|
part.Parent = self.Variables["_imgView"]
|
|
|
|
self.Prefab = part
|
|
|
|
|
|
|
|
-- 相机
|
|
|
|
local viewportCamera = Instance.new("Camera")
|
|
|
|
self.Variables["_imgView"].CurrentCamera = viewportCamera
|
|
|
|
viewportCamera.Parent = self.Variables["_imgView"]
|
|
|
|
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position)
|
|
|
|
self.ViewCamera = viewportCamera
|
2025-07-22 01:56:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function WearingShow:OnInitFinish()
|
|
|
|
local con = self.Variables._btnClick.MouseButton1Click:Connect(function()
|
|
|
|
if self.Data == {} then
|
|
|
|
-- TODO: 之后做提示弹窗
|
|
|
|
else
|
|
|
|
self.TopUI:ShowDetailData(self.Data.id)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
table.insert(self.Connections, con)
|
2025-07-23 01:04:27 +08:00
|
|
|
|
|
|
|
if self.Data.instance then
|
|
|
|
local wearingCon = self.Data.instance:GetAttributeChangedSignal("wearing"):Connect(function()
|
|
|
|
local oldWearing = self.Data.wearing
|
|
|
|
local newWearing = self.Data.instance:GetAttribute("wearing")
|
|
|
|
if oldWearing ~= newWearing then
|
|
|
|
if newWearing > 0 then
|
|
|
|
self.TopUI:WearRefresh(self.Data)
|
|
|
|
else
|
|
|
|
self.TopUI:UnwearRefresh(self.Data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
table.insert(self.Connections, wearingCon)
|
|
|
|
end
|
2025-07-22 01:56:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function WearingShow:Destroy()
|
|
|
|
for k, v in pairs(self) do
|
|
|
|
self[k] = nil
|
|
|
|
end
|
|
|
|
self = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return WearingShow
|