WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Creating minimap buttons (https://www.wowinterface.com/forums/showthread.php?t=2762)

Vayder 12-31-05 09:08 PM

Creating minimap buttons
 
Is there a guide outthere somewhere that explains how to do this? theres a couple mods i use that id like to be able to create minimap buttons for. thanks

Gello 01-01-06 06:58 AM

Hmm this would make an excellent template. I'll flesh one out with a "push" effect and options for "FFA" movement for square minimaps to post later. But this is one style of minimap button. Instead of the slider in options you drag the button directly.

For the icon you can use any square image in place of Interface\Icons\INV_Misc_QuestionMark. Any of the Interface\Icon files in interface.mpq will work fine as the file of MyMod_MinimapButton_Icon.

Assuming your mod is named MyMod, and your SavedVariables settings is MyMod_Settings (feel free to change the convention and replace _ with . or use entirely different means):

In the xml, just before the closing </Ui> add a new Button (ordinarily you'd expect a <Frame> at this level but a Button is just fine):

Code:

        <Button name="MyMod_MinimapButton" parent="Minimap" enableMouse="true" movable="true" hidden="false">
                <Size>
                        <AbsDimension x="33" y="33"/>
                </Size>
                <Anchors>
                        <Anchor point="TOPLEFT"/>
                </Anchors>
                <Layers>
                        <Layer level="BACKGROUND">
                                <Texture name="MyMod_MinimapButton_Icon" file="Interface\Icons\INV_Misc_QuestionMark">
                                        <Size>
                                                <AbsDimension x="21" y="21"/>
                                        </Size>
                                        <Anchors>
                                                <Anchor point="TOPLEFT">
                                                        <Offset>
                                                                <AbsDimension x="7" y="-6"/>
                                                        </Offset>
                                                </Anchor>
                                        </Anchors>
                                </Texture>
                        </Layer>
                        <Layer level="OVERLAY">
                                <Texture file="Interface\Minimap\MiniMap-TrackingBorder">
                                        <Size>
                                                <AbsDimension x="56" y="56"/>
                                        </Size>
                                        <Anchors>
                                                <Anchor point="TOPLEFT"/>
                                        </Anchors>
                                </Texture>
                        </Layer>
                </Layers>
                <Frames>
                        <Frame name="MyMod_MinimapButton_DraggingFrame" hidden="true">
                                <Scripts>
                                        <OnUpdate>
                                                MyMod_MinimapButton_DraggingFrame_OnUpdate()
                                        </OnUpdate>
                                </Scripts>
                        </Frame>
                </Frames>
                <HighlightTexture alphaMode="ADD" file="Interface\Minimap\UI-Minimap-ZoomButton-Highlight"/>
                <Scripts>
                        <OnLoad>
                                this:RegisterForClicks("LeftButtonUp","RightButtonUp")
                                this:RegisterForDrag("LeftButton","RightButton")
                        </OnLoad>
                        <OnDragStart>
                                this:LockHighlight()
                                MyMod_MinimapButton_DraggingFrame:Show()
                        </OnDragStart>
                        <OnDragStop>
                                this:UnlockHighlight()
                                MyMod_MinimapButton_DraggingFrame:Hide()
                        </OnDragStop>
                        <OnClick>
                                MyMod_MinimapButton_OnClick() -- do your thing in here, arg1 is mouse button clicked
                        </OnClick>
                </Scripts>
        </Button>

In your lua:
Code:

-- add this to your SavedVariables or as a separate SavedVariable to store its position
MyMod_Settings = {
        MinimapPos = 45 -- default position of the minimap icon in degrees
}

-- Call this in a mod's initialization to move the minimap button to its saved position (also used in its movement)
-- ** do not call from the mod's OnLoad, VARIABLES_LOADED or later is fine. **
function MyMod_MinimapButton_Reposition()
        MyMod_MinimapButton:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(MyMod_Settings.MinimapPos)),(80*sin(MyMod_Settings.MinimapPos))-52)
end

-- Only while the button is dragged this is called every frame
function MyMod_MinimapButton_DraggingFrame_OnUpdate()

        local xpos,ypos = GetCursorPosition()
        local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()

        xpos = xmin-xpos/UIParent:GetScale()+70 -- get coordinates as differences from the center of the minimap
        ypos = ypos/UIParent:GetScale()-ymin-70

        MyMod_Settings.MinimapPos = math.deg(math.atan2(ypos,xpos)) -- save the degrees we are relative to the minimap center
        MyMod_MinimapButton_Reposition() -- move the button
end

-- Put your code that you want on a minimap button click here.  arg1="LeftButton", "RightButton", etc
function MyMod_MinimapButton_OnClick()
        DEFAULT_CHAT_FRAME:AddMessage(tostring(arg1).." was clicked.")
end

Basically the XML consists of three major elements:
- The icon texture in a BACKGROUND layer
- The minimap tracking border in an OVERLAY layer to put the circle around the icon
- A frame named MyMod_MinimapButton_DraggingFrame whose sole purpose is to contain an OnUpdate

Its events:
OnLoad: register the button for dragging and also for the "RightButtonUp" to register as a click (so you can use left and right clicks on the button)
OnDragStart: start the OnUpdate which continually updates its position relative to cursor
OnDragStop: stop the OnUpdate entirely
OnClick: this function is where you'd put your code

In the lua:
MyMod_Settings: the SavedVariable. Make sure all references to this are the same.
MyMod_MinimapButton_Reposition: Moves the minimap button. Use in VARIABLES_LOADED, PLAYER_LOGIN, PLAYER_ENTERING_WORLD, or any event after VARIABLES_LOADED and frames are rendered (which seems to be before VARIABLES_LOADED nowadays).
MyMod_MinimapButton_DraggingFrame_OnUpdate: This moves the button in relationship to the current mouse position and the center of the minimap. It *only* runs while the button is being dragged.
MyMod_MinimapButton_OnClick: This is where you put your code for when the button is clicked.

You can use OnMouseDown and OnMouseUp instead of OnDragStart/OnDragStop, but since the buttons are moved infrequently the latter seems a safer alternative so users don't accidentally move the button just by clicking it a little awkwardly. If you use OnMouseDown or OnMouseUp you may want to check IsShiftKeyDown() or something similar.

tinyu 12-27-06 11:09 AM

can i get your help with this i dont completly understand what to do

ilimo 07-05-09 12:25 PM

damn Gello

you are a genious

everything workig just by putting your codes as you said

only thing , i changed in xml part :: at line : 6
TOPLEFT to BOTTOM to see the icone

it needs some offset, but well

thkx again to have shared your knowledge

:)

Drshow 07-14-09 10:01 PM

:cool:Here is a downloadable copy, perhaps it will help someone who happens to stumble accross this thread

http://www.wowinterface.com/download...onoptions.html

Options to show/hide the minimap button frame are included.

shurshik 10-30-09 07:57 AM

Thanks :) It's working, but... how to add tooltip info onmouseover? :(

Update: did it! By adding:
xml scripts:
Code:

<Scripts>
                        <OnLoad>
                                this:RegisterForClicks("LeftButtonUp","RightButtonUp")
                                this:RegisterForDrag("LeftButton","RightButton")
                        </OnLoad>
                        <OnEnter>
                                if (not self.dragging) then
                                        PS_MinimapButton_OnEnter(self)
                                end
                        </OnEnter>
                        <OnLeave>
                                GameTooltip:Hide()
                        </OnLeave>
                        <OnDragStart>
                                self.dragging = true
                                GameTooltip:Hide()
                                this:LockHighlight()
                                PS_MinimapButton_DraggingFrame:Show()
                        </OnDragStart>
                        <OnDragStop>
                                self.dragging = false
                                this:UnlockHighlight()
                                PS_MinimapButton_DraggingFrame:Hide()
                        </OnDragStop>
                        <OnClick>
                                PS_MinimapButton_OnClick() -- do your thing in here, arg1 is mouse button clicked
                        </OnClick>
                </Scripts>

LUA:
Code:

function PS_MinimapButton_OnEnter(self)
        if (self.dragging) then
                return
        end
        GameTooltip:SetOwner(self or UIParent, "ANCHOR_LEFT")
        PS_MinimapButton_Details(GameTooltip)
end


function PS_MinimapButton_Details(tt, ldb)
        tt:SetText("PhoenixStyle")

end



All times are GMT -6. The time now is 03:07 AM.

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