add modulemanager module

This commit is contained in:
Eduardo Bart
2012-02-05 23:44:47 -02:00
parent a55e138002
commit 64c9e4f1d5
25 changed files with 379 additions and 60 deletions

View File

@@ -0,0 +1,118 @@
ModuleManager = {}
local moduleManagerWindow
local moduleManagerButton
local moduleList
function ModuleManager.init()
moduleManagerWindow = displayUI('modulemanager.otui')
moduleManagerWindow:hide()
moduleList = moduleManagerWindow:getChildById('moduleList')
connect(moduleList, { onChildFocusChange = function(self, focusedChild)
if focusedChild == nil then return end
ModuleManager.updateModuleInfo(focusedChild:getText())
end })
moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle)
addEvent(ModuleManager.listModules)
end
function ModuleManager.terminate()
moduleManagerWindow:destroy()
moduleManagerWindow = nil
moduleManagerButton:destroy()
moduleManagerButton = nil
moduleList = nil
end
function ModuleManager.hide()
moduleManagerWindow:hide()
end
function ModuleManager.show()
moduleManagerWindow:show()
moduleManagerWindow:focus()
moduleManagerWindow:raise()
end
function ModuleManager.toggle()
if moduleManagerWindow:isVisible() then
ModuleManager.hide()
else
ModuleManager.show()
end
end
function ModuleManager.refreshModules()
g_modules.discoverModules()
ModuleManager.listModules()
end
function ModuleManager.listModules()
moduleList:destroyChildren()
local modules = g_modules.getModules()
for i,module in ipairs(modules) do
local label = createWidget('ModuleListLabel', moduleList)
label:setText(module:getName())
end
moduleList:focusChild(moduleList:getFirstChild(), ActiveFocusReason)
end
function ModuleManager.updateModuleInfo(moduleName)
local name = ''
local description = ''
local autoLoad = ''
local author = ''
local website = ''
local version = ''
local canLoad = false
local canUnload = false
local module = g_modules.getModule(moduleName)
if module then
name = module:getName()
description = module:getDescription()
author = module:getAuthor()
website = module:getWebsite()
version = module:getVersion()
canUnload = module:isLoaded()
canLoad = not canUnload
end
moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name)
moduleManagerWindow:recursiveGetChildById('moduleDescription'):setText(description)
moduleManagerWindow:recursiveGetChildById('moduleDescription'):wrapText()
moduleManagerWindow:recursiveGetChildById('moduleAuthor'):setText(author)
moduleManagerWindow:recursiveGetChildById('moduleWebsite'):setText(website)
moduleManagerWindow:recursiveGetChildById('moduleVersion'):setText(version)
moduleManagerWindow:recursiveGetChildById('moduleLoadButton'):setEnabled(canLoad)
moduleManagerWindow:recursiveGetChildById('moduleUnloadButton'):setEnabled(canUnload)
end
function ModuleManager.loadCurrentModule()
local focusedChild = moduleList:getFocusedChild()
if focusedChild then
local module = g_modules.getModule(focusedChild:getText())
if module then
module:load()
ModuleManager.updateModuleInfo(module:getName())
end
end
end
function ModuleManager.unloadCurrentModule()
local focusedChild = moduleList:getFocusedChild()
if focusedChild then
local module = g_modules.getModule(focusedChild:getText())
if module then
module:unload()
ModuleManager.updateModuleInfo(module:getName())
end
end
end

View File

@@ -0,0 +1,11 @@
Module
name: client_modulemanager
description: Manage other modules
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'modulemanager'
ModuleManager.init()
onUnload: |
ModuleManager.terminate()

View File

@@ -0,0 +1,117 @@
ModuleListLabel < Label
font: verdana-11px-monochrome
background-color: alpha
text-offset: 2 0
focusable: true
$focus:
background-color: #ffffff22
color: #ffffff
ModuleInfoLabel < Label
$!first:
margin-top: 5
margin-bottom: 2
ModuleValueLabel < UILabel
font: verdana-11px-antialised
color: #aaaaaa
text-offset: 3 0
image-source: /core_styles/images/panel_flat.png
image-border: 1
MainWindow
id: moduleManagerWindow
size: 450 450
text: Module Manager
@onEscape: ModuleManager.hide()
TextList
id: moduleList
anchors.top: parent.top
anchors.left: parent.left
anchors.bottom: parent.bottom
width: 180
padding: 1
focusable: false
margin-bottom: 30
Button
anchors.top: moduleList.bottom
anchors.horizontalCenter: moduleList.horizontalCenter
margin-top: 8
text: Refresh
@onClick: ModuleManager.refreshModules()
Panel
id: moduleInfo
anchors.left: moduleList.right
anchors.top: parent.top
anchors.right: parent.right
margin: 0 5 5 15
layout:
type: verticalBox
fit-children: true
ModuleInfoLabel
text: Module name
ModuleValueLabel
id: moduleName
ModuleInfoLabel
text: Description
ModuleValueLabel
id: moduleDescription
height: 100
ModuleInfoLabel
text: Loaded
ModuleValueLabel
id: moduleLoaded
//ModuleInfoLabel
// text: Autoload
//ModuleValueLabel
// id: moduleAutoload
//ModuleInfoLabel
// text: Autoload antecedence
//ModuleValueLabel
// id: moduleLoadAntecedence
// text: 1000
ModuleInfoLabel
text: Author
ModuleValueLabel
id: moduleAuthor
ModuleInfoLabel
text: Website
ModuleValueLabel
id: moduleWebsite
ModuleInfoLabel
text: Version
ModuleValueLabel
id: moduleVersion
Button
id: moduleLoadButton
anchors.top: moduleInfo.bottom
anchors.left: moduleInfo.left
margin-top: 8
text: Load
enabled: false
@onClick: ModuleManager.loadCurrentModule()
Button
id: moduleUnloadButton
anchors.top: moduleInfo.bottom
anchors.right: moduleInfo.right
margin-left: 10
margin-top: 8
text: Unload
enabled: false
@onClick: ModuleManager.unloadCurrentModule()

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B