-
Notifications
You must be signed in to change notification settings - Fork 3
/
LootDroppable.lua
174 lines (145 loc) · 4.64 KB
/
LootDroppable.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
------------------------------------------------
-- Loot Drop - show me what I got
--
-- @classmod LootDroppable
-- @author Pawkette ( [email protected] )
------------------------------------------------
LootDroppable = ZO_Object:Subclass()
local LMP = LibStub( 'LibMediaProvider-1.0' )
if ( not LMP ) then return end
--- Create a new instance of a LootDroppable
-- @treturn LootDroppable
function LootDroppable:New( ... )
local result = ZO_Object.New( self )
result:Initialize( ... )
return result
end
--- Constructor
--
function LootDroppable:Initialize( objectPool )
self.pool = objectPool
self.db = objectPool.db
self.control = CreateControlFromVirtual( 'LootDroppable', objectPool:GetControl(), 'LootDroppable', objectPool:GetNextId() )
self.label = self.control:GetNamedChild( '_Name' )
self.icon = self.control:GetNamedChild( '_Icon' )
self.border = self.control:GetNamedChild( '_Rarity' )
self.bg = self.control:GetNamedChild( '_BG' )
if ( self.label ) then
if ( self.db.font.face == '' ) then
self.label:SetFont( ZoFontGame )
else
local path = LMP:Fetch( LMP.MediaType.FONT, self.db.font.face )
local fmt = '%s|%d'
if ( self.db.font.decoration ~= 'none' ) then
fmt = fmt .. '|%s'
end
self.label:SetFont( fmt:format( path, self.db.font.size, self.db.font.deco or '' ) )
end
end
end
--- Visibility Getter
-- @treturn boolean
function LootDroppable:IsVisible()
return self.control:GetAlpha() > 0
end
--- Show this droppable
-- @tparam number y
function LootDroppable:Show( y )
self.enter_animation:Play()
local current_x, current_y = self:GetOffsets()
self.move_animation = self.pool._slide:Apply( self.control, current_x, current_y, 0, y )
self.move_animation:Play()
end
function LootDroppable:Hide()
if ( self.exit_animation ) then
self.exit_animation:InsertCallback( function( ... ) self:Reset() end, 200 )
self.exit_animation:Play()
else
self.control:SetAlpha( 0.0 )
self:Reset()
end
end
--- Ready this droppable to show
function LootDroppable:Prepare()
self:SetAnchor( BOTTOMRIGHT, self.pool:GetControl(), BOTTOMRIGHT, self.db.width, ( #self.pool._active - 1 ) * ( ( self.db.height + self.db.padding ) * -1 ) )
self.control:SetWidth( self.db.width )
self.control:SetHeight( self.db.height )
self.icon:SetWidth( self.db.height )
self.enter_animation = self.pool._fadeIn:Apply( self.control )
self.exit_animation = self.pool._fadeOut:Apply( self.control )
self.move_animation = nil
self.control:SetAlpha( 0 )
self.label:SetText( '' )
self.icon:SetTexture( '' )
self.timestamp = 0
end
--- Reset this droppable
function LootDroppable:Reset()
self.enter_animation = nil
self.exit_animation = nil
self.move_animation = nil
self.label:SetText( '' )
self.icon:SetHidden( true )
self.timestamp = 0
end
--- Control getter
-- @treturn table
function LootDroppable:GetControl()
return self.control
end
--- Set show timestamp
-- @tparam number stamp
function LootDroppable:SetTimestamp( stamp )
self.timestamp = stamp
end
--- Get show timestamp
-- @treturn number
function LootDroppable:GetTimestamp()
return self.timestamp
end
--- Set label
-- @tparam string label
function LootDroppable:SetLabel( label )
self.label:SetText( label )
end
--- Set rarity border
-- @tparam ZO_ColorDef color
function LootDroppable:SetRarity( color )
if ( not color ) then
color = ZO_ColorDef:New( 1, 1, 1, 1 )
end
self.border:SetColor( color:UnpackRGBA() )
end
function LootDroppable:GetLabel()
return tonumber( self.label:GetText() or 0 )
end
--- Set Icon
-- @tparam string icon
function LootDroppable:SetIcon( icon, coords )
local texture = self.icon:GetTextureFileName()
if ( texture ~= icon ) then
self.icon:SetTexture( icon )
end
if ( coords ) then
self.icon:SetTextureCoords( unpack( coords ) )
else
self.icon:SetTextureCoords( 0, 1, 0, 1 )
end
self.icon:SetHidden( false )
end
--- Pass anchor information to control
function LootDroppable:SetAnchor( ... )
self.control:SetAnchor( ... )
end
--- Pass translate information to animation
function LootDroppable:Move( x, y )
local current_x, current_y = self:GetOffsets()
self.move_animation = self.pool._slide:Apply( self.control, current_x, current_y, x, y )
self.move_animation:Play()
end
--- Get current y offset
-- @treturn number
function LootDroppable:GetOffsets()
local _, _, _, _, offsX, offsY = self.control:GetAnchor( 0 )
return offsX, offsY
end