MyMinimapButton.lua 3.59 KB
Newer Older
humfras's avatar
humfras committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

VuhDoMinimap = {

	["Create"] = function(self, someModSettings, someInitSettings)

		if VuhDoMinimapButton then return; end

		local tFrame = CreateFrame("Button", "VuhDoMinimapButton", Minimap);

		tFrame:SetWidth(31);
		tFrame:SetHeight(31);
		tFrame:SetFrameStrata("LOW");
		tFrame:SetToplevel(true);
		tFrame:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight");
		tFrame:SetPoint("TOPLEFT", Minimap, "TOPLEFT");

		local tIcon = tFrame:CreateTexture("VuhDoMinimapButtonIcon", "BACKGROUND");
		tIcon:SetTexture(VUHDO_STANDARD_ICON);
		tIcon:SetWidth(20);
		tIcon:SetHeight(20);
		tIcon:SetPoint("TOPLEFT", tFrame, "TOPLEFT", 7, -5);

		local tOverlay = tFrame:CreateTexture("VuhDoMinimapButtonOverlay", "OVERLAY");
		tOverlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder");
		tOverlay:SetWidth(53);
		tOverlay:SetHeight(53);
		tOverlay:SetPoint("TOPLEFT", tFrame, "TOPLEFT")

		tFrame:RegisterForClicks("LeftButtonUp", "RightButtonUp");
		tFrame:SetScript("OnClick", self.OnClick);

		tFrame:SetScript("OnMouseDown", self.OnMouseDown);
		tFrame:SetScript("OnMouseUp", self.OnMouseUp);
		tFrame:SetScript("OnEnter", self.OnEnter);
		tFrame:SetScript("OnLeave", self.OnLeave);

		tFrame:RegisterForDrag("LeftButton");
		tFrame:SetScript("OnDragStart", self.OnDragStart);
		tFrame:SetScript("OnDragStop", self.OnDragStop);

		if not someModSettings["position"] then
			someModSettings["drag"] = someInitSettings["drag"];
			someModSettings["position"] = someInitSettings["position"];
		end

		tFrame["modSettings"] = someModSettings;
		self:Move();
	end,


	["Move"] = function(self)
		local tXPos, tYPos;
		local tAngle = VuhDoMinimapButton["modSettings"]["position"];
		--[[if (VuhDoMinimapButton["modSettings"]["drag"] == "SQUARE") then
			tXPos = 110 * cos(tAngle);
			tYPos = 110 * sin(tAngle);
			tXPos = math.max(-82, math.min(tXPos, 84));
			tYPos = math.max(-86, math.min(tYPos, 82));
		else]]
			tXPos = 80 * cos(tAngle);
			tYPos = 80 * sin(tAngle);
		--end
		VuhDoMinimapButton:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", 54 - tXPos, tYPos - 54);
	end,

	-- Internal functions: do not call anything below here

	["OnMouseDown"] = function(self)
		_G[self:GetName().."Icon"]:SetTexCoord(0, 1, 0, 1);
	end,


	["OnMouseUp"] = function(self)
		_G[self:GetName().."Icon"]:SetTexCoord(0.05, 0.95, 0.05, 0.95);
	end,


	["OnEnter"] = function(self)
79 80 81 82 83 84
		if not GameTooltip:IsForbidden() then
			GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
			GameTooltip:AddLine("VuhDo");
			GameTooltip:AddLine(VUHDO_I18N_MM_TOOLTIP, 0.8, 0.8, 0.8, 1);
			GameTooltip:Show();
		end
humfras's avatar
humfras committed
85 86 87 88
	end,


	["OnLeave"] = function(self)
89 90 91
		if not GameTooltip:IsForbidden() then
			GameTooltip:Hide()
		end
humfras's avatar
humfras committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
	end,


	["OnDragStart"] = function(self)
		self:LockHighlight();
		self:SetScript("OnUpdate", VuhDoMinimap.OnUpdate);
	end,


	["OnDragStop"] = function(self)
		self:SetScript("OnUpdate", nil);
		self:UnlockHighlight();
	end,


	["OnUpdate"] = function(self)
		local tXPos, tYPos = GetCursorPosition();
		local tXMin, tYMin = Minimap:GetLeft(), Minimap:GetBottom();

		tXPos = tXMin - tXPos / Minimap:GetEffectiveScale() + 70;
		tYPos = tYPos / Minimap:GetEffectiveScale() - tYMin - 70;

		self["modSettings"]["position"] = math.deg(math.atan2(tYPos, tXPos));
		VuhDoMinimap:Move();
	end,


	["OnClick"] = function(self, aButtonName)
		if "LeftButton" == aButtonName then
			VUHDO_slashCmd("opt");
		elseif "RightButton" == aButtonName then
			ToggleDropDownMenu(1, nil, VuhDoMinimapDropDown, "VuhDoMinimapButton", 0, -5);
		end
	end

}