|
1 | 1 | local name, ns = ...; |
2 | 2 |
|
3 | 3 | local AceDB = LibStub('AceDB-3.0'); |
4 | | -local AceDBOptions = LibStub("AceDBOptions-3.0"); |
5 | | -local AceConfig = LibStub("AceConfig-3.0"); |
6 | | -local AceConfigDialog = LibStub("AceConfigDialog-3.0"); |
| 4 | +local AceDBOptions = LibStub('AceDBOptions-3.0'); |
| 5 | +local AceConfig = LibStub('AceConfig-3.0'); |
| 6 | +local AceConfigDialog = LibStub('AceConfigDialog-3.0'); |
7 | 7 |
|
8 | 8 | local function SortAddons(name1, name2) |
9 | 9 | return strcmputf8i(StripHyperlinks(name1), StripHyperlinks(name2)) < 0; |
10 | 10 | end |
11 | 11 |
|
| 12 | +local currentCharacterName = UnitName('player')..' - '..GetRealmName(); |
| 13 | +local L; |
| 14 | +do |
| 15 | + L = { |
| 16 | + choose_sub = 'Select one of your currently available profiles.', |
| 17 | + default = 'Default', |
| 18 | + }; |
| 19 | + |
| 20 | + local LOCALE = GetLocale(); |
| 21 | + if LOCALE == 'deDE' then |
| 22 | + L['choose_sub'] = 'Wählt ein bereits vorhandenes Profil aus.'; |
| 23 | + L['default'] = 'Standard'; |
| 24 | + elseif LOCALE == 'frFR' then |
| 25 | + L['choose_sub'] = 'Permet de choisir un des profils déjà disponibles.'; |
| 26 | + L['default'] = 'Défaut'; |
| 27 | + elseif LOCALE == 'koKR' then |
| 28 | + L['choose_sub'] = '현재 이용할 수 있는 프로필 중 하나를 선택합니다.'; |
| 29 | + L['default'] = '기본값'; |
| 30 | + elseif LOCALE == 'esES' or LOCALE == 'esMX' then |
| 31 | + L['choose_sub'] = 'Selecciona uno de los perfiles disponibles.'; |
| 32 | + L['default'] = 'Por defecto'; |
| 33 | + elseif LOCALE == 'zhTW' then |
| 34 | + L['choose_sub'] = '從當前可用的設定檔裡面選擇一個。'; |
| 35 | + L['default'] = '預設'; |
| 36 | + elseif LOCALE == 'zhCN' then |
| 37 | + L['choose_sub'] = '从当前可用的配置文件里面选择一个。'; |
| 38 | + L['default'] = '默认'; |
| 39 | + elseif LOCALE == 'ruRU' then |
| 40 | + L['choose_sub'] = 'Выбор одного из уже доступных профилей.'; |
| 41 | + L['default'] = 'По умолчанию'; |
| 42 | + elseif LOCALE == 'itIT' then |
| 43 | + L['choose_sub'] = 'Seleziona uno dei profili attualmente disponibili.'; |
| 44 | + L['default'] = 'Predefinito'; |
| 45 | + elseif LOCALE == 'ptBR' then |
| 46 | + L['choose_sub'] = 'Selecione um de seus perfis atualmente disponíveis.'; |
| 47 | + L['default'] = 'Padrão'; |
| 48 | + end |
| 49 | +end |
| 50 | + |
12 | 51 | ns.resultCache = {}; |
13 | 52 | function ns:FindGlobal(item) |
14 | 53 | if not self.resultCache[item] then |
@@ -50,6 +89,129 @@ function ns:GetAddonNameForDB(db) |
50 | 89 | return ns.dbCache[db]; |
51 | 90 | end |
52 | 91 |
|
| 92 | +local altHandlerPrototype = {}; |
| 93 | +do |
| 94 | + local defaultProfilesProto = { |
| 95 | + ['Default'] = L['default'], |
| 96 | + }; |
| 97 | + for classID = 1, GetNumClasses() do |
| 98 | + local className, classFilename = GetClassInfo(classID); |
| 99 | + if className then |
| 100 | + defaultProfilesProto[classFilename] = className; |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + local defaultProfileCache = {}; |
| 105 | + function altHandlerPrototype:GetDefaultProfilesForCharacter(characterName) |
| 106 | + if defaultProfileCache[characterName] then |
| 107 | + return defaultProfileCache[characterName]; |
| 108 | + end |
| 109 | + local defaultProfiles = Mixin({ |
| 110 | + [characterName] = characterName, |
| 111 | + }, defaultProfilesProto); |
| 112 | + local realm = characterName:match(' %- (.+)'); |
| 113 | + if realm then |
| 114 | + defaultProfiles[realm] = realm; |
| 115 | + end |
| 116 | + |
| 117 | + defaultProfileCache[characterName] = defaultProfiles; |
| 118 | + return defaultProfiles; |
| 119 | + end |
| 120 | + |
| 121 | + function altHandlerPrototype:ListProfiles(info) |
| 122 | + local db = self.db; |
| 123 | + local characterName = info.arg; |
| 124 | + local profiles = {}; |
| 125 | + for profile, _ in pairs(db.sv.profiles) do |
| 126 | + profiles[profile] = profile; |
| 127 | + end |
| 128 | + |
| 129 | + for k, v in pairs(self:GetDefaultProfilesForCharacter(characterName)) do |
| 130 | + profiles[k] = v; |
| 131 | + end |
| 132 | + |
| 133 | + return profiles; |
| 134 | + end |
| 135 | + |
| 136 | + function altHandlerPrototype:GetCurrentProfile(info) |
| 137 | + local db = self.db; |
| 138 | + local characterName = info.arg; |
| 139 | + local currentProfile = db.sv and db.sv.profileKeys and db.sv.profileKeys[characterName]; |
| 140 | + |
| 141 | + return currentProfile; |
| 142 | + end |
| 143 | + |
| 144 | + function altHandlerPrototype:SetProfile(info, profile) |
| 145 | + local db = self.db; |
| 146 | + local characterName = info.arg; |
| 147 | + db.sv.profileKeys[characterName] = profile; |
| 148 | + end |
| 149 | +end |
| 150 | + |
| 151 | +ns.altHandlers = {}; |
| 152 | +function ns:MakeAltOptions(db) |
| 153 | + if not db.sv or not db.sv.profileKeys or not next(db.sv.profileKeys) then |
| 154 | + return nil; |
| 155 | + end |
| 156 | + local altHandler = self.altHandlers[db] or {db = db}; |
| 157 | + Mixin(altHandler, altHandlerPrototype); |
| 158 | + |
| 159 | + local group = { |
| 160 | + type = 'group', |
| 161 | + name = 'Character Profiles', |
| 162 | + inline = true, |
| 163 | + order = -1, |
| 164 | + args = {}, |
| 165 | + handler = altHandler, |
| 166 | + } |
| 167 | + local option = { |
| 168 | + name = '', -- character name |
| 169 | + desc = L['choose_sub'], |
| 170 | + type = 'select', |
| 171 | + order = 1, -- order by character name |
| 172 | + arg = '', -- character name |
| 173 | + get = 'GetCurrentProfile', |
| 174 | + set = 'SetProfile', |
| 175 | + values = 'ListProfiles', |
| 176 | + }; |
| 177 | + |
| 178 | + local orderedCharacterNames = {}; |
| 179 | + for characterName, _ in pairs(db.sv.profileKeys) do |
| 180 | + table.insert(orderedCharacterNames, characterName); |
| 181 | + end |
| 182 | + table.sort(orderedCharacterNames); |
| 183 | + orderedCharacterNames = tInvert(orderedCharacterNames); |
| 184 | + |
| 185 | + local i = 1; |
| 186 | + for characterName, _ in pairs(db.sv.profileKeys) do |
| 187 | + if characterName ~= currentCharacterName then |
| 188 | + i = i + 1; |
| 189 | + local charOption = CopyTable(option, true); |
| 190 | + charOption.name = characterName; |
| 191 | + charOption.arg = characterName; |
| 192 | + charOption.order = orderedCharacterNames[characterName] or i; |
| 193 | + group.args['char'..i] = charOption; |
| 194 | + end |
| 195 | + end |
| 196 | + if not next(group.args) then |
| 197 | + return nil; |
| 198 | + end |
| 199 | + |
| 200 | + return group; |
| 201 | +end |
| 202 | + |
| 203 | +local function DeepCopyTable(settings, ignoredValue) |
| 204 | + local copy = {}; |
| 205 | + for k, v in pairs(settings) do |
| 206 | + if type(v) == "table" and v ~= ignoredValue then |
| 207 | + copy[k] = CopyTable(v); |
| 208 | + else |
| 209 | + copy[k] = v; |
| 210 | + end |
| 211 | + end |
| 212 | + return copy; |
| 213 | +end |
| 214 | + |
53 | 215 | function ns:GetOptionsTable(skipAddons) |
54 | 216 | local options = { |
55 | 217 | type = 'group', |
@@ -105,10 +267,11 @@ function ns:GetOptionsTable(skipAddons) |
105 | 267 | table.insert(addonNames, addonName); |
106 | 268 | addonOrder[addonName] = i; |
107 | 269 |
|
108 | | - local option = CopyTable(AceDBOptions:GetOptionsTable(db), true); |
| 270 | + local option = DeepCopyTable(AceDBOptions:GetOptionsTable(db), db); |
109 | 271 | option.order = getOrder; |
110 | 272 | option.name = addonName; |
111 | 273 | option.inline = false; |
| 274 | + option.args.alts = self:MakeAltOptions(db); |
112 | 275 | options.args['profiles'..i] = option; |
113 | 276 |
|
114 | 277 | local choose = CopyTable(option.args.choose); |
|
0 commit comments