Quantcast

Added plugin for the Master Volume control from cazzbr

Mikeprod [11-12-16 - 23:20]
Added plugin for the Master Volume control from cazzbr
Filename
media/datatexts/sound.tga
modules/armor.lua
modules/load_modules.xml
modules/mastervolume.lua
diff --git a/media/datatexts/sound.tga b/media/datatexts/sound.tga
new file mode 100644
index 0000000..f8889df
Binary files /dev/null and b/media/datatexts/sound.tga differ
diff --git a/modules/armor.lua b/modules/armor.lua
index bb75d69..94e8ad6 100644
--- a/modules/armor.lua
+++ b/modules/armor.lua
@@ -28,13 +28,13 @@ end

 function ArmorModule:OnEnable()
   if self.armorFrame == nil then
-    self.armorFrame = CreateFrame("FRAME", nil, xb:GetFrame('bar'))
+    self.armorFrame = CreateFrame("FRAME", AUCTION_CATEGORY_ARMOR, xb:GetFrame('bar'))
     xb:RegisterFrame('armorFrame', self.armorFrame)
   end
   self.armorFrame:Show()
   self:CreateFrames()
   self:RegisterFrameEvents()
-  self:Refresh()
+  xb:Refresh()
 end

 function ArmorModule:OnDisable()
@@ -203,6 +203,7 @@ function ArmorModule:GetConfig()
             self:Enable()
           else
             self:Disable()
+			xb:Refresh()
           end
         end
       },
diff --git a/modules/load_modules.xml b/modules/load_modules.xml
index 10e910d..f143380 100644
--- a/modules/load_modules.xml
+++ b/modules/load_modules.xml
@@ -9,4 +9,5 @@
   <Script file="currency.lua" />
   <Script file="system.lua" />
   <Script file="talent.lua" />
+  <Script file="mastervolume.lua" />
 </Ui>
diff --git a/modules/mastervolume.lua b/modules/mastervolume.lua
new file mode 100644
index 0000000..d532d94
--- /dev/null
+++ b/modules/mastervolume.lua
@@ -0,0 +1,195 @@
+local addon, xb = ...
+local _G = _G;
+local L = xb.L;
+
+local VolumeModule = xb:NewModule("VolumeModule", 'AceEvent-3.0')
+
+function VolumeModule:GetName()
+  return "MasterVolume";
+end
+
+function VolumeModule:OnInitialize()
+self.frame = nil
+self.icon = nil
+self.text = nil
+end
+
+function VolumeModule:OnEnable()
+	if self.frame == nil then
+		self:CreateModuleFrame()
+		self:RegisterEvents()
+		self:MasterVolume_Update_Value()
+		self:Hooks()
+	else
+		self.frame:Show()
+		self:RegisterEvents()
+	end
+end
+
+function VolumeModule:OnDisable()
+	if self.frame then
+		self.frame:Hide()
+		self.frame:UnregisterAllEvents()
+	end
+end
+
+function VolumeModule:CreateModuleFrame()
+	self.frame=CreateFrame("BUTTON","masterVolume", xb:GetFrame('bar'))
+	xb:RegisterFrame('volumeFrame',self.frame)
+	self.frame:EnableMouse(true)
+	self.frame:RegisterForClicks("AnyDown")
+
+	local relativeAnchorPoint = 'RIGHT'
+	local xOffset = xb.db.profile.general.moduleSpacing
+	local parentFrame = xb:GetFrame('armorFrame')
+	if not xb.db.profile.modules.armor.enabled then
+		parentFrame=xb:GetFrame('microMenuFrame')
+		if not xb.db.profile.modules.microMenu.enabled then
+			parentFrame=xb:GetFrame('bar')
+			relativeAnchorPoint = 'LEFT'
+			xOffset = 0
+		end
+	end
+
+	self.frame:SetPoint('LEFT', parentFrame, relativeAnchorPoint, xOffset, 0)
+
+	self.icon = self.frame:CreateTexture(nil,"OVERLAY",nil,7)
+	self.icon:SetPoint("LEFT")
+	self.icon:SetTexture(xb.constants.mediaPath.."datatexts\\sound")
+	self.icon:SetVertexColor(xb:GetColor('normal'))
+
+	self.text = self.frame:CreateFontString(nil, "OVERLAY")
+	self.text:SetFont(xb:GetFont(xb.db.profile.text.fontSize))
+	self.text:SetPoint("RIGHT", self.frame,2,0)
+	self.text:SetTextColor(xb:GetColor('inactive'))
+end
+
+function VolumeModule:RegisterEvents()
+	self.frame:SetScript("OnEnter", function()
+		if InCombatLockdown() then return end
+		self.icon:SetVertexColor(xb:GetColor('hover'))
+		self.text:SetTextColor(xb:GetColor('hover'))
+
+		GameTooltip:SetOwner(self.frame, "ANCHOR_BOTTOM")
+		GameTooltip:AddLine("[|cff6699FFMaster Volume|r]")
+		GameTooltip:AddLine(" ")
+		GameTooltip:AddDoubleLine("<Left-click>", "|cffffffffMaster Volume UP|r")
+		GameTooltip:AddDoubleLine("<Right-click>", "|cffffffffMaster Volume DOWN|r")
+		GameTooltip:Show()
+	end)
+
+	self.frame:SetScript("OnClick", function(self, button, down)
+		local volume = tonumber(GetCVar("Sound_MasterVolume"));
+
+		if button == "LeftButton" then
+
+		SetCVar( "Sound_MasterVolume", volume + xb.db.profile.modules.MasterVolume.step);
+
+		elseif button == "RightButton" then
+		SetCVar( "Sound_MasterVolume", volume - xb.db.profile.modules.MasterVolume.step);
+		end
+		volume = tonumber(GetCVar("Sound_MasterVolume"));
+		if volume <=0 then SetCVar( "Sound_MasterVolume", 0); end
+		if volume >=1 then SetCVar( "Sound_MasterVolume", 1); end
+	end)
+
+	self.frame:SetScript("OnLeave", function()
+		self.icon:SetVertexColor(xb:GetColor('normal'))
+		self.text:SetTextColor(xb:GetColor('inactive'))
+		GameTooltip:Hide();
+	end)
+
+	self.frame:RegisterEvent("PLAYER_ENTERING_WORLD");
+	self.frame:RegisterEvent("CVAR_UPDATE");
+	self.frame:SetScript("OnEvent", function(self,event, ...)
+		VolumeModule:MasterVolume_Update_Value();
+	end)
+end
+
+function VolumeModule:Refresh()
+	if not xb.db.profile.modules.MasterVolume.enabled then self:Disable(); return; end
+
+	if not self.frame and xb.db.profile.modules.MasterVolume.enabled then
+		self:Enable()
+		return;
+	end
+
+	if self.frame then
+		self.frame:Hide()
+		local relativeAnchorPoint = 'RIGHT'
+		local xOffset = xb.db.profile.general.moduleSpacing
+		local parentFrame = xb:GetFrame('armorFrame')
+		if not xb.db.profile.modules.armor.enabled then
+			parentFrame=xb:GetFrame('microMenuFrame')
+			if not xb.db.profile.modules.microMenu.enabled then
+				parentFrame=xb:GetFrame('bar')
+				relativeAnchorPoint = 'LEFT'
+				xOffset = 0
+			end
+		end
+		self.frame:SetPoint('LEFT', parentFrame, relativeAnchorPoint, xOffset, 0)
+		self.frame:Show()
+	end
+end
+
+function VolumeModule:MasterVolume_Update_Value()
+	local volume = tonumber(GetCVar("Sound_MasterVolume"));
+	local volumePercent = (volume * 100);
+	local volumePercentTrimed = tonumber(string.format("%.1f", volumePercent));
+	if self.text and self.frame then
+		self.text:SetText(volumePercentTrimed.." %")
+		self.frame:SetSize(self.text:GetStringWidth()+18, 16)
+	end
+end
+
+function VolumeModule:Hooks()
+	hooksecurefunc("Sound_MasterVolumeUp", VolumeModule.MasterVolume_Update_Value)
+	hooksecurefunc("Sound_MasterVolumeDown", VolumeModule.MasterVolume_Update_Value)
+
+	hooksecurefunc("SetCVar", function(cvar, value)
+		if cvar == "Sound_MasterVolume" then
+			VolumeModule:MasterVolume_Update_Value()
+		end
+	end)
+end
+
+function VolumeModule:GetDefaultOptions()
+  return self:GetName(), {
+      enabled = false,
+      step = 0.1
+    }
+end
+
+function VolumeModule:GetConfig()
+  return {
+    name = self:GetName(),
+    type = "group",
+    args = {
+      enable = {
+        name = ENABLE,
+        order = 0,
+        type = "toggle",
+        get = function() return xb.db.profile.modules.MasterVolume.enabled; end,
+        set = function(_, val)
+          xb.db.profile.modules.MasterVolume.enabled = val
+          if val then
+            self:Enable();
+          else
+            self:Disable();
+          end
+        end,
+        width = "full"
+      },
+	  step = {
+		name = "Volume step",
+		order = 1,
+		type = "range",
+		min = 1,
+		max = 50,
+		step = 1,
+		get = function() return xb.db.profile.modules.MasterVolume.step*100; end,
+		set = function(_,val) xb.db.profile.modules.MasterVolume.step = val/100.0; end
+	  }
+	  }
+  }
+ end
\ No newline at end of file