diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 4415d580..ced80071 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -8,6 +8,7 @@ Module reloadable: false load-later: + - client_skins - client_locales - client_topmenu - client_background diff --git a/modules/client_skins/skins.lua b/modules/client_skins/skins.lua new file mode 100644 index 00000000..2956d284 --- /dev/null +++ b/modules/client_skins/skins.lua @@ -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 diff --git a/modules/client_skins/skins.otmod b/modules/client_skins/skins.otmod new file mode 100644 index 00000000..1c81a4f9 --- /dev/null +++ b/modules/client_skins/skins.otmod @@ -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() diff --git a/modules/client_skins/skins/default.lua b/modules/client_skins/skins/default.lua new file mode 100644 index 00000000..4d326003 --- /dev/null +++ b/modules/client_skins/skins/default.lua @@ -0,0 +1,7 @@ +local skin = { + name = 'Default', + + styles = {} +} + +Skins.installSkin(skin) diff --git a/modules/client_skins/skins/example.lua b/modules/client_skins/skins/example.lua new file mode 100644 index 00000000..3f8fd1b2 --- /dev/null +++ b/modules/client_skins/skins/example.lua @@ -0,0 +1,9 @@ +local skin = { + name = 'Example', + + styles = { + 'topmenu.otui' + } +} + +Skins.installSkin(skin) diff --git a/modules/client_skins/skins/example/topmenu.otui b/modules/client_skins/skins/example/topmenu.otui new file mode 100644 index 00000000..80e1cf8b --- /dev/null +++ b/modules/client_skins/skins/example/topmenu.otui @@ -0,0 +1,3 @@ +#TopButton < UIButton + size: 36 36 + background-color: #ff0000 \ No newline at end of file