forked from Nevcairiel/HandyNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandyNotes_EditFrame.lua
More file actions
276 lines (257 loc) · 11.8 KB
/
HandyNotes_EditFrame.lua
File metadata and controls
276 lines (257 loc) · 11.8 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
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
---------------------------------------------------------
-- Module declaration
local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes")
local HN = HandyNotes:GetModule("HandyNotes")
local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes", false)
local info = {}
local backdrop2 = {
bgFile = nil,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 0, right = 0, top = 0, bottom = 0 },
}
-- Create the main frame
-- For jncl (Skinner), this frame is accessed by LibStub("AceAddon-3.0"):GetAddon("HandyNotes"):GetModule("HandyNotes").HNEditFrame
local HNEditFrame = CreateFrame("Frame", "HNEditFrame", UIParent, BackdropTemplateMixin and "BackdropTemplate" or nil)
HN.HNEditFrame = HNEditFrame
HNEditFrame:Hide()
HNEditFrame:SetWidth(350)
HNEditFrame:SetHeight(235)
HNEditFrame:SetPoint("BOTTOM", 0, 90)
HNEditFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
})
--HNEditFrame:SetBackdropColor(0, 0, 0, 0.75)
HNEditFrame:SetBackdropColor(0,0,0,1)
HNEditFrame:EnableMouse(true)
HNEditFrame:SetToplevel(true)
HNEditFrame:SetClampedToScreen(true)
HNEditFrame:SetMovable(true)
HNEditFrame:SetFrameStrata("FULLSCREEN")
HNEditFrame.titleTexture = HNEditFrame:CreateTexture(nil, "ARTWORK")
HNEditFrame.titleTexture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
HNEditFrame.titleTexture:SetWidth(300)
HNEditFrame.titleTexture:SetHeight(64)
HNEditFrame.titleTexture:SetPoint("TOP", 0, 12)
--HNEditFrame.titleTexture = temp
HNEditFrame.title = HNEditFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
HNEditFrame.title:SetPoint("TOP", 0, -3)
HNEditFrame.title:SetText(L["Add Handy Note"])
-- This creates a transparent textureless draggable frame to move HNEditFrame
-- It overlaps the above title text and texture (more or less) exactly.
local temp = CreateFrame("Frame", nil, HNEditFrame)
temp:SetWidth(150)
temp:SetHeight(30)
temp:SetPoint("TOP", 0, 8)
temp:EnableMouse(true)
temp:RegisterForDrag("LeftButton")
temp:SetScript("OnDragStart", function(self)
self:GetParent():StartMoving()
end)
temp:SetScript("OnDragStop", function(self)
self:GetParent():StopMovingOrSizing()
end)
-- Create the Close button
HNEditFrame.CloseButton = CreateFrame("Button", nil, HNEditFrame, "UIPanelCloseButton")
HNEditFrame.CloseButton:SetPoint("TOPRIGHT", -2, -1)
HNEditFrame.CloseButton:SetHitRectInsets(5, 5, 5, 5)
-- Create and position the Title text string
HNEditFrame.titletext = HNEditFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
HNEditFrame.titletext:SetPoint("TOPLEFT", 25, -28)
HNEditFrame.titletext:SetText(L["Title"])
-- Create the Title Input Box and position it below the text
HNEditFrame.titleinputframe = CreateFrame("Frame", nil, HNEditFrame, BackdropTemplateMixin and "BackdropTemplate" or nil)
HNEditFrame.titleinputframe:SetWidth(300)
HNEditFrame.titleinputframe:SetHeight(24)
HNEditFrame.titleinputframe:SetBackdrop(backdrop2)
HNEditFrame.titleinputframe:SetPoint("TOPLEFT", HNEditFrame.titletext, "BOTTOMLEFT", 0, 0)
HNEditFrame.titleinputbox = CreateFrame("EditBox", nil, HNEditFrame.titleinputframe)
HNEditFrame.titleinputbox:SetWidth(290)
HNEditFrame.titleinputbox:SetHeight(24)
HNEditFrame.titleinputbox:SetMaxLetters(100)
HNEditFrame.titleinputbox:SetNumeric(false)
HNEditFrame.titleinputbox:SetAutoFocus(false)
HNEditFrame.titleinputbox:SetFontObject("GameFontHighlightSmall")
HNEditFrame.titleinputbox:SetPoint("TOPLEFT", 5, 1)
HNEditFrame.titleinputbox:SetScript("OnShow", HNEditFrame.titleinputbox.SetFocus)
HNEditFrame.titleinputbox:SetScript("OnEscapePressed", HNEditFrame.titleinputbox.ClearFocus)
-- Create and position the Description text string
HNEditFrame.desctext = HNEditFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
HNEditFrame.desctext:SetPoint("TOPLEFT", HNEditFrame.titleinputframe, "BOTTOMLEFT", 0, 0)
HNEditFrame.desctext:SetText(L["Description/Notes:"])
-- Create the ScrollFrame for the Description Edit Box
HNEditFrame.descframe = CreateFrame("Frame", nil, HNEditFrame, BackdropTemplateMixin and "BackdropTemplate" or nil)
HNEditFrame.descframe:SetWidth(300)
HNEditFrame.descframe:SetHeight(67)
HNEditFrame.descframe:SetBackdrop(backdrop2)
HNEditFrame.descframe:SetPoint("TOPLEFT", HNEditFrame.desctext, "BOTTOMLEFT", 0, 0)
HNEditFrame.descscrollframe = CreateFrame("ScrollFrame", "HandyNotes_EditScrollFrame", HNEditFrame.descframe, "UIPanelScrollFrameTemplate")
HNEditFrame.descscrollframe:SetWidth(269)
HNEditFrame.descscrollframe:SetHeight(59)
HNEditFrame.descscrollframe:SetPoint("TOPLEFT", 5, -4)
-- Create the Description Input Box and position it below the text
HNEditFrame.descinputbox = CreateFrame("EditBox", nil, HNEditFrame)
HNEditFrame.descinputbox:SetWidth(269) -- Height is auto set in a multiline editbox
HNEditFrame.descinputbox:SetMaxLetters(512)
HNEditFrame.descinputbox:SetNumeric(false)
HNEditFrame.descinputbox:SetAutoFocus(false)
HNEditFrame.descinputbox:SetFontObject("GameFontHighlightSmall")
HNEditFrame.descinputbox:SetMultiLine(true)
HNEditFrame.descinputbox:SetScript("OnCursorChanged", function(self, x, y, w, h)
local scrollFrame = self:GetParent()
local height = scrollFrame:GetHeight()
local range = scrollFrame:GetVerticalScrollRange()
local scroll = scrollFrame:GetVerticalScroll()
local cursorOffset = -y
while ( cursorOffset < scroll ) do
scroll = (scroll - (height / 2))
if ( scroll < 0 ) then
scroll = 0
end
scrollFrame:SetVerticalScroll(scroll)
end
while ( (cursorOffset + h) > (scroll + height) and scroll < range ) do
scroll = (scroll + (height / 2))
if ( scroll > range ) then
scroll = range
end
scrollFrame:SetVerticalScroll(scroll)
end
end)
HNEditFrame.descinputbox:SetScript("OnEscapePressed", HNEditFrame.descinputbox.ClearFocus)
-- Attach the ScrollChild to the ScrollFrame
HNEditFrame.descscrollframe:SetScrollChild(HNEditFrame.descinputbox)
-- Create the Icon Dropdown
HNEditFrame.icondropdown = CreateFrame("Frame", "HandyNotes_IconDropDown", HNEditFrame, "UIDropDownMenuTemplate")
HNEditFrame.icondropdown:SetPoint("TOPLEFT", HNEditFrame.descframe, "BOTTOMLEFT", -17, 0)
HNEditFrame.icondropdown:SetHitRectInsets(16, 16, 0, 0)
UIDropDownMenu_SetWidth(HNEditFrame.icondropdown, 120)
UIDropDownMenu_EnableDropDown(HNEditFrame.icondropdown)
HNEditFrame.icondropdown.displayMode = "MENU"
HNEditFrame.icondropdown.texture = HNEditFrame.icondropdown:CreateTexture(nil, "OVERLAY")
HNEditFrame.icondropdown.texture:SetWidth(12)
HNEditFrame.icondropdown.texture:SetHeight(12)
HNEditFrame.icondropdown.texture:SetPoint("RIGHT", HNEditFrame.icondropdown, -41, 2)
HNEditFrame.icondropdown.Text:SetPoint("RIGHT", HNEditFrame.icondropdown.texture, "LEFT", -3, 0)
HNEditFrame.icondropdown.Text:SetWidth(HNEditFrame.icondropdown.Text:GetWidth() - 9)
HNEditFrame.icondropdown.OnClick = function(button, value)
local t = HN.icons[value]
HNEditFrame.icondropdown.selectedValue = value
HNEditFrame.icondropdown.texture:SetTexture(t.icon)
if t.tCoordLeft then
HNEditFrame.icondropdown.texture:SetTexCoord(t.tCoordLeft, t.tCoordRight, t.tCoordTop, t.tCoordBottom)
else
HNEditFrame.icondropdown.texture:SetTexCoord(0, 1, 0, 1)
end
HNEditFrame.icondropdown.Text:SetText(t.text)
local color = t.color
if color then
HNEditFrame.icondropdown.Text:SetTextColor(color.r, color.g, color.b, color.a or 1)
else
HNEditFrame.icondropdown.Text:SetTextColor(1, 1, 1, 1)
end
end
HNEditFrame.icondropdown.initialize = function(level)
wipe(info)
for i = 1, #HN.icons do
local t = HN.icons[i]
info.text = t.text
info.icon = t.icon
info.tCoordLeft = t.tCoordLeft
info.tCoordRight = t.tCoordRight
info.tCoordTop = t.tCoordTop
info.tCoordBottom = t.tCoordBottom
info.arg1 = i
info.func = HNEditFrame.icondropdown.OnClick
info.checked = HNEditFrame.icondropdown.selectedValue == i
info.keepShownOnClick = nil
UIDropDownMenu_AddButton(info)
end
end
-- Create the Show on Continent checkbox
HNEditFrame.continentcheckbox = CreateFrame("CheckButton", nil, HNEditFrame, "UICheckButtonTemplate")
HNEditFrame.continentcheckbox:SetWidth(24)
HNEditFrame.continentcheckbox:SetHeight(24)
HNEditFrame.continentcheckbox:SetPoint("LEFT", HNEditFrame.icondropdown, "RIGHT", -10, 2)
HNEditFrame.continentcheckbox.string = HNEditFrame.continentcheckbox:CreateFontString()
HNEditFrame.continentcheckbox.string:SetWidth(153)
HNEditFrame.continentcheckbox.string:SetJustifyH("LEFT")
HNEditFrame.continentcheckbox.string:SetPoint("LEFT", 24, 1)
HNEditFrame.continentcheckbox:SetFontString(HNEditFrame.continentcheckbox.string)
HNEditFrame.continentcheckbox:SetNormalFontObject("GameFontNormalSmall")
HNEditFrame.continentcheckbox:SetHighlightFontObject("GameFontHighlightSmall")
HNEditFrame.continentcheckbox:SetDisabledFontObject("GameFontDisableSmall")
HNEditFrame.continentcheckbox:SetText(L["Show on continent map"])
HNEditFrame.continentcheckbox:SetChecked(true)
HNEditFrame.continentcheckbox:SetHitRectInsets(0, -HNEditFrame.continentcheckbox.string:GetStringWidth(), 0, 0)
HNEditFrame.continentcheckbox:SetPushedTextOffset(0, 0)
-- Create the OK button
HNEditFrame.okbutton = CreateFrame("Button", nil, HNEditFrame, "UIPanelButtonTemplate")
HNEditFrame.okbutton:SetWidth(150)
HNEditFrame.okbutton:SetHeight(22)
HNEditFrame.okbutton:SetPoint("TOPLEFT", HNEditFrame.leveldropdown or HNEditFrame.icondropdown, "BOTTOMLEFT", 15, 0)
HNEditFrame.okbutton:SetText(OKAY)
-- Create the Cancel button
HNEditFrame.cancelbutton = CreateFrame("Button", nil, HNEditFrame, "UIPanelButtonTemplate")
HNEditFrame.cancelbutton:SetWidth(150)
HNEditFrame.cancelbutton:SetHeight(22)
HNEditFrame.cancelbutton:SetPoint("LEFT", HNEditFrame.okbutton, "RIGHT", 3, 0)
HNEditFrame.cancelbutton:SetText(CANCEL)
HNEditFrame.cancelbutton:SetScript("OnClick", HNEditFrame.CloseButton:GetScript("OnClick"))
-- Additional Behavior functions
HNEditFrame:SetScript("OnMouseDown", function(self, button)
if MouseIsOver(HNEditFrame.descframe) and button == "LeftButton" then
HNEditFrame.descinputbox:SetFocus()
end
end)
HNEditFrame.titleinputbox:SetScript("OnTabPressed", function(self)
HNEditFrame.descinputbox:SetFocus()
end)
HNEditFrame.descinputbox:SetScript("OnTabPressed", function(self)
HNEditFrame.titleinputbox:SetFocus()
end)
-- Makes ESC key close HNEditFrame
tinsert(UISpecialFrames, "HNEditFrame")
---------------------------------------------------------
-- OnShow function to show a note for adding or editing
HNEditFrame:SetScript("OnShow", function(self)
local data = HN.db.global[self.mapID][self.coord]
if data then
HNEditFrame.title:SetText(L["Edit Handy Note"])
HNEditFrame.titleinputbox:SetText(data.title)
HNEditFrame.descinputbox:SetText(data.desc)
HNEditFrame.icondropdown.OnClick(nil, data.icon)
HNEditFrame.continentcheckbox:SetChecked(data.cont)
else
HNEditFrame.title:SetText(L["Add Handy Note"])
HNEditFrame.titleinputbox:SetText("")
HNEditFrame.descinputbox:SetText("")
HNEditFrame.icondropdown.OnClick(nil, 1)
HNEditFrame.continentcheckbox:SetChecked(nil)
end
if WorldMapFrame:IsShown() then
self:SetParent(WorldMapFrame)
self:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 20)
else
self:SetParent(UIParent)
self:SetFrameLevel(10)
end
end)
---------------------------------------------------------
-- OnClick function to accept the changes for a new/edited note
HNEditFrame.okbutton:SetScript("OnClick", function(self)
local data = HN.db.global[HNEditFrame.mapID][HNEditFrame.coord]
if not data then
data = {}
HN.db.global[HNEditFrame.mapID][HNEditFrame.coord] = data
end
data.title = HNEditFrame.titleinputbox:GetText()
data.desc = HNEditFrame.descinputbox:GetText()
data.icon = HNEditFrame.icondropdown.selectedValue
data.cont = HNEditFrame.continentcheckbox:GetChecked()
HNEditFrame:Hide()
HN:SendMessage("HandyNotes_NotifyUpdate", "HandyNotes")
end)