-
Notifications
You must be signed in to change notification settings - Fork 18
/
GridUtilsCmd.lua
180 lines (166 loc) · 5.67 KB
/
GridUtilsCmd.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
175
176
177
178
179
180
-- Process command line order
local Grid2 = Grid2
local display = { never = 'Never', always = 'Always', grouped = 'Grouped', raid = 'Raid', toggle = false }
local function ProcessMinimapCmd(p)
if p=='global' then
Grid2.db.global.minimapIcon = (Grid2.db.global.minimapIcon==nil) and {hide=false} or nil
ReloadUI()
elseif p=='toggle' then
Grid2:SetMinimapIcon()
else
Grid2:SetMinimapIcon(p~='hide')
end
end
local ProcessNameListCmd
do
local function GetHeaderType(header)
return header.headerName or header.type or 'players'
end
local function DisplayNameListError()
print("Grid2 Error: Name list or header type not found in the active layout. You must open the layout editor to create a custom layout and a namelist to use this feature.")
end
local function SearchHeader(headerName)
local layout, header = Grid2Layout.layoutSettings[Grid2Layout.layoutName]
headerName = strlower(headerName)
for idx, data in ipairs(layout) do
if data.nameList then
header = header or data
if headerName==strlower(data.headerName or '*') then
return data, true
end
end
end
return header, false
end
local function GetMouseOverPlayer()
local name, server = UnitName('mouseover')
if name then
return (server and server ~= "") and name.."-"..server or name
end
end
local function ToggleNameList(header, name)
if name then
local lst = header.nameList
local nam = ',' .. name .. ','
local str = ',' .. lst .. ','
if strfind(str, nam, 1, true) then -- del player name
nam = nam:gsub("(%W)", "%%%1")
repeat
local old = str
str = old:gsub(nam, ',')
until str == old
header.nameList = str:gsub('^,',''):gsub(',$','')
print( string.format( 'Grid2: Removed [%s] from [%s] name list.', name, GetHeaderType(header)) )
else -- add player name
header.nameList = (lst=='') and name or (lst..','..name)
print( string.format( 'Grid2: Added [%s] to [%s] name list.', name, GetHeaderType(header)) )
end
end
end
local function DisplayNameList(header)
if header then
print( string.format( 'Grid2 nameList [%s]: "%s"', GetHeaderType(header), header.nameList) )
else
DisplayNameListError()
end
end
function ProcessNameListCmd(param)
if param then
local cmd, rst = strsplit(" ", param, 2)
local header, flag = SearchHeader(cmd)
if header then
if flag then
cmd = rst
elseif rst then
print("Grid2 Error: Too many command line arguments or specified header type not found in active layout."); return
end
if cmd==nil then
DisplayNameList(header); return
elseif strlower(cmd) == 'clear' then
header.nameList = ""
print( string.format( 'Grid2: Removed all players from [%s] name list.', GetHeaderType(header)) )
elseif strlower(cmd) == '@mouseover' then
ToggleNameList( header, GetMouseOverPlayer() )
elseif cmd then
ToggleNameList( header, cmd )
end
Grid2Layout:RefreshLayout()
if Grid2Options then Grid2Options:RefreshOptions() end
else
DisplayNameListError(); return
end
else
DisplayNameList( SearchHeader('') )
end
end
end
local function ProcessIgnoreTooltipDebuff(param)
if param then
local status = Grid2.statuses[ 'debuffs-' .. strtrim(param,'" ') ]
if status and status.IgnoreTooltipDebuff then
status:IgnoreTooltipDebuff()
else
Grid2:Print( string.format('Error: Specified %s status not found in current profile.',param) )
end
else
local gstatus, gpriority = nil, 0
for _,status in pairs(Grid2.statusTypes.tooltip) do
if status.IgnoreTooltipDebuff then
local priority = (status.dbx.auras==nil and 1) or (status.dbx.useWhiteList and 2) or 3
if priority>gpriority then
gstatus, gpriority = status, priority
end
end
end
if gstatus then
gstatus:IgnoreTooltipDebuff()
else
Grid2:Print( string.format('Error: You must create at least one debuffs status to use this command.') )
end
end
end
local function ProcessHelpCmd()
Grid2:Print("commands (/grid2, /gr2)")
print(" /grid2")
print(" /grid2 options")
print(" /grid2 help")
print(" /grid2 unlock")
print(" /grid2 lock")
print(" /grid2 lock toggle")
print(" /grid2 theme name || index")
print(" /grid2 show never || always || grouped || raid || toggle")
print(" /grid2 minimapicon show || hide || toggle || global")
print(" /grid2 profile <profile_name>")
if not Grid2.isClassic then
print(" /grid2 profile specIndex name")
print(" /grid2 profilesperspec enable || disable")
end
print(" /grid2 namelist || nl [header_type] clear || @mouseover || <player_name>")
print(" /grid2 parsetip [status_name]")
end
function Grid2:ProcessCommandLine(input)
local command, param = strsplit(" ", input or "", 2)
local c, p = strlower(command), strlower(param or "")
if c=='lock' then -- lock toggle
Grid2Layout:FrameLock( p~='toggle' or nil )
elseif c=='unlock' then
Grid2Layout:FrameLock(false)
elseif c=='show' and display[p]~=nil then
Grid2Layout:FrameVisibility( display[p] )
elseif c=='theme' and param and not InCombatLockdown() then
self:SetDefaultTheme( tonumber(param) or strtrim(param,'" ') )
elseif c=='profile' and param and not InCombatLockdown() then
local specIndex, profileName = strmatch( param, "(%d+) (.+)" )
self:SetProfileForSpec( strtrim(specIndex and profileName or param,'" '), tonumber(specIndex) )
elseif c=='profilesperspec' and (p=='enable' or p=='disable') and not InCombatLockdown() then
self:EnableProfilesPerSpec( p=='enable' )
elseif c=='minimapicon' and param then
ProcessMinimapCmd(p)
elseif c=='help' then
ProcessHelpCmd()
elseif c=='parsetip' then
ProcessIgnoreTooltipDebuff(param)
elseif c=='namelist' or c=='nl' then
ProcessNameListCmd(param)
end
end