Quantcast
Channel: WoWInterface - Latest Updated list
Viewing all articles
Browse latest Browse all 48885

Leatrix Dropdown (5.0.00)

$
0
0
A developer addon for World of Warcraft by Leatrix
8708654What does it do?

Leatrix Dropdown is a developer addon. It allows you, as a developer, to add taint-free dropdown menus to your addon. It consists of a global function which makes it easy to create your dropdown menus. A full demonstration panel is included which consists of 3 dropdown menus (see the screenshot to the right).

Origins

During the development of Leatrix Plus (more specifically, the option to anchor the tooltip to the mouse), it became clear to me that I needed a dropdown menu system in order to allow the user to choose the tooltip anchor that they wish to use.

That presented a problem as I wanted the dropdown menu to work completely taint-free (even during combat). However, it's well known to the developer community that usage of the Blizzard API for creating and manipulating dropdown menus is perhaps the biggest cause of taint in the history of the game. Lots of addons suffer from taint purely because they use the Blizzard API for their dropdown menu system.

To avoid the same problem in Leatrix Plus, I set about creating a dropdown menu system which worked completely independently of the Blizzard API. Up until now, that code has only existed in Leatrix Plus so I'm releasing it here with the intention that other developers can look at it and perhaps use it (or parts of it) in their own addons.

The overall aim of Leatrix Dropdown is to spread the use of dropdown menus which don't cause taint. Feel free to look at the code, change it if you wish and incorporate it into your own addons.

First Impressions

The first thing that you should do is to install Leatrix Dropdown like any other addon. Next, load Wow and then take a look at the panel shown on the screen. This is the best way to see how Leatrix Dropdown works. If you close the panel, you can show it again by entering /ldd or /leadropdown.

Clicking a dropdown menu will report the details of what you have clicked in the chat frame. This includes the dropdown menu name, the item text for the item that you have clicked and the selected item value. Clicking a dropdown menu to open it will automatically close any dropdown menus which are already open.

Clicking the red button underneath will show the dropdown names and selected item values for all three dropdown menus.

Leatrix_Dropdown.lua

Inside the addon, there is a file called Leatrix_Dropdown.lua. This contains a global function called Leatrix_Dropdown:Create. This is the function which creates the dropdown. You don't need to modify this at all, you just need to call it with some arguments when you're ready to create your dropdown menu (more on this shortly).

There is another function in Leatrix_Dropdown.lua. It's at the bottom of the file and it's called Leatrix_Dropdown:Clicked. This function runs when an item in any dropdown menu has been clicked. It prints the dropdown menu name, the selected item text and the selected item value. Obviously, you will need to modify this function to your own preference.

To do that, you should -- out the line in the function which prints the chat frame message (since you won't want that, obviously) and add code which saves the variables according to your own addon structure.

For example, you might use MyAddon = item. This will save the selected dropdown item value in a table called MyAddon (where name is the dropdown name). It's entirely up to you what you choose to put in this function. All the variables that you need are provided (dropdown name, selected item text and selected item value), all you have to do is to store those variables in your own addon structure.

It's worth noting that you can move Leatrix_Dropdown:Clicked to another file if you wish (since Leatrix_Dropdown is global). It doesn't need to stay in Leatrix_Dropdown.lua, it could go in MyAddon.lua, for example.

Leatrix_Dropdown.toc

Obviously, this is the table of contents file. There is only one thing to note here and that is that the Leatrix_Dropdown.lua line (inside Leatrix_Dropdown.toc) needs to go inside your own addon's .toc file before any of your code runs which calls the dropdown function or manipulates the dropdown vaues.

MyAddon.lua

This file represents what your own addon code might look like. The code in this file creates and shows the dropdown menus as well as the panel that they are placed on.

The first block of code in the file creates the panel, adds a title, a close button and slash command support. Obviously, you will already have these things in your own addon but they are provided here so that you can see Leatrix Dropdown in use as soon as you install it.

The second block of code creates the dropdown menus (three of them) and a button to show the selected item value for each menu.

To create a dropdown menu, the Leatrix_Dropdown:Create function is called with some arguments, like this:

Leatrix_Dropdown:Create("Classes", "Which class?", Panel, 146, "TOPLEFT", 16, -90, 1, {"MAGE", "PALADIN", "WARRIOR", "WARLOCK", "PRIEST", "ROGUE", "DRUID", "HUNTER", "MONK", "SHAMAN", "DEATH KNIGHT"})


That will create a dropdown menu called "Classes". The label will be set to "Which class?", the width of the dropdown will be 146, the anchor will be "TOPLEFT", and the X and Y coordinates of the dropdown will be 16 and -90.

The default selected item will be 1 and the dropdown items will be a list of classes.

That's all you need to do to create a dropdown menu. Obviously, instead of 1 for the default value, you could use one of your own variables (such as a saved variable that the user selected last time). The other two dropdowns are created in exactly the same way.

Under the three lines to create the dropdown menus, there is some code to create a simple button which shows the selected items for each dropdown. This is included so that you can see how to reference the items in your own code. It's just a matter of printing Leatrix_Dropdown, such as Leatrix_Dropdown. Since Leatrix_Dropdown is global, you can retrieve the selected item values from anywhere in your addon, or even from within the game by entering this:

/script print(Leatrix_Dropdown)



Obviously, you would replace "Classes" with whatever dropdown name you want to retrieve the selected item value for.

Usage Notes

Use Leatrix Dropdown (or parts of it) in your own addons however you wish. The point of Leatrix Dropdown is not to be a popular addon in itself. The point is to spread and encourage the use of taint-free dropdown menus in World of Warcraft addons. If you want to use Leatrix Dropdown as it is, you can do that, just follow the included demonstration as an example.

Alternatively, look at the function code itself and incorpoate it into your own addon with your own changes. If the end result is a dropdown menu which doesn't taint then it really doesn't matter how that is achieved.

Updates

If you want to be notified when a new version of Leatrix Dropdown is available (recommended), make a free Wowinterface account and add Leatrix Dropdown to your Wowinterface favorites. You will be sent an email when a new version is out. It's important to read the notes in the change log (tab at the top of this page) before installing an update. Sometimes, options are changed and user action may be required.

More

Visit Leatrix Projects here on Wowinterface.com for a full list of available downloads.

Leatrix projects are ONLY hosted on Leatrix.com and Wowinterface.com. Leatrix software hosted anywhere else is NOT genuine and could contain viruses. Stay safe online and use only genuine Leatrix sites.

Viewing all articles
Browse latest Browse all 48885

Trending Articles