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