-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranslit.lua
185 lines (151 loc) · 6.24 KB
/
Translit.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
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
local f = CreateFrame("Frame")
local options = {}
local config = CreateFrame("Frame")
config.name = "Translit"
local configOpenRunOnce = false
local LibTranslit = LibStub("LibTranslit-1.0")
local function Chat(self, event, msg, author, ...)
msg = LibTranslit:Transliterate(msg, options.mark)
author = LibTranslit:Transliterate(author, options.mark)
return false, msg, author, ...
end
local function ChatHeader(self, arg1, arg2, arg3)
if lastHookChatFrame1EditBoxHeader == arg2 then
return
else
if arg3 then
name = LibTranslit:Transliterate(arg3, options.mark)
lastHookChatFrame1EditBoxHeader = name
self:SetFormattedText(arg1, arg2, name)
else
name = LibTranslit:Transliterate(arg2, options.mark)
lastHookChatFrame1EditBoxHeader = name
self:SetFormattedText(arg1, name)
end
end
end
local function SetupChat()
local lastHookChatFrame1EditBoxHeader = nil
hooksecurefunc(ChatFrame1EditBoxHeader, "SetFormattedText", ChatHeader)
ChatFrame_AddMessageEventFilter("CHAT_MSG_ACHIEVEMENT", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_HORDE", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_ALLIANCE", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_NEUTRAL", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_DND", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_EMOTE", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_TEXT_EMOTE", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT_LEADER", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_BOSS_EMOTE", Chat)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_BOSS_WHISPER", Chat)
end
local function Tooltip(self)
for i=1, self:NumLines() do
local text = _G["GameTooltipTextLeft"..i]
if text then
text:SetText(((LibTranslit:Transliterate(text:GetText(), options.mark) or "")))
end
end
end
local function SetupTooltip()
hooksecurefunc(GameTooltip, "Show", Tooltip)
end
local function SetupConfig(c)
if configOpenRunOnce then
return
end
configOpenRunOnce = true
config.title = config:CreateFontString("TranslitConfigTitle", "ARTWORK", "GameFontNormal")
config.title:SetFont(GameFontNormal:GetFont(), 16, "OUTLINE")
config.title:SetPoint("TOPLEFT", config, 10, -10)
config.title:SetText(config.name)
config.markBoxTitle = config:CreateFontString("TranslitMarkBoxTitle", "ARTWORK", "GameFontNormal")
config.markBoxTitle:SetFont(GameFontNormal:GetFont(), 12, "OUTLINE")
config.markBoxTitle:SetPoint("TOPLEFT", config, 10, -50)
config.markBoxTitle:SetText("|cffffffff" .. "Transliteration Mark: " .. "|r")
config.markBox = CreateFrame("EditBox", "TranslitMarkBox", config, "InputBoxTemplate")
config.markBox:SetPoint("TOPLEFT", config, 150, -46)
config.markBox:SetSize(20, 20)
config.markBox:SetAutoFocus(false)
config.markBox:SetMultiLine(false)
config.markBox:SetText(options.mark)
config.markBox:SetCursorPosition(0)
config.markBox:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
config.chatButton = CreateFrame("CheckButton", "TranslitChatButton", config, "InterfaceOptionsCheckButtonTemplate")
config.chatButton:SetPoint("TOPLEFT", config, 10, -80)
config.chatButton:SetChecked(options.chat)
config.chatButton:SetHitRectInsets(0, -200, 0, 0)
config.chatButtonTitle = config:CreateFontString("TranslitChatButtonTitle", "ARTWORK", "GameFontNormal")
config.chatButtonTitle:SetFont(GameFontNormal:GetFont(), 12, "OUTLINE")
config.chatButtonTitle:SetPoint("LEFT", config.chatButton, 30, 0)
config.chatButtonTitle:SetText("|cffffffff Translit Chat|r")
config.tooltipButton = CreateFrame("CheckButton", "TranslitTooltipButton", config, "InterfaceOptionsCheckButtonTemplate")
config.tooltipButton:SetPoint("TOPLEFT", config, 10, -110)
config.tooltipButton:SetChecked(options.tooltip)
config.tooltipButton:SetHitRectInsets(0, -200, 0, 0)
config.tooltipButtonTitle = config:CreateFontString("TranslitTooltipButtonTitle", "ARTWORK", "GameFontNormal")
config.tooltipButtonTitle:SetFont(GameFontNormal:GetFont(), 12, "OUTLINE")
config.tooltipButtonTitle:SetPoint("LEFT", config.tooltipButton, 30, 0)
config.tooltipButtonTitle:SetText("|cffffffff Translit Tooltip|r")
config.okay = function(self)
TranslitSaved.mark = config.markBox:GetText()
TranslitSaved.chat = config.chatButton:GetChecked()
TranslitSaved.tooltip = config.tooltipButton:GetChecked()
options = TranslitSaved
end
config.cancel = function(self)
config.markBox:SetText(options.mark)
config.chatButton:SetChecked(options.chat)
config.tooltipButton:SetChecked(options.tooltip)
end
InterfaceOptions_AddCategory(config)
end
function f:PLAYER_LOGIN()
SetupConfig()
if options.chat then
SetupChat()
end
if options.tooltip then
SetupTooltip()
end
end
function f:ADDON_LOADED(addon)
if addon == "Translit" then
f:UnregisterEvent("ADDON_LOADED")
local defaults = {
mark = "!",
chat = true,
tooltip = true
}
TranslitSaved = TranslitSaved or {}
for k,v in pairs(defaults) do
if TranslitSaved[k] == nil then
TranslitSaved[k] = v
end
end
options = TranslitSaved
SLASH_TRANSLIT1 = "/translit"
SlashCmdList.TRANSLIT = function(msg)
InterfaceOptionsFrame_Show()
InterfaceOptionsFrame_OpenToCategory(config)
end
f:RegisterEvent("PLAYER_LOGIN")
end
end
f:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...)
end)
f:RegisterEvent("ADDON_LOADED")