-
Notifications
You must be signed in to change notification settings - Fork 0
/
DictFrame.lua
130 lines (110 loc) · 3.32 KB
/
DictFrame.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
DictResult = {}
-- close frame by esc
tinsert(UISpecialFrames, DictFrame:GetName())
tinsert(UISpecialFrames, DictLogFrame:GetName())
DictFrame:RegisterEvent("ADDON_LOADED")
DictFrame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "wowdict" then
for i = 1, table.getn(DictKeys) do
local button = CreateFrame("button","DictFrameTab"..i, DictFrame, "DictFrameTabTemplate")
button:SetID(i)
button:SetText(DictKeys[i])
if i == 1 then
button:SetPoint("BOTTOMLEFT", -2, -30)
else
button:SetPoint("BOTTOMLEFT", "DictFrameTab"..(i-1), "BOTTOMRIGHT")
end
button:SetScript("OnShow", function(self)
self:SetWidth(0);
PanelTemplates_TabResize(self, i, nil);
end)
end
DictFrame.numTabs = table.getn(DictKeys);
if DictFrame_LastSelectedTab == nil then
PanelTemplates_SetTab(DictFrame, 1);
else
PanelTemplates_SetTab(DictFrame, DictFrame_LastSelectedTab);
end
if DictLog == nil then
DictLog = {}
end
end
end)
function DictFrame_LookUp(word, shouldLog)
if DictLog == nil then
DictLog = {}
end
DictResult = {}
local hasResult = false
for k, v in pairs(DictSource) do
if v["data"] then
DictResult[k] = nil
for i = 1, table.getn(v["data"]) do
if (v["data"][i][word]) then
DictResult[k] = v["data"][i][word]
hasResult = true
break
end
end
end
end
if hasResult then
DictFrameWord:SetText(word);
if shouldLog then
AddToDictLog(word)
end
DictFrame_Update()
end
end
function DictFrame_Update()
local result;
local dictKey = DictKeys[DictFrame.selectedTab];
DictFrame_LastSelectedTab = DictFrame.selectedTab;
result = DictResult[dictKey];
DictScrollFrame:SetVerticalScroll(0);
if (result) then
DictFramePronounciation:SetText(result["pron"]);
DictFrameDefinition:SetText(result["def"]);
DictFrameSource:SetText(DictSource[dictKey]["source"]);
else
DictFramePronounciation:SetText("");
DictFrameDefinition:SetText(DictSource[dictKey]["noResultText"]);
DictFrameSource:SetText("");
end
ShowUIPanel(DictFrame)
ShowUIPanel(DictScrollChildFrame)
local pronHeight = DictFramePronounciation:GetStringHeight()
DictFrameDefinition:SetPoint("TOPLEFT", 20, -(pronHeight + 20))
local definitionHeight = DictFrameDefinition:GetStringHeight()
DictFrameSource:SetPoint("TOPLEFT", 20, -(pronHeight + 20 + definitionHeight + 60))
end
SLASH_LOOKUP1 = "/d"
SLASH_LOOKUP2 = "/dict"
SlashCmdList["LOOKUP"] = function(msg)
DictFrame_LookUp(msg, true);
end
function AddToDictLog(msg)
local currentDate = date("%Y%m%d%H%M%S")
local currentLog = nil;
for k, v in ipairs(DictLog) do
if (v and v[1] == msg) then
currentLog = v;
DictLog[k] = false;
break
end
end
if currentLog then
table.insert(DictLog, { msg, currentLog[2] + 1, currentDate })
else
table.insert(DictLog, { msg, 1, currentDate })
end
end
-- SLASH_DICTEXPORT1 = "/dictexport"
-- SlashCmdList["DICTEXPORT"] = function(msg)
-- print("Log:")
-- -- print(table.concat(DictLog,", "))
-- ShowUIPanel(DictExportFrame)
-- -- DictExportEditBox:SetText(table.concat(DictLog,", "))
-- DictExportEditBox:HighlightText()
-- print("DictExportEditBox:", DictExportEditBox)
-- end