76 lines
2.3 KiB
Plaintext
76 lines
2.3 KiB
Plaintext
local WearingShow = {}
|
|
WearingShow.__index = WearingShow
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
local Utils = require(ReplicatedStorage.Tools.Utils)
|
|
local Localization = require(ReplicatedStorage.Tools.Localization)
|
|
local JsonRune = require(ReplicatedStorage.Json.Rune)
|
|
local JsonItemProp = require(ReplicatedStorage.Json.ItemProp)
|
|
|
|
function WearingShow:Init(data: table)
|
|
local self = {}
|
|
self.Data = data
|
|
self.Variables = {
|
|
["_btnClick"] = 0,
|
|
["_imgIcon"] = 0,
|
|
["_tmpName"] = 0,
|
|
["_imgView"] = 0,
|
|
}
|
|
self.Connections = {}
|
|
|
|
setmetatable(self, WearingShow)
|
|
|
|
return self
|
|
end
|
|
|
|
function WearingShow:Refresh()
|
|
if self.Data then
|
|
local itemData = Utils:GetIdDataFromJson(JsonItemProp, self.Data.orgId)
|
|
local runeData = Utils:GetIdDataFromJson(JsonRune, self.Data.orgId)
|
|
|
|
self.Variables._imgIcon.Image = Localization:GetImageData(runeData.icon)
|
|
self.Variables._imgIcon.BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality)
|
|
self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId)
|
|
self.Variables._imgIcon.Visible = true
|
|
else
|
|
self.Variables._imgIcon.Image = ""
|
|
self.Variables._tmpName.Text = ""
|
|
self.Variables._imgIcon.Visible = false
|
|
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)
|
|
|
|
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
|
|
end
|
|
|
|
function WearingShow:Destroy()
|
|
for k, v in pairs(self) do
|
|
self[k] = nil
|
|
end
|
|
self = nil
|
|
end
|
|
|
|
return WearingShow |