mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
improvements to skins
This commit is contained in:
@@ -14,12 +14,20 @@ local function onSkinComboBoxOptionChange(self, optionText, optionData)
|
||||
end
|
||||
end
|
||||
|
||||
local function getSkinPath(name)
|
||||
return g_modules.getModulesPath() .. g_lua.getCurrentSourcePath(0) .. '/skins/' .. string.lower(name) .. '/'
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Skins.init()
|
||||
installedSkins = {}
|
||||
|
||||
Skins.installSkins('skins')
|
||||
|
||||
if installedSkins[defaultSkinName] then
|
||||
g_resources.addToSearchPath(getSkinPath(defaultSkinName), 0)
|
||||
end
|
||||
|
||||
local userSkinName = Settings.get('skin')
|
||||
if userSkinName and Skins.setSkin(userSkinName) then
|
||||
info('Using configured skin: ' .. userSkinName)
|
||||
@@ -40,6 +48,11 @@ function Skins.init()
|
||||
end
|
||||
|
||||
function Skins.terminate()
|
||||
g_resources.removeFromSearchPath(getSkinPath(defaultSkinName))
|
||||
if currentSkin then
|
||||
g_resources.removeFromSearchPath(getSkinPath(currentSkin.name))
|
||||
end
|
||||
|
||||
installedSkins = nil
|
||||
currentSkin = nil
|
||||
skinComboBox = nil
|
||||
@@ -51,8 +64,11 @@ function Skins.installSkin(skin)
|
||||
return false
|
||||
end
|
||||
|
||||
if installedSkins[skin.name] then
|
||||
warning(skin.name .. ' has been replaced.')
|
||||
end
|
||||
|
||||
installedSkins[skin.name] = skin
|
||||
-- todo: maybe combine styles if skin already exists
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -67,11 +83,41 @@ function Skins.setSkin(name)
|
||||
return false
|
||||
end
|
||||
|
||||
--g_ui.clearStyles() -- this is crashing
|
||||
for i=1,#skin.styles do
|
||||
g_ui.importStyle('skins/' .. string.lower(name) .. '/' .. skin.styles[i])
|
||||
g_fonts.clearFonts()
|
||||
g_ui.clearStyles()
|
||||
|
||||
if name ~= defaultSkinName then
|
||||
local defaultSkin = installedSkins[defaultSkinName]
|
||||
if not defaultSkin then
|
||||
error("Default skin is not installed.")
|
||||
return false
|
||||
end
|
||||
|
||||
Skins.loadSkin(defaultSkin)
|
||||
end
|
||||
|
||||
if currentSkin then
|
||||
g_resources.removeFromSearchPath(getSkinPath(currentSkin.name))
|
||||
end
|
||||
g_resources.addToSearchPath(getSkinPath(skin.name), true)
|
||||
|
||||
Skins.loadSkin(skin)
|
||||
currentSkin = skin
|
||||
return true
|
||||
end
|
||||
|
||||
function Skins.loadSkin(skin)
|
||||
local lowerName = string.lower(skin.name)
|
||||
|
||||
for i=1,#skin.fonts do
|
||||
g_fonts.importFont('skins/' .. lowerName .. '/fonts/' .. skin.fonts[i])
|
||||
|
||||
if i == 1 then
|
||||
g_fonts.setDefaultFont(skin.fonts[i])
|
||||
end
|
||||
end
|
||||
|
||||
for i=1,#skin.styles do
|
||||
g_ui.importStyle('skins/' .. lowerName .. '/styles/' .. skin.styles[i])
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user