Tercio@23: --[[ Tercio@23: Name: LibSharedMedia-3.0 Tercio@58: Revision: $Revision: 91 $ Tercio@23: Author: Elkano (elkano@gmx.de) Tercio@23: Inspired By: SurfaceLib by Haste/Otravi (troeks@gmail.com) Tercio@23: Website: http://www.wowace.com/projects/libsharedmedia-3-0/ Tercio@23: Description: Shared handling of media data (fonts, sounds, textures, ...) between addons. Tercio@23: Dependencies: LibStub, CallbackHandler-1.0 Tercio@23: License: LGPL v2.1 Tercio@23: ]] Tercio@23: Tercio@58: local MAJOR, MINOR = "LibSharedMedia-3.0", 6010002 -- 6.1.0 v2 / increase manually on changes Tercio@23: local lib = LibStub:NewLibrary(MAJOR, MINOR) Tercio@23: Tercio@23: if not lib then return end Tercio@23: Tercio@23: local _G = getfenv(0) Tercio@23: Tercio@23: local pairs = _G.pairs Tercio@23: local type = _G.type Tercio@23: Tercio@23: local band = _G.bit.band Tercio@23: Tercio@23: local table_insert = _G.table.insert Tercio@23: local table_sort = _G.table.sort Tercio@23: Tercio@23: local locale = GetLocale() Tercio@23: local locale_is_western Tercio@23: local LOCALE_MASK = 0 Tercio@23: lib.LOCALE_BIT_koKR = 1 Tercio@23: lib.LOCALE_BIT_ruRU = 2 Tercio@23: lib.LOCALE_BIT_zhCN = 4 Tercio@23: lib.LOCALE_BIT_zhTW = 8 Tercio@23: lib.LOCALE_BIT_western = 128 Tercio@23: Tercio@23: local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0") Tercio@23: Tercio@23: lib.callbacks = lib.callbacks or CallbackHandler:New(lib) Tercio@23: Tercio@23: lib.DefaultMedia = lib.DefaultMedia or {} Tercio@23: lib.MediaList = lib.MediaList or {} Tercio@23: lib.MediaTable = lib.MediaTable or {} Tercio@23: lib.MediaType = lib.MediaType or {} Tercio@23: lib.OverrideMedia = lib.OverrideMedia or {} Tercio@23: Tercio@23: local defaultMedia = lib.DefaultMedia Tercio@23: local mediaList = lib.MediaList Tercio@23: local mediaTable = lib.MediaTable Tercio@23: local overrideMedia = lib.OverrideMedia Tercio@23: Tercio@23: Tercio@23: -- create mediatype constants Tercio@23: lib.MediaType.BACKGROUND = "background" -- background textures Tercio@23: lib.MediaType.BORDER = "border" -- border textures Tercio@23: lib.MediaType.FONT = "font" -- fonts Tercio@23: lib.MediaType.STATUSBAR = "statusbar" -- statusbar textures Tercio@23: lib.MediaType.SOUND = "sound" -- sound files Tercio@23: Tercio@23: -- populate lib with default Blizzard data Tercio@23: -- BACKGROUND Tercio@23: if not lib.MediaTable.background then lib.MediaTable.background = {} end Tercio@23: lib.MediaTable.background["None"] = [[]] Tercio@58: lib.MediaTable.background["Blizzard Collections Background"] = [[Interface\Collections\CollectionsBackgroundTile]] Tercio@23: lib.MediaTable.background["Blizzard Dialog Background"] = [[Interface\DialogFrame\UI-DialogBox-Background]] Tercio@23: lib.MediaTable.background["Blizzard Dialog Background Dark"] = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]] Tercio@23: lib.MediaTable.background["Blizzard Dialog Background Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]] Tercio@58: lib.MediaTable.background["Blizzard Garrison Background"] = [[Interface\Garrison\GarrisonUIBackground]] Tercio@58: lib.MediaTable.background["Blizzard Garrison Background 2"] = [[Interface\Garrison\GarrisonUIBackground2]] Tercio@58: lib.MediaTable.background["Blizzard Garrison Background 3"] = [[Interface\Garrison\GarrisonMissionUIInfoBoxBackgroundTile]] Tercio@23: lib.MediaTable.background["Blizzard Low Health"] = [[Interface\FullScreenTextures\LowHealth]] Tercio@23: lib.MediaTable.background["Blizzard Marble"] = [[Interface\FrameGeneral\UI-Background-Marble]] Tercio@23: lib.MediaTable.background["Blizzard Out of Control"] = [[Interface\FullScreenTextures\OutOfControl]] Tercio@23: lib.MediaTable.background["Blizzard Parchment"] = [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]] Tercio@23: lib.MediaTable.background["Blizzard Parchment 2"] = [[Interface\AchievementFrame\UI-GuildAchievement-Parchment-Horizontal]] Tercio@23: lib.MediaTable.background["Blizzard Rock"] = [[Interface\FrameGeneral\UI-Background-Rock]] Tercio@23: lib.MediaTable.background["Blizzard Tabard Background"] = [[Interface\TabardFrame\TabardFrameBackground]] Tercio@23: lib.MediaTable.background["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Background]] Tercio@23: lib.MediaTable.background["Solid"] = [[Interface\Buttons\WHITE8X8]] Tercio@23: lib.DefaultMedia.background = "None" Tercio@23: Tercio@23: -- BORDER Tercio@23: if not lib.MediaTable.border then lib.MediaTable.border = {} end Tercio@23: lib.MediaTable.border["None"] = [[]] Tercio@23: lib.MediaTable.border["Blizzard Achievement Wood"] = [[Interface\AchievementFrame\UI-Achievement-WoodBorder]] Tercio@23: lib.MediaTable.border["Blizzard Chat Bubble"] = [[Interface\Tooltips\ChatBubble-Backdrop]] Tercio@23: lib.MediaTable.border["Blizzard Dialog"] = [[Interface\DialogFrame\UI-DialogBox-Border]] Tercio@23: lib.MediaTable.border["Blizzard Dialog Gold"] = [[Interface\DialogFrame\UI-DialogBox-Gold-Border]] Tercio@23: lib.MediaTable.border["Blizzard Party"] = [[Interface\CHARACTERFRAME\UI-Party-Border]] Tercio@23: lib.MediaTable.border["Blizzard Tooltip"] = [[Interface\Tooltips\UI-Tooltip-Border]] Tercio@23: lib.DefaultMedia.border = "None" Tercio@23: Tercio@23: -- FONT Tercio@23: if not lib.MediaTable.font then lib.MediaTable.font = {} end Tercio@23: local SML_MT_font = lib.MediaTable.font Tercio@58: --[[ Tercio@58: All font files are currently in all clients, the following table depicts which font supports which charset as of 5.0.4 Tercio@58: Fonts were checked using langcover.pl from DejaVu fonts (http://sourceforge.net/projects/dejavu/) and FontForge (http://fontforge.org/) Tercio@58: latin means check for: de, en, es, fr, it, pt Tercio@58: Tercio@58: file name latin koKR ruRU zhCN zhTW Tercio@58: 2002.ttf 2002 X X X - - Tercio@58: 2002B.ttf 2002 Bold X X X - - Tercio@58: ARHei.ttf AR CrystalzcuheiGBK Demibold X - X X X Tercio@58: ARIALN.TTF Arial Narrow X - X - - Tercio@58: ARKai_C.ttf AR ZhongkaiGBK Medium (Combat) X - X X X Tercio@58: ARKai_T.ttf AR ZhongkaiGBK Medium X - X X X Tercio@58: bHEI00M.ttf AR Heiti2 Medium B5 - - - - X Tercio@58: bHEI01B.ttf AR Heiti2 Bold B5 - - - - X Tercio@58: bKAI00M.ttf AR Kaiti Medium B5 - - - - X Tercio@58: bLEI00D.ttf AR Leisu Demi B5 - - - - X Tercio@58: FRIZQT__.TTF Friz Quadrata TT X - - - - Tercio@58: FRIZQT___CYR.TTF FrizQuadrataCTT x - X - - Tercio@58: K_Damage.TTF YDIWingsM - X X - - Tercio@58: K_Pagetext.TTF MoK X X X - - Tercio@58: MORPHEUS.TTF Morpheus X - - - - Tercio@58: MORPHEUS_CYR.TTF Morpheus X - X - - Tercio@58: NIM_____.ttf Nimrod MT X - X - - Tercio@58: SKURRI.TTF Skurri X - - - - Tercio@58: SKURRI_CYR.TTF Skurri X - X - - Tercio@58: Tercio@58: WARNING: Although FRIZQT___CYR is available on western clients, it doesn't support special European characters e.g. é, ï, ö Tercio@58: Due to this, we cannot use it as a replacement for FRIZQT__.TTF Tercio@58: ]] Tercio@58: Tercio@23: if locale == "koKR" then Tercio@23: LOCALE_MASK = lib.LOCALE_BIT_koKR Tercio@23: -- Tercio@23: SML_MT_font["굵은 글꼴"] = [[Fonts\2002B.TTF]] Tercio@23: SML_MT_font["기본 글꼴"] = [[Fonts\2002.TTF]] Tercio@23: SML_MT_font["데미지 글꼴"] = [[Fonts\K_Damage.TTF]] Tercio@23: SML_MT_font["퀘스트 글꼴"] = [[Fonts\K_Pagetext.TTF]] Tercio@23: -- Tercio@23: lib.DefaultMedia["font"] = "기본 글꼴" -- someone from koKR please adjust if needed Tercio@23: -- Tercio@23: elseif locale == "zhCN" then Tercio@23: LOCALE_MASK = lib.LOCALE_BIT_zhCN Tercio@23: -- Tercio@23: SML_MT_font["伤害数字"] = [[Fonts\ARKai_C.ttf]] Tercio@23: SML_MT_font["默认"] = [[Fonts\ARKai_T.ttf]] Tercio@23: SML_MT_font["聊天"] = [[Fonts\ARHei.ttf]] Tercio@23: -- Tercio@23: lib.DefaultMedia["font"] = "默认" -- someone from zhCN please adjust if needed Tercio@23: -- Tercio@23: elseif locale == "zhTW" then Tercio@23: LOCALE_MASK = lib.LOCALE_BIT_zhTW Tercio@23: -- Tercio@23: SML_MT_font["提示訊息"] = [[Fonts\bHEI00M.ttf]] Tercio@23: SML_MT_font["聊天"] = [[Fonts\bHEI01B.ttf]] Tercio@23: SML_MT_font["傷害數字"] = [[Fonts\bKAI00M.ttf]] Tercio@23: SML_MT_font["預設"] = [[Fonts\bLEI00D.ttf]] Tercio@23: -- Tercio@23: lib.DefaultMedia["font"] = "預設" -- someone from zhTW please adjust if needed Tercio@23: Tercio@23: elseif locale == "ruRU" then Tercio@23: LOCALE_MASK = lib.LOCALE_BIT_ruRU Tercio@23: -- Tercio@58: SML_MT_font["2002"] = [[Fonts\2002.TTF]] Tercio@58: SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]] Tercio@58: SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]] Tercio@58: SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]] Tercio@58: SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]] Tercio@58: SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]] Tercio@58: SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT___CYR.TTF]] Tercio@58: SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]] Tercio@58: SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]] Tercio@58: SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]] Tercio@58: SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]] Tercio@23: -- Tercio@23: lib.DefaultMedia.font = "Friz Quadrata TT" Tercio@23: -- Tercio@23: else Tercio@23: LOCALE_MASK = lib.LOCALE_BIT_western Tercio@23: locale_is_western = true Tercio@23: -- Tercio@58: SML_MT_font["2002"] = [[Fonts\2002.TTF]] Tercio@58: SML_MT_font["2002 Bold"] = [[Fonts\2002B.TTF]] Tercio@58: SML_MT_font["AR CrystalzcuheiGBK Demibold"] = [[Fonts\ARHei.TTF]] Tercio@58: SML_MT_font["AR ZhongkaiGBK Medium (Combat)"] = [[Fonts\ARKai_C.TTF]] Tercio@58: SML_MT_font["AR ZhongkaiGBK Medium"] = [[Fonts\ARKai_T.TTF]] Tercio@58: SML_MT_font["Arial Narrow"] = [[Fonts\ARIALN.TTF]] Tercio@58: SML_MT_font["Friz Quadrata TT"] = [[Fonts\FRIZQT__.TTF]] Tercio@58: SML_MT_font["MoK"] = [[Fonts\K_Pagetext.TTF]] Tercio@58: SML_MT_font["Morpheus"] = [[Fonts\MORPHEUS_CYR.TTF]] Tercio@58: SML_MT_font["Nimrod MT"] = [[Fonts\NIM_____.ttf]] Tercio@58: SML_MT_font["Skurri"] = [[Fonts\SKURRI_CYR.TTF]] Tercio@23: -- Tercio@23: lib.DefaultMedia.font = "Friz Quadrata TT" Tercio@23: -- Tercio@23: end Tercio@23: Tercio@23: -- STATUSBAR Tercio@23: if not lib.MediaTable.statusbar then lib.MediaTable.statusbar = {} end Tercio@23: lib.MediaTable.statusbar["Blizzard"] = [[Interface\TargetingFrame\UI-StatusBar]] Tercio@23: lib.MediaTable.statusbar["Blizzard Character Skills Bar"] = [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]] Tercio@58: lib.MediaTable.statusbar["Blizzard Raid Bar"] = [[Interface\RaidFrame\Raid-Bar-Hp-Fill]] Tercio@23: lib.DefaultMedia.statusbar = "Blizzard" Tercio@23: Tercio@23: -- SOUND Tercio@23: if not lib.MediaTable.sound then lib.MediaTable.sound = {} end Tercio@23: lib.MediaTable.sound["None"] = [[Interface\Quiet.ogg]] -- Relies on the fact that PlaySound[File] doesn't error on non-existing input. Tercio@23: lib.DefaultMedia.sound = "None" Tercio@23: Tercio@23: local function rebuildMediaList(mediatype) Tercio@23: local mtable = mediaTable[mediatype] Tercio@23: if not mtable then return end Tercio@23: if not mediaList[mediatype] then mediaList[mediatype] = {} end Tercio@23: local mlist = mediaList[mediatype] Tercio@23: -- list can only get larger, so simply overwrite it Tercio@23: local i = 0 Tercio@23: for k in pairs(mtable) do Tercio@23: i = i + 1 Tercio@23: mlist[i] = k Tercio@23: end Tercio@23: table_sort(mlist) Tercio@23: end Tercio@23: Tercio@23: function lib:Register(mediatype, key, data, langmask) Tercio@23: if type(mediatype) ~= "string" then Tercio@23: error(MAJOR..":Register(mediatype, key, data, langmask) - mediatype must be string, got "..type(mediatype)) Tercio@23: end Tercio@23: if type(key) ~= "string" then Tercio@23: error(MAJOR..":Register(mediatype, key, data, langmask) - key must be string, got "..type(key)) Tercio@23: end Tercio@23: mediatype = mediatype:lower() Tercio@58: 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@58: if mediatype == lib.MediaType.SOUND and type(data) == "string" then Tercio@58: local path = data:lower() Tercio@58: -- Only ogg and mp3 are valid sounds. Tercio@58: if not path:find(".ogg", nil, true) and not path:find(".mp3", nil, true) then Tercio@58: return false Tercio@58: end Tercio@58: end Tercio@23: if not mediaTable[mediatype] then mediaTable[mediatype] = {} end Tercio@23: local mtable = mediaTable[mediatype] Tercio@23: if mtable[key] then return false end Tercio@23: Tercio@23: mtable[key] = data Tercio@23: rebuildMediaList(mediatype) Tercio@23: self.callbacks:Fire("LibSharedMedia_Registered", mediatype, key) Tercio@23: return true Tercio@23: end Tercio@23: Tercio@23: function lib:Fetch(mediatype, key, noDefault) Tercio@23: local mtt = mediaTable[mediatype] Tercio@23: local overridekey = overrideMedia[mediatype] Tercio@23: local result = mtt and ((overridekey and mtt[overridekey] or mtt[key]) or (not noDefault and defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])) or nil Tercio@23: return result ~= "" and result or nil Tercio@23: end Tercio@23: Tercio@23: function lib:IsValid(mediatype, key) Tercio@23: return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false Tercio@23: end Tercio@23: Tercio@23: function lib:HashTable(mediatype) Tercio@23: return mediaTable[mediatype] Tercio@23: end Tercio@23: Tercio@23: function lib:List(mediatype) Tercio@23: if not mediaTable[mediatype] then Tercio@23: return nil Tercio@23: end Tercio@23: if not mediaList[mediatype] then Tercio@23: rebuildMediaList(mediatype) Tercio@23: end Tercio@23: return mediaList[mediatype] Tercio@23: end Tercio@23: Tercio@23: function lib:GetGlobal(mediatype) Tercio@23: return overrideMedia[mediatype] Tercio@23: end Tercio@23: Tercio@23: function lib:SetGlobal(mediatype, key) Tercio@23: if not mediaTable[mediatype] then Tercio@23: return false Tercio@23: end Tercio@23: overrideMedia[mediatype] = (key and mediaTable[mediatype][key]) and key or nil Tercio@23: self.callbacks:Fire("LibSharedMedia_SetGlobal", mediatype, overrideMedia[mediatype]) Tercio@23: return true Tercio@23: end Tercio@23: Tercio@23: function lib:GetDefault(mediatype) Tercio@23: return defaultMedia[mediatype] Tercio@23: end Tercio@23: Tercio@23: function lib:SetDefault(mediatype, key) Tercio@23: if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then Tercio@23: defaultMedia[mediatype] = key Tercio@23: return true Tercio@23: else Tercio@23: return false Tercio@23: end Tercio@23: end