-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlaceholder.lua
More file actions
executable file
·139 lines (116 loc) · 5.12 KB
/
Placeholder.lua
File metadata and controls
executable file
·139 lines (116 loc) · 5.12 KB
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
-- Placeholder class
-- a special macro that holds onto the action bar button slot for the Germ
-------------------------------------------------------------------------------
-- Module Loading
-------------------------------------------------------------------------------
---@type Ufo
local ADDON_NAME, Ufo = ...
Ufo.Wormhole() -- Lua voodoo magic that replaces the current Global namespace with the Ufo object
local zebug = Zebug:new(Z_VOLUME_GLOBAL_OVERRIDE or Zebug.TRACE)
---@class Placeholder
Placeholder = {
ufoType = "Placeholder",
}
UfoMixIn:mixInto(Placeholder)
-------------------------------------------------------------------------------
-- Methods
-------------------------------------------------------------------------------
function Placeholder:createIfNotExists(event)
local exists = GetMacroInfo(PLACEHOLDER_MACRO_NAME)
if not exists then
local icon = Ufo.iconTexture
zebug.info:event(event):print("name",PLACEHOLDER_MACRO_NAME, "icon",icon, "PLACEHOLDER_MACRO_TEXT", PLACEHOLDER_MACRO_TEXT)
Ufo.thatWasMeThatDidThatMacro = event
CreateMacro(PLACEHOLDER_MACRO_NAME, icon, PLACEHOLDER_MACRO_TEXT)
else
zebug.info:event(event):print("placeholder exists",PLACEHOLDER_MACRO_NAME)
end
end
function Placeholder:pickup(event)
self:createIfNotExists(event)
Ufo.myPlaceholderSoDoNotDelete = event
zebug.info:event(event):owner(self):print("grabbers")
Cursor:pickupMacro(PLACEHOLDER_MACRO_NAME, event)
end
---@param btnSlotIndex number
---@param event string|Event custom UFO metadata describing the instigating event - good for debugging
---@return ButtonDef whatever was on btnSlotIndex before it got clobbered by the Placeholder
function Placeholder:put(btnSlotIndex, event)
if not Config.opts.usePlaceHolders then return end
local theBtnAlready = BlizActionBarButtonHelper:get(btnSlotIndex, event)
if self:isOn(theBtnAlready, event) then return end
Ufo.droppedPlaceholderOntoActionBar = event or true
-- preserve the current contents of the cursor
local thingWasOnCursor = ButtonDef:getFromCursor(event, "silence")
-- clobber anything on the cursor and replace it with the placeholder
self:pickup(event)
zebug.trace:event(event):print("btnSlotIndex",btnSlotIndex)
Cursor:dropOntoActionBar(btnSlotIndex, event)
-- yes? we're synchronous, yes?
-- Ufo.droppedPlaceholderOntoActionBar = nil
local nowCursor = ButtonDef:getFromCursor(event, "silence")
-- restore anything that had originally been on the cursor
if thingWasOnCursor then
zebug.info:event(event):print("restoring original cursor to", thingWasOnCursor, "which replaces nowCursor",nowCursor)
thingWasOnCursor:pickupToCursor(event)
nowCursor = thingWasOnCursor
else
zebug.info:event(event):mark(Mark.FIRE):print("NOTHING was originally on the cursor to", thingWasOnCursor, "and it's currently nowCursor",nowCursor)
end
return nowCursor
end
function Placeholder:clear(btnSlotIndex, event)
--if not Config.opts.usePlaceHolders then return end
if not Placeholder:isOnBtnSlot(btnSlotIndex, event) then return end
Cursor:pickupFromActionBar(btnSlotIndex, event)
Cursor:clear(event)
end
function Placeholder:isOnBtnSlot(btnSlotIndex, event)
local type, id = GetActionInfo(btnSlotIndex)
zebug.trace:event(event):print("btnSlotIndex",btnSlotIndex, "type",type, "id",id)
if type == ButtonType.MACRO then
local name = GetMacroInfo(id)
zebug.trace:event(event):print("btnSlotIndex",btnSlotIndex, "name",name)
return name == PLACEHOLDER_MACRO_NAME
end
return false
end
---@param btn BlizActionBarButton
function Placeholder:isOn(btn, event)
if not btn then return end
local type, id = btn:getTypeAndId()
zebug.trace:event(event):--[[owner(btn):]]print("type",type, "id",id)
if type == ButtonType.MACRO then
local name = GetMacroInfo(id)
zebug.trace:event(event):--[[owner(btn):]]print("name",name)
return name == PLACEHOLDER_MACRO_NAME
end
return false
end
function Placeholder:nuke()
while GetMacroInfo(PLACEHOLDER_MACRO_NAME) do
DeleteMacro(PLACEHOLDER_MACRO_NAME)
end
end
function Placeholder:doNotLetUserDragMe(event)
local cursor = Cursor:get()
if cursor:isUfoPlaceholder() then
if Ufo.myPlaceholderSoDoNotDelete then
zebug.info:event(event):owner(cursor):print("keeping (this one time) at request of Ufo.myPlaceholderSoDoNotDelete",Ufo.myPlaceholderSoDoNotDelete)
Ufo.myPlaceholderSoDoNotDelete = false
else
zebug.info:event(event):owner(cursor):print("clearing in absence of Ufo.myPlaceholderSoDoNotDelete")
cursor:clear(event)
end
else
--local type, id = GetCursorInfo()
--zebug.info:event(event):owner(cursor):print("ignoring because I only care about Placeholders. type",type, "id",id)
Ufo.myPlaceholderSoDoNotDelete = false
end
end
function Placeholder:getId()
return getMacroIndexByNameOrNil(PLACEHOLDER_MACRO_NAME)
end
function Placeholder:toString()
return string.format("<Placeholder: macroId=%d>", self:getId())
end