2012-06-18 09:47:35 +02:00
|
|
|
Skins = { }
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local defaultSkinName = 'Default'
|
|
|
|
local installedSkins
|
|
|
|
local currentSkin
|
|
|
|
local skinComboBox
|
|
|
|
|
|
|
|
-- private functions
|
|
|
|
local function onSkinComboBoxOptionChange(self, optionText, optionData)
|
|
|
|
if Skins.setSkin(optionText) then
|
2012-06-26 00:13:30 +02:00
|
|
|
g_settings.set('skin', optionText)
|
2012-07-14 23:30:00 +02:00
|
|
|
g_textures.clearTexturesCache()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_modules.reloadModules()
|
2012-06-18 09:47:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-19 10:46:49 +02:00
|
|
|
local function getSkinPath(name)
|
2012-08-23 09:17:19 +02:00
|
|
|
return getfsrcpath() .. '/skins/' .. string.lower(name)
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
|
2012-06-18 09:47:35 +02:00
|
|
|
-- public functions
|
|
|
|
function Skins.init()
|
|
|
|
installedSkins = {}
|
|
|
|
|
|
|
|
Skins.installSkins('skins')
|
|
|
|
|
2012-06-19 10:46:49 +02:00
|
|
|
if installedSkins[defaultSkinName] then
|
2012-08-23 09:17:19 +02:00
|
|
|
g_resources.addSearchPath(getSkinPath(defaultSkinName), true)
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
local userSkinName = g_settings.get('skin', 'false')
|
2012-06-20 08:31:52 +02:00
|
|
|
if userSkinName ~= 'false' and Skins.setSkin(userSkinName) then
|
2012-06-20 02:15:56 +02:00
|
|
|
pdebug('Using configured skin: ' .. userSkinName)
|
2012-06-18 09:47:35 +02:00
|
|
|
else
|
2012-06-20 02:15:56 +02:00
|
|
|
pdebug('Using default skin: ' .. defaultSkinName)
|
2012-06-18 09:47:35 +02:00
|
|
|
Skins.setSkin(defaultSkinName)
|
2012-06-26 00:13:30 +02:00
|
|
|
g_settings.set('skin', defaultSkinName)
|
2012-06-18 09:47:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
addEvent( function()
|
2012-08-06 16:39:27 +02:00
|
|
|
skinComboBox = g_ui.createWidget('ComboBoxRounded', rootWidget:recursiveGetChildById('rightButtonsPanel'))
|
2012-08-05 17:54:23 +02:00
|
|
|
skinComboBox:setFixedSize(true)
|
2012-06-18 09:47:35 +02:00
|
|
|
for key,value in pairs(installedSkins) do
|
|
|
|
skinComboBox:addOption(value.name)
|
|
|
|
end
|
|
|
|
skinComboBox:setCurrentOption(currentSkin.name)
|
|
|
|
skinComboBox.onOptionChange = onSkinComboBoxOptionChange
|
|
|
|
end, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Skins.terminate()
|
2012-07-16 21:35:14 +02:00
|
|
|
g_resources.removeSearchPath(getSkinPath(defaultSkinName))
|
2012-06-19 10:46:49 +02:00
|
|
|
if currentSkin then
|
2012-07-16 21:35:14 +02:00
|
|
|
g_resources.removeSearchPath(getSkinPath(currentSkin.name))
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
|
2012-06-18 09:47:35 +02:00
|
|
|
installedSkins = nil
|
|
|
|
currentSkin = nil
|
|
|
|
skinComboBox = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function Skins.installSkin(skin)
|
|
|
|
if not skin or not skin.name or not skin.styles then
|
|
|
|
error('Unable to install skin.')
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-06-19 10:46:49 +02:00
|
|
|
if installedSkins[skin.name] then
|
2012-06-20 02:15:56 +02:00
|
|
|
pwarning(skin.name .. ' has been replaced.')
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
|
2012-06-18 09:47:35 +02:00
|
|
|
installedSkins[skin.name] = skin
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Skins.installSkins(directory)
|
|
|
|
dofiles(directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Skins.setSkin(name)
|
|
|
|
local skin = installedSkins[name]
|
|
|
|
if not skin then
|
2012-06-20 02:15:56 +02:00
|
|
|
pwarning("Skin " .. name .. ' does not exist.')
|
2012-06-18 09:47:35 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-06-19 10:46:49 +02:00
|
|
|
g_fonts.clearFonts()
|
2012-06-20 02:15:56 +02:00
|
|
|
g_ui.clearStyles()
|
2012-06-19 10:46:49 +02:00
|
|
|
|
2012-07-16 21:35:14 +02:00
|
|
|
if currentSkin and currentSkin.name ~= defaultSkinName then
|
|
|
|
g_resources.removeSearchPath(getSkinPath(currentSkin.name))
|
|
|
|
end
|
2012-08-06 21:15:20 +02:00
|
|
|
|
2012-07-16 21:35:14 +02:00
|
|
|
if skin.name ~= defaultSkinName then
|
|
|
|
g_resources.addSearchPath(getSkinPath(skin.name), true)
|
2012-08-06 21:15:20 +02:00
|
|
|
Skins.loadSkin(skin)
|
|
|
|
end
|
|
|
|
|
|
|
|
local defaultSkin = installedSkins[defaultSkinName]
|
|
|
|
if not defaultSkin then
|
|
|
|
error("Default skin is not installed.")
|
|
|
|
return false
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
2012-08-06 21:15:20 +02:00
|
|
|
Skins.loadSkin(defaultSkin)
|
2012-06-19 10:46:49 +02:00
|
|
|
|
2012-06-18 09:47:35 +02:00
|
|
|
currentSkin = skin
|
|
|
|
return true
|
|
|
|
end
|
2012-06-19 10:46:49 +02:00
|
|
|
|
|
|
|
function Skins.loadSkin(skin)
|
|
|
|
local lowerName = string.lower(skin.name)
|
|
|
|
|
2012-07-06 07:00:49 +02:00
|
|
|
if skin.fonts then
|
|
|
|
for i=1,#skin.fonts do
|
|
|
|
g_fonts.importFont('skins/' .. lowerName .. '/fonts/' .. skin.fonts[i])
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-05 23:43:45 +02:00
|
|
|
if skin.defaultFont then
|
|
|
|
g_fonts.setDefaultFont(skin.defaultFont)
|
|
|
|
end
|
|
|
|
|
2012-07-06 07:00:49 +02:00
|
|
|
if skin.styles then
|
|
|
|
for i=1,#skin.styles do
|
|
|
|
g_ui.importStyle('skins/' .. lowerName .. '/styles/' .. skin.styles[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if skin.particles then
|
|
|
|
for i=1,#skin.particles do
|
|
|
|
g_particles.importParticle('skins/' .. lowerName .. '/particles/' .. skin.particles[i])
|
|
|
|
end
|
2012-06-19 10:46:49 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-06 21:15:20 +02:00
|
|
|
|
|
|
|
function Skins.hideComboBox()
|
|
|
|
if not skinComboBox then
|
|
|
|
addEvent(Skins.hideComboBox)
|
|
|
|
else
|
|
|
|
skinComboBox:hide()
|
|
|
|
skinComboBox:setWidth(0)
|
|
|
|
end
|
|
|
|
end
|