Quantcast

Save Variables (Positions, Alpha), place MailboxButton

Steven Mey [11-29-19 - 10:03]
Save Variables (Positions, Alpha), place MailboxButton
Filename
Bindings.xml
D2Minimap.lua
D2Minimap.toc
diff --git a/Bindings.xml b/Bindings.xml
new file mode 100644
index 0000000..6a288bb
--- /dev/null
+++ b/Bindings.xml
@@ -0,0 +1,19 @@
+<Bindings>
+    <Binding name="Toggle D2Minimap" header="D2Minimap" default="ALT-M" category="Interface Panel">
+        if (Minimap:IsShown()) then
+            Minimap:Hide()
+        else
+            Minimap:Show()
+        end
+    </Binding>
+    <Binding name="Increase D2Minimap alpha" category="Interface Panel">
+        if (Minimap:GetAlpha() &lt; 1) then
+            Minimap:SetAlpha(Minimap:GetAlpha()+.1)
+        end
+    </Binding>
+    <Binding name="Decrease D2Minimap alpha" default="ALT--" category="Interface Panel">
+        if (Minimap:GetAlpha() &gt; 0) then
+            Minimap:SetAlpha(Minimap:GetAlpha()-.1)
+        end
+    </Binding>
+</Bindings>
\ No newline at end of file
diff --git a/D2Minimap.lua b/D2Minimap.lua
index 3ea4468..ce08ce4 100644
--- a/D2Minimap.lua
+++ b/D2Minimap.lua
@@ -1,71 +1,170 @@
 D2Minimap = true

-local function D2Minimap_init(self, event, ...)
-    Minimap:ClearAllPoints()
-    Minimap:SetParent(UIParent)
-    Minimap:SetAlpha(0.1)
-    Minimap:SetFrameStrata("BACKGROUND")
-    Minimap:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
-    Minimap:SetHeight(1000)
-    Minimap:SetWidth(1000)
-    Minimap:SetScale(1.5)
-    Minimap:SetScript("OnMouseDown", nil)
-
-    -- Remove Player-Arrow
-    Minimap:SetPlayerTexture("")
+D2MinimapSettings = {
+    ["Frames"] = {
+        ["Minimap"] = {
+            ["Shown"] = true,
+            ["MaskSquare"] = false,
+            ["Alpha"] = .1,
+        },
+        ["MinimapZoneTextButton"] = {
+            ["Alpha"] = .3,
+        },
+        ["MinimapBorderTop"] = {
+            ["Alpha"] = 1,
+        },
+        ["TimeManagerClockButton"] = {
+            ["Alpha"] = .3,
+        },
+        ["MiniMapWorldMapButton"] = {
+            ["Alpha"] = .8,
+        },
+        ["MiniMapTracking"] = {
+            ["Alpha"] = .2,
+        },
+        ["MiniMapMailFrame"] = {
+            ["Alpha"] = .5,
+        },
+        ["GarrisonLandingPageMinimapButton"] = {
+            ["Alpha"] = .2,
+        },
+    },
+}

-    -- Square the Map
-    Minimap:SetMaskTexture("Interface\\Buttons\\WHITE8X8")
-
-    Minimap:EnableMouse(false)
-
-    Minimap:SetZoom(5)
-    SetCVar("rotateMinimap", true)
+function D2Minimap_load()
+    for frame, ftable in pairs(D2MinimapSettings["Frames"]) do
+        pcall(function()
+            _G[frame]:SetAlpha(ftable["Alpha"])
+            p = ftable["Point"]
+            _G[frame]:SetPoint(p.point, p.relativeTo, p.relativePoint, p.xOfs, p.yOfs)
+        end)
+    end
+end
+
+function D2Minimap_save()
+    for frame, ftable in pairs(D2MinimapSettings["Frames"]) do
+        if not frame == "" then
+            pcall(function()
+                ftable["Alpha"] = _G[frame]:GetAlpha()
+                p = {}
+                p.point, p.relativeTo, p.relativePoint, p.xOfs, p.yOfs = _G[frame]:GetPoint()
+                ftable["Point"] = p
+            end)
+        end
+    end
+end
+
+local function D2Minimap_init(self, event, addon, ...)
+    if (event == "PLAYER_ENTERING_WORLD") then
+        Minimap:ClearAllPoints()
+        Minimap:SetParent(UIParent)
+        Minimap:SetAlpha(D2MinimapSettings["Frames"]["Minimap"]["Alpha"])
+        Minimap:SetFrameStrata("BACKGROUND")
+        Minimap:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
+        Minimap:SetHeight(1200)
+        Minimap:SetWidth(1200)
+        Minimap:SetScale(1.5)
+        Minimap:SetScript("OnMouseDown", nil)
+
+        -- Remove Player-Arrow
+        Minimap:SetPlayerTexture("")
+
+        -- Square the Map
+        if D2MinimapSettings["Frames"]["Minimap"]["MaskSquare"] then
+            Minimap:SetMaskTexture("Interface\\Buttons\\WHITE8X8")
+        end
+
+        Minimap:EnableMouse(false)
+
+        Minimap:SetZoom(5)
+        SetCVar("rotateMinimap", true)
+
+        -- MinimapZoneTextButton and MinimapBorderTop
+        MinimapZoneTextButton:SetParent(UIParent)
+        MinimapZoneTextButton:SetPoint("TOP", UIParent, "TOP", 0, 0)
+        MinimapZoneTextButton:SetAlpha(D2MinimapSettings["Frames"]["MinimapZoneTextButton"]["Alpha"])
+        MinimapBorderTop:SetParent(MinimapZoneTextButton)
+        MinimapBorderTop:ClearAllPoints()
+        MinimapBorderTop:SetPoint("TOP", MinimapZoneTextButton, "CENTER", 0, 15)
+
+        -- TimeManagerClockButton
+        TimeManagerClockButton:SetParent(UIParent)
+        TimeManagerClockButton:SetPoint("TOP", MinimapZoneTextButton, "BOTTOM", 0, 3);
+        TimeManagerClockButton:SetAlpha(D2MinimapSettings["Frames"]["TimeManagerClockButton"]["Alpha"])
+        TimeManagerClockButton:SetMovable(true)
+        TimeManagerClockButton:EnableMouse(true)
+        TimeManagerClockButton:RegisterForDrag("LeftButton")
+        TimeManagerClockButton:SetScript("OnDragStart", TimeManagerClockButton.StartMoving)
+        TimeManagerClockButton:SetScript("OnDragStop", TimeManagerClockButton.StopMovingOrSizing)

-    -- MinimapZoneTextButton and MinimapBorderTop
-    MinimapZoneTextButton:SetParent(UIParent)
-    MinimapZoneTextButton:SetPoint("TOP", UIParent, "TOP", 0, 0)
-    MinimapZoneTextButton:SetAlpha(.3)
-    MinimapBorderTop:SetParent(MinimapZoneTextButton)
-    MinimapBorderTop:ClearAllPoints()
-    MinimapBorderTop:SetPoint("TOP", MinimapZoneTextButton, "CENTER", 0, 15)
-
-    -- TimeManagerClockButton
-    TimeManagerClockButton:SetParent(UIParent)
-    TimeManagerClockButton:SetPoint("TOP", MinimapZoneTextButton, "BOTTOM", 0, 3);
-    TimeManagerClockButton:SetAlpha(.3)
+        -- MiniMapWorldMapButton
+        MiniMapWorldMapButton:SetParent(MinimapZoneTextButton)
+        MiniMapWorldMapButton:ClearAllPoints()
+        MiniMapWorldMapButton:SetPoint("TOP", MinimapZoneTextButton, "RIGHT", 28, 15)
+        MiniMapWorldMapButton:SetAlpha(D2MinimapSettings["Frames"]["MiniMapWorldMapButton"]["Alpha"])

-    -- MiniMapWorldMapButton
-    MiniMapWorldMapButton:SetParent(MinimapZoneTextButton)
-    MiniMapWorldMapButton:ClearAllPoints()
-    MiniMapWorldMapButton:SetPoint("TOP", MinimapZoneTextButton, "RIGHT", 28, 15)
-    MiniMapWorldMapButton:SetAlpha(.8)
+        -- MiniMapTracking
+        MiniMapTracking:SetParent(UIParent)
+        MiniMapTracking:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0);
+        MiniMapTracking:SetAlpha(D2MinimapSettings["Frames"]["MiniMapTracking"]["Alpha"])
+        MiniMapTracking:SetMovable(true)
+        MiniMapTracking:RegisterForDrag("RightButton")
+        MiniMapTracking:SetScript("OnDragStart", MiniMapTracking.StartMoving)
+        MiniMapTracking:SetScript("OnDragStop", MiniMapTracking.StopMovingOrSizing)

-    -- MiniMapTracking
-    MiniMapTracking:SetParent(UIParent)
-    MiniMapTracking:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0);
-    MiniMapTracking:SetAlpha(.2)
+        -- MiniMapMailFrame
+        MiniMapMailFrame:SetParent(UIParent)
+        MiniMapMailFrame:ClearAllPoints()
+        MiniMapMailFrame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 50);
+        MiniMapMailFrame:SetAlpha(D2MinimapSettings["Frames"]["MiniMapMailFrame"]["Alpha"])
+        MiniMapMailFrame:SetFrameStrata("BACKGROUND")
+        MiniMapMailFrame:SetMovable(true)
+        MiniMapMailFrame:EnableMouse(true)
+        MiniMapMailFrame:RegisterForDrag("LeftButton")
+        MiniMapMailFrame:SetScript("OnDragStart", MiniMapMailFrame.StartMoving)
+        MiniMapMailFrame:SetScript("OnDragStop", MiniMapMailFrame.StopMovingOrSizing)

-    -- MinimapZoneTextButton:SetMovable(true)
-    -- MinimapZoneTextButton:EnableMouse(true)
-    -- MinimapZoneTextButton:RegisterForDrag("LeftButton")
-    -- MinimapZoneTextButton:SetScript("OnDragStart", MinimapZoneTextButton.StartMoving)
-    -- MinimapZoneTextButton:SetScript("OnDragStop", MinimapZoneTextButton.StopMovingOrSizing)
+        -- GarrisonLandingPageMinimapButton
+        GarrisonLandingPageMinimapButton:SetParent(UIParent)
+        GarrisonLandingPageMinimapButton:ClearAllPoints()
+        GarrisonLandingPageMinimapButton:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0);
+        GarrisonLandingPageMinimapButton:SetAlpha(D2MinimapSettings["Frames"]["GarrisonLandingPageMinimapButton"]["Alpha"])
+        GarrisonLandingPageMinimapButton:SetFrameStrata("BACKGROUND")
+        GarrisonLandingPageMinimapButton:SetMovable(true)
+        GarrisonLandingPageMinimapButton:EnableMouse(true)
+        GarrisonLandingPageMinimapButton:RegisterForDrag("LeftButton")
+        GarrisonLandingPageMinimapButton:SetScript("OnDragStart", GarrisonLandingPageMinimapButton.StartMoving)
+        GarrisonLandingPageMinimapButton:SetScript("OnDragStop", GarrisonLandingPageMinimapButton.StopMovingOrSizing)

-    -- GarrisonLandingPageMinimapButton
-    GarrisonLandingPageMinimapButton:SetParent(UIParent)
-    GarrisonLandingPageMinimapButton:ClearAllPoints()
-    GarrisonLandingPageMinimapButton:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0);
-    GarrisonLandingPageMinimapButton:SetAlpha(.3)
-    GarrisonLandingPageMinimapButton:SetFrameStrata("BACKGROUND")
+        MinimapBorder:Hide()
+        MinimapZoomIn:Hide()
+        MinimapZoomOut:Hide()
+        -- MinimapCluster:Hide()
+        if not D2MinimapSettings["Frames"]["Minimap"]["Shown"] then
+            Minimap:Hide()
+        end
+    end

-    MinimapBorder:Hide()
-    MinimapZoomIn:Hide()
-    MinimapZoomOut:Hide()
-    -- MinimapCluster:Hide()
+    if (event == "ADDON_LOADED") then
+        D2Minimap_load()
+    end
+    if (event == "PLAYER_LOGOUT") then
+        D2Minimap_save()
+    end
 end

 local D2MinimapFrame = CreateFrame("Frame", "D2MinimapFrame", UIParent, "SecureHandlerStateTemplate")
 D2MinimapFrame:SetScript("OnEvent", D2Minimap_init)
+D2MinimapFrame:RegisterEvent("ADDON_LOADED")
 D2MinimapFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
+D2MinimapFrame:RegisterEvent("PLAYER_LOGIN")
+D2MinimapFrame:RegisterEvent("PLAYER_LOGOUT")

+-- Ingame Configuration
+configui = {}
+configui = CreateFrame( "Frame", "D2Minimap", UIParent )
+configui.name = "D2Minimap"
+configui.okay = nil
+configui.cancel = nil
+configui.default = nil
+InterfaceOptions_AddCategory(configui)
diff --git a/D2Minimap.toc b/D2Minimap.toc
index 89af003..963837c 100644
--- a/D2Minimap.toc
+++ b/D2Minimap.toc
@@ -1,7 +1,8 @@
 ## Interface: 80205
 ## Title: |cFF00CCCCD2|rMinimap
-## Version: 0.8
-## Notes: Shows your minimap as background - Diablo 2 Style
+## Version: 0.9
+## Notes: Shows your minimap as background - Diablo 2 Style | Keybinding ins "Interface Panel"
 ## Author: Darkretailer
+## SavedVariables: D2MinimapSettings

 D2Minimap.lua
\ No newline at end of file