Mercurial > wow > inventory
view Widgets.lua @ 62:fee06221176f
Seperated the config from Core.lua.
Many other code cleaning up for readability.
Added local references for much used globals.
Moved widgets to a different file for readability.
Re-added global function for slash command handling since we do need it for our chat-hyperlinks.
Fixed queueing to properly use the track at property of virtual groups.
Fixed queueing to display the item id instead of the item link if the item link could not be loaded.
Speed slider at the summary now has an interval of 1% down from 5% and rounds rather than ceils it?s value so 101% will become 100% rather than 105%.
Now using the right stock properties at the summary.
Added a help group to the config.
author | Zerotorescue |
---|---|
date | Wed, 22 Dec 2010 19:56:55 +0100 |
parents | |
children | 6216b754350d |
line wrap: on
line source
local addon = select(2, ...); local Widgets = addon:NewModule("Widgets"); local AceGUI = LibStub("AceGUI-3.0"); function Widgets:ItemLinkButton() --[[ [ ItemLinkButton ] This custom widget has to show an icon with the item link next to it. Upon hover it must show the item tooltip. Upon click it must execute the function provided through user data. UserData: itemId, onClickEvent OnEnter: tooltip show OnLeave: tooltip hide OnClick: UserData.onClickEvent ]] local widgetType = "ItemLinkButton"; local widgetVersion = 1; local function Constructor() local widget = AceGUI:Create("InteractiveLabel"); widget.type = widgetType; -- We overwrite the OnAcquire as we want to set our callbacks even -- when the widget is re-used from the widget pool widget.originalOnAcquire = widget.OnAcquire; widget.OnAcquire = function(self, ...) -- We overwrite the setcallback because we don't want anything else -- to overwrite our OnEnter, OnLeave and OnClick events -- which would be done by the AceConfigDialog after a widget gets re-used if not self.originalSetCallBack then self.originalSetCallBack = self.SetCallback; self.SetCallback = function(this, event, func, ...) if event == "OnEnter" or event == "OnLeave" or event == "OnClick" then -- Don't allow overwriting of these events return; elseif event == "CustomOnEnter" then return this.originalSetCallBack(this, "OnEnter", func, ...); elseif event == "CustomOnLeave" then return this.originalSetCallBack(this, "OnLeave", func, ...); elseif event == "CustomOnClick" then return this.originalSetCallBack(this, "OnClick", func, ...); else return this.originalSetCallBack(this, event, func, ...); end end; end -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions self:SetCallback("CustomOnEnter", function(this) local itemId = this:GetUserData("itemId"); if itemId then GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT"); GameTooltip:SetHyperlink(("item:%d"):format(itemId)); GameTooltip:Show(); end end); self:SetCallback("CustomOnLeave", function(this) GameTooltip:Hide(); end); self:SetCallback("CustomOnClick", function(this, ...) -- Below is used in child widgets to prepare for onclick if this.OnClick then this.OnClick(this, ...); end local func = this:GetUserData("exec"); local itemId = this:GetUserData("itemId"); if func then -- If this is a config option we will need the group id local path = this:GetUserData("path"); local groupId = (path and path[2]) or nil; func(groupId, itemId, ...); end end); -- Then also do whatever it wanted to do self.originalOnAcquire(self, ...); end; -- Remember the original SetText as this might get overwritten by the config-widget widget.originalSetText = widget.SetText; widget.SetItemId = function(self, itemId) self:SetUserData("itemId", itemId); -- Put the icon in front of it self:SetImage(GetItemIcon(itemId)); -- Standardize the size self:SetImageSize(16, 16); -- Make readable font self:SetFontObject(GameFontHighlight); -- We don't want to set the itemId as text, but rather the item link, so get that. local itemLink = select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId); self:originalSetText(itemLink); end; return widget; end AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion); end function Widgets:ConfigItemLinkButton() -- Define out custom item link button widget -- This will be called as if it's an input element, we overwrite some of the related functions which are called for default input fields local widgetType = "ConfigItemLinkButton"; local widgetVersion = 1; -- Empty function for disabling functions local function Dummy() end -- Makes an instance of our ItemLinkButton widget local function GetItemLinkButton() local widget = AceGUI:Create("ItemLinkButton"); widget.type = widgetType; -- We can only provide custom widgets for input, select and multiselect fields -- Input being the simplest, we use that - however, it provides two parameters: label and text. We only need one, disable the other. widget.SetLabel = Dummy; -- SetText is called when this button is being created and contains the itemId -- Forward that itemId to the ItemLinkButton widget.SetText = function(self, value, ...) if value and tonumber(value) then self:SetItemId(tonumber(value)); end end; widget.OnClick = function(self, ...) local option = self:GetUserData("option"); if option and option.set then self:SetUserData("exec", option.set); end end; return widget; end AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion); end function Widgets:InlineGroupWithButton() -- Register InlineGroupWithButton-widget -- This widget adds a button next to the header of an inline group -- SetPoint doesn't seem usable within AceGUI. local widgetType = "InlineGroupWithButton"; local widgetVersion = 1; local function Constructor() local widget = AceGUI:Create("InlineGroup"); widget.type = widgetType; widget.MakeButton = function(self, buttonSettings) if type(buttonSettings) == "table" then if not self.btnQueue then -- Because widgets are re-used, we don't want to recreate this button self.btnQueue = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate"); self.btnQueue:SetHeight(22); self.btnQueue:SetWidth(120); end self.btnQueue:SetText(buttonSettings.name); self.btnQueue:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5); -- Triggers self.btnQueue:SetScript("OnClick", buttonSettings.exec); -- Tooltip self.btnQueue.tooltipTitle = buttonSettings.name; self.btnQueue.tooltip = buttonSettings.desc or ""; self.btnQueue:SetScript("OnEnter", ShowTooltip); self.btnQueue:SetScript("OnLeave", HideTooltip); else error("settings must be a table - usage: MakeButton(table);"); end end; return widget; end AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion); end