skins, not fully working

This commit is contained in:
Henrique Santiago 2012-06-18 04:47:35 -03:00
parent 1c7bbaea89
commit 2d04d41f09
6 changed files with 109 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Module
reloadable: false reloadable: false
load-later: load-later:
- client_skins
- client_locales - client_locales
- client_topmenu - client_topmenu
- client_background - client_background

View File

@ -0,0 +1,77 @@
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
Settings.set('skin', optionText)
reloadModules()
end
end
-- public functions
function Skins.init()
installedSkins = {}
Skins.installSkins('skins')
local userSkinName = Settings.get('skin')
if userSkinName and Skins.setSkin(userSkinName) then
info('Using configured skin: ' .. userSkinName)
else
info('Using default skin: ' .. defaultSkinName)
Skins.setSkin(defaultSkinName)
Settings.set('skin', defaultSkinName)
end
addEvent( function()
skinComboBox = createWidget('ComboBox', rootWidget:recursiveGetChildById('rightButtonsPanel'))
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()
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
installedSkins[skin.name] = skin
-- todo: maybe combine styles if skin already exists
return true
end
function Skins.installSkins(directory)
dofiles(directory)
end
function Skins.setSkin(name)
local skin = installedSkins[name]
if not skin then
warning("Skin " .. name .. ' does not exist.')
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])
end
currentSkin = skin
return true
end

View File

@ -0,0 +1,12 @@
Module
name: client_skins
description: Changes modules styles
author: baxnie
website: www.otclient.info
@onLoad: |
dofile 'skins'
Skins.init()
@onUnload: |
Skins.terminate()

View File

@ -0,0 +1,7 @@
local skin = {
name = 'Default',
styles = {}
}
Skins.installSkin(skin)

View File

@ -0,0 +1,9 @@
local skin = {
name = 'Example',
styles = {
'topmenu.otui'
}
}
Skins.installSkin(skin)

View File

@ -0,0 +1,3 @@
#TopButton < UIButton
size: 36 36
background-color: #ff0000