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
02-03-09, 03:48 PM   #9
Arabeth
A Black Drake
 
Arabeth's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2006
Posts: 84
I looked at this same thread just this week for exactly the same reason. Other than me modifying it to handle right clicks only and changing the background texture, the code works a treat.

Edit:Not that modifying it caused a problem, just that's what I did to the code.
__________________
Beth
  Reply With Quote
03-01-09, 05:49 PM   #10
eliljey
A Deviate Faerie Dragon
Join Date: Feb 2009
Posts: 14
I'm still coming up to speed on all this stuff and am not able to get this to work. I can only assume that this is because the code is taken out of context so I'm putting it in the wrong place or handling it wrong.

First, I get the CreateFrame line but where does that go? Anywhere in the body of the addon or does it need to live inside of a specific function?

Second, what calls the :Load() function for the button frame? Do I need to register an event for the frame to cause it to trigger the load?
  Reply With Quote
03-01-09, 06:20 PM   #11
DreamStorm
A Deviate Faerie Dragon
 
DreamStorm's Avatar
Join Date: Feb 2009
Posts: 15
In hipjipp's example, because the variable assigned to the frame has been declared 'local', I would place it at the top of the *.lua file; that is, outside any other function declaration or whatever. That way it can be referenced by any function/variable in that lua file. But only in that lua file.

If you declared it like this:

Code:
MinimapButton = CreateFrame('Button', "MainMenuBarToggler", Minimap);
then 'MinimapButton' would be a global variable and could effectively be seen by your and (technically) any other addon you were running in your current WoW session. In that case it actually wouldn't mater where you put the CreateFrame. It is a matter of what is called scope. Reading this will give you a good idea.

As to the second part, you are correct in thinking you need an event to fire the :Load() method. Something like this:

Code:
MinimapButton:RegisterEvent("PLAYER_ENTERING_WORLD");

MinimapButton:SetScript("OnEvent", function (self, event, addon)

     if(event == "PLAYER_ENTERING_WORLD") then
             MinimapButton:Load();
             MinimapButton:UnregisterEvent("PLAYER_ENTERING_WORLD");
             OnEvent = nil;
     end

end);
In the example above, you don't strictly need the conditional that checks for the type of event as there is only one registered, but you could have more events registered, in which case you would need a series of conditionals to allow the right code to fire from the appropriate event. Hope that helps.
__________________


ultima ratio regum
  Reply With Quote
03-02-09, 03:26 AM   #12
eliljey
A Deviate Faerie Dragon
Join Date: Feb 2009
Posts: 14
Thanks for all the help. I wasn't able to get it to work using PLAYER_ENTERING_WORLD but ADDON_LOADED worked. Close enough. Now to figure out how to let the user move it around the minimap....
  Reply With Quote
03-02-09, 11:24 AM   #13
DreamStorm
A Deviate Faerie Dragon
 
DreamStorm's Avatar
Join Date: Feb 2009
Posts: 15
Originally Posted by eliljey View Post
Thanks for all the help. I wasn't able to get it to work using PLAYER_ENTERING_WORLD but ADDON_LOADED worked. Close enough. Now to figure out how to let the user move it around the minimap....
Hmmm. I was wondering why that would be as it works for me; until I looked at my own code and I realised I had copy pasted the wrong OnEvent handler function (I modified it after pasting but not the args). My actual button code is this:

Code:
--Create the button
dStormButton = CreateFrame("Button", "dStormButton", UIParent, "SecureActionButtonTemplate");

--Register the appropriate event
dStormButton:RegisterEvent("PLAYER_ENTERING_WORLD");

--Set the functionality for the event
dStormButton:SetScript("OnEvent", function()
    dStormButton:initialiseButton();
    dStormButton:UnregisterEvent("PLAYER_ENTERING_WORLD");
    OnEvent = nil;
end);
Can anyone tell me if the fact that the above code has no arguments to the scripted function (compared to the code I posted last) would make a difference in whether or not it would run under PLAYER_ENTERING_WORLD?

Thanks in advance.

P.S. Sorry for any duff advice! :-(
__________________


ultima ratio regum

Last edited by DreamStorm : 03-02-09 at 11:26 AM.
  Reply With Quote

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

Thread Tools
Display Modes

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