mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
add modulemanager module
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
function dumpWidgets()
|
||||
for i=1,rootWidget:getChildCount() do
|
||||
print(rootWidget:getChildByIndex(i):getId())
|
||||
function dumpWidgets(widget, level)
|
||||
widget = widget or rootWidget
|
||||
level = level or 0
|
||||
for i=1,widget:getChildCount() do
|
||||
local child = widget:getChildByIndex(i)
|
||||
if child:isVisible() then
|
||||
local name = child:getId()
|
||||
if name:match('widget%d+') == nil then
|
||||
print(string.rep(' ', level) .. name)
|
||||
end
|
||||
if child:getId() ~= 'terminalBuffer' then
|
||||
dumpWidgets(child, level+1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -12,6 +12,7 @@ Module
|
||||
- client_about
|
||||
- client_options
|
||||
- client_entergame
|
||||
- client_modulemanager
|
||||
- game
|
||||
|
||||
onLoad: |
|
||||
|
118
modules/client_modulemanager/modulemanager.lua
Normal file
118
modules/client_modulemanager/modulemanager.lua
Normal 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
|
||||
|
11
modules/client_modulemanager/modulemanager.otmod
Normal file
11
modules/client_modulemanager/modulemanager.otmod
Normal 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()
|
117
modules/client_modulemanager/modulemanager.otui
Normal file
117
modules/client_modulemanager/modulemanager.otui
Normal 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()
|
||||
|
BIN
modules/client_modulemanager/modulemanager.png
Normal file
BIN
modules/client_modulemanager/modulemanager.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 952 B |
@@ -6,7 +6,7 @@ TopButton < UIButton
|
||||
image-color: #ffffffff
|
||||
icon-color: #ffffffff
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
image-color: #ffffff99
|
||||
image-clip: 26 0 26 26
|
||||
|
||||
|
@@ -7,7 +7,7 @@ Button < UIButton
|
||||
image-source: /core_styles/images/button.png
|
||||
image-border: 5
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
image-source: /core_styles/images/button_hover.png
|
||||
|
||||
$pressed:
|
||||
|
@@ -8,7 +8,7 @@ CheckBox < UICheckBox
|
||||
image-offset: 0 2
|
||||
image-source: /core_styles/images/checkbox.png
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
color: #cccccc
|
||||
|
||||
$!checked:
|
||||
@@ -48,7 +48,7 @@ ButtonBox < UICheckBox
|
||||
image-color: white
|
||||
image-border: 5
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
image-source: /core_styles/images/button_hover.png
|
||||
|
||||
$checked:
|
||||
|
@@ -6,7 +6,7 @@ ComboBoxPopupMenuButton < UIButton
|
||||
color: #aaaaaa
|
||||
background-color: alpha
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
color: #ffffff
|
||||
background-color: #ffffff44
|
||||
|
||||
@@ -38,7 +38,7 @@ ComboBox < UIComboBox
|
||||
image-border-right: 17
|
||||
image-clip: 0 0 89 20
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
image-clip: 0 20 89 20
|
||||
|
||||
$on:
|
||||
|
@@ -13,4 +13,4 @@ GameLabel < UILabel
|
||||
|
||||
FrameCounter < UIFrameCounter
|
||||
size: 68 16
|
||||
align: right
|
||||
align: right
|
||||
|
@@ -7,7 +7,7 @@ PopupMenuButton < UIButton
|
||||
color: #aaaaaa
|
||||
background-color: alpha
|
||||
|
||||
$hover:
|
||||
$hover !disabled:
|
||||
color: #ffffff
|
||||
background-color: #ffffff44
|
||||
|
||||
@@ -29,4 +29,4 @@ PopupMenu < UIPopupMenu
|
||||
image-source: /core_styles/images/menubox.png
|
||||
image-border: 3
|
||||
padding-top: 3
|
||||
padding-bottom: 3
|
||||
padding-bottom: 3
|
||||
|
@@ -1,5 +1,5 @@
|
||||
Module
|
||||
name: game_minewindow
|
||||
name: game_miniwindow
|
||||
description: Manage game miniwindow
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
Reference in New Issue
Block a user