Guest User

Untitled

a guest
Mar 11th, 2020
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 184.94 KB | None | 0 0
  1. --[[ CensusPlusClassic for World of Warcraft(tm).
  2.    
  3.     Copyright 2005 - 2016 Cooper Sellers
  4.  
  5.     License:
  6.         This program is free software; you can redistribute it and/or
  7.         modify it under the terms of the GNU General Public License
  8.         as published by the Free Software Foundation; either version 2
  9.         of the License, or (at your option) any later version.
  10.  
  11.         This program is distributed in the hope that it will be useful,
  12.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.         GNU General Public License for more details.
  15.  
  16.         You should have received a copy of the GNU General Public License
  17.         along with this program(see GLP.txt); if not, write to the Free Software
  18.         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19.        
  20.   Debugging/profiling note:  
  21.   Global  CPp.EnableProfiling must be set to True
  22.   the appropriate profiling point must be set in code with
  23.   --CP_profiling_timerstart =   debugprofilestop()
  24.   don't use debugprofilestart() this does a reset of the timer...
  25.   if multiple code (addons) have profiling turned on.. then debugprofilestart()
  26.   will impact timing of the all the code profiles.
  27. ]]
  28. --local regionKey = GetCVar("portal") == "public-test" and "PTR" or GetCVar("portal")
  29. --Note: file layout structured for use with NotePad++ as editor using Lua(WoW) language definition
  30.  
  31. --[[    CensusPlus
  32. --      A WoW UI customization by Cooper Sellers
  33. --
  34. --      CensusPlusClassic
  35. --      Modified by christophrus
  36. ]]
  37.  
  38. local   addon_name, addon_tableID = ...         -- Addon_name contains the Addon name which must be the same as the container folder name... addon_tableID is a common private table for all .lua files in the directory.
  39.  
  40. local CPp = addon_tableID                       --short cut name for private shared table.
  41.  
  42. local checksum = LibStub:GetLibrary("LibChecksum-1.0", true)
  43.  
  44. CPp.InterfaceVersion = "Captain Placeholder";   -- random value.. must not match CensusPlus_VERSION string.
  45. local g_CensusPlusTZOffset = -999;
  46. CPp.LocaleSet = false;  -- not used?
  47. CPp.TZWarningSent = false;  -- not used?
  48.  
  49. -- Bindings
  50. BINDING_NAME_CENSUSPLUSCLASSIC_MANUALWHO = 'Issue a manual /who request'
  51. BINDING_HEADER_CENSUSPLUSCLASSIC = 'CensusPlusClassic'
  52.  
  53. -- Constants
  54. local CensusPlus_Version_Major = "0"; -- changing this number will force a saved data purge
  55. local CensusPlus_Version_Minor = "8"; -- changing this number will force a saved data purge
  56. local CensusPlus_Version_Maint = "4";
  57. local CensusPlus_SubVersion = "";
  58. --local CensusPlus_VERSION = "WoD"
  59. local CensusPlus_VERSION = CensusPlus_Version_Major.."."..CensusPlus_Version_Minor .."."..CensusPlus_Version_Maint;
  60. local CensusPlus_VERSION_FULL = CensusPlus_VERSION --.."."..CensusPlus_SubVersion ;
  61. local CensusPlus_PTR = GetCVar("portal") == "public-test" and "PTR";    -- enable true for PTR testing  enable false for live use
  62. local CensusPlus_MAXBARHEIGHT = 128;            -- Length of blue bars
  63. local CensusPlus_NUMGUILDBUTTONS = 10;          -- How many guild buttons are on the UI?
  64.  
  65.  
  66. local MAX_CHARACTER_LEVEL = 60;                 -- Maximum level a PC can attain  testing only comment out for live
  67. local MIN_CHARACTER_LEVEL = 1;                  -- Minimum observed level returned by /who command (undocumented and barely acknowledged.)
  68. local MAX_WHO_RESULTS = 49;                     -- Maximum number of who results the server will return
  69. CensusPlus_GUILDBUTTONSIZEY = 16;               -- pixil height of guild name lines
  70. local CensusPlus_UPDATEDELAY = 5;               -- Delay time between /who messages
  71. local CensusPlus_UPDATEDELAY2 = 10              -- Delay time from who request to database updated
  72. local CP_MAX_TIMES = 50;
  73.  
  74. --local g_ServerPrefix = "";                    --  US VERSION!!
  75. --local g_ServerPrefix = "EU-";                 --  EU VERSION!!
  76.  
  77. -- debug flags for remote QA testing of version upgrades.
  78. local CP_api = "api"
  79. local CP_letterselect = 0                   -- default letter selector pattern... valid options 1 and 2.. testing only
  80. local CensusPlus_WHOPROCESSOR = CP_api      -- default processing of who request to full wholib  CP_api --
  81. local CensusPLus_DEBUGWRITES = false        -- don't add debug into to censusplus.lua output.
  82. local CP_g_queue_count = 0                  -- process speed checking avg time to process 1 queue
  83.  
  84.  
  85.  
  86.  
  87.  
  88. -- Global scope variables
  89. CensusPlus_Database = {};                       -- Database of all CensusPlusClassic results
  90. --removed CensusPlus_BGInfo   = {};             --  Battleground info
  91. CensusPlus_PerCharInfo = {};                    --  Per character settings
  92. CensusPlus_Unhandled = {};
  93. CensusPlus_JobQueue = {};                       -- The queue of pending jobs
  94. local g_TrackUnhandled = false;
  95. CPp.Options_Holder = {}                         -- table is populated with existing option settings when Options panel is opened.. cancel resets live options to these settings.
  96. CPp.Options_Holder["AccountWide"] = {}
  97. CPp.Options_Holder["CCOverrides"] = {}
  98.    
  99. -- File scope variables
  100. local g_addon_loaded = false
  101. local g_player_loaded = false
  102.  
  103. local g_stealth = false;                    -- Stealth mode switch
  104. local g_Verbose = false;                    -- Verbose mode switch
  105. local g_Options_confirm_txt = true;         -- enable chatty confirm of options until user no longer desires
  106. CPp.AutoCensus = false;                     -- AutoCensus mode switch
  107. local g_Options_Scope = "AW"                -- options are AW or CO
  108. CPp.AutoStartTimer = 30                     -- default Slider value in Options
  109. local g_FinishSoundNumber = 1               -- default finish sound..
  110. local g_PlayFinishSound = false             -- mode switch
  111. local g_CensusPlusInitialized = false;      -- Is CensusPlusClassic initialized?
  112. local g_CurrentJob = {};                    -- Current job being executed
  113. CPp.IsCensusPlusInProgress = false;         -- Is a CensusPlusClassic in progress?
  114. local g_CensusPlusPaused = false            -- Is CensusPlusClassic in progress paused?
  115. CPp.CensusPlusManuallyPaused = false;       -- Is CensusPlusClassic in progress manually paused?
  116. local CensusPlayerOnly = false              -- true if player requests via /census me
  117.  
  118. CensusPlus_JobQueue.g_NumNewCharacters = 0;                 -- How many new characters found this CensusPlusClassic
  119. CensusPlus_JobQueue.g_NumUpdatedCharacters = 0;             -- How many characters were updated during this CensusPlusClassic
  120.  
  121. local g_MobXPByLevel = {};                      -- XP earned for killing
  122. local g_CharacterXPByLevel = {};                -- XP required to advance through the given level
  123. local g_TotalCharacterXPPerLevel = {};          -- Total XP required to attain the given level
  124.  
  125. CensusPlus_Guilds = {};                         -- All known guild
  126.  
  127. local g_TotalCharacterXP = 0;                   -- Total character XP for currently selected search
  128. local g_Consecutive = 0;                        -- Current consecutive same realm/faction run count
  129. local g_TotalCount = 0;                         -- Total number of characters which meet search criteria
  130. local g_RaceCount = {};                         -- Totals for each race given search criteria
  131. local g_ClassCount = {};                        -- Totals for each class given search criteria
  132. local g_LevelCount = {};                        -- Totals for each level given search criteria
  133. local g_AccumulatorCount = 0;
  134. local g_AccumulatorXPTotal = 0;
  135. local g_AccumulateGuildTotals = true;           -- switch for guild work when scanning characters
  136.  
  137. CensusPlus_JobQueue.g_TempCount  = {}; 
  138.  
  139. CPp.GuildSelected = 0;                      -- Search criteria: Currently selected guild, 0 indicates none
  140. CPp.RaceSelected = 0;                       -- Search criteria: Currently selected race, 0 indicates none
  141. CPp.ClassSelected = 0;                      -- Search criteria: Currently selected class, 0 indicates none
  142. CPp.LevelSelected = 0;
  143. local current_realm = 0;
  144.  
  145. local g_LastOnUpdateTime = 0;                   -- Last time OnUpdate was called
  146. local g_WaitingForWhoUpdate = false;            -- Are we waiting for a who update event?
  147.  
  148. local g_factionGroup = "Neutral"                        -- Faction of character running census. used to select/verify correct faction of race
  149.  
  150. local g_WhoAttempts = 0;                        -- Counter for detecting stuck who results
  151. local g_MiniOnStart = 1;                        -- Flag to have the mini-censusP displayed on startup
  152.  
  153. local g_CompleteCensusStarted = false;          -- Flag for counter
  154. local g_TakeHour = 0;                           -- Our timing hour
  155. local g_ResetHour = true;                       -- Rest hour
  156. local g_VariablesLoaded = false;                -- flag to tell us if vars are loaded
  157. CPp.FirstLoad = false                       -- Flag to handle (hide) various database rebuild messages on initial database creation
  158. local g_FirstRun = true;
  159. local g_wasPurged = false
  160. local whoquery_answered = false;
  161. local whoquery_active = false
  162. CPp.LastCensusRun = time() -- (CPp.AutoStartTrigger * 60)   --  timer used if auto census is turned on
  163. CPp.LastManualWho = time()
  164.  
  165. local g_Pre_SFX = nil;
  166. local CP_updatingGuild  = nil;
  167. local g_CurrentlyInBG = false;
  168. local g_CurrentlyInBG_Msg = false;
  169. local g_InternalSearchName = nil;
  170. local g_InternalSearchLevel = nil;
  171. local g_InternalSearchCount = 0;
  172. CPp.EnableProfiling = false;
  173. local CP_profiling_timerstart = 0
  174. local CP_profiling_timediff = 0
  175. local g_CensusPlus_StartTime = 0;
  176. local g_CensusWhoOverrideMsg = nil;
  177. local g_WaitingForOverrideUpdate = false;
  178. local g_ProblematicMessageShown = false;
  179. local g_PratLoaded = false;
  180.  
  181. --  Battleground info
  182. CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES = {};
  183.  
  184. local g_AccumulatedPruneData = {};
  185.  
  186. local g_RaceClassList = { };                        -- Used to pick the right icon
  187. g_RaceClassList[CENSUSPLUS_DRUID]       = 10;
  188. g_RaceClassList[CENSUSPLUS_HUNTER]      = 11;
  189. g_RaceClassList[CENSUSPLUS_MAGE]        = 12;
  190. g_RaceClassList[CENSUSPLUS_PRIEST]      = 13;
  191. g_RaceClassList[CENSUSPLUS_ROGUE]       = 14;
  192. g_RaceClassList[CENSUSPLUS_WARLOCK]     = 15;
  193. g_RaceClassList[CENSUSPLUS_WARRIOR]     = 16;
  194. g_RaceClassList[CENSUSPLUS_SHAMAN]      = 17;
  195. g_RaceClassList[CENSUSPLUS_PALADIN]     = 18;
  196.  
  197. g_RaceClassList[CENSUSPLUS_DWARF]       = 20;
  198. g_RaceClassList[CENSUSPLUS_GNOME]       = 21;
  199. g_RaceClassList[CENSUSPLUS_HUMAN]       = 22;
  200. g_RaceClassList[CENSUSPLUS_NIGHTELF]    = 23;
  201. g_RaceClassList[CENSUSPLUS_ORC]         = 24;
  202. g_RaceClassList[CENSUSPLUS_TAUREN]      = 25;
  203. g_RaceClassList[CENSUSPLUS_TROLL]       = 26;
  204. g_RaceClassList[CENSUSPLUS_UNDEAD]      = 27;
  205.  
  206. CensusPlus_JobQueue.g_TimeDatabase = {};                      -- Time database
  207. local function CensusPlus_Zero_g_TimeDatabase()
  208.     CensusPlus_JobQueue.g_TimeDatabase = nil;
  209.     CensusPlus_JobQueue.g_TimeDatabase = {};
  210.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_DRUID]        = 0;
  211.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_HUNTER]       = 0;
  212.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_MAGE]         = 0;
  213.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PRIEST]       = 0;
  214.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_ROGUE]        = 0;
  215.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARLOCK]      = 0;
  216.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARRIOR]      = 0;
  217.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_SHAMAN]       = 0;
  218.     CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PALADIN]      = 0;
  219. end
  220. CensusPlus_Zero_g_TimeDatabase();
  221.  
  222.  
  223. --  These two DO NOT need to be localized
  224. local CENSUSPlus_HORDE            = "Horde";
  225. local CENSUSPlus_ALLIANCE         = "Alliance";
  226.  
  227. local g_FactionCheck = {};
  228. g_FactionCheck[CENSUSPLUS_ORC]      = CENSUSPlus_HORDE;
  229. g_FactionCheck[CENSUSPLUS_TAUREN]   = CENSUSPlus_HORDE;
  230. g_FactionCheck[CENSUSPLUS_TROLL]    = CENSUSPlus_HORDE;
  231. g_FactionCheck[CENSUSPLUS_UNDEAD]   = CENSUSPlus_HORDE;
  232. g_FactionCheck[CENSUSPLUS_DWARF]    = CENSUSPlus_ALLIANCE;
  233. g_FactionCheck[CENSUSPLUS_GNOME]    = CENSUSPlus_ALLIANCE;
  234. g_FactionCheck[CENSUSPLUS_HUMAN]    = CENSUSPlus_ALLIANCE;
  235. g_FactionCheck[CENSUSPLUS_NIGHTELF] = CENSUSPlus_ALLIANCE;
  236.  
  237. -- Print a string to the chat frame
  238. local function CensusPlus_Msg(msg)
  239.     if( msg == nil ) then
  240.         msg = " NIL ";
  241.     end
  242.     if(not(g_stealth) )then
  243.         ChatFrame1:AddMessage(CENSUSPLUS_TEXT.." "..msg, 1.0, 1.0, 0.5);
  244.     end
  245. end
  246.  
  247. local function CensusPlus_WhoMsg(msg)
  248.     if( msg == nil ) then
  249.         msg = " NIL ";
  250.     end
  251.     ChatFrame1:AddMessage(CENSUSPLUS_TEXT.." "..WHO..": "..msg, 0.8, 0.8, 0.1);
  252. end
  253.  
  254. local function CensusPlus_Msg2( msg )
  255.     if( msg == nil ) then
  256.         msg = " NIL ";
  257.     end
  258.     if(not(g_stealth) )then
  259.         ChatFrame2:AddMessage(CENSUSPLUS_TEXT..": "..msg, 0.5, 1.0, 1.0);
  260.     end
  261. end
  262.  
  263. --- PTR debug messages
  264. local channel = 0
  265. local channelName = " "
  266. local channelReady = false
  267. local instanceID = 0
  268. local language = nil -- nil = common for faction
  269. local HortonBug = false
  270. local HortonFingers = false
  271. local HortonChannel = "Hortondebug"
  272.  
  273. local function HortonChatMsg(hotair)
  274.     DEFAULT_CHAT_FRAME:AddMessage(hotair, 0.7, 0.5, 0.7)
  275. end
  276.  
  277. local function HortonChannelMsg(hotair)
  278.     SendChatMessage(hotair, "CHANNEL", language, channel)
  279.     -- chattype = CHANNEL
  280.     -- language = COMMON
  281.     -- channel = channel
  282. end
  283.  
  284. -- local says = HortonChannelMsg
  285. local says = HortonChatMsg -- work around for incomplete work on Starter client sigh
  286. local chat = HortonChatMsg
  287.  
  288. local function HortonChannelSetup()
  289.     channel, channelName, instanceID = GetChannelName(HortonChannel)
  290.     ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, channel)
  291.     channelReady = true
  292.     says("Horton finds his very own channel")
  293.     says("Horton turned on the chatlog")
  294. end
  295.  
  296. function CensusPlus_GetUniqueRealmName()
  297.    
  298.     local realmname = GetRealmName()
  299.     local guid = UnitGUID("player")
  300.     local realmid = string.match(guid, "^Player%-(%d+)")
  301.    
  302.     return realmid .. "_" .. realmname
  303.  
  304. end
  305.  
  306. -- Set up confirmation boxes
  307. StaticPopupDialogs["CP_PURGE_CONFIRM"] = {
  308.     text = CENSUSPLUS_PURGE_LOCAL_CONFIRM,
  309.     button1 = YES,
  310.     button2 = NO,
  311.     OnAccept = function()
  312.         CensusPlus_DoPurge()
  313.     end,
  314.     --  sound = "levelup2",
  315.     timeout = 0,
  316.     whileDead = 1,
  317.     hideOnEscape = 1,
  318.     showAlert = 1
  319. }
  320.  
  321. -- Set up Continue after override box  .. no longer valid
  322. StaticPopupDialogs["CP_CONTINUE_CENSUS"] = {
  323.     text = CENSUSPlus_OVERRIDE_COMPLET_PAUSED,
  324.     button1 = CENSUSPlus_CONTINUE,
  325.     OnAccept = function()
  326.         CPp.CensusPlusManuallyPaused = false
  327.         CensusPlusTakeButton:SetText(CENSUSPLUS_PAUSE)
  328.     end,
  329.     --  sound = "levelup2",
  330.     timeout = 0,
  331.     whileDead = 1,
  332.     hideOnEscape = 1,
  333.     showAlert = 1
  334. }
  335.  
  336.  
  337. -- Insert a job at the end of the job queue
  338. local function InsertJobIntoQueue(job)
  339.     --CensusPlus_DumpJob( job )
  340.     table.insert(CensusPlus_JobQueue, job)
  341. end
  342.  
  343. -- Initialize the tables of constants for XP calculations
  344. local function InitConstantTables()
  345.     -- XP earned for killing
  346.     for i = 1, MAX_CHARACTER_LEVEL, 1 do
  347.         g_MobXPByLevel[i] = i
  348.     end
  349.  
  350.     -- XP required to advance through the given level
  351.     for i = 1, MAX_CHARACTER_LEVEL, 1 do
  352.         g_CharacterXPByLevel[i] = ((8 * i * g_MobXPByLevel[i]) / 100) * 100
  353.     end
  354.  
  355.     -- Total XP required to attain the given level
  356.     local totalCharacterXP = 0
  357.     for i = 1, MAX_CHARACTER_LEVEL, 1 do
  358.         --g_TotalCharacterXPPerLevel[i] = totalCharacterXP;
  359.         --totalCharacterXP = totalCharacterXP + g_CharacterXPByLevel[i];
  360.         val = (i * 5) / MAX_CHARACTER_LEVEL
  361.         g_TotalCharacterXPPerLevel[i] = math.exp(val)
  362.     end
  363. end
  364.  
  365. -- Return a table of races for the input faction
  366. function CensusPlus_GetFactionRaces(faction)
  367.     local ret = {};
  368.     if (faction == CENSUSPlus_HORDE) then
  369.         ret = {CENSUSPLUS_ORC, CENSUSPLUS_TAUREN, CENSUSPLUS_TROLL, CENSUSPLUS_UNDEAD};
  370.     elseif (faction == CENSUSPlus_ALLIANCE) then
  371.         ret = {CENSUSPLUS_DWARF, CENSUSPLUS_GNOME, CENSUSPLUS_HUMAN, CENSUSPLUS_NIGHTELF};
  372.     end
  373.     return ret;
  374. end
  375.  
  376. -- Return a table of classes for the input faction
  377. -- the following function hasn't really been needed since Burning Crusade xPac v2.03..
  378. -- but might (not likely) be needed in the future.
  379. function CensusPlus_GetFactionClasses(faction)  
  380.     -- this is last in first out list... add new classes to front of list.
  381.     local ret = {};
  382.     if (faction == CENSUSPlus_HORDE) then
  383.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_SHAMAN,
  384.         CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK, CENSUSPLUS_DRUID};
  385.     elseif (faction == CENSUSPlus_ALLIANCE) then
  386.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST,
  387.         CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK, CENSUSPLUS_DRUID};
  388.     end
  389.     return ret;
  390. end
  391.  
  392. -- Return a table of classes for the input race
  393. local function GetRaceClasses(race)
  394.     local ret = {};
  395.     if (race == CENSUSPLUS_ORC) then
  396.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_SHAMAN, CENSUSPLUS_WARLOCK}
  397.     elseif (race == CENSUSPLUS_TAUREN) then
  398.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_SHAMAN, CENSUSPLUS_DRUID}
  399.     elseif (race == CENSUSPLUS_TROLL) then
  400.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_SHAMAN, CENSUSPLUS_MAGE}
  401.     elseif (race == CENSUSPLUS_UNDEAD) then
  402.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK}
  403.     elseif (race == CENSUSPLUS_DWARF) then
  404.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST}
  405.     elseif (race == CENSUSPLUS_GNOME) then
  406.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_ROGUE, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK}
  407.     elseif (race == CENSUSPLUS_HUMAN) then
  408.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_PALADIN, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_MAGE, CENSUSPLUS_WARLOCK}
  409.     elseif (race == CENSUSPLUS_NIGHTELF) then
  410.         ret = {CENSUSPLUS_WARRIOR, CENSUSPLUS_HUNTER, CENSUSPLUS_ROGUE, CENSUSPLUS_PRIEST, CENSUSPLUS_DRUID}
  411.     end
  412.     return ret
  413. end
  414.  
  415. -- Return common letters found in zone names
  416. -- only used for census splitting by zone.. not used
  417. local function GetZoneLetters()
  418.     return { "а", "б", "в", "г", "д", "e", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "э", "ю", "я" };
  419. end
  420.  
  421. -- Return common letters found in names, may override this for other languages
  422. -- Worst case scenario is to do it for every letter in the alphabet
  423. --[[
  424.     see http://www.warcraftrealms.com/forum/viewtopic.php?t=4819&start=40
  425.     Advantage: as seen from data sample
  426.     removing the last 3 selectors "mkc" returned about same counts as current set..
  427.     adding the "mkc" making the selector count the same increased found unique names by %0.17
  428.     disavantage: as seen from data sample
  429.     current selector will generates a duplicate name hit of 3.27 duplicates /unique name
  430.     alternate selector will generate a duplicate name hit of 4.04 duplicates /unique name
  431.     shortened alternate will generate duplicate name hit of 3.47 duplicates /unique name
  432. ]]
  433.  
  434. --[[local function GetNameLetters()
  435.     return { "а", "б", "в", "г", "д", "e", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "э", "ю", "я", "a", "b", "c", "d", "e", "f", "j", "h", "k", "l", "m", "n", "g", "i", "o", "p", "r", "s", "t", "u", "v", "w", "y", "x", "z", "йя", "йч", "йс", "йм", "йи", "йт", "йб", "йю", "цу", "цк", "це", "цн", "цг", "цш", "цщ", "цз", "цх", "цф", "цв", "ца", "цп", "цр", "цо", "цл", "цд", "цж", "цэ", "ця", "цч", "цс", "цм", "ци", "цт", "цб", "цю", "ук", "уе", "ун", "уг", "уш", "ущ", "уз", "ух", "уф", "ув", "уа", "уп", "ур", "уо", "ул", "уд", "уж", "уэ", "уя", "уч", "ус", "ум", "уи", "ут", "уб", "ую", "ке", "кн", "кг", "кш", "кщ", "кз", "кх", "кф", "кв", "ка", "кп", "кр", "ко", "кл", "кд", "кж", "кэ", "кя", "кч", "кс", "км", "ки", "кт", "кб", "кю", "ен", "ег", "еш", "ещ", "ез", "ех", "еф", "ев", "еа", "еп", "ер", "ео", "ел", "ед", "еж", "еэ", "ея", "еч", "ес", "ем", "еи", "ет", "еб", "ею", "нг", "нш", "нщ", "нз", "нх", "нф", "нв", "на", "нп", "нр", "но", "нл", "нд", "нж", "нэ", "ня", "нч", "нс", "нм", "ни", "нт", "нб", "ню", "гш", "гщ", "гз", "гх", "гф", "гв", "га", "гп", "гр", "го", "гл", "гд", "гж", "гэ", "гя", "гч", "гс", "гм", "ги", "гт", "гб", "гю", "шщ", "шз", "шх", "шф", "шв", "ша", "шп", "шр", "шо", "шл", "шд", "шж", "шэ", "шя", "шч", "шс", "шм", "ши", "шт", "шб", "шю", "щз", "щх", "щф", "щв", "ща", "щп", "щр", "що", "щл", "щд", "щж", "щэ", "щя", "щч", "щс", "щм", "щи", "щт", "щб", "щю", "зх", "зф", "зв", "за", "зп", "зр", "зо", "зл", "зд", "зж", "зэ", "зя", "зч", "зс", "зм", "зи", "зт", "зб", "зю", "хф", "хв", "ха", "хп", "хр", "хо", "хл", "хд", "хж", "хэ", "хя", "хч", "хс", "хм", "хи", "хт", "хб", "хю", "фв", "фа", "фп", "фр", "фо", "фл", "фд", "фж", "фэ", "фя", "фч", "фс", "фм", "фи", "фт", "фб", "фю", "ва", "вп", "вр", "во", "вл", "вд", "вж", "вэ", "вя", "вч", "вс", "вм", "ви", "вт", "вб", "вю", "ап", "ар", "ао", "ал", "ад", "аж", "аэ", "ая", "ач", "ас", "ам", "аи", "ат", "аб", "аю", "пр", "по", "пл", "пд", "пж", "пэ", "пя", "пч", "пс", "пм", "пи", "пт", "пб", "пю", "ро", "рл", "рд", "рж", "рэ", "ря", "рч", "рс", "рм", "ри", "рт", "рб", "рю", "ол", "од", "ож", "оэ", "оя", "оч", "ос", "ом", "ои", "от", "об", "ою", "лд", "лж", "лэ", "ля", "лч", "лс", "лм", "ли", "лт", "лб", "лю", "дж", "дэ", "дя", "дч", "дс", "дм", "ди", "дт", "дб", "дю", "жэ", "жя", "жч", "жс", "жм", "жи", "жт", "жб", "жю", "эя", "эч", "эс", "эм", "эи", "эт", "эб", "эю", "яч", "яс", "ям", "яи", "ят", "яб", "яю", "чс", "чм", "чи", "чт", "чб", "чю", "см", "си", "ст", "сб", "сю", "ми", "мт", "мб", "мю", "ит", "иб", "ию", "тб", "тю", "бю", "ab", "ac", "ad", "ae", "af", "aj", "ah", "ak", "al", "am", "an", "ag", "ai", "ao", "ap", "ar", "as", "at", "au", "av", "aw", "ay", "ax", "az", "bc", "bd", "be", "bf", "bj", "bh", "bk", "bl", "bm", "bn", "bg", "bi", "bo", "bp", "br", "bs", "bt", "bu", "bv", "bw", "by", "bx", "bz", "cd", "ce", "cf", "cj", "ch", "ck", "cl", "cm", "cn", "cg", "ci", "co", "cp", "cr", "cs", "ct", "cu", "cv", "cw", "cy", "cx", "cz", "de", "df", "dj", "dh", "dk", "dl", "dm", "dn", "dg", "di", "do", "dp", "dr", "ds", "dt", "du", "dv", "dw", "dy", "dx", "dz", "ef", "ej", "eh", "ek", "el", "em", "en", "eg", "ei", "eo", "ep", "er", "es", "et", "eu", "ev", "ew", "ey", "ex", "ez", "fj", "fh", "fk", "fl", "fm", "fn", "fg", "fi", "fo", "fp", "fr", "fs", "ft", "fu", "fv", "fw", "fy", "fx", "fz", "jh", "jk", "jl", "jm", "jn", "jg", "ji", "jo", "jp", "jr", "js", "jt", "ju", "jv", "jw", "jy", "jx", "jz", "hk", "hl", "hm", "hn", "hg", "hi", "ho", "hp", "hr", "hs", "ht", "hu", "hv", "hw", "hy", "hx", "hz", "kl", "km", "kn", "kg", "ki", "ko", "kp", "kr", "ks", "kt", "ku", "kv", "kw", "ky", "kx", "kz", "lm", "ln", "lg", "li", "lo", "lp", "lr", "ls", "lt", "lu", "lv", "lw", "ly", "lx", "lz", "mn", "mg", "mi", "mo", "mp", "mr", "ms", "mt", "mu", "mv", "mw", "my", "mx", "mz", "ng", "ni", "no", "np", "nr", "ns", "nt", "nu", "nv", "nw", "ny", "nx", "nz", "gi", "go", "gp", "gr", "gs", "gt", "gu", "gv", "gw", "gy", "gx", "gz", "io", "ip", "ir", "is", "it", "iu", "iv", "iw", "iy", "ix", "iz", "op", "or", "os", "ot", "ou", "ov", "ow", "oy", "ox", "oz", "pr", "ps", "pt", "pu", "pv", "pw", "py", "px", "pz", "rs", "rt", "ru", "rv", "rw", "ry", "rx", "rz", "st", "su", "sv", "sw", "sy", "sx", "sz", "tu", "tv", "tw", "ty", "tx", "tz", "uv", "uw", "uy", "ux", "uz", "vw", "vy", "vx", "vz", "wy", "wx", "wz", "yx", "yz", "xz" }
  436. end
  437. ]]
  438. local function GetNameLetters()
  439.   local locale = GetLocale()
  440.   if (locale == "ruRU") then
  441.     return { "а", "б", "в", "г", "д", "e", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "э", "ю", "я" }
  442.   else
  443.     return { "a", "b", "c", "d", "e", "f", "g", "i", "o", "p", "r", "s", "t", "u", "y" }
  444.   end
  445. end
  446.  
  447. local function GetNameLetters1()
  448.     return {"a", "e", "r", "i", "n", "o", "l", "s", "t", "h", "d", "u", "m", "k", "c" }
  449. end
  450.  
  451. local function GetNameLetters2()
  452.     return {"a", "e", "r", "i", "n", "o", "l", "s", "t", "h", "d", "u"}
  453. end
  454.  
  455.  
  456. -- Called when the main window is shown
  457. function CensusPlus_OnShow() -- referenced by CensusPlusClassic.xml
  458.     -- Initialize if this is the first OnShow event
  459.     if g_CensusPlusInitialized and g_VariablesLoaded then
  460.         CensusPlus_UpdateView()
  461.     end
  462. end
  463.  
  464. -- Toggle hidden status
  465. function CensusPlus_Toggle()
  466.     if CensusPlusClassic:IsVisible() then
  467.         CensusPlusClassic:Hide()
  468.     else
  469.         CensusPlusClassic:Show()
  470.     end
  471. end
  472.  
  473. -- Toggle options pane
  474. -- referenced by CensusPlusClassic.xml
  475. function CensusPlus_ToggleOptions(self)
  476.     PlaySound(856, "Master")
  477.  
  478.     if not InterfaceOptionsFrame:IsShown() then
  479.         InterfaceOptionsFrame:Show()
  480.     end
  481.     InterfaceOptionsFrame_OpenToCategory("CensusPlusClassic")
  482.     --      CensusPlusSetCheckButtonState()
  483. end
  484.  
  485. -- referenced by CensusPlusClassic.xml
  486. function CensusPlus_OnLoad(self)
  487.     -- Update the version number
  488.     CensusPlusText:SetText(
  489.         "CensusPlusClassic v" .. CensusPlus_VERSION .. CensusPlus_SubVersion
  490.     )
  491.     CensusPlusText2:SetText(CENSUSPLUS_UPLOAD)
  492.  
  493.     -- Init constant tables
  494.     InitConstantTables()
  495.  
  496.     -- Register for events
  497.     self:RegisterEvent("ADDON_LOADED")
  498.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  499.     self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  500.  
  501.     -- Called once on load
  502.     -- SLASH_CensusPlusVerbose1 = "/censusverbose";
  503.     -- SlashCmdList["CensusPlusVerbose"] = CensusPlus_Verbose_toggle("alter");
  504.     SLASH_CensusPlusCMD1 = "/CensusPlusClassic"
  505.     SLASH_CensusPlusCMD2 = "/Census+"
  506.     SLASH_CensusPlusCMD3 = "/Census"
  507.     SlashCmdList["CensusPlusCMD"] = CensusPlus_Command
  508.  
  509.     CensusPlus_CheckForBattleground()
  510.  
  511.     --  Set up an empty frame for updates
  512.     local updateFrame = CreateFrame("Frame")
  513.     updateFrame:SetScript("OnUpdate", CensusPlus_OnUpdate)
  514.    
  515.     CensusPlusWhoButton:SetScript("OnClick", function(self, button, down)
  516.     -- As we have not specified the button argument to SetBindingClick,
  517.     -- the binding will be mapped to a LeftButton click.
  518.         ManualWho()
  519.     end)
  520. end
  521.  
  522. function InitializeExperimental()
  523.     hookWorldClicks = CensusPlus_Database["Info"]["UseWorldFrameClicks"]
  524.  
  525.     if hookWorldClicks then
  526.         WorldFrame:HookScript("OnMouseDown", function(self,button)
  527.             ManualWho()
  528.         end)
  529.     end
  530. end
  531.  
  532.  
  533. function CP_ProcessWhoEvent(query, result, complete)
  534.     if (CPp.IsCensusPlusInProgress ~= true) then return end
  535.  
  536.     local numWhoResults = 0
  537.     local cpdb_complete_flag = ""
  538.     whoquery_answered = true
  539.  
  540.     numWhoResults = C_FriendList.GetNumWhoResults()
  541.  
  542.     if (g_Verbose == true) then
  543.         CensusPlus_Msg(
  544.             CENSUSPLUS_WHOQUERY .. " " .. query .. ", " .. CENSUSPLUS_FOUND .. " " .. numWhoResults .. cpdb_complete_flag
  545.         )
  546.         --CensusPlus_Msg(CENSUSPLUS_WHOQUERY.." "..query);
  547.     end
  548.  
  549.     if (numWhoResults == 0) then
  550.         --print("no results returned")
  551.         local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
  552.         if whoText and whoText == query then
  553.             g_WaitingForWhoUpdate = false
  554.             whoquery_active = false
  555.             whoquery_answered = false
  556.         end
  557.         -- remove job from the queue
  558.         table.remove(CensusPlus_JobQueue)
  559.         return
  560.     end
  561.  
  562.     CensusPlus_ProcessWhoResults(result, numWhoResults)
  563.  
  564.     if (numWhoResults > MAX_WHO_RESULTS) then
  565.         -- Who list is overflowed, split the query to make the return smaller
  566.         local minLevel = g_CurrentJob.m_MinLevel
  567.         local maxLevel = g_CurrentJob.m_MaxLevel
  568.         local race = g_CurrentJob.m_Race
  569.         local class = g_CurrentJob.m_Class
  570.         local zoneLetter = g_CurrentJob.m_zoneLetter
  571.         local letter = g_CurrentJob.m_Letter
  572.  
  573.         if (minLevel < maxLevel) then
  574.             -- The level range is greater than a single level, so split it in half and submit the two jobs
  575.             local pivot = floor((minLevel + maxLevel) / 2)
  576.             local jobLower =
  577.                 CensusPlus_CreateJob(minLevel, pivot, nil, nil, nil)
  578.             InsertJobIntoQueue(jobLower)
  579.             local jobUpper =
  580.                 CensusPlus_CreateJob(pivot + 1, maxLevel, nil, nil, nil)
  581.             InsertJobIntoQueue(jobUpper)
  582.         else
  583.             -- We cannot split the level range any more
  584.             local factionGroup = UnitFactionGroup("player")
  585.             local level = minLevel
  586.             if (race == nil) then
  587.                 -- This job does not specify race, so split it that way, making jobs for each race]
  588.                 local thisFactionRaces =
  589.                     CensusPlus_GetFactionRaces(factionGroup)
  590.                 local numRaces = #thisFactionRaces
  591.                 for i = 1, numRaces, 1 do
  592.                     if (CENSUSPLUS_LIGHTFORGED ~= thisFactionRaces[i]) and (CENSUSPLUS_HIGHMOUNTAIN ~= thisFactionRaces[i]) then
  593.                         local job =
  594.                             CensusPlus_CreateJob(
  595.                                 level,
  596.                                 level,
  597.                                 thisFactionRaces[i],
  598.                                 nil,
  599.                                 nil
  600.                             )
  601.                         InsertJobIntoQueue(job)
  602.                     end
  603.                 end
  604.             else
  605.                 if (class == nil) then
  606.                     -- This job does not specify class, so split it that way, making jobs for each class
  607.                     local thisRaceClasses = GetRaceClasses(race)
  608.                     local numClasses = #thisRaceClasses
  609.                     for i = 1, numClasses, 1 do
  610.                         if CENSUSPLUS_DEMONHUNTER ~= thisRaceClasses[i] then
  611.                             local job =
  612.                                 CensusPlus_CreateJob(
  613.                                     level,
  614.                                     level,
  615.                                     race,
  616.                                     thisRaceClasses[i],
  617.                                     nil
  618.                                 )
  619.                             InsertJobIntoQueue(job)
  620.                         end
  621.                     end
  622.                 else
  623.                     if (letter == nil) then
  624.                         -- There are too many characters with a single level, class and race
  625.                         -- The work around we are going to pursue is to check by name for a,e,i,o,r,s,t,u
  626.                         local letters = {}
  627.                         if CP_letterselect == 0 then
  628.                             letters = GetNameLetters()
  629.                         elseif CP_letterselect == 1 then
  630.                             letters = GetNameLetters1()
  631.                         elseif CP_letterselect == 2 then
  632.                             letters = GetNameLetters2()
  633.                         end
  634.  
  635.                         for i = 1, #letters, 1 do
  636.                             local job =
  637.                                 CensusPlus_CreateJob(
  638.                                     level,
  639.                                     level,
  640.                                     race,
  641.                                     class,
  642.                                     letters[i]
  643.                                 )
  644.                             InsertJobIntoQueue(job)
  645.                         end
  646.                         -- Block of code removed that isn't currently or ever used.. splitting by zone
  647.                     else
  648.                         -- There are too many characters with a single level, class, race and letter, give up
  649.                         local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
  650.                         if (g_Verbose == true) then
  651.                             CensusPlus_Msg(format(CENSUSPLUS_TOOMANY, whoText))
  652.                         end
  653.                     end
  654.                 end
  655.             end
  656.         end
  657.     else
  658.     end
  659.  
  660.     local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
  661.  
  662.     if whoText == query then
  663.         g_WaitingForWhoUpdate = false
  664.     end
  665. end
  666.  
  667.  
  668. -- CensusPlusClassic command
  669. function CensusPlus_Command(param)
  670.     local jcmdend = 0
  671.     local jvalend = 0
  672.     local jfolend = 0
  673.     local command = nil
  674.     local value = nil
  675.     local nameval = nil
  676.     local followon = nil
  677.     local levelon = 0
  678.     local _ = nil
  679.  
  680.     if (param ~= nil) then
  681.         param = string.lower(param)
  682.         _, jcmdend, command = string.find(param, "(%w+)")
  683.         if (command == "options") then
  684.             CensusPlus_ToggleOptions()
  685.         elseif (command == "take") then
  686.             CENSUSPLUS_TAKE_OnClick()
  687.         elseif (command == "me") then
  688.             CensusPlayerOnly = true
  689.             CENSUSPLUS_TAKE_OnClick()
  690.         elseif (command == "stop") then
  691.             CENSUSPLUS_STOPCENSUS()
  692.         elseif (command == "serverprune") then
  693.             _, jvalend, value = string.find(param, "(%w+)", jcmdend + 1) -- alphanumeric selector used to warn of bad input
  694.             if (value ~= nil) then
  695.                 value = tonumber(value)
  696.                 if (value ~= nil) then
  697.                     CENSUSPLUS_PRUNEData(value, 1) -- value isn't a number .. bad user input
  698.                 else
  699.                     CENSUSPLUS_PRUNEData(0, 1)
  700.                 end -- value is nil
  701.             else
  702.                 CENSUSPLUS_PRUNEData(0, 1)
  703.             end
  704.         elseif (command == "verbose") then
  705.             CensusPlus_Verbose_toggle("alter")
  706.         elseif (command == "stealth") then
  707.             CensusPlus_Stealth_toggle("alter")
  708.         elseif (command == "prune") then
  709.             _, jvalend, value = string.find(param, "(%w+)", jcmdend + 1) -- alphanumeric selector used to warn of bad input
  710.             if (value ~= nil) then
  711.                 value = tonumber(value)
  712.                 if (value ~= nil) then
  713.                     CENSUSPLUS_PRUNEData(value, nil) -- value isn't a number .. bad user input
  714.                 else
  715.                     CENSUSPLUS_PRUNEData(30, nil)
  716.                 end -- value is nil
  717.             else
  718.                 CENSUSPLUS_PRUNEData(30, nil)
  719.             end
  720.         elseif (command == "timer") then
  721.             _, jvalend, value = string.find(param, "(%d+)", jcmdend + 1) -- decimal seletor works here, if bad input just reset timer
  722.             if (value ~= nil) then
  723.                 value = tonumber(value)
  724.             end
  725.             CensusPlus_TimerSet(self, value, true)
  726.         elseif (command == "who") then -- get 2nd term
  727.             _, jvalend, nameval = string.find(param, "(%w+)", jcmdend + 1) --alphanumeric selector used to give warning of bad input
  728.             if (nameval ~= nil) then -- nameval found non nil
  729.                 _, jfalend, followon = string.find(param, "(%a+)", jcmdend + 1) -- see if same match is found as alpha only
  730.                 if (nameval == followon) then -- alpha world so get 3rd term
  731.                     _, jfalend, followon =
  732.                         string.find(param, "(%w+)", jvalend + 1) --alphanumeric selector used to give warning of bad input
  733.                     if (followon == nil) then -- no 3rd term found
  734.                         CensusPlus_InternalWho(string.lower(nameval), nil) -- 3rd term found
  735.                     else
  736.                         levelon = tonumber(followon)
  737.                         CensusPlus_InternalWho(
  738.                             string.lower(nameval),
  739.                             string.lower(levelon)
  740.                         )
  741.                     end -- 2nd term is a number -- 3rd term is NOT a number
  742.                 else
  743.                     CensusPlus_Msg(CENSUSPLUS_CMDERR_WHO2NUM)
  744.                 end -- 2nd term is nil -- 2nd term is ""
  745.             else
  746.                 CensusPlus_Msg(CENSUSPLUS_CMDERR_WHO2)
  747.             end
  748.         elseif (param == "debug") then
  749.             if (HortonBug == false) then
  750.                 chat("Horton puts trunk in Rabbit hole and blows real hard")
  751.                 HortonChannelSetup()
  752.                 JoinTemporaryChannel(HortonChannel)
  753.                 LoggingChat(true)
  754.                 HortonBug = true
  755.                 says("Hello HortonChannel")
  756.             else
  757.                 says("Horton turns off the chatlog")
  758.                 LoggingChat(false)
  759.                 HortonBug = false
  760.             end
  761.         else
  762.             CensusPlus_DisplayUsage()
  763.         end
  764.     else
  765.         CensusPlus_DisplayUsage()
  766.     end
  767. end
  768.  
  769. function CensusPlus_Verbose(self)
  770.     --print(CensusPlus_Database["Info"]["Verbose"])
  771.     --print(CensusPlus_PerCharInfo["Verbose"])
  772.     if ((CensusPlus_PerCharInfo["Verbose"] == nil) and (CensusPlus_Database["Info"]["Verbose"] == true)) then
  773.         CensusPlus_Verbose_toggle("On")
  774.     elseif ((CensusPlus_PerCharInfo["Verbose"] == nil) and (CensusPlus_Database["Info"]["Verbose"] == false)) then
  775.         CensusPlus_Verbose_toggle("Off")
  776.     elseif (CensusPlus_PerCharInfo["Verbose"] == true) then
  777.         CensusPlus_Verbose_toggle("On")
  778.     elseif (CensusPlus_PerCharInfo["Verbose"] == false) then
  779.         CensusPlus_Verbose_toggle("Off")
  780.     else
  781.     end
  782. end
  783.  
  784. function CensusPlus_Verbose_toggle(state)
  785.     if (state == "alter") then
  786.         if (g_Verbose == true) then
  787.             g_Verbose = false
  788.             CensusPlus_Msg(CENSUSPLUS_VERBOSEOFF)
  789.         else
  790.             g_Verbose = true
  791.             g_stealth = false
  792.             CensusPlus_Msg(CENSUSPLUS_VERBOSEON)
  793.         end
  794.     elseif (state == "On") then
  795.         g_Verbose = true
  796.         g_stealth = false
  797.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  798.             CensusPlus_Msg(CENSUSPLUS_VERBOSEON)
  799.         end
  800.     elseif (state == "Off") then
  801.         g_Verbose = false
  802.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  803.             CensusPlus_Msg(CENSUSPLUS_VERBOSEOFF)
  804.         end
  805.     end
  806. end
  807.  
  808. local function CensusPlus_Stealth(self)
  809.     --print(CensusPlus_Database["Info"]["Stealth"])
  810.     --print(CensusPlus_PerCharInfo["Stealth"])
  811.     if ((CensusPlus_PerCharInfo["Stealth"] == nil) and (CensusPlus_Database["Info"]["Stealth"] == true)) then
  812.         CensusPlus_Stealth_toggle("On")
  813.     elseif ((CensusPlus_PerCharInfo["Stealth"] == nil) and (CensusPlus_Database["Info"]["Stealth"] == false)) then
  814.         CensusPlus_Stealth_toggle("Off")
  815.     elseif (CensusPlus_PerCharInfo["Stealth"] == true) then
  816.         CensusPlus_Stealth_toggle("On")
  817.     elseif (CensusPlus_PerCharInfo["Stealth"] == false) then
  818.         CensusPlus_Stealth_toggle("Off")
  819.     else
  820.     end
  821. end
  822.  
  823. function CensusPlus_Stealth_toggle(state)
  824.     if (state == "alter") then
  825.         if (g_stealth == true) then
  826.             g_stealth = false
  827.             CensusPlus_Msg(CENSUSPLUS_STEALTHOFF)
  828.         else
  829.             g_Verbose = false
  830.             CensusPlus_Msg(CENSUSPLUS_STEALTHON)
  831.             g_stealth = true
  832.         end
  833.     elseif (state == "On") then
  834.         g_Verbose = false
  835.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  836.             CensusPlus_Msg(CENSUSPLUS_STEALTHON)
  837.         end
  838.         g_stealth = true
  839.     elseif (state == "Off") then
  840.         g_stealth = false
  841.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  842.             CensusPlus_Msg(CENSUSPLUS_STEALTHOFF)
  843.         end
  844.     end
  845. end
  846.  
  847. local function CensusPlus_CensusButtonShown(self)
  848.     --print(CensusPlus_Database["Info"]["CensusButtonShown"])
  849.     --print(CensusPlus_PerCharInfo["CensusButtonShown"])
  850.     if ((CensusPlus_PerCharInfo["CensusButtonShown"] == nil) and (CensusPlus_Database["Info"]["CensusButtonShown"] == true)) then
  851.         CensusPlus_CensusButtonShown_toggle("On")
  852.         --_G[CensusButton:GetName().."Text"]:SetText("C+")
  853.     elseif ((CensusPlus_PerCharInfo["CensusButtonShown"] == nil) and (CensusPlus_Database["Info"]["CensusButtonShown"] == false)) then
  854.         CensusPlus_CensusButtonShown_toggle("Off")
  855.     elseif (CensusPlus_PerCharInfo["CensusButtonShown"] == true) then
  856.         --CensusButton:SetText("30")
  857.         CensusPlus_CensusButtonShown_toggle("On")
  858.     elseif (CensusPlus_PerCharInfo["CensusButtonShown"] == false) then
  859.         CensusPlus_CensusButtonShown_toggle("Off")
  860.     else
  861.     end
  862. end
  863.  
  864. function CensusPlus_CensusButtonShown_toggle(state)
  865.     if (state == "alter") then
  866.         if (g_CensusButtonShown == true) then
  867.             g_CensusButtonShown = false
  868.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNOFF)
  869.             CensusButtonFrame:Hide()
  870.         else
  871.             g_CensusButtonShown = true
  872.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNON)
  873.             CensusButtonFrame:Show()
  874.         end
  875.     elseif (state == "On") then
  876.         g_CensusButtonShown = true
  877.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  878.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNON)
  879.         end
  880.         CensusButtonFrame:Show()
  881.     elseif (state == "Off") then
  882.         g_CensusButtonShown = false
  883.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  884.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONSHOWNOFF)
  885.         end
  886.         CensusButtonFrame:Hide()
  887.     end
  888. end
  889.  
  890. local function CensusPlus_CensusButtonAnimi(self)
  891.     --print(CensusPlus_Database["Info"]["CensusButtonAnimi"])
  892.     --print(CensusPlus_PerCharInfo["CensusButtonAnimi"])
  893.     if ((CensusPlus_PerCharInfo["CensusButtonAnimi"] == nil) and (CensusPlus_Database["Info"]["CensusButtonAnimi"] == true)) then
  894.         CensusPlus_CensusButtonAnimi_toggle("On")
  895.         --_G[CensusButton:GetName().."Text"]:SetText("C+")
  896.     elseif ((CensusPlus_PerCharInfo["CensusButtonAnimi"] == nil) and (CensusPlus_Database["Info"]["CensusButtonAnimi"] == false)) then
  897.         --print("CensusButtonAnimi 2")
  898.         CensusPlus_CensusButtonAnimi_toggle("Off")
  899.     elseif (CensusPlus_PerCharInfo["CensusButtonAnimi"] == true) then
  900.         --CensusButton:SetText("30")
  901.         CensusPlus_CensusButtonAnimi_toggle("On")
  902.     elseif (CensusPlus_PerCharInfo["CensusButtonAnimi"] == false) then
  903.         CensusPlus_CensusButtonAnimi_toggle("Off")
  904.     else
  905.     end
  906. end
  907.  
  908. function CensusPlus_CensusButtonAnimi_toggle(state)
  909.     if (state == "alter") then
  910.         if (g_CensusButtonAnimi == true) then
  911.             g_CensusButtonAnimi = false
  912.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMIOFF)
  913.             CensusButton:SetNormalFontObject(GameFontNormal)
  914.             CensusButton:SetText("C+")
  915.         else
  916.             g_CensusButtonAnimi = true
  917.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMION)
  918.         end
  919.         --CensusButtonFrame:Show()
  920.     elseif (state == "On") then
  921.         g_CensusButtonAnimi = true
  922.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  923.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMION)
  924.         end
  925.         --CensusButtonFrame:Show()
  926.     elseif (state == "Off") then
  927.         g_CensusButtonAnimi = false
  928.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  929.             CensusPlus_Msg(CENSUSPLUS_CENSUSBUTTONANIMIOFF)
  930.         end
  931.         CensusButton:SetNormalFontObject(GameFontNormal)
  932.         CensusButton:SetText("C+")
  933.     end
  934. end
  935.  
  936. function CensusPlus_FinishSound(state)
  937.     --print(CensusPlus_Database["Info"]["PlayFinishSound"])
  938.     --print(CensusPlus_PerCharInfo["PlayFinishSound"])
  939.     if ((CensusPlus_PerCharInfo["PlayFinishSound"] == nil) and (CensusPlus_Database["Info"]["PlayFinishSound"] == true)) then
  940.         CensusPlus_FinishSound_toggle("On")
  941.         --_G[CensusButton:GetName().."Text"]:SetText("C+")
  942.     elseif ((CensusPlus_PerCharInfo["PlayFinishSound"] == nil) and (CensusPlus_Database["Info"]["PlayFinishSound"] == false)) then
  943.         CensusPlus_FinishSound_toggle("Off")
  944.     elseif (CensusPlus_PerCharInfo["PlayFinishSound"] == true) then
  945.         --CensusButton:SetText("30")
  946.         CensusPlus_FinishSound_toggle("On")
  947.     elseif (CensusPlus_PerCharInfo["PlayFinishSound"] == false) then
  948.         CensusPlus_FinishSound_toggle("Off")
  949.     else
  950.     end
  951. end
  952.  
  953. function CensusPlus_FinishSound_toggle(state)
  954.     if (state == "alter") then
  955.         if (g_PlayFinishSound == true) then
  956.             g_PlayFinishSound = false
  957.             CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDOFF)
  958.         else
  959.             g_PlayFinishSound = true
  960.             CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDON)
  961.         end
  962.     elseif (state == "On") then
  963.         g_PlayFinishSound = true
  964.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  965.             CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDON)
  966.         end
  967.     elseif (state == "Off") then
  968.         g_PlayFinishSound = false
  969.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  970.             CensusPlus_Msg(CENSUSPLUS_PLAYFINISHSOUNDOFF)
  971.         end
  972.     end
  973. end
  974.  
  975. -- CensusPlusClassic Auto Census set flag
  976. local function CensusPlus_SetAutoCensus(self)
  977.     --print(CensusPlus_Database["Info"]["AutoCensus"])
  978.     --print(CensusPlus_PerCharInfo["AutoCensus"])
  979.     if ((CensusPlus_PerCharInfo["AutoCensus"] == nil) and (CensusPlus_Database["Info"]["AutoCensus"] == true)) then
  980.         CensusPlus_AutoCensus_toggle("On")
  981.         --_G[CensusButton:GetName().."Text"]:SetText("C+")
  982.     elseif ((CensusPlus_PerCharInfo["AutoCensus"] == nil) and (CensusPlus_Database["Info"]["AutoCensus"] == false)) then
  983.         CensusPlus_AutoCensus_toggle("Off")
  984.     elseif (CensusPlus_PerCharInfo["AutoCensus"] == true) then
  985.         --CensusButton:SetText("30")
  986.         CensusPlus_AutoCensus_toggle("On")
  987.     elseif (CensusPlus_PerCharInfo["AutoCensus"] == false) then
  988.         CensusPlus_AutoCensus_toggle("Off")
  989.     else
  990.         print("call AutoCensus farm")
  991.     end
  992. end
  993.  
  994. function CensusPlus_AutoCensus_toggle(state)
  995.     if (state == "alter") then
  996.         if (CPp.AutoCensus == true) then
  997.             CPp.AutoCensus = false
  998.             CensusPlus_Msg(CENSUSPLUS_AUTOCENSUSOFF)
  999.         else
  1000.             CPp.AutoCensus = true
  1001.             CensusPlus_Msg(CENSUSPLUS_AUTOCENSUSON)
  1002.         end
  1003.     elseif (state == "On") then
  1004.         CPp.AutoCensus = true
  1005.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  1006.             CensusPlus_Msg(CENSUSPLUS_AUTOCENSUSON)
  1007.         end
  1008.     elseif (state == "Off") then
  1009.         CPp.AutoCensus = false
  1010.         if (g_Options_confirm_txt and not (CPp.FirstLoad == true)) then
  1011.             CensusPlus_Msg(CENSUSPLUS_AUTOCENSUSOFF)
  1012.         end
  1013.     end
  1014. end
  1015.  
  1016. -- CensusPlusClassic Display Usage
  1017. function CensusPlus_DisplayUsage()
  1018.     CensusPlusClassic:Show()
  1019.     local stealthUsage = g_stealth
  1020.     g_stealth = false
  1021.     CensusPlus_Msg(
  1022.         CENSUSPLUS_USAGE .. "\n  /CensusPlusClassic" .. CENSUSPLUS_OR .. "/Census+ " .. CENSUSPLUS_OR .. "/Census" .. CENSUSPLUS_AND .. CENSUSPLUS_HELP_0
  1023.     )
  1024.     CensusPlus_Msg(
  1025.         "  /CensusPlusClassic " .. CENSUS_OPTIONS_VERBOSE .. CENSUSPLUS_HELP_1
  1026.     )
  1027.     CensusPlus_Msg(
  1028.         "  /CensusPlusClassic " .. CENSUS_OPTIONS_STEALTH .. CENSUSPLUS_HELP_11
  1029.     )
  1030.     CensusPlus_Msg(
  1031.         "  /CensusPlusClassic " .. CENSUSPLUS_BUTTON_OPTIONS .. CENSUSPLUS_HELP_2
  1032.     )
  1033.     CensusPlus_Msg(
  1034.         "  /CensusPlusClassic " .. CENSUSPLUS_TAKE .. CENSUSPLUS_HELP_3
  1035.     )
  1036.     CensusPlus_Msg(
  1037.         "  /CensusPlusClassic " .. CENSUSPLUS_STOP .. CENSUSPLUS_HELP_4
  1038.     )
  1039.     CensusPlus_Msg(
  1040.         "  /CensusPlusClassic " .. CENSUSPLUS_PRUNE .. CENSUSPLUS_HELP_5
  1041.     )
  1042.     CensusPlus_Msg("  /CensusPlusClassic serverprune" .. CENSUSPLUS_HELP_6)
  1043.     CensusPlus_Msg("  /CensusPlusClassic who name" .. CENSUSPLUS_HELP_7)
  1044.     CensusPlus_Msg("  /CensusPlusClassic who unguilded 70" .. CENSUSPLUS_HELP_8)
  1045.     CensusPlus_Msg("  /CensusPlusClassic timer X " .. CENSUSPLUS_HELP_9)
  1046.     CensusPlus_Msg("  /CensusPlusClassic me" .. CENSUSPLUS_HELP_10)
  1047.     g_stealth = stealthUsage
  1048. end
  1049.  
  1050. -- CensusPlus_InternalWho - will go through our local database and see if we have
  1051. -- any info on this person
  1052. function CensusPlus_InternalWho(search, level)
  1053.     g_InternalSearchName = search
  1054.     g_InternalSearchLevel = level
  1055.     g_InternalSearchCount = 0
  1056.     local realmName = CensusPlus_GetUniqueRealmName()
  1057.  
  1058.     CensusPlus_ForAllCharacters(
  1059.         realmName,
  1060.         UnitFactionGroup("player"),
  1061.         nil,
  1062.         nil,
  1063.         nil,
  1064.         nil,
  1065.         CensusPlus_InternalWhoResult
  1066.     )
  1067.  
  1068.     CensusPlus_WhoMsg(
  1069.         CENSUSPLUS_FOUND_CAP .. g_InternalSearchCount .. CENSUSPLUS_PLAYERS
  1070.     )
  1071. end
  1072.  
  1073. function CensusPlus_InternalWhoResult(name, level, guild, race, class, lastSeen)
  1074.     lowerName = string.lower(name)
  1075.     level = string.lower(level)
  1076.     lowerGuild = string.lower(CensusPlus_SafeCheck(guild))
  1077.     if (g_InternalSearchName == "unguilded") then
  1078.         if (guild == "") then
  1079.             local doit = 1
  1080.             if (g_InternalSearchLevel ~= nil) then
  1081.                 if (g_InternalSearchLevel ~= level) then
  1082.                     doit = 0
  1083.                 end
  1084.             end
  1085.             if (doit == 1) then
  1086.                 local out =
  1087.                     name .. " : " .. LEVEL .. " " .. level .. " " .. race .. " " .. " " .. class
  1088.                 out = out .. CENSUSPLUS_LASTSEEN_COLON .. lastSeen
  1089.                 CensusPlus_WhoMsg(out)
  1090.                 g_InternalSearchCount = g_InternalSearchCount + 1
  1091.             end
  1092.         end
  1093.         -- found someone!
  1094.     elseif (string.find(lowerName, g_InternalSearchName) or string.find(
  1095.         lowerGuild,
  1096.         g_InternalSearchName
  1097.     )) then
  1098.         local out =
  1099.             name .. " : " .. LEVEL .. " " .. level .. " " .. race .. " " .. " " .. class
  1100.         if (guild ~= "") then
  1101.             out = out .. " <" .. guild .. ">"
  1102.         end
  1103.         out = out .. CENSUSPLUS_LASTSEEN_COLON .. lastSeen
  1104.         CensusPlus_WhoMsg(out)
  1105.         g_InternalSearchCount = g_InternalSearchCount + 1
  1106.     end
  1107. end
  1108.  
  1109.  
  1110. -- Minimize the window
  1111. -- referenced by CensusPlusClassic.xml
  1112. function CensusPlus_OnClickMinimize(self)  
  1113.     if( CensusPlusClassic:IsVisible() ) then
  1114.         --MiniCensusPlus:Show();
  1115.         CensusPlusClassic:Hide();
  1116.     end
  1117. end
  1118.  
  1119. -- Minimize the window
  1120. -- referenced by CensusPlusClassic.xml
  1121. function CensusPlus_OnClickMaximize(self)
  1122.     if MiniCensusPlus:IsVisible() then
  1123.         MiniCensusPlus:Hide()
  1124.         CensusPlusClassic:Show()
  1125.     end
  1126. end
  1127.  
  1128. -- Take or pause a census depending on current status
  1129. -- referenced by CensusPlusClassic.xml
  1130. function CENSUSPLUS_TAKE_OnClick(self)
  1131.     if CPp.IsCensusPlusInProgress then
  1132.         --CensusPlus_Msg(CENSUSPLUS_ISINPROGRESS);
  1133.         CensusPlus_TogglePause()
  1134.     else
  1135.         CensusPlus_StartCensus()
  1136.     end
  1137. end
  1138.  
  1139. -- Display a tooltip for the take button
  1140. -- referenced by CensusPlusClassic.xml
  1141. function CENSUSPLUS_TAKE_OnEnter(self, motion)
  1142.     if (motion == true) then
  1143.         if CPp.IsCensusPlusInProgress then
  1144.             if CPp.CensusPlusManuallyPaused then
  1145.                 GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  1146.                 GameTooltip:SetText(CENSUSPLUS_UNPAUSECENSUS, 1.0, 1.0, 1.0)
  1147.                 GameTooltip:Show()
  1148.             else
  1149.                 GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  1150.                 GameTooltip:SetText(CENSUSPLUS_PAUSECENSUS, 1.0, 1.0, 1.0)
  1151.                 GameTooltip:Show()
  1152.             end
  1153.         else
  1154.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  1155.             GameTooltip:SetText(CENSUSPLUS_TAKECENSUS, 1.0, 1.0, 1.0)
  1156.             GameTooltip:Show()
  1157.         end
  1158.     -- frame created underneath cursor.. not cursor movement to frame
  1159.     else
  1160.     end
  1161. end
  1162.  
  1163. -- referenced by CensusPlusClassic.xml
  1164. function CENSUSPLUS_STOP_OnEnter(self, motion)
  1165.     if (motion == true) then
  1166.         GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  1167.         GameTooltip:SetText(CENSUSPLUS_STOPCENSUS_TOOLTIP, 1.0, 1.0, 1.0)
  1168.         GameTooltip:Show()
  1169.     -- frame created underneath cursor.. not cursor movement to frame
  1170.     else
  1171.     end
  1172. end
  1173.  
  1174. -- referenced by CensusPlusClassic.xml
  1175. function CENSUSPLUS_MANUALWHO_OnEnter(self, motion)
  1176.     if (motion == true) then
  1177.         GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  1178.         GameTooltip:SetText("Issues manual who request.", 1.0, 1.0, 1.0)
  1179.         GameTooltip:Show()
  1180.     -- frame created underneath cursor.. not cursor movement to frame
  1181.     else
  1182.     end
  1183. end
  1184.  
  1185.  
  1186. function CensusPlus_TimerSet(self, minutes, ovrride)
  1187.     if minutes == nil then
  1188.         minutes = 30
  1189.     end
  1190.     if ovrride then
  1191.         CensusPlus_PerCharInfo["AutoCensusTimer"] = minutes * 60
  1192.         --print("CCO Timer = "..minutes)
  1193.         --print("AW timer = "..minutes)
  1194.     else
  1195.         CensusPlus_Database["Info"]["AutoCensusTimer"] = minutes * 60
  1196.     end
  1197.     --CensusPlus_Msg( CENSUS_OPTIONS_AUTOCENSUS.." "..CENSUSPLUS_AUTOCENSUS_DELAYTIME .." ".. minutes);
  1198. end
  1199.  
  1200. local function CensusPlus_BackgroundAlpha(self,steps)
  1201.     CensusPlus_Database["Info"]["CPWindow_Transparency"] = steps
  1202. end
  1203.    
  1204. -- Pause the current census
  1205. function CensusPlus_TogglePause()
  1206.     if (CPp.IsCensusPlusInProgress == true) then
  1207.         if (CPp.CensusPlusManuallyPaused == true) then
  1208.             CensusPlusTakeButton:SetText(CENSUSPLUS_PAUSE)
  1209.             CPp.CensusPlusManuallyPaused = false
  1210.         else
  1211.             CensusPlusTakeButton:SetText(CENSUSPLUS_UNPAUSE)
  1212.             if (g_Verbose == true) then
  1213.                 CensusPlus_Msg(CENSUSPLUS_PAUSECENSUS)
  1214.             end
  1215.  
  1216.             CPp.CensusPlusManuallyPaused = true
  1217.             CensusPlayerOnly = false
  1218.         end
  1219.     end
  1220. end
  1221.  
  1222. -- Purge the database for this realm and faction
  1223. -- referenced by CensusPlusClassic.xml
  1224. function CENSUSPLUS_PURGE_OnClick()
  1225.     StaticPopup_Show ("CP_PURGE_CONFIRM");
  1226. end
  1227.  
  1228. -- CensusPlus_DoPurge
  1229. function CensusPlus_DoPurge()
  1230.     if (CensusPlus_Database["Servers"] ~= nil) then
  1231.         CensusPlus_Database["Servers"] = nil
  1232.     end
  1233.     CensusPlus_Database["Servers"] = {}
  1234.     CensusPlus_UpdateView()
  1235.     --CensusPlus_Msg(CENSUSPLUS_PURGEMSG);
  1236.  
  1237.     if (CensusPlus_Database["Guilds"] ~= nil) then
  1238.         CensusPlus_Database["Guilds"] = nil
  1239.     end
  1240.     CensusPlus_Database["Guilds"] = {}
  1241.  
  1242.     if (CensusPlus_Database["TimesPlus"] ~= nil) then
  1243.         CensusPlus_Database["TimesPlus"] = nil
  1244.     end
  1245.     CensusPlus_Database["TimesPlus"] = {}
  1246.  
  1247.     if (CensusPlus_Profile ~= nil) then
  1248.         CensusPlus_Profile = nil
  1249.     end
  1250.     CensusPlus_Profile = {}
  1251.  
  1252.     if not (CPp.FirstLoad == true) then
  1253.         CensusPlus_Msg(CENSUSPLUS_PURGEDALL)
  1254.     end
  1255. end
  1256.  
  1257. -- Take a CensusPlusClassic
  1258. function CensusPlus_StartCensus()
  1259.     CensusPlusTakeButton:SetText(CENSUSPLUS_PAUSE)
  1260.  
  1261.     --[[ work in progress - continue census run from last state on DC or valid Character stop restart.
  1262.          Determine if pre-existing jobqueue exists from running job that was DCed or paused and logged out.
  1263.          if exists that determine delay since last queue completion..
  1264.          if more then x time then dump queues and restart as new start else set below states to active run status and process existing queues.
  1265.      --]]
  1266.  
  1267.     -- used to trigger queue processing when OnUpdate
  1268.     g_FirstRun = true
  1269.     local g_factionGroup = UnitFactionGroup("player")
  1270.     local realm = ""
  1271.     local lastjobtimediff = 1
  1272.     local realmName = CensusPlus_GetUniqueRealmName()
  1273.     --print( "Prep for start");
  1274.     if (CensusPlus_JobQueue.CensusPlus_last_time and CensusPlus_JobQueue.CensusPlus_last_time > 1) then
  1275.         lastjobtimediff = time() - CensusPlus_JobQueue.CensusPlus_last_time
  1276.         --print( "got time");
  1277.         --print( lastjobtimediff);
  1278.     else
  1279.         CensusPlus_JobQueue.CensusPlus_last_time = 1000
  1280.         lastjobtimediff = time() - CensusPlus_JobQueue.CensusPlus_last_time
  1281.     end
  1282.     if not CensusPlus_JobQueue.CensusPlus_LoginRealm then
  1283.         CensusPlus_JobQueue.CensusPlus_LoginRealm = " "
  1284.         --print( "typed Realm");
  1285.     end
  1286.     if not CensusPlus_JobQueue.CensusPlus_LoginFaction then
  1287.         CensusPlus_JobQueue.CensusPlus_LoginFaction = " "
  1288.     end
  1289.     --print(lastjobtimediff);
  1290.     if (lastjobtimediff <= 300 and CensusPlus_JobQueue.CensusPlus_LoginFaction and CensusPlus_JobQueue.CensusPlus_LoginRealm and (CensusPlus_JobQueue.CensusPlus_LoginFaction == g_factionGroup) and (CensusPlus_JobQueue.CensusPlus_LoginRealm == realmName)) then
  1291.         --print ("continue last Census");
  1292.         local queue_entry_count = #CensusPlus_JobQueue
  1293.         --print (queue_entry_count);
  1294.         g_FirstRun = False
  1295.         --print ("Start new Census");
  1296.     else
  1297.         CensusPlus_JobQueue = {}
  1298.         CensusPlus_JobQueue.g_NumNewCharacters = 0
  1299.         CensusPlus_JobQueue.g_NumUpdatedCharacters = 0
  1300.         CensusPlus_Zero_g_TimeDatabase()
  1301.         CensusPlus_JobQueue.g_TempCount = nil
  1302.         CensusPlus_JobQueue.g_TempCount = {}
  1303.     end
  1304.  
  1305.     CensusPlus_UpdateView()
  1306.     if (g_factionGroup == nil or g_factionGroup == CENSUSPlus_NEUTRAL) then
  1307.         CensusPlus_Msg(CENSUSPLUS_NOTINFACTION)
  1308.         CPp.LastCensusRun = time()
  1309.     --return;
  1310.     elseif CPp.IsCensusPlusInProgress then
  1311.         --if( CPp.CensusPlusManuallyPaused == true ) then
  1312.         --  CPp.CensusPlusManuallyPaused = false;
  1313.         --  CensusPlusPauseButton:SetText( CENSUSPLUS_PAUSE );
  1314.         --else
  1315.         -- D.o not initiate a new CensusPlusClassic whi.le one is in progress
  1316.         CensusPlus_Msg(
  1317.             "Census in progress but this message should not have shown"
  1318.         )
  1319.           --return
  1320.         --end
  1321.     elseif g_CurrentlyInBG then
  1322.         CPp.LastCensusRun = time() - 600
  1323.         if not g_CurrentlyInBG_Msg then
  1324.             CensusPlus_Msg(CENSUSPLUS_ISINBG)
  1325.             g_CurrentlyInBG_Msg = true
  1326.         end
  1327.     else
  1328.         --
  1329.         --  Set a timer
  1330.         --
  1331.         g_CensusPlus_StartTime = time()
  1332.         --
  1333.         -- Initialize the job queue and counters
  1334.         --
  1335.         CensusPlus_Msg(CENSUSPLUS_TAKINGONLINE)
  1336.  
  1337.         local realmName = CensusPlus_GetUniqueRealmName()
  1338.         CensusPlus_JobQueue.CensusPlus_LoginRealm = realmName
  1339.         CensusPlus_JobQueue.CensusPlus_LoginFaction = g_factionGroup
  1340.         if (HortonBug == true) then
  1341.             says("after check local realm = " .. realmName)
  1342.         end
  1343.  
  1344.         if CensusPlayerOnly then
  1345.             if (UnitLevel("player") >= MIN_CHARACTER_LEVEL) then
  1346.                 local meplayer = GetUnitName("player")
  1347.                 local job =
  1348.                     CensusPlus_CreateJob(
  1349.                         MIN_CHARACTER_LEVEL,
  1350.                         MAX_CHARACTER_LEVEL,
  1351.                         nil,
  1352.                         nil,
  1353.                         meplayer
  1354.                     )
  1355.                 InsertJobIntoQueue(job)
  1356.                 CPp.IsCensusPlusInProgress = true
  1357.                 g_WaitingForWhoUpdate = false
  1358.                 CPp.CensusPlusManuallyPaused = false
  1359.  
  1360.                 local hour, minute = GetGameTime()
  1361.                 g_TakeHour = hour
  1362.                 g_ResetHour = true
  1363.  
  1364.             -- queue who for player into job que
  1365.             elseif (UnitLevel("player") < MIN_CHARACTER_LEVEL) then
  1366.                 CensusPlus_Msg("Player is below level 20")
  1367.                 CensusPlayerOnly = false
  1368.             elseif CPp.IsCensusPlusInProgress then
  1369.                 CensusPlus_Msg(CENSUSPLUS_ISINPROGRESS)
  1370.                 CensusPlayerOnly = false
  1371.             end
  1372.         else
  1373.             if (CensusPlus_Database["Info"]["CensusButtonAnimi"] == true) then
  1374.                 CensusButton:SetNormalFontObject(GameFontNormalSmall)
  1375.                 CensusButton:SetText(MAX_CHARACTER_LEVEL)
  1376.             end
  1377.  
  1378.             if g_FirstRun then
  1379.                 CensusPlus_Load_JobQueue()
  1380.             end
  1381.  
  1382.             CPp.IsCensusPlusInProgress = true
  1383.             g_WaitingForWhoUpdate = false
  1384.             CPp.CensusPlusManuallyPaused = false
  1385.  
  1386.             local hour, minute = GetGameTime()
  1387.             g_TakeHour = hour
  1388.             g_ResetHour = true
  1389.         end
  1390.     end
  1391. end
  1392.  
  1393.  
  1394. -- First we load the stack with our jobs... First in last out
  1395. function CensusPlus_Load_JobQueue()
  1396.     -- first load queue with jobs in increment of 10 from 1-10 thru max_character_level-19 - max_character_level-10
  1397.     for counter = MIN_CHARACTER_LEVEL / 10, floor(
  1398.         MAX_CHARACTER_LEVEL / 10
  1399.     ) - 1, 1 do
  1400.         local job =
  1401.             CensusPlus_CreateJob(counter * 10, counter * 10 + 9, nil, nil, nil)
  1402.         InsertJobIntoQueue(job)
  1403.     end
  1404.     -- next to last job to load is Max_character_level-9 thrun Max_character_level-1  if Max_character_level modulo 10 = 0
  1405.     local job =
  1406.         CensusPlus_CreateJob(
  1407.             MAX_CHARACTER_LEVEL - 9,
  1408.             MAX_CHARACTER_LEVEL - 1,
  1409.             nil,
  1410.             nil,
  1411.             nil
  1412.         )
  1413.     InsertJobIntoQueue(job)
  1414.  
  1415.     -- last job to load in last in first out queus is MAX_CHARACTER_LEVEL to MAX_CHARACTER_LEVEL
  1416.     -- this is one job that will almost always en.d up having to be broken up and reloaded (depending on realm population)
  1417.     local job =
  1418.         CensusPlus_CreateJob(
  1419.             MAX_CHARACTER_LEVEL,
  1420.             MAX_CHARACTER_LEVEL,
  1421.             nil,
  1422.             nil,
  1423.             nil
  1424.         )
  1425.     InsertJobIntoQueue(job)
  1426.  
  1427.     --for counter = 60, MAX_CHARACTER_LEVEL, 1  do
  1428.     --  local job = CensusPlus_CreateJob( counter, counter, nil, nil, nil );
  1429.     --  InsertJobIntoQueue(job);
  1430.     --end
  1431.  
  1432.     --  Test inserts
  1433.     --local job = CensusPlus_CreateJob( 11, 12, "Troll", nil, nil );
  1434.     --InsertJobIntoQueue(job);
  1435. end
  1436.  
  1437. -- Stop a CensusPlusClassic
  1438. -- referenced by CensusPlusClassic.xml
  1439. function CENSUSPLUS_STOPCENSUS()
  1440.     if CPp.IsCensusPlusInProgress then
  1441.         CensusPlusTakeButton:SetText(CENSUSPLUS_TAKE)
  1442.         CPp.CensusPlusManuallyPaused = false
  1443.         whoquery_answered = false
  1444.         whoquery_active = false
  1445.  
  1446.         CensusPlusScanProgress:SetText(CENSUSPLUS_SCAN_PROGRESS_0)
  1447.  
  1448.         CensusPlus_DisplayResults()
  1449.         CensusPlus_JobQueue = {}
  1450.  
  1451.         --  Clean up the times
  1452.         CENSUSPLUS_PRUNETimes()
  1453.     else
  1454.         CensusPlus_Msg(CENSUSPLUS_NOCENSUS)
  1455.     end
  1456.    
  1457.     -- Add revert CensusButton back to defauit
  1458.     CensusButton:SetNormalFontObject(GameFontNormal)
  1459.     CensusButton:SetText("C+")
  1460. end
  1461.  
  1462. function CENSUSPLUS_MANUALWHO()
  1463.     print("istsecure() = ", issecure())
  1464.     ManualWho()
  1465. end
  1466.  
  1467. -- Display Census results
  1468. function CensusPlus_DisplayResults()
  1469.     --
  1470.     -- We are all done, report our results
  1471.     --
  1472.     CPp.IsCensusPlusInProgress = false
  1473.     CensusPlusScanProgress:SetText(CENSUSPLUS_SCAN_PROGRESS_0)
  1474.     g_Consecutive = g_Consecutive + 1
  1475.     CensusPlusConsecutive:SetText(format(CENSUSPLUS_CONSECUTIVE, g_Consecutive))
  1476.  
  1477.     --
  1478.     --  Finish our timer
  1479.     --
  1480.     local total_time = time() - g_CensusPlus_StartTime
  1481.     local realmslisttext = ""
  1482.     if not g_stealth then
  1483.         --print( CensusPlus_JobQueue.g_NumNewCharacters);
  1484.         --print( CensusPlus_JobQueue.g_NumUpdatedCharacters);
  1485.         CensusPlus_Msg(
  1486.             format(
  1487.                 CENSUSPLUS_FINISHED,
  1488.                 CensusPlus_JobQueue.g_NumNewCharacters,
  1489.                 CensusPlus_JobQueue.g_NumUpdatedCharacters,
  1490.                 SecondsToTime(total_time)
  1491.             )
  1492.         )
  1493.         --print( CP_g_queue_count);
  1494.         if (CP_g_queue_count > 0) then
  1495.             local avg_Time_per_que = total_time / CP_g_queue_count
  1496.             --print( avg_Time_per_que);
  1497.         end
  1498.        
  1499.         realmslisttext = string.sub(realmslisttext, 3)
  1500.         ChatFrame1:AddMessage(realmslisttext, 1.0, 0.3, 0.1)
  1501.         ChatFrame1:AddMessage(CENSUSPLUS_UPLOAD, 0.1, 1.0, 1.0)
  1502.     end
  1503.     CensusPlus_UpdateView()
  1504.     CPp.LastCensusRun = time()
  1505.     CensusPlus_JobQueue.g_NumNewCharacters = 0
  1506.     CensusPlus_JobQueue.g_NumUpdatedCharacters = 0
  1507.     CensusPlusTakeButton:SetText(CENSUSPLUS_TAKE)
  1508. end
  1509.  
  1510. -- Create a who command text for the input job
  1511. function CensusPlus_CreateWhoText(job)
  1512.     local whoText = ""
  1513.     local race = job.m_Race
  1514.     local locale = GetLocale()
  1515.     if (race ~= nil) then
  1516.         if (locale == "ruRU") then
  1517.             whoText = whoText .. ' р-"' .. race .. '"'
  1518.         else
  1519.             whoText = whoText .. ' r-"' .. race .. '"'
  1520.         end
  1521.     end
  1522.  
  1523.     local class = job.m_Class
  1524.     if (class ~= nil) then
  1525.         if (locale == "ruRU") then
  1526.             whoText = whoText .. ' к-"' .. class .. '"'
  1527.         else
  1528.             whoText = whoText .. ' c-"' .. class .. '"'
  1529.         end
  1530.     end
  1531.  
  1532.     local letter = job.m_Letter
  1533.     if (letter ~= nil) then
  1534.         if (locale == "ruRU") then
  1535.             whoText = whoText .. " и-" .. letter
  1536.         else
  1537.             whoText = whoText .. " n-" .. letter
  1538.         end
  1539.     end
  1540.  
  1541.     local minLevel = tostring(job.m_MinLevel)
  1542.     if (minLevel == nil) then
  1543.         minLevel = 1
  1544.     end
  1545.     local maxLevel = job.m_MaxLevel
  1546.     if (maxLevel == nil) then
  1547.         maxLevel = MAX_CHARACTER_LEVEL
  1548.     end
  1549.     whoText = whoText .. " " .. minLevel .. "-" .. maxLevel
  1550.  
  1551.     local zoneLetter = job.m_zoneLetter
  1552.     if (zoneLetter ~= nil) then
  1553.         if (locale == "ruRU") then
  1554.             whoText = whoText .. " з-" .. zoneLetter
  1555.         else
  1556.             whoText = whoText .. " z-" .. zoneLetter
  1557.         end
  1558.     end
  1559.  
  1560.     return whoText
  1561. end
  1562.  
  1563. -- Create a job
  1564. function CensusPlus_CreateJob(minLevel, maxLevel, race, class, letter)
  1565.     local job = {}
  1566.     job.m_MinLevel = minLevel
  1567.     job.m_MaxLevel = maxLevel
  1568.     job.m_Race = race
  1569.     job.m_Class = class
  1570.     job.m_Letter = letter
  1571.  
  1572.     CensusPlus_DumpJob(job)
  1573.  
  1574.     return job
  1575. end
  1576.  
  1577. -- Debug function do dump a job
  1578. function CensusPlus_DumpJob(job)
  1579.     local whoText = ""
  1580.     local race = job.m_Race
  1581.     if (race ~= nil) then
  1582.         whoText = whoText .. " R: " .. race
  1583.     end
  1584.  
  1585.     local class = job.m_Class
  1586.     if (class ~= nil) then
  1587.         whoText = whoText .. " C: " .. class
  1588.     end
  1589.  
  1590.     local letter = job.m_Letter
  1591.     if (letter ~= nil) then
  1592.         whoText = whoText .. " N: " .. letter
  1593.     end
  1594.  
  1595.     local minLevel = job.m_MinLevel
  1596.     if (minLevel ~= nil and minLevel ~= 0) then
  1597.         whoText = whoText .. " min: " .. minLevel
  1598.     end
  1599.  
  1600.     local maxLevel = job.m_MaxLevel
  1601.     if (maxLevel ~= nil and maxLevel ~= 0) then
  1602.         whoText = whoText .. " max: " .. maxLevel
  1603.     end
  1604.  
  1605.     local zoneLetter = job.m_zoneLetter
  1606.     if (zoneLetter ~= nil) then
  1607.         whoText = whoText .. " Z: " .. zoneLetter
  1608.     end
  1609.  
  1610.     ---CensusPlus_Msg( "JOB DUMP: " .. whoText );
  1611. end
  1612.  
  1613. local whoMsg
  1614.  
  1615. -- Called on events
  1616. -- referenced by CensusPlusClassic.xml
  1617. function CensusPlus_OnEvent(self, event, ...)
  1618.     local arg1, arg2, arg3, arg4 = ...
  1619.     if (arg1 == nil) then
  1620.         arg1 = "nil"
  1621.     end
  1622.     if (arg2 == nil) then
  1623.         arg2 = "nil"
  1624.     end
  1625.     if (arg3 == nil) then
  1626.         arg3 = "nil"
  1627.     end
  1628.     if (arg4 == nil) then
  1629.         arg4 = "nil"
  1630.     end
  1631.  
  1632.     -- If we have not been initialized,  nothing
  1633.     if (g_CensusPlusInitialized == false) then
  1634.         if ((event == "ADDON_LOADED") and (arg1 == "CensusPlusClassic")) then
  1635.             self:UnregisterEvent("ADDON_LOADED") -- need this or we get hit on all preceeding addon loaded.. including the LOD's
  1636.             --  Initialize our variables
  1637.             g_addon_loaded = true
  1638.             --print("Addon Loaded")
  1639.             return
  1640.         end
  1641.         if (event == "PLAYER_ENTERING_WORLD") then
  1642.             g_player_loaded = true
  1643.             --print("Player in world")
  1644.             self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  1645.             if g_addon_loaded and g_player_loaded then
  1646.                 CensusPlus_InitializeVariables()
  1647.                 InitializeExperimental()
  1648.             end
  1649.         end
  1650.     end
  1651.  
  1652.     -- WHO_LIST_UPDATE
  1653.     if (event == "WHO_LIST_UPDATE") then
  1654.         CensusPlusClassic:UnregisterEvent("WHO_LIST_UPDATE")
  1655.         C_FriendList.SetWhoToUi(false)
  1656.         if WhoFrame:IsShown() then
  1657.           FriendsFrameCloseButton:Click()
  1658.         end
  1659.     FriendsFrame:RegisterEvent("WHO_LIST_UPDATE")
  1660.         CP_ProcessWhoEvent(whoMsg)
  1661.     end
  1662.    
  1663.     if (event == "TRAINER_SHOW" or event == "MERCHANT_SHOW" or event == "TRADE_SHOW" or event == "GUILD_REGISTRAR_SHOW" or event == "AUCTION_HOUSE_SHOW" or event == "BANKFRAME_OPENED" or event == "QUEST_DETAIL") then
  1664.         print(" Event triggered = " .. event)
  1665.         if CPp.IsCensusPlusInProgress then
  1666.             g_CensusPlusPaused = true
  1667.         end
  1668.     elseif (event == "TRAINER_CLOSED" or event == "MERCHANT_CLOSED" or event == "TRADE_CLOSED" or event == "GUILD_REGISTRAR_CLOSED" or event == "AUCTION_HOUSE_CLOSED" or event == "BANKFRAME_CLOSED" or event == "QUEST_FINISHED") then
  1669.         print(" Event triggered = " .. event)
  1670.         if CPp.IsCensusPlusInProgress then
  1671.             g_CensusPlusPaused = false
  1672.         end
  1673.        
  1674.     --[[
  1675.     -- Guild roster info not ready for release
  1676.     elseif (event == "GUILD_ROSTER_UPDATE") th.en
  1677.    
  1678.         --  Process Guild info
  1679.         --CensusPlus_Msg( " UPDATE GUILD " );
  1680.         if(not CP_updatingGuild ) th.en
  1681.             CP_updatingGuild  = 1;
  1682.             CensusPlus_ProcessGuildResults();
  1683.             CP_updatingGuild  = nil;
  1684.         end
  1685.    
  1686.     elseif (( event == "ADDON_LOADED") and (arg1 == "CensusPlusClassic")) then
  1687.         self:UnregisterEvent("ADDON_LOADED")   -- need this or we get hit on all preceeding addon loaded.. including the LOD's
  1688.        
  1689.         --  Initialize our variables
  1690.         CensusPlus_InitializeVariables()
  1691.     --]]
  1692.  
  1693.     elseif (event == "ZONE_CHANGED_NEW_AREA") then
  1694.         --  We need to check to see if we entered a battleground
  1695.         CensusPlus_CheckForBattleground()
  1696.     elseif (event == "UPDATE_BATTLEFIELD_STATUS") then
  1697.         CensusPlus_UpdateBattleGroundInfo()
  1698.     end
  1699. end
  1700.  
  1701. -- ProcessTarget --  called when UNIT_FOCUS event is fired
  1702. function CensusPlus_ProcessTarget(unit)
  1703.     if (not UnitIsPlayer(unit) or UnitIsUnit(unit, "player")) then
  1704.         return -- bail out on non-player unit or unit focus on self
  1705.     end
  1706.  
  1707.     local sightingData = {}
  1708.     sightingData = CensusPlus_CollectSightingData(unit)
  1709.  
  1710.     if (sightingData == nil or sightingData.faction == nil or sightingData.faction == CENSUSPlus_NEUTRAL) then
  1711.         -- worthless Neutral
  1712.         return
  1713.     end
  1714.  
  1715.     if (sightingData.level < 1) then
  1716.         --  Run away, Run Away.. Uncountable DEATH
  1717.         return
  1718.     end
  1719.  
  1720.     if (sightingData ~= nil and (sightingData.faction == CENSUSPlus_ALLIANCE or sightingData.faction == CENSUSPlus_HORDE)) then
  1721.         if (sightingData.guild == nil) then
  1722.             sightingData.guild = ""
  1723.             -- RGK testing [GUILD]
  1724.             sightingData.guildRankName = ""
  1725.             sightingData.guildRankIndex = ""
  1726.             --RGK endblock
  1727.         else
  1728.             sightingData.guild =
  1729.                 PTR_Color_ProblemRealmGuilds_check(sightingData.guild)
  1730.         end
  1731.         --
  1732.         -- Get the portion of the database for this server
  1733.         --
  1734.         realmName = CensusPlus_GetUniqueRealmName()
  1735.        
  1736.         local realmDatabase = CensusPlus_Database["Servers"][realmName]
  1737.         if (realmDatabase == nil) then
  1738.             CensusPlus_Database["Servers"][realmName] = {}
  1739.             realmDatabase = CensusPlus_Database["Servers"][realmName]
  1740.         end
  1741.  
  1742.         -- Get the portion of the database for this faction
  1743.         local factionDatabase = realmDatabase[sightingData.faction]
  1744.         if (factionDatabase == nil) then
  1745.             realmDatabase[sightingData.faction] = {}
  1746.             factionDatabase = realmDatabase[sightingData.faction]
  1747.         end
  1748.  
  1749.         -- Get racial database
  1750.         local raceDatabase = factionDatabase[sightingData.race]
  1751.         if (raceDatabase == nil) then
  1752.             factionDatabase[sightingData.race] = {}
  1753.             raceDatabase = factionDatabase[sightingData.race]
  1754.         end
  1755.  
  1756.         -- Get class database
  1757.         local classDatabase = raceDatabase[sightingData.class]
  1758.         if (classDatabase == nil) then
  1759.             raceDatabase[sightingData.class] = {}
  1760.             classDatabase = raceDatabase[sightingData.class]
  1761.         end
  1762.  
  1763.         sightingData.name = PTR_Color_ProblemNames_check(sightingData.name)
  1764.  
  1765.         --
  1766.         local entry = classDatabase[sightingData.name]
  1767.         if (entry == nil) then
  1768.             classDatabase[sightingData.name] = {}
  1769.             entry = classDatabase[sightingData.name]
  1770.         end
  1771.  
  1772.         sightingData.lastSeen = CensusPlus_DetermineServerDate() .. ""
  1773.  
  1774.         --
  1775.         -- Update the information
  1776.         --
  1777.         entry[1] = sightingData.level
  1778.         entry[2] = sightingData.guild
  1779.         entry[3] = sightingData.lastSeen
  1780.         entry[4] =
  1781.             checksum:generate(
  1782.                 realmName .. sightingData.faction .. sightingData.race .. sightingData.class .. sightingData.name .. sightingData.level .. sightingData.guild .. sightingData.lastSeen .. sightingData.sex
  1783.             )
  1784.         entry[5] = sightingData.sex
  1785.     end
  1786. end
  1787.  
  1788.  
  1789. -- Gather targeting data
  1790. function CensusPlus_CollectSightingData(unit)
  1791.     if (UnitIsPlayer(unit) and UnitName(unit) ~= "Unknown") then
  1792.         -- create the return structure as non-nil fields
  1793.         local ret = {}
  1794.         local _ = nil
  1795.         ret.name = ""
  1796.         ret.realm = ""
  1797.         ret.relationship = ""
  1798.         ret.race = ""
  1799.         ret.level = 0
  1800.         ret.sex = 1
  1801.         ret.class = ""
  1802.         ret.guild = ""
  1803.         ret.guildrealm = ""
  1804.         ret.faction = ""
  1805.  
  1806.         -- now populate the return structure
  1807.         ret.name, ret.realm = UnitName(unit) -- returns realm also Y +?
  1808.         ret.relationship = UnitRealmRelationship(unit) -- compares against self returns LE_REALM_RELATION_VIRTUAL|LE_REALM_RELATION_COALESCED|LE_REALM_RELATION_SAME
  1809.         if ((ret.realm == nil) or ret.relationship == 1) then
  1810.             ret.realm = CensusPlus_GetUniqueRealmName()
  1811.         end
  1812.         ret.level = UnitLevel(unit) -- a number  YNum
  1813.         ret.sex = UnitSex(unit) -- a number 2=male 3=female  YNum
  1814.         ret.race, _ = UnitRace(unit) -- localized , non Y + Y non is english race treated as one word.. i.e. Blood Elf  Bloodelf
  1815.         ret.class, _ = UnitClass(unit) -- localized ,non (warning if npc the npc name is returned!) y + y  Monk  MONK
  1816.         ret.guild, ret.guildRankName, ret.guildRankIndex = GetGuildInfo(unit) -- ? + ? +Ynum=0?
  1817.         --[Note] getGuildinfo call does return all of the above.. or if not valid nil or zero for the index
  1818.         if (ret.guild == nil) then
  1819.             ret.guild = ""
  1820.             ret.guildrealm = ""
  1821.         end
  1822.         if (ret.guildrealm == nil) then
  1823.             if (ret.guild == "") then
  1824.                 ret.guildrealm = ""
  1825.             else
  1826.                 ret.guildrealm = CensusPlus_GetUniqueRealmName()
  1827.             end
  1828.         end
  1829.         ret.faction, _ = UnitFactionGroup(unit)
  1830.         return ret
  1831.     else
  1832.         return nil
  1833.     end
  1834. end
  1835.  
  1836. -- Initialize our primary save variables --  called when CensusPlusClassic ADDON_LOADED event is fired
  1837. function CensusPlus_InitializeVariables()
  1838.     if (CensusPlus_Database["Servers"] == nil) then
  1839.         CensusPlus_Database["Servers"] = {}
  1840.     end
  1841.  
  1842.     if (CensusPlus_Database["Times"] ~= nil) then
  1843.         CensusPlus_Database["Times"] = nil
  1844.     end
  1845.  
  1846.     if (CensusPlus_Database["TimesPlus"] == nil) then
  1847.         CensusPlus_Database["TimesPlus"] = {}
  1848.     end
  1849.  
  1850.     --  Make sure info is last so it will be first in the output so we can grab the version number
  1851.     if (CensusPlus_Database["Info"] == nil) then
  1852.         CensusPlus_Database["Info"] = {}
  1853.     end
  1854.     if (CensusPlus_PerCharInfo["Version"] == nil) then
  1855.         CensusPlus_PerCharInfo["Version"] = {}
  1856.     end
  1857.  
  1858.     -- V 6.0.1 to 6.1.0 database purge
  1859.     if (CensusPlus_Database["Info"]["Version"] ~= nil) then
  1860.         g_InterfaceVersion = CensusPlus_Database["Info"]["Version"]
  1861.         -- keep left V.v to compare with V.v in code
  1862.         local _, cpsubset = string.find(g_InterfaceVersion, "%.")
  1863.         local _, cpsubset2 = string.find(g_InterfaceVersion, "%.", cpsubset + 1)
  1864.         g_InterfaceVersion = string.sub(g_InterfaceVersion, 1, cpsubset2 - 1)
  1865.         --      print("found interface version "..g_InterfaceVersion)
  1866.         local _, cpsubset = string.find(CensusPlus_VERSION, "%.")
  1867.         local _, cpsubset2 = string.find(CensusPlus_VERSION, "%.", cpsubset + 1)
  1868.         local CensusPlus_Version_subset =
  1869.             string.sub(CensusPlus_VERSION, 1, cpsubset2 - 1)
  1870.         --      print("coded interface version "..CensusPlus_Version_subset)
  1871.         if (g_InterfaceVersion ~= CensusPlus_Version_subset) then
  1872.             CensusPlus_Database["Info"] = {}
  1873.             CensusPlus_PerCharInfo = nil
  1874.             CensusPlus_PerCharInfo = {}
  1875.             CensusPlus_PerCharInfo["Version"] = CensusPlus_VERSION
  1876.             CensusPlus_DoPurge()
  1877.             g_wasPurged = true
  1878.             CensusPlus_Msg(CENSUSPLUS_OBSOLETEDATAFORMATTEXT)
  1879.         end
  1880.     end
  1881.     CPp.FirstLoad = true
  1882.  
  1883.     CensusPlus_Database["Info"]["Version"] = CensusPlus_VERSION
  1884.    
  1885.     local g_templang = GetLocale()
  1886.     if (CensusPlus_Database["Info"]["ClientLocale"] ~= g_templang) then
  1887.         -- Client language has been changed must purge
  1888.         CensusPlus_DoPurge()
  1889.         g_wasPurged = true
  1890.         CensusPlus_Msg(CENSUSPLUS_LANGUAGECHANGED)
  1891.     end
  1892.     CensusPlus_Database["Info"]["ClientLocale"] = GetLocale()
  1893.     CensusPlusLocaleName:SetText( format(CENSUSPLUS_LOCALE, CensusPlus_Database["Info"]["ClientLocale"]) )
  1894.    
  1895.     CensusPlus_Database["Info"]["LoginServer"] = GetCVar("portal")
  1896.     CensusPlus_Database["Info"]["LogVer"] = CensusPlus_VERSION_FULL
  1897.    
  1898.     local wowVersion, wowBuild = GetBuildInfo()
  1899.     wowVersion = format("%s (%s)", wowVersion, wowBuild)
  1900.    
  1901.     CensusPlus_Database["Info"]["wowVersion"] = wowVersion
  1902.     CensusPlus_Database["Info"]['versionChecksum'] = checksum:generate(CensusPlus_VERSION_FULL..wowVersion)
  1903.  
  1904.     if (CensusPlus_Database["Info"]["AutoCensus"] == nil) then
  1905.         CensusPlus_Database["Info"]["AutoCensus"] = true
  1906.     end
  1907.     if (CensusPlus_Database["Info"]["Verbose"] == nil) then
  1908.         CensusPlus_Database["Info"]["Verbose"] = false
  1909.     end
  1910.     if (CensusPlus_Database["Info"]["Stealth"] == nil) then
  1911.         CensusPlus_Database["Info"]["Stealth"] = false
  1912.     end
  1913.     if (CensusPlus_Database["Info"]["PlayFinishSound"] == nil) then
  1914.         CensusPlus_Database["Info"]["PlayFinishSound"] = false
  1915.     end
  1916.     if (CensusPlus_Database["Info"]["SoundFile"] == nil) then
  1917.         CensusPlus_Database["Info"]["SoundFile"] = g_FinishSoundNumber
  1918.     end
  1919.  
  1920.     if (CensusPlus_Database["Info"]["AutoCensusTimer"] == nil) then
  1921.         CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800
  1922.     end
  1923.    
  1924.     if (CensusPlus_JobQueue["CensusPlus_last_time"] == nil) then
  1925.         CensusPlus_JobQueue["CensusPlus_last_time"] = time() - (CPp.AutoStartTimer *60)
  1926.     end
  1927.    
  1928.     if (CensusPlus_JobQueue["CensusPlus_LoginRealm_last"] == nil) then
  1929.         CensusPlus_JobQueue["CensusPlus_LoginRealm_last"] = ""
  1930.     end
  1931.    
  1932.     if (CensusPlus_JobQueue["CensusPlus_LoginFaction_last"] == nil) then
  1933.         CensusPlus_JobQueue["CensusPlus_LoginFaction_last"] = ""
  1934.     end
  1935.  
  1936.     if (CensusPlus_Database["Info"]["CPWindow_Transparency"] == nil) then
  1937.         CensusPlus_Database["Info"]["CPWindow_Transparency"] = 0.5
  1938.     end
  1939.  
  1940.     if (CensusPlus_Database["Info"]["CensusButtonShown"] == nil) then
  1941.         CensusPlus_Database["Info"]["CensusButtonShown"] = true
  1942.     end
  1943.  
  1944.     if (CensusPlus_Database["Info"]["CensusButtonShown"] == true) then
  1945.         CensusButtonFrame:Show()
  1946.     else
  1947.         CensusButtonFrame:Hide()
  1948.     end
  1949.  
  1950.     if (CensusPlus_Database["Info"]["CensusButtonAnimi"] == nil) then
  1951.         CensusPlus_Database["Info"]["CensusButtonAnimi"] = true
  1952.     end
  1953.  
  1954.     if (CensusPlus_Database["Info"]["UseLogBars"] == nil) then
  1955.         CensusPlus_Database["Info"]["UseLogBars"] = true
  1956.     end
  1957.  
  1958.     if (CensusPlus_Database["Info"]["UseWorldFrameClicks"] == nil) then
  1959.         CensusPlus_Database["Info"]["UseWorldFrameClicks"] = true
  1960.     end
  1961.  
  1962.     --CensusPlusSetCheckButtonState()
  1963.     CensusPlus_Msg(" v" .. CensusPlus_VERSION .. CENSUSPLUS_MSG1)
  1964.  
  1965.     g_VariablesLoaded = true
  1966.  
  1967.     --CensusPlus_CheckTZ();
  1968.     InitConstantTables()
  1969.  
  1970.     g_CensusPlusInitialized = true
  1971.  
  1972.     --  If we are in a guild, attempt to gather the guild roster data
  1973.     --  if (IsInGuild()) then
  1974.     --      GuildRoster();
  1975.     --  end
  1976.  
  1977.     --  Prune times if we have too many
  1978.     CENSUSPLUS_PRUNETimes()
  1979.  
  1980.     --
  1981.     CensusPlus_Unhandled = nil
  1982.     CensusPlus_Unhandled = {}
  1983.  
  1984.     CensusPlusBlizzardOptions()
  1985.     CensusPlusSetCheckButtonState()
  1986.     CPp.FirstLoad = false -- main table initialized and options initialized
  1987.    
  1988. end
  1989.  
  1990.  
  1991. function CensusPlus_AutoStart()
  1992.    
  1993.     local currentRealm = CensusPlus_GetUniqueRealmName()
  1994.     local currentFaction = UnitFactionGroup("player")
  1995.     local lastRealm = CensusPlus_JobQueue["CensusPlus_LoginRealm_last"]
  1996.     local lastFaction = CensusPlus_JobQueue["CensusPlus_LoginFaction_last"]
  1997.     local lastRun = CensusPlus_JobQueue["CensusPlus_last_time"]
  1998.    
  1999.     if (g_wasPurged or currentRealm ~= lastRealm or currentFaction ~= lastFaction or (lastRun < time() - (CPp.AutoStartTimer * 60))) then
  2000.         CENSUSPLUS_TAKE_OnClick()
  2001.     end
  2002.  
  2003. end
  2004.  
  2005.  
  2006. -- referenced by CensusPlusClassic.xml
  2007. function CensusPlus_OnUpdate()
  2008.     if g_FirstRun then
  2009.         CensusButton:SetText("C+")
  2010.         if (g_VariablesLoaded and not CPp.IsCensusPlusInProgress and CPp.AutoCensus == true) then
  2011.             CensusPlus_AutoStart()
  2012.         end
  2013.     elseif (g_VariablesLoaded and not CPp.IsCensusPlusInProgress and CPp.AutoCensus == true and (CPp.LastCensusRun < time() - (CPp.AutoStartTimer * 60))) then
  2014.         CENSUSPLUS_TAKE_OnClick()
  2015.     end
  2016.     if (CPp.IsCensusPlusInProgress and not g_CensusPlusPaused and not CPp.CensusPlusManuallyPaused) then
  2017.    
  2018.         --  update our progress
  2019.         local numJobs = #CensusPlus_JobQueue
  2020.         if (numJobs > 0) then
  2021.             CensusPlusScanProgress:SetText(
  2022.                 format(
  2023.                     CENSUSPLUS_SCAN_PROGRESS,
  2024.                     numJobs,
  2025.                     CensusPlus_CreateWhoText(CensusPlus_JobQueue[numJobs])
  2026.                 )
  2027.             )
  2028.         end
  2029.  
  2030.         if (not whoquery_active or g_FirstRun) then
  2031.             --ok to request next query
  2032.             whoquery_answered = false
  2033.  
  2034.             -- Determine if there is any more work to
  2035.             if (numJobs > 0) then
  2036.                 -- Send the job and remove it later after it is processed in CP_ProcessWhoEvent (Lib-Who callback)
  2037.                 local job = CensusPlus_JobQueue[numJobs]
  2038.                 local whoText = CensusPlus_CreateWhoText(job)
  2039.                 g_FirstRun = false
  2040.                
  2041.                 --  Zap our current job
  2042.                 g_CurrentJob = nil
  2043.  
  2044.                 g_CurrentJob = job
  2045.                 g_WaitingForWhoUpdate = true
  2046.  
  2047.                 CensusPlus_SendWho(whoText)
  2048.                 g_WhoAttempts = 0
  2049.                 g_LastOnUpdateTime = GetTime()
  2050.                 CensusPlus_JobQueue.CensusPlus_last_time = time()
  2051.             else
  2052.                 -- We are all done, hide the friends frame and report our results
  2053.                 if CensusPlus_PerCharInfo["PlayFinishSound"] then
  2054.                     if (CensusPlus_PerCharInfo["SoundFile"] == nil) then
  2055.                         g_FinishSoundNumber = 1
  2056.                     else
  2057.                         g_FinishSoundNumber =
  2058.                             CensusPlus_PerCharInfo["SoundFile"]
  2059.                     end
  2060.                     local CPSoundFile =
  2061.                         "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete" .. g_FinishSoundNumber .. ".ogg"
  2062.                     local willplay = PlaySoundFile(CPSoundFile, "Master")
  2063.                     if not willplay then
  2064.                         local CPSoundFile =
  2065.                             "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete" .. g_FinishSoundNumber .. ".mp3"
  2066.                         PlaySoundFile(CPSoundFile, "Master")
  2067.                     end
  2068.                 elseif ((CensusPlus_PerCharInfo["PlayFinishSound"] == nil) and CensusPlus_Database["Info"]["PlayFinishSound"]) then
  2069.                     if (CensusPlus_Database["Info"]["SoundFile"] == nil) then
  2070.                         g_FinishSoundNumber = 1
  2071.                     else
  2072.                         g_FinishSoundNumber =
  2073.                             CensusPlus_Database["Info"]["SoundFile"]
  2074.                     end
  2075.                     local CPSoundFile =
  2076.                         "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete" .. g_FinishSoundNumber .. ".ogg"
  2077.                     local willplay = PlaySoundFile(CPSoundFile, "Master")
  2078.                     if not willplay then
  2079.                         local CPSoundFile =
  2080.                             "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete" .. g_FinishSoundNumber .. ".mp3"
  2081.                         PlaySoundFile(CPSoundFile, "Master")
  2082.                     end
  2083.                 end
  2084.                 if not CensusPlayerOnly then
  2085.                     CensusPlus_DoTimeCounts()
  2086.                 end
  2087.                 CensusPlayerOnly = false
  2088.                 CensusPlus_JobQueue.CensusPlus_LoginRealm_last = CensusPlus_JobQueue.CensusPlus_LoginRealm
  2089.                 CensusPlus_JobQueue.CensusPlus_LoginFaction_last = CensusPlus_JobQueue.CensusPlus_LoginFaction
  2090.                 CensusPlus_JobQueue.CensusPlus_LoginRealm = ""
  2091.                 CensusPlus_JobQueue.CensusPlus_LoginFaction = ""
  2092.                 CensusPlus_JobQueue.g_TempCount = {}
  2093.                 CensusPlus_DisplayResults()
  2094.                
  2095.                 -- Add CensusButton reset
  2096.                 CensusButton:SetText("C+")
  2097.             end
  2098.         elseif whoquery_answered then
  2099.             local now = GetTime()
  2100.             local delta = now - g_LastOnUpdateTime
  2101.             if (delta > CensusPlus_UPDATEDELAY2) then
  2102.                 g_LastOnUpdateTime = now
  2103.                 print(CENSUSPLUS_TOOSLOW) -- >10 seconds to finish query!
  2104.             end
  2105.         else
  2106.             local now = GetTime()
  2107.             local delta2 = now - g_LastOnUpdateTime
  2108.             if (delta2 > CensusPlus_UPDATEDELAY) then
  2109.                 g_LastOnUpdateTime = now
  2110.                 --
  2111.                 -- Resend /who command
  2112.                 --
  2113.                 g_WhoAttempts = g_WhoAttempts + 1
  2114.                 local whoText = CensusPlus_CreateWhoText(g_CurrentJob)
  2115.                 if (CensusPlus_PerCharInfo["Verbose"] == true) then
  2116.                     CensusPlus_Msg(CENSUSPLUS_WAITING) -- this hasn't shown up in testing yet.
  2117.                 end
  2118.                 if (g_WhoAttempts < 2) then
  2119.                     CensusPlus_SendWho(whoText)
  2120.                 else
  2121.                     g_WaitingForWhoUpdate = false
  2122.                 end
  2123.             end
  2124.             --return -- server hasn't returned query.. so wait for next frame update
  2125.         end
  2126.     end
  2127. end
  2128.  
  2129.  
  2130. -- Take final tally
  2131. function CensusPlus_DoTimeCounts()
  2132.     -- first zero counts in g_TimeDatabase each realm/faction
  2133.     --CensusPlus_JobQueue.g_NumUpdatedCharacters = 0;
  2134.     --CensusPlus_JobQueue.g_NumNewCharacters = 0;
  2135.     local factionGroup = UnitFactionGroup("player")
  2136.  
  2137.     local realmName = CensusPlus_GetUniqueRealmName()
  2138.    
  2139.  
  2140.     CensusPlus_Zero_g_TimeDatabase()
  2141.     local thisFactionClasss = CensusPlus_GetFactionClasses(factionGroup)
  2142.     local numClasses = #thisFactionClasss
  2143.     for i = 1, numClasses, 1 do
  2144.         local charClass = thisFactionClasss[i]
  2145.         local classCount = 0
  2146.  
  2147.         for realmKey, factionData in
  2148.             pairs(CensusPlus_JobQueue.g_TempCount) -- realmname, factionname
  2149.         do
  2150.             for factionKey, classData in pairs(factionData) do
  2151.                 if (factionKey == factionGroup) then
  2152.                     for classKey, NameData in pairs(classData) do
  2153.                         if (charClass == classKey) then
  2154.                             for nameKey, charData in
  2155.                                 pairs(NameData)
  2156.                             do
  2157.                                 --                                              if (HortonBug == true) then
  2158.                                 --                                                  s.ays("TempCount level 3");
  2159.                                 --                                              end
  2160.  
  2161.                                 local gotcha = charData[1]
  2162.                                 if (gotcha == charClass) then
  2163.                                     classCount = classCount + 1
  2164.                                 end
  2165.                             end
  2166.                         end
  2167.                     end
  2168.                 end
  2169.             end
  2170.         end
  2171.  
  2172.         if (CENSUSPlusFemale[charClass] ~= nil) then
  2173.             charClass = CENSUSPlusFemale[class]
  2174.         end
  2175.         CensusPlus_JobQueue.g_TimeDatabase[charClass] =
  2176.             CensusPlus_JobQueue.g_TimeDatabase[charClass] + classCount
  2177.         CensusPlus_JobQueue.g_NumUpdatedCharacters =
  2178.             CensusPlus_JobQueue.g_NumUpdatedCharacters + classCount
  2179.     end
  2180.     if (CensusPlus_Database["TimesPlus"][realmName] == nil) then
  2181.         CensusPlus_Database["TimesPlus"][realmName] = {}
  2182.     end
  2183.     if (CensusPlus_Database["TimesPlus"][realmName][factionGroup] == nil) then
  2184.         CensusPlus_Database["TimesPlus"][realmName][factionGroup] = {}
  2185.     end
  2186.  
  2187.     if CensusPLus_DEBUGWRITES then
  2188.         CensusPlus_Database["TimesPlus"][realmName][factionGroup] =
  2189.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_DRUID] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_HUNTER] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_MAGE] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PRIEST] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_ROGUE] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARLOCK] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARRIOR] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_SHAMAN] .. "&" .. CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PALADIN] .. "&" .. CensusPlus_WHOPROCESSOR .. ":" .. CensusPlus_JobQueue.g_NumNewCharacters .. "," .. CensusPlus_JobQueue.g_NumUpdatedCharacters .. "," .. total_time
  2190.     else
  2191.         local TimeDataTime = date("!%Y-%m-%d&%H:%M:%S", GetServerTime())
  2192.  
  2193.         CensusPlus_Database["TimesPlus"][realmName][factionGroup][TimeDataTime] =
  2194.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_DRUID] .. "&" ..
  2195.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_HUNTER] .. "&" ..
  2196.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_MAGE] .. "&" ..
  2197.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PRIEST] .. "&" ..
  2198.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_ROGUE] .. "&" ..
  2199.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARLOCK] .. "&" ..
  2200.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_WARRIOR] .. "&" ..
  2201.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_SHAMAN] .. "&" ..
  2202.             CensusPlus_JobQueue.g_TimeDatabase[CENSUSPLUS_PALADIN]
  2203.  
  2204.         CensusPlus_Database["TimesPlus"][realmName][factionGroup][TimeDataTime] =
  2205.             CensusPlus_Database["TimesPlus"][realmName][factionGroup][TimeDataTime] .. ":" ..
  2206.             checksum:generate(
  2207.                 CensusPlus_Database["TimesPlus"][realmName][factionGroup][TimeDataTime] ..
  2208.                 realmName ..
  2209.                 factionGroup ..
  2210.                 TimeDataTime
  2211.             )
  2212.     end
  2213.     CensusPlus_Zero_g_TimeDatabase() --b temp data no longer needed
  2214. end
  2215.  
  2216. -- Add the contents of the guild results to the database
  2217. local function CensusPlus_ProcessGuildResults()
  2218.     if not g_VariablesLoaded then return end
  2219.  
  2220.     --  Grab temp var
  2221.     local showOfflineTemp = GetGuildRosterShowOffline()
  2222.     SetGuildRosterShowOffline(true)
  2223.  
  2224.     -- Walk through the guild info
  2225.     local numGuildMembers, numOnline = GetNumGuildMembers()
  2226.     if (numOnline < 2) then
  2227.         return -- only guild member online is player who is counted elsewhere
  2228.     end
  2229.     --  CensusPlus_Msg("Processing "..numOnline.." online of "..numGuildMembers.." total guild members.");
  2230.  
  2231.     local realmName = CensusPlus_GetUniqueRealmName()
  2232.     CensusPlus_Database["Guilds"] = nil
  2233.     if (CensusPlus_Database["Guilds"] == nil) then
  2234.         CensusPlus_Database["Guilds"] = {}
  2235.     end
  2236.  
  2237.     if (CensusPlus_Database["Guilds"][realmName] == nil) then
  2238.         CensusPlus_Database["Guilds"][realmName] = {}
  2239.     end
  2240.  
  2241.     local guildRealmDatabase = CensusPlus_Database["Guilds"][realmName]
  2242.     if (guildRealmDatabase == nil) then
  2243.         CensusPlus_Database["Guilds"][realmName] = {}
  2244.         guildRealmDatabase = CensusPlus_Database["Guilds"][realmName]
  2245.     end
  2246.  
  2247.     local factionGroup = UnitFactionGroup("player")
  2248.     if (factionGroup == nil) then
  2249.         CensusPlus_Database["Guilds"] = nil
  2250.         SetGuildRosterShowOffline(showOfflineTemp)
  2251.         return
  2252.     end
  2253.  
  2254.     local factionDatabase = guildRealmDatabase[factionGroup]
  2255.     if (factionDatabase == nil) then
  2256.         guildRealmDatabase[factionGroup] = {}
  2257.         factionDatabase = guildRealmDatabase[factionGroup]
  2258.     end
  2259.  
  2260.     CensusPlus_Database["Guilds"][realmName][factionGroup] = nil
  2261.     CensusPlus_Database["Guilds"][realmName][factionGroup] = {}
  2262.  
  2263.     factionDatabase = CensusPlus_Database["Guilds"][realmName][factionGroup]
  2264.  
  2265.     local Ginfo = GetGuildInfo("player")
  2266.     if (Ginfo == nil) then
  2267.         CensusPlus_Database["Guilds"] = nil
  2268.         SetGuildRosterShowOffline(showOfflineTemp)
  2269.         return
  2270.     end
  2271.     local guildDatabase = factionDatabase[Ginfo]
  2272.     if (guildDatabase == nil) then
  2273.         factionDatabase[Ginfo] = {}
  2274.         guildDatabase = factionDatabase[Ginfo]
  2275.     end
  2276.  
  2277.     local info = guildDatabase["GuildInfo"]
  2278.     if (info == nil) then
  2279.         guildDatabase["GuildInfo"] = {}
  2280.         info = guildDatabase["GuildInfo"]
  2281.     end
  2282.  
  2283.     info["Update"] = date("%m-%d-%Y", time()) .. ""
  2284.     info["ShowOnline"] = 1 --  Variable comes from FriendsFrame
  2285.     guildDatabase["Members"] = nil
  2286.     guildDatabase["Members"] = {}
  2287.  
  2288.     local members = guildDatabase["Members"]
  2289.  
  2290.     for index = 1, numGuildMembers, 1 do
  2291.         local name,
  2292.             rank,
  2293.             rankIndex,
  2294.             level,
  2295.             class,
  2296.             zone,
  2297.             note,
  2298.             officernote,
  2299.             online,
  2300.             status
  2301.         = GetGuildRosterInfo(index)
  2302.  
  2303.         if (members[name] == nil) then
  2304.             members[name] = {}
  2305.         end
  2306.  
  2307.         --CensusPlus_Msg( "Name =>" .. name );
  2308.         --CensusPlus_Msg( "rank =>" .. rank );
  2309.         --CensusPlus_Msg( "rankIndex =>" .. rankIndex );
  2310.         --CensusPlus_Msg( "level =>" .. level );
  2311.         --CensusPlus_Msg( "class =>" .. class );
  2312.         members[name]["Rank"] = rank
  2313.         members[name]["RankIndex"] = rankIndex
  2314.         members[name]["Level"] = level
  2315.         members[name]["Class"] = class
  2316.         --members[name]["Zone"]= zone;
  2317.         --members[name]["Note"]= CensusPlus_SafeSet( note );
  2318.         --members[name]["OfficerNote"]= CensusPlus_SafeSet( officernote );
  2319.         --members[name]["Online"]= online;
  2320.         --members[name]["Status"]= CensusPlus_SafeSet( status );
  2321.     end
  2322.  
  2323.     SetGuildRosterShowOffline(showOfflineTemp)
  2324. end
  2325.  
  2326. function CensusPlus_SafeCheck(param)
  2327.     if (param == nil) then
  2328.         return "nil"
  2329.     else
  2330.         return param
  2331.     end
  2332. end
  2333.  
  2334. -- Add the contents of the who results to the database
  2335. function CensusPlus_ProcessWhoResults(result, numWhoResults)
  2336.     --  If we are in a BG th.en stop a census
  2337.     if (g_CurrentlyInBG and CPp.IsCensusPlusInProgress) then
  2338.         CPp.LastCensusRun = time() - 600
  2339.         CensusPlus_Msg(CENSUSPLUS_ISINBG)
  2340.         CENSUSPLUS_STOPCENSUS()
  2341.     end
  2342.  
  2343.     --[[
  2344.         Old process, assume single realm.. process realm,faction,level,race,class,
  2345.         new process no assumption. process realm, then faction, level, race,class
  2346.         need to build dotimes for each realm found in Virtual realm set.
  2347.        
  2348.         name comes in as name-realm
  2349.         split to name, realm
  2350.         process
  2351.  
  2352.     --]]
  2353.     --5.4
  2354.  
  2355.     local numWhoResults = C_FriendList.GetNumWhoResults()
  2356.    
  2357.  
  2358.  
  2359.     if (g_Verbose == true) then
  2360.         CensusPlus_Msg(format(CENSUSPLUS_PROCESSING, numWhoResults))
  2361.     end
  2362.  
  2363.     local name = ""
  2364.     --5.4
  2365.     local realm = ""
  2366.     --
  2367.     local guild = ""
  2368.     --5.4
  2369.     local guildRealm = ""
  2370.     --
  2371.     local level = ""
  2372.     local race = ""
  2373.     local class = ""
  2374.     local zone = ""
  2375.     local sex = ""
  2376.     --  local relate = ""
  2377.     for i = 1, numWhoResults, 1 do
  2378.         local tmpNmst = nil
  2379.         local tmpNmend = nil
  2380.         local tmpGldst = nil
  2381.         local tmpGldend = nil
  2382.         local relationship = nil
  2383.        
  2384.         local p = C_FriendList.GetWhoInfo(i)
  2385.         name = p.fullName
  2386.         guild = p.fullGuildName
  2387.         level = p.level
  2388.         race = p.raceStr
  2389.         class = p.classStr
  2390.         zone = p.area
  2391.         sex = p.gender
  2392.         if (CENSUSPlusFemale[race] ~= nil) then
  2393.             race = CENSUSPlusFemale[race]
  2394.         end
  2395.         if (CENSUSPlusFemale[class] ~= nil) then
  2396.             class = CENSUSPlusFemale[class]
  2397.         end
  2398.         if (HortonBug == true) then
  2399.             says("who API returned " .. name)
  2400.         end
  2401.         local orig_name = name
  2402.         local orig_guild = guild
  2403.         tmpNmst, tmpNmend = string.find(name, "-")
  2404.         if tmpNmst then
  2405.             realm = string.sub(name, tmpNmst + 1)
  2406.             name = string.sub(name, 1, tmpNmst - 1)
  2407.         else
  2408.             realm = CensusPlus_GetUniqueRealmName()
  2409.         end
  2410.  
  2411.         if ((guild ~= nil) and (guild ~= "")) then
  2412.             local guildName = ""
  2413.             guildName, _, _ = GetGuildInfo(orig_name)
  2414.             if (guildName == nil) then
  2415.                 tmpGldst, tmpGldend = string.find(orig_guild, "-")
  2416.                 if tmpGldst then
  2417.                     guildRealm = string.sub(orig_guild, tmpGldst + 1)
  2418.                     guild = string.sub(orig_guild, 1, tmpGldst - 1)
  2419.                 else
  2420.                     guildRealm = CensusPlus_GetUniqueRealmName()
  2421.                 end
  2422.             else
  2423.                 if (guildRealm == nil) then
  2424.                     guildRealm = CensusPlus_GetUniqueRealmName()
  2425.                 end
  2426.             end
  2427.         else
  2428.             guild = ""
  2429.             guildRealm = ""
  2430.         end
  2431.  
  2432.         --[[
  2433.                 PTR testing modifications
  2434.                 Blizzard has odd naming allowances in PTR realms
  2435.                 name (US) or name (EU)  ditto for guild names
  2436.  
  2437.         --]]
  2438.        
  2439.         realm = PTR_Color_ProblemRealmGuilds_check(realm)
  2440.         name = PTR_Color_ProblemNames_check(name)
  2441.         if ((guild ~= nil) and (guild ~= "")) then
  2442.             guild = PTR_Color_ProblemRealmGuilds_check(guild)
  2443.         end
  2444.         if ((guildRealm ~= nil) and (guildRealm ~= "")) then
  2445.             guildRealm = PTR_Color_ProblemRealmGuilds_check(guildRealm)
  2446.         end
  2447.  
  2448.         local realmName = CensusPlus_GetUniqueRealmName()
  2449.        
  2450.         -- coalesced realms should not show up here via /who queries.
  2451.         local realmDatabase = CensusPlus_Database["Servers"][realmName]
  2452.         if (realmDatabase == nil) then
  2453.             CensusPlus_Database["Servers"][realmName] = {}
  2454.             realmDatabase = CensusPlus_Database["Servers"][realmName]
  2455.         end
  2456.  
  2457.         -- Get the portion of the database for this faction
  2458.         local factionGroup = UnitFactionGroup("player")
  2459.         if (factionGroup == nil or factionGroup == "Neutral") then return end
  2460.  
  2461.         local factionDatabase = realmDatabase[factionGroup]
  2462.         if (factionDatabase == nil) then
  2463.             realmDatabase[factionGroup] = {}
  2464.             factionDatabase = realmDatabase[factionGroup]
  2465.         end
  2466.  
  2467.         -- Get racial database
  2468.         local raceDatabase = factionDatabase[race]
  2469.         if (raceDatabase == nil) then
  2470.             factionDatabase[race] = {}
  2471.             raceDatabase = factionDatabase[race]
  2472.         end
  2473.  
  2474.         -- Get class database
  2475.         local classDatabase = raceDatabase[class]
  2476.         if (classDatabase == nil) then
  2477.             raceDatabase[class] = {}
  2478.             classDatabase = raceDatabase[class]
  2479.         end
  2480.  
  2481.         -- Get this player's entry
  2482.         local entry = classDatabase[name]
  2483.         if (entry == nil) then
  2484.             classDatabase[name] = {}
  2485.             entry = classDatabase[name]
  2486.             CensusPlus_JobQueue.g_NumNewCharacters =
  2487.                 CensusPlus_JobQueue.g_NumNewCharacters + 1
  2488.         end
  2489.  
  2490.         lastSeen = CensusPlus_DetermineServerDate() .. ""
  2491.  
  2492.         -- Update the information
  2493.         entry[1] = level
  2494.         entry[2] = guild
  2495.         --local hour, minute = GetGameTime();
  2496.         entry[3] = lastSeen
  2497.         entry[4] =
  2498.             checksum:generate(
  2499.                 realmName .. factionGroup .. race .. class .. name .. level .. guild .. lastSeen .. sex
  2500.             )
  2501.         entry[5] = sex
  2502.  
  2503.         -- 5.3 g_TempCount[name] = class;
  2504.         -- 5.4 g_TempCount[realm][name] = class;
  2505.         local gct_realm = CensusPlus_JobQueue.g_TempCount[realmName]
  2506.         if (gct_realm == nil) then
  2507.             CensusPlus_JobQueue.g_TempCount[realmName] = {}
  2508.             gct_realm = CensusPlus_JobQueue.g_TempCount[realmName]
  2509.         end
  2510.  
  2511.         local gct_faction = gct_realm[factionGroup]
  2512.         if (gct_faction == nil) then
  2513.             gct_realm[factionGroup] = {}
  2514.             gct_faction = gct_realm[factionGroup]
  2515.         end
  2516.  
  2517.         local gct_class = gct_faction[class]
  2518.         if (gct_class == nil) then
  2519.             gct_faction[class] = {}
  2520.             gct_class = gct_faction[class]
  2521.         end
  2522.  
  2523.         local gct_name = gct_class[name]
  2524.         if (gct_name == nil) then
  2525.             gct_class[name] = {}
  2526.             gct_name = gct_class[name]
  2527.         end
  2528.         gct_name[1] = class
  2529.     end
  2530.  
  2531.     -- remove the job
  2532.     table.remove(CensusPlus_JobQueue)
  2533.     whoquery_active = false
  2534.     --CensusPlus_UpdateView();
  2535. end
  2536.  
  2537. -- Process a single entry
  2538. -- not currently used since we don't want to activity record foreign realm characters that we spot id.
  2539. local function WR_ProcessSingleEntry(name, level, race, class, guild, zone)
  2540.     CensusPlus_Msg2(BLIZZARD_STORE_PROCESSING .. name)
  2541.  
  2542.     if (CENSUSPlusFemale[race] ~= nil) then
  2543.         race = CENSUSPlusFemale[race]
  2544.     end
  2545.  
  2546.     if (CENSUSPlusFemale[class] ~= nil) then
  2547.         class = CENSUSPlusFemale[class]
  2548.     end
  2549.  
  2550.     -- Get the portion of the database for this server
  2551.     local realmName = CensusPlus_GetUniqueRealmName()
  2552.     local realmDatabase = CensusPlus_Database["Servers"][realmName]
  2553.     if (realmDatabase == nil) then
  2554.         CensusPlus_Database["Servers"][realmName] = {}
  2555.         realmDatabase = CensusPlus_Database["Servers"][realmName]
  2556.     end
  2557.  
  2558.     -- Get the portion of the database for this faction
  2559.     local factionGroup = UnitFactionGroup("player")
  2560.     if (factionGroup == nil) then return end
  2561.  
  2562.     local factionDatabase = realmDatabase[factionGroup]
  2563.     if (factionDatabase == nil) then
  2564.         realmDatabase[factionGroup] = {}
  2565.         factionDatabase = realmDatabase[factionGroup]
  2566.     end
  2567.  
  2568.     --  Remove the trailing ] that I can't remove through patterns
  2569.     --  local oldname = name;
  2570.     --  name = string.sub( oldname, 1, string.len(oldname) - 3 );
  2571.  
  2572.     level = tonumber(level)
  2573.  
  2574.     --  Test the name for possible color coding
  2575.     --  for example |cffff0000Rollie|r
  2576.     local karma_check = string.find(name, "|cff")
  2577.     if (karma_check ~= nil) then
  2578.         name = string.sub(name, 11, -3)
  2579.     end
  2580.  
  2581.     local pattern = "[0-9\| :]"
  2582.     if (string.find(name, pattern) ~= nil) then
  2583.         if not g_ProblematicMessageShown then
  2584.             CensusPlus_Msg(
  2585.                 CENSUSPLUS_PROBLEMNAME .. name .. CENSUSPLUS_PROBLEMNAME_ACTION
  2586.             )
  2587.         end
  2588.         return
  2589.     end
  2590.  
  2591.     --  Do a race check just to be sure this is working
  2592.     if (g_FactionCheck[race] == nil) then
  2593.         CensusPlus_Msg(
  2594.             CENSUSPLUS_UNKNOWNRACE .. race .. CENSUSPLUS_UNKNOWNRACE_ACTION
  2595.         )
  2596.         return
  2597.     end
  2598.  
  2599.     -- Get racial database
  2600.     local raceDatabase = factionDatabase[race]
  2601.     if (raceDatabase == nil) then
  2602.         factionDatabase[race] = {}
  2603.         raceDatabase = factionDatabase[race]
  2604.     end
  2605.  
  2606.     -- Get class database
  2607.     local classDatabase = raceDatabase[class]
  2608.     if (classDatabase == nil) then
  2609.         raceDatabase[class] = {}
  2610.         classDatabase = raceDatabase[class]
  2611.     end
  2612.  
  2613.     -- Get this player's entry
  2614.     local entry = classDatabase[name]
  2615.     if (entry == nil) then
  2616.         classDatabase[name] = {}
  2617.         entry = classDatabase[name]
  2618.         CensusPlus_JobQueue.g_NumNewCharacters =
  2619.             CensusPlus_JobQueue.g_NumNewCharacters + 1
  2620.     end
  2621.  
  2622.     -- Update the information
  2623.     entry[1] = level
  2624.     entry[2] = guild
  2625.     --      local hour, minute = GetGameTime();
  2626.     entry[3] = CensusPlus_DetermineServerDate() .. ""
  2627.  
  2628.     g_TempCount[name] = class
  2629.  
  2630.     --CensusPlus_Msg2( "Processed   " .. name );
  2631. end
  2632.  
  2633. -- Find a guild in the CensusPlus_Guilds array by name
  2634. local function FindGuildByName(name)
  2635.     local i
  2636.     local size = #CensusPlus_Guilds
  2637.     for i = 1, size, 1 do
  2638.         local entry = CensusPlus_Guilds[i]
  2639.         --5.4 to be done
  2640.         -- if name and realm == name and realm   to differentiate same name guild of different realms
  2641.         if (entry.m_Name == name) then
  2642.             return i
  2643.         end
  2644.     end
  2645.     return nil
  2646. end
  2647.  
  2648. -- Add up the total character XP and count
  2649. local function TotalsAccumulator(name, level, guild, raceName, className, lastseen, realmName, guildRealm)
  2650.     --  Add character to our player list
  2651.     --print(name.." ".. level.." "..className.." "..raceName.." "..realmName.." "..guild.." "..guildRealm.." "..lastseen)
  2652.     if g_AccumulateGuildTotals then
  2653.         CensusPlus_AddPlayerToList(
  2654.             name,
  2655.             level,
  2656.             guild,
  2657.             raceName,
  2658.             className,
  2659.             lastseen,
  2660.             realmName,
  2661.             guildRealm
  2662.         )
  2663.     end
  2664.  
  2665.     if g_TotalCharacterXPPerLevel[level] then
  2666.         InitConstantTables()
  2667.     end
  2668.  
  2669.     local totalCharacterXP = g_TotalCharacterXPPerLevel[level]
  2670.     if (totalCharacterXP == nil) then
  2671.         totalCharacterXP = 0
  2672.     end
  2673.     if (g_TotalCharacterXP == nil) then
  2674.         g_TotalCharacterXP = 0
  2675.     end
  2676.     g_TotalCharacterXP = g_TotalCharacterXP + totalCharacterXP
  2677.     g_TotalCount = g_TotalCount + 1
  2678.     --  print("g_TCount = "..g_TotalCount.." "..guild)
  2679.     if (g_AccumulateGuildTotals and (guild ~= nil)) then
  2680.         local index = FindGuildByName(guild)
  2681.         if (index == nil) then
  2682.             local size = #CensusPlus_Guilds
  2683.             index = size + 1
  2684.             CensusPlus_Guilds[index] = {
  2685.                 m_Name = guild,
  2686.                 m_TotalCharacterXP = 0,
  2687.                 m_Count = 0,
  2688.                 m_GuildRealm = guildRealm,
  2689.                 m_GNfull = guild
  2690.             }
  2691.         end
  2692.         local entry = CensusPlus_Guilds[index]
  2693.         entry.m_TotalCharacterXP = entry.m_TotalCharacterXP + totalCharacterXP
  2694.         entry.m_Count = entry.m_Count + 1
  2695.     end
  2696. end
  2697.  
  2698. -- Predicate function which can be used to compare two guilds for sorting
  2699. local function GuildPredicate(lhs, rhs)
  2700.  
  2701.     -- nil references are always less than
  2702.     if (lhs == nil) then
  2703.         if (rhs == nil) then
  2704.             return false
  2705.         else
  2706.             return true
  2707.         end
  2708.     elseif (rhs == nil) then
  2709.         return false
  2710.     end
  2711.    
  2712.     -- unguilded always first
  2713.     if (lhs.m_Name == "") then
  2714.         return true
  2715.     end
  2716.    
  2717.     if (rhs.m_Name == "") then
  2718.         return false
  2719.     end
  2720.  
  2721.     -- Sort by total XP first
  2722.     if (rhs.m_TotalCharacterXP < lhs.m_TotalCharacterXP) then
  2723.         return true
  2724.     elseif (lhs.m_TotalCharacterXP < rhs.m_TotalCharacterXP) then
  2725.         return false
  2726.     end
  2727.  
  2728.     -- Sort by name
  2729.     if (lhs.m_Name < rhs.m_Name) then
  2730.         return true
  2731.     elseif (rhs.m_Name < lhs.m_Name) then
  2732.         return false
  2733.     end
  2734.  
  2735.     -- identical
  2736.     return false
  2737. end
  2738.  
  2739. -- Another accumulator for adding up XP and counts
  2740. local function CensusPlus_Accumulator(name, level, guild)
  2741.     if (g_TotalCharacterXPPerLevel[level] == nil) then
  2742.         InitConstantTables()
  2743.     end
  2744.     local totalCharacterXP = g_TotalCharacterXPPerLevel[level]
  2745.     if (totalCharacterXP == nil or g_TotalCharacterXPPerLevel[level] == nil) then return end
  2746.     g_AccumulatorXPTotal = g_AccumulatorXPTotal + totalCharacterXP
  2747.     g_AccumulatorCount = g_AccumulatorCount + 1
  2748. end
  2749.  
  2750. -- Reset the above accumulator
  2751. local function CensusPlus_ResetAccumulator()
  2752.     g_AccumulatorCount = 0
  2753.     g_AccumulatorXPTotal = 0
  2754. end
  2755.  
  2756. -- Search the character database using the search criteria and update display
  2757. function CensusPlus_UpdateView()
  2758.  
  2759.     --  No need to do anything if the window is not open
  2760.     if not CensusPlusClassic:IsVisible() then return end
  2761.  
  2762.     -- Get realm and faction
  2763.     local realmName = CensusPlus_GetUniqueRealmName()
  2764.  
  2765.     CensusPlusTopGuildsTitle:SetText(CENSUSPLUS_TOPGUILD)
  2766.     g_AccumulateGuildTotals = true
  2767.  
  2768.     if (realmName == nil) then return end
  2769.  
  2770.     if (CensusPlus_PTR ~= false) then
  2771.         realmName = PTR_Color_ProblemRealmGuilds_check(realmName)
  2772.     end -- not PTR must be live
  2773.  
  2774.     CensusPlusRealmName:SetText(format(CENSUSPLUS_REALMNAME, string.match(realmName, "_(.*)")))
  2775.  
  2776.     local factionGroup, factionGName = UnitFactionGroup("player")
  2777.     if (factionGroup == nil or factionGroup == "Neutral") then
  2778.         return -- rework this area?.. if neutral display warn message elif display faction  ..or not needed handled in xml
  2779.     end
  2780.  
  2781.     CensusPlusFactionName:SetText(format(CENSUSPLUS_FACTION, factionGName))
  2782.  
  2783.     if not g_VariablesLoaded then
  2784.         return -- if variables aren't loaded show partial window data and escape
  2785.     end
  2786.    
  2787.     local guildKey = nil
  2788.     local raceKey = nil
  2789.     local classKey = nil
  2790.     local levelKey = nil
  2791.     g_TotalCharacterXP = 0
  2792.     g_TotalCount = 0
  2793.  
  2794.  
  2795.  
  2796.     -- Has the user selected a guild?
  2797.     if (CPp.GuildSelected > 0) then
  2798.         guildKey = CensusPlus_Guilds[CPp.GuildSelected].m_Name;
  2799.     end
  2800.  
  2801.     -- Has the user added any search criteria?
  2802.     if (CPp.RaceSelected > 0) then
  2803.         local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup)
  2804.         raceKey = thisFactionRaces[CPp.RaceSelected]
  2805.     end
  2806.     if (CPp.ClassSelected > 0) then
  2807.         local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup)
  2808.         classKey = thisFactionClasses[CPp.ClassSelected]
  2809.     end
  2810.     if (CPp.LevelSelected > 0 or CPp.LevelSelected < 0) then
  2811.         levelKey = CPp.LevelSelected
  2812.     end
  2813.  
  2814.     -- Has the user added any search criteria?
  2815.     if ((guildKey ~= nil) or (raceKey ~= nil) or (classKey ~= nil) or (levelKey ~= nil)) then
  2816.         -- Get totals for this criteria
  2817.         g_AccumulateGuildTotals = false;
  2818.         CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, classKey, guildKey, levelKey, TotalsAccumulator);
  2819.        
  2820.         if( CensusPlus_EnableProfiling ) then
  2821.             CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 );
  2822.             --debugprofilestart();
  2823.         end
  2824.        
  2825.     else
  2826.         -- Get the overall totals and find guild information
  2827.         CensusPlus_Guilds = {};
  2828.         g_AccumulateGuildTotals = true;
  2829.         CensusPlus_ForAllCharacters(realmName, factionGroup, nil, nil, nil, nil, TotalsAccumulator);
  2830.        
  2831.         if( CensusPlus_EnableProfiling ) then
  2832.             CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 );
  2833.             --debugprofilestart();
  2834.         end
  2835.        
  2836.         local size = table.getn(CensusPlus_Guilds);
  2837.         if (size) then
  2838.             table.sort(CensusPlus_Guilds, GuildPredicate);
  2839.         end
  2840.        
  2841.         if( CensusPlus_EnableProfiling ) then
  2842.             CensusPlus_Msg( "PROFILE: Time to sort guilds " .. debugprofilestop() / 1000000000 );
  2843.             --debugprofilestart();
  2844.         end        
  2845.     end
  2846.    
  2847.     local levelSearch = nil;
  2848.     if (levelKey ~= nil) then
  2849.         levelSearch = "  ("..CENSUSPLUS_LEVEL..": ";
  2850.         local level = levelKey;
  2851.         if (levelKey < 0) then
  2852.             levelSearch = levelSearch.."!";
  2853.             level = 0 - levelKey;
  2854.         end
  2855.         levelSearch = levelSearch..level..")";
  2856.     end
  2857.  
  2858.     local totalCharactersText = nil;
  2859.     if (levelSearch ~= nil) then
  2860.         totalCharactersText = format(CENSUSPLUS_TOTALCHAR, g_TotalCount) .. levelSearch
  2861.     else
  2862.         totalCharactersText = format(CENSUSPLUS_TOTALCHAR, g_TotalCount)
  2863.     end
  2864.     CensusPlusTotalCharacters:SetText(totalCharactersText);
  2865.     --CensusPlusTotalCharacterXP:SetText(format(CENSUSPlus_TOTALCHARXP, g_TotalCharacterXP));
  2866.     CensusPlus_UpdateGuildButtons();
  2867.    
  2868.     if( CensusPlus_EnableProfiling ) then
  2869.         CensusPlus_Msg( "PROFILE: Update Guilds " .. debugprofilestop() / 1000000000 );
  2870.         --debugprofilestart();
  2871.     end
  2872.  
  2873.     -- Accumulate totals for each race
  2874.     local maxCount = 0;
  2875.     local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
  2876.     local numRaces = table.getn(thisFactionRaces);
  2877.     for i = 1, numRaces, 1 do
  2878.         local race = thisFactionRaces[i];
  2879.         CensusPlus_ResetAccumulator();
  2880.         if ((raceKey == nil) or (raceKey == race)) then
  2881.             CensusPlus_ForAllCharacters(realmName, factionGroup, race, classKey, guildKey, levelKey, CensusPlus_Accumulator);
  2882.         end
  2883.         if (g_AccumulatorCount > maxCount) then
  2884.             maxCount = g_AccumulatorCount;
  2885.         end
  2886.         g_RaceCount[i] = g_AccumulatorCount;
  2887.     end
  2888.  
  2889.     -- Update race bars
  2890.     for i = 1, numRaces, 1 do
  2891.         local race = thisFactionRaces[i];
  2892.         local buttonName = "CensusPlusRaceBar"..i;
  2893.         local button = _G[buttonName];
  2894.         local thisCount = g_RaceCount[i];
  2895.         if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
  2896.             local height = floor((thisCount / maxCount) * CensusPlus_MAXBARHEIGHT);
  2897.             if (height < 1 or height == nil ) then height = 1; end
  2898.             button:SetHeight(height);
  2899.             button:Show();
  2900.         else
  2901.             button:Hide();
  2902.         end
  2903.         local normalTextureName= "Interface\\AddOns\\CensusPlusClassic\\skins\\CensusPlus_" .. g_RaceClassList[race]
  2904.         local legendName = "CensusPlusRaceLegend"..i;
  2905.         local legend = _G[legendName]
  2906.         legend:SetNormalTexture(normalTextureName);
  2907.         if (CPp.RaceSelectedd == i) then
  2908.             legend:LockHighlight();
  2909.         else
  2910.             legend:UnlockHighlight();
  2911.         end
  2912.     end
  2913.  
  2914.     if( CensusPlus_EnableProfiling ) then
  2915.         CensusPlus_Msg( "PROFILE: Update Races " .. debugprofilestop() / 1000000000 );
  2916.         --debugprofilestart();
  2917.     end
  2918.  
  2919.     -- Accumulate totals for each class
  2920.     local maxCount = 0;
  2921.     local thisFactionClasss = CensusPlus_GetFactionClasses(factionGroup);
  2922.     local numClasses = table.getn(thisFactionClasss);
  2923.     for i = 1, numClasses, 1 do
  2924.         local class = thisFactionClasss[i];
  2925.         CensusPlus_ResetAccumulator();
  2926.         if ((classKey == nil) or (classKey == class)) then
  2927.             CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, class, guildKey, levelKey, CensusPlus_Accumulator);
  2928.         end
  2929.         if (g_AccumulatorCount > maxCount) then
  2930.             maxCount = g_AccumulatorCount;
  2931.         end
  2932.         g_ClassCount[i] = g_AccumulatorCount;
  2933.     end
  2934.  
  2935.     -- Update class bars
  2936.     for i = 1, numClasses, 1 do
  2937.         local class = thisFactionClasss[i];
  2938.  
  2939.         local buttonName = "CensusPlusClassBar"..i;
  2940.         local button = _G[buttonName]
  2941.         local thisCount = g_ClassCount[i];
  2942.         if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
  2943.             local height = floor((thisCount / maxCount) * CensusPlus_MAXBARHEIGHT);
  2944.             if (height < 1 or height == nil ) then height = 1; end
  2945.             button:SetHeight(height);
  2946.             button:Show();
  2947.         else
  2948.             button:Hide();
  2949.         end
  2950.  
  2951.         local normalTextureName="Interface\\AddOns\\CensusPlusClassic\\skins\\CensusPlus_" .. g_RaceClassList[class]
  2952.         local legendName = "CensusPlusClassLegend"..i;
  2953.         local legend = _G[legendName]
  2954.         legend:SetNormalTexture(normalTextureName);
  2955.         if (g_ClassSelected == i) then
  2956.             legend:LockHighlight();
  2957.         else
  2958.             legend:UnlockHighlight();
  2959.         end
  2960.     end
  2961.  
  2962.     if( CensusPlus_EnableProfiling ) then
  2963.         CensusPlus_Msg( "PROFILE: Update Classes " .. debugprofilestop() / 1000000000 );
  2964.         --debugprofilestart();
  2965.     end
  2966.  
  2967.     -- Accumulate totals for each level
  2968.     local maxCount = 0;
  2969.     for i = 1, MAX_CHARACTER_LEVEL, 1 do
  2970.         if ((levelKey == nil) or (levelKey == i) or (levelKey < 0 and levelKey + i ~= 0)) then
  2971.             CensusPlus_ResetAccumulator();
  2972.             CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, classKey, guildKey, i, CensusPlus_Accumulator);
  2973.             if (g_AccumulatorCount > maxCount) then
  2974.                 maxCount = g_AccumulatorCount;
  2975.             end
  2976.             g_LevelCount[i] = g_AccumulatorCount;
  2977.         else
  2978.             g_LevelCount[i] = 0;
  2979.         end
  2980.     end
  2981.  
  2982.     -- Update level bars
  2983.     for i = 1, MAX_CHARACTER_LEVEL, 1 do
  2984.         local buttonName = "CensusPlusLevelBar"..i;
  2985.         local buttonEmptyName = "CensusPlusLevelBarEmpty"..i;
  2986.         local button = getglobal(buttonName);
  2987.         local emptyButton = getglobal(buttonEmptyName);
  2988.         local thisCount = g_LevelCount[i];
  2989.         if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
  2990.             local height = floor((thisCount / maxCount) * CensusPlus_MAXBARHEIGHT);
  2991.             if (height < 1 or height == nil ) then height = 1; end
  2992.             button:SetHeight(height);
  2993.             button:Show();
  2994.             if (emptyButton ~= nil) then
  2995.                 emptyButton:Hide();
  2996.             end
  2997.         else
  2998.             button:Hide();
  2999.             if (emptyButton ~= nil) then
  3000.                 emptyButton:SetHeight(CensusPlus_MAXBARHEIGHT);
  3001.                 emptyButton:Show();
  3002.             end
  3003.         end
  3004.     end
  3005.    
  3006.     if( CensusPlus_EnableProfiling ) then
  3007.         CensusPlus_Msg( "PROFILE: Update Levels " .. debugprofilestop() / 1000000000 );
  3008.         --debugprofilestart(); 
  3009.     end
  3010.    
  3011.     if( CP_PlayerListWindow:IsVisible() ) then
  3012.         CensusPlus_PlayerListOnShow();
  3013.     end
  3014.    
  3015.  
  3016.     debugprofilestop();
  3017. end
  3018.  
  3019. -- Walk the character database and call the callback function for every entry that matches the search criteria
  3020. function CensusPlus_ForAllCharacters(realmKey, factionKey, raceKey, classKey, guildKey, levelKey, callback)
  3021.     for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
  3022.         if ((realmKey == nil) or (realmKey == realmName)) then
  3023.             for factionName, factionDatabase in pairs(realmDatabase) do
  3024.                 if ((factionKey == nil) or (factionKey == factionName)) then
  3025.                     for raceName, raceDatabase in pairs(factionDatabase) do
  3026.                         if ((raceKey == nil) or (raceKey == raceName)) then
  3027.                             for className, classDatabase in pairs(raceDatabase) do
  3028.                                 if ((classKey == nil) or (classKey == className)) then
  3029.                                     for characterName, character in pairs(classDatabase) do
  3030.                                     local characterGuild = character[2];
  3031.                                         if ((guildKey == nil) or (guildKey == characterGuild)) then
  3032.                                             local characterLevel = character[1];
  3033.                                             if( characterLevel == nil ) then
  3034.                                                 characterLevel = 0;
  3035.                                             end
  3036.                                             if ((levelKey == nil) or (levelKey == characterLevel) or (levelKey < 0 and levelKey + characterLevel ~= 0)) then
  3037.                                                 callback(characterName, characterLevel, characterGuild, raceName, className, character[3] );
  3038.                                             end
  3039.                                         end
  3040.                                     end
  3041.                                 end
  3042.                             end
  3043.                         end
  3044.                     end
  3045.                 end
  3046.             end
  3047.         end
  3048.     end
  3049. end
  3050.  
  3051. -- Race legend clicked
  3052. -- referenced by CensusPlusClassic.xml
  3053. function CensusPlus_OnClickRace(self )
  3054.     --  default click is "LeftButton" and up .. no RegisterForClicks used
  3055.     local id = self:GetID()
  3056.     if (id == CPp.RaceSelected) then
  3057.         CPp.RaceSelected = 0
  3058.     else
  3059.         CPp.RaceSelected = id
  3060.     end
  3061.     CensusPlus_UpdateView()
  3062. end
  3063.  
  3064. -- Class legend clicked
  3065. -- referenced by CensusPlusClassic.xml
  3066. function CensusPlus_OnClickClass(self)
  3067.     --  default click is "LeftButton" and up .. no RegisterForClicks used
  3068.     local id = self:GetID()
  3069.     if (id == CPp.ClassSelected) then
  3070.         CPp.ClassSelected = 0
  3071.     else
  3072.         CPp.ClassSelected = id
  3073.     end
  3074.     CensusPlus_UpdateView()
  3075. end
  3076.  
  3077. -- Level bar loaded
  3078. -- referenced by CensusPlusClassic.xml
  3079. function CensusPlus_OnLoadLevel(self)
  3080.     self:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  3081. end
  3082.  
  3083. -- Level bar clicked
  3084. -- referenced by CensusPlusClassic.xml
  3085. function CensusPlus_OnClickLevel(self, CP_button)
  3086.     -- both right and left buttons up registered.
  3087.     local id = self:GetID()
  3088.     if (((CP_button == "LeftButton") and (id == CPp.LevelSelected)) or ((CP_button == "RightButton") and (id + CPp.LevelSelected == 0))) then
  3089.         CPp.LevelSelected = 0
  3090.     elseif (CP_button == "RightButton") then
  3091.         CPp.LevelSelected = 0 - id
  3092.     else
  3093.         CPp.LevelSelected = id
  3094.     end
  3095.     CensusPlus_UpdateView()
  3096. end
  3097.  
  3098. -- Race tooltip
  3099. -- referenced by CensusPlusClassic.xml
  3100. function CensusPlus_OnEnterRace(self, motion)
  3101.     if motion then
  3102.         local factionGroup = UnitFactionGroup("player")
  3103.         local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup)
  3104.         local id = self:GetID()
  3105.         local raceName = thisFactionRaces[id]
  3106.         local count = g_RaceCount[id]
  3107.         if (count ~= nil) and (g_TotalCount > 0) then
  3108.             local percent = string.format("%.2f", (count / g_TotalCount) * 100)
  3109.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  3110.             GameTooltip:SetText(
  3111.                 raceName .. "\n" .. count .. "\n" .. percent .. "%",
  3112.                 1.0,
  3113.                 1.0,
  3114.                 1.0
  3115.             )
  3116.             GameTooltip:Show()
  3117.             -- this should never happen
  3118.             --GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  3119.             --GameTooltip:SetText(raceName.."\n 0", 1.0, 1.0, 1.0);
  3120.             --GameTooltip:Show();
  3121.         else
  3122.         end
  3123.     end -- event triggered by frame creation.. not moues movement.. so ignore
  3124. end
  3125.  
  3126. -- Class tooltip
  3127. -- referenced by CensusPlusClassic.xml
  3128. function CensusPlus_OnEnterClass(self, motion)
  3129.     if motion then
  3130.         local factionGroup = UnitFactionGroup("player")
  3131.         local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup)
  3132.         local id = self:GetID()
  3133.         local className = thisFactionClasses[id]
  3134.         local count = g_ClassCount[id]
  3135.         if (count ~= nil) and (g_TotalCount > 0) then
  3136.             local percent = string.format("%.2f", (count / g_TotalCount) * 100)
  3137.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  3138.             GameTooltip:SetText(
  3139.                 className .. "\n" .. count .. "\n" .. percent .. "%",
  3140.                 1.0,
  3141.                 1.0,
  3142.                 1.0
  3143.             )
  3144.             GameTooltip:Show()
  3145.             -- this should never happen
  3146.             --GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  3147.             --GameTooltip:SetText(className.."\n 0", 1.0, 1.0, 1.0);
  3148.             --GameTooltip:Show();
  3149.         else
  3150.         end
  3151.     end -- entered via frame creation.. not mouse motion .. ignore
  3152. end
  3153.  
  3154. -- Level tooltip
  3155. -- referenced by CensusPlusClassic.xml
  3156. function CensusPlus_OnEnterLevel(self, motion )
  3157.     if motion then
  3158.         local id = self:GetID()
  3159.         local count = g_LevelCount[id]
  3160.         if (count ~= nil) and (g_TotalCount > 0) then
  3161.             local percent = string.format("%.2f", (count / g_TotalCount) * 100)
  3162.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  3163.             GameTooltip:SetText(
  3164.                 LEVEL .. " " .. id .. "\n" .. count .. "\n" .. percent .. "%",
  3165.                 1.0,
  3166.                 1.0,
  3167.                 1.0
  3168.             )
  3169.             GameTooltip:Show()
  3170.             -- this should never happen
  3171.             --GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  3172.             --GameTooltip:SetText("Level "..id.."\n 0", 1.0, 1.0, 1.0);
  3173.             --GameTooltip:Show();
  3174.         else
  3175.         end
  3176.     end -- entered via frame creation .. not mouse movement.. ignore
  3177. end
  3178.  
  3179. -- Clicked a guild button
  3180. -- referenced by CensusPlusClassic.xml
  3181. function CensusPlus_GuildButton_OnClick(self )
  3182.     local id = self:GetID();
  3183.     local offset = FauxScrollFrame_GetOffset(CensusPlusGuildScrollFrame);
  3184.     local newSelection = id + offset;
  3185.     if (CPp.GuildSelected ~= newSelection) then
  3186.         CPp.GuildSelected = newSelection;
  3187.     else
  3188.         CPp.GuildSelected = 0;
  3189.     end
  3190.     CensusPlus_UpdateView();
  3191. end
  3192.  
  3193. -- Update the guild button contents
  3194. function CensusPlus_UpdateGuildButtons()
  3195.     -- Determine where the scroll bar is
  3196.     local offset = FauxScrollFrame_GetOffset(CensusPlusGuildScrollFrame)
  3197.     -- Walk through all the rows in the frame
  3198.     local size = #CensusPlus_Guilds
  3199.     --  print("num guild buttons = "..size)
  3200.     local i = 1
  3201.     while (i <= CensusPlus_NUMGUILDBUTTONS) do
  3202.         -- Get the index to the ad displayed in this row
  3203.         local iGuild = i + offset
  3204.         -- Get the button on this row
  3205.         local button = _G["CensusPlusGuildButton" .. i]
  3206.         -- Is there a valid guild on this row?
  3207.         if (iGuild <= size) then
  3208.             local guild = CensusPlus_Guilds[iGuild]
  3209.             -- Update the button text
  3210.             button:Show()
  3211.             local textField = "CensusPlusGuildButton" .. i .. "Text"
  3212.             if (guild.m_Name == "") then
  3213.                 _G[textField]:SetText(CENSUSPLUS_UNGUILDED)
  3214.             else
  3215.                 _G[textField]:SetText(guild.m_GNfull)
  3216.             end
  3217.             -- If this is the guild, highlight it
  3218.             if (CPp.GuildSelected == iGuild) then
  3219.                 button:LockHighlight();
  3220.             else
  3221.                 button:UnlockHighlight();
  3222.             end
  3223.         -- Hide the button
  3224.         else
  3225.             button:Hide()
  3226.         end
  3227.         --
  3228.         -- Next row
  3229.         --
  3230.         i = i + 1
  3231.     end
  3232.    
  3233.     -- Update the scroll bar
  3234.     FauxScrollFrame_Update(
  3235.         CensusPlusGuildScrollFrame,
  3236.         size,
  3237.         CensusPlus_NUMGUILDBUTTONS,
  3238.         CensusPlus_GUILDBUTTONSIZEY
  3239.     )
  3240. end
  3241.  
  3242. -- Walk the character database prune all characters entries that are older than X days
  3243. -- referenced by CensusPlusClassic.xml
  3244. function CENSUSPLUS_PRUNEData(nDays, sServer)
  3245.  
  3246.     local pruneTime = 24 * 60 * 60 * nDays
  3247.  
  3248.     for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
  3249.         for factionName, factionDatabase in pairs(realmDatabase) do
  3250.             if ((factionKey == nil) or (factionKey == factionName)) then
  3251.                 for raceName, raceDatabase in pairs(factionDatabase) do
  3252.                     if ((raceKey == nil) or (raceKey == raceName)) then
  3253.                         for className, classDatabase in
  3254.                             pairs(raceDatabase)
  3255.                         do
  3256.                             if ((classKey == nil) or (classKey == className)) then
  3257.                                 for characterName, character in
  3258.                                     pairs(classDatabase)
  3259.                                 do
  3260.                                     if (characterName ~= nil) then
  3261.                                         --[[
  3262.                                             if( sServer == 1 ) then
  3263.                                                 if( realmName ~= thisRealmName ) then
  3264.                                                     CensusPlus_AccumulatePruneData( realmName, factionName, raceName, className, characterName );
  3265.                                                 end
  3266.                                             else
  3267.                                                 if( realmName == thisRealmName ) then
  3268.                                         --]]
  3269.                                         local lastSeen = character[3] --  2005-05-02
  3270.                                         local tYear, tMonth, tDay
  3271.                                         tYear = string.sub(lastSeen, 1, 4)
  3272.                                         tMonth = string.sub(lastSeen, 6, 7)
  3273.                                         tDay = string.sub(lastSeen, 9)
  3274.  
  3275.                                         local lastSeenTime = time({
  3276.                                             year = tYear,
  3277.                                             month = tMonth,
  3278.                                             day = tDay,
  3279.                                             hour = 0
  3280.                                         })
  3281.  
  3282.                                         if (time() - lastSeenTime > pruneTime) then
  3283.                                             CensusPlus_AccumulatePruneData(
  3284.                                                 realmName,
  3285.                                                 factionName,
  3286.                                                 raceName,
  3287.                                                 className,
  3288.                                                 characterName
  3289.                                             )
  3290.                                         end
  3291.                                         --end
  3292.                                         --end
  3293.                                     end
  3294.                                 end
  3295.                             end
  3296.                         end
  3297.                     end
  3298.                 end
  3299.             end
  3300.         end
  3301.     end
  3302.     CENSUSPLUS_PRUNETimes()
  3303.     CensusPlus_UpdateView()
  3304.     CENSUSPLUS_PRUNETheData()
  3305.     CENSUSPLUS_PRUNEDeadBranches()
  3306. end
  3307.  
  3308. -- Prune the accumulation
  3309. function CensusPlus_AccumulatePruneData(realm, faction, race, class, name)
  3310.     local pruneData = {}
  3311.     pruneData.realm = realm
  3312.     pruneData.faction = faction
  3313.     pruneData.race = race
  3314.     pruneData.class = class
  3315.     pruneData.name = name
  3316.     --print("Prune "..realm.." "..faction.." "..race.." "..class.." "..name)
  3317.     table.insert(g_AccumulatedPruneData, pruneData)
  3318. end
  3319.  
  3320. -- Prune the accumulation
  3321. function CENSUSPLUS_PRUNETheData()
  3322.     local num = #g_AccumulatedPruneData
  3323.     CensusPlus_Msg(format(CENSUSPLUS_PRUNEINFO, num))
  3324.     while (num > 0) do
  3325.         -- Remove the top job from the queue and send it
  3326.         local pruneData = g_AccumulatedPruneData[num]
  3327.  
  3328.         CensusPlus_Database["Servers"][pruneData.realm][pruneData.faction][pruneData.race][pruneData.class][pruneData.name]
  3329.         = {}
  3330.         CensusPlus_Database["Servers"][pruneData.realm][pruneData.faction][pruneData.race][pruneData.class][pruneData.name]
  3331.         = nil
  3332.  
  3333.         table.remove(g_AccumulatedPruneData)
  3334.         num = #g_AccumulatedPruneData
  3335.     end
  3336. end
  3337.  
  3338. -- Prune time entries
  3339. function CENSUSPLUS_PRUNETimes()
  3340.     local pruneDays = 60 * 60 * 24 * 21 --  num seconds
  3341.     local accumTimesData = {}
  3342.     local PruneCount = 0
  3343.  
  3344.     for realmName, realmDatabase in pairs(CensusPlus_Database["TimesPlus"]) do
  3345.         if (realmName ~= nil) then
  3346.             for factionName, factionDatabase in pairs(realmDatabase) do
  3347.                 if (factionName ~= nil) then
  3348.                     for moment, count in pairs(factionDatabase) do
  3349.                         --  Moment is in format of YYYY-MM-DD&HH:MM
  3350.                         local test = string.sub(moment, 1, 2)
  3351.                         local tYear, tMonth, tDay
  3352.                         tYear = string.sub(moment, 1, 4)
  3353.                         tMonth = string.sub(moment, 6, 7)
  3354.                         tDay = string.sub(moment, 9, 10)
  3355.                         local momentTime = time({
  3356.                             year = tYear,
  3357.                             month = tMonth,
  3358.                             day = tDay,
  3359.                             hour = 0
  3360.                         })
  3361.  
  3362.                         if (time() - momentTime > pruneDays) then
  3363.                             --  cull entry
  3364.                             local pruneData = {}
  3365.                             pruneData.realm = realmName
  3366.                             pruneData.faction = factionName
  3367.                             pruneData.entry = moment
  3368.                             table.insert(accumTimesData, pruneData)
  3369.                         end
  3370.                     end
  3371.                 end
  3372.             end
  3373.         end
  3374.     end
  3375.  
  3376.     local num = #accumTimesData
  3377.     while (num > 0) do
  3378.         local pruneData = accumTimesData[num]
  3379.  
  3380.         CensusPlus_Database["TimesPlus"][pruneData.realm][pruneData.faction][pruneData.entry]
  3381.         = {}
  3382.         CensusPlus_Database["TimesPlus"][pruneData.realm][pruneData.faction][pruneData.entry]
  3383.         = nil
  3384.         table.remove(accumTimesData)
  3385.         num = #accumTimesData
  3386.     end
  3387.  
  3388.     for realmName, realmDatabase in pairs(CensusPlus_Database["TimesPlus"]) do
  3389.         if (realmName ~= nil) then
  3390.             for factionName, factionDatabase in pairs(realmDatabase) do
  3391.                 if (factionName ~= nil) then
  3392.                     PruneCount = 0
  3393.                     for _ in pairs(factionDatabase) do
  3394.                         PruneCount = PruneCount + 1
  3395.                     end
  3396.                     if (PruneCount == 0) then
  3397.                         realmDatabase[factionName] = {}
  3398.                         realmDatabase[factionName] = nil
  3399.                     end
  3400.                 end
  3401.             end
  3402.             PruneCount = 0
  3403.             for _ in pairs(realmDatabase) do
  3404.                 PruneCount = PruneCount + 1
  3405.             end
  3406.             if (PruneCount == 0) then
  3407.                 CensusPlus_Database["TimesPlus"][realmName] = {}
  3408.                 CensusPlus_Database["TimesPlus"][realmName] = nil
  3409.             end
  3410.         end
  3411.     end
  3412. end
  3413.  
  3414. function CENSUSPLUS_PRUNEDeadBranches()
  3415.     local PruneCount = 0
  3416.  
  3417.     for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
  3418.         if (realmName ~= nil) then
  3419.             for factionName, factionDatabase in pairs(realmDatabase) do
  3420.                 if (factionName ~= nil) then
  3421.                     for raceName, raceDatabase in pairs(factionDatabase) do
  3422.                         if (raceName ~= nil) then
  3423.                             for className, classDatabase in
  3424.                                 pairs(raceDatabase)
  3425.                             do
  3426.                                 if (className ~= nil) then
  3427.                                     PruneCount = 0
  3428.                                     for _ in pairs(classDatabase) do
  3429.                                         PruneCount = PruneCount + 1
  3430.                                         if (PruneCount > 0) then
  3431.                                             break
  3432.                                         end
  3433.                                     end
  3434.                                     if (PruneCount == 0) then
  3435.                                         raceDatabase[className] = {}
  3436.                                         raceDatabase[className] = nil
  3437.                                     end
  3438.                                 end
  3439.                             end
  3440.                             PruneCount = 0
  3441.                             for _ in pairs(raceDatabase) do
  3442.                                 PruneCount = PruneCount + 1
  3443.                                 if (PruneCount > 0) then
  3444.                                     break
  3445.                                 end
  3446.                             end
  3447.                             if (PruneCount == 0) then
  3448.                                 factionDatabase[raceName] = {}
  3449.                                 factionDatabase[raceName] = nil
  3450.                             end
  3451.                         end
  3452.                     end
  3453.                     PruneCount = 0
  3454.                     for _ in pairs(factionDatabase) do
  3455.                         PruneCount = PruneCount + 1
  3456.                         if (PruneCount > 0) then
  3457.                             break
  3458.                         end
  3459.                     end
  3460.                     if (PruneCount == 0) then
  3461.                         realmDatabase[factionName] = {}
  3462.                         realmDatabase[factionName] = nil
  3463.                     end
  3464.                 end
  3465.             end
  3466.             PruneCount = 0
  3467.             for _ in pairs(realmDatabase) do
  3468.                 PruneCount = PruneCount + 1
  3469.                 if (PruneCount > 0) then
  3470.                     break
  3471.                 end
  3472.             end
  3473.             if (PruneCount == 0) then
  3474.                 CensusPlus_Database["Servers"][realmName] = {}
  3475.                 CensusPlus_Database["Servers"][realmName] = nil
  3476.             end
  3477.         end
  3478.     end
  3479. end
  3480.  
  3481. function CensusPlus_CheckForBattleground()
  3482.     --CensusPlus_Msg( "Checking for BG" );
  3483.     g_CurrentlyInBG_Msg = false
  3484.  
  3485.     local battlefieldTime = GetBattlefieldInstanceRunTime()
  3486.     if (battlefieldTime > 0) then
  3487.         --  We are in a battleground so cancel the current take
  3488.         g_CurrentlyInBG = true -- if player in battlefield
  3489.     else
  3490.         if (GetBattlefieldStatInfo(1) ~= nil) then
  3491.             g_CurrentlyInBG = true
  3492.         else
  3493.             g_CurrentlyInBG = false
  3494.         end
  3495.     end
  3496. end
  3497.  
  3498. -- CensusPlus_DetermineServerDate
  3499. function CensusPlus_DetermineServerDate()
  3500.     return date("!%Y-%m-%d", GetServerTime())
  3501. end
  3502.  
  3503. -- Check time zone
  3504. function CensusPlus_CheckTZ()
  3505.     local UTCTimeHour = date("!%H", time())
  3506.     local LocTimeHour = date("%H", time())
  3507.     local hour, minute = GetGameTime()
  3508.     local locDiff = LocTimeHour - UTCTimeHour
  3509.     local servDiff = hour - UTCTimeHour
  3510.     g_CensusPlusTZOffset = servDiff
  3511. end
  3512.  
  3513. function ManualWho()
  3514.   if (CPp.IsCensusPlusInProgress and not g_CurrentlyInBG) then
  3515.     now = time()
  3516.     local deltaManual = now - CPp.LastManualWho
  3517.     if deltaManual > CensusPlus_UPDATEDELAY then
  3518.       if (g_Verbose == true) then
  3519.         print("ManualWho:", whoMsg)
  3520.       end
  3521.       CPp.LastManualWho = time()
  3522.       if (whoquery_active) then
  3523.         FriendsFrame:UnregisterEvent("WHO_LIST_UPDATE")
  3524.         C_FriendList.SetWhoToUi(true)
  3525.         CensusPlusClassic:RegisterEvent("WHO_LIST_UPDATE")
  3526.         C_FriendList.SendWho(whoMsg)
  3527.       end
  3528.     end
  3529.   end
  3530. end
  3531.  
  3532. function CensusPlus_SendWho(msg)
  3533.     if (g_Verbose == true) then
  3534.         CensusPlus_Msg(format(CENSUSPLUS_SENDING, msg))
  3535.     end
  3536.  
  3537.     -- Add CensusButton show top of whoquery
  3538.     if g_CensusButtonAnimi then
  3539.         local _, _, topwho = string.find(msg, "(%d+)")
  3540.         topwho = string.sub(msg, string.find(msg, "-", -4) + 1)
  3541.         topwhoval = tonumber(topwho)
  3542.         if (topwhoval > 99) then
  3543.             --topwho = topwho - 100
  3544.             CensusButton:SetNormalFontObject(GameFontNormalSmall)
  3545.             topwho = "|cffff5e16" .. topwho .. "|r"
  3546.         else
  3547.             CensusButton:SetNormalFontObject(GameFontNormal)
  3548.         end
  3549.         CensusButton:SetText(topwho)
  3550.     end
  3551.  
  3552.     whoMsg = msg
  3553.    
  3554.     whoquery_active = true
  3555.     CP_g_queue_count = CP_g_queue_count + 1
  3556. end
  3557.  
  3558. function PTR_Color_ProblemNames_check(name)
  3559.     --[[
  3560.             PTR testing modifications
  3561.             Blizzard has odd naming allowances in PTR realms
  3562.             name (US) or name (EU)  ditto for guild names
  3563.     --]]
  3564.  
  3565.     if (CensusPlus_PTR ~= false) then
  3566.         local cp_ptr_name_check, _, _ = string.find(name, "  %(")
  3567.         if (cp_ptr_name_check ~= nil) then
  3568.             name =
  3569.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3570.                     name,
  3571.                     cp_ptr_name_check + 3,
  3572.                     cp_ptr_name_check + 4
  3573.                 )
  3574.         end
  3575.         local cp_ptr_name_check, _, _ = string.find(name, " %(")
  3576.         if (cp_ptr_name_check ~= nil) then
  3577.             name =
  3578.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3579.                     name,
  3580.                     cp_ptr_name_check + 2,
  3581.                     cp_ptr_name_check + 3
  3582.                 )
  3583.         end
  3584.         local cp_ptr_name_check, _, _ = string.find(name, "%(")
  3585.         if (cp_ptr_name_check ~= nil) then
  3586.             name =
  3587.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3588.                     name,
  3589.                     cp_ptr_name_check + 1,
  3590.                     cp_ptr_name_check + 2
  3591.                 )
  3592.         end
  3593.     end
  3594.  
  3595.     --  Test the name for possible color coding
  3596.     --  for example |cffff0000Rollie|r
  3597.     local karma_check = string.find(name, "|cff")
  3598.     if (karma_check ~= nil) then
  3599.         name = string.sub(name, 11, -3)
  3600.     end
  3601.    
  3602.     --  Further check for problematic chars
  3603.     local pattern = "[%d| ]"
  3604.     if (string.find(name, pattern) ~= nil) then
  3605.         if not g_ProblematicMessageShown then
  3606.             CensusPlus_Msg(
  3607.                 CENSUSPLUS_PROBLEMNAME .. name .. CENSUSPLUS_PROBLEMNAME_ACTION
  3608.             )
  3609.             g_ProblematicMessageShown = true
  3610.         end
  3611.         name = ""
  3612.     end
  3613.     return name
  3614. end
  3615.  
  3616. function PTR_Color_ProblemRealmGuilds_check(name)
  3617.     --[[
  3618.             PTR testing modifications
  3619.             Blizzard has odd naming allowances in PTR realms
  3620.             name (US) or name (EU)  ditto for guild names
  3621. ´  --]]
  3622.  
  3623.     if (CensusPlus_PTR ~= false) then
  3624.         local cp_ptr_name_check, _, _ = string.find(name, "  %(")
  3625.         if (cp_ptr_name_check ~= nil) then
  3626.             name =
  3627.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3628.                     name,
  3629.                     cp_ptr_name_check + 3,
  3630.                     cp_ptr_name_check + 4
  3631.                 )
  3632.             if (HortonBug == true) then
  3633.                 says("1 " .. name)
  3634.             end
  3635.         end
  3636.         local cp_ptr_name_check, _, _ = string.find(name, " %(")
  3637.         if (cp_ptr_name_check ~= nil) then
  3638.             name =
  3639.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3640.                     name,
  3641.                     cp_ptr_name_check + 2,
  3642.                     cp_ptr_name_check + 3
  3643.                 )
  3644.             if (HortonBug == true) then
  3645.                 says("2 " .. name)
  3646.             end
  3647.         end
  3648.         local cp_ptr_name_check, _, _ = string.find(name, "%(")
  3649.         if (cp_ptr_name_check ~= nil) then
  3650.             name =
  3651.                 string.sub(name, 1, cp_ptr_name_check - 1) .. string.sub(
  3652.                     name,
  3653.                     cp_ptr_name_check + 1,
  3654.                     cp_ptr_name_check + 2
  3655.                 )
  3656.             if (HortonBug == true) then
  3657.                 says("3 " .. name)
  3658.             end
  3659.         end
  3660.     end
  3661.     return name
  3662. end
  3663.  
  3664.  
  3665. -- this function not correctly setup.. in fact the mini window isn't setup {acutally i5 is but hidden and off screen}
  3666. function CensusPlus_Mini_OnMouseDown(
  3667. self,
  3668.     mCP_button -- referenced by CensusPlusClassic.xml
  3669. )
  3670.     if ((not self.isLocked or (self.isLocked == 0)) and (mCP_button == "LeftButton")) then
  3671.         self:StartMoving()
  3672.         self.isMoving = true
  3673.     end
  3674. end
  3675.  
  3676. -- referenced by CensusPlusClassic.xml
  3677. function CensusPlus_Census_OnMouseDown(self, CP_button)
  3678.     if (not self.isLocked or (self.isLocked == 0)) then
  3679.         self:StartMoving()
  3680.         self.isMoving = true
  3681.     end
  3682. end
  3683.  
  3684. function CensusPlusBlizzardOptions()
  3685.     -- Create main frame for information text
  3686.     CensusPlusOptions = CreateFrame("FRAME", "CensusPlusOptions")
  3687.     CensusPlusOptions.name = GetAddOnMetadata("CensusPlusClassic", "Title")
  3688.     CensusPlusOptions.default = function(self)
  3689.         CensusPlus_ResetConfig()
  3690.     end
  3691.     CensusPlusOptions.refresh = function(self)
  3692.         CensusPlusSetCheckButtonState()
  3693.     end
  3694.     CensusPlusOptions.cancel = function(self)
  3695.         CensusPlusRestoreSettings()
  3696.     end
  3697.     CensusPlusOptions.okay = function(self)
  3698.         CensusPlusCloseOptions()
  3699.     end
  3700.     InterfaceOptions_AddCategory(CensusPlusOptions)
  3701.  
  3702.     -- Create Title frame
  3703.     CensusPlusOptionsHeader = CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  3704.     CensusPlusOptionsHeader:SetFontObject(GameFontNormalLarge)
  3705.     CensusPlusOptionsHeader:SetJustifyH("LEFT")
  3706.     CensusPlusOptionsHeader:SetJustifyV("TOP")
  3707.     CensusPlusOptionsHeader:ClearAllPoints()
  3708.     CensusPlusOptionsHeader:SetPoint("TOPLEFT", 16, -16)
  3709.     CensusPlusOptionsHeader:SetText(
  3710.         "CensusClassic v" .. CensusPlus_VERSION_FULL
  3711.     )
  3712.  
  3713.     -- Create Top Text frame (section 1 header)
  3714.     CensusPlusOptionsWL = CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  3715.     CensusPlusOptionsWL:SetFontObject(GameFontWhite)
  3716.     CensusPlusOptionsWL:SetJustifyH("LEFT")
  3717.     CensusPlusOptionsWL:SetJustifyV("TOP")
  3718.     CensusPlusOptionsWL:ClearAllPoints()
  3719.     CensusPlusOptionsWL:SetPoint(
  3720.         "TOPLEFT",
  3721.         CensusPlusOptionsHeader,
  3722.         "BOTTOMLEFT",
  3723.         14,
  3724.         -6
  3725.     )
  3726.     CensusPlusOptionsWL:SetText(
  3727.         CENSUSPLUS_ACCOUNT_WIDE .. " " .. CENSUSPLUS_BUTTON_OPTIONS
  3728.     )
  3729.  
  3730.     -- Create Top Text frame (section 1 header)
  3731.     CensusPlusOptionsWR = CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  3732.     CensusPlusOptionsWR:SetFontObject(GameFontWhite)
  3733.     CensusPlusOptionsWR:SetJustifyH("LEFT")
  3734.     CensusPlusOptionsWR:SetJustifyV("TOP")
  3735.     CensusPlusOptionsWR:ClearAllPoints()
  3736.     CensusPlusOptionsWR:SetPoint(
  3737.         "TOPLEFT",
  3738.         CensusPlusOptionsWL,
  3739.         "TOPRIGHT",
  3740.         100,
  3741.         0
  3742.     )
  3743.     CensusPlusOptionsWR:SetText(CENSUSPLUS_CCO_OPTIONOVERRIDES)
  3744.  
  3745.     --Create Frame CheckButton (Verbose)
  3746.     CensusPlusCheckButton1 =
  3747.         CreateFrame(
  3748.             "CheckButton",
  3749.             "CensusPlusCheckButton1",
  3750.             CensusPlusOptions,
  3751.             "OptionsCheckButtonTemplate"
  3752.         )
  3753.     CensusPlusCheckButton1:SetPoint(
  3754.         "TOPLEFT",
  3755.         CensusPlusOptionsWL,
  3756.         "BOTTOMLEFT",
  3757.         2,
  3758.         -10
  3759.     )
  3760.     CensusPlusCheckButton1:SetScript("OnClick", function(self)
  3761.         local g_AW_Verbose = CensusPlusCheckButton1:GetChecked()
  3762.         --print("CB1 = ".. g_AW_Verbose)
  3763.         if g_AW_Verbose then
  3764.             CensusPlus_Database["Info"]["Verbose"] = true
  3765.             CensusPlus_Database["Info"]["Stealth"] = false
  3766.             CensusPlusCheckButton2:SetChecked(false)
  3767.             CensusPlus_Stealth(self)
  3768.         else
  3769.             CensusPlus_Database["Info"]["Verbose"] = false
  3770.         end
  3771.         CensusPlus_Verbose(self)
  3772.     end)
  3773.     CensusPlusCheckButton1Text:SetText(CENSUS_OPTIONS_VERBOSE)
  3774.     CensusPlusCheckButton1.tooltipText = CENSUS_OPTIONS_VERBOSE_TOOLTIP
  3775.  
  3776.     --Create Frame tri-selector button (CO - Verbose - enable)
  3777.     CensusPlusOptionsRadioButton_C1a =
  3778.         CreateFrame(
  3779.             "CheckButton",
  3780.             "CensusPlusOptionsRadioButton_C1a",
  3781.             CensusPlusOptions,
  3782.             "UIRadioButtonTemplate"
  3783.         )
  3784.     CensusPlusOptionsRadioButton_C1a:SetHeight(20)
  3785.     CensusPlusOptionsRadioButton_C1a:SetWidth(20)
  3786.     CensusPlusOptionsRadioButton_C1a:SetHitRectInsets(0, -5, 0, 0)
  3787.     CensusPlusOptionsRadioButton_C1a:ClearAllPoints()
  3788.     CensusPlusOptionsRadioButton_C1a:SetPoint(
  3789.         "TOPLEFT",
  3790.         CensusPlusCheckButton1,
  3791.         "TOPRIGHT",
  3792.         210,
  3793.         0
  3794.     )
  3795.     CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  3796.     CensusPlusOptionsRadioButton_C1a:SetScript("OnEnter", function(self)
  3797.         if self.tooltipText then
  3798.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  3799.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  3800.         end
  3801.         if self.tooltipRequirement then
  3802.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  3803.             GameTooltip:Show()
  3804.         end
  3805.     end)
  3806.     CensusPlusOptionsRadioButton_C1a:SetScript("OnLeave", function(self)
  3807.         GameTooltip:Hide()
  3808.     end)
  3809.     CensusPlusOptionsRadioButton_C1a:SetScript("OnClick", function(self)
  3810.         local g_CO_Verbose = CensusPlusOptionsRadioButton_C1a:GetChecked()
  3811.         if g_CO_Verbose then
  3812.             CensusPlusOptionsRadioButton_C1b:SetChecked(false)
  3813.             CensusPlusOptionsRadioButton_C1c:SetChecked(false)
  3814.             CensusPlus_PerCharInfo["Verbose"] = true
  3815.             CensusPlus_PerCharInfo["Stealth"] = false
  3816.             CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  3817.             CensusPlusOptionsRadioButton_C2b:SetChecked(true)
  3818.             CensusPlusOptionsRadioButton_C2c:SetChecked(false)
  3819.             CensusPlus_Stealth(self)
  3820.         elseif not CensusPlusOptionsRadioButton_C1b:GetChecked() then
  3821.             CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  3822.             CensusPlus_PerCharInfo["Verbose"] = nil
  3823.         end
  3824.         CensusPlus_Verbose(self)
  3825.     end)
  3826.     CensusPlusOptionsRadioButton_C1a.tooltipText = ENABLE
  3827.  
  3828.     --Create Frame tri-selector button (CO - Verbose - disable)
  3829.     CensusPlusOptionsRadioButton_C1b =
  3830.         CreateFrame(
  3831.             "CheckButton",
  3832.             "CensusPlusOptionsRadioButton_C1b",
  3833.             CensusPlusOptions,
  3834.             "UIRadioButtonTemplate"
  3835.         )
  3836.     CensusPlusOptionsRadioButton_C1b:SetHeight(20)
  3837.     CensusPlusOptionsRadioButton_C1b:SetWidth(20)
  3838.     CensusPlusOptionsRadioButton_C1b:SetHitRectInsets(0, -5, 0, 0)
  3839.     CensusPlusOptionsRadioButton_C1b:ClearAllPoints()
  3840.     CensusPlusOptionsRadioButton_C1b:SetPoint(
  3841.         "TOPLEFT",
  3842.         CensusPlusOptionsRadioButton_C1a,
  3843.         "TOPRIGHT",
  3844.         20,
  3845.         0
  3846.     )
  3847.     CensusPlusOptionsRadioButton_C1b:SetChecked(false)
  3848.     CensusPlusOptionsRadioButton_C1b:SetScript("OnEnter", function(self)
  3849.         if self.tooltipText then
  3850.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  3851.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  3852.         end
  3853.         if self.tooltipRequirement then
  3854.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  3855.             GameTooltip:Show()
  3856.         end
  3857.     end)
  3858.     CensusPlusOptionsRadioButton_C1b:SetScript("OnLeave", function(self)
  3859.         GameTooltip:Hide()
  3860.     end)
  3861.     CensusPlusOptionsRadioButton_C1b:SetScript("OnClick", function(self)
  3862.         local g_CO_Verbose = CensusPlusOptionsRadioButton_C1b:GetChecked()
  3863.         if g_CO_Verbose then
  3864.             CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  3865.             CensusPlusOptionsRadioButton_C1c:SetChecked(false)
  3866.             CensusPlus_PerCharInfo["Verbose"] = false --if (not(CensusPlusOptionsRadioButton_C1a:GetChecked()))then
  3867.         else
  3868.             CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  3869.             CensusPlus_PerCharInfo["Verbose"] = nil
  3870.             if CensusPlusOptionsRadioButton_C2a:GetChecked() then
  3871.                 CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  3872.                 CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  3873.                 CensusPlus_PerCharInfo["Stealth"] = nil
  3874.                 CensusPlus_Stealth(self)
  3875.             end
  3876.         end
  3877.         CensusPlus_Verbose(self)
  3878.     end)
  3879.     CensusPlusOptionsRadioButton_C1b.tooltipText = DISABLE
  3880.  
  3881.     --Create Frame tri-selector button (CO - Verbose - remove)
  3882.     CensusPlusOptionsRadioButton_C1c =
  3883.         CreateFrame(
  3884.             "CheckButton",
  3885.             "CensusPlusOptionsRadioButton_C1c",
  3886.             CensusPlusOptions,
  3887.             "UIRadioButtonTemplate"
  3888.         )
  3889.     CensusPlusOptionsRadioButton_C1c:SetHeight(20)
  3890.     CensusPlusOptionsRadioButton_C1c:SetWidth(20)
  3891.     CensusPlusOptionsRadioButton_C1c:SetHitRectInsets(0, -5, 0, 0)
  3892.     CensusPlusOptionsRadioButton_C1c:ClearAllPoints()
  3893.     CensusPlusOptionsRadioButton_C1c:SetPoint(
  3894.         "TOPLEFT",
  3895.         CensusPlusOptionsRadioButton_C1b,
  3896.         "TOPRIGHT",
  3897.         20,
  3898.         0
  3899.     )
  3900.     CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  3901.     _G[CensusPlusOptionsRadioButton_C1c:GetName() .. "Text"]:SetText(
  3902.         CENSUS_OPTIONS_VERBOSE .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  3903.     )
  3904.     CensusPlusOptionsRadioButton_C1c:SetScript("OnEnter", function(self)
  3905.         if self.tooltipText then
  3906.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  3907.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  3908.         end
  3909.         if self.tooltipRequirement then
  3910.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  3911.             GameTooltip:Show()
  3912.         end
  3913.     end)
  3914.     CensusPlusOptionsRadioButton_C1c:SetScript("OnLeave", function(self)
  3915.         GameTooltip:Hide()
  3916.     end)
  3917.     CensusPlusOptionsRadioButton_C1c:SetScript("OnClick", function(self)
  3918.         local g_CO_Verbose = CensusPlusOptionsRadioButton_C1c:GetChecked()
  3919.         if g_CO_Verbose then
  3920.             CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  3921.             CensusPlusOptionsRadioButton_C1b:SetChecked(false)
  3922.             CensusPlus_PerCharInfo["Verbose"] = nil
  3923.             if (CensusPlusCheckButton1:GetChecked() and CensusPlusOptionsRadioButton_C2a:GetChecked()) then
  3924.                 CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  3925.                 CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  3926.                 CensusPlus_PerCharInfo["Stealth"] = false
  3927.                 CensusPlus_Stealth(self)
  3928.             end
  3929.         elseif not (CensusPlusOptionsRadioButton_C1a:GetChecked() or CensusPlusOptionsRadioButton_C1b:GetChecked()) then
  3930.             CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  3931.             CensusPlus_PerCharInfo["Verbose"] = nil
  3932.         end
  3933.         CensusPlus_Verbose(self)
  3934.     end)
  3935.     CensusPlusOptionsRadioButton_C1c.tooltipText =
  3936.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  3937.  
  3938.     --Create Frame enable Stealth Mode
  3939.     CensusPlusCheckButton2 =
  3940.         CreateFrame(
  3941.             "CheckButton",
  3942.             "CensusPlusCheckButton2",
  3943.             CensusPlusOptions,
  3944.             "OptionsCheckButtonTemplate"
  3945.         )
  3946.     CensusPlusCheckButton2:SetPoint(
  3947.         "TOPLEFT",
  3948.         CensusPlusCheckButton1,
  3949.         "BOTTOMLEFT",
  3950.         0,
  3951.         -4
  3952.     )
  3953.     CensusPlusCheckButton2:SetScript("OnClick", function(self)
  3954.         local g_AW_Stealth = CensusPlusCheckButton2:GetChecked()
  3955.         if g_AW_Stealth then
  3956.             CensusPlus_Database["Info"]["Stealth"] = true
  3957.             CensusPlus_Database["Info"]["Verbose"] = false
  3958.             CensusPlusCheckButton1:SetChecked(false)
  3959.             CensusPlus_Verbose(self)
  3960.         else
  3961.             CensusPlus_Database["Info"]["Stealth"] = false
  3962.         end
  3963.         CensusPlus_Stealth(self)
  3964.     end)
  3965.     CensusPlusCheckButton2Text:SetText(CENSUS_OPTIONS_STEALTH)
  3966.     CensusPlusCheckButton2.tooltipText = CENSUS_OPTIONS_STEALTH_TOOLTIP
  3967.  
  3968.     --Create Frame tri-selector button (CO - Stealth - enable)
  3969.     CensusPlusOptionsRadioButton_C2a =
  3970.         CreateFrame(
  3971.             "CheckButton",
  3972.             "CensusPlusOptionsRadioButton_C2a",
  3973.             CensusPlusOptions,
  3974.             "UIRadioButtonTemplate"
  3975.         )
  3976.     CensusPlusOptionsRadioButton_C2a:SetHeight(20)
  3977.     CensusPlusOptionsRadioButton_C2a:SetWidth(20)
  3978.     CensusPlusOptionsRadioButton_C2a:SetHitRectInsets(0, -5, 0, 0)
  3979.     CensusPlusOptionsRadioButton_C2a:ClearAllPoints()
  3980.     CensusPlusOptionsRadioButton_C2a:SetPoint(
  3981.         "TOPLEFT",
  3982.         CensusPlusCheckButton2,
  3983.         "TOPRIGHT",
  3984.         210,
  3985.         0
  3986.     )
  3987.     CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  3988.     CensusPlusOptionsRadioButton_C2a:SetScript("OnEnter", function(self)
  3989.         if self.tooltipText then
  3990.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  3991.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  3992.         end
  3993.         if self.tooltipRequirement then
  3994.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  3995.             GameTooltip:Show()
  3996.         end
  3997.     end)
  3998.     CensusPlusOptionsRadioButton_C2a:SetScript("OnLeave", function(self)
  3999.         GameTooltip:Hide()
  4000.     end)
  4001.     CensusPlusOptionsRadioButton_C2a:SetScript("OnClick", function(self)
  4002.         local g_CO_Stealth = CensusPlusOptionsRadioButton_C2a:GetChecked()
  4003.         if g_CO_Stealth then
  4004.             CensusPlusOptionsRadioButton_C2b:SetChecked(false)
  4005.             CensusPlusOptionsRadioButton_C2c:SetChecked(false)
  4006.             CensusPlus_PerCharInfo["Stealth"] = true
  4007.             CensusPlus_PerCharInfo["Verbose"] = false
  4008.             CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  4009.             CensusPlusOptionsRadioButton_C1b:SetChecked(true)
  4010.             CensusPlusOptionsRadioButton_C1c:SetChecked(false)
  4011.             CensusPlus_Verbose(self)
  4012.         elseif not CensusPlusOptionsRadioButton_C2b:GetChecked() then
  4013.             CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  4014.             CensusPlus_PerCharInfo["Stealth"] = nil
  4015.         end
  4016.         CensusPlus_Stealth(self)
  4017.     end)
  4018.     CensusPlusOptionsRadioButton_C2a.tooltipText = ENABLE
  4019.  
  4020.     --Create Frame tri-selector button (CO - Stealth - disable)
  4021.     CensusPlusOptionsRadioButton_C2b =
  4022.         CreateFrame(
  4023.             "CheckButton",
  4024.             "CensusPlusOptionsRadioButton_C2b",
  4025.             CensusPlusOptions,
  4026.             "UIRadioButtonTemplate"
  4027.         )
  4028.     CensusPlusOptionsRadioButton_C2b:SetHeight(20)
  4029.     CensusPlusOptionsRadioButton_C2b:SetWidth(20)
  4030.     CensusPlusOptionsRadioButton_C2b:SetHitRectInsets(0, -5, 0, 0)
  4031.     CensusPlusOptionsRadioButton_C2b:ClearAllPoints()
  4032.     CensusPlusOptionsRadioButton_C2b:SetPoint(
  4033.         "TOPLEFT",
  4034.         CensusPlusOptionsRadioButton_C2a,
  4035.         "TOPRIGHT",
  4036.         20,
  4037.         0
  4038.     )
  4039.     CensusPlusOptionsRadioButton_C2b:SetChecked(false)
  4040.     CensusPlusOptionsRadioButton_C2b:SetScript("OnEnter", function(self)
  4041.         if self.tooltipText then
  4042.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4043.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4044.         end
  4045.         if self.tooltipRequirement then
  4046.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4047.             GameTooltip:Show()
  4048.         end
  4049.     end)
  4050.     CensusPlusOptionsRadioButton_C2b:SetScript("OnLeave", function(self)
  4051.         GameTooltip:Hide()
  4052.     end)
  4053.     CensusPlusOptionsRadioButton_C2b:SetScript("OnClick", function(self)
  4054.         local g_CO_Stealth = CensusPlusOptionsRadioButton_C2b:GetChecked()
  4055.         if g_CO_Stealth then
  4056.             CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  4057.             CensusPlusOptionsRadioButton_C2c:SetChecked(false)
  4058.             CensusPlus_PerCharInfo["Stealth"] = false --if(not(CensusPlusOptionsRadioButton_C2a:GetChecked()) )then
  4059.         else
  4060.             CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  4061.             CensusPlus_PerCharInfo["Stealth"] = nil
  4062.             if CensusPlusOptionsRadioButton_C1a:GetChecked() then
  4063.                 CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  4064.                 CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  4065.                 CensusPlus_PerCharInfo["Verbose"] = nil
  4066.                 CensusPlus_Verbose(self)
  4067.             end
  4068.         end
  4069.         CensusPlus_Stealth(self)
  4070.     end)
  4071.     CensusPlusOptionsRadioButton_C2b.tooltipText = DISABLE
  4072.  
  4073.     --Create Frame tri-selector button (CO - Stealth - remove)
  4074.     CensusPlusOptionsRadioButton_C2c =
  4075.         CreateFrame(
  4076.             "CheckButton",
  4077.             "CensusPlusOptionsRadioButton_C2c",
  4078.             CensusPlusOptions,
  4079.             "UIRadioButtonTemplate"
  4080.         )
  4081.     CensusPlusOptionsRadioButton_C2c:SetHeight(20)
  4082.     CensusPlusOptionsRadioButton_C2c:SetWidth(20)
  4083.     CensusPlusOptionsRadioButton_C2c:SetHitRectInsets(0, -5, 0, 0)
  4084.     CensusPlusOptionsRadioButton_C2c:ClearAllPoints()
  4085.     CensusPlusOptionsRadioButton_C2c:SetPoint(
  4086.         "TOPLEFT",
  4087.         CensusPlusOptionsRadioButton_C2b,
  4088.         "TOPRIGHT",
  4089.         20,
  4090.         0
  4091.     )
  4092.     CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  4093.     _G[CensusPlusOptionsRadioButton_C2c:GetName() .. "Text"]:SetText(
  4094.         CENSUS_OPTIONS_STEALTH .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  4095.     )
  4096.     CensusPlusOptionsRadioButton_C2c:SetScript("OnEnter", function(self)
  4097.         if self.tooltipText then
  4098.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4099.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4100.         end
  4101.         if self.tooltipRequirement then
  4102.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4103.             GameTooltip:Show()
  4104.         end
  4105.     end)
  4106.     CensusPlusOptionsRadioButton_C2c:SetScript("OnLeave", function(self)
  4107.         GameTooltip:Hide()
  4108.     end)
  4109.     CensusPlusOptionsRadioButton_C2c:SetScript("OnClick", function(self)
  4110.         local g_CO_Stealth = CensusPlusOptionsRadioButton_C2c:GetChecked()
  4111.         if g_CO_Stealth then
  4112.             CensusPlusOptionsRadioButton_C2b:SetChecked(false)
  4113.             CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  4114.             CensusPlus_PerCharInfo["Stealth"] = nil
  4115.             if (CensusPlusCheckButton2:GetChecked() and CensusPlusOptionsRadioButton_C1a:GetChecked()) then
  4116.                 CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  4117.                 CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  4118.                 CensusPlus_PerCharInfo["Verbose"] = nil
  4119.                 CensusPlus_Verbose(self)
  4120.             end
  4121.             --CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  4122.         elseif not (CensusPlusOptionsRadioButton_C2a:GetChecked() or CensusPlusOptionsRadioButton_C2b:GetChecked()) then
  4123.             CensusPlus_PerCharInfo["Stealth"] = nil
  4124.         end
  4125.         CensusPlus_Stealth(self)
  4126.     end)
  4127.     CensusPlusOptionsRadioButton_C2c.tooltipText =
  4128.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  4129.  
  4130.     --Create Frame enable Census Button
  4131.     CensusPlusCheckButton3 =
  4132.         CreateFrame(
  4133.             "CheckButton",
  4134.             "CensusPlusCheckButton3",
  4135.             CensusPlusOptions,
  4136.             "OptionsCheckButtonTemplate"
  4137.         )
  4138.     CensusPlusCheckButton3:SetPoint(
  4139.         "TOPLEFT",
  4140.         CensusPlusCheckButton2,
  4141.         "BOTTOMLEFT",
  4142.         2,
  4143.         -4
  4144.     )
  4145.    
  4146.     --CensusPlusOptionsWMZ
  4147.     CensusPlusCheckButton3:SetScript("OnClick", function(self)
  4148.         local g_AW_CensusButtonShown = CensusPlusCheckButton3:GetChecked()
  4149.         if g_AW_CensusButtonShown then
  4150.             CensusPlus_Database["Info"]["CensusButtonShown"] = true
  4151.         else
  4152.             CensusPlus_Database["Info"]["CensusButtonShown"] = false
  4153.             CensusPlus_Database["Info"]["CensusButtonAnimi"] = false
  4154.             CensusPlusCheckButton4:SetChecked(false)
  4155.             CensusPlus_CensusButtonAnimi(self)
  4156.         end
  4157.         CensusPlus_CensusButtonShown(self)
  4158.     end)
  4159.     CensusPlusCheckButton3Text:SetText(CENSUS_OPTIONS_BUTSHOW)
  4160.     CensusPlusCheckButton3.tooltipText = CENSUS_OPTIONS_BUTSHOW
  4161.  
  4162.     -- Create Frame tri-selector button (CO - CensusPlusClassic Button - enable)
  4163.     CensusPlusOptionsRadioButton_C3a =
  4164.         CreateFrame(
  4165.             "CheckButton",
  4166.             "CensusPlusOptionsRadioButton_C3a",
  4167.             CensusPlusOptions,
  4168.             "UIRadioButtonTemplate"
  4169.         )
  4170.     CensusPlusOptionsRadioButton_C3a:SetHeight(20)
  4171.     CensusPlusOptionsRadioButton_C3a:SetWidth(20)
  4172.     CensusPlusOptionsRadioButton_C3a:SetHitRectInsets(0, -5, 0, 0)
  4173.     CensusPlusOptionsRadioButton_C3a:ClearAllPoints()
  4174.     CensusPlusOptionsRadioButton_C3a:SetPoint(
  4175.         "TOPLEFT",
  4176.         CensusPlusCheckButton3,
  4177.         "TOPRIGHT",
  4178.         210,
  4179.         0
  4180.     )
  4181.     CensusPlusOptionsRadioButton_C3a:SetChecked(false)
  4182.     CensusPlusOptionsRadioButton_C3a:SetScript("OnEnter", function(self)
  4183.         if self.tooltipText then
  4184.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4185.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4186.         end
  4187.         if self.tooltipRequirement then
  4188.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4189.             GameTooltip:Show()
  4190.         end
  4191.     end)
  4192.     CensusPlusOptionsRadioButton_C3a:SetScript("OnLeave", function(self)
  4193.         GameTooltip:Hide()
  4194.     end)
  4195.     CensusPlusOptionsRadioButton_C3a:SetScript("OnClick", function(self)
  4196.         local g_CO_CensusButtonShown =
  4197.             CensusPlusOptionsRadioButton_C3a:GetChecked()
  4198.         if g_CO_CensusButtonShown then
  4199.             CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  4200.             CensusPlusOptionsRadioButton_C3c:SetChecked(false)
  4201.             CensusPlus_PerCharInfo["CensusButtonShown"] = true -- if (not(CensusPlusOptionsRadioButton_C3b:GetChecked()) )then
  4202.         else
  4203.             CensusPlusOptionsRadioButton_C3c:SetChecked(true)
  4204.             CensusPlus_PerCharInfo["CensusButtonShown"] = nil
  4205.             if CensusPlusOptionsRadioButton_C4a:GetChecked() then
  4206.                 CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  4207.                 CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  4208.                 CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  4209.                 CensusPlus_CensusButtonAnimi(self)
  4210.             end
  4211.         end
  4212.         CensusPlus_CensusButtonShown(self)
  4213.     end)
  4214.     CensusPlusOptionsRadioButton_C3a.tooltipText = ENABLE
  4215.  
  4216.     --Create Frame tri-selector button (CO - CensusPlusClassic Button - disable)
  4217.     CensusPlusOptionsRadioButton_C3b =
  4218.         CreateFrame(
  4219.             "CheckButton",
  4220.             "CensusPlusOptionsRadioButton_C3b",
  4221.             CensusPlusOptions,
  4222.             "UIRadioButtonTemplate"
  4223.         )
  4224.     CensusPlusOptionsRadioButton_C3b:SetHeight(20)
  4225.     CensusPlusOptionsRadioButton_C3b:SetWidth(20)
  4226.     CensusPlusOptionsRadioButton_C3b:SetHitRectInsets(0, -5, 0, 0)
  4227.     CensusPlusOptionsRadioButton_C3b:ClearAllPoints()
  4228.     CensusPlusOptionsRadioButton_C3b:SetPoint(
  4229.         "TOPLEFT",
  4230.         CensusPlusOptionsRadioButton_C3a,
  4231.         "TOPRIGHT",
  4232.         20,
  4233.         0
  4234.     )
  4235.     CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  4236.     CensusPlusOptionsRadioButton_C3b:SetScript("OnEnter", function(self)
  4237.         if self.tooltipText then
  4238.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4239.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4240.         end
  4241.         if self.tooltipRequirement then
  4242.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4243.             GameTooltip:Show()
  4244.         end
  4245.     end)
  4246.     CensusPlusOptionsRadioButton_C3b:SetScript("OnLeave", function(self)
  4247.         GameTooltip:Hide()
  4248.     end)
  4249.     CensusPlusOptionsRadioButton_C3b:SetScript("OnClick", function(self)
  4250.         local g_CO_CensusButtonShown =
  4251.             CensusPlusOptionsRadioButton_C3b:GetChecked()
  4252.         if g_CO_CensusButtonShown then
  4253.             CensusPlusOptionsRadioButton_C3a:SetChecked(false)
  4254.             CensusPlusOptionsRadioButton_C3c:SetChecked(false)
  4255.             CensusPlus_PerCharInfo["CensusButtonShown"] = false
  4256.             if (CensusPlusCheckButton4:GetChecked() or CensusPlusOptionsRadioButton_C4a:GetChecked()) then
  4257.                 CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  4258.                 CensusPlusOptionsRadioButton_C4b:SetChecked(true)
  4259.                 CensusPlusOptionsRadioButton_C4c:SetChecked(false)
  4260.                 CensusPlus_PerCharInfo["CensusButtonAnimi"] = false
  4261.                 CensusPlus_CensusButtonAnimi(self)
  4262.             end --if (not(CensusPlusOptionsRadioButton_C3a:GetChecked()) )then
  4263.         else
  4264.             CensusPlusOptionsRadioButton_C3c:SetChecked(true)
  4265.             CensusPlus_PerCharInfo["CensusButtonShown"] = nil
  4266.         end
  4267.         CensusPlus_CensusButtonShown(self)
  4268.     end)
  4269.     CensusPlusOptionsRadioButton_C3b.tooltipText = DISABLE
  4270.  
  4271.     --Create Frame tri-selector button (CO - CensusPlusClassic Button - remove)
  4272.     CensusPlusOptionsRadioButton_C3c =
  4273.         CreateFrame(
  4274.             "CheckButton",
  4275.             "CensusPlusOptionsRadioButton_C3c",
  4276.             CensusPlusOptions,
  4277.             "UIRadioButtonTemplate"
  4278.         )
  4279.     CensusPlusOptionsRadioButton_C3c:SetHeight(20)
  4280.     CensusPlusOptionsRadioButton_C3c:SetWidth(20)
  4281.     CensusPlusOptionsRadioButton_C3c:SetHitRectInsets(0, -5, 0, 0)
  4282.     CensusPlusOptionsRadioButton_C3c:ClearAllPoints()
  4283.     CensusPlusOptionsRadioButton_C3c:SetPoint(
  4284.         "TOPLEFT",
  4285.         CensusPlusOptionsRadioButton_C3b,
  4286.         "TOPRIGHT",
  4287.         20,
  4288.         0
  4289.     )
  4290.     CensusPlusOptionsRadioButton_C3c:SetChecked(true)
  4291.     _G[CensusPlusOptionsRadioButton_C3c:GetName() .. "Text"]:SetText(
  4292.         CENSUS_OPTIONS_BUTSHOW .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  4293.     )
  4294.     CensusPlusOptionsRadioButton_C3c:SetScript("OnEnter", function(self)
  4295.         if self.tooltipText then
  4296.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4297.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4298.         end
  4299.         if self.tooltipRequirement then
  4300.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4301.             GameTooltip:Show()
  4302.         end
  4303.     end)
  4304.     CensusPlusOptionsRadioButton_C3c:SetScript("OnLeave", function(self)
  4305.         GameTooltip:Hide()
  4306.     end)
  4307.     CensusPlusOptionsRadioButton_C3c:SetScript("OnClick", function(self)
  4308.         local g_CO_CensusButtonShown =
  4309.             CensusPlusOptionsRadioButton_C3c:GetChecked()
  4310.         if g_CO_CensusButtonShown then
  4311.             CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  4312.             CensusPlusOptionsRadioButton_C3a:SetChecked(false)
  4313.             CensusPlus_PerCharInfo["CensusButtonShown"] = nil
  4314.         elseif not (CensusPlusOptionsRadioButton_C3a:GetChecked() or CensusPlusOptionsRadioButton_C3b:GetChecked()) then
  4315.             CensusPlusOptionsRadioButton_C3c:SetChecked(true)
  4316.             CensusPlus_PerCharInfo["CensusButtonShown"] = nil
  4317.         end
  4318.         CensusPlus_CensusButtonShown(self)
  4319.     end)
  4320.     CensusPlusOptionsRadioButton_C3c.tooltipText =
  4321.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  4322.  
  4323.     --Create Frame CensusButton Animation
  4324.     CensusPlusCheckButton4 =
  4325.         CreateFrame(
  4326.             "CheckButton",
  4327.             "CensusPlusCheckButton4",
  4328.             CensusPlusOptions,
  4329.             "OptionsCheckButtonTemplate"
  4330.         )
  4331.     CensusPlusCheckButton4:SetPoint(
  4332.         "TOPLEFT",
  4333.         CensusPlusCheckButton3,
  4334.         "BOTTOMLEFT",
  4335.         0,
  4336.         -4
  4337.     )
  4338.     CensusPlusCheckButton4:SetScript("OnClick", function(self)
  4339.         local g_AWCensusButtonAnimi = CensusPlusCheckButton4:GetChecked()
  4340.         if g_AWCensusButtonAnimi then
  4341.             CensusPlus_Database["Info"]["CensusButtonAnimi"] = true
  4342.             CensusPlus_Database["Info"]["CensusButtonShown"] = true
  4343.             CensusPlusCheckButton3:SetChecked(true)
  4344.             CensusPlus_CensusButtonShown(self)
  4345.         else
  4346.             CensusPlus_Database["Info"]["CensusButtonAnimi"] = false
  4347.         end
  4348.         CensusPlus_CensusButtonAnimi(self)
  4349.     end)
  4350.     CensusPlusCheckButton4Text:SetText(CENSUSPLUS_CENSUSBUTTONANIMITEXT)
  4351.     CensusPlusCheckButton4.tooltipText =
  4352.         ENABLE .. " " .. CENSUSPLUS_CENSUSBUTTONANIMITEXT
  4353.  
  4354.     --Create Frame tri-selector button (CO - Census button animation - enable)
  4355.     CensusPlusOptionsRadioButton_C4a =
  4356.         CreateFrame(
  4357.             "CheckButton",
  4358.             "CensusPlusOptionsRadioButton_C4a",
  4359.             CensusPlusOptions,
  4360.             "UIRadioButtonTemplate"
  4361.         )
  4362.     CensusPlusOptionsRadioButton_C4a:SetHeight(20)
  4363.     CensusPlusOptionsRadioButton_C4a:SetWidth(20)
  4364.     CensusPlusOptionsRadioButton_C4a:SetHitRectInsets(0, -5, 0, 0)
  4365.     CensusPlusOptionsRadioButton_C4a:ClearAllPoints()
  4366.     CensusPlusOptionsRadioButton_C4a:SetPoint(
  4367.         "TOPLEFT",
  4368.         CensusPlusCheckButton4,
  4369.         "TOPRIGHT",
  4370.         210,
  4371.         0
  4372.     )
  4373.     CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  4374.     CensusPlusOptionsRadioButton_C4a:SetScript("OnEnter", function(self)
  4375.         if self.tooltipText then
  4376.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4377.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4378.         end
  4379.         if self.tooltipRequirement then
  4380.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4381.             GameTooltip:Show()
  4382.         end
  4383.     end)
  4384.     CensusPlusOptionsRadioButton_C4a:SetScript("OnLeave", function(self)
  4385.         GameTooltip:Hide()
  4386.     end)
  4387.     CensusPlusOptionsRadioButton_C4a:SetScript("OnClick", function(self)
  4388.         local g_CO_CPBAnimi = CensusPlusOptionsRadioButton_C4a:GetChecked()
  4389.         if g_CO_CPBAnimi then
  4390.             CensusPlusOptionsRadioButton_C4b:SetChecked(false)
  4391.             CensusPlusOptionsRadioButton_C4c:SetChecked(false)
  4392.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = true
  4393.             CensusPlusOptionsRadioButton_C3a:SetChecked(true)
  4394.             CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  4395.             CensusPlusOptionsRadioButton_C3c:SetChecked(false)
  4396.             CensusPlus_PerCharInfo["CensusButtonShown"] = true
  4397.             CensusPlus_CensusButtonShown(self)
  4398.         elseif not CensusPlusOptionsRadioButton_C4a:GetChecked() then
  4399.             CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  4400.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  4401.         end
  4402.         CensusPlus_CensusButtonAnimi(self)
  4403.     end)
  4404.     CensusPlusOptionsRadioButton_C4a.tooltipText = ENABLE
  4405.  
  4406.     --Create Frame tri-selector button (CO - Census button animation - disable)
  4407.     CensusPlusOptionsRadioButton_C4b =
  4408.         CreateFrame(
  4409.             "CheckButton",
  4410.             "CensusPlusOptionsRadioButton_C4b",
  4411.             CensusPlusOptions,
  4412.             "UIRadioButtonTemplate"
  4413.         )
  4414.     CensusPlusOptionsRadioButton_C4b:SetHeight(20)
  4415.     CensusPlusOptionsRadioButton_C4b:SetWidth(20)
  4416.     CensusPlusOptionsRadioButton_C4b:SetHitRectInsets(0, -5, 0, 0)
  4417.     CensusPlusOptionsRadioButton_C4b:ClearAllPoints()
  4418.     CensusPlusOptionsRadioButton_C4b:SetPoint(
  4419.         "TOPLEFT",
  4420.         CensusPlusOptionsRadioButton_C4a,
  4421.         "TOPRIGHT",
  4422.         20,
  4423.         0
  4424.     )
  4425.     CensusPlusOptionsRadioButton_C4b:SetChecked(false)
  4426.     CensusPlusOptionsRadioButton_C4b:SetScript("OnEnter", function(self)
  4427.         if self.tooltipText then
  4428.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4429.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4430.         end
  4431.         if self.tooltipRequirement then
  4432.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4433.             GameTooltip:Show()
  4434.         end
  4435.     end)
  4436.     CensusPlusOptionsRadioButton_C4b:SetScript("OnLeave", function(self)
  4437.         GameTooltip:Hide()
  4438.     end)
  4439.     CensusPlusOptionsRadioButton_C4b:SetScript("OnClick", function(self)
  4440.         local g_CO_CPBAnimi = CensusPlusOptionsRadioButton_C4b:GetChecked()
  4441.         if g_CO_CPBAnimi then
  4442.             CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  4443.             CensusPlusOptionsRadioButton_C4c:SetChecked(false)
  4444.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = false --if (not(CensusPlusOptionsRadioButton_C4a:GetChecked()))then
  4445.         else
  4446.             CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  4447.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  4448.         end
  4449.         CensusPlus_CensusButtonAnimi(self)
  4450.     end)
  4451.     CensusPlusOptionsRadioButton_C4b.tooltipText = DISABLE
  4452.  
  4453.     --Create Frame tri-selector button (CO - Census button animation - remove)
  4454.     CensusPlusOptionsRadioButton_C4c =
  4455.         CreateFrame(
  4456.             "CheckButton",
  4457.             "CensusPlusOptionsRadioButton_C4c",
  4458.             CensusPlusOptions,
  4459.             "UIRadioButtonTemplate"
  4460.         )
  4461.     CensusPlusOptionsRadioButton_C4c:SetHeight(20)
  4462.     CensusPlusOptionsRadioButton_C4c:SetWidth(20)
  4463.     CensusPlusOptionsRadioButton_C4c:SetHitRectInsets(0, -5, 0, 0)
  4464.     CensusPlusOptionsRadioButton_C4c:ClearAllPoints()
  4465.     CensusPlusOptionsRadioButton_C4c:SetPoint(
  4466.         "TOPLEFT",
  4467.         CensusPlusOptionsRadioButton_C4b,
  4468.         "TOPRIGHT",
  4469.         20,
  4470.         0
  4471.     )
  4472.     CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  4473.     _G[CensusPlusOptionsRadioButton_C4c:GetName() .. "Text"]:SetText(
  4474.         CENSUSPLUS_CENSUSBUTTONANIMITEXT .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  4475.     )
  4476.     CensusPlusOptionsRadioButton_C4c:SetScript("OnEnter", function(self)
  4477.         if self.tooltipText then
  4478.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4479.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4480.         end
  4481.         if self.tooltipRequirement then
  4482.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4483.             GameTooltip:Show()
  4484.         end
  4485.     end)
  4486.     CensusPlusOptionsRadioButton_C4c:SetScript("OnLeave", function(self)
  4487.         GameTooltip:Hide()
  4488.     end)
  4489.     CensusPlusOptionsRadioButton_C4c:SetScript("OnClick", function(self)
  4490.         local g_CO_CPBAnimi = CensusPlusOptionsRadioButton_C4c:GetChecked()
  4491.         if g_CO_CPBAnimi then
  4492.             CensusPlusOptionsRadioButton_C4b:SetChecked(false)
  4493.             CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  4494.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  4495.         elseif not (CensusPlusOptionsRadioButton_C4a:GetChecked() or CensusPlusOptionsRadioButton_C4b:GetChecked()) then
  4496.             CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  4497.             CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  4498.         end
  4499.         CensusPlus_CensusButtonAnimi(self)
  4500.     end)
  4501.     CensusPlusOptionsRadioButton_C4c.tooltipText =
  4502.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  4503.  
  4504.     -- Create Frame AutoCensus enable
  4505.     CensusPlusCheckButton5 =
  4506.         CreateFrame(
  4507.             "CheckButton",
  4508.             "CensusPlusCheckButton5",
  4509.             CensusPlusOptions,
  4510.             "OptionsCheckButtonTemplate"
  4511.         )
  4512.     CensusPlusCheckButton5:SetPoint(
  4513.         "TOPLEFT",
  4514.         CensusPlusCheckButton4,
  4515.         "BOTTOMLEFT",
  4516.         0,
  4517.         -4
  4518.     )
  4519.     CensusPlusCheckButton5:SetScript("OnClick", function(self)
  4520.         local g_AW_AutoCensus = CensusPlusCheckButton5:GetChecked()
  4521.         if g_AW_AutoCensus then
  4522.             CensusPlus_Database["Info"]["AutoCensus"] = true
  4523.         else
  4524.             CensusPlus_Database["Info"]["AutoCensus"] = false
  4525.             CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800
  4526.             if not CensusPlusOptionsRadioButton_C5a:GetChecked() then
  4527.                 CensusPlusSlider1:SetValue(15)
  4528.             end
  4529.         end
  4530.         CensusPlus_SetAutoCensus(self)
  4531.     end)
  4532.     CensusPlusCheckButton5Text:SetText(CENSUS_OPTIONS_AUTOCENSUS)
  4533.     CensusPlusCheckButton5.tooltipText = CENSUSPLUS_AUTOCENSUSTEXT
  4534.  
  4535.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_AUTOCENSUS - enable)
  4536.     CensusPlusOptionsRadioButton_C5a =
  4537.         CreateFrame(
  4538.             "CheckButton",
  4539.             "CensusPlusOptionsRadioButton_C5a",
  4540.             CensusPlusOptions,
  4541.             "UIRadioButtonTemplate"
  4542.         )
  4543.     CensusPlusOptionsRadioButton_C5a:SetHeight(20)
  4544.     CensusPlusOptionsRadioButton_C5a:SetWidth(20)
  4545.     CensusPlusOptionsRadioButton_C5a:SetHitRectInsets(0, -5, 0, 0)
  4546.     CensusPlusOptionsRadioButton_C5a:ClearAllPoints()
  4547.     CensusPlusOptionsRadioButton_C5a:SetPoint(
  4548.         "TOPLEFT",
  4549.         CensusPlusCheckButton5,
  4550.         "TOPRIGHT",
  4551.         210,
  4552.         0
  4553.     )
  4554.     CensusPlusOptionsRadioButton_C5a:SetChecked(false)
  4555.     CensusPlusOptionsRadioButton_C5a:SetScript("OnEnter", function(self)
  4556.         if self.tooltipText then
  4557.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4558.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4559.         end
  4560.         if self.tooltipRequirement then
  4561.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4562.             GameTooltip:Show()
  4563.         end
  4564.     end)
  4565.     CensusPlusOptionsRadioButton_C5a:SetScript("OnLeave", function(self)
  4566.         GameTooltip:Hide()
  4567.     end)
  4568.     CensusPlusOptionsRadioButton_C5a:SetScript("OnClick", function(self)
  4569.         local g_CO_CPAuto = CensusPlusOptionsRadioButton_C5a:GetChecked()
  4570.         if g_CO_CPAuto then
  4571.             CensusPlusOptionsRadioButton_C5b:SetChecked(false)
  4572.             CensusPlusOptionsRadioButton_C5c:SetChecked(false)
  4573.             CensusPlus_PerCharInfo["AutoCensus"] = true
  4574.             CensusPlus_PerCharInfo["AutoCensusTimer"] = 1800
  4575.             CensusPlusSlider1:SetValue(30)
  4576.             -- enable new override.. reset timer to 30 and disabled
  4577.             --print(CPp.AutoStartTimer) -- revert to AW settings
  4578.         elseif not CensusPlusOptionsRadioButton_C5b:GetChecked() then
  4579.             CensusPlusOptionsRadioButton_C5c:SetChecked(true)
  4580.             CensusPlus_PerCharInfo["AutoCensus"] = nil
  4581.             CensusPlus_PerCharInfo["AutoCensusTimer"] = 1800
  4582.             CensusPlusSlider1:SetValue(30)
  4583.             if CensusPlusCheckButton5:GetChecked() then
  4584.                 CensusPlusSlider1:SetValue(CensusPlus_Database["Info"]["AutoCensusTimer"] / 60)
  4585.             else
  4586.             end
  4587.         end
  4588.         CensusPlus_SetAutoCensus(self)
  4589.     end)
  4590.     CensusPlusOptionsRadioButton_C5a.tooltipText = ENABLE
  4591.  
  4592.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_AUTOCENSUS - disable)
  4593.     CensusPlusOptionsRadioButton_C5b =
  4594.         CreateFrame(
  4595.             "CheckButton",
  4596.             "CensusPlusOptionsRadioButton_C5b",
  4597.             CensusPlusOptions,
  4598.             "UIRadioButtonTemplate"
  4599.         )
  4600.     CensusPlusOptionsRadioButton_C5b:SetHeight(20)
  4601.     CensusPlusOptionsRadioButton_C5b:SetWidth(20)
  4602.     CensusPlusOptionsRadioButton_C5b:SetHitRectInsets(0, -5, 0, 0)
  4603.     CensusPlusOptionsRadioButton_C5b:ClearAllPoints()
  4604.     CensusPlusOptionsRadioButton_C5b:SetPoint(
  4605.         "TOPLEFT",
  4606.         CensusPlusOptionsRadioButton_C5a,
  4607.         "TOPRIGHT",
  4608.         20,
  4609.         0
  4610.     )
  4611.     CensusPlusOptionsRadioButton_C5b:SetChecked(false)
  4612.     CensusPlusOptionsRadioButton_C5b:SetScript("OnEnter", function(self)
  4613.         if self.tooltipText then
  4614.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4615.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4616.         end
  4617.         if self.tooltipRequirement then
  4618.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4619.             GameTooltip:Show()
  4620.         end
  4621.     end)
  4622.     CensusPlusOptionsRadioButton_C5b:SetScript("OnLeave", function(self)
  4623.         GameTooltip:Hide()
  4624.     end)
  4625.     CensusPlusOptionsRadioButton_C5b:SetScript("OnClick", function(self)
  4626.         local g_CO_CPAuto = CensusPlusOptionsRadioButton_C5b:GetChecked()
  4627.         if g_CO_CPAuto then
  4628.             CensusPlusOptionsRadioButton_C5a:SetChecked(false)
  4629.             CensusPlusOptionsRadioButton_C5c:SetChecked(false)
  4630.             CensusPlus_PerCharInfo["AutoCensus"] = false
  4631.             -- enable new override.. reset timer to 30 and disabled
  4632.             CensusPlus_PerCharInfo["AutoCensusTimer"] = 1800
  4633.             CensusPlusSlider1:SetValue(30)
  4634.             CPp.AutoStartText =
  4635.                 CPp.AutoStartTimer .. " " .. CENSUS_OPTIONS_AUTOSTART .. " " .. ADDON_DISABLED
  4636.         elseif not CensusPlusOptionsRadioButton_C5a:GetChecked() then
  4637.             CensusPlusOptionsRadioButton_C5c:SetChecked(true)
  4638.             CensusPlus_PerCharInfo["AutoCensus"] = nil
  4639.             if CensusPlusCheckButton5:GetChecked() then
  4640.                 CensusPlusSlider1:SetValue(CensusPlus_Database["Info"]["AutoCensusTimer"] / 60)
  4641.             end
  4642.         end
  4643.         CensusPlus_SetAutoCensus(self)
  4644.     end)
  4645.     CensusPlusOptionsRadioButton_C5b.tooltipText = DISABLE
  4646.  
  4647.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_AUTOCENSUS - remove)
  4648.     CensusPlusOptionsRadioButton_C5c =
  4649.         CreateFrame(
  4650.             "CheckButton",
  4651.             "CensusPlusOptionsRadioButton_C5c",
  4652.             CensusPlusOptions,
  4653.             "UIRadioButtonTemplate"
  4654.         )
  4655.     CensusPlusOptionsRadioButton_C5c:SetHeight(20)
  4656.     CensusPlusOptionsRadioButton_C5c:SetWidth(20)
  4657.     CensusPlusOptionsRadioButton_C5c:SetHitRectInsets(0, -5, 0, 0)
  4658.     CensusPlusOptionsRadioButton_C5c:ClearAllPoints()
  4659.     CensusPlusOptionsRadioButton_C5c:SetPoint(
  4660.         "TOPLEFT",
  4661.         CensusPlusOptionsRadioButton_C5b,
  4662.         "TOPRIGHT",
  4663.         20,
  4664.         0
  4665.     )
  4666.     CensusPlusOptionsRadioButton_C5c:SetChecked(true)
  4667.     _G[CensusPlusOptionsRadioButton_C5c:GetName() .. "Text"]:SetText(
  4668.         CENSUS_OPTIONS_AUTOCENSUS .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  4669.     )
  4670.     CensusPlusOptionsRadioButton_C5c:SetScript("OnEnter", function(self)
  4671.         if self.tooltipText then
  4672.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4673.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4674.         end
  4675.         if self.tooltipRequirement then
  4676.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4677.             GameTooltip:Show()
  4678.         end
  4679.     end)
  4680.     CensusPlusOptionsRadioButton_C5c:SetScript("OnLeave", function(self)
  4681.         GameTooltip:Hide()
  4682.     end)
  4683.     CensusPlusOptionsRadioButton_C5c:SetScript("OnClick", function(self)
  4684.         local g_CO_CPAuto = CensusPlusOptionsRadioButton_C5c:GetChecked()
  4685.         if g_CO_CPAuto then
  4686.             CensusPlusOptionsRadioButton_C5b:SetChecked(false)
  4687.             CensusPlusOptionsRadioButton_C5a:SetChecked(false)
  4688.             CensusPlus_PerCharInfo["AutoCensus"] = nil
  4689.             -- enable new override.. reset timer to 30 and disabled
  4690.             CensusPlus_PerCharInfo["AutoCensusTimer"] = 1800
  4691.             if CensusPlusCheckButton5:GetChecked() then
  4692.                 CensusPlusSlider1:SetValue(CensusPlus_Database["Info"]["AutoCensusTimer"] / 60)
  4693.             else
  4694.                 CensusPlusSlider1:SetValue(30)
  4695.             end
  4696.             CensusPlus_SetAutoCensus(self)
  4697.         end
  4698.     end)
  4699.     CensusPlusOptionsRadioButton_C5c.tooltipText =
  4700.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  4701.  
  4702.     --Create Frame Timer Slider
  4703.     CensusPlusSlider1 =
  4704.         CreateFrame(
  4705.             "Slider",
  4706.             "CensusPlusSlider1",
  4707.             CensusPlusOptions,
  4708.             "OptionsSliderTemplate"
  4709.         )
  4710.     CensusPlusSlider1:SetWidth(100)
  4711.     CensusPlusSlider1:SetHeight(20)
  4712.     CensusPlusSlider1:SetOrientation("HORIZONTAL")
  4713.     CensusPlusSlider1:SetMinMaxValues(5, 30)
  4714.     CensusPlusSlider1:SetObeyStepOnDrag(true)
  4715.     CensusPlusSlider1:SetValueStep(1)
  4716.     CensusPlusSlider1:SetValue(15)
  4717.     CensusPlusSlider1:SetThumbTexture(
  4718.         "Interface\\Buttons\\UI-SliderBar-Button-Horizontal"
  4719.     )
  4720.     CensusPlusSlider1:SetPoint(
  4721.         "TOPLEFT",
  4722.         CensusPlusCheckButton5,
  4723.         "BOTTOMLEFT",
  4724.         68,
  4725.         -8
  4726.     )
  4727.     CensusPlusSlider1:SetScript("OnValueChanged", function(self, value)
  4728.         CPp.AutoStartTimer = CensusPlusSlider1:GetValue()
  4729.     end)
  4730.     CensusPlusSlider1:SetScript("OnMouseUp", function(self, value)
  4731.         local value = CensusPlusSlider1:GetValue()
  4732.         local ovrride = false
  4733.         if CensusPlusOptionsRadioButton_C5a:GetChecked() then
  4734.             ovrride = true
  4735.         else
  4736.             ovrride = false
  4737.         end
  4738.         CensusPlus_TimerSet(self, value, ovrride)
  4739.     end)
  4740.     CensusPlusSlider1.tooltipText = CENSUS_OPTIONS_TIMER_TOOLTIP --Creates a tooltip on mouseover.
  4741.     _G[CensusPlusSlider1:GetName() .. "Low"]:SetText("5") --Sets the left-side slider text (default is "Low").
  4742.     _G[CensusPlusSlider1:GetName() .. "High"]:SetText("30") --Sets the right-side slider text (default is "High").
  4743.     _G[CensusPlusSlider1:GetName() .. "Text"]:SetText(
  4744.         CENSUSPLUS_AUTOCENSUS_DELAYTIME
  4745.     ) --Sets the "title" text (top-centre of slider).
  4746.     CensusPlusSlider1:Enable()
  4747.  
  4748.     --Create Frame Enable FinishSound
  4749.     CensusPlusCheckButton6 =
  4750.         CreateFrame(
  4751.             "CheckButton",
  4752.             "CensusPlusCheckButton6",
  4753.             CensusPlusOptions,
  4754.             "OptionsCheckButtonTemplate"
  4755.         )
  4756.     CensusPlusCheckButton6:SetPoint(
  4757.         "TOPLEFT",
  4758.         CensusPlusSlider1,
  4759.         "BOTTOMLEFT",
  4760.         -68,
  4761.         -12
  4762.     )
  4763.     CensusPlusCheckButton6:SetScript("OnClick", function(self)
  4764.         local g_AW_FinishSound = CensusPlusCheckButton6:GetChecked()
  4765.         if g_AW_FinishSound then
  4766.             CensusPlus_Database["Info"]["PlayFinishSound"] = true
  4767.         else
  4768.             CensusPlus_Database["Info"]["PlayFinishSound"] = false
  4769.         end
  4770.         CensusPlus_FinishSound(self)
  4771.     end)
  4772.     CensusPlusCheckButton6Text:SetText(CENSUS_OPTIONS_SOUND_ON_COMPLETE)
  4773.     CensusPlusCheckButton6.tooltipText = CENSUS_OPTIONS_SOUND_TOOLTIP
  4774.  
  4775.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_FinishSound- enable)
  4776.     CensusPlusOptionsRadioButton_C6a =
  4777.         CreateFrame(
  4778.             "CheckButton",
  4779.             "CensusPlusOptionsRadioButton_C6a",
  4780.             CensusPlusOptions,
  4781.             "UIRadioButtonTemplate"
  4782.         )
  4783.     CensusPlusOptionsRadioButton_C6a:SetHeight(20)
  4784.     CensusPlusOptionsRadioButton_C6a:SetWidth(20)
  4785.     CensusPlusOptionsRadioButton_C6a:SetHitRectInsets(0, -5, 0, 0)
  4786.     CensusPlusOptionsRadioButton_C6a:ClearAllPoints()
  4787.     CensusPlusOptionsRadioButton_C6a:SetPoint(
  4788.         "TOPLEFT",
  4789.         CensusPlusCheckButton6,
  4790.         "TOPRIGHT",
  4791.         210,
  4792.         0
  4793.     )
  4794.     CensusPlusOptionsRadioButton_C6a:SetChecked(false)
  4795.     CensusPlusOptionsRadioButton_C6a:SetScript("OnEnter", function(self)
  4796.         if self.tooltipText then
  4797.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4798.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4799.         end
  4800.         if self.tooltipRequirement then
  4801.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4802.             GameTooltip:Show()
  4803.         end
  4804.     end)
  4805.     CensusPlusOptionsRadioButton_C6a:SetScript("OnLeave", function(self)
  4806.         GameTooltip:Hide()
  4807.     end)
  4808.     CensusPlusOptionsRadioButton_C6a:SetScript("OnClick", function(self)
  4809.         local g_CO_CPSound = CensusPlusOptionsRadioButton_C6a:GetChecked()
  4810.         if g_CO_CPSound then
  4811.             CensusPlusOptionsRadioButton_C6b:SetChecked(false)
  4812.             CensusPlusOptionsRadioButton_C6c:SetChecked(false)
  4813.             CensusPlus_PerCharInfo["PlayFinishSound"] = true
  4814.         elseif not CensusPlusOptionsRadioButton_C6b:GetChecked() then
  4815.             CensusPlusOptionsRadioButton_C6c:SetChecked(true)
  4816.             CensusPlus_PerCharInfo["PlayFinishSound"] = nil
  4817.         end
  4818.         CensusPlus_FinishSound(self)
  4819.     end)
  4820.     CensusPlusOptionsRadioButton_C6a.tooltipText = ENABLE
  4821.  
  4822.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_FinishSound - disable)
  4823.     CensusPlusOptionsRadioButton_C6b =
  4824.         CreateFrame(
  4825.             "CheckButton",
  4826.             "CensusPlusOptionsRadioButton_C6b",
  4827.             CensusPlusOptions,
  4828.             "UIRadioButtonTemplate"
  4829.         )
  4830.     CensusPlusOptionsRadioButton_C6b:SetHeight(20)
  4831.     CensusPlusOptionsRadioButton_C6b:SetWidth(20)
  4832.     CensusPlusOptionsRadioButton_C6b:SetHitRectInsets(0, -5, 0, 0)
  4833.     CensusPlusOptionsRadioButton_C6b:ClearAllPoints()
  4834.     CensusPlusOptionsRadioButton_C6b:SetPoint(
  4835.         "TOPLEFT",
  4836.         CensusPlusOptionsRadioButton_C6a,
  4837.         "TOPRIGHT",
  4838.         20,
  4839.         0
  4840.     )
  4841.     CensusPlusOptionsRadioButton_C6b:SetChecked(false)
  4842.     CensusPlusOptionsRadioButton_C6b:SetScript("OnEnter", function(self)
  4843.         if self.tooltipText then
  4844.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4845.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4846.         end
  4847.         if self.tooltipRequirement then
  4848.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4849.             GameTooltip:Show()
  4850.         end
  4851.     end)
  4852.     CensusPlusOptionsRadioButton_C6b:SetScript("OnLeave", function(self)
  4853.         GameTooltip:Hide()
  4854.     end)
  4855.     CensusPlusOptionsRadioButton_C6b:SetScript("OnClick", function(self)
  4856.         local g_CO_CPSound = CensusPlusOptionsRadioButton_C6b:GetChecked()
  4857.         if g_CO_CPSound then
  4858.             CensusPlusOptionsRadioButton_C6a:SetChecked(false)
  4859.             CensusPlusOptionsRadioButton_C6c:SetChecked(false)
  4860.             CensusPlus_PerCharInfo["PlayFinishSound"] = false
  4861.         elseif not CensusPlusOptionsRadioButton_C6a:GetChecked() then
  4862.             CensusPlusOptionsRadioButton_C6c:SetChecked(true)
  4863.             CensusPlus_PerCharInfo["PlayFinishSound"] = nil
  4864.         end
  4865.         CensusPlus_FinishSound(self)
  4866.     end)
  4867.     CensusPlusOptionsRadioButton_C6b.tooltipText = DISABLE
  4868.  
  4869.     --Create Frame tri-selector button (CO - CENSUS_OPTIONS_FinishSound- remove)
  4870.     CensusPlusOptionsRadioButton_C6c =
  4871.         CreateFrame(
  4872.             "CheckButton",
  4873.             "CensusPlusOptionsRadioButton_C6c",
  4874.             CensusPlusOptions,
  4875.             "UIRadioButtonTemplate"
  4876.         )
  4877.     CensusPlusOptionsRadioButton_C6c:SetHeight(20)
  4878.     CensusPlusOptionsRadioButton_C6c:SetWidth(20)
  4879.     CensusPlusOptionsRadioButton_C6c:SetHitRectInsets(0, -5, 0, 0)
  4880.     CensusPlusOptionsRadioButton_C6c:ClearAllPoints()
  4881.     CensusPlusOptionsRadioButton_C6c:SetPoint(
  4882.         "TOPLEFT",
  4883.         CensusPlusOptionsRadioButton_C6b,
  4884.         "TOPRIGHT",
  4885.         20,
  4886.         0
  4887.     )
  4888.     CensusPlusOptionsRadioButton_C6c:SetChecked(true)
  4889.     _G[CensusPlusOptionsRadioButton_C6c:GetName() .. "Text"]:SetText(
  4890.         CENSUS_OPTIONS_SOUND_ON_COMPLETE .. " " .. CENSUSPLUS_OPTIONS_OVERRIDE
  4891.     )
  4892.     CensusPlusOptionsRadioButton_C6c:SetScript("OnEnter", function(self)
  4893.         if self.tooltipText then
  4894.             GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
  4895.             GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, 1)
  4896.         end
  4897.         if self.tooltipRequirement then
  4898.             GameTooltip:AddLine(self.tooltipRequirement, 1.0, 1.0, 1.0, 1.0)
  4899.             GameTooltip:Show()
  4900.         end
  4901.     end)
  4902.     CensusPlusOptionsRadioButton_C6c:SetScript("OnLeave", function(self)
  4903.         GameTooltip:Hide()
  4904.     end)
  4905.     CensusPlusOptionsRadioButton_C6c:SetScript("OnClick", function(self)
  4906.         local g_CO_CPSound = CensusPlusOptionsRadioButton_C6c:GetChecked()
  4907.         if g_CO_CPSound then
  4908.             CensusPlusOptionsRadioButton_C6b:SetChecked(false)
  4909.             CensusPlusOptionsRadioButton_C6a:SetChecked(false)
  4910.             CensusPlus_PerCharInfo["PlayFinishSound"] = nil
  4911.         elseif not (CensusPlusOptionsRadioButton_C6a:GetChecked() or CensusPlusOptionsRadioButton_C6b:GetChecked()) then
  4912.             CensusPlusOptionsRadioButton_C6c:SetChecked(true)
  4913.             CensusPlus_PerCharInfo["PlayFinishSound"] = nil
  4914.         end
  4915.         CensusPlus_FinishSound(self)
  4916.     end)
  4917.     CensusPlusOptionsRadioButton_C6c.tooltipText =
  4918.         CENSUS_OPTIONS_CCO_REMOVE_OVERRIDE
  4919.  
  4920.     --Create Frame SoundFilesHeader
  4921.     CensusPlusOptionsSoundFilesHeader =
  4922.         CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  4923.     CensusPlusOptionsSoundFilesHeader:SetFontObject(GameFontWhite)
  4924.     CensusPlusOptionsSoundFilesHeader:SetJustifyH("LEFT")
  4925.     CensusPlusOptionsSoundFilesHeader:SetJustifyV("TOP")
  4926.     CensusPlusOptionsSoundFilesHeader:ClearAllPoints()
  4927.     CensusPlusOptionsSoundFilesHeader:SetPoint(
  4928.         "TOPLEFT",
  4929.         CensusPlusCheckButton6,
  4930.         "BOTTOMLEFT",
  4931.         120,
  4932.         -4
  4933.     )
  4934.     CensusPlusOptionsSoundFilesHeader:SetText(CENSUS_OPTIONS_SOUNDFILETEXT)
  4935.  
  4936.     --Create Frame SoundFile select1
  4937.     CensusPlusSoundFile1Button =
  4938.         CreateFrame(
  4939.             "Button",
  4940.             "CensusPlusSoundFile1Button",
  4941.             CensusPlusOptions,
  4942.             "UIPanelButtonTemplate"
  4943.         )
  4944.     CensusPlusSoundFile1Button:SetWidth(25)
  4945.     CensusPlusSoundFile1Button:SetHeight(25)
  4946.     CensusPlusSoundFile1Button:SetPoint(
  4947.         "TOPLEFT",
  4948.         CensusPlusOptionsSoundFilesHeader,
  4949.         0,
  4950.         -15
  4951.     )
  4952.     CensusPlusSoundFile1Button:Enable()
  4953.     CensusPlusSoundFile1Button:SetText("1")
  4954.     CensusPlusSoundFile1Button:SetScript("OnClick", function(self)
  4955.         local willplay =
  4956.             PlaySoundFile(
  4957.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete1.ogg",
  4958.                 "Master"
  4959.             )
  4960.         if not willplay then
  4961.             PlaySoundFile(
  4962.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete1.mp3",
  4963.                 "Master"
  4964.             )
  4965.         end
  4966.         g_FinishSoundNumber = 1
  4967.         if CensusPlusOptionsRadioButton_C6a:GetChecked() then
  4968.             CensusPlus_PerCharInfo["SoundFile"] = g_FinishSoundNumber
  4969.         elseif CensusPlus_Database["Info"]["PlayFinishSound"] then
  4970.             CensusPlus_Database["Info"]["SoundFile"] = g_FinishSoundNumber
  4971.         end
  4972.     end)
  4973.     --CensusPlusSoundFile1Button:SetScript("OnMouseUp", function(self)
  4974.     --  PlaySoundFile("Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete1.ogg")
  4975.     --end)
  4976.     CensusPlusSoundFile1Button.tooltipText =
  4977.         CENSUS_OPTIONS_SOUNDFILEDEFAULT .. "1"
  4978.  
  4979.     --Create Frame SoundFile select2
  4980.     CensusPlusSoundFile2Button =
  4981.         CreateFrame(
  4982.             "Button",
  4983.             "CensusPlusSoundFile2Button",
  4984.             CensusPlusOptions,
  4985.             "UIPanelButtonTemplate"
  4986.         )
  4987.     CensusPlusSoundFile2Button:SetWidth(25)
  4988.     CensusPlusSoundFile2Button:SetHeight(25)
  4989.     CensusPlusSoundFile2Button:SetPoint(
  4990.         "TOPLEFT",
  4991.         CensusPlusSoundFile1Button,
  4992.         80,
  4993.         0
  4994.     )
  4995.     CensusPlusSoundFile2Button:Enable()
  4996.     CensusPlusSoundFile2Button:SetText("2")
  4997.     CensusPlusSoundFile2Button:SetScript("OnClick", function(self)
  4998.         local willplay =
  4999.             PlaySoundFile(
  5000.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete2.ogg",
  5001.                 "Master"
  5002.             )
  5003.         if not willplay then
  5004.             PlaySoundFile(
  5005.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete2.mp3",
  5006.                 "Master"
  5007.             )
  5008.         end
  5009.         g_FinishSoundNumber = 2
  5010.         if CensusPlusOptionsRadioButton_C6a:GetChecked() then
  5011.             CensusPlus_PerCharInfo["SoundFile"] = g_FinishSoundNumber
  5012.         elseif CensusPlus_Database["Info"]["PlayFinishSound"] then
  5013.             CensusPlus_Database["Info"]["SoundFile"] = g_FinishSoundNumber
  5014.         end
  5015.     end)
  5016.     --CensusPlusSoundFile2Button:SetScript("OnMouseUp", function(self)
  5017.     --  PlaySoundFile("Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete2.ogg")
  5018.     --end)
  5019.     CensusPlusSoundFile2Button.tooltipText =
  5020.         CENSUS_OPTIONS_SOUNDFILEDEFAULT .. "2"
  5021.  
  5022.     --Create Frame SoundFile select3
  5023.     CensusPlusSoundFile3Button =
  5024.         CreateFrame(
  5025.             "Button",
  5026.             "CensusPlusSoundFile2Button",
  5027.             CensusPlusOptions,
  5028.             "UIPanelButtonTemplate"
  5029.         )
  5030.     CensusPlusSoundFile3Button:SetWidth(25)
  5031.     CensusPlusSoundFile3Button:SetHeight(25)
  5032.     CensusPlusSoundFile3Button:SetPoint(
  5033.         "TOPLEFT",
  5034.         CensusPlusSoundFile2Button,
  5035.         80,
  5036.         0
  5037.     )
  5038.     CensusPlusSoundFile3Button:Enable()
  5039.     CensusPlusSoundFile3Button:SetText("3")
  5040.     CensusPlusSoundFile3Button:SetScript("OnClick", function(self)
  5041.         local willplay =
  5042.             PlaySoundFile(
  5043.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete3.ogg",
  5044.                 "Master"
  5045.             )
  5046.         if not willplay then
  5047.             PlaySoundFile(
  5048.                 "Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete3.mp3",
  5049.                 "Master"
  5050.             )
  5051.         end
  5052.         g_FinishSoundNumber = 3
  5053.         if CensusPlusOptionsRadioButton_C6a:GetChecked() then
  5054.             CensusPlus_PerCharInfo["SoundFile"] = g_FinishSoundNumber
  5055.         elseif CensusPlus_Database["Info"]["PlayFinishSound"] then
  5056.             CensusPlus_Database["Info"]["SoundFile"] = g_FinishSoundNumber
  5057.         end
  5058.     end)
  5059.     --CensusPlusSoundFile3Button:SetScript("OnMouseUp", function(self)
  5060.     --  PlaySoundFile("Interface\\AddOns\\CensusPlusClassic\\sounds\\CensusComplete3.ogg")
  5061.     --end)
  5062.     CensusPlusSoundFile3Button.tooltipText =
  5063.         CENSUS_OPTIONS_SOUNDFILEDEFAULT .. "3"
  5064.  
  5065.     --Create another frame..
  5066.     CensusPlusOptionsWMZ = CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  5067.     CensusPlusOptionsWMZ:SetFontObject(GameFontWhite)
  5068.     CensusPlusOptionsWMZ:SetJustifyH("LEFT")
  5069.     CensusPlusOptionsWMZ:SetJustifyV("TOP")
  5070.     CensusPlusOptionsWMZ:ClearAllPoints()
  5071.     CensusPlusOptionsWMZ:SetPoint(
  5072.         "TOPLEFT",
  5073.         CensusPlusSoundFile1Button,
  5074.         "BOTTOMLEFT",
  5075.         -120,
  5076.         -4
  5077.     )
  5078.     CensusPlusOptionsWMZ:SetText(CENSUSPLUS_ACCOUNT_WIDE_ONLY_OPTIONS)
  5079.  
  5080.     --Create Frame Logarithmic  bars
  5081.     CensusPlusCheckButton7 =
  5082.         CreateFrame(
  5083.             "CheckButton",
  5084.             "CensusPlusCheckButton7",
  5085.             CensusPlusOptions,
  5086.             "OptionsCheckButtonTemplate"
  5087.         )
  5088.     CensusPlusCheckButton7:SetPoint(
  5089.         "TOPLEFT",
  5090.         CensusPlusOptionsWMZ,
  5091.         "BOTTOMLEFT",
  5092.         0,
  5093.         -6
  5094.     )
  5095.     CensusPlusCheckButton7:SetChecked(true)
  5096.     CensusPlusCheckButton7:SetScript("OnClick", function(self)
  5097.         local g_AW_LogBars = CensusPlusCheckButton7:GetChecked()
  5098.         if g_AW_LogBars then
  5099.             CensusPlus_Database["Info"]["UseLogBars"] = true
  5100.         else
  5101.             CensusPlus_Database["Info"]["UseLogBars"] = false
  5102.         end
  5103.         --CensusPlus_FinishSound(self)
  5104.     end)
  5105.     CensusPlusCheckButton7Text:SetText(CENSUS_OPTIONS_LOG_BARS) --
  5106.     CensusPlusCheckButton7.tooltipText = CENSUS_OPTIONS_LOG_BARSTEXT
  5107.  
  5108.     --Create CensusPlusClassic.Background:alpha Slider
  5109.     local g_CPWin_background_alpha = 0.5
  5110.     CensusPlusSlider2 =
  5111.         CreateFrame(
  5112.             "Slider",
  5113.             "CensusPlusSlider2",
  5114.             CensusPlusOptions,
  5115.             "OptionsSliderTemplate"
  5116.         )
  5117.     CensusPlusSlider2:SetWidth(100)
  5118.     CensusPlusSlider2:SetHeight(20)
  5119.     CensusPlusSlider2:SetOrientation("HORIZONTAL")
  5120.     CensusPlusSlider2:SetMinMaxValues(0.1, 1.0)
  5121.     CensusPlusSlider2:SetObeyStepOnDrag(true)
  5122.     CensusPlusSlider2:SetValueStep(0.1)
  5123.     CensusPlusSlider2:SetValue(0.5)
  5124.     CensusPlusSlider2:SetThumbTexture(
  5125.         "Interface\\Buttons\\UI-SliderBar-Button-Horizontal"
  5126.     )
  5127.     CensusPlusSlider2:SetPoint(
  5128.         "TOPLEFT",
  5129.         CensusPlusCheckButton7,
  5130.         "BOTTOMLEFT",
  5131.         48,
  5132.         -15
  5133.     )
  5134.     CensusPlusSlider2:SetScript("OnValueChanged", function(self, value)
  5135.         g_CPWin_background_alpha = CensusPlusSlider2:GetValue()
  5136.     end)
  5137.     CensusPlusSlider2:SetScript("OnMouseUp", function(self, value)
  5138.         CensusPlus_BackgroundAlpha(self, g_CPWin_background_alpha)
  5139.         CensusPlusBackground:SetAlpha(g_CPWin_background_alpha)
  5140.         CensusPlayerListBackground:SetAlpha(g_CPWin_background_alpha)
  5141.     end)
  5142.     CensusPlusSlider2.tooltipText =
  5143.         CENSUS_OPTIONS_BACKGROUND_TRANSPARENCY_TOOLTIP --Creates a tooltip on mouseover.
  5144.     _G[CensusPlusSlider2:GetName() .. "Low"]:SetText("0.1") --Sets the left-side slider text (default is "Low").
  5145.     _G[CensusPlusSlider2:GetName() .. "High"]:SetText("1.0") --Sets the right-side slider text (default is "High").
  5146.     _G[CensusPlusSlider2:GetName() .. "Text"]:SetText(CENSUSPLUS_TRANSPARENCY) --Sets the "title" text (top-centre of slider).
  5147.     CensusPlusSlider2:Enable()
  5148.  
  5149.  
  5150.     --Create another frame..
  5151.     CensusPlusOptionsExperimental = CensusPlusOptions:CreateFontString(nil, "ARTWORK")
  5152.     CensusPlusOptionsExperimental:SetFontObject(GameFontWhite)
  5153.     CensusPlusOptionsExperimental:SetJustifyH("LEFT")
  5154.     CensusPlusOptionsExperimental:SetJustifyV("TOP")
  5155.     CensusPlusOptionsExperimental:ClearAllPoints()
  5156.     CensusPlusOptionsExperimental:SetPoint(
  5157.         "TOPLEFT",
  5158.         CensusPlusSlider2,
  5159.         "BOTTOMLEFT",
  5160.         -50,
  5161.         -20
  5162.     )
  5163.     CensusPlusOptionsExperimental:SetText("Semi automatic requests (requires UI reload)")
  5164.  
  5165.     CensusPlusCheckButton8 =
  5166.         CreateFrame(
  5167.             "CheckButton",
  5168.             "CensusPlusCheckButton8",
  5169.             CensusPlusOptions,
  5170.             "OptionsCheckButtonTemplate"
  5171.         )
  5172.     CensusPlusCheckButton8:SetPoint(
  5173.         "TOPLEFT",
  5174.         CensusPlusOptionsExperimental,
  5175.         "BOTTOMLEFT",
  5176.         0,
  5177.         -6
  5178.     )
  5179.     CensusPlusCheckButton8:SetChecked(true)
  5180.     CensusPlusCheckButton8:SetScript("OnClick", function(self)
  5181.         currentOption = CensusPlus_Database["Info"]["UseWorldFrameClicks"]
  5182.         if currentOption then
  5183.             CensusPlus_Database["Info"]["UseWorldFrameClicks"] = false
  5184.         else
  5185.             CensusPlus_Database["Info"]["UseWorldFrameClicks"] = true
  5186.         end
  5187.     end)
  5188.     CensusPlusCheckButton8Text:SetText("Send who request on mouse clicks in world") --
  5189.     CensusPlusCheckButton8.tooltipText = "Sends a who request each time the user clicks into the 3D world. At minimum every 5 seconds."
  5190.  
  5191. end
  5192.  
  5193. function CensusPlus_ResetConfig() -- reset to defaults
  5194.     CensusPlus_Database["Info"]["AutoCensus"] = true
  5195.     CensusPlus_PerCharInfo["AutoCensus"] = nil
  5196.     CensusPlus_Database["Info"]["Verbose"] = false
  5197.     CensusPlus_PerCharInfo["Verbose"] = nil
  5198.     CensusPlus_Database["Info"]["Stealth"] = false
  5199.     CensusPlus_PerCharInfo["Stealth"] = nil
  5200.     CensusPlus_Database["Info"]["PlayFinishSound"] = false
  5201.     CensusPlus_PerCharInfo["PlayFinishSound"] = nil
  5202.     CensusPlus_Database["Info"]["SoundFile"] = 1
  5203.     CensusPlus_PerCharInfo["SoundFile"] = 1
  5204.     CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800
  5205.     CensusPlus_PerCharInfo["AutoCensusTimer"] = 1800
  5206.     CensusPlus_Database["Info"]["CensusButtonShown"] = true
  5207.     CensusPlus_PerCharInfo["CensusButtonShown"] = nil
  5208.     CensusPlus_Database["Info"]["CensusButtonAnimi"] = true
  5209.     CensusPlus_PerCharInfo["CensusButtonAnimi"] = nil
  5210.     CensusPlus_Database["Info"]["CPWindow_Transparency"] = 0.5
  5211.     CensusPlus_Database["Info"]["UseLogBars"] = true
  5212.     CensusPlus_Database["Info"]["UseWorldFrameClicks"] = false
  5213.     print("ResetConfig")
  5214.     CensusPlusSetCheckButtonState()
  5215. end
  5216.  
  5217. function CensusPlusSetCheckButtonState() -- set option check buttons and radio button states to match existing saved variables both AW and CCO - populate backup options tables
  5218.     CensusPlusCheckButton1:SetChecked(CensusPlus_Database["Info"]["Verbose"])
  5219.     CPp.Options_Holder["AccountWide"]["Verbose"] =
  5220.         CensusPlus_Database["Info"]["Verbose"]
  5221.     CPp.Options_Holder["CCOverrides"]["Verbose"] =
  5222.         CensusPlus_PerCharInfo["Verbose"]
  5223.     if (CensusPlus_PerCharInfo["Verbose"] == nil) then
  5224.         CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  5225.         CensusPlusOptionsRadioButton_C1b:SetChecked(false)
  5226.         CensusPlusOptionsRadioButton_C1c:SetChecked(true)
  5227.     elseif (CensusPlus_PerCharInfo["Verbose"] == true) then
  5228.         CensusPlusOptionsRadioButton_C1a:SetChecked(true)
  5229.         CensusPlusOptionsRadioButton_C1b:SetChecked(false)
  5230.         CensusPlusOptionsRadioButton_C1c:SetChecked(false)
  5231.     else
  5232.         CensusPlusOptionsRadioButton_C1a:SetChecked(false)
  5233.         CensusPlusOptionsRadioButton_C1b:SetChecked(true)
  5234.         CensusPlusOptionsRadioButton_C1c:SetChecked(false)
  5235.     end
  5236.     CensusPlus_Verbose(self)
  5237.  
  5238.     CensusPlusCheckButton2:SetChecked(CensusPlus_Database["Info"]["Stealth"])
  5239.     CPp.Options_Holder["AccountWide"]["Stealth"] =
  5240.         CensusPlus_Database["Info"]["Stealth"]
  5241.     CPp.Options_Holder["CCOverrides"]["Stealth"] =
  5242.         CensusPlus_PerCharInfo["Stealth"]
  5243.     if (CensusPlus_PerCharInfo["Stealth"] == nil) then
  5244.         CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  5245.         CensusPlusOptionsRadioButton_C2b:SetChecked(false)
  5246.         CensusPlusOptionsRadioButton_C2c:SetChecked(true)
  5247.     elseif (CensusPlus_PerCharInfo["Stealth"] == true) then
  5248.         CensusPlusOptionsRadioButton_C2a:SetChecked(true)
  5249.         CensusPlusOptionsRadioButton_C2b:SetChecked(false)
  5250.         CensusPlusOptionsRadioButton_C2c:SetChecked(false)
  5251.     else
  5252.         CensusPlusOptionsRadioButton_C2a:SetChecked(false)
  5253.         CensusPlusOptionsRadioButton_C2b:SetChecked(true)
  5254.         CensusPlusOptionsRadioButton_C2c:SetChecked(false)
  5255.     end
  5256.     CensusPlus_Stealth(self)
  5257.  
  5258.     CensusPlusCheckButton3:SetChecked(
  5259.         CensusPlus_Database["Info"]["CensusButtonShown"]
  5260.     )
  5261.     CPp.Options_Holder["AccountWide"]["CensusButtonShown"] =
  5262.         CensusPlus_Database["Info"]["CensusButtonShown"]
  5263.     CPp.Options_Holder["CCOverrides"]["CensusButtonShown"] =
  5264.         CensusPlus_PerCharInfo["CensusButtonShown"]
  5265.     if (CensusPlus_PerCharInfo["CensusButtonShown"] == nil) then
  5266.         CensusPlusOptionsRadioButton_C3a:SetChecked(false)
  5267.         CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  5268.         CensusPlusOptionsRadioButton_C3c:SetChecked(true)
  5269.     elseif (CensusPlus_PerCharInfo["CensusButtonShown"] == true) then
  5270.         CensusPlusOptionsRadioButton_C3a:SetChecked(true)
  5271.         CensusPlusOptionsRadioButton_C3b:SetChecked(false)
  5272.         CensusPlusOptionsRadioButton_C3c:SetChecked(false)
  5273.     else
  5274.         CensusPlusOptionsRadioButton_C3a:SetChecked(false)
  5275.         CensusPlusOptionsRadioButton_C3b:SetChecked(true)
  5276.         CensusPlusOptionsRadioButton_C3c:SetChecked(false)
  5277.     end
  5278.     CensusPlus_CensusButtonShown(self)
  5279.  
  5280.     CensusPlusCheckButton4:SetChecked(
  5281.         CensusPlus_Database["Info"]["CensusButtonAnimi"]
  5282.     )
  5283.     CPp.Options_Holder["AccountWide"]["CensusButtonAnimi"] =
  5284.         CensusPlus_Database["Info"]["CensusButtonAnimi"]
  5285.     CPp.Options_Holder["CCOverrides"]["CensusButtonAnimi"] =
  5286.         CensusPlus_PerCharInfo["CensusButtonAnimi"]
  5287.     if (CensusPlus_PerCharInfo["CensusButtonAnimi"] == nil) then
  5288.         CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  5289.         CensusPlusOptionsRadioButton_C4b:SetChecked(false)
  5290.         CensusPlusOptionsRadioButton_C4c:SetChecked(true)
  5291.     elseif (CensusPlus_PerCharInfo["CensusButtonAnimi"] == true) then
  5292.         CensusPlusOptionsRadioButton_C4a:SetChecked(true)
  5293.         CensusPlusOptionsRadioButton_C4b:SetChecked(false)
  5294.         CensusPlusOptionsRadioButton_C4c:SetChecked(false)
  5295.     else
  5296.         CensusPlusOptionsRadioButton_C4a:SetChecked(false)
  5297.         CensusPlusOptionsRadioButton_C4b:SetChecked(true)
  5298.         CensusPlusOptionsRadioButton_C4c:SetChecked(false)
  5299.     end
  5300.     CensusPlus_CensusButtonAnimi(self)
  5301.  
  5302.     CensusPlusCheckButton5:SetChecked(CensusPlus_Database["Info"]["AutoCensus"])
  5303.     CPp.Options_Holder["AccountWide"]["AutoCensus"] =
  5304.         CensusPlus_Database["Info"]["AutoCensus"]
  5305.     CPp.Options_Holder["CCOverrides"]["AutoCensus"] =
  5306.         CensusPlus_PerCharInfo["AutoCensus"]
  5307.     if (CensusPlus_PerCharInfo["AutoCensus"] == nil) then
  5308.         CensusPlusOptionsRadioButton_C5a:SetChecked(false)
  5309.         CensusPlusOptionsRadioButton_C5b:SetChecked(false)
  5310.         CensusPlusOptionsRadioButton_C5c:SetChecked(true)
  5311.     elseif (CensusPlus_PerCharInfo["AutoCensus"] == true) then
  5312.         CensusPlusOptionsRadioButton_C5a:SetChecked(true)
  5313.         CensusPlusOptionsRadioButton_C5b:SetChecked(false)
  5314.         CensusPlusOptionsRadioButton_C5c:SetChecked(false)
  5315.     else
  5316.         CensusPlusOptionsRadioButton_C5a:SetChecked(false)
  5317.         CensusPlusOptionsRadioButton_C5b:SetChecked(true)
  5318.         CensusPlusOptionsRadioButton_C5c:SetChecked(false)
  5319.     end
  5320.     CensusPlus_SetAutoCensus(self)
  5321.  
  5322.     if (CensusPlus_PerCharInfo["AutoCensus"] == true) then
  5323.         CensusPlusSlider1:SetValue(
  5324.             CensusPlus_PerCharInfo["AutoCensusTimer"] / 60
  5325.         )
  5326.         CPp.Options_Holder["CCOverrides"]["AutoCensusTimer"] =
  5327.             CensusPlus_PerCharInfo["AutoCensusTimer"]
  5328.         CPp.AutoStartTimer = CensusPlus_PerCharInfo["AutoCensusTimer"] / 60
  5329.     end
  5330.     if ((CensusPlus_PerCharInfo["AutoCensus"] == nil) and (CensusPlus_Database["Info"]["AutoCensus"] == true)) then
  5331.         CensusPlusSlider1:SetValue(
  5332.             CensusPlus_Database["Info"]["AutoCensusTimer"] / 60
  5333.         )
  5334.         CPp.Options_Holder["AccountWide"]["AutoCensusTimer"] =
  5335.             CensusPlus_Database["Info"]["AutoCensusTimer"]
  5336.         CPp.AutoStartTimer = CensusPlus_Database["Info"]["AutoCensusTimer"] / 60
  5337.     end
  5338.     if ((CensusPlus_Database["Info"]["AutoCensus"] == false) and not (CensusPlus_PerCharInfo["AutoCensus"] == true)) then
  5339.         CensusPlusSlider1:SetValue(30)
  5340.     end
  5341.  
  5342.     CensusPlusSlider2:SetValue(
  5343.         CensusPlus_Database["Info"]["CPWindow_Transparency"]
  5344.     )
  5345.     CPp.Options_Holder["AccountWide"]["CPWindow_Transparency"] =
  5346.         CensusPlus_Database["Info"]["CPWindow_Transparency"]
  5347.     CensusPlusBackground:SetAlpha(
  5348.         CensusPlus_Database["Info"]["CPWindow_Transparency"]
  5349.     )
  5350.     CensusPlayerListBackground:SetAlpha(
  5351.         CensusPlus_Database["Info"]["CPWindow_Transparency"]
  5352.     )
  5353.  
  5354.     CensusPlusCheckButton6:SetChecked(
  5355.         CensusPlus_Database["Info"]["PlayFinishSound"]
  5356.     )
  5357.     CPp.Options_Holder["AccountWide"]["PlayFinishSound"] =
  5358.         CensusPlus_Database["Info"]["PlayFinishSound"]
  5359.     CPp.Options_Holder["CCOverrides"]["PlayFinishSound"] =
  5360.         CensusPlus_PerCharInfo["PlayFinishSound"]
  5361.     if (CensusPlus_PerCharInfo["PlayFinishSound"] == nil) then
  5362.         CensusPlusOptionsRadioButton_C6a:SetChecked(false)
  5363.         CensusPlusOptionsRadioButton_C6b:SetChecked(false)
  5364.         CensusPlusOptionsRadioButton_C6c:SetChecked(true)
  5365.     elseif (CensusPlus_PerCharInfo["PlayFinishSound"] == true) then
  5366.         CensusPlusOptionsRadioButton_C6a:SetChecked(true)
  5367.         CensusPlusOptionsRadioButton_C6b:SetChecked(false)
  5368.         CensusPlusOptionsRadioButton_C6c:SetChecked(false)
  5369.     else
  5370.         CensusPlusOptionsRadioButton_C6a:SetChecked(false)
  5371.         CensusPlusOptionsRadioButton_C6b:SetChecked(true)
  5372.         CensusPlusOptionsRadioButton_C6c:SetChecked(false)
  5373.     end
  5374.  
  5375.     CPp.Options_Holder["AccountWide"]["SoundFile"] =
  5376.         CensusPlus_Database["Info"]["SoundFile"]
  5377.     CPp.Options_Holder["CCOverrides"]["SoundFile"] =
  5378.         CensusPlus_PerCharInfo["SoundFile"]
  5379.  
  5380.     CPp.Options_Holder["AccountWide"]["UseLogBars"] =
  5381.         CensusPlus_Database["Info"]["UseLogBars"]
  5382.     CensusPlusCheckButton7:SetChecked(CensusPlus_Database["Info"]["UseLogBars"])
  5383.     g_AW_LogBars = CensusPlus_Database["Info"]["UseLogBars"]
  5384.  
  5385.     CensusPlusCheckButton8:SetChecked(CensusPlus_Database["Info"]["UseWorldFrameClicks"])
  5386.    
  5387.     --  CensusPlusCheckButton8:SetChecked(CensusPlus2["WMZ party4"])
  5388.     --  CensusPlusCheckButton9:SetChecked(CensusPlus2["show decimals"])
  5389. end
  5390.  
  5391. function CensusPlusRestoreSettings() -- reset any changes to saved settings back to previous saved in backups
  5392.     -- account wide and CCO overrides
  5393.     CensusPlus_Database["Info"]["Verbose"] =
  5394.         CPp.Options_Holder["AccountWide"]["Verbose"]
  5395.     CensusPlus_PerCharInfo["Verbose"] =
  5396.         CPp.Options_Holder["CCOverrides"]["Verbose"]
  5397.     CensusPlus_Database["Info"]["Stealth"] =
  5398.         CPp.Options_Holder["AccountWide"]["Stealth"]
  5399.     CensusPlus_PerCharInfo["Stealth"] =
  5400.         CPp.Options_Holder["CCOverrides"]["Stealth"]
  5401.     CensusPlus_Database["Info"]["CensusButtonShown"] =
  5402.         CPp.Options_Holder["AccountWide"]["CensusButtonShown"]
  5403.     CensusPlus_PerCharInfo["CensusButtonShown"] =
  5404.         CPp.Options_Holder["CCOverrides"]["CensusButtonShown"]
  5405.     CensusPlus_Database["Info"]["CensusButtonAnimi"] =
  5406.         CPp.Options_Holder["AccountWide"]["CensusButtonAnimi"]
  5407.     CensusPlus_PerCharInfo["CensusButtonAnimi"] =
  5408.         CPp.Options_Holder["CCOverrides"]["CensusButtonAnimi"]
  5409.     CensusPlus_Database["Info"]["AutoCensus"] =
  5410.         CPp.Options_Holder["AccountWide"]["AutoCensus"]
  5411.     CensusPlus_PerCharInfo["AutoCensus"] =
  5412.         CPp.Options_Holder["CCOverrides"]["AutoCensus"]
  5413.     CensusPlus_Database["Info"]["AutoCensusTimer"] =
  5414.         CPp.Options_Holder["AccountWide"]["AutoCensusTimer"]
  5415.     CensusPlus_PerCharInfo["AutoCensusTimer"] =
  5416.         CPp.Options_Holder["CCOverrides"]["AutoCensusTimer"]
  5417.     CensusPlus_Database["Info"]["PlayFinishSound"] =
  5418.         CPp.Options_Holder["AccountWide"]["PlayFinishSound"]
  5419.     CensusPlus_PerCharInfo["PlayFinishSound"] =
  5420.         CPp.Options_Holder["CCOverrides"]["PlayFinishSound"]
  5421.     CensusPlus_Database["Info"]["SoundFile"] =
  5422.         CPp.Options_Holder["AccountWide"]["SoundFile"]
  5423.     CensusPlus_PerCharInfo["SoundFile"] =
  5424.         CPp.Options_Holder["CCOverrides"]["SoundFile"]
  5425.     -- account wide only
  5426.     CensusPlus_Database["Info"]["CPWindow_Transparency"] =
  5427.         CPp.Options_Holder["AccountWide"]["CPWindow_Transparency"]
  5428.     CensusPlus_Database["Info"]["UseLogBars"] =
  5429.         CPp.Options_Holder["AccountWide"]["UseLogBars"]
  5430.     CensusPlusCloseOptions()
  5431. end
  5432.  
  5433. function CensusPlusCloseOptions() -- reset Interface Options frame to Blizzard default CONTROLS_LABEL =='Game.Controls'
  5434.     InterfaceOptionsFrame_OpenToCategory(CONTROLS_LABEL)
  5435. end
Advertisement
Add Comment
Please, Sign In to add comment