WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Help with Minimap Button for Addon (https://www.wowinterface.com/forums/showthread.php?t=59590)

BloodDragon 05-25-23 03:59 AM

Help with Minimap Button for Addon
 
1 Attachment(s)
Hello at all, i need help with a minimap button for an addon.
I want to make a minimap button for it so you don't have to type /gt in the chat all the time.
it would be very nice if someone could help me with this.

BloodDragon 05-25-23 05:01 AM

That is what i have at this time.
lua:
Lua Code:
  1. MyMod_Settings = {
  2.     MinimapPos = 45
  3. }
  4.  
  5. function MyMod_MinimapButton_Reposition()
  6.     MyMod_MinimapButton:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(MyMod_Settings.MinimapPos)),(80*sin(MyMod_Settings.MinimapPos))-52)
  7. end
  8.  
  9. function MyMod_MinimapButton_DraggingFrame_OnUpdate()
  10.  
  11.     local xpos,ypos = GetCursorPosition()
  12.     local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()
  13.  
  14.     xpos = xmin-xpos/UIParent:GetScale()+70
  15.     ypos = ypos/UIParent:GetScale()-ymin-70
  16.  
  17.     MyMod_Settings.MinimapPos = math.deg(math.atan2(ypos,xpos))
  18.     MyMod_MinimapButton_Reposition()
  19. end
  20.  
  21. function MyMod_MinimapButton_OnClick()
  22.     DEFAULT_CHAT_FRAME.editBox:SetText("/gt")
  23.     ChatEdit_SendText(DEFAULT_CHAT_FRAME.editBox, 0)
  24. end

xml:
Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\FrameXML\UI.xsd">
  3.  
  4.     <Script file="GildenSteuerMiniMapButton.lua"/>
  5.  
  6.     <Button name="MyMod_MinimapButton" parent="Minimap" enableMouse="true" movable="true" hidden="false">
  7.         <Size>
  8.             <AbsDimension x="33" y="33"/>
  9.         </Size>
  10.         <Anchors>
  11.             <Anchor point="TOPLEFT"/>
  12.         </Anchors>
  13.         <Layers>
  14.             <Layer level="BACKGROUND">
  15.                 <Texture name="MyMod_MinimapButton_Icon" file="Interface\Icons\inv_misc_notefolded2a">
  16.                     <Size>
  17.                         <AbsDimension x="21" y="21"/>
  18.                     </Size>
  19.                     <Anchors>
  20.                         <Anchor point="TOPLEFT">
  21.                             <Offset>
  22.                                 <AbsDimension x="7" y="-6"/>
  23.                             </Offset>
  24.                         </Anchor>
  25.                     </Anchors>
  26.                 </Texture>
  27.             </Layer>
  28.             <Layer level="OVERLAY">
  29.                 <Texture file="Interface\Minimap\MiniMap-TrackingBorder">
  30.                     <Size>
  31.                         <AbsDimension x="56" y="56"/>
  32.                     </Size>
  33.                     <Anchors>
  34.                         <Anchor point="TOPLEFT"/>
  35.                     </Anchors>
  36.                 </Texture>
  37.             </Layer>
  38.         </Layers>
  39.         <Frames>
  40.             <Frame name="MyMod_MinimapButton_DraggingFrame" hidden="true">
  41.                 <Scripts>
  42.                     <OnUpdate>
  43.                         MyMod_MinimapButton_DraggingFrame_OnUpdate()
  44.                     </OnUpdate>
  45.                 </Scripts>
  46.             </Frame>
  47.         </Frames>
  48.         <HighlightTexture alphaMode="ADD" file="Interface\Minimap\UI-Minimap-ZoomButton-Highlight"/>
  49.         <Scripts>
  50.             <OnLoad>
  51.                 this:RegisterForClicks("LeftButtonUp","RightButtonUp")
  52.                 this:RegisterForDrag("LeftButton","RightButton")
  53.             </OnLoad>
  54.             <OnDragStart>
  55.                 this:LockHighlight()
  56.                 MyMod_MinimapButton_DraggingFrame:Show()
  57.             </OnDragStart>
  58.             <OnDragStop>
  59.                 this:UnlockHighlight()
  60.                 MyMod_MinimapButton_DraggingFrame:Hide()
  61.             </OnDragStop>
  62.             <OnClick>
  63.                 MyMod_MinimapButton_OnClick() -- do your thing in here, arg1 is mouse button clicked
  64.             </OnClick>
  65.         </Scripts>
  66.     </Button>
  67. </Ui>
But i cant move the Button. And I will add a tooltip for it.

Fizzlemizz 05-25-23 09:02 AM

The easiest way to create an MM button for your addon is with LibDbIcon as it makes creating, moving, tooltips, clickable sub-menus and Addon Compartment compliance etc. pretty effortless.

If you're just more interested in the mechanics of making a frame movable using the mouse, see

BloodDragon 05-27-23 02:09 AM

Thx 4 the help it can be close.


All times are GMT -6. The time now is 11:28 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI