Skip to content

Commit

Permalink
feat: 装备列表
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 4, 2024
1 parent f00a9ce commit 91d2f2c
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Core/Inspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ function Inspect:SetUnit(unit, name)
end
end

function Inspect:GetUnit()
return self.unit, self.unitName
end

function Inspect:GetUnitName()
if self.unit then
return ns.UnitName(self.unit)
Expand Down
1 change: 1 addition & 0 deletions Load.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Script file="Tooltip\FixMetaGem.lua" />
<Script file="Tooltip\FixRune.lua" />

<Include file="UI\Template.xml" />
<Script file="UI\SocketItem.lua" />
<Script file="UI\BaseItem.lua" />
<Script file="UI\SlotItem.lua" />
Expand Down
55 changes: 33 additions & 22 deletions UI/GearFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
---@class ns
local ns = select(2, ...)

local L = ns.L

local EQUIP_SLOTS = {
{id = 1, name = HEADSLOT}, --
{id = 2, name = NECKSLOT}, --
Expand Down Expand Up @@ -34,21 +36,10 @@ local PADDING = 10
local GearFrame = ns.Addon:NewClass('UI.GearFrame', 'Frame')

function GearFrame:Create(parent)
return self:Bind(CreateFrame('Frame', nil, parent, 'BackdropTemplate'))
return self:Bind(CreateFrame('Frame', nil, parent, 'tdInspectGearFrameTemplate'))
end

function GearFrame:Constructor()
self:SetHeight(424)
self:SetBackdrop{
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
tile = true,
tileSize = 8,
edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
}
self:SetBackdropColor(0, 0, 0, 0.95)

local SlotColumn = CreateFrame('Frame', nil, self)
SlotColumn:SetPoint('TOPLEFT', PADDING, 0)
SlotColumn:SetHeight(1)
Expand All @@ -59,16 +50,6 @@ function GearFrame:Constructor()
LevelColumn:SetHeight(1)
self.LevelColumn = LevelColumn

local Title = self:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLargeOutline')
Title:SetPoint('TOPLEFT', 66, -18)
self.Title = Title

local ItemLevel = self:CreateFontString(nil, 'ARTWORK', 'ChatFontNormal')
ItemLevel:SetPoint('TOPLEFT', 66, -42)
ItemLevel:SetFont(ItemLevel:GetFont(), 12, 'THINOUTLINE')
ItemLevel:SetTextColor(NORMAL_FONT_COLOR:GetRGB())
self.ItemLevel = ItemLevel

self.gears = {}
self.columnWidths = {}

Expand Down Expand Up @@ -113,3 +94,33 @@ end
function GearFrame:EndLayout()
self:RequestUpdateSize()
end

function GearFrame:SetClass(class)
self.class = class

local color = RAID_CLASS_COLORS[class]
self.Name:SetTextColor(color.r, color.g, color.b)
self:SetBackdropBorderColor(color.r, color.g, color.b)
self.Portrait.PortraitRingQuality:SetVertexColor(color.r, color.g, color.b)
self.Portrait.LevelBorder:SetVertexColor(color.r, color.g, color.b)
end

function GearFrame:SetUnit(unit, name)
self.unit, self.name = unit, name

self.Name:SetText(Ambiguate(name or ns.UnitName(unit), 'none'))

if unit then
SetPortraitTexture(self.Portrait.Portrait, unit)
else
-- self.Portrait.Portrait:SetTexture([[Interface\CharacterFrame\TempPortrait]])
end
end

function GearFrame:SetItemLevel(level)
self.ItemLevel:SetFormattedText('%s %.1f', L['iLvl:'], level or 0)
end

function GearFrame:SetLevel(level)
self.Portrait.Level:SetText(level or '')
end
34 changes: 20 additions & 14 deletions UI/InspectGearFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,37 @@ local ns = select(2, ...)
local L = ns.L
local Inspect = ns.Inspect

---@class UI.InspectGearFrame : UI.GearFrame
---@class UI.InspectGearFrame : UI.GearFrame, Frame
local InspectGearFrame = ns.Addon:NewClass('UI.InspectGearFrame', ns.UI.GearFrame)

function InspectGearFrame:Constructor()
self:SetScript('OnShow', self.OnShow)
self:SetScript('OnHide', self.UnregisterAllMessages)
self:SetScript('OnHide', self.OnHide)

-- @debug@
local DataSource = self:CreateFontString(nil, 'ARTWORK', 'GameFontNormalSmall')
DataSource:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 10, 0)
DataSource:SetFont(DataSource:GetFont(), 12, 'OUTLINE')
self.DataSource = DataSource
-- @end-debug@
end

function InspectGearFrame:OnShow()
self:RegisterMessage('INSPECT_READY', 'Update')
self:RegisterEvent('UNIT_LEVEL', 'Update')
self:RegisterEvent('UNIT_INVENTORY_CHANGED')
self:Update()
end

function InspectGearFrame:OnHide()
self:UnregisterAllEvents()
self:UnregisterAllMessages()
end

function InspectGearFrame:UNIT_INVENTORY_CHANGED(_, unit)
if self.unit == unit then
self:Update()
end
end

function InspectGearFrame:Update()
self:StartLayout()

Expand All @@ -37,20 +48,15 @@ function InspectGearFrame:Update()
end

local classFileName = Inspect:GetUnitClassFileName()
local classColor = RAID_CLASS_COLORS[classFileName]

self.ItemLevel:SetFormattedText('%s %.1f', L['iLvl:'], Inspect:GetItemLevel() or 0)
self.Title:SetTextColor(classColor.r, classColor.g, classColor.b)
self.Title:SetText(Ambiguate(Inspect:GetUnitName(), 'none'))

self:SetBackdropBorderColor(classColor.r, classColor.g, classColor.b)

-- @debug@
local dataSource = Inspect:GetDataSource()
local lastUpdate = Inspect:GetLastUpdate()

self:SetClass(classFileName)
self:SetUnit(Inspect:GetUnit())
self:SetLevel(Inspect:GetUnitLevel())
self:SetItemLevel(Inspect:GetItemLevel())
self.DataSource:SetFormattedText('%s|cffffffff%s|r %s|cffffffff%s|r', L['Data source:'], dataSource,
L['Last update:'], FriendsFrame_GetLastOnline(lastUpdate))
-- @end-debug@

self:EndLayout()
end
87 changes: 87 additions & 0 deletions UI/Template.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Frame name="tdInspectPortraitTemplate" scale="0.8" virtual="true">
<Size x="52" y="60"/>
<Layers>
<Layer level="BORDER">
<Texture parentKey="PortraitRing" atlas="GarrMission_PortraitRing" useAtlasSize="true">
<Anchors>
<Anchor point="TOP"/>
</Anchors>
</Texture>
</Layer>
<Layer level="BORDER" textureSubLevel="-1">
<Texture parentKey="Portrait">
<Size x="44" y="44"/>
<Anchors>
<Anchor point="CENTER" relativeKey="$parent.PortraitRing" y="5"/>
</Anchors>
</Texture>
</Layer>
<Layer level="BORDER" textureSubLevel="1">
<Texture parentKey="PortraitRingQuality" atlas="GarrMission_PortraitRing_Quality" useAtlasSize="true">
<Anchors>
<Anchor point="TOP"/>
</Anchors>
</Texture>
</Layer>
<Layer level="BORDER" textureSubLevel="2">
<Texture parentKey="LevelBorder" atlas="GarrMission_PortraitRing_LevelBorder" useAtlasSize="true">
<Anchors>
<Anchor point="BOTTOM" y="-3"/>
</Anchors>
</Texture>
</Layer>
<Layer level="ARTWORK">
<FontString parentKey="Level" inherits="GameFontHighlightSmall" justifyH="CENTER" text="95">
<Anchors>
<Anchor point="CENTER" relativeKey="$parent.LevelBorder"/>
</Anchors>
</FontString>
</Layer>
<Layer level="OVERLAY">
<Texture parentKey="PortraitRingCover" atlas="GarrMission_PortraitRing_Darkener" useAtlasSize="true" hidden="true" alpha="0.6">
<Anchors>
<Anchor point="TOP" x="0" y="-1"/>
</Anchors>
</Texture>
</Layer>
</Layers>
</Frame>

<Frame name="tdInspectGearFrameTemplate" inherits="BackdropTemplate" enableMouse="true" virtual="true">
<Size x="200" y="424"/>
<Frames>
<Frame parentKey="Portrait" inherits="tdInspectPortraitTemplate">
<Anchors>
<Anchor point="TOPLEFT" x="18" y="-16"/>
</Anchors>
</Frame>
</Frames>
<Layers>
<Layer level="ARTWORK">
<FontString parentKey="Name" inherits="GameFontNormalLargeOutline" justifyH="LEFT">
<Anchors>
<Anchor point="TOPLEFT" x="66" y="-18"/>
</Anchors>
</FontString>
<FontString parentKey="ItemLevel" height="12" outline="NORMAL" inherits="Tooltip_Small">
<Color r="1.0" g="0.82" b="0"/>
<Anchors>
<Anchor point="TOPLEFT" x="66" y="-42"/>
</Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnLoad>
self:SetBackdrop{
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
tile = true,
tileSize = 8,
edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
}
self:SetBackdropColor(0, 0, 0, 0.95)
</OnLoad>
</Scripts>
</Frame>
</Ui>

0 comments on commit 91d2f2c

Please sign in to comment.