forked from Monteo/SuperMacro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSM_MacroExtend.lua
109 lines (89 loc) · 2.67 KB
/
SM_MacroExtend.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
-- SuperMacroExtend handlers
-- string: saved current extend script page to show.
local currentPageId
-- Change current page to new Id
local function SetCurrentPage(pageId)
currentPageId = pageId
local extendText
if currentPageId then
extendText=SM_EXTEND[currentPageId]
end
if extendText then
SuperMacroFrameExtendText:SetText(extendText)
else
-- Create new or invalid id. Show empty text
SuperMacroFrameExtendText:SetText("")
end
end
-- Save current extend script text to SM_EXTEND and update UI
local function SaveCurrentPage()
if not currentPageId then
return
end
local text=SuperMacroFrameExtendText:GetText()
if text and text~="" then
SM_EXTEND[currentPageId]=text
else
-- auto delete empty page
SM_EXTEND[currentPageId]=nil
end
SuperMacroFrameExtendText:ClearFocus()
SuperMacroSaveExtendButton:SetTextColor(0.5, 0.5, 0.5)
end
-- Run all current scripts
local function RunAllScripts()
for m,e in pairs(SM_EXTEND) do
if ( e ) then
RunScript(e)
end
end
end
-- External functions
-- Initialize extend macro
function SuperMacroInitExtend()
RunAllScripts()
end
-- Save current UI text changes and run scripts
function SuperMacroRunAllExtend()
SaveCurrentPage()
RunAllScripts()
end
function SuperMacroSelectExtend(pageId)
SaveCurrentPage()
SetCurrentPage(pageId)
end
function SuperMacroCopyExtend(fromId, toId)
assert(fromId ~= toId)
SaveCurrentPage()
local text = SM_EXTEND[fromId]
SM_EXTEND[toId] = text
end
function SuperMacroDeleteExtend(pageId)
SaveCurrentPage()
SM_EXTEND[pageId]=nil
if pageId == currentPageId then
-- Update script UI
SetCurrentPage(pageId)
end
end
-- Save button action
function SuperMacroSaveExtendButton_OnClick()
SuperMacroRunAllExtend()
end
-- Delete button action
function SuperMacroDeleteExtendButton_OnClick()
if currentPageId then
SuperMacroDeleteExtend(currentPageId)
end
SuperMacroRunAllExtend()
end
-- UI change text action
function SuperMacroFrameExtendText_OnTextChanged()
SuperMacroFrameExtendCharLimitText:SetText(format(TEXT(SUPERMACROFRAME_EXTEND_CHAR_LIMIT), strlen(SuperMacroFrameExtendText:GetText())))
SuperMacroHandleEditBox(SuperMacroFrameExtendText)
SuperMacroSaveExtendButton:SetTextColor(1, 0.82, 0)
end
function SuperMacroSetDefaultTooltipColor(frame)
frame:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
frame:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
end