Go to most recent revision | Compare with Previous | Blame | View Log
--[[ Changelog: Version 2.0.0 Updated TOC Version Updated SilvanasAddonLib Removed enable / disable toggle Repositioned the checkbox Version 1.1.1 Updated TOC Version Updated SilvanasAddonLib Interface is back and working again Version 1.1.0 Updated for 3.0.2 Version 1.0.1 Updated TOC Version Updated SilvanasAddonLib Version 1.0.0 First fully woking version Known Bugs: checkboxews are located in a wrong way so scaling the ui will case it tobe misplaced Todo: ^^ fix that litle bug --]] --main global var AutoReputationBar = { ["NAME"] = "|cFF3366FFAuto Reputation Bar|r", ["VERSION"] = "(|cFF9900001|cFFFFFFFF.|cFF9900001|cFFFFFFFF.|cFF9900000|cFFFFFFFF)|r", } -- --event array local AutoReputationBarEventArray = {} function AutoReputationBar_Event(event,...) AutoReputationBarEventArray[event](...) end -- ------------------- --event triggered-- ------------------- --onload function AutoReputationBar_Load(self) --register events AutoReputationBarEventArray = { ["VARIABLES_LOADED"] = AutoReputationBar_Event_Variables_Loaded, ["COMBAT_TEXT_UPDATE"] = AutoReputationBar_Event_Combat_Text_Update, } Silvanas.RegisterEvents(self,AutoReputationBarEventArray) end ---on event function AutoReputationBar_Event_Variables_Loaded() ---relaod saved vars --if the saved var didnt load then set it whit default setting esle we assume all setting to exist if (not AutoReputationBar_SavedVars) or (not AutoReputationBar_SavedVars["VERSION"]) or (AutoReputationBar_SavedVars["VERSION"] ~= AutoReputationBar["VERSION"]) then AutoReputationBar_SavedVars = { ["ACTIVEONLY"] = false, ["VERSION"] = AutoReputationBar["VERSION"] } end --build up the checkbox that shows up in the reputation tab local checkbox,checkboxText --active only button checkbox = CreateFrame("CheckButton","AutoReputationBar_Interface_Button_ActiveOnly",ReputationFrame,"OptionsCheckButtonTemplate") checkbox:SetWidth(20) checkbox:SetHeight(20) checkbox:SetFrameStrata("HIGH") checkbox:SetChecked(AutoReputationBar_SavedVars["ACTIVEONLY"]) checkbox:RegisterForClicks("LeftButtonUp") checkbox:SetScript("OnClick",function(self,button) AutoReputationBar_Interface_Button_ActiveOnly_Clicked(self); end) checkbox:SetPoint("TOPLEFT",ReputationFrame,"TOPLEFT", 53, -18) checkboxText = _G[checkbox:GetName() .."Text"] checkboxText:SetText("Switch to active factions only") --loaded message Silvanas.Print(AutoReputationBar["NAME"] .." |cFFFFFFFFBy: ".. Silvanas.Author .." |cFFFFFFFFversion: ".. AutoReputationBar["VERSION"] .." |cFFFFFFFFloaded.|r") end function AutoReputationBar_Event_Combat_Text_Update(updatetype, updatefaction) --see if we are updating a faction if updatetype == "FACTION" then --if we are not already watcinh that faction if updatefaction ~= GetWatchedFactionInfo() then --try to switch the bar AutoReputationBar_SetBar(updatefaction) end end end -------------------- -------------------- -------------------- ----------------------- --Switching Functions-- ----------------------- function AutoReputationBar_SetBar(faction) local x,factionID,factionName,factionHeader,factionWatched,factionColapsed,NumFactions local AutoReputationBar_ColapsedList = {} --parse default nr of items NumFactions = GetNumFactions() --go over each faction to find the ID nummer --set first fiction id factionID = 1 while factionID <= NumFactions do --get factions name factionName,x,x,x,x,x,x,x,factionHeader,factionColapsed,factionWatched = GetFactionInfo(factionID) --only contine if its not already watched if not factionWatched then --only contine if not a header if factionHeader then --if its closed then open it if factionColapsed then --open header ExpandFactionHeader(factionID) --recalc the number of factions NumFactions = GetNumFactions() --store header name to close it later AutoReputationBar_ColapsedList[factionName] = true end else --option only show active factions if (AutoReputationBar_SavedVars["ACTIVEONLY"] and IsFactionInactive(factionID)) then break; end --now lets see if its the correct name if factionName == faction then --oke let set the bar SetWatchedFactionIndex(factionID) --stop function return end end end factionID = factionID + 1 end --if we opened any headers lets now close them if #AutoReputationBar_ColapsedList > 0 then local factionID --close any colapsed headers for factionID=1, GetNumFactions() do --if the faction name is in our list then close it if AutoReputationBar_ColapsedList[GetFactionInfo(factionID)] then CollapseFactionHeader(factionID) end end --reset the list of closed headers AutoReputationBar_ColapsedList = {} end end ----------------------- ----------------------- ----------------------- ------------- --interface-- ------------- function AutoReputationBar_Interface_Button_ActiveOnly_Clicked(self) --toggle activeonly AutoReputationBar_SavedVars["ACTIVEONLY"] = not AutoReputationBar_SavedVars["ACTIVEONLY"] end ------------- ------------- -------------