remove debug spam
[QuestHelper.git] / LibAboutPanel / LibAboutPanel.lua
blob8d2a86ad1df62be61da33007e9084cf7b6e4ca9e
1 --[[
2 ****************************************************************************************
3 LibAboutPanel
4 $Date: 2008-10-24 17:15:53 +0000 (Fri, 24 Oct 2008) $
5 $Rev: 21 $
7 Author: Tekkub
8 Modifications: Ackis on Illidan US Horde
10 ****************************************************************************************
12 This library will add an about panel to your Blizzard interface options. You can specify whether or not
13 to have the panel linked to a main panel, or just have it created seperately. It will populate the fields of
14 the about panel from the fields located in your ToC. To create the about panel, just add the following
15 line of code into your mod:
17 LibStub("LibAboutPanel").new(parentframe, addonname)
19 It will also return the frame so you can call it like:
21 frame = LibStub("LibAboutPanel").new(parentframe, addonname)
23 The parentframe option may be nil, in which case it will not anchor the about panel to any frame.
24 Otherwise, it will anchor the about frame to that frame.
26 The second option is the name of your add-on. This is manditory as the about panel will pull all
27 information from this add-ons ToC.
29 The ToC fields which the add-on reads are:
31 "Notes"
32 "Version"
33 "Author"
34 "X-Author-Faction"
35 "X-Author-Server"
36 "X-Category"
37 "X-License"
38 "X-Email"
39 "X-Website"
40 "X-Credits"
41 "X-Localizations"
42 "X-Donate"
44 It will only read fields when they exist, and skip them if they do not exist.
46 Currently it will not read localization versions of fields all fields.
48 ****************************************************************************************
49 ]]--
51 local lib, oldminor = LibStub:NewLibrary("LibAboutPanelQH", 1)
52 if not lib then return end
54 function lib.new(parent, addonname)
55 local frame = CreateFrame("Frame", nil, UIParent)
56 frame.name, frame.parent, frame.addonname = not parent and gsub(addonname," ","") or "About", parent, gsub(addonname," ","") -- Remove spaces from addonname because GetMetadata doesn't like that
57 frame:Hide()
58 frame:SetScript("OnShow", lib.OnShow)
59 InterfaceOptions_AddCategory(frame)
60 return frame
61 end
63 --[[
65 local GAME_LOCALE = GetLocale()
67 if GAME_LOCALE ~= "frFR" then
68 GAME_LOCALE = "enUS"
69 end
71 local L = {}
73 if GAME_LOCALE == "enUS" then
74 L["About"] = true
75 L["Click and press Ctrl-C to copy"] = true
76 elseif GAME_LOCALE == "frFR" then
77 L["About"] = "à propos de"
78 L["Click and press Ctrl-C to copy"] = true
79 end
81 ]]--
83 local editbox = CreateFrame('EditBox', nil, UIParent)
84 editbox:Hide()
85 editbox:SetAutoFocus(true)
86 editbox:SetHeight(32)
87 editbox:SetFontObject('GameFontHighlightSmall')
88 lib.editbox = editbox
90 local left = editbox:CreateTexture(nil, "BACKGROUND")
91 left:SetWidth(8) left:SetHeight(20)
92 left:SetPoint("LEFT", -5, 0)
93 left:SetTexture("Interface\\Common\\Common-Input-Border")
94 left:SetTexCoord(0, 0.0625, 0, 0.625)
96 local right = editbox:CreateTexture(nil, "BACKGROUND")
97 right:SetWidth(8) right:SetHeight(20)
98 right:SetPoint("RIGHT", 0, 0)
99 right:SetTexture("Interface\\Common\\Common-Input-Border")
100 right:SetTexCoord(0.9375, 1, 0, 0.625)
102 local center = editbox:CreateTexture(nil, "BACKGROUND")
103 center:SetHeight(20)
104 center:SetPoint("RIGHT", right, "LEFT", 0, 0)
105 center:SetPoint("LEFT", left, "RIGHT", 0, 0)
106 center:SetTexture("Interface\\Common\\Common-Input-Border")
107 center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
109 editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
110 editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
111 editbox:SetScript("OnEditFocusLost", editbox.Hide)
112 editbox:SetScript("OnEditFocusGained", editbox.HighlightText)
113 editbox:SetScript("OnTextChanged", function(self)
114 self:SetText(self:GetParent().val)
115 self:HighlightText()
116 end)
119 function lib.OpenEditbox(self)
120 editbox:SetText(self.val)
121 editbox:SetParent(self)
122 editbox:SetPoint("LEFT", self)
123 editbox:SetPoint("RIGHT", self)
124 editbox:Show()
128 local fields = {"Version", "Author", "X-Category", "X-License", "X-Email", "X-Website", "X-Credits", "X-Localizations", "X-Donate"}
129 local haseditbox = {["Version"] = true, ["X-Website"] = true, ["X-Email"] = true, ["X-Donate"] = true}
130 local function HideTooltip() GameTooltip:Hide() end
131 local function ShowTooltip(self)
132 GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
133 --GameTooltip:SetText(L["Click and press Ctrl-C to copy"])
134 GameTooltip:SetText("Click and press Ctrl-C to copy")
136 function lib.OnShow(frame)
137 --[[
138 local notefield = "Notes"
140 if (GAME_LOCALE ~= "enUS") then
141 notefield = notefield .. "-" .. GAME_LOCALE
144 local notes = GetAddOnMetadata(frame.addonname, notefield) or GetAddOnMetadata(frame.addonname, "Notes")
145 ]]--
147 local notes = GetAddOnMetadata(frame.addonname, "Notes")
149 local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
150 title:SetPoint("TOPLEFT", 16, -16)
151 title:SetText(frame.parent and (frame.parent.." - About") or frame.name)
153 local subtitle = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
154 subtitle:SetHeight(32)
155 subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
156 subtitle:SetPoint("RIGHT", frame, -32, 0)
157 subtitle:SetNonSpaceWrap(true)
158 subtitle:SetJustifyH("LEFT")
159 subtitle:SetJustifyV("TOP")
160 subtitle:SetText(notes)
162 local anchor
163 for _,field in pairs(fields) do
164 local val = GetAddOnMetadata(frame.addonname, field)
165 if val then
166 local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
167 title:SetWidth(75)
168 if not anchor then title:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", -2, -12)
169 else title:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10) end
170 title:SetJustifyH("RIGHT")
171 title:SetText(field:gsub("X%-", ""))
173 local detail = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
174 detail:SetHeight(32)
175 detail:SetPoint("LEFT", title, "RIGHT", 4, 0)
176 detail:SetPoint("RIGHT", frame, -16, 0)
177 detail:SetJustifyH("LEFT")
179 if (field == "Author") then
181 local authorservername = GetAddOnMetadata(frame.addonname, "X-Author-Server")
182 local authorfaction = GetAddOnMetadata(frame.addonname, "X-Author-Faction")
184 if authorservername and authorfaction then
185 detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val .. " on " .. authorservername .. " (" .. authorfaction .. ")")
186 elseif authorservername and not authorfaction then
187 detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val .. " on " .. authorservername)
188 elseif not authorservername and authorfaction then
189 detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val .. " (" .. authorfaction .. ")")
190 else
191 detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val)
194 else
195 detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val)
198 if haseditbox[field] then
199 local button = CreateFrame("Button", nil, frame)
200 button:SetAllPoints(detail)
201 button.val = val
202 button:SetScript("OnClick", lib.OpenEditbox)
203 button:SetScript("OnEnter", ShowTooltip)
204 button:SetScript("OnLeave", HideTooltip)
207 anchor = title
211 -- seriously did you really think I wouldn't go and tweak things
212 local commentary = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
213 commentary:SetHeight(32)
214 commentary:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -24)
215 commentary:SetPoint("RIGHT", frame, -32, 0)
216 commentary:SetNonSpaceWrap(true)
217 commentary:SetJustifyH("LEFT")
218 commentary:SetJustifyV("TOP")
219 commentary:SetText(QHText("HOW_TO_CONFIGURE"))