-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsgFrame.lua
290 lines (259 loc) · 10.2 KB
/
MsgFrame.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
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
--------------------------------------------------------------------------------------
-- MsgFrame.lua
-- AUTHOR: Shadowraith@Feathermoon
-- ORIGINAL DATE: 12 January, 2019
----------------------------------------------------------------------------------------
local AddonName, ChaChing = ...
ChaChing = ChaChing or {}
ChaChing.MsgFrame = {}
local mf = ChaChing.MsgFrame
local core = ChaChing.Core
local dbg = ChaChing.DebugTools
local item = ChaChing.Item
local L = ChaChing.L
local FRAME_WIDTH_DEFAULT = 900
local FRAME_HEIGHT_DEFAULT = 600
local DEFAULT_XPOS = 0
local DEFAULT_YPOS = 200
local DEFAULT_FRAME_WIDTH = 600
local DEFAULT_FRAME_HEIGHT = 500
local messageFrame = nil
local errorMsgFrame = nil
---------------------------------------------------------------------------------------------------
-- Create the MAIN FRAME
---------------------------------------------------------------------------------------------------
local function createTopFrame( frameTitle, width, height )
local topFrame = CreateFrame("Frame", "EXCLUDED_ITEMS", UIParent, BackdropTemplateMixin and "BackdropTemplate" )
topFrame:SetSize(width, height)
topFrame:SetPoint("CENTER", 0, 200)
topFrame:SetFrameStrata("BACKGROUND")
topFrame:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
edgeSize = 26,
insets = {left = 9, right = 9, top = 9, bottom = 9},
})
topFrame:SetBackdropColor(0, 0, 0)
topFrame:EnableMouse(true)
topFrame:EnableMouseWheel(true)
topFrame:SetMovable(true)
topFrame:Hide()
topFrame:RegisterForDrag("LeftButton")
topFrame:SetScript("OnDragStart", topFrame.StartMoving)
topFrame:SetScript("OnDragStop", topFrame.StopMovingOrSizing)
-- Create the title bar
local titleBar = CreateFrame("Frame", nil, topFrame, BackdropTemplateMixin and "BackdropTemplate")
titleBar:SetPoint("TOPLEFT", topFrame, "TOPLEFT", 10, -10)
titleBar:SetPoint("TOPRIGHT", topFrame, "TOPRIGHT", -30, -10)
titleBar:SetHeight(30)
titleBar:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 14,
})
titleBar:SetBackdropColor(0.1, 0.1, 0.1, 1)
-- Add the title to the title bar
local titleText = titleBar:CreateFontString(nil, "OVERLAY")
titleText:SetFontObject("GameFontHighlight")
titleText:SetPoint("CENTER", titleBar, "CENTER", 0, 0)
titleText:SetText(frameTitle)
topFrame.titleBar = titleBar
topFrame.titleText = titleText
return topFrame
end
----------------------------------------------------------------------------------------------------
-- Create the Buttons
----------------------------------------------------------------------------------------------------
local function createResizeButton( f )
f:SetResizable(true)
local resizeButton = CreateFrame("Button", nil, f)
resizeButton:SetSize(16, 16)
resizeButton:SetPoint("BOTTOMRIGHT")
resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizeButton:SetScript("OnMouseDown", function(self, button)
f:StartSizing("BOTTOMRIGHT")
f:SetUserPlaced(true)
end)
resizeButton:SetScript("OnMouseUp", function(self, button)
f:StopMovingOrSizing()
FRAME_WIDTH, FRAME_HEIGHT = f:GetSize()
end)
end
local function createReloadButton( f )
local reloadButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
reloadButton:SetPoint("BOTTOM", -200, 10)
reloadButton:SetHeight(25)
reloadButton:SetWidth(70)
reloadButton:SetText("Reload")
reloadButton:SetScript("OnClick",
function(self)
ReloadUI()
end)
f.reloadButton = reloadButton
end
local function createSelectButton(f)
local selectButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
selectButton:SetPoint("BOTTOMRIGHT", -10, 10)
selectButton:SetHeight(25)
selectButton:SetWidth(70)
selectButton:SetText("Select")
selectButton:SetScript("OnClick",
function(self)
local editBox = self:GetParent().Text
editBox:SetFocus() -- Set focus to the edit box
editBox:HighlightText() -- Highlight all the text
editBox:EnableKeyboard(true) -- Ensure the EditBox can receive keyboard input
editBox:EnableMouse(true) -- Ensure the EditBox can receive mouse input
-- You may also force the user to press "Enter" to finalize the selection
-- and then notify them to press Ctrl+C to copy
print("Text selected! Press Ctrl+C to copy.")
end)
f.selectButton = selectButton
end
local function createRemoveButton( f )
local removeButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
removeButton:SetPoint("BOTTOM", 160, 10)
removeButton:SetHeight(25)
removeButton:SetWidth(120)
removeButton:SetText("Remove Entries")
removeButton:SetScript("OnClick",
function(self)
self:GetParent().Text:EnableMouse( false )
self:GetParent().Text:EnableKeyboard( false )
self:GetParent().Text:SetText("")
self:GetParent().Text:ClearFocus()
wipe( ChaChing_ExcludedItemsList )
f:Hide()
end)
f.removeButton = removeButton
end
local function createDismissButton( f )
local dismissButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
dismissButton:SetPoint("TOPRIGHT", f, "TOPRIGHT", -10, -10)
dismissButton:SetHeight(25)
dismissButton:SetWidth(25)
dismissButton:SetText("X")
dismissButton:SetNormalFontObject("GameFontNormalSmall")
dismissButton:SetScript("OnClick",
function(self)
f:Hide()
end)
f.dismissButton = dismissButton
end
local function createClearButton( f )
local clearButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
clearButton:SetPoint("BOTTOMLEFT", 10, 10)
clearButton:SetHeight(25)
clearButton:SetWidth(70)
clearButton:SetText("Clear")
clearButton:SetScript("OnClick",
function(self)
self:GetParent().Text:SetText("")
self:GetParent().Text:ClearFocus()
end)
f.clearButton = clearButton
end
----------------------------------------------------------------------------------------------------
-- Create the Scrollbar and the EditBox frames
----------------------------------------------------------------------------------------------------
local function createTextDisplay(f)
f.SF = CreateFrame("ScrollFrame", "$parent_DF", f, "UIPanelScrollFrameTemplate")
f.SF:SetPoint("TOPLEFT", f, 12, -40)
f.SF:SetPoint("BOTTOMRIGHT", f, -30, 50)
-- Now create the EditBox
f.Text = CreateFrame("EditBox", nil, f)
f.Text:SetMultiLine(true)
f.Text:SetSize(FRAME_WIDTH_DEFAULT - 20, FRAME_HEIGHT_DEFAULT)
f.Text:SetPoint("TOPLEFT", f.SF)
f.Text:SetPoint("BOTTOMRIGHT", f.SF)
f.Text:SetMaxLetters(99999)
f.Text:SetFontObject(GameFontNormalLarge)
f.Text:SetHyperlinksEnabled(true)
f.Text:SetTextInsets(5, 5, 5, 5)
f.Text:SetAutoFocus(false)
f.Text:EnableMouse(true)
f.Text:EnableKeyboard(true)
f.Text:SetScript("OnEscapePressed",
function(self)
self:ClearFocus()
end)
f.SF:SetScrollChild(f.Text)
end
local function createPostMsgFrame( title, width, height )
local f = createTopFrame( title, DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT )
f:SetPoint("CENTER", DEFAULT_XPOS, DEFAULT_YPOS - 200 )
f:SetFrameStrata("BACKGROUND")
f:EnableMouse(true)
f:EnableMouseWheel(true)
f:SetMovable(true)
f:Hide()
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
createTextDisplay(f)
createResizeButton(f)
-- createReloadButton(f)
createSelectButton(f)
createClearButton(f)
createDismissButton(f)
return f
end
function mf:postMsg( msg )
if messageFrame == nil then
messageFrame = createPostMsgFrame( "ChaChing Messages", 600, 400 )
end
messageFrame:Show()
messageFrame.Text:SetText( msg )
end
function mf:createListFrame( frameTitle )
local f = createTopFrame( frameTitle, 500, 300 )
createRemoveButton(f)
createDismissButton(f)
createTextDisplay(f)
return f
end
local function createErrorMsgFrame(title)
local f = createTopFrame( "ErrorMsgFrame", 700, 400 )
f:SetPoint("CENTER", DEFAULT_XPOS, DEFAULT_YPOS)
f:SetFrameStrata("BACKGROUND")
f:EnableMouse(true)
f:EnableMouseWheel(true)
f:SetMovable(true)
f:Hide()
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
createTextDisplay(f)
createResizeButton(f)
createReloadButton(f)
createSelectButton(f)
createClearButton(f)
createDismissButton(f)
return f
end
function mf:postResult(result)
if coreL:debuggingIsEnabled() then
assert(result ~= nil, L["INPUT_PARAM_NIL"])
assert(type(result) == "table", L["INVALID_TYPE"])
assert(#result == 3, L["PARAM_ILL_FORMED"])
end
if errorMsgFrame == nil then
errorMsgFrame = createErrorMsgFrame("ChaChing Error Message(s)")
end
local str = nil
if result[3] ~= nil then
str = string.format("%s\nSTACK TRACE:\n%s\n", result[2], result[3])
else
str = string.format("%s", result[2])
end
-- Append text to the EditBox
local existingText = errorMsgFrame.Text:GetText() or ""
errorMsgFrame.Text:SetText(existingText .. "\n" .. str)
errorMsgFrame:Show()
end
local fileName = "MsgFrame.lua"
if core:debuggingIsEnabled() then
DEFAULT_CHAT_FRAME:AddMessage( string.format("%s loaded", fileName), 1.0, 1.0, 0.0 )
end