mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
a lot of changes in modules
This commit is contained in:
@@ -54,25 +54,40 @@ function ModuleManager.refreshModules()
|
||||
end
|
||||
|
||||
function ModuleManager.listModules()
|
||||
if not moduleManagerWindow then return end
|
||||
|
||||
moduleList:destroyChildren()
|
||||
|
||||
local modules = g_modules.getModules()
|
||||
for i,module in ipairs(modules) do
|
||||
local label = createWidget('ModuleListLabel', moduleList)
|
||||
label:setText(module:getName())
|
||||
label:setOn(module:isLoaded())
|
||||
end
|
||||
|
||||
moduleList:focusChild(moduleList:getFirstChild(), ActiveFocusReason)
|
||||
end
|
||||
|
||||
function ModuleManager.refreshLoadedModules()
|
||||
if not moduleManagerWindow then return end
|
||||
|
||||
for i,child in ipairs(moduleList:getChildren()) do
|
||||
local module = g_modules.getModule(child:getText())
|
||||
child:setOn(module:isLoaded())
|
||||
end
|
||||
end
|
||||
|
||||
function ModuleManager.updateModuleInfo(moduleName)
|
||||
if not moduleManagerWindow then return end
|
||||
|
||||
local name = ''
|
||||
local description = ''
|
||||
local autoLoad = ''
|
||||
local author = ''
|
||||
local website = ''
|
||||
local version = ''
|
||||
local canLoad = false
|
||||
local loaded = false
|
||||
local canReload = false
|
||||
local canUnload = false
|
||||
|
||||
local module = g_modules.getModule(moduleName)
|
||||
@@ -82,8 +97,9 @@ function ModuleManager.updateModuleInfo(moduleName)
|
||||
author = module:getAuthor()
|
||||
website = module:getWebsite()
|
||||
version = module:getVersion()
|
||||
canUnload = module:isLoaded()
|
||||
canLoad = not canUnload
|
||||
loaded = module:isLoaded()
|
||||
canUnload = module:canUnload()
|
||||
canReload = not loaded or canUnload
|
||||
end
|
||||
|
||||
moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name)
|
||||
@@ -93,17 +109,26 @@ function ModuleManager.updateModuleInfo(moduleName)
|
||||
moduleManagerWindow:recursiveGetChildById('moduleWebsite'):setText(website)
|
||||
moduleManagerWindow:recursiveGetChildById('moduleVersion'):setText(version)
|
||||
|
||||
moduleManagerWindow:recursiveGetChildById('moduleLoadButton'):setEnabled(canLoad)
|
||||
moduleManagerWindow:recursiveGetChildById('moduleUnloadButton'):setEnabled(canUnload)
|
||||
local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton')
|
||||
reloadButton:setEnabled(canReload)
|
||||
reloadButton:setVisible(true)
|
||||
if loaded then reloadButton:setText('Reload')
|
||||
else reloadButton:setText('Load') end
|
||||
|
||||
local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton')
|
||||
unloadButton:setVisible(true)
|
||||
unloadButton:setEnabled(canUnload)
|
||||
end
|
||||
|
||||
function ModuleManager.loadCurrentModule()
|
||||
function ModuleManager.reloadCurrentModule()
|
||||
local focusedChild = moduleList:getFocusedChild()
|
||||
if focusedChild then
|
||||
local module = g_modules.getModule(focusedChild:getText())
|
||||
if module then
|
||||
module:load()
|
||||
module:reload()
|
||||
ModuleManager.updateModuleInfo(module:getName())
|
||||
ModuleManager.refreshLoadedModules()
|
||||
ModuleManager.show()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -115,7 +140,14 @@ function ModuleManager.unloadCurrentModule()
|
||||
if module then
|
||||
module:unload()
|
||||
ModuleManager.updateModuleInfo(module:getName())
|
||||
ModuleManager.refreshLoadedModules()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ModuleManager.reloadAllModules()
|
||||
g_modules.reloadModules()
|
||||
ModuleManager.refreshLoadedModules()
|
||||
ModuleManager.show()
|
||||
end
|
||||
|
||||
|
@@ -3,6 +3,12 @@ Module
|
||||
description: Manage other modules
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
autoload: true
|
||||
autoload-antecedence: 140
|
||||
|
||||
dependencies:
|
||||
- client_topmenu
|
||||
|
||||
onLoad: |
|
||||
dofile 'modulemanager'
|
||||
ModuleManager.init()
|
||||
|
@@ -3,11 +3,21 @@ ModuleListLabel < Label
|
||||
background-color: alpha
|
||||
text-offset: 2 0
|
||||
focusable: true
|
||||
color: #cccccc
|
||||
|
||||
$focus:
|
||||
background-color: #ffffff22
|
||||
color: #ffffff
|
||||
|
||||
$on:
|
||||
background-color: #006600
|
||||
$!on:
|
||||
background-color: #660000
|
||||
|
||||
$on focus:
|
||||
background-color: #004400
|
||||
$!on focus:
|
||||
background-color: #440000
|
||||
|
||||
ModuleInfoLabel < Label
|
||||
$!first:
|
||||
margin-top: 5
|
||||
@@ -19,10 +29,11 @@ ModuleValueLabel < UILabel
|
||||
text-offset: 3 0
|
||||
image-source: /core_styles/images/panel_flat.png
|
||||
image-border: 1
|
||||
height: 16
|
||||
|
||||
MainWindow
|
||||
id: moduleManagerWindow
|
||||
size: 450 450
|
||||
size: 480 450
|
||||
text: Module Manager
|
||||
|
||||
@onEscape: ModuleManager.hide()
|
||||
@@ -38,21 +49,31 @@ MainWindow
|
||||
margin-bottom: 30
|
||||
|
||||
Button
|
||||
id: refreshModulesButton
|
||||
anchors.top: moduleList.bottom
|
||||
anchors.horizontalCenter: moduleList.horizontalCenter
|
||||
anchors.left: moduleList.left
|
||||
margin-top: 8
|
||||
width: 80
|
||||
text: Refresh
|
||||
@onClick: ModuleManager.refreshModules()
|
||||
|
||||
Button
|
||||
id: reloadAllModulesButton
|
||||
anchors.top: moduleList.bottom
|
||||
anchors.right: moduleList.right
|
||||
margin-top: 8
|
||||
width: 80
|
||||
text: Reload All
|
||||
@onClick: ModuleManager.reloadAllModules()
|
||||
|
||||
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
|
||||
layout: verticalBox
|
||||
height: 265
|
||||
|
||||
ModuleInfoLabel
|
||||
text: Module name
|
||||
@@ -65,11 +86,6 @@ MainWindow
|
||||
id: moduleDescription
|
||||
height: 100
|
||||
|
||||
ModuleInfoLabel
|
||||
text: Loaded
|
||||
ModuleValueLabel
|
||||
id: moduleLoaded
|
||||
|
||||
//ModuleInfoLabel
|
||||
// text: Autoload
|
||||
//ModuleValueLabel
|
||||
@@ -97,13 +113,13 @@ MainWindow
|
||||
id: moduleVersion
|
||||
|
||||
Button
|
||||
id: moduleLoadButton
|
||||
id: moduleReloadButton
|
||||
anchors.top: moduleInfo.bottom
|
||||
anchors.left: moduleInfo.left
|
||||
margin-top: 8
|
||||
text: Load
|
||||
enabled: false
|
||||
@onClick: ModuleManager.loadCurrentModule()
|
||||
visible: false
|
||||
@onClick: ModuleManager.reloadCurrentModule()
|
||||
|
||||
Button
|
||||
id: moduleUnloadButton
|
||||
@@ -112,6 +128,6 @@ MainWindow
|
||||
margin-left: 10
|
||||
margin-top: 8
|
||||
text: Unload
|
||||
enabled: false
|
||||
visible: false
|
||||
@onClick: ModuleManager.unloadCurrentModule()
|
||||
|
||||
|
Reference in New Issue
Block a user