View Single Post
02-20-21, 03:38 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Refresh options screen dynamically

Below are chunks of code from two files in RepByZone. I am not getting any errors. However, when the user toggles useClassRep, the inline description does not update unless a UI reload occurs. As you can see, I have tried putting a .NotifyChange at line 136, but it isn't doing anything. Therefore, I must be missing something, but I don't know what it is or how to address the issue. According to the Ace3 docs, .NotifyChange fires a callback, which could be what I need, but I am not sure where to handle it, or how.

Examples for Classic and/or Retail: The description, with the toggle on, assign Druids == Cenarion Circle, and Darnassus if off, or Death Knights == Knights of the Ebon Blade when on, or Orgrimmar if off. Like I said above, this does happen, but it requires a UI reload to update the text. Is it possible to do this dynamically based on the status of the toggle?

Lua Code:
  1. ---------- Core.lua ----------
  2. function RepByZone:GetRacialRep()
  3.     local _, playerRace = UnitRace("player")
  4.     --@retail@
  5.     local H = UnitFactionGroup("player") == "Horde"
  6.     local A = UnitFactionGroup("player") == "Alliance"
  7.     --@end-retail@
  8.  
  9.     local racialRepID = playerRace == "Dwarf" and 47 -- Ironforge
  10.     or playerRace == "Gnome" and 54 -- Gnomeregan
  11.     or playerRace == "Human" and 72 -- Stormwind
  12.     or playerRace == "NightElf" and 69 -- Darnassus
  13.     or playerRace == "Orc" and 76 -- Orgrimmar
  14.     or playerRace == "Tauren" and 81 -- Thunder Bluff
  15.     or playerRace == "Troll" and 530 -- Darkspear Trolls
  16.     or playerRace == "Scourge" and 68 -- Undercity
  17.     --@retail@
  18.     or playerRace == "Goblin" and 1133 -- Bilgewater Cartel
  19.     or playerRace == "Draenei" and 930 -- Exodar
  20.     or playerRace == "Worgen" and 1134 -- Gilneas
  21.     or playerRace == "BloodElf" and 911 -- Sukvermoon City
  22.     or playerRace == "Pandaren" and (A and 1353 or H and 1352 or 1216) -- Tushui Pandaren or Huojin Pandaren or Shang Xi's Academy
  23.     or playerRace == "HighmountainTauren" and 1828 -- Highmountain Tribe
  24.     or playerRace == "VoidElf" and 2170 -- Argussian Reach
  25.     or playerRace == "Mechagnome" and 2391 -- Rustbolt Resistance
  26.     or playerRace == "Vulpera" and 2158 -- Voldunai
  27.     or playerRace == "KulTiran" and 2160 -- Proudmoore Admiralty
  28.     or playerRace == "ZandalariTroll" and 2103 -- Zandalari Empire
  29.     or playerRace == "Nightborne" and 1859 -- The Nightfallen
  30.     or playerRace == "MagharOrc" and 941 -- The Mag'har
  31.     or playerRace == "DarkIronDwarf" and 59 -- Thorium Brotherhood
  32.     or playerRace == "LightforgedDraenei" and 2165 -- Army of the Light
  33.     --@end-retail@
  34.  
  35.     -- classes have factions
  36.     local classRepID = nil
  37.     local _, classFileName = UnitClass("player")
  38.     if self.db.char.useClassRep then
  39.         classRepID = classFileName == "ROGUE" and 349 -- Ravenholdt
  40.         or classFileName == "DRUID" and 609 -- Cenarion Circle
  41.         --@retail@
  42.         or classFileName == "SHAMAN" and 1135 -- The Earthen Ring
  43.         or classFileName == "DEATHKNIGHT" and 1098 -- Knights of the Ebon Blade
  44.         or classFileName == "MAGE" and 1090 -- Kirin Tor
  45.         --@end-retail@
  46.     end
  47.  
  48.     racialRepID = classRepID or racialRepID
  49.     local racialRepName = GetFactionInfoByID(racialRepID)
  50.     return racialRepID, racialRepName
  51. end
  52.  
  53. ----------- Options.lua -----------
  54. function RepByZone:GetOptions()
  55.     local db = self.db.char
  56.     local racialRepID, racialRepName = self:GetRacialRep()
  57.     local options = {
  58.         name = "RepByZone",
  59.         handler = RepByZone,
  60.         type = "group",
  61.         childGroups = "tab",
  62.         args = {
  63.             enableDisable = {
  64.                 order = 10,
  65.                 name = ENABLE .. " " .. JUST_OR .. " " .. DISABLE,
  66.                 desc = L["Toggle RepByZone on or off."],
  67.                 descStyle = "inline",
  68.                 type = "toggle",
  69.                 width = "full",
  70.                 get = function() return db.enabled end,
  71.                 set = function(info, value)
  72.                     db.enabled = value
  73.                     if value then
  74.                         self:OnEnable()
  75.                     else
  76.                         self:OnDisable()
  77.                     end
  78.                 end
  79.             },
  80.             factionStuff = {
  81.                 order = 20,
  82.                 name = L["Reputation Settings"],
  83.                 type = "group",
  84.                 args = {
  85.                     watchSubZones = {
  86.                         order = 10,
  87.                         name = L["Watch Subzones"],
  88.                         desc = L["Switch watched faction based on subzones."],
  89.                         descStyle = "inline",
  90.                         type = "toggle",
  91.                         width = "double",
  92.                         get = function() return db.watchSubZones end,
  93.                         set = function(info, value)
  94.                             db.watchSubZones = value
  95.                             if value then
  96.                                 self:RegisterEvent("ZONE_CHANGED", "SwitchedSubZones")
  97.                                 self:RegisterEvent("ZONE_CHANGED_INDOORS", "SwitchedSubZones")
  98.                                 self:SwitchedSubZones()
  99.                             else
  100.                                 self:UnregisterEvent("ZONE_CHANGED")
  101.                                 self:UnregisterEvent("ZONE_CHANGED_INDOORS")
  102.                             end
  103.                         end
  104.                     },
  105.                     verbose = {
  106.                         order = 20,
  107.                         name = L["Verbose"],
  108.                         desc = L["Print to chat when you switch watched faction."],
  109.                         descStyle = "inline",
  110.                         type = "toggle",
  111.                         width = "double",
  112.                         get = function() return db.verbose end,
  113.                         set = function(info, value) db.verbose = value end
  114.                     },
  115.                     watchOnTaxi = {
  116.                         order = 30,
  117.                         name = L["Switch on taxi"],
  118.                         desc = L["Switch watched faction while you are on a taxi."],
  119.                         descStyle = "inline",
  120.                         type = "toggle",
  121.                         width = "double",
  122.                         get = function() return db.watchOnTaxi end,
  123.                         set = function(info, value) db.watchOnTaxi = value end
  124.                     },
  125.                     useClassRep = {
  126.                         order = 40,
  127.                         name = L["Override some default racial reps with class reps."],
  128.                         desc = (L["Your class reputation is %s"]):format(racialRepName),
  129.                         descStyle = "inline",
  130.                         type = "toggle",
  131.                         width = "double",
  132.                         get = function() return db.useClassRep end,
  133.                         set = function(info, value)
  134.                             db.useClassRep = value
  135.                             racialRepID, racialRepName = self:GetRacialRep()
  136.                             LibStub("AceConfigRegistry-3.0"):NotifyChange("RepByZone")
  137.                         end
  138.                     },
  139.                     defaultRep = {
  140.                         order = 100,
  141.                         name = L["Default watched faction"],
  142.                         desc = L["Defaults to your racial faction per character."],
  143.                         type = "select",
  144.                         values = function() return self:GetAllFactions() end,
  145.                         get = function() return db.watchedRepID end,
  146.                         set = function(info, value)
  147.                             db.watchedRepID = value
  148.                             db.watchedRepName = GetFactionInfoByID(value)
  149.                         end
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.     }
  155.     return options
  156. end
  Reply With Quote