2 ****************************************************************************************
4 $Date: 2008-10-24 17:15:53 +0000 (Fri, 24 Oct 2008) $
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:
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 ****************************************************************************************
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
58 frame
:SetScript("OnShow", lib
.OnShow
)
59 InterfaceOptions_AddCategory(frame
)
65 local GAME_LOCALE = GetLocale()
67 if GAME_LOCALE ~= "frFR" then
73 if GAME_LOCALE == "enUS" then
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
83 local editbox
= CreateFrame('EditBox', nil, UIParent
)
85 editbox
:SetAutoFocus(true)
87 editbox
:SetFontObject('GameFontHighlightSmall')
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")
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
)
119 function lib
.OpenEditbox(self
)
120 editbox
:SetText(self
.val
)
121 editbox
:SetParent(self
)
122 editbox
:SetPoint("LEFT", self
)
123 editbox
:SetPoint("RIGHT", self
)
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
)
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")
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
)
163 for _
,field
in pairs(fields
) do
164 local val
= GetAddOnMetadata(frame
.addonname
, field
)
166 local title
= frame
:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
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")
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
.. ")")
191 detail
:SetText((haseditbox
[field
] and "|cff9999ff" or "").. val
)
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
)
202 button
:SetScript("OnClick", lib
.OpenEditbox
)
203 button
:SetScript("OnEnter", ShowTooltip
)
204 button
:SetScript("OnLeave", HideTooltip
)
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"))