Mercurial > wow > reaction
comparison classes/Bar.lua @ 153:d5e11e924053
Code formatting, separate accessors from other methods in Bar.lua
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Fri, 08 May 2009 17:14:36 +0000 |
| parents | de1da46dadb3 |
| children | df67685b340e |
comparison
equal
deleted
inserted
replaced
| 152:6d7ef2a3f828 | 153:d5e11e924053 |
|---|---|
| 108 | 108 |
| 109 function Bar:LIBKEYBOUND_DISABLED(evt) | 109 function Bar:LIBKEYBOUND_DISABLED(evt) |
| 110 self:SetKeybindMode(false) | 110 self:SetKeybindMode(false) |
| 111 end | 111 end |
| 112 | 112 |
| 113 -- | |
| 114 -- Accessors | |
| 115 -- | |
| 116 | |
| 117 function Bar:GetName() | |
| 118 return self.name | |
| 119 end | |
| 120 | |
| 121 -- only ReAction:RenameBar() should call this function. Calling from any other | |
| 122 -- context will desync the bar list in the ReAction class. | |
| 123 function Bar:SetName(name) | |
| 124 self.name = name | |
| 125 self:SetLabel(self.name) -- Bar:SetLabel() defined in Overlay.lua | |
| 126 end | |
| 127 | |
| 128 function Bar:GetFrame() | |
| 129 -- this method is included for documentation purposes. It is overridden | |
| 130 -- for each object in the :New() method. | |
| 131 error("Invalid Bar object: used without initialization") | |
| 132 end | |
| 133 | |
| 134 function Bar:GetConfig() | |
| 135 return self.config | |
| 136 end | |
| 137 | |
| 138 function Bar:GetAnchor() | |
| 139 local c = self.config | |
| 140 return (c.point or "CENTER"), | |
| 141 (c.anchor or self:GetFrame():GetParent():GetName()), | |
| 142 (c.relpoint or c.point or "CENTER"), | |
| 143 (c.x or 0), | |
| 144 (c.y or 0) | |
| 145 end | |
| 146 | |
| 147 function Bar:SetAnchor(point, frame, relativePoint, x, y) | |
| 148 local c = self.config | |
| 149 c.point = point or c.point | |
| 150 c.anchor = frame or c.anchor | |
| 151 c.relpoint = relativePoint or c.relpoint | |
| 152 c.x = x or c.x | |
| 153 c.y = y or c.y | |
| 154 self:ApplyAnchor() | |
| 155 ReAction:RefreshBar(self) | |
| 156 end | |
| 157 | |
| 158 function Bar:GetSize() | |
| 159 local f = self:GetFrame() | |
| 160 return f:GetWidth(), f:GetHeight() | |
| 161 end | |
| 162 | |
| 163 function Bar:SetSize(w,h) | |
| 164 local f = self:GetFrame() | |
| 165 self.config.width = w | |
| 166 self.config.height = h | |
| 167 f:SetWidth(w) | |
| 168 f:SetHeight(h) | |
| 169 end | |
| 170 | |
| 171 function Bar:GetButtonSize() | |
| 172 local w = self.config.btnWidth or 32 | |
| 173 local h = self.config.btnHeight or 32 | |
| 174 -- TODO: get from modules? | |
| 175 return w,h | |
| 176 end | |
| 177 | |
| 178 function Bar:SetButtonSize(w,h) | |
| 179 if w > 0 and h > 0 then | |
| 180 self.config.btnWidth = w | |
| 181 self.config.btnHeight = h | |
| 182 end | |
| 183 ReAction:RefreshBar(self) | |
| 184 end | |
| 185 | |
| 186 function Bar:GetNumButtons() | |
| 187 local r,c = self:GetButtonGrid() | |
| 188 return r*c | |
| 189 end | |
| 190 | |
| 191 function Bar:GetButtonGrid() | |
| 192 local cfg = self.config | |
| 193 local r = cfg.btnRows or 1 | |
| 194 local c = cfg.btnColumns or 1 | |
| 195 local s = cfg.spacing or 4 | |
| 196 return r,c,s | |
| 197 end | |
| 198 | |
| 199 function Bar:SetButtonGrid(r,c,s) | |
| 200 if r > 0 and c > 0 and s > 0 then | |
| 201 local cfg = self.config | |
| 202 cfg.btnRows = r | |
| 203 cfg.btnColumns = c | |
| 204 cfg.spacing = s | |
| 205 end | |
| 206 ReAction:RefreshBar(self) | |
| 207 end | |
| 208 | |
| 209 function Bar:GetAlpha() | |
| 210 return self.config.alpha or 1.0 | |
| 211 end | |
| 212 | |
| 213 function Bar:SetAlpha(value) | |
| 214 self.config.alpha = value | |
| 215 self:GetFrame():SetAlpha(value or 1.0) | |
| 216 ReAction:RefreshBar(self) | |
| 217 end | |
| 218 | |
| 219 -- iterator returns button, idx and does NOT iterate in index order | |
| 220 function Bar:IterateButtons() | |
| 221 return pairs(self.buttons) | |
| 222 end | |
| 223 | |
| 224 -- | |
| 225 -- Methods | |
| 226 -- | |
| 227 | |
| 228 function Bar:SetConfigMode(mode) | |
| 229 self:ShowControls(mode) | |
| 230 if self.unitwatch then | |
| 231 if mode then | |
| 232 UnregisterUnitWatch(self:GetFrame()) | |
| 233 self:GetFrame():Show() | |
| 234 else | |
| 235 RegisterUnitWatch(self:GetFrame()) | |
| 236 end | |
| 237 end | |
| 238 for b in self:IterateButtons() do | |
| 239 b:ShowGridTemp(mode) | |
| 240 b:UpdateActionIDLabel(mode) | |
| 241 end | |
| 242 end | |
| 243 | |
| 244 function Bar:SetKeybindMode(mode) | |
| 245 if self.unitwatch then | |
| 246 if mode then | |
| 247 UnregisterUnitWatch(self:GetFrame()) | |
| 248 self:GetFrame():Show() | |
| 249 else | |
| 250 RegisterUnitWatch(self:GetFrame()) | |
| 251 end | |
| 252 end | |
| 253 for b in self:IterateButtons() do | |
| 254 b:SetKeybindMode(mode) | |
| 255 end | |
| 256 end | |
| 257 | |
| 113 function Bar:ApplyAnchor() | 258 function Bar:ApplyAnchor() |
| 114 local f = self:GetFrame() | 259 local f = self:GetFrame() |
| 115 local c = self.config | 260 local c = self.config |
| 116 local p = c.point | 261 local p = c.point |
| 117 | 262 |
| 134 else | 279 else |
| 135 f:SetPoint("CENTER") | 280 f:SetPoint("CENTER") |
| 136 end | 281 end |
| 137 end | 282 end |
| 138 | 283 |
| 139 function Bar:SetAnchor(point, frame, relativePoint, x, y) | |
| 140 local c = self.config | |
| 141 c.point = point or c.point | |
| 142 c.anchor = frame or c.anchor | |
| 143 c.relpoint = relativePoint or c.relpoint | |
| 144 c.x = x or c.x | |
| 145 c.y = y or c.y | |
| 146 self:ApplyAnchor() | |
| 147 ReAction:RefreshBar(self) | |
| 148 end | |
| 149 | |
| 150 function Bar:GetAnchor() | |
| 151 local c = self.config | |
| 152 return (c.point or "CENTER"), | |
| 153 (c.anchor or self:GetFrame():GetParent():GetName()), | |
| 154 (c.relpoint or c.point or "CENTER"), | |
| 155 (c.x or 0), | |
| 156 (c.y or 0) | |
| 157 end | |
| 158 | |
| 159 function Bar:GetSize() | |
| 160 local f = self:GetFrame() | |
| 161 return f:GetWidth(), f:GetHeight() | |
| 162 end | |
| 163 | |
| 164 function Bar:SetSize(w,h) | |
| 165 local f = self:GetFrame() | |
| 166 self.config.width = w | |
| 167 self.config.height = h | |
| 168 f:SetWidth(w) | |
| 169 f:SetHeight(h) | |
| 170 end | |
| 171 | |
| 172 function Bar:GetButtonSize() | |
| 173 local w = self.config.btnWidth or 32 | |
| 174 local h = self.config.btnHeight or 32 | |
| 175 -- TODO: get from modules? | |
| 176 return w,h | |
| 177 end | |
| 178 | |
| 179 function Bar:SetButtonSize(w,h) | |
| 180 if w > 0 and h > 0 then | |
| 181 self.config.btnWidth = w | |
| 182 self.config.btnHeight = h | |
| 183 end | |
| 184 ReAction:RefreshBar(self) | |
| 185 end | |
| 186 | |
| 187 function Bar:GetButtonGrid() | |
| 188 local cfg = self.config | |
| 189 local r = cfg.btnRows or 1 | |
| 190 local c = cfg.btnColumns or 1 | |
| 191 local s = cfg.spacing or 4 | |
| 192 return r,c,s | |
| 193 end | |
| 194 | |
| 195 function Bar:GetNumButtons() | |
| 196 local r,c = self:GetButtonGrid() | |
| 197 return r*c | |
| 198 end | |
| 199 | |
| 200 function Bar:SetButtonGrid(r,c,s) | |
| 201 if r > 0 and c > 0 and s > 0 then | |
| 202 local cfg = self.config | |
| 203 cfg.btnRows = r | |
| 204 cfg.btnColumns = c | |
| 205 cfg.spacing = s | |
| 206 end | |
| 207 ReAction:RefreshBar(self) | |
| 208 end | |
| 209 | |
| 210 function Bar:ClipNButtons( n ) | 284 function Bar:ClipNButtons( n ) |
| 211 local cfg = self.config | 285 local cfg = self.config |
| 212 local r = cfg.btnRows or 1 | 286 local r = cfg.btnRows or 1 |
| 213 local c = cfg.btnColumns or 1 | 287 local c = cfg.btnColumns or 1 |
| 214 | 288 |
| 215 cfg.btnRows = ceil(n/c) | 289 cfg.btnRows = ceil(n/c) |
| 216 cfg.btnColumns = min(n,c) | 290 cfg.btnColumns = min(n,c) |
| 217 end | |
| 218 | |
| 219 function Bar:GetName() | |
| 220 return self.name | |
| 221 end | |
| 222 | |
| 223 function Bar:GetFrame() | |
| 224 -- this method is included for documentation purposes. It is overridden | |
| 225 -- for each object in the :New() method. | |
| 226 error("Invalid Bar object: used without initialization") | |
| 227 end | |
| 228 | |
| 229 -- only ReAction:RenameBar() should call this function. Calling from any other | |
| 230 -- context will desync the bar list in the ReAction class. | |
| 231 function Bar:SetName(name) | |
| 232 self.name = name | |
| 233 self:SetLabel(self.name) -- Bar:SetLabel() defined in Overlay.lua | |
| 234 end | |
| 235 | |
| 236 function Bar:GetAlpha() | |
| 237 return self.config.alpha or 1.0 | |
| 238 end | |
| 239 | |
| 240 function Bar:SetAlpha(value) | |
| 241 self.config.alpha = value | |
| 242 self:GetFrame():SetAlpha(value or 1.0) | |
| 243 ReAction:RefreshBar(self) | |
| 244 end | 291 end |
| 245 | 292 |
| 246 function Bar:AddButton(idx, button) | 293 function Bar:AddButton(idx, button) |
| 247 local f = self:GetFrame() | 294 local f = self:GetFrame() |
| 248 | 295 |
| 257 function Bar:RemoveButton(button) | 304 function Bar:RemoveButton(button) |
| 258 local idx = self.buttons[button] | 305 local idx = self.buttons[button] |
| 259 if idx then | 306 if idx then |
| 260 self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil) | 307 self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil) |
| 261 self.buttons[button] = nil | 308 self.buttons[button] = nil |
| 262 end | |
| 263 end | |
| 264 | |
| 265 -- iterator returns button, idx and does NOT iterate in index order | |
| 266 function Bar:IterateButtons() | |
| 267 return pairs(self.buttons) | |
| 268 end | |
| 269 | |
| 270 function Bar:SetConfigMode(mode) | |
| 271 self:ShowControls(mode) | |
| 272 if self.unitwatch then | |
| 273 if mode then | |
| 274 UnregisterUnitWatch(self:GetFrame()) | |
| 275 self:GetFrame():Show() | |
| 276 else | |
| 277 RegisterUnitWatch(self:GetFrame()) | |
| 278 end | |
| 279 end | |
| 280 for b in self:IterateButtons() do | |
| 281 b:ShowGridTemp(mode) | |
| 282 b:UpdateActionIDLabel(mode) | |
| 283 end | |
| 284 end | |
| 285 | |
| 286 function Bar:SetKeybindMode(mode) | |
| 287 if self.unitwatch then | |
| 288 if mode then | |
| 289 UnregisterUnitWatch(self:GetFrame()) | |
| 290 self:GetFrame():Show() | |
| 291 else | |
| 292 RegisterUnitWatch(self:GetFrame()) | |
| 293 end | |
| 294 end | |
| 295 for b in self:IterateButtons() do | |
| 296 b:SetKeybindMode(mode) | |
| 297 end | 309 end |
| 298 end | 310 end |
| 299 | 311 |
| 300 function Bar:PlaceButton(button, baseW, baseH) | 312 function Bar:PlaceButton(button, baseW, baseH) |
| 301 local idx = self.buttons[button] | 313 local idx = self.buttons[button] |
