ESOUI SVN LibMediaProvider

[/] [trunk/] [LibMediaProvider-1.0/] [LibMediaProvider-1.0/] [LibMediaProvider-1.0.lua] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Seerah-7
--LibMediaProvider-1.0 is inspired by and borrows from LibSharedMedia-3.0 for World of Warcraft by Elkano
2 Seerah-7
--LibSharedMedia-3.0 and LibMediaProvider-1.0 are under the LGPL-2.1 license
3 Seerah-7
 
4 11 Seerah-7
local MAJOR, MINOR = "LibMediaProvider-1.0", 7 -- remember to increase manually on changes
5 2 Seerah-7
local LMP = LibStub:NewLibrary(MAJOR, MINOR)
6 Seerah-7
if not LMP then return end
7 Seerah-7
 
8 Seerah-7
local cm = CALLBACK_MANAGER
9 Seerah-7
local tinsert = table.insert
10 Seerah-7
local tsort = table.sort
11 Seerah-7
local pairs = pairs
12 Seerah-7
 
13 9 Seerah-7
LMP.DefaultMedia = LMP.DefaultMedia or {}
14 Seerah-7
LMP.MediaList = LMP.MediaList or {}
15 Seerah-7
LMP.MediaTable = LMP.MediaTable or {}
16 10 Seerah-7
if not LMP.MediaType then
17 Seerah-7
        LMP.MediaType = {
18 Seerah-7
                BACKGROUND = "background",      -- background textures
19 Seerah-7
                BORDER = "border",                      -- border textures
20 Seerah-7
                FONT = "font",                          -- fonts
21 Seerah-7
                STATUSBAR = "statusbar",        -- statusbar textures
22 Seerah-7
                SOUND = "sound",                        -- sound files
23 Seerah-7
        }
24 Seerah-7
end
25 2 Seerah-7
local defaultMedia = LMP.DefaultMedia
26 Seerah-7
local mediaList = LMP.MediaList
27 Seerah-7
local mediaTable = LMP.MediaTable
28 Seerah-7
 
29 Seerah-7
--DEFAULT UI MEDIA--
30 Seerah-7
-- BACKGROUND
31 10 Seerah-7
LMP.MediaTable.background = LMP.MediaTable.background or {}
32 4 Seerah-7
--commented out because it still leaves a white texture behind - addons can use alpha to hide the background
33 Seerah-7
--LMP.MediaTable.background["None"]                             = ""
34 2 Seerah-7
LMP.MediaTable.background["ESO Black"]                  = "EsoUI/Art/Miscellaneous/borderedinset_center.dds"
35 Seerah-7
LMP.MediaTable.background["ESO Chat"]                   = "EsoUI/Art/chatwindow/chat_bg_center.dds"
36 Seerah-7
LMP.MediaTable.background["ESO Gray"]                   = "EsoUI/Art/itemtooltip/simpleprogbarbg_center.dds"
37 8 Seerah-7
LMP.MediaTable.background["Solid"]                              = ""
38 5 Seerah-7
--LMP.DefaultMedia.background = "None"
39 Seerah-7
LMP.DefaultMedia.background = "Solid"
40 2 Seerah-7
 
41 Seerah-7
-- BORDER
42 10 Seerah-7
LMP.MediaTable.border = LMP.MediaTable.border or {}
43 3 Seerah-7
--commented out because it still leaves a white texture behind - addons can use alpha to hide the border
44 Seerah-7
--LMP.MediaTable.border["None"]                                 = ""
45 2 Seerah-7
LMP.MediaTable.border["ESO Gold"]                               = "EsoUI/Art/Miscellaneous/borderedinsettransparent_edgefile.dds"
46 Seerah-7
LMP.MediaTable.border["ESO Chat"]                               = "EsoUI/Art/chatwindow/chat_bg_edge.dds"
47 Seerah-7
LMP.MediaTable.border["ESO Rounded"]                    = "EsoUI/Art/miscellaneous/interactkeyframe_edge.dds"
48 Seerah-7
LMP.MediaTable.border["ESO Blue Highlight"]             = "EsoUI/Art/miscellaneous/textentry_highlight_edge.dds"
49 3 Seerah-7
LMP.MediaTable.border["ESO Blue Glow"]                  = "EsoUI/Art/crafting/crafting_tooltip_glow_edge_blue64.dds"
50 Seerah-7
LMP.MediaTable.border["ESO Red Glow"]                   = "EsoUI/Art/crafting/crafting_tooltip_glow_edge_red64.dds"
51 Seerah-7
LMP.MediaTable.border["ESO Red Overlay"]                = "EsoUI/Art/uicombatoverlay/uicombatoverlayedge.dds"
52 5 Seerah-7
--LMP.DefaultMedia.border = "None"
53 Seerah-7
LMP.DefaultMedia.border = "ESO Gold"
54 2 Seerah-7
 
55 Seerah-7
-- FONT
56 10 Seerah-7
LMP.MediaTable.font = LMP.MediaTable.font or {}
57 2 Seerah-7
LMP.MediaTable.font["ProseAntique"]                             = "EsoUI/Common/Fonts/ProseAntiquePSMT.otf"
58 Seerah-7
LMP.MediaTable.font["Consolas"]                                 = "EsoUI/Common/Fonts/consola.ttf"
59 11 Seerah-7
LMP.MediaTable.font["Futura Condensed Light"]   = "EsoUI/Common/Fonts/FuturaStd-CondensedLight.otf"
60 Seerah-7
LMP.MediaTable.font["Futura Condensed"]                 = "EsoUI/Common/Fonts/FuturaStd-Condensed.otf"
61 2 Seerah-7
LMP.MediaTable.font["Skyrim Handwritten"]               = "EsoUI/Common/Fonts/Handwritten_Bold.otf"
62 Seerah-7
LMP.MediaTable.font["Trajan Pro"]                               = "EsoUI/Common/Fonts/trajanpro-regular.otf"
63 Seerah-7
LMP.MediaTable.font["Univers 55"]                               = "EsoUI/Common/Fonts/univers55.otf"
64 Seerah-7
LMP.MediaTable.font["Univers 57"]                               = "EsoUI/Common/Fonts/univers57.otf"
65 Seerah-7
LMP.MediaTable.font["Univers 67"]                               = "EsoUI/Common/Fonts/univers67.otf"
66 11 Seerah-7
LMP.DefaultMedia.font = "Univers 55"
67 2 Seerah-7
 
68 Seerah-7
-- STATUSBAR
69 10 Seerah-7
LMP.MediaTable.statusbar = LMP.MediaTable.statusbar or {}
70 8 Seerah-7
--LMP.MediaTable.statusbar["ESO Basic"]                 = "EsoUI/Art/miscellaneous/progressbar_genericfill_tall.dds"
71 Seerah-7
LMP.MediaTable.statusbar["ESO Basic"]                   = ""
72 2 Seerah-7
LMP.DefaultMedia.statusbar = "ESO Basic"
73 Seerah-7
 
74 Seerah-7
-- SOUND
75 10 Seerah-7
LMP.MediaTable.sound = LMP.MediaTable.sound or {}
76 2 Seerah-7
LMP.MediaTable.sound["None"]                                    = ""
77 Seerah-7
LMP.MediaTable.sound["AvA Gate Open"]                   = SOUNDS.AVA_GATE_OPENED
78 Seerah-7
LMP.MediaTable.sound["AvA Gate Close"]                  = SOUNDS.AVA_GATE_CLOSED
79 Seerah-7
LMP.MediaTable.sound["Emperor Coronated"]               = SOUNDS.EMPEROR_CORONATED_DAGGERFALL
80 Seerah-7
LMP.MediaTable.sound["Level Up"]                                = SOUNDS.LEVEL_UP
81 Seerah-7
LMP.MediaTable.sound["Skill Gained"]                    = SOUNDS.SKILL_GAINED
82 Seerah-7
LMP.MediaTable.sound["Ability Purchased"]               = SOUNDS.ABILITY_SKILL_PURCHASED
83 Seerah-7
LMP.MediaTable.sound["Book Acquired"]                   = SOUNDS.BOOK_ACQUIRED
84 Seerah-7
LMP.MediaTable.sound["Unlock"]                                  = SOUNDS.LOCKPICKING_UNLOCKED
85 Seerah-7
LMP.MediaTable.sound["Enchanting Extract"]              = SOUNDS.ENCHANTING_EXTRACT_START_ANIM
86 Seerah-7
LMP.MediaTable.sound["Enchanting Create"]               = SOUNDS.ENCHANTING_CREATE_TOOLTIP_GLOW
87 Seerah-7
LMP.MediaTable.sound["Blacksmith Improve"]              = SOUNDS.BLACKSMITH_IMPROVE_TOOLTIP_GLOW_SUCCESS
88 Seerah-7
LMP.DefaultMedia.sound = "None"
89 Seerah-7
 
90 Seerah-7
local function rebuildMediaList(mediatype)
91 Seerah-7
        local mtable = mediaTable[mediatype]
92 Seerah-7
        if not mtable then return end
93 Seerah-7
        if not mediaList[mediatype] then mediaList[mediatype] = {} end
94 Seerah-7
        local mlist = mediaList[mediatype]
95 Seerah-7
        -- list can only get larger, so simply overwrite it
96 Seerah-7
        local i = 0
97 Seerah-7
        for k in pairs(mtable) do
98 Seerah-7
                i = i + 1
99 Seerah-7
                mlist[i] = k
100 Seerah-7
        end
101 Seerah-7
        tsort(mlist)
102 Seerah-7
end
103 Seerah-7
 
104 Seerah-7
function LMP:Register(mediatype, key, data)
105 Seerah-7
        if type(mediatype) ~= "string" then
106 Seerah-7
                error(MAJOR..":Register(mediatype, key, data) - mediatype must be string, got "..type(mediatype))
107 Seerah-7
        end
108 Seerah-7
        if type(key) ~= "string" then
109 Seerah-7
                error(MAJOR..":Register(mediatype, key, data) - key must be string, got "..type(key))
110 Seerah-7
        end
111 Seerah-7
        mediatype = mediatype:lower()
112 Seerah-7
        if not mediaTable[mediatype] then
113 Seerah-7
                mediaTable[mediatype] = {}
114 Seerah-7
        end
115 Seerah-7
 
116 Seerah-7
        local mtable = mediaTable[mediatype]
117 Seerah-7
        if mtable[key] then
118 Seerah-7
                return false
119 Seerah-7
        end
120 Seerah-7
        mtable[key] = data
121 Seerah-7
        rebuildMediaList(mediatype)
122 Seerah-7
        cm:FireCallbacks("LibMediaProvider_Registered", mediatype, key)
123 Seerah-7
        return true
124 Seerah-7
end
125 Seerah-7
 
126 Seerah-7
function LMP:Fetch(mediatype, key)
127 Seerah-7
        local mtt = mediaTable[mediatype]
128 7 Seerah-7
        local result = (mtt and mtt[key]) or (defaultMedia[mediatype] and mtt[defaultMedia[mediatype]])
129 2 Seerah-7
        return result ~= "" and result or nil
130 Seerah-7
end
131 Seerah-7
 
132 Seerah-7
function LMP:IsValid(mediatype, key)
133 Seerah-7
        return mediaTable[mediatype] and (not key or mediaTable[mediatype][key]) and true or false
134 Seerah-7
end
135 Seerah-7
 
136 Seerah-7
function LMP:HashTable(mediatype)
137 Seerah-7
        return mediaTable[mediatype]
138 Seerah-7
end
139 Seerah-7
 
140 Seerah-7
function LMP:List(mediatype)
141 Seerah-7
        if not mediaTable[mediatype] then
142 Seerah-7
                return nil
143 Seerah-7
        end
144 Seerah-7
        if not mediaList[mediatype] then
145 Seerah-7
                rebuildMediaList(mediatype)
146 Seerah-7
        end
147 Seerah-7
        return mediaList[mediatype]
148 Seerah-7
end
149 Seerah-7
 
150 Seerah-7
function LMP:GetDefault(mediatype)
151 Seerah-7
        return defaultMedia[mediatype]
152 Seerah-7
end
153 Seerah-7
 
154 Seerah-7
function LMP:SetDefault(mediatype, key)
155 Seerah-7
        if mediaTable[mediatype] and mediaTable[mediatype][key] and not defaultMedia[mediatype] then
156 Seerah-7
                defaultMedia[mediatype] = key
157 Seerah-7
                return true
158 Seerah-7
        else
159 Seerah-7
                return false
160 Seerah-7
        end
161 Seerah-7
end
162 Seerah-7
 
163 Seerah-7