tercio@0
|
1 --[[
|
tercio@0
|
2 Name: LibSharedMedia-3.0
|
tercio@5
|
3 Revision: $Revision: 89 $
|
tercio@0
|
4 Author: Elkano (elkano@gmx.de)
|
tercio@0
|
5 Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com)
|
tercio@0
|
6 Website: http://www.wowace.com/projects/libsharedmedia-3-0/
|
tercio@0
|
7 Description: Shared handling of media data (fonts, sounds, textures, ...) between addons.
|
tercio@0
|
8 Dependencies: LibStub, CallbackHandler-1.0
|
tercio@0
|
9 License: LGPL v2.1
|
tercio@0
|
10 ]]
|
tercio@0
|
11
|
tercio@5
|
12 local MAJOR, MINOR = "LibSharedMedia-3.0", 6000201 -- 6.0.2 v1 / increase manually on changes
|
tercio@0
|
13 local lib = LibStub:NewLibrary(MAJOR, MINOR)
|
tercio@0
|
14
|
tercio@0
|
15 if not lib then return end
|
tercio@0
|
16
|
tercio@0
|
17 local _G = getfenv(0)
|
tercio@0
|
18
|
tercio@0
|
19 local pairs = _G.pairs
|
tercio@0
|
20 local type = _G.type
|
tercio@0
|
21
|
tercio@0
|
22 local band = _G.bit.band
|
tercio@0
|
23
|
tercio@0
|
24 local table_insert = _G.table.insert
|
tercio@0
|
25 local table_sort = _G.table.sort
|
tercio@0
|
26
|
tercio@0
|
27 local locale = GetLocale()
|
tercio@0
|
28 local locale_is_western
|
tercio@0
|
29 local LOCALE_MASK = 0
|
tercio@0
|
30 lib.LOCALE_BIT_koKR = 1
|
tercio@0
|
31 lib.LOCALE_BIT_ruRU = 2
|
tercio@0
|
32 lib.LOCALE_BIT_zhCN = 4
|
tercio@0
|
33 lib.LOCALE_BIT_zhTW = 8
|
tercio@0
|
34 lib.LOCALE_BIT_western = 128
|
tercio@0
|
35
|
tercio@0
|
36 local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
|
tercio@0
|
37
|
tercio@0
|
38 lib.callbacks = lib.callbacks or CallbackHandler:New(lib)
|
tercio@0
|
39
|
tercio@0
|
40 lib.DefaultMedia = lib.DefaultMedia or {}
|
tercio@0
|
41 lib.MediaList = lib.MediaList or {}
|
tercio@0
|
42 lib.MediaTable = lib.MediaTable or {}
|
tercio@0
|
43 lib.MediaType = lib.MediaType or {}
|
tercio@0
|
44 lib.OverrideMedia = lib.OverrideMedia or {}
|
tercio@0
|
45
|
tercio@0
|
46 local defaultMedia = lib.DefaultMedia
|
tercio@0
|
47 local mediaList = lib.MediaList
|
tercio@0
|
48 local mediaTable = lib.MediaTable
|
tercio@0
|
49 local overrideMedia = lib.OverrideMedia
|
tercio@0
|
50
|
tercio@0
|
51
|
tercio@0
|
52 -- create mediatype constants
|
tercio@0
|
53 lib.MediaType.BACKGROUND = "background" -- background textures
|
tercio@0
|
54 lib.MediaType.BORDER = "border" -- border textures
|
tercio@0
|
55 lib.MediaType.FONT = "font" -- fonts
|
tercio@0
|
56 lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures
|
tercio@0
|
57 lib.MediaType.SOUND = "sound" -- sound files
|
tercio@0
|
58
|
tercio@0
|
59 -- populate lib with default Blizzard data
|
tercio@0
|
60 -- BACKGROUND
|
tercio@0
|
61 if not lib.MediaTable.background then lib.MediaTable.background = {} end
|
tercio@0
|
62 lib.MediaTable.background["None"] = [[]]
|
tercio@5
|
63 lib.MediaTable.background["Blizzard Collections Background"] = [[Interface\Collections\CollectionsBackgroundTile]]
|
tercio@0
|
64 lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]]
|
tercio@0
|
65 lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
|
tercio@0
|
66 lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]
|
tercio@5
|
67 lib.MediaTable.background["Blizzard Garrison Background"] = [[Interface\Garrison\GarrisonUIBackground]]
|
tercio@5
|
68 lib.MediaTable.background["Blizzard Garrison Background 2"] = [[Interface\Garrison\GarrisonUIBackground2]]
|
tercio@5
|
69 lib.MediaTable.background["Blizzard Garrison Background 3"] = [[Interface\Garrison\GarrisonMissionUIInfoBoxBackgroundTile]]
|
tercio@0
|
70 lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]]
|
tercio@0
|
71 lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]]
|
tercio@0
|
72 lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]]
|
tercio@0
|
73 lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]]
|
tercio@0
|
74 lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]]
|
tercio@0
|
75 lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]]
|
tercio@0
|
76 lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]]
|
tercio@0
|
77 lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]]
|
tercio@0
|
78 lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]]
|
tercio@0
|
79 lib.DefaultMedia.background = "None"
|
tercio@0
|
80
|
tercio@0
|
81 -- BORDER
|
tercio@0
|
82 if not lib.MediaTable.border then lib.MediaTable.border = {} end
|
tercio@0
|
83 lib.MediaTable.border["None"] = [[]]
|
tercio@0
|
84 lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]]
|
tercio@0
|
85 lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]]
|
tercio@0
|
86 lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]]
|
tercio@0
|
87 lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]]
|
tercio@0
|
88 lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]]
|
tercio@0
|
89 lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]]
|
tercio@0
|
90 lib.DefaultMedia.border = "None"
|
tercio@0
|
91
|
tercio@0
|
92 -- FONT
|
tercio@0
|
93 if not lib.MediaTable.font then lib.MediaTable.font = {} end
|
tercio@0
|
94 local SML_MT_font = lib.MediaTable.font
|
tercio@5
|
95 --[[
|
tercio@5
|
96 All font files are currently in all clients, the following table depicts which font supports which charset as of 5.0.4
|
tercio@5
|
97 Fonts were checked using langcover.pl from DejaVu fonts (http://sourceforge.net/projects/dejavu/) and FontForge (http://fontforge.org/)
|
tercio@5
|
98 latin means check for: de, en, es, fr, it, pt
|
tercio@5
|
99
|
tercio@5
|
100 file name latin koKR ruRU zhCN zhTW
|
tercio@5
|
101 2002.ttf 2002 X X X - -
|
tercio@5
|
102 2002B.ttf 2002 Bold X X X - -
|
tercio@5
|
103 ARHei.ttf AR CrystalzcuheiGBK Demibold X - X X X
|
tercio@5
|
104 ARIALN.TTF Arial Narrow X - X - -
|
tercio@5
|
105 ARKai_C.ttf AR ZhongkaiGBK Medium (Combat) X - X X X
|
tercio@5
|
106 ARKai_T.ttf AR ZhongkaiGBK Medium X - X X X
|
tercio@5
|
107 bHEI00M.ttf AR Heiti2 Medium B5 - - - - X
|
tercio@5
|
108 bHEI01B.ttf AR Heiti2 Bold B5 - - - - X
|
tercio@5
|
109 bKAI00M.ttf AR Kaiti Medium B5 - - - - X
|
tercio@5
|
110 bLEI00D.ttf AR Leisu Demi B5 - - - - X
|
tercio@5
|
111 FRIZQT__.TTF Friz Quadrata TT X - - - -
|
tercio@5
|
112 FRIZQT___CYR.TTF FrizQuadrataCTT x - X - -
|
tercio@5
|
113 K_Damage.TTF YDIWingsM - X X - -
|
tercio@5
|
114 K_Pagetext.TTF MoK X X X - -
|
tercio@5
|
115 MORPHEUS.TTF Morpheus X - - - -
|
tercio@5
|
116 MORPHEUS_CYR.TTF Morpheus X - X - -
|
tercio@5
|
117 NIM_____.ttf Nimrod MT X - X - -
|
tercio@5
|
118 SKURRI.TTF Skurri X - - - -
|
tercio@5
|
119 SKURRI_CYR.TTF Skurri X - X - -
|
tercio@5
|
120
|
tercio@5
|
121 WARNING: Although FRIZQT___CYR is available on western clients, it doesn't support special European characters e.g. é, ï, ö
|
tercio@5
|
122 Due to this, we cannot use it as a replacement for FRIZQT__.TTF
|
tercio@5
|
123 ]]
|
tercio@5
|
124
|
tercio@0
|
125 if locale == "koKR" then
|
tercio@0
|
126 LOCALE_MASK = lib.LOCALE_BIT_koKR
|
tercio@0
|
127 --
|
tercio@0
|
128 SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]]
|
tercio@0
|
129 SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]]
|
tercio@0
|
130 SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]]
|
tercio@0
|
131 SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]]
|
tercio@0
|
132 --
|
tercio@0
|
133 lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed
|
tercio@0
|
134 --
|
tercio@0
|
135 elseif locale == "zhCN" then
|
tercio@0
|
136 LOCALE_MASK = lib.LOCALE_BIT_zhCN
|
tercio@0
|
137 --
|
tercio@0
|
138 SML_MT_font["伤害数字"] = [[Fonts\ARKai_C.ttf]]
|
tercio@0
|
139 SML_MT_font["默认"] = [[Fonts\ARKai_T.ttf]]
|
tercio@0
|
140 SML_MT_font["聊天"] = [[Fonts\ARHei.ttf]]
|
tercio@0
|
141 --
|
tercio@0
|
142 lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed
|
tercio@0
|
143 --
|
tercio@0
|
144 elseif locale == "zhTW" then
|
tercio@0
|
145 LOCALE_MASK = lib.LOCALE_BIT_zhTW
|
tercio@0
|
146 --
|
tercio@0
|
147 SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]]
|
tercio@0
|
148 SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]]
|
tercio@0
|
149 SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]]
|
tercio@0
|
150 SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]]
|
tercio@0
|
151 --
|
tercio@0
|
152 lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed
|
tercio@0
|
153
|
tercio@0
|
154 elseif locale == "ruRU" then
|
tercio@0
|
155 LOCALE_MASK = lib.LOCALE_BIT_ruRU
|
tercio@0
|
156 --
|
tercio@5
|
157 SML_MT_font["2002"] = [[Fonts\2002.TTF]]
|
tercio@5
|
158 SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
|
tercio@5
|
159 SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
|
tercio@5
|
160 SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
|
tercio@5
|
161 SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
|
tercio@5
|
162 SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
tercio@5
|
163 SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT___CYR.TTF]]
|
tercio@5
|
164 SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
|
tercio@5
|
165 SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
|
tercio@5
|
166 SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
|
tercio@5
|
167 SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
|
tercio@0
|
168 --
|
tercio@0
|
169 lib.DefaultMedia.font = "Friz Quadrata TT"
|
tercio@0
|
170 --
|
tercio@0
|
171 else
|
tercio@0
|
172 LOCALE_MASK = lib.LOCALE_BIT_western
|
tercio@0
|
173 locale_is_western = true
|
tercio@0
|
174 --
|
tercio@5
|
175 SML_MT_font["2002"] = [[Fonts\2002.TTF]]
|
tercio@5
|
176 SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]]
|
tercio@5
|
177 SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]]
|
tercio@5
|
178 SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]]
|
tercio@5
|
179 SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]]
|
tercio@5
|
180 SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]]
|
tercio@5
|
181 SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]]
|
tercio@5
|
182 SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]]
|
tercio@5
|
183 SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]]
|
tercio@5
|
184 SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]]
|
tercio@5
|
185 SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]]
|
tercio@0
|
186 --
|
tercio@0
|
187 lib.DefaultMedia.font = "Friz Quadrata TT"
|
tercio@0
|
188 --
|
tercio@0
|
189 end
|
tercio@0
|
190
|
tercio@0
|
191 -- STATUSBAR
|
tercio@0
|
192 if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end
|
tercio@0
|
193 lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]]
|
tercio@0
|
194 lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]
|
tercio@5
|
195 lib.MediaTable.statusbar["Blizzard Raid Bar"] = [[Interface\RaidFrame\Raid-Bar-Hp-Fill]]
|
tercio@0
|
196 lib.DefaultMedia.statusbar = "Blizzard"
|
tercio@0
|
197
|
tercio@0
|
198 -- SOUND
|
tercio@0
|
199 if not lib.MediaTable.sound then lib.MediaTable.sound = {} end
|
tercio@0
|
200 lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on non-existing input.
|
tercio@0
|
201 lib.DefaultMedia.sound = "None"
|
tercio@0
|
202
|
tercio@0
|
203 local function rebuildMediaList(mediatype)
|
tercio@0
|
204 local mtable = mediaTable[mediatype]
|
tercio@0
|
205 if not mtable then return end
|
tercio@0
|
206 if not mediaList[mediatype] then mediaList[mediatype] = {} end
|
tercio@0
|
207 local mlist = mediaList[mediatype]
|
tercio@0
|
208 -- list can only get larger, so simply overwrite it
|
tercio@0
|
209 local i = 0
|
tercio@0
|
210 for k in pairs(mtable) do
|
tercio@0
|
211 i = i + 1
|
tercio@0
|
212 mlist[i] = k
|
tercio@0
|
213 end
|
tercio@0
|
214 table_sort(mlist)
|
tercio@0
|
215 end
|
tercio@0
|
216
|
tercio@0
|
217 function lib:Register(mediatype, key, data, langmask)
|
tercio@0
|
218 if type(mediatype) ~= "string" then
|
tercio@0
|
219 error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype))
|
tercio@0
|
220 end
|
tercio@0
|
221 if type(key) ~= "string" then
|
tercio@0
|
222 error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key))
|
tercio@0
|
223 end
|
tercio@0
|
224 mediatype = mediatype:lower()
|
tercio@5
|
225 if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then return false end
|
tercio@0
|
226 if not mediaTable[mediatype] then mediaTable[mediatype] = {} end
|
tercio@0
|
227 local mtable = mediaTable[mediatype]
|
tercio@0
|
228 if mtable[key] then return false end
|
tercio@0
|
229
|
tercio@0
|
230 mtable[key] = data
|
tercio@0
|
231 rebuildMediaList(mediatype)
|
tercio@0
|
232 self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key)
|
tercio@0
|
233 return true
|
tercio@0
|
234 end
|
tercio@0
|
235
|
tercio@0
|
236 function lib:Fetch(mediatype, key, noDefault)
|
tercio@0
|
237 local mtt = mediaTable[mediatype]
|
tercio@0
|
238 local overridekey = overrideMedia[mediatype]
|
tercio@0
|
239 local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil
|
tercio@0
|
240 return result ~= "" and result or nil
|
tercio@0
|
241 end
|
tercio@0
|
242
|
tercio@0
|
243 function lib:IsValid(mediatype, key)
|
tercio@0
|
244 return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false
|
tercio@0
|
245 end
|
tercio@0
|
246
|
tercio@0
|
247 function lib:HashTable(mediatype)
|
tercio@0
|
248 return mediaTable[mediatype]
|
tercio@0
|
249 end
|
tercio@0
|
250
|
tercio@0
|
251 function lib:List(mediatype)
|
tercio@0
|
252 if not mediaTable[mediatype] then
|
tercio@0
|
253 return nil
|
tercio@0
|
254 end
|
tercio@0
|
255 if not mediaList[mediatype] then
|
tercio@0
|
256 rebuildMediaList(mediatype)
|
tercio@0
|
257 end
|
tercio@0
|
258 return mediaList[mediatype]
|
tercio@0
|
259 end
|
tercio@0
|
260
|
tercio@0
|
261 function lib:GetGlobal(mediatype)
|
tercio@0
|
262 return overrideMedia[mediatype]
|
tercio@0
|
263 end
|
tercio@0
|
264
|
tercio@0
|
265 function lib:SetGlobal(mediatype, key)
|
tercio@0
|
266 if not mediaTable[mediatype] then
|
tercio@0
|
267 return false
|
tercio@0
|
268 end
|
tercio@0
|
269 overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil
|
tercio@0
|
270 self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype])
|
tercio@0
|
271 return true
|
tercio@0
|
272 end
|
tercio@0
|
273
|
tercio@0
|
274 function lib:GetDefault(mediatype)
|
tercio@0
|
275 return defaultMedia[mediatype]
|
tercio@0
|
276 end
|
tercio@0
|
277
|
tercio@0
|
278 function lib:SetDefault(mediatype, key)
|
tercio@0
|
279 if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then
|
tercio@0
|
280 defaultMedia[mediatype] = key
|
tercio@0
|
281 return true
|
tercio@0
|
282 else
|
tercio@0
|
283 return false
|
tercio@0
|
284 end
|
tercio@0
|
285 end
|