Mercurial > wow > cyborg-mmo7
view CallbackFactory.lua @ 13:6cb9a2936580
Miscellanous Lua code consistency improvements:
- no semicolon except between statements on same line
- use of implicit cast to bool in if/while conditions, instead of various eq/neq against true, false or nil
- no parenthesis around if/while conditions (C-ism)
- avoid long function calls in if conditions
- removed space in comma-separated expressions lists in multiple assignments
- added spaces between arguments of functions calls
- use tabs for indentation (in Lua files only)
- don't reverse == in if conditions, like "if 42==foo then" (C-ism)
- removed some extra parenthesis in complex expressions (C-ism)
- added spaces around operators in most expressions for ease of reading
- added comma after last element of table initializers
- removed space after # operator
- moved comment prefix of disabled code into tab (to keep disabled code aligned)
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Thu, 25 Apr 2013 01:29:45 +0000 |
parents | d186f8cd5000 |
children | 3b1c0b676583 |
line wrap: on
line source
--~ Warcraft Plugin for Cyborg MMO7 --~ Filename: CalbackFactory.lua --~ Description: Creates lua callbacks that can be executed from a user keycombination --~ Copyright (C) 2012 Mad Catz Inc. --~ Author: Christopher Hooks --~ This program is free software; you can redistribute it and/or --~ modify it under the terms of the GNU General Public License --~ as published by the Free Software Foundation; either version 2 --~ of the License, or (at your option) any later version. --~ This program is distributed in the hope that it will be useful, --~ but WITHOUT ANY WARRANTY; without even the implied warranty of --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --~ GNU General Public License for more details. --~ You should have received a copy of the GNU General Public License --~ along with this program; if not, write to the Free Software --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. CyborgMMO_CallbackFactory = { new = function() local self = {} self.Frame = CreateFrame("Frame", "CallbackFactoryFrame", UIParent) self.Callbacks = {} self.Id = 1 self.AddCallback = function(fn) local name = "Button"..self.Id self.Callbacks[name] = CreateFrame("Button", name, self.Frame) self.Callbacks[name]:SetScript("OnClick", fn) self.Id = self.Id + 1 return self.Callbacks[name],self.Frame,name end self.RemoveCallback = function(name) self.Callbacks[name] = nil end self.GetCallback = function(callbackName) local callback = nil if callbackName == "Map" then callback = self.ToggleMap elseif callbackName == "CharacterPage" then callback = self.ToggleCharacterPage elseif callbackName == "Spellbook" then callback = self.ToggleSpellbook elseif callbackName == "Macros" then callback = self.ToggleMacros elseif callbackName == "QuestLog" then callback = self.ToggleQuests elseif callbackName == "Achievement" then callback = self.ToggleAchievements elseif callbackName == "Inventory" then callback = self.ToggleBags end return callback end self.ToggleMap = function() ToggleFrame(WorldMapFrame) end self.ToggleCharacterPage = function() ToggleCharacter("PaperDollFrame") end self.ToggleSpellbook = function() ToggleFrame(SpellBookFrame) if SpellBookFrame:IsShown() then SpellbookMicroButton:SetButtonState("PUSHED", 1) else SpellbookMicroButton:SetButtonState("NORMAL") end end self.ToggleMacros = function() if MacroFrame:IsShown() and MacroFrame:IsVisible() then HideUIPanel(MacroFrame) else ShowMacroFrame() end end self.ToggleQuests = function() ToggleFrame(QuestLogFrame) if QuestLogFrame:IsShown() then QuestLogMicroButton:SetButtonState("PUSHED", 1) else QuestLogMicroButton:SetButtonState("NORMAL") end end self.ToggleAchievements = function() ToggleAchievementFrame() if AchievementFrame and AchievementFrame:IsShown() then AchievementMicroButton:SetButtonState("PUSHED", 1) else if (HasCompletedAnyAchievement() or IsInGuild()) and CanShowAchievementUI() then AchievementMicroButton:Enable() AchievementMicroButton:SetButtonState("NORMAL") else AchievementMicroButton:Disable() end end end self.ToggleBags = function() ToggleAllBags() end return self end, m_Instance = nil, Instance = function() if not CyborgMMO_CallbackFactory.m_Instance then CyborgMMO_CallbackFactory.m_Instance = CyborgMMO_CallbackFactory.new() end return CyborgMMO_CallbackFactory.m_Instance end, }