-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogs.lua
More file actions
274 lines (236 loc) · 8.43 KB
/
Copy pathdialogs.lua
File metadata and controls
274 lines (236 loc) · 8.43 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
local addon = ForgedMapNotes
if not addon then
return
end
addon.noteDialog = addon.noteDialog or nil
addon.deleteDialog = addon.deleteDialog or nil
function addon:ResetDialogState()
self.pendingX = nil
self.pendingY = nil
self.editMapKey = nil
self.editNoteIndex = nil
self.dialogDefaultName = ""
self.deleteMapKey = nil
self.deleteNoteIndex = nil
end
function addon:GetDeleteDialog()
if self.deleteDialog then
return self.deleteDialog
end
local deleteDialog = CreateFrame("Frame", "ForgedMapNotesDeleteDialog", WorldMapFrame)
deleteDialog:SetPoint("CENTER", WorldMapFrame, "CENTER", 0, 0)
deleteDialog:SetWidth(320)
deleteDialog:SetHeight(130)
deleteDialog:SetFrameStrata("FULLSCREEN")
deleteDialog:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 25)
deleteDialog:EnableMouse(true)
deleteDialog: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,
},
})
local headerTexture = deleteDialog:CreateTexture(nil, "ARTWORK")
headerTexture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
headerTexture:SetWidth(256)
headerTexture:SetHeight(64)
headerTexture:SetPoint("TOP", deleteDialog, "TOP", 0, 12)
local header = deleteDialog:CreateFontString(nil, "ARTWORK", "GameFontNormal")
header:SetPoint("TOP", headerTexture, "TOP", 0, -14)
header:SetText("Delete Note")
local text = deleteDialog:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
text:SetPoint("TOP", deleteDialog, "TOP", 0, -44)
text:SetWidth(270)
text:SetJustifyH("CENTER")
text:SetText("Delete this note?")
local acceptButton = CreateFrame("Button", nil, deleteDialog, "UIPanelButtonTemplate")
acceptButton:SetPoint("BOTTOMLEFT", deleteDialog, "BOTTOMLEFT", 20, 18)
acceptButton:SetWidth(130)
acceptButton:SetHeight(24)
acceptButton:SetText(ACCEPT)
local cancelButton = CreateFrame("Button", nil, deleteDialog, "UIPanelButtonTemplate")
cancelButton:SetPoint("BOTTOMRIGHT", deleteDialog, "BOTTOMRIGHT", -20, 18)
cancelButton:SetWidth(130)
cancelButton:SetHeight(24)
cancelButton:SetText(CANCEL)
acceptButton:SetScript("OnClick", function()
if addon.deleteMapKey and addon.deleteNoteIndex then
addon:DeleteNote(addon.deleteMapKey, addon.deleteNoteIndex)
end
addon:ResetDialogState()
deleteDialog:Hide()
end)
cancelButton:SetScript("OnClick", function()
addon.deleteMapKey = nil
addon.deleteNoteIndex = nil
deleteDialog:Hide()
end)
deleteDialog:Hide()
self.deleteDialog = deleteDialog
return deleteDialog
end
function addon:GetNoteDialog()
if self.noteDialog then
return self.noteDialog
end
local noteDialog = CreateFrame("Frame", "ForgedMapNotesAddDialog", WorldMapFrame)
noteDialog:SetPoint("CENTER", WorldMapFrame, "CENTER", 0, 0)
noteDialog:SetWidth(320)
noteDialog:SetHeight(140)
noteDialog:SetFrameStrata("FULLSCREEN")
noteDialog:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 20)
noteDialog:EnableMouse(true)
noteDialog:SetMovable(true)
noteDialog:RegisterForDrag("LeftButton")
noteDialog:SetScript("OnDragStart", function()
this:StartMoving()
end)
noteDialog:SetScript("OnDragStop", function()
this:StopMovingOrSizing()
end)
noteDialog: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,
},
})
local headerTexture = noteDialog:CreateTexture(nil, "ARTWORK")
headerTexture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
headerTexture:SetWidth(256)
headerTexture:SetHeight(64)
headerTexture:SetPoint("TOP", noteDialog, "TOP", 0, 12)
local header = noteDialog:CreateFontString(nil, "ARTWORK", "GameFontNormal")
header:SetPoint("TOP", headerTexture, "TOP", 0, -14)
header:SetText("New Note")
noteDialog.header = header
local label = noteDialog:CreateFontString(nil, "ARTWORK", "GameFontNormal")
label:SetPoint("TOPLEFT", noteDialog, "TOPLEFT", 20, -45)
label:SetText("Name")
local editBox = CreateFrame("EditBox", "ForgedMapNotesAddDialogEditBox", noteDialog, "InputBoxTemplate")
editBox:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 0, -8)
editBox:SetWidth(270)
editBox:SetHeight(20)
editBox:SetAutoFocus(false)
editBox:SetMaxLetters(64)
noteDialog.editBox = editBox
local acceptButton = CreateFrame("Button", nil, noteDialog, "UIPanelButtonTemplate")
acceptButton:SetPoint("BOTTOMLEFT", noteDialog, "BOTTOMLEFT", 20, 18)
acceptButton:SetWidth(130)
acceptButton:SetHeight(24)
acceptButton:SetText(ACCEPT)
local cancelButton = CreateFrame("Button", nil, noteDialog, "UIPanelButtonTemplate")
cancelButton:SetPoint("BOTTOMRIGHT", noteDialog, "BOTTOMRIGHT", -20, 18)
cancelButton:SetWidth(130)
cancelButton:SetHeight(24)
cancelButton:SetText(CANCEL)
local function SubmitNote()
local noteName = ""
if noteDialog.editBox then
noteName = noteDialog.editBox:GetText() or ""
end
if addon.editMapKey and addon.editNoteIndex then
addon:UpdateNoteName(addon.editMapKey, addon.editNoteIndex, noteName)
else
addon:AddNote(noteName)
end
addon:ResetDialogState()
noteDialog:Hide()
end
acceptButton:SetScript("OnClick", SubmitNote)
cancelButton:SetScript("OnClick", function()
addon:ResetDialogState()
noteDialog:Hide()
end)
editBox:SetScript("OnEnterPressed", SubmitNote)
editBox:SetScript("OnEscapePressed", function()
addon:ResetDialogState()
noteDialog:Hide()
end)
noteDialog:SetScript("OnShow", function()
this:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 20)
this:EnableMouse(true)
if this.header then
if addon.editMapKey and addon.editNoteIndex then
this.header:SetText("Edit Note")
else
this.header:SetText("New Note")
end
end
if this.editBox then
this.editBox:SetText(addon.dialogDefaultName or "")
this.editBox:SetFocus()
this.editBox:HighlightText()
end
end)
noteDialog:Hide()
self.noteDialog = noteDialog
return noteDialog
end
function addon:ShowNoteDialog(mapKey, noteIndex, defaultName)
self.editMapKey = mapKey
self.editNoteIndex = noteIndex
self.dialogDefaultName = defaultName or ""
local dialog = self:GetNoteDialog()
dialog:ClearAllPoints()
dialog:SetPoint("CENTER", WorldMapFrame, "CENTER", 0, 0)
dialog:Show()
end
function addon:ShowDeleteDialog(mapKey, noteIndex)
self.deleteMapKey = mapKey
self.deleteNoteIndex = noteIndex
self.pendingX = nil
self.pendingY = nil
self.editMapKey = nil
self.editNoteIndex = nil
if self.noteDialog and self.noteDialog:IsShown() then
self.noteDialog:Hide()
end
local dialog = self:GetDeleteDialog()
dialog:ClearAllPoints()
dialog:SetPoint("CENTER", WorldMapFrame, "CENTER", 0, 0)
dialog:SetFrameLevel(WorldMapFrame:GetFrameLevel() + 25)
dialog:Show()
end
function addon:HandlePinClick(pin, click)
if not pin or not pin.noteIndex then
return
end
if click ~= "LeftButton" and click ~= "RightButton" then
return
end
local mapKey = self:GetMapKey()
local notes = ForgedMapNotesDB.notes and ForgedMapNotesDB.notes[mapKey]
local note = notes and notes[pin.noteIndex]
if not note then
return
end
if click == "RightButton" then
self:ShowDeleteDialog(mapKey, pin.noteIndex)
return
end
self.pendingX = nil
self.pendingY = nil
self:ShowNoteDialog(mapKey, pin.noteIndex, note.name or "")
end
function addon:HideDialogs()
if self.noteDialog and self.noteDialog:IsShown() then
self.noteDialog:Hide()
end
if self.deleteDialog and self.deleteDialog:IsShown() then
self.deleteDialog:Hide()
end
end