comparison Widgets.lua @ 74:8d11fc88ecab

Default summary width is now 700 pixels (up from 650). Changed the item data table into a class which is now also used at the custom widgets.
author Zerotorescue
date Fri, 24 Dec 2010 21:55:11 +0100
parents 6216b754350d
children
comparison
equal deleted inserted replaced
73:6216b754350d 74:8d11fc88ecab
53 53
54 54
55 55
56 -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions 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) 57 self:SetCallback("CustomOnEnter", function(this)
58 local itemId = this:GetUserData("itemId"); 58 local itemData = this:GetUserData("ItemData");
59 59
60 if itemId then 60 if itemData then
61 GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT"); 61 GameTooltip:SetOwner(this.frame, "ANCHOR_TOPRIGHT");
62 GameTooltip:SetHyperlink(("item:%d"):format(itemId)); 62 GameTooltip:SetHyperlink(("item:%d"):format(itemData.id));
63 GameTooltip:Show(); 63 GameTooltip:Show();
64 end 64 end
65 end); 65 end);
66 self:SetCallback("CustomOnLeave", function(this) 66 self:SetCallback("CustomOnLeave", function(this)
67 GameTooltip:Hide(); 67 GameTooltip:Hide();
71 if this.OnClick then 71 if this.OnClick then
72 this.OnClick(this, ...); 72 this.OnClick(this, ...);
73 end 73 end
74 74
75 local func = this:GetUserData("exec"); 75 local func = this:GetUserData("exec");
76 local itemId = this:GetUserData("itemId"); 76 local itemData = this:GetUserData("ItemData");
77 77
78 if func then 78 if func then
79 -- If this is a config option we will need the group id 79 -- If this is a config option we will need the group id
80 local path = this:GetUserData("path"); 80 local path = this:GetUserData("path");
81 local groupId = (path and path[2]) or nil; 81 local groupId = (path and path[2]) or nil;
82 82
83 func(groupId, itemId, ...); 83 func(groupId, itemData, ...);
84 end 84 end
85 end); 85 end);
86 86
87 87
88 88
91 end; 91 end;
92 92
93 -- Remember the original SetText as this might get overwritten by the config-widget 93 -- Remember the original SetText as this might get overwritten by the config-widget
94 widget.originalSetText = widget.SetText; 94 widget.originalSetText = widget.SetText;
95 95
96 widget.SetItemId = function(self, itemId) 96 widget.SetItem = function(self, item)
97 self:SetUserData("itemId", itemId); 97 self:SetUserData("ItemData", item);
98 98
99 -- Put the icon in front of it 99 -- Put the icon in front of it
100 self:SetImage(GetItemIcon(itemId)); 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 -- We don't want to set the itemId as text, but rather the item link, so get that.
108 local itemLink = select(2, GetItemInfo(itemId)) or ("Unknown (#%d)"):format(itemId);
109
110 self:originalSetText(itemLink);
111 end;
112 widget.SetItem = function(self, item)
113 self:SetUserData("itemId", item.id);
114
115 -- Put the icon in front of it
116 self:SetImage(GetItemIcon(item.id));
117 -- Standardize the size 101 -- Standardize the size
118 self:SetImageSize(16, 16); 102 self:SetImageSize(16, 16);
119 103
120 -- Make readable font 104 -- Make readable font
121 self:SetFontObject(GameFontHighlight); 105 self:SetFontObject(GameFontHighlight);
130 item.link = itemLink; 114 item.link = itemLink;
131 item.rarity = itemRarity; 115 item.rarity = itemRarity;
132 end 116 end
133 117
134 -- We don't want to set the itemId as text, but rather the item link, so get that. 118 -- We don't want to set the itemId as text, but rather the item link, so get that.
135 local itemLink = item.link or ("Unknown (#%d)"):format(itemId); 119 local itemLink = item.link or ("Unknown (#%d)"):format(item.id);
136 120
137 self:originalSetText(itemLink); 121 self:originalSetText(itemLink);
138 end; 122 end;
139 123
140 return widget; 124 return widget;
164 148
165 -- SetText is called when this button is being created and contains the itemId 149 -- SetText is called when this button is being created and contains the itemId
166 -- Forward that itemId to the ItemLinkButton 150 -- Forward that itemId to the ItemLinkButton
167 widget.SetText = function(self, value, ...) 151 widget.SetText = function(self, value, ...)
168 if value and tonumber(value) then 152 if value and tonumber(value) then
169 self:SetItemId(tonumber(value)); 153 local newItemData = addon.ItemData:New(tonumber(value));
154
155 self:SetItem(newItemData);
170 end 156 end
171 end; 157 end;
172 158
173 widget.OnClick = function(self, ...) 159 widget.OnClick = function(self, ...)
174 local option = self:GetUserData("option"); 160 local option = self:GetUserData("option");