Thread Tools Display Modes
05-17-08, 08:27 AM   #1
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Minimap button

Hi again! I'd like to write a minimapbutton in lua that shows/hides my frame depending on the button i pressed. I've seen alot of them made, but never explained for newbs, and trying to steal some code will result in copy-pasta..

Please help!
  Reply With Quote
05-17-08, 08:58 AM   #2
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Code:
CreateFrame('Button', <Frame Name>, Minimap)
And use trig to place the button around the minimap, using :SetPoint(). Maybe take a look at Bongos 3 Minimap code.
  Reply With Quote
05-17-08, 11:44 AM   #3
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Man i suck at coding at times.. I read, ripped, scratched, petted and mended the code from bongos3's minimap code. But i can't make the damn button appear. I get no errors, but nothing shows. I'll paste the code here. (Yes, i made it orange for easy read).
Code:
local MinimapButton = CreateFrame('Button', "MainMenuBarToggler", Minimap)

function MinimapButton:Load()
    self:SetFrameStrata('HIGH')
    self:SetWidth(31)
    self:SetHeight(31)
    self:SetFrameLevel(8)
    self:RegisterForClicks('anyUp')
    self:SetHighlightTexture('Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight')

    local overlay = self:CreateTexture(nil, 'OVERLAY')
    overlay:SetWidth(53)
    overlay:SetHeight(53)
    overlay:SetTexture('Interface\\Minimap\\MiniMap-TrackingBorder')
    overlay:SetPoint('TOPLEFT')

    local icon = self:CreateTexture(nil, 'BACKGROUND')
    icon:SetWidth(20)
    icon:SetHeight(20)
    icon:SetTexture('Interface\\Icons\\Spell_ChargeNegative')
    icon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
    icon:SetPoint('TOPLEFT', 7, -5)
    self.icon = icon

    self:SetScript('OnClick', self.OnClick)

    self:SetPoint("BOTTOMRIGHT", Minimap, "BOTTOMRIGHT", -2, 2)
end
     
  function MinimapButton:OnClick(button)
    if button == 'LeftButton' then
        MainMenuBar:ClearAllPoints()
        MainMenuBar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, -300)
    elseif button == 'RightButton' then
        MainMenuBar:ClearAllPoints()
        MainMenuBar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 10)
    end
end 
Edit: Changed the color of the code and cleaned it up a bit for people wanting to steal it...

Last edited by hipjipp : 05-18-08 at 09:31 AM. Reason: cleanup
  Reply With Quote
05-17-08, 12:15 PM   #4
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
You will undoubtably kick yourself for this but add
Code:
MinimapButton:Load()
to the end.

Also why have you got
Code:
local B = CreateFrame('Button', "MainMenuBarToggler", Minimap)
local MinimapButton = B
wouldn't
Code:
local MinimapButton = CreateFrame('Button', "MainMenuBarToggler", Minimap)
achieve exactly the same thing?

and you have no drag enter leave etc. functions so arn't all the :SetScript() pointless
Code:
    self:SetScript('OnEnter', self.OnEnter)
    self:SetScript('OnLeave', self.OnLeave)
    self:SetScript('OnClick', self.OnClick)
    self:SetScript('OnDragStart', self.OnDragStart)
    self:SetScript('OnDragStop', self.OnDragStop)
    self:SetScript('OnMouseDown', self.OnMouseDown)
    self:SetScript('OnMouseUp', self.OnMouseUp)
appart from
Code:
    self:SetScript('OnClick', self.OnClick)

and finally you have already set the parent of the button to Minimap in
Code:
CreateFrame('Button', "MainMenuBarToggler", Minimap)
so why do you do it in :Load()
Code:
self:SetParent(Minimap)
  Reply With Quote
05-17-08, 12:30 PM   #5
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
*Slaps forehead* Yeah.. Gonna fix it now.. Really long day, thanks for helping me even though i keep asking newb questions.

Edit: about all the extra unneeded code, i tried some of them since i couldnt find what was causing (or in this case, not causing) the button to not appear. And the extra script code, i just didn't think about it at the time.

Last edited by hipjipp : 05-17-08 at 12:47 PM.
  Reply With Quote
05-17-08, 02:14 PM   #6
Sepioth
A Molten Giant
AddOn Author - Click to view addons
Join Date: Apr 2005
Posts: 894
Originally Posted by hipjipp View Post
(Yes, i made it orange for easy read).
FYI ... it's not easy to read on the Light version of the website cause the background is a beige color. Just thought I would let you know
  Reply With Quote
05-18-08, 09:31 AM   #7
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Fixed it, cleaned the code and it will be on the site later tonight for people wanting to use it. =)
  Reply With Quote
02-03-09, 08:43 AM   #8
Nuckin
is laughing at you
 
Nuckin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 58
I hate to bump an old thread, but how well does this script work? achieve basic minimap button functionality in 30000+ interface?

If so I would love to integrate this into my addon
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Minimap button


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off