-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportImport.lua
More file actions
129 lines (120 loc) · 4.71 KB
/
ExportImport.lua
File metadata and controls
129 lines (120 loc) · 4.71 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
local addonName, addonTable = ...
local ReforgeLite = addonTable.ReforgeLite
local FRAME_NAME = addonName .. "ExportImport"
local L = addonTable.L
local print = addonTable.print
local firstInitialize
local function GetDataFrame(anchor)
if _G[FRAME_NAME] then
_G[FRAME_NAME]:Hide()
end
local AceGUI = LibStub("AceGUI-3.0")
local displayFrame = AceGUI:Create("Frame")
displayFrame:SetLayout("Flow")
displayFrame:SetStatusTable({ width = 525, height = 275 })
if anchor then
displayFrame:ClearAllPoints()
displayFrame:SetPoint("CENTER", anchor, "CENTER")
end
displayFrame:SetCallback("OnClose", function(widget)
AceGUI:Release(widget)
_G[FRAME_NAME] = nil
end)
displayFrame:SetCallback("OnEnterStatusBar", function(widget)
if widget.statustext:IsTruncated() then
GameTooltip:SetOwner(widget.statustext, "ANCHOR_LEFT")
GameTooltip:AddLine(widget.statustext:GetText(), nil, nil, nil, true)
GameTooltip:Show()
end
end)
displayFrame:SetCallback("OnLeaveStatusBar", GameTooltip_Hide)
local editbox = AceGUI:Create("MultiLineEditBox")
editbox:SetFullWidth(true)
editbox:SetFullHeight(true)
editbox.editBox:SetFontObject(GameFontHighlightSmall)
displayFrame:AddChild(editbox)
if not firstInitialize then
tinsert(UISpecialFrames, FRAME_NAME)
firstInitialize = true
end
_G[FRAME_NAME] = displayFrame
return displayFrame, editbox
end
function ReforgeLite:DisplayMessage(message, name, copyOnly)
local frame, editBox = GetDataFrame(self)
frame:SetTitle(L["Export"])
frame:SetStatusText(name or "")
editBox:DisableButton(true)
editBox:SetLabel()
editBox:SetText(message)
if copyOnly then
frame.status.message = message
editBox.editBox:SetFocus()
editBox.editBox:HighlightText()
editBox:SetCallback("OnLeave", function(widget) widget.editBox:HighlightText() widget:SetFocus() end)
editBox:SetCallback("OnEnter", function(widget) widget.editBox:HighlightText() widget:SetFocus() end)
editBox:SetCallback("OnTextChanged", function(widget) widget.editBox:SetText(widget.parent.status.message) widget.editBox:HighlightText() end)
end
end
function ReforgeLite:PrintLog()
self:DisplayMessage(table.concat(addonTable.printLog, "\n"), "Print Log", true)
end
function ReforgeLite:ExportJSON(preset, name)
self:DisplayMessage(C_EncodingUtil.SerializeJSON(preset), name, true)
end
function ReforgeLite:ImportData(anchor)
self:Initialize()
self:UpdateItems()
local frame, editBox = GetDataFrame(not anchor and self)
frame:SetTitle(L["Import"])
if anchor then
frame:ClearAllPoints()
frame:SetPoint("TOP", anchor, "TOP")
end
editBox:DisableButton(false)
editBox:SetLabel(L["Enter WoWSims JSON or Pawn string"])
editBox.editBox:SetFocus()
local function ParseUserInput(widget)
local userInput = widget:GetText()
if not userInput or userInput == "" then
widget.parent:SetStatusText("")
return
end
local validWoWSims, wowsims = self:ValidateWoWSimsString(userInput)
if validWoWSims then
self:ApplyWoWSimsImport(wowsims, anchor ~= nil)
widget.parent:Hide()
return
elseif type(wowsims) == "table" and wowsims.slot then
local function UpdateText(item)
if _G[FRAME_NAME] then
_G[FRAME_NAME]:SetStatusText(L["%s does not match your currently equipped %s: %s. ReforgeLite only supports equipped items."]:format(
item or self.itemSlots[wowsims.slot],
_G[self.itemSlots[wowsims.slot]],
self.itemData[wowsims.slot].item or EMPTY
))
end
end
if wowsims.itemId then
local mismatchItem = Item:CreateFromItemID(wowsims.itemId)
mismatchItem:ContinueOnItemLoad(function() UpdateText(mismatchItem:GetItemLink()) end)
else
UpdateText()
end
return
end
local validPawn, pawnValues = self:ValidatePawnString(userInput)
if pawnValues then
self:ParsePawnString(pawnValues)
widget.parent:Hide()
print(L["Pawn successfully imported."])
return
end
widget.parent:SetStatusText(wowsims or ERROR_CAPS)
end
editBox.button:SetScript("OnClick", function(btn) ParseUserInput(btn.obj) end)
editBox:SetCallback("OnTextChanged", ParseUserInput)
if self.pdb.methodOrigin == addonTable.WoWSimsOriginTag and anchor then
self:ShowMethodWindow(true)
end
end