-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransmogRoulette.xml
384 lines (365 loc) · 14.4 KB
/
TransmogRoulette.xml
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<Ui>
<CheckButton name='TransmogRouletteIgnoreButtonTemplate' virtual='true' frameLevel='100'>
<Size x='24' y='24' />
<HitRectInsets left='0' right='0' top='0' bottom='0' />
<NormalTexture file='Interface/Buttons/UI-GroupLoot-Dice-Up'/>
<PushedTexture file='Interface/Buttons/UI-GroupLoot-Dice-Down'/>
<HighlightTexture file='Interface/Buttons/UI-GroupLoot-Dice-Highlight' alphaMode='ADD' alpha='0.5' />
<CheckedTexture file='Interface/Transmogrify/Textures.png' desaturated='false'>
<TexCoords left='0.2890625' right='0.5546875' top='0.51171875' bottom='0.578125'/>
</CheckedTexture>
<Scripts>
<OnLoad>
-- not sure why registerForClicks='ANYUP' xml attribute isn't working for this
self:RegisterForClicks('ANYUP')
</OnLoad>
<OnMouseDown>
if button == 'LeftButton' and not IsModifierKeyDown() then
-- start rolling
TransmogRouletteButton:StartRolling(self.slotID)
self.rolling = true
-- else set checkbox, but that's automatically handled
end
GameTooltip_Hide()
</OnMouseDown>
<OnMouseUp>
if self.rolling then
TransmogRouletteButton:StopRolling()
self.rolling = false
if MouseIsOver(self) then -- it only gets checked if the mouse is released on top of it
self:SetChecked(not self:GetChecked())
end
end
</OnMouseUp>
<OnEnter>
if self.rolling then return end -- mouse left and returned while holding down the button
GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
GameTooltip:AddLine('TransmogRoulette', 1, 0.5, 0)
GameTooltip:AddLine('Left-click to randomize only this slot')
GameTooltip:AddLine('Shift or right-click to exclude this slot from randomization')
GameTooltip:Show()
</OnEnter>
<OnLeave function='GameTooltip_Hide' />
</Scripts>
</CheckButton>
<Button name='TransmogRouletteOutfitButton' parent='WardrobeOutfitDropDown' frameLevel='100'>
<Size x='20' y='20' />
<NormalTexture file='Interface/Buttons/UI-GroupLoot-Dice-Up'/>
<PushedTexture file='Interface/Buttons/UI-GroupLoot-Dice-Down'/>
<HighlightTexture file='Interface/Buttons/UI-GroupLoot-Dice-Highlight' alphaMode='ADD' alpha='0.5' />
<Anchors>
<!-- Anchor point='TOPLEFT' relativePoint='BOTTOMRIGHT' x='-28' y='4' / -->
<Anchor point='RIGHT' relativePoint='LEFT' relativeTo='WardrobeOutfitDropDownButton' x='-2' y='-2' />
</Anchors>
<Scripts>
<OnMouseDown>
self.rolling = true
TransmogRouletteButton:StartRolling(0)
GameTooltip_Hide()
</OnMouseDown>
<OnMouseUp>
if self.rolling then
TransmogRouletteButton:StopRolling()
self.rolling = false
end
</OnMouseUp>
<OnEnter>
if self.rolling then return end
GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
GameTooltip:AddLine('TransmogRoulette', 1, 0.5, 0)
GameTooltip:AddLine('Choose a random outfit')
GameTooltip:Show()
</OnEnter>
<OnLeave function='GameTooltip_Hide' />
</Scripts>
</Button>
<Button name='TransmogRouletteButton' parent='WardrobeTransmogFrame' frameLevel='100'>
<Size x='32' y='32' />
<Anchors>
<Anchor point='BOTTOMRIGHT' x='-8' y='6' />
</Anchors>
<NormalTexture parentKey='icon' file='interface/icons/ability_rogue_rollthebones' horizTile='false' vertTile='false'/>
<Frames>
<Frame parentKey='border' setAllPoints='true'>
<Layers>
<Layer level='ARTWORK'>
<Texture parentKey='glow' file='Interface/Transmogrify/Textures.png' desaturated='true'>
<Size x='58' y='57' />
<Anchors>
<Anchor point='CENTER'/>
</Anchors>
<TexCoords left='0.5234375' right='0.9765625' top='0.38476563' bottom='0.49609375'/>
<Color r='1' g='0.3' b='0' />
</Texture>
</Layer>
<Layer level='OVERLAY'>
<Texture parentKey='ants' file='Interface/Transmogrify/PurpleIconAlertAnts.png' desaturated='true'>
<Size x='44' y='44' />
<Anchors>
<Anchor point='CENTER' />
</Anchors>
<Color r='1' g='0.3' b='0' />
</Texture>
</Layer>
</Layers>
<Scripts>
<OnLoad>
self.throttle = 0.03
</OnLoad>
<OnUpdate>
AnimateTexCoords(self.ants, 256, 256, 48, 48, 22, elapsed, self.throttle)
</OnUpdate>
</Scripts>
</Frame>
</Frames>
<Scripts>
<OnShow>
C_Timer.After(0, function() -- inexplicibly required for C_TransmogCollection.GetCategoryAppearances() to return data for whatever category is actively selected when the frame is shown
-- probably an issue with the filter?
-- todo: figure out why this is happening for a real fix
local FilteredList = self.FilteredList
wipe(FilteredList)
for i, slotInfo in pairs(TRANSMOG_SLOTS) do
local slot = slotInfo.location:GetSlotName()
if slot then
local slotID = GetInventorySlotInfo(slot)
if not FilteredList[ slotID ] then
FilteredList[ slotID ] = {}
end
local isTransmogrified, hasPending, isPendingCollected, canTransmogrify, cannotTransmogrifyReason, hasUndo, isHideVisual, texture = C_Transmog.GetSlotInfo(slotInfo.location, Enum.TransmogType.Appearance)
if canTransmogrify or cannotTransmogrifyReason == 0 then
local categoryID = slotInfo.armorCategoryID
if categoryID then
for i, v in ipairs(C_TransmogCollection.GetCategoryAppearances(categoryID)) do
if v.isUsable and v.isCollected then
tinsert(FilteredList[ slotID ], {visualID=v.visualID, categoryID=categoryID})
end
end
else
-- This is mostly a hack for feral druid's dual daggers, because C_TransmogCollection.GetCategoryInfo claims you can't transmog anything to your offhand slot
-- It could probably replace the code block above this
local baseSourceID, baseVisualID, appliedSourceID, appliedVisualID, pendingSourceID, pendingVisualID, hasPendingUndo = C_Transmog.GetSlotVisualInfo(slotInfo.location, Enum.TransmogType.Appearance)
local baseCategoryID = C_TransmogCollection.GetAppearanceSourceInfo(baseSourceID) -- we can always transmog an item into its own category?
if baseCategoryID then
for i, v in ipairs(C_TransmogCollection.GetCategoryAppearances(baseCategoryID)) do
if v.isUsable and v.isCollected then
tinsert(FilteredList[ slotID ], {visualID=v.visualID, categoryID=baseCategoryID})
end
end
end
--[[ FIXME: Figure out how to get the correct categoryID for visualID 27492 (should be 29/Artifact, we get 23/Staves)
for categoryID = FIRST_TRANSMOG_COLLECTION_WEAPON_TYPE, LAST_TRANSMOG_COLLECTION_WEAPON_TYPE do
local name, isWeapon, canEnchant, canMainHand, canOffHand = C_TransmogCollection.GetCategoryInfo(categoryID);
if name and isWeapon and categoryID ~= baseCategoryID then
if (slot == 'MAINHANDSLOT' and canMainHand) or (slot == 'SECONDARYHANDSLOT' and canOffHand) then
-- make sure we can actually transmog our weapon into this category
local equippedItemID = GetInventoryItemID('player', GetInventorySlotInfo(slot))
if C_TransmogCollection.IsCategoryValidForItem(categoryID, equippedItemID) then
for i, v in ipairs(C_TransmogCollection.GetCategoryAppearances(categoryID)) do
if v.isUsable and v.isCollected then
--if v.visualID == 27492 then
--print(v.visualID, baseCategoryID, categoryID)
--end
--tinsert(FilteredList[ slotID ], {visualID=v.visualID, categoryID=categoryID})
end
end
end
end
end
end
--]]
end
end
end
end
end)
</OnShow>
<OnLoad>
self.FilteredList = {}
-- todo: maybe store these in sv
local IgnoreButtons = {}
for _, button in pairs(WardrobeTransmogFrame.SlotButtons) do
if button ~= WardrobeTransmogFrame.ModelScene.MainHandEnchantButton -- skip illusion buttons
and button ~= WardrobeTransmogFrame.ModelScene.SecondaryHandEnchantButton then
local f = CreateFrame('CheckButton', nil, button, 'TransmogRouletteIgnoreButtonTemplate')
f:SetPoint('BOTTOMRIGHT', 5, -5)
f.slot = button.slot
local slotID = GetInventorySlotInfo(button.slot)
f.slotID = slotID
IgnoreButtons[ slotID ] = f
if button == WardrobeTransmogFrame.ModelScene.ShirtButton -- ignore shirt and tabard by default
or button == WardrobeTransmogFrame.ModelScene.TabardButton then
f:SetChecked(true)
end
end
end
local function RandomizeSlot(slotID)
local visuals = self.FilteredList[ slotID ]
if not visuals then return end
-- todo: store the sourceIDs directly in the filtered list instead of appearances
local numVisuals = #visuals
if numVisuals > 0 then
local appearance = visuals[ random(numVisuals) ]
local appearanceID = appearance.visualID
local categoryID = appearance.categoryID
local sources = C_TransmogCollection.GetAppearanceSources(appearanceID, categoryID)
if sources then
for i, source in pairs(sources) do
if source.isCollected then
local sourceID = source.sourceID
--C_Transmog.ClearPending(slotID, Enum.TransmogType.Appearance)
local transmogLocation = TransmogUtil.GetTransmogLocation(slotID, Enum.TransmogType.Appearance, Enum.TransmogModification.Main)
local pendingInfo = TransmogUtil.CreateTransmogPendingInfo(Enum.TransmogPendingType.Apply, sourceID)
C_Transmog.SetPending(transmogLocation, pendingInfo)
break
end
end
end
end
end
self.RandomizeSlot = RandomizeSlot
local function RandomizeAllSlots()
for slotID, visuals in pairs(self.FilteredList) do
if not IgnoreButtons[ slotID ]
or not IgnoreButtons[ slotID ]:GetChecked() then
RandomizeSlot(slotID)
end
end
end
local Released = false
local DefaultSpinThrottle = 0.1
local SpinThrottle = DefaultSpinThrottle
local TimeSince = 0
local RandomizedSlot -- specific slot to randomize
local function RandomizeSlotOnUpdate(self, elapsed)
TimeSince = TimeSince + elapsed
if TimeSince >= SpinThrottle then
RandomizeSlot(RandomizedSlot)
if Released then
SpinThrottle = SpinThrottle * 1.3
if SpinThrottle >= 0.3 then
self:SetScript('OnUpdate', nil)
end
end
TimeSince = 0
end
end
local function RandomizeAllOnUpdate(self, elapsed)
TimeSince = TimeSince + elapsed
if TimeSince >= SpinThrottle then
RandomizeAllSlots()
if Released then
SpinThrottle = SpinThrottle * 1.3
if SpinThrottle >= 0.3 then
self:SetScript('OnUpdate', nil)
end
end
TimeSince = 0
end
end
-- Outfit stuff
-- I should probably put this stuff in a lua file at some point
local function RandomNot(min, max, n)
-- return a number between min and max that isn't "n"
--if not n then return random(min, max) end
if min >= max then return min end
local num = random(min + 1, max)
return num == n and min or num
end
-- local LastOutfit -- store previous outfit rather than testing for the current outfit every time
local CollectedOutfits = {}
local function GetOutfits()
-- outfits are NOT guaranteed to be a sequential list
-- eg. if you make 2 outfits and delete the first one, your list will start from 1 instead of 0; it can have holes in it
wipe(CollectedOutfits)
local prevSelection = WardrobeOutfitDropDown.selectedOutfitID
local outfits = C_TransmogCollection.GetOutfits()
for _, outfit in pairs(outfits) do
if outfit.collected then -- assuming it's not "collected" if you're missing an appearance from it, I don't know if I should ignore these or not
tinsert(CollectedOutfits, outfit.outfitID)
end
end
-- Get index of current outfit ID in our filtered list
for i, outfitID in ipairs(CollectedOutfits) do
WardrobeOutfitDropDown.selectedOutfitID = outfitID
if WardrobeOutfitDropDown:IsOutfitDressed() then -- returns TRUE for invalid outfitIDs, this is important
WardrobeOutfitDropDown.selectedOutfitID = prevSelection
--LastOutfit = i
return CollectedOutfits, i, outfitID --outfitID
end
end
WardrobeOutfitDropDown.selectedOutfitID = prevSelection
return CollectedOutfits
end
local function EquipRandomOutfit()
local outfits, currentOutfit = GetOutfits()
local numOutfits = #outfits
if numOutfits > 1 then
local randomOutfitID
if currentOutfit then
randomOutfitID = outfits[ RandomNot(1, numOutfits, currentOutfit) ]
else
randomOutfitID = outfits[ random(numOutfits) ]
end
WardrobeOutfitDropDown:SelectOutfit(randomOutfitID, true)
elseif numOutfits == 1 then
WardrobeOutfitDropDown:SelectOutfit(outfits[1], true)
end
end
local function RandomizeOutfitOnUpdate(self, elapsed)
TimeSince = TimeSince + elapsed
if TimeSince >= SpinThrottle then
EquipRandomOutfit()
if Released then
SpinThrottle = SpinThrottle * 1.3
if SpinThrottle >= 0.3 then
self:SetScript('OnUpdate', nil)
end
end
TimeSince = 0
end
end
function self:StartRolling(slotID)
TimeSince = 0
SpinThrottle = DefaultSpinThrottle
Released = false
if slotID then
if slotID == 0 then -- outfit (probably not the best way to do this)
--LastOutfit = nil
EquipRandomOutfit()
self:SetScript('OnUpdate', RandomizeOutfitOnUpdate)
else
RandomizedSlot = slotID
RandomizeSlot(slotID)
self:SetScript('OnUpdate', RandomizeSlotOnUpdate)
end
else
RandomizeAllSlots()
self:SetScript('OnUpdate', RandomizeAllOnUpdate)
end
end
function self:StopRolling()
Released = true
end
</OnLoad>
<OnHide>
-- In case this is still doing something for some reason, stop it
self:SetScript('OnUpdate', nil)
</OnHide>
<OnMouseDown>
self.icon:SetTexCoord(-0.03, 0.97, -0.03, 0.97)
self.border.throttle = 0.005
self.border.glow:SetVertexColor(1, 0, 0)
self.border.ants:SetVertexColor(1, 0, 0)
self:StartRolling()
</OnMouseDown>
<OnMouseUp>
self.icon:SetTexCoord(0, 1, 0, 1)
self.border.throttle = 0.03
self.border.glow:SetVertexColor(1, 0.3, 0)
self.border.ants:SetVertexColor(1, 0.3, 0)
self:StopRolling()
</OnMouseUp>
</Scripts>
</Button>
</Ui>