ruen-ui/RuenUI/Controls.lua

228 lines
16 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local _, P = ...
-- Only this small set migrates on an existing character: combat slots, graphics,
-- ESDF, pet controls and personal action assignments are left alone.
P.controlsVersion = 1
P.menuBindings = {
{"N", "TOGGLEWORLDMAP"}, {"SHIFT-N", "TOGGLEBATTLEFIELDMINIMAP"},
{"I", "OPENALLBAGS"}, {"J", "TOGGLEQUESTLOG"}, {"ALT-J", "SPOKEN_COMPENDIUM"},
{"K", "TOGGLECHARACTER0"}, {"SHIFT-K", "TOGGLETALENTS"},
{"CTRL-K", "TOGGLECHARACTER2"}, {"ALT-K", "TOGGLECURRENCY"},
{"P", "TOGGLESPELLBOOK"}, {"SHIFT-P", "TOGGLEPROFESSIONBOOK"},
{"CTRL-P", "TOGGLEPETBOOK"},
{"L", "TOGGLEGROUPFINDER"}, {"SHIFT-L", "TOGGLELEGACYSYSTEM"},
{"O", "TOGGLESOCIAL"}, {"SHIFT-O", "TOGGLEGUILDTAB"},
{"CTRL-O", "TOGGLERAIDTAB"}, {"ALT-O", "TOGGLEWHOTAB"},
{"Y", "TOGGLECOLLECTIONS"}, {"SHIFT-Y", "TOGGLECOLLECTIONSMOUNTJOURNAL"},
{"CTRL-Y", "TOGGLECOLLECTIONSTOYBOX"}, {"ALT-Y", "TOGGLECOLLECTIONSWARDROBE"},
{"SHIFT-J", "TOGGLEENCOUNTERJOURNAL"}, {"CTRL-J", "TOGGLEACHIEVEMENT"},
{"F6", "NAMEPLATES"}, {"SHIFT-F6", "ALLNAMEPLATES"}, {"CTRL-F6", "FRIENDNAMEPLATES"},
{"F8", "RUENUI_MACROS"}, {"F9", "RUENUI_SETTINGS"},
{"SHIFT-F9", "RUENUI_KEYBINDINGS"}, {"F10", "TOGGLEHOUSINGDASHBOARD"},
{"F12", "RUENUI_HELP"}, {"SHIFT-F12", "RUENUI_SUPPORT"},
}
local function say(text) print("|cff60d5ffRuen UI:|r " .. P.Translate(text)) end
function P.ApplyUtilityBindings(force)
if InCombatLockdown() then return false end
local scope = GetCurrentBindingSet() == 1 and RuenUIDB or RuenUICharacter
-- Independent one-time addition: never replay the existing menu migration
-- or take over a key already used by the player or an active override.
if not scope.graveAutorunChecked then
local previous = GetBindingAction("`", true)
if not previous or previous == "" then
if not SetBinding("`", "TOGGLEAUTORUN") then return false end
RuenUICharacter.bindingChanges = RuenUICharacter.bindingChanges or {}
local changes = RuenUICharacter.bindingChanges
changes["`"] = changes["`"] or {before = ""}
changes["`"].applied = "TOGGLEAUTORUN"
SaveBindings(GetCurrentBindingSet())
say("Grave (`) now toggles autorun.")
elseif previous ~= "TOGGLEAUTORUN" then
say("Grave (`) is already bound; its shortcut was preserved.")
end
scope.graveAutorunChecked = true
end
local available = {}
for i = 1, GetNumBindings() do
local action = GetBinding(i)
available[action] = true
end
RuenUICharacter.bindingChanges = RuenUICharacter.bindingChanges or {}
local changes = RuenUICharacter.bindingChanges
local missing = {}
local function bind(key, action)
if action and not available[action] then missing[#missing + 1] = key .. ": " .. action; return end
local before = GetBindingAction(key)
if before == (action or "") then return end
if not SetBinding(key, action) then error("Could not bind " .. key) end
changes[key] = changes[key] or {before = before}
changes[key].applied = action or ""
end
-- Add the Compendium key to already-configured binding sets without
-- replaying other menu defaults. Retry later if Spoken is not available.
if (force or scope.compendiumBindingVersion ~= 1) and available.SPOKEN_COMPENDIUM then
bind("ALT-J", "SPOKEN_COMPENDIUM")
SaveBindings(GetCurrentBindingSet())
scope.compendiumBindingVersion = 1
end
if not force and scope.controlsVersion == P.controlsVersion then return false end
-- M is deliberately free. N is navigation; nameplates move off the letter keys.
bind("M", nil)
bind("SPACE", "JUMP")
for _, modifier in ipairs({"", "SHIFT-", "CTRL-", "CTRL-SHIFT-"}) do
bind(modifier .. "BUTTON3", "JUMP")
bind(modifier .. "BUTTON4", "TARGETPREVIOUSENEMY")
bind(modifier .. "BUTTON5", "TARGETNEARESTENEMY")
end
bind("TAB", "TARGETNEARESTENEMY")
bind("SHIFT-TAB", "TARGETPREVIOUSENEMY")
for _, entry in ipairs(P.menuBindings) do bind(entry[1], entry[2]) end
SaveBindings(GetCurrentBindingSet())
scope.controlsVersion = P.controlsVersion
RuenUICharacter.unavailableMenuBindings = missing
say("Mouse: middle = jump; rear thumb = previous enemy; front thumb = next. N = map; M is free. /ruen help shows shortcuts.")
if #missing > 0 then say("Menus unavailable in this client: " .. table.concat(missing, "; ")) end
return true
end
function P.OpenMenu(which)
if InCombatLockdown() then say("Open this menu after combat."); return end
if which == "macros" then
if C_AddOns.LoadAddOn then C_AddOns.LoadAddOn("Blizzard_MacroUI") end
if ShowMacroFrame then ShowMacroFrame() end
elseif which == "settings" then
if Settings and Settings.OpenToCategory and Settings.INTERFACE_CATEGORY_ID then
Settings.OpenToCategory(Settings.INTERFACE_CATEGORY_ID)
elseif ToggleGameMenu then ToggleGameMenu() end
elseif which == "keybindings" then
if Settings and Settings.OpenToCategory and Settings.KEYBINDINGS_CATEGORY_ID then
Settings.OpenToCategory(Settings.KEYBINDINGS_CATEGORY_ID)
elseif ToggleGameMenu then ToggleGameMenu() end
elseif which == "support" and ToggleHelpFrame then ToggleHelpFrame() end
end
function P.Help()
say(P.BarHelp())
say(P.Localized("/ruen role auto|healer|tank|damage: mouseover default follows the selected role. /ruen mouseover on|off overrides it. Cooldown and meter modes are per character.",
"/ruen role auto|healer|tank|damage: наведение зависит от выбранной роли. /ruen mouseover on|off задаёт свой режим. Перезарядки и счётчики настраиваются для каждого персонажа."))
say(P.Localized("/ruen guns on|off|settings|status; /ruen guns 100: softer gunshots, volume 10–100. Nearby stock gunshots are muted while enabled.",
"/ruen guns on|off|settings|status; /ruen guns 100: тихие выстрелы, громкость 10–100. Стандартные выстрелы окружающих при включении заглушаются."))
say(P.Localized("/ruen cooldowns auto|show|hide|off|settings|status: class-aware timers. /ruen mouseover auto|on|off: per-character casting preference.",
"/ruen cooldowns auto|show|hide|off|settings|status: таймеры класса. /ruen mouseover auto|on|off: наведение для персонажа."))
say(P.Localized("/ruen meters auto|show|off: native damage/healing meter; auto shows in dungeons and raids.",
"/ruen meters auto|show|off: встроенный счётчик урона/исцеления; auto — в подземельях и рейдах."))
say(P.Localized("Alt now selects action buttons. Automatic self-cast stays on; use F1 to target yourself. Ctrl+Shift+F11 hides/shows the UI.", "Alt выбирает кнопки действий. Автовыбор себя включён; F1 — выбрать себя. Ctrl+Shift+F11 скрывает интерфейс."))
say(P.Localized("/ruen optimize [FPS]: retune this area (default 60 or your saved target). optimize pause|resume|status|changes|restore. /ruen bench: frame times and hitches.","/ruen optimize [FPS]: настройка текущей зоны (60 или сохранённая цель). optimize pause|resume|status|changes|restore. /ruen bench: время кадров и рывки."))
say(P.Localized("/ruen swing on|off|preview: thin attack timers. /ruen lock | unlock: lock or drag action and pet abilities normally outside combat.",
"/ruen swing on|off|preview: таймеры атак. /ruen unlock: свободное перемещение способностей, включая питомца, вне боя."))
say("Grave (`): autorun, added only if the key was unbound.")
say("ESDF movement; Space/middle mouse jump. Rear thumb/Shift-Tab previous enemy; front thumb/Tab next enemy.")
say(P.Localized("Combat: Q W R T / A G H / Z X C V B. Rows bottom to top: base, Shift, Ctrl, Alt. /ruen lock | unlock.", "Бой: Q W R T / A G H / Z X C V B. Ряды снизу вверх: без модификатора, Shift, Ctrl, Alt. /ruen lock | unlock."))
say("N map, Shift-N zone map; I bags; J quests, Alt-J Compendium; K character; Shift-K talents; Ctrl-K reputation; Alt-K currency.")
say("P spells, Shift-P professions, Ctrl-P pet spells; L group finder, Shift-L legacy; O friends, Shift-O guild, Ctrl-O raid, Alt-O Who.")
say("Y collections, Shift-Y mounts, Ctrl-Y toys, Alt-Y appearances; Shift-J adventure guide; Ctrl-J achievements (where available).")
say("F6 enemy nameplates, Shift-F6 all, Ctrl-F6 friendly; F8 macros; F9 settings; Shift-F9 keybindings; F10 housing (where available); Esc game menu.")
say("U interact, Shift-U assist, Alt-U ping; Ctrl-I sit, Shift-I sheathe. F12 this help; Shift-F12 support.")
say("/ruen language en|ru: game text/audio + narration; client restart required. /ruen voice en|ru: narration only, immediate. /ruen language: status.")
say(P.Localized("/ruen chat reset: restore chat size/position. /ruen layout reset: restore Ruen positions/sizes; keep graphics, keys and assigned abilities.",
"/ruen chat reset: сброс размера и положения чата. /ruen layout reset: сброс положения и размеров элементов Ruen; графика, клавиши и способности сохраняются."))
say("/ruen bindings: reapply mouse/menu keys; /ruen bags: reposition bags; /ruen pet auto: reset the two extra pet buttons. /ruen status | balanced | performance | bench | export | restore. /ruen apply reapplies gameplay/key defaults and selects the saved Ruen layout.")
end
local aliases = {en = "enUS", english = "enUS", enus = "enUS", ru = "ruRU", russian = "ruRU", ruru = "ruRU"}
local function spokenProfile()
-- Spoken 3.9 exposes reads in its public API; this is the same active AceDB
-- table its own language dropdown updates. Do not replace the table.
return SpokenEnv and SpokenEnv.Addon and SpokenEnv.Addon.db and SpokenEnv.Addon.db.profile
end
function P.LanguageStatus()
local voice, fallback
if Spoken and Spoken.GetLanguageChoice then voice, fallback = Spoken:GetLanguageChoice() end
local regional = GetAvailableLocales and {GetAvailableLocales()} or {}
local available = GetAvailableLocales and {GetAvailableLocales(true)} or {}
say("Running text: " .. tostring(GetLocale()) .. "; selected text/audio: " .. tostring(C_CVar.GetCVar("textLocale")) .. "/" .. tostring(C_CVar.GetCVar("audioLocale")) .. "; narration: " .. tostring(voice or "auto") .. "; fallback: " .. tostring(fallback or "enUS") .. ".")
say("Regional menu: " .. table.concat(regional, ", ") .. ". Full client language support: " .. table.concat(available, ", ") .. ".")
say("/ruen language en|ru changes game text/audio and narration; restart required. /ruen voice en|ru changes narration only. Available does not mean the language files have finished downloading.")
end
function P.SetLanguage(value, voiceOnly)
if value == "toggle" then value = (voiceOnly and RuenUIDB.narrationLanguage or C_CVar.GetCVar("textLocale")) == "ruRU" and "en" or "ru" end
local code = aliases[value]
if not code then say("Choose en (English) or ru (Russian). /ruen language shows current settings."); return end
local profile = spokenProfile()
if not profile or not Spoken or not Spoken.GetLanguageChoice then
say("Spoken has not initialized. Enable Spoken and Spoken_Quests, then /reload."); return
end
if Spoken.StopAll then Spoken:StopAll() end
profile.Language = profile.Language or {}
profile.Language.Voice, profile.Language.Fallback = code, "enUS"
if SpokenEnv.Options and SpokenEnv.Options.UpdateRows then SpokenEnv.Options:UpdateRows() end
RuenUIDB.narrationLanguage = code
say(P.Localized("Narration: ", "Озвучка: ") .. code .. P.Localized("; missing recordings fall back to English. Open a quest to hear the new language.", "; отсутствующие записи заменяются английскими, если они есть. Откройте задание для проверки."))
if voiceOnly then return true end
if InCombatLockdown() then say("Narration changed. Run the command after combat to change game text/audio too."); return end
local supported = code == GetLocale()
if GetAvailableLocales then
-- The default list is region-filtered, not an installed/supported locale list.
-- Battle.net lists ruRU among wowf supported_text_languages for this US install.
-- Query the full client catalog; do not spoof GetLocale or replace native APIs.
for _, locale in ipairs({GetAvailableLocales(true)}) do if locale == code then supported = true end end
end
if not supported then
say("Game text/audio did NOT change: the full client language catalog does not include " .. code .. ". In Battle.net > WoW > gear > Game Settings / Modify Install, add that text and spoken language, then restart. Narration is already changed.")
return
end
local oldText, oldAudio = C_CVar.GetCVar("textLocale"), C_CVar.GetCVar("audioLocale")
local function set(key, text)
if Settings and Settings.GetSetting and Settings.GetSetting(key) then Settings.SetValue(key, text)
else C_CVar.SetCVar(key, text) end
if C_CVar.GetCVar(key) ~= text then error(key .. " was rejected") end
end
local function setPair(text, audio)
-- English text forces English audio inside the client. If text changes
-- first, that implicit audio update can skip the Agent notification.
-- English audio is valid with Russian text, so set it explicitly first.
if text == "enUS" then set("audioLocale", audio); set("textLocale", text)
else set("textLocale", text); set("audioLocale", audio) end
end
local ok, err = pcall(setPair, code, code)
if not ok then
pcall(setPair, oldText, oldAudio)
say("Game language change failed: " .. tostring(err) .. ". Use Battle.net's game language settings. Narration changed successfully."); return
end
RuenUIDB.requestedGameLanguage = code
say(P.Localized("Game text and audio selected: ", "Текст и звук игры: ") .. code .. P.Localized(". Fully exit WoW and relaunch through Battle.net; /reload is insufficient. If language files are missing, use Modify Install and keep English + Russian checked. Chat is not translated.", ". Полностью закройте WoW и запустите через Battle.net; /reload недостаточно. Если файлов языка нет: «Изменить установку», оставить английский и русский. Чат не переводится."))
return true
end
BINDING_HEADER_RUENUI = "Ruen UI"
BINDING_NAME_RUENUI_MACROS = P.Translate("Open macros")
BINDING_NAME_RUENUI_SETTINGS = P.Translate("Open settings")
BINDING_NAME_RUENUI_KEYBINDINGS = P.Translate("Open keybindings")
BINDING_NAME_RUENUI_HELP = P.Translate("Ruen UI help and key map")
BINDING_NAME_RUENUI_SUPPORT = P.Translate("Open Blizzard support")
-- Binding handlers only execute on the user's keypress.
RuenUI_OpenMenu = P.OpenMenu
-- Runs after the portable presets, once per account or explicit installer request.
-- A plain addon-folder copy follows the running client language on first use.
function P.InitializeLanguage()
local profile = spokenProfile()
if not profile or not Spoken or not Spoken.GetLanguageChoice then return end
local request = P.installLanguageRequest
if request and RuenUIDB.installerLanguageRequest ~= request then
-- Battle.net overrides offline Config.wtf edits. A live CVar change
-- makes the game notify the Agent of its selected text/audio locales.
-- First login may therefore need one further full game restart.
if P.SetLanguage(P.installLanguage == "ruRU" and "ru" or "en", false) then
RuenUIDB.installerLanguageRequest = request
end
elseif not RuenUIDB.narrationLanguage then
P.SetLanguage(GetLocale() == "ruRU" and "ru" or "en", true)
end
end