-
Notifications
You must be signed in to change notification settings - Fork 2
/
Ghost.lua
executable file
·142 lines (117 loc) · 3.53 KB
/
Ghost.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
function ghostInit()
ChatFrame1:AddMessage( ghostText['loaded'] , 1.0, 1.0, 0.0, 1.0);
SLASH_Ghost1 = "/ghost";
SlashCmdList["Ghost"] = function (msg)
cmd, param = ghostCommandFormat( msg );
if cmd == "reload" then
ReloadUI();
elseif cmd == ghostText['scale'] then
ghostSlashCommandScale( param );
elseif cmd == ghostText['reset'] then
ghostSlashCommandReset( param );
elseif cmd == ghostText['lock'] then
ghostSlashCommandLock( param );
elseif cmd == ghostText['text'] then
ghostSlashCommandText( param );
else
ChatFrame1:AddMessage( ghostText['slashHelp'] , 1.0, 1.0, 0.0, 1.0);
end
end
ghostCreateFrame();
ghostCreateButton();
end
-- Cut string in half at the first blankspace
function ghostCommandFormat( msg )
if msg and strlen(msg) > 0 then
msg = string.lower(msg)
else
msg = ""
end
local i, j, cmd, param = string.find(msg, "^([^ ]+) (.+)$")
if not cmd then
cmd = msg
end
if not cmd then
cmd = ""
end
if not param then
param = ""
end
return cmd, param;
end
-- Slash lock command
function ghostSlashCommandLock( param )
cmdSub, paramSub = ghostCommandFormat( param )
-- Lock buttons
if cmdSub == "button" then
if ghost['lockButton'] == false then
ChatFrame1:AddMessage( ghostText['buttonLocked'] , 1.0, 1.0, 0.0, 1.0);
ghost['lockButton'] = true;
else
ghost['lockButton'] = false;
ChatFrame1:AddMessage( ghostText['buttonUnlocked'] , 1.0, 1.0, 0.0, 1.0);
end
-- Lock frame
elseif cmdSub == "frame" then
if ghost['lockFrame'] == false then
ChatFrame1:AddMessage( ghostText['frameLocked'] , 1.0, 1.0, 0.0, 1.0);
ghost['lockFrame'] = true;
else
ghost['lockFrame'] = false;
ChatFrame1:AddMessage( ghostText['frameUnlocked'] , 1.0, 1.0, 0.0, 1.0);
end
else
ChatFrame1:AddMessage( ghostText['lockHelp'] , 1.0, 1.0, 0.0, 1.0);
end
end
-- Slash reset command
function ghostSlashCommandReset( param )
cmdSub, paramSub = ghostCommandFormat( param )
if cmdSub == "lock" then
ChatFrame1:AddMessage( ghostText['resetLock'] , 1.0, 1.0, 0.0, 1.0);
ghost['lockFrame'] = true;
ghost['lockButton'] = true;
elseif cmdSub == "scale" then
ChatFrame1:AddMessage( ghostText['resetScale'] , 1.0, 1.0, 0.0, 1.0);
ghost['frameScale'] = 1;
elseif cmdSub == "text" then
ChatFrame1:AddMessage( ghostText['resetText'] , 1.0, 1.0, 0.0, 1.0);
ghost['showBindingText'] = true;
else
ChatFrame1:AddMessage( ghostText['resetHelp'] , 1.0, 1.0, 0.0, 1.0);
end
end
-- Slash Scale command
function ghostSlashCommandScale( param )
if not tonumber(param) or param == nil then
param = 0;
end
local scale = tonumber(param);
if not scale then
scale = 0;
end
if scale > 0 and scale <= 2.5 then
ChatFrame1:AddMessage( ghostText['setScale'] .. scale, 1.0, 1.0, 0.0, 1.0);
ghost['frameScale'] = param;
else
ChatFrame1:AddMessage( ghostText['scaleHelp'], 1.0, 1.0, 0.0, 1.0);
end
end
-- Slash text command
function ghostSlashCommandText( param )
if ghost['showBindingText'] == false then
ghost['showBindingText'] = true;
ChatFrame1:AddMessage( ghostText['ShowText'] , 1.0, 1.0, 0.0, 1.0);
else
ghost['showBindingText'] = false;
ChatFrame1:AddMessage( ghostText['ShowNoText'] , 1.0, 1.0, 0.0, 1.0);
end
end
-- Register all events
local frame = CreateFrame("Frame")
frame:RegisterEvent("VARIABLES_LOADED")
frame:SetScript("OnEvent", function()
if event == "VARIABLES_LOADED" then
ghostInit();
end
end)