Mercurial > wow > hotcorners
comparison Libs/LibSharedMedia-3.0/LibSharedMedia-3.0.lua @ 0:fc346da3afd9
First commit Hot Corners standalone.
author | tercio |
---|---|
date | Fri, 08 Aug 2014 12:35:17 -0300 |
parents | |
children | c31ee4251181 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc346da3afd9 |
---|---|
1 --[[ | |
2 Name: LibSharedMedia-3.0 | |
3 Revision: $Revision: 69 $ | |
4 Author: Elkano (elkano@gmx.de) | |
5 Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com) | |
6 Website: http://www.wowace.com/projects/libsharedmedia-3-0/ | |
7 Description: Shared handling of media data (fonts, sounds, textures, ...) between addons. | |
8 Dependencies: LibStub, CallbackHandler-1.0 | |
9 License: LGPL v2.1 | |
10 ]] | |
11 | |
12 local MAJOR, MINOR = "LibSharedMedia-3.0", 4030402 -- increase manualy on changes | |
13 local lib = LibStub:NewLibrary(MAJOR, MINOR) | |
14 | |
15 if not lib then return end | |
16 | |
17 local _G = getfenv(0) | |
18 | |
19 local pairs = _G.pairs | |
20 local type = _G.type | |
21 | |
22 local band = _G.bit.band | |
23 | |
24 local table_insert = _G.table.insert | |
25 local table_sort = _G.table.sort | |
26 | |
27 local locale = GetLocale() | |
28 local locale_is_western | |
29 local LOCALE_MASK = 0 | |
30 lib.LOCALE_BIT_koKR = 1 | |
31 lib.LOCALE_BIT_ruRU = 2 | |
32 lib.LOCALE_BIT_zhCN = 4 | |
33 lib.LOCALE_BIT_zhTW = 8 | |
34 lib.LOCALE_BIT_western = 128 | |
35 | |
36 local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0") | |
37 | |
38 lib.callbacks = lib.callbacks or CallbackHandler:New(lib) | |
39 | |
40 lib.DefaultMedia = lib.DefaultMedia or {} | |
41 lib.MediaList = lib.MediaList or {} | |
42 lib.MediaTable = lib.MediaTable or {} | |
43 lib.MediaType = lib.MediaType or {} | |
44 lib.OverrideMedia = lib.OverrideMedia or {} | |
45 | |
46 local defaultMedia = lib.DefaultMedia | |
47 local mediaList = lib.MediaList | |
48 local mediaTable = lib.MediaTable | |
49 local overrideMedia = lib.OverrideMedia | |
50 | |
51 | |
52 -- create mediatype constants | |
53 lib.MediaType.BACKGROUND = "background" -- background textures | |
54 lib.MediaType.BORDER = "border" -- border textures | |
55 lib.MediaType.FONT = "font" -- fonts | |
56 lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures | |
57 lib.MediaType.SOUND = "sound" -- sound files | |
58 | |
59 -- populate lib with default Blizzard data | |
60 -- BACKGROUND | |
61 if not lib.MediaTable.background then lib.MediaTable.background = {} end | |
62 lib.MediaTable.background["None"] = [[]] | |
63 lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]] | |
64 lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]] | |
65 lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]] | |
66 lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]] | |
67 lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]] | |
68 lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]] | |
69 lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]] | |
70 lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]] | |
71 lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]] | |
72 lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]] | |
73 lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]] | |
74 lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]] | |
75 lib.DefaultMedia.background = "None" | |
76 | |
77 -- BORDER | |
78 if not lib.MediaTable.border then lib.MediaTable.border = {} end | |
79 lib.MediaTable.border["None"] = [[]] | |
80 lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]] | |
81 lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]] | |
82 lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]] | |
83 lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]] | |
84 lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]] | |
85 lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]] | |
86 lib.DefaultMedia.border = "None" | |
87 | |
88 -- FONT | |
89 if not lib.MediaTable.font then lib.MediaTable.font = {} end | |
90 local SML_MT_font = lib.MediaTable.font | |
91 if locale == "koKR" then | |
92 LOCALE_MASK = lib.LOCALE_BIT_koKR | |
93 -- | |
94 SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]] | |
95 SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]] | |
96 SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]] | |
97 SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]] | |
98 -- | |
99 lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed | |
100 -- | |
101 elseif locale == "zhCN" then | |
102 LOCALE_MASK = lib.LOCALE_BIT_zhCN | |
103 -- | |
104 SML_MT_font["伤害数字"] = [[Fonts\ARKai_C.ttf]] | |
105 SML_MT_font["默认"] = [[Fonts\ARKai_T.ttf]] | |
106 SML_MT_font["聊天"] = [[Fonts\ARHei.ttf]] | |
107 -- | |
108 lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed | |
109 -- | |
110 elseif locale == "zhTW" then | |
111 LOCALE_MASK = lib.LOCALE_BIT_zhTW | |
112 -- | |
113 SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]] | |
114 SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]] | |
115 SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]] | |
116 SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]] | |
117 -- | |
118 lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed | |
119 | |
120 elseif locale == "ruRU" then | |
121 LOCALE_MASK = lib.LOCALE_BIT_ruRU | |
122 -- | |
123 SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]] | |
124 SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]] | |
125 SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS.TTF]] | |
126 SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]] | |
127 SML_MT_font["Skurri"] = [[Fonts\SKURRI.TTF]] | |
128 -- | |
129 lib.DefaultMedia.font = "Friz Quadrata TT" | |
130 -- | |
131 else | |
132 LOCALE_MASK = lib.LOCALE_BIT_western | |
133 locale_is_western = true | |
134 -- | |
135 SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]] | |
136 SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]] | |
137 SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS.TTF]] | |
138 SML_MT_font["Skurri"] = [[Fonts\SKURRI.TTF]] | |
139 -- | |
140 lib.DefaultMedia.font = "Friz Quadrata TT" | |
141 -- | |
142 end | |
143 | |
144 -- STATUSBAR | |
145 if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end | |
146 lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]] | |
147 lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]] | |
148 lib.DefaultMedia.statusbar = "Blizzard" | |
149 | |
150 -- SOUND | |
151 if not lib.MediaTable.sound then lib.MediaTable.sound = {} end | |
152 lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on non-existing input. | |
153 lib.DefaultMedia.sound = "None" | |
154 | |
155 local function rebuildMediaList(mediatype) | |
156 local mtable = mediaTable[mediatype] | |
157 if not mtable then return end | |
158 if not mediaList[mediatype] then mediaList[mediatype] = {} end | |
159 local mlist = mediaList[mediatype] | |
160 -- list can only get larger, so simply overwrite it | |
161 local i = 0 | |
162 for k in pairs(mtable) do | |
163 i = i + 1 | |
164 mlist[i] = k | |
165 end | |
166 table_sort(mlist) | |
167 end | |
168 | |
169 function lib:Register(mediatype, key, data, langmask) | |
170 if type(mediatype) ~= "string" then | |
171 error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype)) | |
172 end | |
173 if type(key) ~= "string" then | |
174 error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key)) | |
175 end | |
176 mediatype = mediatype:lower() | |
177 if mediatype == lib.MediaType.FONT and ((langmask and band(langmask, LOCALE_MASK) == 0) or not (langmask or locale_is_western)) then return false end | |
178 if not mediaTable[mediatype] then mediaTable[mediatype] = {} end | |
179 local mtable = mediaTable[mediatype] | |
180 if mtable[key] then return false end | |
181 | |
182 mtable[key] = data | |
183 rebuildMediaList(mediatype) | |
184 self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key) | |
185 return true | |
186 end | |
187 | |
188 function lib:Fetch(mediatype, key, noDefault) | |
189 local mtt = mediaTable[mediatype] | |
190 local overridekey = overrideMedia[mediatype] | |
191 local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil | |
192 return result ~= "" and result or nil | |
193 end | |
194 | |
195 function lib:IsValid(mediatype, key) | |
196 return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false | |
197 end | |
198 | |
199 function lib:HashTable(mediatype) | |
200 return mediaTable[mediatype] | |
201 end | |
202 | |
203 function lib:List(mediatype) | |
204 if not mediaTable[mediatype] then | |
205 return nil | |
206 end | |
207 if not mediaList[mediatype] then | |
208 rebuildMediaList(mediatype) | |
209 end | |
210 return mediaList[mediatype] | |
211 end | |
212 | |
213 function lib:GetGlobal(mediatype) | |
214 return overrideMedia[mediatype] | |
215 end | |
216 | |
217 function lib:SetGlobal(mediatype, key) | |
218 if not mediaTable[mediatype] then | |
219 return false | |
220 end | |
221 overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil | |
222 self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype]) | |
223 return true | |
224 end | |
225 | |
226 function lib:GetDefault(mediatype) | |
227 return defaultMedia[mediatype] | |
228 end | |
229 | |
230 function lib:SetDefault(mediatype, key) | |
231 if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then | |
232 defaultMedia[mediatype] = key | |
233 return true | |
234 else | |
235 return false | |
236 end | |
237 end |