Quantcast

Added profile support

Alar of Daggerspine [03-01-16 - 15:22]
Added profile support

Now mission control settings are stored in profiles.
Filename
GarrisonCommander.lua
MissionCompletion.lua
MissionControl.lua
Widgets.lua
diff --git a/GarrisonCommander.lua b/GarrisonCommander.lua
index b342171..9d78cfa 100644
--- a/GarrisonCommander.lua
+++ b/GarrisonCommander.lua
@@ -407,7 +407,6 @@ print("Initialize")
 		dbGAC.namespaces.missionscache=nil  -- Removed in 2.6.9
 		dbGAC.namespaces=nil
 	end
-	blacklist=chardb.missionControl.blacklist
 	self:AddLabel(L["Garrison Appearance"])
 	self:AddToggle("MOVEPANEL",true,L["Unlock Panel"],L["Makes main mission panel movable"])
 	self:AddToggle("BIGSCREEN",true,L["Big screen"],L["Disabling this will give you the interface from 1.1.8, given or taken. Need to reload interface"])
@@ -474,7 +473,7 @@ print("Initialize")
 	tabCO.Quantity:SetFormattedText("%d",GetItemCount(missionCompleteOrder))
 	tabCO:SetAttribute("type","item")
 	tabCO:SetAttribute("item",select(2,GetItemInfo(missionCompleteOrder)))
-	return true
+	--return true
 end
 function addon:showdata(fullargs,action,missionid)
 	self:Print(fullargs,",",missionid)
@@ -789,6 +788,27 @@ end
 function addon:SetDbDefaults(default)
 	default.global=default.global or {}
 	default.global["*"]={}
+	default.profile=default.profile or {}
+	default.profile.missionControl={
+		blacklist={},
+		version=1,
+		allowedRewards = {
+			['*']=true,
+		},
+		rewardChance={
+			['*']=100,
+		},
+		rewardList={},
+		useOneChance=true,
+		minimumChance = 100,
+		minDuration = 0,
+		maxDuration = 24,
+		epicExp = false,
+		skipRare=true,
+		skipEpic=not addon:HasSalvageYard(),
+		minLevel=540,
+		minUpgrade=600
+	}
 end
 function addon:CreatePrivateDb()
 	self.privatedb=self:RegisterDatabase(
diff --git a/MissionCompletion.lua b/MissionCompletion.lua
index 509a99b..0ab41d8 100644
--- a/MissionCompletion.lua
+++ b/MissionCompletion.lua
@@ -153,11 +153,11 @@ function module:MissionComplete(this,button,skiprescheck)
 		if stop and not skiprescheck then
 			self:Popup(message.."\n" ..format(L["If you %s, you will loose them\nClick on %s to abort"],ACCEPT,CANCEL),0,
 				function()
-					StaticPopup_Hide("LIBINIT_POPUP")
+					StaticPopup_Hide("LIBINIT_POPUP")
 					module:MissionComplete(this,button,true)
 				end,
 				function()
-					StaticPopup_Hide("LIBINIT_POPUP")
+					StaticPopup_Hide("LIBINIT_POPUP")
 					this:SetEnabled(true)
 					missionsFrame.CompleteDialog.BorderFrame.ViewButton:SetEnabled(true)
 					panel:Hide()
@@ -273,7 +273,7 @@ function module:MissionAutoComplete(event,ID,arg1,arg2,arg3,arg4)
 			end
 			currentMission.state=step
 		else
-			report:AddButton(L["Building Final report"],function() module:MissionsPrintResults() end)
+			report:AddButton(L["Building Final report"])
 			startTimer(1,"LOOT")
 		end
 	end
diff --git a/MissionControl.lua b/MissionControl.lua
index a55aa0c..c03c756 100644
--- a/MissionControl.lua
+++ b/MissionControl.lua
@@ -9,8 +9,6 @@ local _G=_G
 local factory=addon:GetFactory()
 --GMC_G.frame = CreateFrame('FRAME')
 local aMissions={}
-local chardb
-local db
 local GMF=GarrisonMissionFrame
 local GMCUsedFollowers={}
 local wipe=wipe
@@ -38,7 +36,7 @@ for _,data in ipairs(addon:GetRewardClasses()) do
 end
 local classlist={} ---#table local reference to settings.rewardList
 local class2order={} ---#table maps a classname to its priority
-local settings
+local settings ---#table Pointer to settings in saved var
 local module=addon:NewSubClass("MissionControl") --#module
 function module:GMCBusy(followerID)
 	return GMCUsedFollowers[followerID]
@@ -50,7 +48,6 @@ addon.GMCBusy=module.GMCBusy
 -- @param #table workList table to be filled with mission list
 function module:GMCCreateMissionList(workList)
 	--First get rid of unwanted rewards and missions that are too long
-	local settings=self.privatedb.profile.missionControl
 	local ar=settings.allowedRewards
 	wipe(workList)
 	for _,missionID in self:GetMissionIterator() do
@@ -185,7 +182,7 @@ do
 	local x=0
 	function module:GMCCalculateMissions(this,elapsed)
 		local GMC=GMF.MissionControlTab
-		db.news.MissionControl=true
+		addon.db.global.news.MissionControl=true

 		timeElapsed = timeElapsed + elapsed
 		if (#aMissions == 0 ) then
@@ -388,7 +385,7 @@ local function drawItemButtons(frame)
 	local single=settings.useOneChance
 	--for j = 1, #tItems do
 	--local i=tOrder[j]
-	local wrap=#classlist/2 +1
+	local wrap=math.ceil(#classlist/2 +1)
 	for frameIndex,i in ipairs(classlist) do
 		local row = GMC.ignoreFrames[frameIndex]
 		if not row then
@@ -552,23 +549,17 @@ local function toggleEpicWarning()
 end
 function module:OnInitialized()
 	local bigscreen=ns.bigscreen
-	db=addon.db.global
-	chardb=addon.privatedb.profile
 	chestTexture='GarrMission-'..UnitFactionGroup('player').. 'Chest'
 	local GMC = CreateFrame('FRAME', nil, GMF)
 	GMF.MissionControlTab=GMC
-	settings=chardb.missionControl
+	settings=addon.privatedb.profile.missionControl
+	self:RefreshConfig("Init")
 	if settings.version < 2 then
 		dbfixV1()
 	end
 	if settings.version < 3 or type(settings.rewardOrder)=='table' or #settings.rewardList==0 then
 		dbfixV2()
 	end
-	wipe(class2order)
-	classlist=settings.rewardList
-	for index,key in ipairs(classlist) do
-		class2order[key]=index
-	end
 	if settings.itemPrio then
 		settings.itemPrio=nil
 	end
@@ -607,8 +598,55 @@ function module:OnInitialized()
 	GMC.Credits:SetFormattedText(C(L["Original concept and interface by %s"],'Yellow'),C("Motig","Red") )
 	GMC.Credits:SetJustifyH("RIGHT")
 	GMC.Credits:SetPoint("BOTTOMRIGHT",-50,5)
+	addon.db.RegisterCallback(self, "OnNewProfile", "RefreshConfig")
+	--addon.db.RegisterCallback(self,"OnProfileShutdown","ShowList")
+	addon.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
+	addon.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
+	addon.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
 	return GMC
 end
+function module:ShowList()
+	self:Print("Rewards list for profile",addon.db:GetCurrentProfile())
+	DevTools_Dump(settings.rewardList)
+end
+local function clone(from,to)
+	for k,v in pairs(from) do
+		if type(v)~="table" then
+			to[k]=v
+		else
+			to[k]=to[k] or {}
+			clone(v,to[k])
+		end
+	end
+end
+function module:RefreshConfig(event)
+	settings=addon.db.profile.missionControl
+	local oldsettings=addon.privatedb.profile.missionControl
+	if #settings.rewardList==0 and oldsettings and #oldsettings.rewardList>0 then
+		clone(oldsettings,settings)
+	end
+	--self:ShowList()
+	blacklist=settings.blacklist
+	classlist=settings.rewardList
+	wipe(class2order)
+	for index,key in ipairs(classlist) do
+		class2order[key]=index
+	end
+	if #classlist < #addon:GetRewardClasses() then
+		for _,v in ipairs(addon:GetRewardClasses()) do
+			if not class2order[v.key] then
+				tinsert(classlist,v.key)
+			end
+		end
+		wipe(class2order)
+		for index,key in ipairs(classlist) do
+			class2order[key]=index
+		end
+	end
+	if event ~="Init" then -- Initialization routine, we cant design yet
+		drawItemButtons()
+	end
+end
 local refreshTimer
 function module:Refresh()
 	if not GMF.MissionControlTab.startButton then return end
diff --git a/Widgets.lua b/Widgets.lua
index 922e5db..d51c068 100644
--- a/Widgets.lua
+++ b/Widgets.lua
@@ -54,10 +54,11 @@ local function GMCList()
 	end
 	function m:AddButton(text,action)
 		local obj=self.scroll
-		local b=AceGUI:Create("Button")
+		local b=AceGUI:Create("Label")
 		b:SetFullWidth(true)
 		b:SetText(text)
-		b:SetCallback("OnClick",action)
+		b:SetColor(C.yellow.r,C.yellow.g,C.yellow.b)
+		--b:SetCallback("OnClick",action)
 		obj:AddChild(b)
 	end
 	function m:AddMissionButton(mission,party,perc,source)