Skip to content

Commit e14844d

Browse files
committed
first export save
1 parent c71b871 commit e14844d

File tree

3 files changed

+296
-31
lines changed

3 files changed

+296
-31
lines changed

Myslot.toc

+3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
## Notes-zhTW: @localization(locale="zhTW", key="TOC_NOTES")@
1414
## Author: Boshi Lian
1515
## Version: @project-version@
16+
## SavedVariables: MyslotExports
17+
1618

1719
libs\base64.lua
1820
libs\crc32.lua
1921
libs\lua-pb\lua-pb.xml
2022

2123
protobuf\Myslot.lua
2224

25+
event.lua
2326
locales.lua
2427
keys.lua
2528
Myslot.lua

event.lua

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local ADDONNAME, ADDONSELF = ...
2+
3+
local f = CreateFrame("Frame")
4+
local m = {}
5+
f:SetScript("OnEvent", function(self, event, ...)
6+
if event == "ADDON_LOADED" then
7+
local name = select(1, ...)
8+
9+
if ADDONNAME ~= name then
10+
return
11+
end
12+
end
13+
14+
local cbs = m[event]
15+
if cbs then
16+
for _, cb in pairs(cbs) do
17+
cb(...)
18+
end
19+
end
20+
end)
21+
22+
ADDONSELF.regevent = function(event, cb)
23+
if not m[event] then
24+
m[event] = {}
25+
end
26+
27+
f:RegisterEvent(event)
28+
table.insert(m[event] , cb)
29+
end

gui.lua

+264-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local _, MySlot = ...
22

33
local L = MySlot.L
4+
local RegEvent = MySlot.regevent
45

56

67
local f = CreateFrame("Frame", nil, UIParent)
@@ -43,38 +44,38 @@ end
4344

4445
-- export editbox
4546
local exportEditbox
46-
do
47-
local t = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
48-
t:EnableMouse(true)
49-
t:SetPoint("TOPLEFT", f, 25, -30)
50-
t:SetWidth(580)
51-
t:SetHeight(500)
52-
local edit = CreateFrame("EditBox", nil, t)
53-
edit:SetWidth(560)
54-
edit:SetHeight(480)
55-
edit:SetPoint("TOPLEFT", t, 0, 0)
56-
edit:SetAutoFocus(false)
57-
edit:SetMaxLetters(99999999)
58-
edit:SetMultiLine(true)
59-
edit:SetFontObject(GameTooltipTextSmall)
60-
edit:SetScript("OnTextChanged", function(self)
61-
ScrollingEdit_OnTextChanged(self, t)
62-
end)
63-
edit:SetScript("OnCursorChanged", ScrollingEdit_OnCursorChanged)
64-
edit:SetScript("OnUpdate", function(self, elapsed)
65-
ScrollingEdit_OnUpdate(self, elapsed, t)
66-
end)
67-
edit:SetScript("OnEscapePressed", edit.ClearFocus)
68-
edit:SetScript("OnTextSet", edit.HighlightText)
69-
edit:SetScript("OnMouseUp", edit.HighlightText)
47+
-- do
48+
-- local t = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
49+
-- t:EnableMouse(true)
50+
-- t:SetPoint("TOPLEFT", f, 25, -30)
51+
-- t:SetWidth(580)
52+
-- t:SetHeight(500)
53+
-- local edit = CreateFrame("EditBox", nil, t)
54+
-- edit:SetWidth(560)
55+
-- edit:SetHeight(480)
56+
-- edit:SetPoint("TOPLEFT", t, 0, 0)
57+
-- edit:SetAutoFocus(false)
58+
-- edit:SetMaxLetters(99999999)
59+
-- edit:SetMultiLine(true)
60+
-- edit:SetFontObject(GameTooltipTextSmall)
61+
-- edit:SetScript("OnTextChanged", function(self)
62+
-- ScrollingEdit_OnTextChanged(self, t)
63+
-- end)
64+
-- edit:SetScript("OnCursorChanged", ScrollingEdit_OnCursorChanged)
65+
-- edit:SetScript("OnUpdate", function(self, elapsed)
66+
-- ScrollingEdit_OnUpdate(self, elapsed, t)
67+
-- end)
68+
-- edit:SetScript("OnEscapePressed", edit.ClearFocus)
69+
-- edit:SetScript("OnTextSet", edit.HighlightText)
70+
-- edit:SetScript("OnMouseUp", edit.HighlightText)
7071

71-
t:SetScript("OnMouseDown", function()
72-
edit:SetFocus()
73-
end)
72+
-- t:SetScript("OnMouseDown", function()
73+
-- edit:SetFocus()
74+
-- end)
7475

75-
t:SetScrollChild(edit)
76-
exportEditbox = edit
77-
end
76+
-- t:SetScrollChild(edit)
77+
-- exportEditbox = edit
78+
-- end
7879

7980
-- close
8081
do
@@ -136,10 +137,226 @@ do
136137
b:SetScript("OnClick", function()
137138
local s = MySlot:Export()
138139
exportEditbox:SetText(s)
139-
ScrollingEdit_SetCursorOffsets(exportEditbox, 0, 0)
140140
end)
141141
end
142142

143+
144+
145+
RegEvent("ADDON_LOADED", function()
146+
do
147+
local t = CreateFrame("Frame", nil, f)
148+
t:SetWidth(600)
149+
t:SetHeight(400)
150+
t:SetPoint("TOPLEFT", f, 25, -75)
151+
t:SetBackdrop({
152+
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
153+
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
154+
tile = true,
155+
tileEdge = true,
156+
tileSize = 16,
157+
edgeSize = 16,
158+
insets = { left = -2, right = -2, top = -2, bottom = -2 },
159+
})
160+
t:SetBackdropColor(0, 0, 0, 0)
161+
162+
local s = CreateFrame("ScrollFrame", nil, t, "UIPanelScrollFrameTemplate")
163+
s:SetWidth(560)
164+
s:SetHeight(375)
165+
s:SetPoint("TOPLEFT", 10, -10)
166+
167+
168+
local edit = CreateFrame("EditBox", nil, s)
169+
s.cursorOffset = 0
170+
edit:SetWidth(550)
171+
s:SetScrollChild(edit)
172+
edit:SetAutoFocus(false)
173+
edit:EnableMouse(true)
174+
edit:SetMaxLetters(99999999)
175+
edit:SetMultiLine(true)
176+
edit:SetFontObject(GameTooltipText)
177+
-- edit:SetScript("OnTextChanged", function(self)
178+
-- ScrollingEdit_OnTextChanged(self, s)
179+
-- end)
180+
-- edit:SetScript("OnUpdate", function(self, elapsed)
181+
-- ScrollingEdit_OnUpdate(self, elapsed, s)
182+
-- end)
183+
-- edit:SetScript("OnCursorChanged", function(self)
184+
-- ScrollingEdit_OnCursorChanged(self)
185+
-- -- ScrollingEdit_OnUpdate(self, 0, s)
186+
-- end)
187+
edit:SetScript("OnEscapePressed", edit.ClearFocus)
188+
edit:SetScript("OnTextSet", edit.HighlightText)
189+
edit:SetScript("OnMouseUp", edit.HighlightText)
190+
191+
t:SetScript("OnMouseDown", function()
192+
edit:SetFocus()
193+
end)
194+
195+
exportEditbox = edit
196+
end
197+
198+
do
199+
local t = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
200+
t:SetPoint("TOPLEFT", f, 5, -45)
201+
UIDropDownMenu_SetWidth(t, 200)
202+
203+
-- local tt = t:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
204+
-- tt:SetPoint("BOTTOMLEFT", t, "TOPLEFT", 20, 0)
205+
-- tt:SetText(L["Saved exported text"])
206+
207+
if not MyslotExports then
208+
MyslotExports = {}
209+
end
210+
if not MyslotExports["exports"] then
211+
MyslotExports["exports"] = {}
212+
end
213+
local exports = MyslotExports["exports"]
214+
215+
local onclick = function(self)
216+
local idx = self.value
217+
UIDropDownMenu_SetSelectedValue(t, idx)
218+
219+
local n = exports[idx] and exports[idx].name or ""
220+
UIDropDownMenu_SetText(t, n)
221+
222+
local v = exports[idx] and exports[idx].value or ""
223+
exportEditbox:SetText(v)
224+
end
225+
226+
local create = function(name)
227+
local txt = {
228+
name = name
229+
}
230+
table.insert(exports, txt)
231+
232+
local info = UIDropDownMenu_CreateInfo()
233+
info.text = txt.name
234+
info.value = #exports
235+
info.func = onclick
236+
UIDropDownMenu_AddButton(info)
237+
end
238+
239+
local save = function(force)
240+
local c = UIDropDownMenu_GetSelectedValue(t)
241+
local v = exportEditbox:GetText()
242+
if not force and v == "" then
243+
return
244+
end
245+
if (not c) or (not exports[c]) then
246+
local n = date()
247+
create(n)
248+
UIDropDownMenu_SetSelectedValue(t, #exports)
249+
UIDropDownMenu_SetText(t, n)
250+
c = #exports
251+
end
252+
253+
exports[c].value = v
254+
end
255+
-- exportEditbox:SetScript("OnTextChanged", function() save(false) end)
256+
257+
UIDropDownMenu_Initialize(t, function()
258+
for i, txt in pairs(exports) do
259+
-- print(txt.name)
260+
local info = UIDropDownMenu_CreateInfo()
261+
info.text = txt.name
262+
info.value = i
263+
info.func = onclick
264+
UIDropDownMenu_AddButton(info)
265+
end
266+
end)
267+
268+
local popctx = {}
269+
270+
StaticPopupDialogs["MYSLOT_EXPORT_TITLE"].OnShow = function(self)
271+
local c = popctx.current
272+
273+
if c and exports[c] then
274+
self.editBox:SetText(exports[c].name or "")
275+
end
276+
end
277+
278+
279+
StaticPopupDialogs["MYSLOT_EXPORT_TITLE"].OnAccept = function(self)
280+
local c = popctx.current
281+
282+
-- if c then rename
283+
if c and exports[c] then
284+
local n = self.editBox:GetText()
285+
if n ~= "" then
286+
exports[c].name = n
287+
UIDropDownMenu_SetText(t, n)
288+
end
289+
return
290+
end
291+
292+
create(self.editBox:GetText())
293+
onclick({value = #exports})
294+
end
295+
296+
do
297+
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
298+
b:SetWidth(70)
299+
b:SetHeight(25)
300+
b:SetPoint("TOPLEFT", t, 240, 0)
301+
b:SetText(NEW)
302+
b:SetScript("OnClick", function()
303+
popctx.current = nil
304+
StaticPopup_Show("MYSLOT_EXPORT_TITLE")
305+
end)
306+
end
307+
308+
do
309+
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
310+
b:SetWidth(70)
311+
b:SetHeight(25)
312+
b:SetPoint("TOPLEFT", t, 315, 0)
313+
b:SetText(SAVE)
314+
b:SetScript("OnClick", function() save(true) end)
315+
end
316+
317+
do
318+
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
319+
b:SetWidth(70)
320+
b:SetHeight(25)
321+
b:SetPoint("TOPLEFT", t, 390, 0)
322+
b:SetText(DELETE)
323+
b:SetScript("OnClick", function()
324+
local c = UIDropDownMenu_GetSelectedValue(t)
325+
326+
if c then
327+
table.remove( exports, c)
328+
end
329+
330+
if #exports == 0 then
331+
UIDropDownMenu_SetSelectedValue(t, nil)
332+
UIDropDownMenu_SetText(t, "")
333+
exportEditbox:SetText("")
334+
else
335+
onclick({value = #exports})
336+
end
337+
end)
338+
end
339+
340+
do
341+
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
342+
b:SetWidth(70)
343+
b:SetHeight(25)
344+
b:SetPoint("TOPLEFT", t, 465, 0)
345+
b:SetText(L["Rename"])
346+
b:SetScript("OnClick", function()
347+
local c = UIDropDownMenu_GetSelectedValue(t)
348+
349+
if c and exports[c] then
350+
popctx.current = c
351+
StaticPopup_Show("MYSLOT_EXPORT_TITLE")
352+
end
353+
end)
354+
end
355+
356+
end
357+
358+
end)
359+
143360
SlashCmdList["MYSLOT"] = function(msg, editbox)
144361
local cmd, what = msg:match("^(%S*)%s*(%S*)%s*$")
145362

@@ -160,3 +377,19 @@ StaticPopupDialogs["MYSLOT_MSGBOX"] = {
160377
hideOnEscape = 1,
161378
multiple = 0,
162379
}
380+
381+
StaticPopupDialogs["MYSLOT_EXPORT_TITLE"] = {
382+
text = L["Name of exported text"],
383+
button1 = ACCEPT,
384+
button2 = CANCEL,
385+
hasEditBox = true,
386+
timeout = 0,
387+
whileDead = 1,
388+
hideOnEscape = 1,
389+
multiple = 0,
390+
OnAccept = function()
391+
end,
392+
OnShow = function()
393+
end,
394+
}
395+

0 commit comments

Comments
 (0)