Skip to content

Commit d7d781e

Browse files
committed
Add hotkey button to toggle translation frame
1 parent 0cdeebd commit d7d781e

2 files changed

Lines changed: 152 additions & 6 deletions

File tree

Frames/MultiLanguageOptionsFrame.lua

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ local defaultOptions = {
33
ITEM_TRANSLATIONS = true,
44
SPELL_TRANSLATIONS = true,
55
NPC_TRANSLATIONS = true,
6-
SELECTED_LANGUAGE = 'en'
6+
SELECTED_LANGUAGE = 'en',
7+
SELECTED_INTERACTION = 'hover',
8+
SELECTED_HOTKEY = nil
79
}
810

911
local addonName = ...
@@ -41,7 +43,7 @@ local function InitializeOptions()
4143
languageDropdownDescription:SetText("Select language:")
4244

4345
local languageDropdown = CreateFrame("Frame", "MultiLanguageLanguageDropdown", optionsPanel, "UIDropDownMenuTemplate")
44-
languageDropdown:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -16, -26)
46+
languageDropdown:SetPoint("TOPLEFT", languageDropdownDescription, "BOTTOMLEFT", -16, -4)
4547

4648
local function OnLanguageDropdownValueChanged(self, arg1, arg2, checked)
4749
MultiLanguageOptions.SELECTED_LANGUAGE = arg1
@@ -91,6 +93,99 @@ local function InitializeOptions()
9193

9294
UIDropDownMenu_SetWidth(languageDropdown, 150)
9395
UIDropDownMenu_Initialize(languageDropdown, InitializeLanguageDropdown)
96+
97+
local interactionDropdownDescription = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontnormalSmall")
98+
interactionDropdownDescription:SetPoint("TOPLEFT", enableNpcTranslationCheckbox, "BOTTOMLEFT", 0, -8)
99+
interactionDropdownDescription:SetText("Select interaction:")
100+
101+
local interactionDropdown = CreateFrame("Frame", "MultiLanguageInteractionDropdown", optionsPanel, "UIDropDownMenuTemplate")
102+
interactionDropdown:SetPoint("TOPLEFT", interactionDropdownDescription, "BOTTOMLEFT", -16, -4)
103+
104+
local function SetSelectedInteractionText(interactionText, selectedInteractionText, checked)
105+
if checked then
106+
return selectedInteractionText
107+
end
108+
109+
return interactionText
110+
end
111+
112+
local function OnInteractionDropdownValueChanged(self, arg1, arg2, checked)
113+
MultiLanguageOptions.SELECTED_INTERACTION = arg1
114+
UIDropDownMenu_SetText(interactionDropdown, arg2)
115+
end
116+
117+
local function InitializeInteractionDropdown()
118+
local info = UIDropDownMenu_CreateInfo()
119+
local interactionText = "Hover"
120+
121+
info.text = "Hover"
122+
info.value = "hover"
123+
info.arg1 = info.value
124+
info.arg2 = info.text
125+
info.checked = MultiLanguageOptions.SELECTED_INTERACTION == "hover"
126+
info.func = OnInteractionDropdownValueChanged
127+
info.minWidth = 145
128+
interactionText = SetSelectedInteractionText(interactionText, info.text, info.checked)
129+
UIDropDownMenu_AddButton(info)
130+
131+
info.text = "Hover + hotkey"
132+
info.value = "hover-hotkey"
133+
info.arg1 = info.value
134+
info.arg2 = info.text
135+
info.checked = MultiLanguageOptions.SELECTED_INTERACTION == "hover-hotkey"
136+
info.func = OnInteractionDropdownValueChanged
137+
info.minWidth = 145
138+
interactionText = SetSelectedInteractionText(interactionText, info.text, info.checked)
139+
UIDropDownMenu_AddButton(info)
140+
141+
UIDropDownMenu_SetText(interactionDropdown, interactionText)
142+
UIDropDownMenu_SetAnchor(interactionDropdown, 16, 4, "TOPLEFT", interactionDropdown, "BOTTOMLEFT")
143+
end
144+
145+
UIDropDownMenu_SetWidth(interactionDropdown, 150)
146+
UIDropDownMenu_Initialize(interactionDropdown, InitializeInteractionDropdown)
147+
148+
local hotkeyDescription = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontnormalSmall")
149+
hotkeyDescription:SetPoint("TOPLEFT", interactionDropdown, "BOTTOMLEFT", 16, -8)
150+
hotkeyDescription:SetText("Register Hotkey (right-click to unbind):")
151+
152+
local registerHotkeyButton = CreateFrame("Button", "MultiLanguageRegisterHotkeyButton", optionsPanel, "UIPanelButtonTemplate")
153+
registerHotkeyButton:SetWidth(120)
154+
registerHotkeyButton:SetHeight(25)
155+
registerHotkeyButton:SetPoint("TOPLEFT", hotkeyDescription, "TOPLEFT", 0, -12)
156+
157+
if MultiLanguageOptions.SELECTED_HOTKEY then
158+
registerHotkeyButton:SetText(MultiLanguageOptions.SELECTED_HOTKEY)
159+
else
160+
registerHotkeyButton:SetText("Not Bound")
161+
end
162+
163+
local waitingForKey = false
164+
165+
registerHotkeyButton:SetScript("OnMouseDown", function(self, button)
166+
if button == "LeftButton" then
167+
if not waitingForKey then
168+
waitingForKey = true
169+
registerHotkeyButton:SetText("Press button..")
170+
end
171+
elseif button == "RightButton" then
172+
waitingForKey = false
173+
registerHotkeyButton:SetText("Not Bound")
174+
MultiLanguageOptions.SELECTED_HOTKEY = nil
175+
end
176+
end)
177+
178+
local function SetHotkeyButton(self, key)
179+
if waitingForKey then
180+
MultiLanguageOptions.SELECTED_HOTKEY = key
181+
registerHotkeyButton:SetText(MultiLanguageOptions.SELECTED_HOTKEY)
182+
waitingForKey = false
183+
end
184+
end
185+
186+
registerHotkeyButton:SetScript("OnKeyDown", SetHotkeyButton)
187+
registerHotkeyButton:SetPropagateKeyboardInput(true)
188+
94189
InterfaceOptions_AddCategory(optionsPanel)
95190
end
96191

MultiLanguage.lua

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ local addonName, addonTable = ...
33
local translationFrame = CreateFrame("Frame")
44
local activeItemSpellOrUnitLines = {}
55
local activeItemSpellOrUnitId = nil
6+
local hotkeyButtonPressed = false
7+
local questFrameBeingHovered = false
68
local textColorCodes = {
79
["[q]"] = "|cFFFFD100",
810
["[q0]"] = "|cFF9D9D9D",
@@ -12,6 +14,29 @@ local textColorCodes = {
1214
["[q5]"] = "|cFFFF8000"
1315
}
1416

17+
local function SetHotkeyButtonPressed(self, key, eventType)
18+
if MultiLanguageOptions.SELECTED_INTERACTION == "hover-hotkey" and MultiLanguageOptions.SELECTED_HOTKEY then
19+
if eventType == "OnKeyDown" and key == MultiLanguageOptions.SELECTED_HOTKEY then
20+
if hotkeyButtonPressed then
21+
hotkeyButtonPressed = false
22+
23+
if questFrameBeingHovered then
24+
QuestTranslationFrame:Hide()
25+
end
26+
else
27+
hotkeyButtonPressed = true
28+
29+
if questFrameBeingHovered then
30+
QuestTranslationFrame:Show()
31+
end
32+
end
33+
end
34+
end
35+
end
36+
37+
translationFrame:SetScript("OnKeyDown", function(self, key) SetHotkeyButtonPressed(self, key, "OnKeyDown") end)
38+
translationFrame:SetPropagateKeyboardInput(true)
39+
1540
local function GetDataByID(dataType, dataId)
1641
if addonTable[dataType] then
1742
languageCode = MultiLanguageOptions["SELECTED_LANGUAGE"]
@@ -77,9 +102,16 @@ local function UpdateQuestTranslationFrame()
77102
questData = GetDataByID("questData", questId)
78103

79104
if questData then
80-
QuestTranslationFrame:Show()
105+
if MultiLanguageOptions.SELECTED_INTERACTION == "hover-hotkey" then
106+
if hotkeyButtonPressed then
107+
QuestTranslationFrame:Show()
108+
end
109+
else
110+
QuestTranslationFrame:Show()
111+
end
112+
81113
languageCode = MultiLanguageOptions["SELECTED_LANGUAGE"]
82-
114+
83115
SetQuestDetails(
84116
questData.title,
85117
questData.objective,
@@ -100,7 +132,14 @@ local function UpdateQuestTranslationFrame()
100132
if questId then
101133
questData = GetDataByID("questData", questId)
102134
if questData then
103-
QuestTranslationFrame:Show()
135+
if MultiLanguageOptions.SELECTED_INTERACTION == "hover-hotkey" then
136+
if hotkeyButtonPressed then
137+
QuestTranslationFrame:Show()
138+
end
139+
else
140+
QuestTranslationFrame:Show()
141+
end
142+
104143
languageCode = MultiLanguageOptions["SELECTED_LANGUAGE"]
105144

106145
if lastQuestFrameEvent == "QUEST_PROGRESS" then
@@ -153,13 +192,16 @@ local function SetQuestHoverScripts(frame, children)
153192

154193
if questTranslationsEnabled then
155194
UpdateQuestTranslationFrame()
195+
questFrameBeingHovered = true
156196
else
157197
QuestTranslationFrame:Hide()
198+
questFrameBeingHovered = false
158199
end
159200
end)
160201

161202
frame:SetScript("OnLeave", function()
162203
QuestTranslationFrame:Hide()
204+
questFrameBeingHovered = false
163205
end)
164206

165207
if children then
@@ -207,13 +249,22 @@ local function UpdateItemSpellAndUnitTranslationFrame(itemHeader, itemText, id,
207249
local gameToolTipHeight = GameTooltip:GetHeight()
208250

209251
ItemSpellAndUnitTranslationFrame:SetWidth(gameToolTipWidth)
210-
ItemSpellAndUnitTranslationFrame:Show()
211252

212253
ItemSpellAndUnitTranslationFrameHeader:SetWidth(ItemSpellAndUnitTranslationFrame:GetWidth() - 17.5)
213254
ItemSpellAndUnitTranslationFrameHeader:Show()
214255
ItemSpellAndUnitTranslationFrameHeader:SetText(SetColorForLine(itemHeader))
215256
ItemSpellAndUnitTranslationFrameHeader:SetPoint("TOPLEFT", 10, -10)
216257

258+
if MultiLanguageOptions.SELECTED_INTERACTION == "hover-hotkey" then
259+
if hotkeyButtonPressed then
260+
ItemSpellAndUnitTranslationFrame:Show()
261+
else
262+
ItemSpellAndUnitTranslationFrame:Hide()
263+
end
264+
else
265+
ItemSpellAndUnitTranslationFrame:Show()
266+
end
267+
217268
if id ~= activeItemSpellOrUnitId then
218269
local parent = ItemSpellAndUnitTranslationFrameHeader
219270
local existingLines = #activeItemSpellOrUnitLines

0 commit comments

Comments
 (0)