Mercurial > wow > cyborg-mmo7
comparison CyborgMMO7.lua @ 54:c9706291c141
Added per-spec bindings. This is optional and must be enabled in the addon settings.
| author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
|---|---|
| date | Fri, 03 May 2013 23:24:21 +0000 |
| parents | fb81254bd7b8 |
| children | 1236b2b22dde |
comparison
equal
deleted
inserted
replaced
| 53:4b9e27be9c68 | 54:c9706291c141 |
|---|---|
| 21 local RAT7 = { | 21 local RAT7 = { |
| 22 BUTTONS = 13, | 22 BUTTONS = 13, |
| 23 MODES = 3, | 23 MODES = 3, |
| 24 SHIFT = 0, | 24 SHIFT = 0, |
| 25 } | 25 } |
| 26 | |
| 27 local function toboolean(value) | |
| 28 if value then | |
| 29 return true | |
| 30 else | |
| 31 return false | |
| 32 end | |
| 33 end | |
| 26 | 34 |
| 27 function CyborgMMO_LoadStrings(self) | 35 function CyborgMMO_LoadStrings(self) |
| 28 -- CyborgMMO_DPrint("LoadStrings("..self:GetName()..") = "..CyborgMMO_StringTable[self:GetName()]) | 36 -- CyborgMMO_DPrint("LoadStrings("..self:GetName()..") = "..CyborgMMO_StringTable[self:GetName()]) |
| 29 self:SetText(CyborgMMO_StringTable[self:GetName()]) | 37 self:SetText(CyborgMMO_StringTable[self:GetName()]) |
| 30 end | 38 end |
| 92 return CyborgMMO7SaveData | 100 return CyborgMMO7SaveData |
| 93 end | 101 end |
| 94 | 102 |
| 95 function CyborgMMO_SetRatSaveData(objects) | 103 function CyborgMMO_SetRatSaveData(objects) |
| 96 assert(VarsLoaded) | 104 assert(VarsLoaded) |
| 97 local data = {} | 105 local specIndex |
| 106 if Settings.PerSpecBindings then | |
| 107 specIndex = GetActiveSpecGroup() | |
| 108 else | |
| 109 specIndex = 1 | |
| 110 end | |
| 111 local ratData = {} | |
| 98 for mode=1,RAT7.MODES do | 112 for mode=1,RAT7.MODES do |
| 99 data[mode] = {} | 113 ratData[mode] = {} |
| 100 for button=1,RAT7.BUTTONS do | 114 for button=1,RAT7.BUTTONS do |
| 101 if objects[mode][button] then | 115 if objects[mode][button] then |
| 102 data[mode][button] = objects[mode][button]:SaveData() | 116 ratData[mode][button] = objects[mode][button]:SaveData() |
| 103 end | 117 end |
| 104 end | 118 end |
| 105 end | 119 end |
| 106 CyborgMMO_GetSaveData().Rat = data | 120 local saveData = CyborgMMO_GetSaveData() |
| 121 if not saveData.Rat then saveData.Rat = {} end | |
| 122 saveData.Rat[specIndex] = ratData | |
| 107 end | 123 end |
| 108 | 124 |
| 109 function CyborgMMO_GetRatSaveData() | 125 function CyborgMMO_GetRatSaveData() |
| 110 return CyborgMMO_GetSaveData().Rat | 126 local specIndex |
| 127 if Settings.PerSpecBindings then | |
| 128 specIndex = GetActiveSpecGroup() | |
| 129 else | |
| 130 specIndex = 1 | |
| 131 end | |
| 132 CyborgMMO_DPrint("returning rat data for spec:", specIndex, GetActiveSpecGroup()) | |
| 133 local saveData = CyborgMMO_GetSaveData() | |
| 134 return saveData.Rat and saveData.Rat[specIndex] | |
| 111 end | 135 end |
| 112 | 136 |
| 113 local function GetSpellID(name) | 137 local function GetSpellID(name) |
| 114 local link = GetSpellLink(name) | 138 local link = GetSpellLink(name) |
| 115 if link then | 139 if link then |
| 245 local itemIDs = {} | 269 local itemIDs = {} |
| 246 local petIDs = {} | 270 local petIDs = {} |
| 247 | 271 |
| 248 -- gather all needed IDs (and trigger sync while doing so) | 272 -- gather all needed IDs (and trigger sync while doing so) |
| 249 if data.Rat then | 273 if data.Rat then |
| 250 for mode=1,RAT7.MODES do | 274 for spec,specData in pairs(data.Rat) do |
| 251 for button=1,RAT7.BUTTONS do | 275 for mode=1,RAT7.MODES do |
| 252 local data = data.Rat[mode][button] | 276 for button=1,RAT7.BUTTONS do |
| 253 if data then | 277 local buttonData = specData[mode] and specData[mode][button] |
| 254 if data.type=='item' then | 278 if buttonData then |
| 255 local itemID = data.detail | 279 if buttonData.type=='item' then |
| 256 if not GetItemInfo(itemID) then | 280 local itemID = buttonData.detail |
| 257 itemIDs[itemID] = true | 281 if not GetItemInfo(itemID) then |
| 258 end | 282 itemIDs[itemID] = true |
| 259 elseif data.type=='battlepet' then | 283 end |
| 260 local petID = data.detail | 284 elseif buttonData.type=='battlepet' then |
| 261 if not C_PetJournal.GetPetInfoByPetID(petID) then | 285 local petID = buttonData.detail |
| 262 petIDs[petID] = true | 286 if not C_PetJournal.GetPetInfoByPetID(petID) then |
| 287 petIDs[petID] = true | |
| 288 end | |
| 263 end | 289 end |
| 264 end | 290 end |
| 265 end | 291 end |
| 266 end | 292 end |
| 267 end | 293 end |
| 309 -- convert old profile | 335 -- convert old profile |
| 310 if CyborgMMO7SaveData[SaveName] and not CyborgMMO7SaveData.Settings then | 336 if CyborgMMO7SaveData[SaveName] and not CyborgMMO7SaveData.Settings then |
| 311 local oldData = CyborgMMO7SaveData[SaveName] | 337 local oldData = CyborgMMO7SaveData[SaveName] |
| 312 CyborgMMO7SaveData = {} | 338 CyborgMMO7SaveData = {} |
| 313 CyborgMMO7SaveData.Settings = oldData.Settings | 339 CyborgMMO7SaveData.Settings = oldData.Settings |
| 314 CyborgMMO7SaveData.Rat = ConvertOldRatData(oldData.Rat) | 340 -- Rat is an array, with one child per talent spec/group |
| 341 CyborgMMO7SaveData.Rat = {} | |
| 342 CyborgMMO7SaveData.Rat[1] = ConvertOldRatData(oldData.Rat) | |
| 315 CyborgMMO7SaveData[SaveName] = oldData -- for now keep the data, we may have missed something in the conversion | 343 CyborgMMO7SaveData[SaveName] = oldData -- for now keep the data, we may have missed something in the conversion |
| 316 end | 344 end |
| 317 elseif event == "PLAYER_ENTERING_WORLD" then | 345 elseif event == "PLAYER_ENTERING_WORLD" then |
| 318 EnteredWorld = true | 346 EnteredWorld = true |
| 319 elseif event == "PLAYER_REGEN_DISABLED" then | 347 elseif event == "PLAYER_REGEN_DISABLED" then |
| 320 CyborgMMO_Close() | 348 CyborgMMO_Close() |
| 349 elseif event == "ACTIVE_TALENT_GROUP_CHANGED" then | |
| 350 -- force a re-loading of bindings | |
| 351 BindingsLoaded = false | |
| 321 else | 352 else |
| 322 CyborgMMO_DPrint("Event is "..tostring(event)) | 353 CyborgMMO_DPrint("Event is "..tostring(event)) |
| 323 end | 354 end |
| 324 | 355 |
| 325 -- Fire Loading if and only if the player is in the world and vars are loaded | 356 -- Fire Loading if and only if the player is in the world and vars are loaded |
| 357 if not SettingsLoaded and VarsLoaded and AsyncDataLoaded and EnteredWorld then | |
| 358 local data = CyborgMMO_GetSaveData() | |
| 359 | |
| 360 Settings = data.Settings | |
| 361 if not Settings then | |
| 362 Settings = {} | |
| 363 data.Settings = Settings | |
| 364 end | |
| 365 if Settings.MiniMapButton == nil then | |
| 366 Settings.MiniMapButton = true | |
| 367 end | |
| 368 if Settings.CyborgButton == nil then | |
| 369 Settings.CyborgButton = true | |
| 370 end | |
| 371 if Settings.PerSpecBindings == nil then | |
| 372 Settings.PerSpecBindings = false | |
| 373 end | |
| 374 if not Settings.Cyborg then | |
| 375 Settings.Cyborg = 0.75 | |
| 376 end | |
| 377 if not Settings.Plugin then | |
| 378 Settings.Plugin = 0.75 | |
| 379 end | |
| 380 if not Settings.MiniMapButtonAngle then | |
| 381 Settings.MiniMapButtonAngle = math.rad(150) | |
| 382 end | |
| 383 | |
| 384 -- Reload Slider values: | |
| 385 CyborgMMO_SetOpenButtonSize(Settings.Cyborg) | |
| 386 CyborgMMO_SetMainPageSize(Settings.Plugin) | |
| 387 | |
| 388 CyborgMMO_SetMiniMapButton(Settings.MiniMapButton) | |
| 389 CyborgMMO_MiniMapButtonReposition(Settings.MiniMapButtonAngle) | |
| 390 CyborgMMO_SetCyborgHeadButton(Settings.CyborgButton) | |
| 391 CyborgMMO_SetPerSpecBindings(Settings.PerSpecBindings) | |
| 392 | |
| 393 SettingsLoaded = true | |
| 394 end | |
| 395 | |
| 396 -- load data AFTER the settings, because PerSpecBindings may affect what's loaded | |
| 326 if not BindingsLoaded and VarsLoaded and AsyncDataLoaded and EnteredWorld then | 397 if not BindingsLoaded and VarsLoaded and AsyncDataLoaded and EnteredWorld then |
| 327 local data = CyborgMMO_GetSaveData() | |
| 328 | |
| 329 CyborgMMO_RatPageModel:LoadData() | 398 CyborgMMO_RatPageModel:LoadData() |
| 330 BindingsLoaded = true | |
| 331 | 399 |
| 332 CyborgMMO_SetupModeCallbacks(1) | 400 CyborgMMO_SetupModeCallbacks(1) |
| 333 CyborgMMO_SetupModeCallbacks(2) | 401 CyborgMMO_SetupModeCallbacks(2) |
| 334 CyborgMMO_SetupModeCallbacks(3) | 402 CyborgMMO_SetupModeCallbacks(3) |
| 335 | 403 |
| 336 Settings = data.Settings | 404 BindingsLoaded = true |
| 337 if not Settings then | |
| 338 Settings = {} | |
| 339 Settings.MiniMapButton = true | |
| 340 Settings.CyborgButton = true | |
| 341 data.Settings = Settings | |
| 342 end | |
| 343 if not Settings.Cyborg then | |
| 344 Settings.Cyborg = 0.75 | |
| 345 end | |
| 346 if not Settings.Plugin then | |
| 347 Settings.Plugin = 0.75 | |
| 348 end | |
| 349 if not Settings.MiniMapButtonAngle then | |
| 350 Settings.MiniMapButtonAngle = math.rad(150) | |
| 351 end | |
| 352 | |
| 353 -- Reload Slider values: | |
| 354 CyborgMMO_SetOpenButtonSize(Settings.Cyborg) | |
| 355 CyborgMMO_SetMainPageSize(Settings.Plugin) | |
| 356 | |
| 357 CyborgMMO_SetMiniMapButton(Settings.MiniMapButton) | |
| 358 CyborgMMO_MiniMapButtonReposition(Settings.MiniMapButtonAngle) | |
| 359 CyborgMMO_SetCyborgHeadButton(Settings.CyborgButton) | |
| 360 | |
| 361 SettingsLoaded = true | |
| 362 end | 405 end |
| 363 end | 406 end |
| 364 | 407 |
| 365 function CyborgMMO_SetDefaultSettings() | 408 function CyborgMMO_SetDefaultSettings() |
| 366 CyborgMMO_OpenButtonPageOpenMainForm:ClearAllPoints() | 409 CyborgMMO_OpenButtonPageOpenMainForm:ClearAllPoints() |
| 387 | 430 |
| 388 function CyborgMMO_Loaded() | 431 function CyborgMMO_Loaded() |
| 389 CyborgMMO_MainPage:RegisterEvent("VARIABLES_LOADED") | 432 CyborgMMO_MainPage:RegisterEvent("VARIABLES_LOADED") |
| 390 CyborgMMO_MainPage:RegisterEvent("PLAYER_ENTERING_WORLD") | 433 CyborgMMO_MainPage:RegisterEvent("PLAYER_ENTERING_WORLD") |
| 391 CyborgMMO_MainPage:RegisterEvent("PLAYER_REGEN_DISABLED") | 434 CyborgMMO_MainPage:RegisterEvent("PLAYER_REGEN_DISABLED") |
| 435 CyborgMMO_MainPage:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") | |
| 392 end | 436 end |
| 393 | 437 |
| 394 function CyborgMMO_Close() | 438 function CyborgMMO_Close() |
| 395 CyborgMMO_MainPage:Hide() | 439 CyborgMMO_MainPage:Hide() |
| 396 end | 440 end |
| 460 else | 504 else |
| 461 CyborgMMO_OpenButtonPage:Hide() | 505 CyborgMMO_OpenButtonPage:Hide() |
| 462 end | 506 end |
| 463 CyborgMMO_OptionPageCyborgButton:SetChecked(visible) | 507 CyborgMMO_OptionPageCyborgButton:SetChecked(visible) |
| 464 if SettingsLoaded then | 508 if SettingsLoaded then |
| 465 Settings.CyborgButton = visible | 509 Settings.CyborgButton = toboolean(visible) |
| 466 end | 510 end |
| 467 end | 511 end |
| 468 | 512 |
| 469 function CyborgMMO_SetMiniMapButton(visible) | 513 function CyborgMMO_SetMiniMapButton(visible) |
| 470 if visible then | 514 if visible then |
| 472 else | 516 else |
| 473 CyborgMMO_MiniMapButton:Hide() | 517 CyborgMMO_MiniMapButton:Hide() |
| 474 end | 518 end |
| 475 CyborgMMO_OptionPageMiniMapButton:SetChecked(visible) | 519 CyborgMMO_OptionPageMiniMapButton:SetChecked(visible) |
| 476 if SettingsLoaded then | 520 if SettingsLoaded then |
| 477 Settings.MiniMapButton = visible | 521 Settings.MiniMapButton = toboolean(visible) |
| 478 end | 522 end |
| 479 end | 523 end |
| 480 | 524 |
| 525 function CyborgMMO_SetPerSpecBindings(perSpec) | |
| 526 CyborgMMO_OptionPagePerSpecBindings:SetChecked(perSpec) | |
| 527 if SettingsLoaded then | |
| 528 Settings.PerSpecBindings = toboolean(perSpec) | |
| 529 end | |
| 530 -- reload bindings if necessary (AFTER altering the setting) | |
| 531 if BindingsLoaded then | |
| 532 CyborgMMO_RatPageModel:LoadData() | |
| 533 end | |
| 534 end | |
| 535 |
