Permalink
Browse files

Bring in empty addon template

  • Loading branch information...
1 parent d382116 commit 130fc0b3056e59d61c512b4f89a0398d15f190c3 @tekkub tekkub committed May 28, 2008
Showing with 236 additions and 0 deletions.
  1. +71 −0 Instantiation.lua
  2. +23 −0 Instantiation.toc
  3. +30 −0 LibStub.lua
  4. +112 −0 tekKonfigAboutPanel.lua
View
@@ -0,0 +1,71 @@
+
+----------------------
+-- Locals --
+----------------------
+
+local L = setmetatable({}, {__index=function(t,i) return i end})
+local defaults, defaultsPC, db, dbpc = {}, {}
+
+
+------------------------------
+-- Util Functions --
+------------------------------
+
+local function Print(...) ChatFrame1:AddMessage(string.join(" ", "|cFF33FF99Addon Template|r:", ...)) end
+
+local debugf = tekDebug and tekDebug:GetFrame("Instantiation")
+local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", ...)) end end
+
+
+-----------------------------
+-- Event Handler --
+-----------------------------
+
+local f = CreateFrame("frame")
+f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
+f:RegisterEvent("ADDON_LOADED")
+
+
+function f:ADDON_LOADED(event, addon)
+ if addon ~= "Instantiation" then return end
+
+ InstantiationDB, InstantiationDBPC = setmetatable(InstantiationDB or {}, {__index = defaults}), setmetatable(InstantiationDBPC or {}, {__index = defaultsPC})
+ db, dbpc = InstantiationDB, InstantiationDBPC
+
+ -- Do anything you need to do after addon has loaded
+
+ LibStub("tekKonfig-AboutPanel").new("Instantiation", "Instantiation") -- Remove first arg if no parent config panel
+
+ self:UnregisterEvent("ADDON_LOADED")
+ self.ADDON_LOADED = nil
+
+ if IsLoggedIn() then self:PLAYER_LOGIN() else self:RegisterEvent("PLAYER_LOGIN") end
+end
+
+
+function f:PLAYER_LOGIN()
+ self:RegisterEvent("PLAYER_LOGOUT")
+
+ -- Do anything you need to do after the player has entered the world
+
+ self:UnregisterEvent("PLAYER_LOGIN")
+ self.PLAYER_LOGIN = nil
+end
+
+
+function f:PLAYER_LOGOUT()
+ for i,v in pairs(defaults) do if db[i] == v then db[i] = nil end end
+ for i,v in pairs(defaultsPC) do if dbpc[i] == v then dbpc[i] = nil end end
+
+ -- Do anything you need to do as the player logs out
+end
+
+
+-----------------------------
+-- Slash Handler --
+-----------------------------
+
+SLASH_INSTANTIATION1 = "/instantiation"
+SlashCmdList.INSTANTIATION = function(msg)
+ -- Do crap here
+end
View
@@ -0,0 +1,23 @@
+## Interface: 20400
+
+## Title: Instantiation
+## Notes: Instance maps and crap
+## Author: Tekkub Stoutwrithe
+## Version: Alpha
+## X-Website: http://www.tekkub.net/
+## X-Email: tekkub-wow@googlegroups.com
+## X-Category: Map
+
+## SavedVariables: InstantiationDB
+## SavedVariablesPerCharacter: InstantiationDBPC
+
+## OptionalDeps: tekDebug
+
+## LoadManagers: AddonLoader
+## X-LoadOn-Always: delayed
+## X-LoadOn-Slash: /instantiation
+
+LibStub.lua
+tekKonfigAboutPanel.lua
+
+Instantiation.lua
View
@@ -0,0 +1,30 @@
+-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
+-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
+local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
+local LibStub = _G[LIBSTUB_MAJOR]
+
+if not LibStub or LibStub.minor < LIBSTUB_MINOR then
+ LibStub = LibStub or {libs = {}, minors = {} }
+ _G[LIBSTUB_MAJOR] = LibStub
+ LibStub.minor = LIBSTUB_MINOR
+
+ function LibStub:NewLibrary(major, minor)
+ assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
+ minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
+
+ local oldminor = self.minors[major]
+ if oldminor and oldminor >= minor then return nil end
+ self.minors[major], self.libs[major] = minor, self.libs[major] or {}
+ return self.libs[major], oldminor
+ end
+
+ function LibStub:GetLibrary(major, silent)
+ if not self.libs[major] and not silent then
+ error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
+ end
+ return self.libs[major], self.minors[major]
+ end
+
+ function LibStub:IterateLibraries() return pairs(self.libs) end
+ setmetatable(LibStub, { __call = LibStub.GetLibrary })
+end
View
@@ -0,0 +1,112 @@
+
+local lib, oldminor = LibStub:NewLibrary("tekKonfig-AboutPanel", 2)
+if not lib then return end
+
+
+function lib.new(parent, addonname)
+ local frame = CreateFrame("Frame", nil, UIParent)
+ frame.name, frame.parent, frame.addonname = "About", parent, addonname
+ frame:Hide()
+ frame:SetScript("OnShow", lib.OnShow)
+ InterfaceOptions_AddCategory(frame)
+end
+
+
+local editbox = CreateFrame('EditBox', nil, UIParent)
+editbox:Hide()
+editbox:SetAutoFocus(true)
+editbox:SetHeight(32)
+editbox:SetFontObject('GameFontHighlightSmall')
+lib.editbox = editbox
+
+local left = editbox:CreateTexture(nil, "BACKGROUND")
+left:SetWidth(8) left:SetHeight(20)
+left:SetPoint("LEFT", -5, 0)
+left:SetTexture("Interface\\Common\\Common-Input-Border")
+left:SetTexCoord(0, 0.0625, 0, 0.625)
+
+local right = editbox:CreateTexture(nil, "BACKGROUND")
+right:SetWidth(8) right:SetHeight(20)
+right:SetPoint("RIGHT", 0, 0)
+right:SetTexture("Interface\\Common\\Common-Input-Border")
+right:SetTexCoord(0.9375, 1, 0, 0.625)
+
+local center = editbox:CreateTexture(nil, "BACKGROUND")
+center:SetHeight(20)
+center:SetPoint("RIGHT", right, "LEFT", 0, 0)
+center:SetPoint("LEFT", left, "RIGHT", 0, 0)
+center:SetTexture("Interface\\Common\\Common-Input-Border")
+center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
+
+editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
+editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
+editbox:SetScript("OnEditFocusLost", editbox.Hide)
+editbox:SetScript("OnEditFocusGained", editbox.HighlightText)
+editbox:SetScript("OnTextChanged", function(self)
+ self:SetText(self:GetParent().val)
+ self:HighlightText()
+end)
+
+
+function lib.OpenEditbox(self)
+ editbox:SetText(self.val)
+ editbox:SetParent(self)
+ editbox:SetPoint("LEFT", self)
+ editbox:SetPoint("RIGHT", self)
+ editbox:Show()
+end
+
+
+local fields = {"Version", "Author", "X-Category", "X-License", "X-Email", "X-Website", "X-Credits"}
+local haseditbox = {["Version"] = true, ["X-Website"] = true, ["X-Email"] = true}
+local function HideTooltip() GameTooltip:Hide() end
+local function ShowTooltip(self)
+ GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
+ GameTooltip:SetText("Click and press Ctrl-C to copy")
+end
+function lib.OnShow(frame)
+ local notes = GetAddOnMetadata(frame.addonname, "Notes")
+
+ local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
+ title:SetPoint("TOPLEFT", 16, -16)
+ title:SetText(frame.parent.." - About")
+
+ local subtitle = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+ subtitle:SetHeight(32)
+ subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
+ subtitle:SetPoint("RIGHT", parent, -32, 0)
+ subtitle:SetNonSpaceWrap(true)
+ subtitle:SetJustifyH("LEFT")
+ subtitle:SetJustifyV("TOP")
+ subtitle:SetText(notes)
+
+ local anchor
+ for _,field in pairs(fields) do
+ local val = GetAddOnMetadata(frame.addonname, field)
+ if val then
+ local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
+ title:SetWidth(75)
+ if not anchor then title:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", -2, -8)
+ else title:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -6) end
+ title:SetJustifyH("RIGHT")
+ title:SetText(field:gsub("X%-", ""))
+
+ local detail = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+ detail:SetPoint("LEFT", title, "RIGHT", 4, 0)
+ detail:SetPoint("RIGHT", -16, 0)
+ detail:SetJustifyH("LEFT")
+ detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val)
+
+ if haseditbox[field] then
+ local button = CreateFrame("Button", nil, frame)
+ button:SetAllPoints(detail)
+ button.val = val
+ button:SetScript("OnClick", lib.OpenEditbox)
+ button:SetScript("OnEnter", ShowTooltip)
+ button:SetScript("OnLeave", HideTooltip)
+ end
+
+ anchor = title
+ end
+ end
+end

0 comments on commit 130fc0b

Please sign in to comment.