Quantcast

Add suport for vehicle swap (possibly)

James Whitehead II [11-28-10 - 17:05]
Add suport for vehicle swap (possibly)
Filename
PerfectRaid.lua
PerfectRaid_Frames.lua
diff --git a/PerfectRaid.lua b/PerfectRaid.lua
index 25d1e26..92c8356 100644
--- a/PerfectRaid.lua
+++ b/PerfectRaid.lua
@@ -87,6 +87,7 @@ function PerfectRaid:Enable()
 	self.db.global.sv_version = self.rev

 	self:RegisterEvent("RAID_ROSTER_UPDATE")
+    self:RegisterEvent("PARTY_MEMBERS_CHANGED", "RAID_ROSTER_UPDATE")
 	self:RegisterEvent("UNIT_DISPLAYPOWER")
 	self:RegisterEvent("UNIT_HEALTH")
 	self:RegisterEvent("UNIT_MAXHEALTH")
@@ -256,6 +257,7 @@ function PerfectRaid:CreateRaidFrame(idx)
 	frame.initialConfigFunction = PerfectRaid.ConfigureButton
     frame:SetAttribute("initialConfigFunction", [===[
         local header = self:GetParent()
+        self:SetAttribute("toggleForVehicle", true)
         header:CallMethod("initialConfigFunction", self:GetName())
     ]===])

@@ -468,6 +470,9 @@ function OnAttributeChanged(frame, name, value)

 	-- If we've been given a unit, instead of nil
 	if value then
+        -- Get the modified unit, rather than using the one we're given
+        vaulue = SecureButton_GetModifiedUnit(frame)
+
 		-- Register us for frame updates under the correct unit ID.
 		frames[value] = frames[value] or {}
 		frames[value][frame] = true
@@ -564,10 +569,7 @@ function PerfectRaid.ConfigureButton(header, buttonName)
     button:SetWidth(225)
     button:SetHeight(14)

-    -- Change with vehicle state:
-    button:SetAttribute("toggleForVehicle", true)
-
-	if self.db.profile.clickcast then
+    if self.db.profile.clickcast then
 		ClickCastFrames[button] = true
 	end

@@ -590,6 +592,9 @@ function PerfectRaid.ConfigureButton(header, buttonName)
 	local options = self.db.profile.headers[parent.idx]
 	button.options = options

+    -- Change with vehicle state:
+    button:SetAttribute("toggleForVehicle", not not options.vehicleSwap)
+
 	local leftbox = CreateFrame("Frame", nil, button)
 	button.leftbox = leftbox

diff --git a/PerfectRaid_Frames.lua b/PerfectRaid_Frames.lua
index 5da1977..55d47e1 100644
--- a/PerfectRaid_Frames.lua
+++ b/PerfectRaid_Frames.lua
@@ -12,7 +12,7 @@
         copyright notice, this list of conditions and the following
         disclaimer in the documentation and/or other materials provided
         with the distribution.
-      * Neither the name of PerfectRaid nor the names of its contributors
+      * Neither the name of PerfectRaid nor the names of its contributors
         may be used to endorse or promote products derived from this software
         without specific prior written permission.

@@ -86,7 +86,7 @@ function Frames:CreateOptions(opt)
 		button:Click()
 		self:EditEntry()
 	end
-
+
 	for i=1,num_entries do
 		button = scrollframe.entries[i]
 		button:SetScript("OnDoubleClick", OnDoubleClick)
@@ -105,10 +105,10 @@ function Frames:CreateOptions(opt)
 				local entry = list[idx]
 				local work = {}

-				if entry.showParty then table.insert(work, L["inParty"]) end
-				if entry.showRaid then table.insert(work, L["inRaid"]) end
-				if entry.showPlayer then table.insert(work, L["showPlayer"]) end
-				if entry.showSolo then table.insert(work, L["showSolo"]) end
+				if entry.showParty then table.insert(work, L["inParty"]) end
+				if entry.showRaid then table.insert(work, L["inRaid"]) end
+				if entry.showPlayer then table.insert(work, L["showPlayer"]) end
+				if entry.showSolo then table.insert(work, L["showSolo"]) end
 				local flags = string.join(",", unpack(work))

 				if #flags > 0 then
@@ -137,7 +137,7 @@ function Frames:CreateOptions(opt)
 		end
 		self:EnableButtons()
 	end
-
+
 	scrollframe.update = update

 	scrollframe:SetScript("OnVerticalScroll", function(frame, value)
@@ -170,7 +170,7 @@ function Frames:CreateOptions(opt)
 	edit:SetPoint("BOTTOMRIGHT", delete, "BOTTOMLEFT", -10, 0)
 	edit:SetScript("OnClick", function() self:EditEntry() end)
 	edit:Show()
-
+
 	local add = CreateFrame("Button", "PRFrames_Add", options, "PRButtonTemplate")
 	add:SetText(L["Add"])
 	add:SetPoint("BOTTOMRIGHT", edit, "BOTTOMLEFT", -10, 0)
@@ -267,7 +267,7 @@ function Frames:CreateEditFrame(parent)
 	makeCheck(L["All Groups"], "1,2,3,4,5,6,7,8")
 	makeCheck(L["Main tanks"], "MAINTANK")
 	makeCheck(L["Main assists"], "MAINASSIST")
-
+
 	for idx,button in ipairs(self.filters) do
 		if idx == 1 then
 			button:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -15)
@@ -330,7 +330,7 @@ function Frames:CreateEditFrame(parent)

 	local hbackdrop = CreateFrame("CheckButton", "PRFrame_HeaderBackdrop", PROptions_Frames_Edit, "PRCheckTemplate")
 	hbackdrop.Label:SetText(L["Display a header backdrop"])
-	hbackdrop:SetPoint("BOTTOMLEFT", 0, 160)
+	hbackdrop:SetPoint("BOTTOMLEFT", 0, 210)
 	hbackdrop:Show()

 	local strict = CreateFrame("CheckButton", "PRFrame_Strict", PROptions_Frames_Edit, "PRCheckTemplate")
@@ -399,6 +399,11 @@ function Frames:CreateEditFrame(parent)
 										end
 									end)

+    local vehicleSwap = CreateFrame("CheckButton", "PRFrame_VehicleSwap", PROptions_Frames_Edit, "PRCheckTemplate")
+    vehicleSwap.Label:SetText(L["Swap unit in vehicle"])
+    vehicleSwap:SetPoint("TOPLEFT", showParty, "BOTTOMLEFT", 0, 0)
+    vehicleSwap:Show()
+
 --[[
 	local hborderswatch = self:CreateSwatch("PRFrame_HBorder_Color", PROptions_Frames_Edit)
 	local fborderswatch = self:CreateSwatch("PRFrame_FBorder_Color", PROptions_Frames_Edit)
@@ -446,7 +451,7 @@ function Frames:CreateEditFrame(parent)

 	local function onTabPressed(self)
 		if IsShiftKeyDown() then
-			self.prev:SetFocus()
+			self.prev:SetFocus()
 		else
 			self.next:SetFocus()
 		end
@@ -525,6 +530,8 @@ function Frames:EditEntry()
 	PRFrame_ShowRaid:SetChecked(entry.showRaid)
 	PRFrame_ShowPlayer:SetChecked(entry.showPlayer)
 	PRFrame_ShowSolo:SetChecked(entry.showSolo)
+
+	PRFrame_VehicleSwap:SetChecked(entry.vehicleSwap)
 end

 function Frames:AddEntry()
@@ -563,7 +570,7 @@ function Frames:EnableButtons()
 		PRFrames_Disable:Disable()
 	end
 end
-
+
 function Frames:SaveEntry()
 	local title = PROptions_Frames_EditTitle:GetText()
 	local groupBy = UIDropDownMenu_GetSelectedValue(PRFrames_GroupByDropDown)
@@ -596,6 +603,7 @@ function Frames:SaveEntry()
 	local showRaid = PRFrame_ShowRaid:GetChecked()
 	local showPlayer = PRFrame_ShowPlayer:GetChecked()
 	local showSolo = PRFrame_ShowSolo:GetChecked()
+    local vehicleSwap = PRFrame_VehicleSwap:GetChecked()

 	if title == "" then title = nil end
 	if filter == "" then filter = nil end
@@ -607,14 +615,14 @@ function Frames:SaveEntry()

 	-- Validation code here
 	local err
-	if not (numColumns and maxUnits and colSpacing and colAnchor) and
+	if not (numColumns and maxUnits and colSpacing and colAnchor) and
 		(numColumns or maxUnits or colSpacing or colAnchor) then
 		err = L["If you choose any of the column options, all of them become required fields.  Please choose the number of columns, max units, column spacing and column anchor."]
 	elseif not filter and not partyFrame then
 		--err = L["You must select at least one class or group to display."]
 	end

-	if err then
+	if err then
 		StaticPopupDialogs["PR_FRAME_SAVE_ERROR"].text = err
 		StaticPopup_Show("PR_FRAME_SAVE_ERROR")
 		return
@@ -647,6 +655,8 @@ function Frames:SaveEntry()
 	entry.showPlayer = showPlayer
 	entry.showSolo = showSolo

+    entry.vehicleSwap = vehicleSwap
+
 	if not self.editEntry then
 		table.insert(PerfectRaid.db.profile.headers, entry)
 	end
@@ -694,6 +704,7 @@ function Frames:CancelEntry()
 	PRFrame_ShowRaid:SetChecked(false)
 	PRFrame_ShowPlayer:SetChecked(false)
 	PRFrame_ShowSolo:SetChecked(false)
+    PRFrame_VehicleSwap:SetChecked(false)

 	self.options:FadeOut(PROptions_Frames_Edit)
 	self.options:FadeIn(PROptions_Frames)
@@ -731,12 +742,12 @@ end

 local function colorSwatchShow(self)
 	local r, g, b, a = 1, 1, 1, 1
-
+
 	self.r, self.g, self.b, self.a = r, g, b, a
 	self.opacityFunc = colorSwatchOpacity
 	self.swatchFunc = colorSwatchColor
 	self.cancelFunc = colorSwatchCancel
-
+
 	ColorPickerFrame.object = self
 	ColorPickerFrame.opacity = a
 	ColorPickerFrame.hasOpacity = self.hasAlpha