1. #1
    Deleted

    How to hide minimap button from interface? LUA

    Hi, so I have this code
    Code:
    function LoadMinimapButton()
    
    	local dragMode = nil --"free", nil
    	
    	local function moveButton(self)
    		if dragMode == "free" then
    			local centerX, centerY = Minimap:GetCenter()
    			local x, y = GetCursorPosition()
    			x, y = x / self:GetEffectiveScale() - centerX, y / self:GetEffectiveScale() - centerY
    			self:ClearAllPoints()
    			self:SetPoint("CENTER", x, y)
    		else
    			local centerX, centerY = Minimap:GetCenter()
    			local x, y = GetCursorPosition()
    			x, y = x / self:GetEffectiveScale() - centerX, y / self:GetEffectiveScale() - centerY
    			centerX, centerY = math.abs(x), math.abs(y)
    			centerX, centerY = (centerX / math.sqrt(centerX^2 + centerY^2)) * 76, (centerY / sqrt(centerX^2 + centerY^2)) * 76
    			centerX = x < 0 and -centerX or centerX
    			centerY = y < 0 and -centerY or centerY
    			self:ClearAllPoints()
    			self:SetPoint("CENTER", centerX, centerY)
    		end
    	end
    
    	local button = CreateFrame("Button", "DPMMinimapButton", Minimap)
    	button:SetHeight(25)
    	button:SetWidth(25)
    	button:SetFrameStrata("MEDIUM")
    	button:SetPoint("CENTER", 75.70,-6.63)
    	button:SetMovable(true)
    	button:SetUserPlaced(true)
    	button:SetNormalTexture("Interface\\HelpFrame\\HotIssueIcon.blp")
    	button:SetPushedTexture("Interface\\HelpFrame\\HotIssueIcon.blp")
    	button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-Background.blp")
    	
    	button:SetScript("OnMouseDown", function(self, button)
    		if IsShiftKeyDown() and IsAltKeyDown() then
    			dragMode = "free"
    			self:SetScript("OnUpdate", moveButton)
    		elseif IsShiftKeyDown() or button == "RightButton" then
    			dragMode = nil
    			self:SetScript("OnUpdate", moveButton)
    		end
    	end)
    	button:SetScript("OnMouseUp", function(self)
    		self:SetScript("OnUpdate", nil)
    	end)
    	button:SetScript("OnClick", function(self, button)
    		if IsShiftKeyDown() or button == "RightButton" then return end
    		DPMShowInterface()
    	end)
    	button:SetScript("OnEnter", function(self)
    		GameTooltip_SetDefaultAnchor(GameTooltip, self)
    		GameTooltip:SetText("Deadly Pvp Mods", 1, 1, 0)
    		GameTooltip:AddLine("version: "..DPM_version.." ",0, 1, 1, 1)
    		GameTooltip:AddLine(" ")
    		GameTooltip:AddLine("Shift+click or right-click to move\nAlt+shift+click for free drag&drop", 1, 1,1, 1)
    		GameTooltip:Show()
    	end)
    	button:SetScript("OnLeave", function(self)
    		GameTooltip:Hide()
    	end)
    end
    I want to make a box at interface addon menu and hide or show by clicking there. Can you help me?

  2. #2
    Deleted
    Try adding this at the bottom of your function:
    Code:
    local frame = CreateFrame("Frame")
    frame.name = "Deadly Pvp Mods"
    InterfaceOptions_AddCategory(frame)
    
    local option = CreateFrame("CheckButton", nil, frame, "InterfaceOptionsCheckButtonTemplate")
    option:SetPoint("TOPLEFT", 32, -32)
    option:SetChecked(button:IsShown())
    option:SetText("Show minimap button")
    option:SetScript("OnClick", function(self)
    	button:SetShown(self:GetChecked())
    end)

  3. #3
    Deleted
    I added this code but since there is already a frame called DPM_MFrame I couldnt
    Code:
    local frame = CreateFrame("Frame")
    frame.name = "Deadly Pvp Mods"
    InterfaceOptions_AddCategory(frame)
    since it adds a second menu in interface.

    So I used the second part of your code like this
    Code:
    	local option = CreateFrame("CheckButton", nil, DPM_Mframe, "InterfaceOptionsCheckButtonTemplate")
    	option:SetPoint("CENTER", 32,-32)
    	option:SetChecked(button:IsShown())
    	option:SetText("Show minimap button")
    	option:SetScript("OnClick", function(self)
    	button:SetShown(self:GetChecked())
    	end)
    Now the button works as it should but the problem is that its not at the interface but at my UI so I see it all the time:P
    So what am I doing wrong? How can I put it in the addon options menu? :S

    Thanks for your answer!

  4. #4
    Deleted
    That would indicate that it was unable to find the frame called DPM_Mframe. Make sure it's spelt correctly, and that it's global.

  5. #5
    Deleted
    Well you were right about spelling correctly (if you see my previous reply I had DPM_Mframe instead of DPM_MFrame, so now its in the options and works.
    But the problem now is that the setting doesn't save itself. Its always ticked so it shows button but if you untick it and relog its ticked again!

  6. #6
    Deleted
    Well, you have to tell it whether or not it should be checked. Add a SavedVariable entry for it, modify that in the OnClick, then restore its state in your addon's ADDON_LOADED.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •