comparison Modules/Widgets.lua @ 84:3bec0ea44607

Cleaned the Inventorium folder; moved all classes to classes directory, modules to modules directory and support addons to plugins directory. In addition support addons are now references within XML files rather than inside the TOC. Fixed the default local item count setting, you can now exclude bag and AH data from it. Fixed some mover algorithm bugs. Mover can no longer freeze the game but instead will terminate the process after a 1000 passes. Now reversing the moves table after making it, rather than every single time it is used. Fixed guild bank support. Now displaying the amount of items moved. Scanner now scans all guild bank tabs rather than only the current. Fixed a bug with local item data not being retrieved properly. Disabled ?enterClicksFirstButton? within dialogs as this causes the dialog to consume all keypress. Events are now at the addon object rather than local.
author Zerotorescue
date Thu, 06 Jan 2011 20:05:30 +0100
parents Widgets.lua@8d11fc88ecab
children
comparison
equal deleted inserted replaced
83:6b60f7a1410c 84:3bec0ea44607
1 local addon = select(2, ...);
2 local Widgets = addon:NewModule("Widgets");
3
4 local AceGUI = LibStub("AceGUI-3.0");
5
6 function Widgets:ItemLinkButton()
7 --[[
8 [ ItemLinkButton ]
9 This custom widget has to show an icon with the item link next to it.
10 Upon hover it must show the item tooltip.
11 Upon click it must execute the function provided through user data.
12
13 UserData: itemId, onClickEvent
14
15 OnEnter: tooltip show
16 OnLeave: tooltip hide
17 OnClick: UserData.onClickEvent
18 ]]
19
20 local widgetType = "ItemLinkButton";
21 local widgetVersion = 1;
22
23 local function Constructor()
24 local widget = AceGUI:Create("InteractiveLabel");
25 widget.type = widgetType;
26
27 -- We overwrite the OnAcquire as we want to set our callbacks even
28 -- when the widget is re-used from the widget pool
29 widget.originalOnAcquire = widget.OnAcquire;
30 widget.OnAcquire = function(self, ...)
31
32
33 -- We overwrite the setcallback because we don't want anything else
34 -- to overwrite our OnEnter, OnLeave and OnClick events
35 -- which would be done by the AceConfigDialog after a widget gets re-used
36 if not self.originalSetCallBack then
37 self.originalSetCallBack = self.SetCallback;
38 self.SetCallback = function(this, event, func, ...)
39 if event == "OnEnter" or event == "OnLeave" or event == "OnClick" then
40 -- Don't allow overwriting of these events
41 return;
42 elseif event == "CustomOnEnter" then
43 return this.originalSetCallBack(this, "OnEnter", func, ...);
44 elseif event == "CustomOnLeave" then
45 return this.originalSetCallBack(this, "OnLeave", func, ...);
46 elseif event == "CustomOnClick" then
47 return this.originalSetCallBack(this, "OnClick", func, ...);
48 else
49 return this.originalSetCallBack(this, event, func, ...);
50 end
51 end;
52 end
53
54
55
56 -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions
57 self:SetCallback("CustomOnEnter", function(this)
58 local itemData = this:GetUserData("ItemData");
59
60 if itemData then
61 GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT");
62 GameTooltip:SetHyperlink(("item:%d"):format(itemData.id));
63 GameTooltip:Show();
64 end
65 end);
66 self:SetCallback("CustomOnLeave", function(this)
67 GameTooltip:Hide();
68 end);
69 self:SetCallback("CustomOnClick", function(this, ...)
70 -- Below is used in child widgets to prepare for onclick
71 if this.OnClick then
72 this.OnClick(this, ...);
73 end
74
75 local func = this:GetUserData("exec");
76 local itemData = this:GetUserData("ItemData");
77
78 if func then
79 -- If this is a config option we will need the group id
80 local path = this:GetUserData("path");
81 local groupId = (path and path[2]) or nil;
82
83 func(groupId, itemData, ...);
84 end
85 end);
86
87
88
89 -- Then also do whatever it wanted to do
90 self.originalOnAcquire(self, ...);
91 end;
92
93 -- Remember the original SetText as this might get overwritten by the config-widget
94 widget.originalSetText = widget.SetText;
95
96 widget.SetItem = function(self, item)
97 self:SetUserData("ItemData", item);
98
99 -- Put the icon in front of it
100 self:SetImage(item.icon);
101 -- Standardize the size
102 self:SetImageSize(16, 16);
103
104 -- Make readable font
105 self:SetFontObject(GameFontHighlight);
106
107 if not item.link then
108 -- If no item link was cached, give it another try
109
110 local itemName, itemLink, itemRarity = GetItemInfo(item.id);
111
112 -- item is a table, so passed by reference, so updatable
113 item.name = itemName;
114 item.link = itemLink;
115 item.rarity = itemRarity;
116 end
117
118 -- We don't want to set the itemId as text, but rather the item link, so get that.
119 local itemLink = item.link or ("Unknown (#%d)"):format(item.id);
120
121 self:originalSetText(itemLink);
122 end;
123
124 return widget;
125 end
126
127 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
128 end
129
130 function Widgets:ConfigItemLinkButton()
131 -- Define out custom item link button widget
132 -- 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
133
134 local widgetType = "ConfigItemLinkButton";
135 local widgetVersion = 1;
136
137 -- Empty function for disabling functions
138 local function Dummy() end
139
140 -- Makes an instance of our ItemLinkButton widget
141 local function GetItemLinkButton()
142 local widget = AceGUI:Create("ItemLinkButton");
143 widget.type = widgetType;
144
145 -- We can only provide custom widgets for input, select and multiselect fields
146 -- Input being the simplest, we use that - however, it provides two parameters: label and text. We only need one, disable the other.
147 widget.SetLabel = Dummy;
148
149 -- SetText is called when this button is being created and contains the itemId
150 -- Forward that itemId to the ItemLinkButton
151 widget.SetText = function(self, value, ...)
152 if value and tonumber(value) then
153 local newItemData = addon.ItemData:New(tonumber(value));
154
155 self:SetItem(newItemData);
156 end
157 end;
158
159 widget.OnClick = function(self, ...)
160 local option = self:GetUserData("option");
161
162 if option and option.set then
163 self:SetUserData("exec", option.set);
164 end
165 end;
166
167 return widget;
168 end
169
170 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion);
171 end
172
173 function Widgets:InlineGroupWithButton()
174 -- Register InlineGroupWithButton-widget
175 -- This widget adds a button next to the header of an inline group
176 -- SetPoint doesn't seem usable within AceGUI.
177
178 local widgetType = "InlineGroupWithButton";
179 local widgetVersion = 1;
180
181 local function Constructor()
182 local widget = AceGUI:Create("InlineGroup");
183 widget.type = widgetType;
184
185 widget.MakeButton = function(self, buttonSettings)
186 if type(buttonSettings) == "table" then
187 if not self.btnQueue then
188 -- Because widgets are re-used, we don't want to recreate this button
189 self.btnQueue = CreateFrame("Button", nil, self.frame, "UIPanelButtonTemplate");
190 self.btnQueue:SetHeight(22);
191 self.btnQueue:SetWidth(120);
192 end
193 self.btnQueue:SetText(buttonSettings.name);
194 self.btnQueue:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -10, 5);
195
196 -- Triggers
197 self.btnQueue:SetScript("OnClick", buttonSettings.exec);
198
199 -- Tooltip
200 self.btnQueue.tooltipTitle = buttonSettings.name;
201 self.btnQueue.tooltip = buttonSettings.desc or "";
202 self.btnQueue:SetScript("OnEnter", ShowTooltip);
203 self.btnQueue:SetScript("OnLeave", HideTooltip);
204 else
205 error("settings must be a table - usage: MakeButton(table);");
206 end
207 end;
208
209 return widget;
210 end
211
212 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
213 end