BEAWARE all game functionality is disabled with this commit for a while

* rework client modules
* hide main window when loading
* remake top menu functions
* rework modules autoload
* improve path resolving for otml and lua
* move core_widgets to core_lib
* fix tooltip issues
* split some styles
* add bit32 lua library
* fix assert issues
* fix compilation on linux 32 systems
* rework gcc compile options
* renable and fix some warnings
* remove unused constants
* speedup sprite cache
* move UIGame to lua (not funcional yet)
* fix a lot of issues in x11 window
* fix crash handler
* add some warnings do uiwidget
and much more...
master
Eduardo Bart 12 years ago
parent 96358b317d
commit e03bf33f58

@ -1,7 +1,6 @@
Client = {} Client = {}
function Client.init() function Client.init()
g_window.show()
g_window.setMinimumSize({ width = 600, height = 480 }) g_window.setMinimumSize({ width = 600, height = 480 })
-- initialize in fullscreen mode on mobile devices -- initialize in fullscreen mode on mobile devices
@ -27,6 +26,13 @@ function Client.init()
g_window.setTitle('OTClient') g_window.setTitle('OTClient')
g_window.setIcon(resolvepath('clienticon.png')) g_window.setIcon(resolvepath('clienticon.png'))
-- show the only window after the first frame is rendered
addEvent(function()
addEvent(function()
g_window.show()
end)
end)
end end
function Client.terminate() function Client.terminate()

@ -0,0 +1,23 @@
Module
name: client
description: Initialize the client and setups its main window
author: OTClient team
website: https://github.com/edubart/otclient
autoload: true
autoload-priority: 100
load-later:
- client_topmenu
- client_background
- client_about
- client_options
- client_terminal
- client_modulemanager
- client_entergame
@onLoad: |
dofile 'client'
Client.init()
@onUnload: |
Client.terminate()

Before

Width:  |  Height:  |  Size: 518 B

After

Width:  |  Height:  |  Size: 518 B

@ -2,22 +2,33 @@ About = {}
-- private variables -- private variables
local aboutButton local aboutButton
local aboutWindow
-- public functions -- public functions
function About.init() function About.init()
aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.display) aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.show)
end aboutWindow = displayUI('about.otui')
aboutWindow:hide()
function About.display()
displayUI('about.otui', { locked = true })
end end
function About.terminate() function About.terminate()
aboutButton:destroy() aboutButton:destroy()
aboutButton = nil aboutButton = nil
aboutWindow:destroy()
aboutWindow = nil
About = nil About = nil
end end
function About.show()
aboutWindow:show()
aboutWindow:raise()
aboutWindow:focus()
end
function About.hide()
aboutWindow:hide()
end
function About.openWebpage() function About.openWebpage()
displayErrorBox("Error", "Not implemented yet") displayErrorBox("Error", "Not implemented yet")
end end

@ -3,16 +3,14 @@ Module
description: Create the about window description: Create the about window
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 160
unloadable: true
dependencies: dependencies:
- client_topmenu - client_topmenu
onLoad: | @onLoad: |
dofile 'about' dofile 'about'
About.init() About.init()
onUnload: | @onUnload: |
About.terminate() About.terminate()

@ -3,6 +3,9 @@ MainWindow
text: Info text: Info
size: 244 221 size: 244 221
@onEnter: About.hide()
@onEscape: About.hide()
FlatPanel FlatPanel
size: 208 129 size: 208 129
anchors.left: parent.left anchors.left: parent.left
@ -52,4 +55,4 @@ MainWindow
size: 46 24 size: 46 24
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: self:getParent():destroy() @onClick: About.hide()

@ -7,11 +7,18 @@ local background
function Background.init() function Background.init()
background = displayUI('background.otui') background = displayUI('background.otui')
background:lower() background:lower()
connect(g_game, { onGameStart = Background.hide })
connect(g_game, { onGameEnd = Background.show })
end end
function Background.terminate() function Background.terminate()
disconnect(g_game, { onGameStart = Background.hide })
disconnect(g_game, { onGameEnd = Background.show })
background:destroy() background:destroy()
background = nil background = nil
Background = nil Background = nil
end end

@ -3,12 +3,14 @@ Module
description: Handles the background of the login screen description: Handles the background of the login screen
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 110
onLoad: | dependencies:
- client_topmenu
@onLoad: |
dofile 'background' dofile 'background'
Background.init() Background.init()
onUnload: | @onUnload: |
Background.terminate() Background.terminate()

@ -52,7 +52,27 @@ local function tryLogin(charInfo, tries)
Settings.set('lastUsedCharacter', charInfo.characterName) Settings.set('lastUsedCharacter', charInfo.characterName)
end end
function onGameLoginError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
errorBox.onOk = CharacterList.show
end
function onGameConnectionError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
errorBox.onOk = CharacterList.show
end
-- public functions -- public functions
function CharacterList.init()
connect(g_game, { onLoginError = onGameLoginError })
connect(g_game, { onConnectionError = onGameConnectionError })
connect(g_game, { onGameStart = CharacterList.destroyLoadBox })
connect(g_game, { onGameEnd = CharacterList.show })
end
function CharacterList.terminate() function CharacterList.terminate()
characterList = nil characterList = nil
if charactersWindow then if charactersWindow then
@ -60,6 +80,7 @@ function CharacterList.terminate()
charactersWindow = nil charactersWindow = nil
end end
if loadBox then if loadBox then
g_game.cancelLogin()
loadBox:destroy() loadBox:destroy()
loadBox = nil loadBox = nil
end end
@ -118,6 +139,7 @@ end
function CharacterList.show() function CharacterList.show()
if not loadBox then if not loadBox then
charactersWindow:show() charactersWindow:show()
charactersWindow:raise()
charactersWindow:focus() charactersWindow:focus()
end end
end end

@ -59,11 +59,11 @@ end
-- public functions -- public functions
function EnterGame.init() function EnterGame.init()
enterGameButton = TopMenu.addButton('enterGameButton', 'Login (Ctrl + G)', '/core_styles/icons/login.png', EnterGame.openWindow)
Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
motdButton = TopMenu.addButton('motdButton', 'Message of the day', '/core_styles/icons/motd.png', EnterGame.displayMotd)
motdButton:hide()
enterGame = displayUI('entergame.otui') enterGame = displayUI('entergame.otui')
enterGameButton = TopMenu.addLeftButton('enterGameButton', 'Login (Ctrl + G)', 'login.png', EnterGame.openWindow)
motdButton = TopMenu.addLeftButton('motdButton', 'Message of the day', 'motd.png', EnterGame.displayMotd)
motdButton:hide()
Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
local account = Settings.get('account') local account = Settings.get('account')
local password = Settings.get('password') local password = Settings.get('password')
@ -102,6 +102,7 @@ end
function EnterGame.show() function EnterGame.show()
enterGame:show() enterGame:show()
enterGame:raise()
enterGame:focus() enterGame:focus()
end end

@ -3,14 +3,17 @@ Module
description: Manages enter game and character list windows description: Manages enter game and character list windows
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 150
onLoad: | dependencies:
- client_topmenu
@onLoad: |
dofile 'entergame' dofile 'entergame'
dofile 'characterlist' dofile 'characterlist'
EnterGame.init() EnterGame.init()
CharacterList.init()
onUnload: | @onUnload: |
EnterGame.terminate() EnterGame.terminate()
CharacterList.terminate() CharacterList.terminate()

@ -5,7 +5,7 @@ MainWindow
@onEnter: EnterGame.doLogin() @onEnter: EnterGame.doLogin()
@onEscape: EnterGame.hide() @onEscape: EnterGame.hide()
LargerLabel Label
text: Account name text: Account name
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
@ -17,7 +17,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 2 margin-top: 2
LargerLabel Label
text: Password text: Password
anchors.left: prev.left anchors.left: prev.left
anchors.top: prev.bottom anchors.top: prev.bottom
@ -30,7 +30,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 2 margin-top: 2
LargerLabel Label
id: serverLabel id: serverLabel
width: 140 width: 140
text: Server text: Server
@ -46,7 +46,7 @@ MainWindow
anchors.top: serverLabel.bottom anchors.top: serverLabel.bottom
margin-top: 2 margin-top: 2
LargerLabel Label
id: portLabel id: portLabel
text: Port text: Port
width: 50 width: 50

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 696 B

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 331 B

@ -1,14 +0,0 @@
Module
name: client_main
description: Initialize the client and setups its main window
author: OTClient team
website: https://github.com/edubart/otclient
autoload: true
autoload-antecedence: 100
onLoad: |
dofile 'client'
Client.init()
onUnload: |
Client.terminate()

@ -16,8 +16,9 @@ function ModuleManager.init()
Keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow) Keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow)
Keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow) Keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow)
moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle) moduleManagerButton = TopMenu.addLeftButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle)
-- refresh modules only after all modules are loaded
addEvent(ModuleManager.listModules) addEvent(ModuleManager.listModules)
end end
@ -36,8 +37,8 @@ end
function ModuleManager.show() function ModuleManager.show()
moduleManagerWindow:show() moduleManagerWindow:show()
moduleManagerWindow:focus()
moduleManagerWindow:raise() moduleManagerWindow:raise()
moduleManagerWindow:focus()
end end
function ModuleManager.toggle() function ModuleManager.toggle()
@ -98,8 +99,8 @@ function ModuleManager.updateModuleInfo(moduleName)
website = module:getWebsite() website = module:getWebsite()
version = module:getVersion() version = module:getVersion()
loaded = module:isLoaded() loaded = module:isLoaded()
canReload = module:canReload()
canUnload = module:canUnload() canUnload = module:canUnload()
canReload = not loaded or canUnload
end end
moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name) moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name)
@ -111,12 +112,10 @@ function ModuleManager.updateModuleInfo(moduleName)
local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton') local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton')
reloadButton:setEnabled(canReload) reloadButton:setEnabled(canReload)
reloadButton:setVisible(true)
if loaded then reloadButton:setText('Reload') if loaded then reloadButton:setText('Reload')
else reloadButton:setText('Load') end else reloadButton:setText('Load') end
local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton') local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton')
unloadButton:setVisible(true)
unloadButton:setEnabled(canUnload) unloadButton:setEnabled(canUnload)
end end
@ -126,6 +125,7 @@ function ModuleManager.reloadCurrentModule()
local module = g_modules.getModule(focusedChild:getText()) local module = g_modules.getModule(focusedChild:getText())
if module then if module then
module:reload() module:reload()
if ModuleManager == nil then return end
ModuleManager.updateModuleInfo(module:getName()) ModuleManager.updateModuleInfo(module:getName())
ModuleManager.refreshLoadedModules() ModuleManager.refreshLoadedModules()
ModuleManager.show() ModuleManager.show()
@ -139,6 +139,7 @@ function ModuleManager.unloadCurrentModule()
local module = g_modules.getModule(focusedChild:getText()) local module = g_modules.getModule(focusedChild:getText())
if module then if module then
module:unload() module:unload()
if ModuleManager == nil then return end
ModuleManager.updateModuleInfo(module:getName()) ModuleManager.updateModuleInfo(module:getName())
ModuleManager.refreshLoadedModules() ModuleManager.refreshLoadedModules()
end end

@ -3,15 +3,16 @@ Module
description: Manage other modules description: Manage other modules
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
reloadable: true
autoload: true autoload: true
autoload-antecedence: 140 autoload-priority: 140
dependencies: dependencies:
- client_topmenu - client_topmenu
onLoad: | @onLoad: |
dofile 'modulemanager' dofile 'modulemanager'
ModuleManager.init() ModuleManager.init()
onUnload: | @onUnload: |
ModuleManager.terminate() ModuleManager.terminate()

@ -27,7 +27,7 @@ ModuleValueLabel < UILabel
font: verdana-11px-antialised font: verdana-11px-antialised
color: #aaaaaa color: #aaaaaa
text-offset: 3 0 text-offset: 3 0
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/styles/images/panel_flat.png
image-border: 1 image-border: 1
height: 16 height: 16
@ -92,9 +92,9 @@ MainWindow
// id: moduleAutoload // id: moduleAutoload
//ModuleInfoLabel //ModuleInfoLabel
// text: Autoload antecedence // text: Autoload priority
//ModuleValueLabel //ModuleValueLabel
// id: moduleLoadAntecedence // id: moduleLoadPriority
// text: 1000 // text: 1000
ModuleInfoLabel ModuleInfoLabel
@ -118,7 +118,7 @@ MainWindow
anchors.left: moduleInfo.left anchors.left: moduleInfo.left
margin-top: 8 margin-top: 8
text: Load text: Load
visible: false enabled: false
@onClick: ModuleManager.reloadCurrentModule() @onClick: ModuleManager.reloadCurrentModule()
Button Button
@ -128,6 +128,14 @@ MainWindow
margin-left: 10 margin-left: 10
margin-top: 8 margin-top: 8
text: Unload text: Unload
visible: false enabled: false
@onClick: ModuleManager.unloadCurrentModule() @onClick: ModuleManager.unloadCurrentModule()
Button
id: closeButton
anchors.bottom: parent.bottom
anchors.right: parent.right
text: Close
width: 60
@onClick: ModuleManager.hide()

@ -2,29 +2,29 @@ Options = {}
local optionsWindow local optionsWindow
local optionsButton local optionsButton
local options = { vsync = true,
showfps = true,
fullscreen = false,
classicControl = false,
showStatusMessagesInConsole = true,
showEventMessagesInConsole = true,
showInfoMessagesInConsole = true,
showTimestampsInConsole = true,
showLevelsInConsole = true,
showPrivateMessagesInConsole = true }
function Options.init() function Options.init()
-- load settings -- load options
local booleanOptions = { vsync = true, for k,v in pairs(options) do
showfps = true, if type(v) == 'boolean' then
fullscreen = false, Settings.setDefault(k, v)
classicControl = false, Options.setOption(k, Settings.getBoolean(k))
showStatusMessagesInConsole = true, end
showEventMessagesInConsole = true,
showInfoMessagesInConsole = true,
showTimestampsInConsole = true,
showLevelsInConsole = true,
showPrivateMessagesInConsole = true,
}
for k,v in pairs(booleanOptions) do
Settings.setDefault(k, v)
Options.changeOption(k, Settings.getBoolean(k))
end end
optionsWindow = displayUI('options.otui') optionsWindow = displayUI('options.otui')
optionsWindow:setVisible(false) optionsWindow:hide()
optionsButton = TopMenu.addButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle) optionsButton = TopMenu.addLeftButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle)
Keyboard.bindKeyDown('Ctrl+O', Options.toggle) Keyboard.bindKeyDown('Ctrl+O', Options.toggle)
end end
@ -47,11 +47,11 @@ end
function Options.show() function Options.show()
optionsWindow:show() optionsWindow:show()
optionsWindow:lock() optionsWindow:raise()
optionsWindow:focus()
end end
function Options.hide() function Options.hide()
optionsWindow:unlock()
optionsWindow:hide() optionsWindow:hide()
end end
@ -59,20 +59,24 @@ function Options.openWebpage()
displayErrorBox("Error", "Not implemented yet") displayErrorBox("Error", "Not implemented yet")
end end
-- private functions function Options.setOption(key, value)
function Options.changeOption(key, status)
if key == 'vsync' then if key == 'vsync' then
g_window.setVerticalSync(status) g_window.setVerticalSync(value)
elseif key == 'showfps' then elseif key == 'showfps' then
addEvent(function() addEvent(function()
local frameCounter = rootWidget:recursiveGetChildById('frameCounter') local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
if frameCounter then frameCounter:setVisible(status) end if frameCounter then frameCounter:setVisible(value) end
end) end)
elseif key == 'fullscreen' then elseif key == 'fullscreen' then
addEvent(function() addEvent(function()
g_window.setFullscreen(status) g_window.setFullscreen(value)
end) end)
end end
Settings.set(key, status) Settings.set(key, value)
Options[key] = status options[key] = value
end end
function Options.getOption(key)
return options[key]
end

@ -3,15 +3,14 @@ Module
description: Create the options window description: Create the options window
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 130
dependencies: dependencies:
- client_topmenu - client_topmenu
onLoad: | @onLoad: |
dofile 'options' dofile 'options'
Options.init() Options.init()
onUnload: | @onUnload: |
Options.terminate() Options.terminate()

@ -1,6 +1,6 @@
OptionCheckBox < CheckBox OptionCheckBox < CheckBox
@onCheckChange: Options.changeOption(self:getId(), self:isChecked()) @onCheckChange: Options.setOption(self:getId(), self:isChecked())
@onSetup: self:setChecked(Options[self:getId()]) @onSetup: self:setChecked(Options.getOption(self:getId()))
$first: $first:
anchors.left: parent.left anchors.left: parent.left
@ -67,4 +67,4 @@ MainWindow
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: Options.hide() @onClick: Options.hide()

@ -41,10 +41,6 @@ function debugContainersItems()
end end
end end
function quit()
exit()
end
function autoReloadModule(name) function autoReloadModule(name)
local function reloadEvent() local function reloadEvent()
reloadModule(name) reloadModule(name)

@ -110,26 +110,27 @@ function Terminal.init()
terminalWidget = displayUI('terminal.otui') terminalWidget = displayUI('terminal.otui')
terminalWidget:setVisible(false) terminalWidget:setVisible(false)
terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle) terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle) Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle)
commandHistory = Settings.getList('terminal-history') commandHistory = Settings.getList('terminal-history')
commandLineEdit = terminalWidget:getChildById('commandLineEdit') commandLineEdit = terminalWidget:getChildById('commandLineEdit')
Keyboard.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit) Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit)
Keyboard.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit) Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit)
Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit) Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit)
Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit) Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit)
Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWidget)
terminalBuffer = terminalWidget:getChildById('terminalBuffer') terminalBuffer = terminalWidget:getChildById('terminalBuffer')
Logger.setOnLog(onLog) g_logger.setOnLog(onLog)
Logger.fireOldMessages() g_logger.fireOldMessages()
end end
function Terminal.terminate() function Terminal.terminate()
Settings.setList('terminal-history', commandHistory) Settings.setList('terminal-history', commandHistory)
Keyboard.unbindKeyDown('Ctrl+T') Keyboard.unbindKeyDown('Ctrl+T')
Logger.setOnLog(nil) g_logger.setOnLog(nil)
terminalButton:destroy() terminalButton:destroy()
terminalButton = nil terminalButton = nil
commandLineEdit = nil commandLineEdit = nil
@ -150,11 +151,11 @@ end
function Terminal.show() function Terminal.show()
terminalWidget:show() terminalWidget:show()
terminalWidget:lock() terminalWidget:raise()
terminalWidget:focus()
end end
function Terminal.hide() function Terminal.hide()
terminalWidget:unlock()
terminalWidget:hide() terminalWidget:hide()
end end
@ -178,7 +179,7 @@ function Terminal.executeCommand(command)
if command == nil or #command == 0 then return end if command == nil or #command == 0 then return end
logLocked = true logLocked = true
Logger.log(LogInfo, '>> ' .. command) g_logger.log(LogInfo, '>> ' .. command)
logLocked = false logLocked = false
-- detect and convert commands with simple syntax -- detect and convert commands with simple syntax
@ -210,7 +211,7 @@ function Terminal.executeCommand(command)
-- check for syntax errors -- check for syntax errors
if not func then if not func then
Logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5)) g_logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5))
return return
end end
@ -223,6 +224,6 @@ function Terminal.executeCommand(command)
-- if the command returned a value, print it -- if the command returned a value, print it
if ret then print(ret) end if ret then print(ret) end
else else
Logger.log(LogError, 'command failed: ' .. ret) g_logger.log(LogError, 'command failed: ' .. ret)
end end
end end

@ -3,13 +3,12 @@ Module
description: Terminal for executing lua functions description: Terminal for executing lua functions
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 160
onLoad: | @onLoad: |
dofile 'terminal' dofile 'terminal'
dofile 'commands' dofile 'commands'
Terminal.init() Terminal.init()
onUnload: | @onUnload: |
Terminal.terminate() Terminal.terminate()

@ -1,14 +0,0 @@
Module
name: client_tibiafiles
description: Contains tibia spr and dat
unloadable: false
autoload: true
autoload-antecedence: 170
onLoad: |
if not g_thingsType.load('/client_tibiafiles/Tibia.dat') then
fatal("Unable to load dat file, please place a valid Tibia dat in modules/client_tibiafiles/Tibia.dat")
end
if not g_sprites.load('/client_tibiafiles/Tibia.spr') then
fatal("Unable to load spr file, please place a valid Tibia spr in modules/client_tibiafiles/Tibia.spr")
end

Before

Width:  |  Height:  |  Size: 470 B

After

Width:  |  Height:  |  Size: 470 B

Before

Width:  |  Height:  |  Size: 426 B

After

Width:  |  Height:  |  Size: 426 B

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

@ -7,12 +7,25 @@ local rightButtonsPanel
local gameButtonsPanel local gameButtonsPanel
-- private functions -- private functions
local function onLogout() local function addButton(id, description, icon, callback, panel, toggle)
if g_game.isOnline() then local class
g_game.safeLogout() if toggle then
class = 'TopToggleButton'
else
class = 'TopButton'
end
local button = createWidget(class, panel)
button:setId(id)
button:setTooltip(description)
button:setIcon(resolvepath(icon, 3))
if toggle then
button.onCheckChange = callback
else else
exit() button.onClick = callback
end end
return button
end end
-- public functions -- public functions
@ -22,15 +35,11 @@ function TopMenu.init()
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel') rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
gameButtonsPanel = topMenu:getChildById('gameButtonsPanel') gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
Keyboard.bindKeyDown('Ctrl+Q', onLogout)
connect(g_game, { onGameStart = TopMenu.showGameButtons, connect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
end end
function TopMenu.terminate() function TopMenu.terminate()
Keyboard.unbindKeyDown('Ctrl+Q')
leftButtonsPanel = nil leftButtonsPanel = nil
rightButtonsPanel = nil rightButtonsPanel = nil
gameButtonsPanel = nil gameButtonsPanel = nil
@ -38,45 +47,33 @@ function TopMenu.terminate()
topMenu = nil topMenu = nil
disconnect(g_game, { onGameStart = TopMenu.showGameButtons, disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
TopMenu = nil TopMenu = nil
end end
function TopMenu.addButton(id, description, icon, callback, right) function TopMenu.addLeftButton(id, description, icon, callback)
local panel return addButton(id, description, icon, callback, leftButtonsPanel, false)
local class end
if right then
panel = rightButtonsPanel
class = 'TopRightButton'
else
panel = leftButtonsPanel
class = 'TopLeftButton'
end
local button = createWidget(class, panel) function TopMenu.addLeftToggleButton(id, description, icon, callback, right)
button:setId(id) return addButton(id, description, icon, callback, leftButtonsPanel, true)
button:setTooltip(description)
button:setIcon(resolvepath(icon, 2))
button.onClick = callback
return button
end end
function TopMenu.addGameButton(id, description, icon, callback) function TopMenu.addRightButton(id, description, icon, callback)
local button = createWidget('GameTopButton', gameButtonsPanel) return addButton(id, description, icon, callback, rightButtonsPanel, false)
button:setId(id)
button:setTooltip(description)
button:setIcon(resolvepath(icon, 2))
button.onClick = callback
return button
end end
function TopMenu.addLeftButton(id, description, icon, callback) function TopMenu.addRightToggleButton(id, description, icon, callback, right)
return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, false) return addButton(id, description, icon, callback, rightButtonsPanel, true)
end end
function TopMenu.addRightButton(id, description, icon, callback) function TopMenu.addGameButton(id, description, icon, callback)
return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true) return addButton(id, description, icon, callback, gameButtonsPanel, false)
end
function TopMenu.addGameToggleButton(id, description, icon, callback, right)
return addButton(id, description, icon, callback, gameButtonsPanel, true)
end end
function TopMenu.hideGameButtons() function TopMenu.hideGameButtons()
@ -90,3 +87,5 @@ end
function TopMenu.getButton(id) function TopMenu.getButton(id)
return topMenu:recursiveGetChildById(id) return topMenu:recursiveGetChildById(id)
end end

@ -3,12 +3,11 @@ Module
description: Create the top menu description: Create the top menu
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true reloadable: true
autoload-antecedence: 120
onLoad: | @onLoad: |
dofile 'topmenu' dofile 'topmenu'
TopMenu.init() TopMenu.init()
onUnload: | @onUnload: |
TopMenu.terminate() TopMenu.terminate()

@ -1,6 +1,6 @@
TopButton < UIButton TopButton < UIButton
size: 26 26 size: 26 26
image-source: /core_styles/images/top_button.png image-source: images/top_button.png
image-clip: 0 0 26 26 image-clip: 0 0 26 26
image-border: 3 image-border: 3
image-color: #ffffffff image-color: #ffffffff
@ -17,66 +17,61 @@ TopButton < UIButton
image-color: #ffffff44 image-color: #ffffff44
icon-color: #ffffff44 icon-color: #ffffff44
GameTopButton < UIButton TopToggleButton < UICheckBox
size: 26 26 size: 26 26
image-source: /core_styles/images/top_button2.png image-source: images/top_game_button.png
image-clip: 26 0 26 26 image-clip: 26 0 26 26
image-color: #ffffff22 image-color: #ffffff22
icon-color: #ffffffff
image-border: 3 image-border: 3
icon-color: #ffffffff
$on: $checked:
image-clip: 0 0 26 26 image-clip: 0 0 26 26
image-color: #ffffffff image-color: #ffffffff
icon-color: #ffffffff icon-color: #ffffffff
TopLeftButton < TopButton TopMenuButtonsPanel < Panel
TopRightButton < TopButton layout:
type: horizontalBox
spacing: 4
fit-children: true
padding: 6 4
TopPanel < Panel
height: 36
image-source: images/top_panel.png
image-repeated: true
focusable: false
TopPanel TopPanel
id: topMenu id: topMenu
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
focusable: false
Panel TopMenuButtonsPanel
id: leftButtonsPanel id: leftButtonsPanel
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
layout:
type: horizontalBox
spacing: 4
fit-children: true
padding: 6 4
Panel TopMenuButtonsPanel
id: gameButtonsPanel id: gameButtonsPanel
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: prev.right anchors.left: prev.right
anchors.right: next.left anchors.right: next.left
layout:
type: horizontalBox
spacing: 4
padding: 6 4
visible: false
Panel TopMenuButtonsPanel
id: rightButtonsPanel id: rightButtonsPanel
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
layout:
type: horizontalBox
spacing: 4
fit-children: true
padding: 6 4
FrameCounter FrameCounter
id: frameCounter id: frameCounter
anchors.top: parent.top anchors.top: parent.top
anchors.right: prev.left anchors.right: prev.left
margin-top: 8 margin-top: 8
margin-right: 5 margin-right: 5

@ -1,15 +0,0 @@
Module
name: core_fonts
description: Contains fonts used by core
author: OTClient team
website: https://github.com/edubart/otclient
autoload: true
autoload-antecedence: 30
onLoad: |
importFont 'verdana-11px-antialised'
importFont 'verdana-11px-monochrome'
importFont 'verdana-11px-rounded'
importFont 'terminus-14px-bold'
setDefaultFont 'verdana-11px-antialised'

@ -4,9 +4,9 @@ Module
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoload: true autoload: true
autoload-antecedence: 10 autoload-priority: 10
onLoad: | @onLoad: |
dofile 'ext/table' dofile 'ext/table'
dofile 'ext/string' dofile 'ext/string'
dofile 'ext/os' dofile 'ext/os'
@ -17,9 +17,26 @@ Module
dofile 'const' dofile 'const'
dofile 'util' dofile 'util'
dofile 'globals' dofile 'globals'
dofile 'dispatcher'
dofile 'effects'
dofile 'settings' dofile 'settings'
dofile 'keyboard' dofile 'keyboard'
dofile 'mouse' dofile 'mouse'
dofile 'ui/effects'
dofile 'ui/radiogroup'
dofile 'ui/tooltip'
dofile 'widgets/uiwidget'
dofile 'widgets/uibutton'
dofile 'widgets/uilabel'
dofile 'widgets/uicheckbox'
dofile 'widgets/uicombobox'
dofile 'widgets/uispinbox'
dofile 'widgets/uiprogressbar'
dofile 'widgets/uitabbar'
dofile 'widgets/uipopupmenu'
dofile 'widgets/uiwindow'
--dofile 'widgets/uiminiwindow'
--dofile 'widgets/uiminiwindowcontainer'
dofile 'widgets/uimessagebox'

@ -1,20 +0,0 @@
function scheduleEvent(callback, delay)
local event = g_dispatcher.scheduleEvent(callback, delay)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function addEvent(callback, front)
local event = g_dispatcher.addEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function removeEvent(event)
if event then
event:cancel()
end
end

@ -1,57 +1,13 @@
rootWidget = g_ui.getRootWidget() rootWidget = g_ui.getRootWidget()
function importStyle(otui) importStyle = g_ui.importStyle
g_ui.importStyle(resolvepath(otui, 2)) importFont = g_fonts.importFont
end setDefaultFont = g_fonts.setDefaultFont
function importFont(otfont)
g_fonts.importFont(resolvepath(otfont, 2))
end
function setDefaultFont(font) loadUI = g_ui.loadUI
g_fonts.setDefaultFont(font)
end
function displayUI(arg1, options) function displayUI(otui, parent)
local widget
local parent
if options then parent = options.parent end
parent = parent or rootWidget parent = parent or rootWidget
-- display otui files
if type(arg1) == 'string' then
local otuiFilePath = resolvepath(arg1, 2)
widget = g_ui.loadUI(otuiFilePath, parent)
-- display already loaded widgets
else
widget = arg1
if parent:hasChild(widget) then
widget:focus()
widget:show()
else
parent:addChild(widget)
widget:show()
end
end
-- apply display options
if widget and options then
for option,value in pairs(options) do
if option == 'locked' and value then
widget:lock()
elseif option == 'visible' then
widget:setVisible(value)
elseif option == 'x' then
widget:setX(value)
elseif option == 'y' then
widget:setY(value)
end
end
end
return widget
end
function loadUI(otui, parent)
local otuiFilePath = resolvepath(otui, 2) local otuiFilePath = resolvepath(otui, 2)
return g_ui.loadUI(otuiFilePath, parent) return g_ui.loadUI(otuiFilePath, parent)
end end
@ -65,7 +21,7 @@ function createWidget(style, parent)
local class = _G[className] local class = _G[className]
if not class then if not class then
error('could not find widget class ' .. class) error('could not find widget class ' .. className)
return return
end end
@ -80,6 +36,28 @@ function createWidget(style, parent)
return widget return widget
end end
function scheduleEvent(callback, delay)
local event = g_dispatcher.scheduleEvent(callback, delay)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function addEvent(callback, front)
local event = g_dispatcher.addEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function removeEvent(event)
if event then
event:cancel()
event._callback = nil
end
end
function reloadModule(name) function reloadModule(name)
local module = g_modules.getModule(name) local module = g_modules.getModule(name)
if module then if module then

@ -7,3 +7,4 @@ end
function Mouse.restoreCursor() function Mouse.restoreCursor()
g_window.restoreMouseCursor() g_window.restoreMouseCursor()
end end

@ -32,7 +32,6 @@ function Settings.set(key, value)
g_configs.set(key, convertSettingValue(value)) g_configs.set(key, convertSettingValue(value))
end end
function Settings.setDefault(key, value) function Settings.setDefault(key, value)
if Settings.exists(key) then return false end if Settings.exists(key) then return false end
Settings.set(key, value) Settings.set(key, value)

@ -41,13 +41,15 @@ end
-- public functions -- public functions
function ToolTip.init() function ToolTip.init()
toolTipLabel = createWidget('Label', rootWidget)
toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111bb')
toolTipLabel.onMouseMove = moveToolTip
connect(UIWidget, { onStyleApply = onWidgetStyleApply, connect(UIWidget, { onStyleApply = onWidgetStyleApply,
onHoverChange = onWidgetHoverChange}) onHoverChange = onWidgetHoverChange})
addEvent(function()
toolTipLabel = createWidget('Label', rootWidget)
toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111bb')
toolTipLabel.onMouseMove = moveToolTip
end)
end end
function ToolTip.terminate() function ToolTip.terminate()
@ -63,6 +65,8 @@ end
function ToolTip.display(text) function ToolTip.display(text)
if text == nil then return end if text == nil then return end
if not toolTipLabel then return end
toolTipLabel:setText(text) toolTipLabel:setText(text)
toolTipLabel:resizeToText() toolTipLabel:resizeToText()
toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4) toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4)
@ -73,6 +77,7 @@ function ToolTip.display(text)
end end
function ToolTip.hide() function ToolTip.hide()
toolTipLabel:hide() toolTipLabel:hide()
end end
@ -85,3 +90,5 @@ function UIWidget:getTooltip()
return self.tooltip return self.tooltip
end end
ToolTip.init()
connect(g_app, { onTerminate = ToolTip.terminate })

@ -3,20 +3,15 @@ function print(...)
for i,v in ipairs(arg) do for i,v in ipairs(arg) do
msg = msg .. tostring(v) .. "\t" msg = msg .. tostring(v) .. "\t"
end end
Logger.log(LogInfo, msg) g_logger.log(LogInfo, msg)
end end
function fatal(msg) function fatal(msg)
Logger.log(LogFatal, msg) g_logger.log(LogFatal, msg)
end end
function setonclose(func) exit = g_app.exit
g_app.onClose = func quit = g_app.exit
end
function exit()
g_app.exit()
end
function connect(object, signalsAndSlots, pushFront) function connect(object, signalsAndSlots, pushFront)
for signal,slot in pairs(signalsAndSlots) do for signal,slot in pairs(signalsAndSlots) do

@ -21,7 +21,8 @@ function UIPopupMenu:display(pos)
currentMenu:destroy() currentMenu:destroy()
end end
displayUI(self, {x = pos.x, y = pos.y}) rootWidget:addChild(self)
self:setPosition(pos)
self:grabMouse() self:grabMouse()
self:grabKeyboard() self:grabKeyboard()
currentMenu = self currentMenu = self

@ -7,7 +7,7 @@ function UIWindow.create()
return window return window
end end
function UIWindow:onKeyPress(keyCode, keyboardModifiers) function UIWindow:onKeyDown(keyCode, keyboardModifiers)
if keyboardModifiers == KeyboardNoModifier then if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyEnter then if keyCode == KeyEnter then
signalcall(self.onEnter, self) signalcall(self.onEnter, self)
@ -17,9 +17,8 @@ function UIWindow:onKeyPress(keyCode, keyboardModifiers)
end end
end end
function UIWindow:onMousePress(mousePos, mouseButton) function UIWindow:onFocusChange(focused)
self:raise() if focused then self:raise() end
return true
end end
function UIWindow:onDragEnter(mousePos) function UIWindow:onDragEnter(mousePos)

@ -3,11 +3,16 @@ Module
description: Contains ui styles used by other modules description: Contains ui styles used by other modules
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
reloadable: true
autoload: true autoload: true
autoload-antecedence: 20 autoload-priority: 20
@onLoad: |
importFont 'fonts/verdana-11px-antialised'
importFont 'fonts/verdana-11px-monochrome'
importFont 'fonts/verdana-11px-rounded'
importFont 'fonts/terminus-14px-bold'
setDefaultFont 'verdana-11px-antialised'
onLoad: |
importStyle 'styles/buttons.otui' importStyle 'styles/buttons.otui'
importStyle 'styles/labels.otui' importStyle 'styles/labels.otui'
importStyle 'styles/panels.otui' importStyle 'styles/panels.otui'

Before

Width:  |  Height:  |  Size: 266 B

After

Width:  |  Height:  |  Size: 266 B

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

@ -4,15 +4,15 @@ Button < UIButton
size: 106 24 size: 106 24
text-offset: 0 0 text-offset: 0 0
image-color: white image-color: white
image-source: /core_styles/images/button.png image-source: /core_styles/styles/images/button.png
image-border: 5 image-border: 5
$hover !disabled: $hover !disabled:
image-source: /core_styles/images/button_hover.png image-source: /core_styles/styles/images/button_hover.png
$pressed: $pressed:
text-offset: 1 1 text-offset: 1 1
image-source: /core_styles/images/button_down.png image-source: /core_styles/styles/images/button_down.png
$disabled: $disabled:
color: #f0ad4d88 color: #f0ad4d88
@ -20,7 +20,7 @@ Button < UIButton
ConsoleButton < UIButton ConsoleButton < UIButton
size: 20 20 size: 20 20
image-source: /core_styles/images/tabbutton.png image-source: /core_styles/styles/images/tabbutton.png
image-color: white image-color: white
image-clip: 0 0 20 20 image-clip: 0 0 20 20
image-border: 2 image-border: 2

@ -6,7 +6,7 @@ CheckBox < UICheckBox
image-color: #ffffffff image-color: #ffffffff
image-rect: 0 0 12 12 image-rect: 0 0 12 12
image-offset: 0 2 image-offset: 0 2
image-source: /core_styles/images/checkbox.png image-source: /core_styles/styles/images/checkbox.png
$hover !disabled: $hover !disabled:
color: #cccccc color: #cccccc
@ -30,7 +30,7 @@ CheckBox < UICheckBox
ColorBox < UICheckBox ColorBox < UICheckBox
size: 16 16 size: 16 16
image-color: #ffffffff image-color: #ffffffff
image-source: /core_styles/images/colorbox.png image-source: /core_styles/styles/images/colorbox.png
$checked: $checked:
image-clip: 16 0 16 16 image-clip: 16 0 16 16
@ -44,16 +44,16 @@ ButtonBox < UICheckBox
size: 106 24 size: 106 24
text-offset: 0 0 text-offset: 0 0
text-align: center text-align: center
image-source: /core_styles/images/button.png image-source: /core_styles/styles/images/button.png
image-color: white image-color: white
image-border: 5 image-border: 5
$hover !disabled: $hover !disabled:
image-source: /core_styles/images/button_hover.png image-source: /core_styles/styles/images/button_hover.png
$checked: $checked:
text-offset: 1 1 text-offset: 1 1
image-source: /core_styles/images/button_down.png image-source: /core_styles/styles/images/button_down.png
$disabled: $disabled:
color: #f0ad4d88 color: #f0ad4d88

@ -14,14 +14,14 @@ ComboBoxPopupMenuButton < UIButton
color: #555555 color: #555555
ComboBoxPopupMenuSeparator < UIWidget ComboBoxPopupMenuSeparator < UIWidget
image-source: /core_styles/images/combobox.png image-source: /core_styles/styles/images/combobox.png
image-repeated: true image-repeated: true
image-clip: 1 59 89 1 image-clip: 1 59 89 1
height: 1 height: 1
phantom: true phantom: true
ComboBoxPopupMenu < UIPopupMenu ComboBoxPopupMenu < UIPopupMenu
image-source: /core_styles/images/combobox.png image-source: /core_styles/styles/images/combobox.png
image-clip: 0 60 89 20 image-clip: 0 60 89 20
image-border: 1 image-border: 1
image-border-top: 0 image-border-top: 0
@ -33,7 +33,7 @@ ComboBox < UIComboBox
size: 86 20 size: 86 20
text-offset: 3 0 text-offset: 3 0
text-align: left text-align: left
image-source: /core_styles/images/combobox.png image-source: /core_styles/styles/images/combobox.png
image-border: 1 image-border: 1
image-border-right: 17 image-border-right: 17
image-clip: 0 0 89 20 image-clip: 0 0 89 20

@ -1,8 +1,5 @@
Creature < UICreature Creature < UICreature
size: 80 80 size: 80 80
padding: 1 padding: 1
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/styles/images/panel_flat.png
image-border: 1 image-border: 1
UIWidget
id: lala

Before

Width:  |  Height:  |  Size: 825 B

After

Width:  |  Height:  |  Size: 825 B

Before

Width:  |  Height:  |  Size: 833 B

After

Width:  |  Height:  |  Size: 833 B

Before

Width:  |  Height:  |  Size: 859 B

After

Width:  |  Height:  |  Size: 859 B

Before

Width:  |  Height:  |  Size: 548 B

After

Width:  |  Height:  |  Size: 548 B

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 457 B

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

Before

Width:  |  Height:  |  Size: 241 B

After

Width:  |  Height:  |  Size: 241 B

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 179 B

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

Before

Width:  |  Height:  |  Size: 415 B

After

Width:  |  Height:  |  Size: 415 B

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

@ -1,5 +1,5 @@
Item < UIItem Item < UIItem
size: 34 34 size: 34 34
image-source: /core_styles/images/item.png image-source: /core_styles/styles/images/item.png
font: verdana-11px-rounded font: verdana-11px-rounded
border-color: white border-color: white

@ -5,8 +5,6 @@ Label < UILabel
$disabled: $disabled:
color: #aaaaaa88 color: #aaaaaa88
LargerLabel < Label
GameLabel < UILabel GameLabel < UILabel
font: verdana-11px-antialised font: verdana-11px-antialised
color: #aaaaaa color: #aaaaaa

@ -3,7 +3,7 @@ LineEdit < UILineEdit
color: #aaaaaa color: #aaaaaa
size: 86 20 size: 86 20
text-margin: 3 text-margin: 3
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/styles/images/panel_flat.png
image-border: 1 image-border: 1
$disabled: $disabled:

@ -2,4 +2,4 @@ TextList < UIWidget
layout: verticalBox layout: verticalBox
border-width: 1 border-width: 1
border-color: #1d222b border-color: #1d222b
background-color: #222833 background-color: #222833

@ -2,23 +2,5 @@ Panel < UIWidget
phantom: true phantom: true
FlatPanel < Panel FlatPanel < Panel
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/styles/images/panel_flat.png
image-border: 1 image-border: 1
TopPanel < Panel
height: 36
image-source: /core_styles/images/top_panel.png
image-repeated: true
InterfacePanel < UIMiniWindowContainer
image-source: /core_styles/images/interface_panel.png
image-border: 4
InterfacePanel2 < Panel
image-source: /core_styles/images/interface_panel2.png
image-border: 4
Map < UIMap
padding: 4
image-source: /core_styles/images/map_panel.png
image-border: 4

@ -17,7 +17,7 @@ PopupMenuButton < UIButton
PopupMenuSeparator < UIWidget PopupMenuSeparator < UIWidget
margin-left: 2 margin-left: 2
margin-right: 2 margin-right: 2
image-source: /core_styles/images/menubox.png image-source: /core_styles/styles/images/menubox.png
image-border-left: 1 image-border-left: 1
image-border-right: 1 image-border-right: 1
image-clip: 0 0 32 2 image-clip: 0 0 32 2
@ -26,7 +26,7 @@ PopupMenuSeparator < UIWidget
PopupMenu < UIPopupMenu PopupMenu < UIPopupMenu
width: 50 width: 50
image-source: /core_styles/images/menubox.png image-source: /core_styles/styles/images/menubox.png
image-border: 3 image-border: 3
padding-top: 3 padding-top: 3
padding-bottom: 3 padding-bottom: 3

@ -2,6 +2,6 @@ ProgressBar < UIProgressBar
height: 16 height: 16
background-color: red background-color: red
border: 1 black border: 1 black
image: /core_styles/images/progressbar.png image: /core_styles/styles/images/progressbar.png
image-border: 1 image-border: 1

@ -1,5 +1,5 @@
HorizontalSeparator < UIWidget HorizontalSeparator < UIWidget
image-source: /core_styles/images/horizontal_separator.png image-source: /core_styles/styles/images/horizontal_separator.png
image-border-top: 2 image-border-top: 2
height: 2 height: 2
phantom: true phantom: true

@ -3,7 +3,7 @@ SpinBox < UISpinBox
color: #aaaaaa color: #aaaaaa
size: 86 20 size: 86 20
text-margin: 3 text-margin: 3
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/styles/images/panel_flat.png
image-border: 1 image-border: 1
$disabled: $disabled:

@ -2,7 +2,7 @@ TabBar < UITabBar
TabBarPanel < Panel TabBarPanel < Panel
TabBarButton < UIButton TabBarButton < UIButton
size: 20 20 size: 20 20
image-source: /core_styles/images/tabbutton.png image-source: /core_styles/styles/images/tabbutton.png
image-color: white image-color: white
image-clip: 0 0 20 20 image-clip: 0 0 20 20
image-border: 2 image-border: 2

@ -5,7 +5,7 @@ Window < UIWindow
color: white color: white
text-offset: 0 2 text-offset: 0 2
text-align: top text-align: top
image-source: /core_styles/images/window.png image-source: /core_styles/styles/images/window.png
image-border: 4 image-border: 4
image-border-top: 20 image-border-top: 20
opacity: 1 opacity: 1
@ -35,7 +35,7 @@ MiniWindow < UIMiniWindow
margin-left: 6 margin-left: 6
margin-right: 6 margin-right: 6
move-policy: free updated move-policy: free updated
image-source: /core_styles/images/mini_window.png image-source: /core_styles/styles/images/mini_window.png
image-border: 4 image-border: 4
image-border-top: 23 image-border-top: 23
padding: 25 8 2 8 padding: 25 8 2 8

@ -1,33 +0,0 @@
Module
name: core_widgets
description: Contains widgets used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
reloadable: true
unloadble: false
autoload: true
autoload-antecedence: 40
onLoad: |
dofile 'uiwidget'
dofile 'uibutton'
dofile 'uilabel'
dofile 'uicheckbox'
dofile 'uicombobox'
dofile 'uispinbox'
dofile 'uiprogressbar'
dofile 'uitabbar'
dofile 'uipopupmenu'
dofile 'uiwindow'
dofile 'uiminiwindow'
dofile 'uiminiwindowcontainer'
dofile 'uiitem'
dofile 'uimessagebox'
dofile 'tooltip'
dofile 'radiogroup'
ToolTip.init()
onUnload: |
ToolTip.terminate()

@ -46,19 +46,6 @@ function g_game.startUseWith(thing)
end end
function g_game.createInterface() function g_game.createInterface()
Background.hide()
CharacterList.destroyLoadBox()
g_game.gameUi = displayUI('game.otui')
--Keyboard.bindKeyPress('Up', function() g_game.walk(North) end)
--Keyboard.bindKeyPress('Down', function() g_game.walk(South) end)
--Keyboard.bindKeyPress('Left', function() g_game.walk(West) end)
--Keyboard.bindKeyPress('Right', function() g_game.walk(East) end)
Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end)
Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end)
Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end)
Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end)
rootWidget:moveChildToIndex(g_game.gameUi, 1) rootWidget:moveChildToIndex(g_game.gameUi, 1)
g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel') g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
@ -89,17 +76,6 @@ function g_game.hide()
end end
-- hooked events -- hooked events
function g_game.onLoginError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
connect(errorBox, { onOk = CharacterList.show })
end
function g_game.onConnectionError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
connect(errorBox, { onOk = CharacterList.show })
end
local function onApplicationClose() local function onApplicationClose()
if g_game.isOnline() then if g_game.isOnline() then

@ -3,19 +3,11 @@ Module
description: Create the game interface, where the ingame stuff starts description: Create the game interface, where the ingame stuff starts
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
reloadable: true
dependencies: dependencies:
- game_healthbar - game_tibiafiles
- game_inventory //- game_shaders
- game_skills
- game_textmessage
- game_viplist
- game_console
- game_outfit
- game_containers
- game_combatcontrols
- game_hotkeys
- game_battle
onLoad: | onLoad: |
dofile 'game' dofile 'game'

@ -0,0 +1,11 @@
Module
name: game_tibiafiles
description: Contains tibia spr and dat
@onLoad: |
if not g_thingsType.load('/game_tibiafiles/Tibia.dat') then
fatal("Unable to load dat file, please place a valid Tibia dat in modules/game_tibiafiles/Tibia.dat")
end
if not g_sprites.load('/game_tibiafiles/Tibia.spr') then
fatal("Unable to load spr file, please place a valid Tibia spr in modules/game_tibiafiles/Tibia.spr")
end

@ -36,29 +36,29 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
-- public functions -- public functions
function Battle.create() function Battle.create()
battleWindow = displayUI('battle.otui', { parent = g_game.gameRightPanel }) battleWindow = displayUI('battle.otui', g_game.gameRightPanel)
battleWindow:hide() battleWindow:hide()
battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle) battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle)
Keyboard.bindKeyDown('Ctrl+B', Battle.toggle) Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
battlePannel = battleWindow:getChildById('battlePanel') battlePannel = battleWindow:getChildById('battlePanel')
hidePlayersButton = battleWindow:getChildById('hidePlayers') hidePlayersButton = battleWindow:getChildById('hidePlayers')
hideNPCsButton = battleWindow:getChildById('hideNPCs') hideNPCsButton = battleWindow:getChildById('hideNPCs')
hideMonstersButton = battleWindow:getChildById('hideMonsters') hideMonstersButton = battleWindow:getChildById('hideMonsters')
hideSkullsButton = battleWindow:getChildById('hideSkulls') hideSkullsButton = battleWindow:getChildById('hideSkulls')
hidePartyButton = battleWindow:getChildById('hideParty') hidePartyButton = battleWindow:getChildById('hideParty')
mouseWidget = createWidget('UIButton') mouseWidget = createWidget('UIButton')
mouseWidget:setVisible(false) mouseWidget:setVisible(false)
mouseWidget:setFocusable(false) mouseWidget:setFocusable(false)
connect(Creature, { onSkullChange = Battle.checkCreatureSkull, connect(Creature, { onSkullChange = Battle.checkCreatureSkull,
onEmblemChange = Battle.checkCreatureEmblem } ) onEmblemChange = Battle.checkCreatureEmblem } )
connect(g_game, { onAttackingCreatureChange = Battle.onAttack, connect(g_game, { onAttackingCreatureChange = Battle.onAttack,
onFollowingCreatureChange = Battle.onFollow } ) onFollowingCreatureChange = Battle.onFollow } )
addEvent(Battle.addAllCreatures) addEvent(Battle.addAllCreatures)
checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200) checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200)
end end
@ -80,10 +80,10 @@ function Battle.destroy()
battleButton = nil battleButton = nil
battleWindow:destroy() battleWindow:destroy()
battleWindow = nil battleWindow = nil
disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull, disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull,
onEmblemChange = Battle.checkCreatureEmblem } ) onEmblemChange = Battle.checkCreatureEmblem } )
disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } ) disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } )
end end
@ -94,7 +94,7 @@ function Battle.toggle()
end end
function Battle.addAllCreatures() function Battle.addAllCreatures()
local spectators = {} local spectators = {}
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if player then if player then
creatures = g_map.getSpectators(player:getPosition(), false) creatures = g_map.getSpectators(player:getPosition(), false)
@ -104,7 +104,7 @@ function Battle.addAllCreatures()
end end
end end
end end
for i, v in pairs(spectators) do for i, v in pairs(spectators) do
Battle.addCreature(v) Battle.addCreature(v)
end end
@ -116,7 +116,7 @@ function Battle.doCreatureFitFilters(creature)
local hideMonsters = hideMonstersButton:isChecked() local hideMonsters = hideMonstersButton:isChecked()
local hideSkulls = hideSkullsButton:isChecked() local hideSkulls = hideSkullsButton:isChecked()
local hideParty = hidePartyButton:isChecked() local hideParty = hidePartyButton:isChecked()
if hidePlayers and not creature:asMonster() and not creature:asNpc() then if hidePlayers and not creature:asMonster() and not creature:asNpc() then
return false return false
elseif hideNPCs and creature:asNpc() then elseif hideNPCs and creature:asNpc() then
@ -128,35 +128,35 @@ function Battle.doCreatureFitFilters(creature)
elseif hideParty and creature:getShield() > ShieldWhiteBlue then elseif hideParty and creature:getShield() > ShieldWhiteBlue then
return false return false
end end
return true return true
end end
function Battle.checkCreatures() function Battle.checkCreatures()
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if player then if player then
local spectators = {} local spectators = {}
-- reloading list of spectators -- reloading list of spectators
local creaturesAppeared = {} local creaturesAppeared = {}
creatures = g_map.getSpectators(player:getPosition(), false) creatures = g_map.getSpectators(player:getPosition(), false)
for i, creature in ipairs(creatures) do for i, creature in ipairs(creatures) do
if creature ~= player and Battle.doCreatureFitFilters(creature) then if creature ~= player and Battle.doCreatureFitFilters(creature) then
-- searching for creatures that appeared on battle list -- searching for creatures that appeared on battle list
local battleButton = battleButtonsByCreaturesList[creature:getId()] local battleButton = battleButtonsByCreaturesList[creature:getId()]
if battleButton == nil then if battleButton == nil then
table.insert(creaturesAppeared, creature) table.insert(creaturesAppeared, creature)
else else
Battle.setLifeBarPercent(battleButton, creature:getHealthPercent()) Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
end end
spectators[creature:getId()] = creature spectators[creature:getId()] = creature
end end
end end
for i, v in pairs(creaturesAppeared) do for i, v in pairs(creaturesAppeared) do
Battle.addCreature(v) Battle.addCreature(v)
end end
-- searching for creatures that disappeared from battle list -- searching for creatures that disappeared from battle list
local creaturesDisappeared = {} local creaturesDisappeared = {}
for i, creature in pairs(battleButtonsByCreaturesList) do for i, creature in pairs(battleButtonsByCreaturesList) do
@ -164,7 +164,7 @@ function Battle.checkCreatures()
table.insert(creaturesDisappeared, creature.creature) table.insert(creaturesDisappeared, creature.creature)
end end
end end
for i, v in pairs(creaturesDisappeared) do for i, v in pairs(creaturesDisappeared) do
Battle.removeCreature(v) Battle.removeCreature(v)
end end
@ -174,28 +174,28 @@ end
function Battle.addCreature(creature) function Battle.addCreature(creature)
local creatureId = creature:getId() local creatureId = creature:getId()
if battleButtonsByCreaturesList[creatureId] == nil then if battleButtonsByCreaturesList[creatureId] == nil then
local battleButton = displayUI('battleButton.otui', { parent = battlePannel }) local battleButton = displayUI('battleButton.otui', battlePanne)
local creatureWidget = battleButton:getChildById('creature') local creatureWidget = battleButton:getChildById('creature')
local labelWidget = battleButton:getChildById('label') local labelWidget = battleButton:getChildById('label')
local lifeBarWidget = battleButton:getChildById('lifeBar') local lifeBarWidget = battleButton:getChildById('lifeBar')
battleButton:setId('BattleButton_' .. creature:getName():gsub('%s','_')) battleButton:setId('BattleButton_' .. creature:getName():gsub('%s','_'))
battleButton.creatureId = creatureId battleButton.creatureId = creatureId
battleButton.creature = creature battleButton.creature = creature
battleButton.isHovered = false battleButton.isHovered = false
battleButton.isTarget = false battleButton.isTarget = false
battleButton.isFollowed = false battleButton.isFollowed = false
labelWidget:setText(creature:getName()) labelWidget:setText(creature:getName())
creatureWidget:setCreature(creature) creatureWidget:setCreature(creature)
Battle.setLifeBarPercent(battleButton, creature:getHealthPercent()) Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
battleButtonsByCreaturesList[creatureId] = battleButton battleButtonsByCreaturesList[creatureId] = battleButton
Battle.checkCreatureSkull(battleButton.creature) Battle.checkCreatureSkull(battleButton.creature)
Battle.checkCreatureEmblem(battleButton.creature) Battle.checkCreatureEmblem(battleButton.creature)
end end
end end
@ -205,7 +205,7 @@ function Battle.checkCreatureSkull(creature, skullId)
local skullWidget = battleButton:getChildById('skull') local skullWidget = battleButton:getChildById('skull')
local labelWidget = battleButton:getChildById('label') local labelWidget = battleButton:getChildById('label')
local creature = battleButton.creature local creature = battleButton.creature
if creature:getSkull() ~= SkullNone then if creature:getSkull() ~= SkullNone then
skullWidget:setWidth(skullWidget:getHeight()) skullWidget:setWidth(skullWidget:getHeight())
local imagePath = getSkullImagePath(creature:getSkull()) local imagePath = getSkullImagePath(creature:getSkull())
@ -265,12 +265,12 @@ end
function Battle.removeCreature(creature) function Battle.removeCreature(creature)
local creatureId = creature:getId() local creatureId = creature:getId()
if battleButtonsByCreaturesList[creatureId] ~= nil then if battleButtonsByCreaturesList[creatureId] ~= nil then
if lastBattleButtonSwitched == battleButtonsByCreaturesList[creatureId] then if lastBattleButtonSwitched == battleButtonsByCreaturesList[creatureId] then
lastBattleButtonSwitched = nil lastBattleButtonSwitched = nil
end end
battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare() battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare()
battleButtonsByCreaturesList[creatureId]:destroy() battleButtonsByCreaturesList[creatureId]:destroy()
battleButtonsByCreaturesList[creatureId] = nil battleButtonsByCreaturesList[creatureId] = nil
@ -280,7 +280,7 @@ end
function Battle.setLifeBarPercent(battleButton, percent) function Battle.setLifeBarPercent(battleButton, percent)
local lifeBarWidget = battleButton:getChildById('lifeBar') local lifeBarWidget = battleButton:getChildById('lifeBar')
lifeBarWidget:setPercent(percent) lifeBarWidget:setPercent(percent)
local color local color
for i, v in pairs(lifeBarColors) do for i, v in pairs(lifeBarColors) do
if percent > v.percentAbove then if percent > v.percentAbove then
@ -288,31 +288,31 @@ function Battle.setLifeBarPercent(battleButton, percent)
break break
end end
end end
lifeBarWidget:setBackgroundColor(color) lifeBarWidget:setBackgroundColor(color)
end end
function Battle.onbattlePannelHoverChange(widget, hovered) function Battle.onbattlePannelHoverChange(widget, hovered)
if widget.isBattleButton then if widget.isBattleButton then
widget.isHovered = hovered widget.isHovered = hovered
Battle.checkBattleButton(widget) Battle.checkBattleButton(widget)
end end
end end
function Battle.onAttack(creature) function Battle.onAttack(creature)
local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
if battleButton then if battleButton then
battleButton.isTarget = creature and true or false battleButton.isTarget = creature and true or false
Battle.checkBattleButton(battleButton) Battle.checkBattleButton(battleButton)
end end
end end
function Battle.onFollow(creature) function Battle.onFollow(creature)
local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
if battleButton then if battleButton then
battleButton.isFollowed = creature and true or false battleButton.isFollowed = creature and true or false
Battle.checkBattleButton(battleButton) Battle.checkBattleButton(battleButton)
end end
end end
function Battle.checkBattleButton(battleButton) function Battle.checkBattleButton(battleButton)
@ -322,20 +322,20 @@ function Battle.checkBattleButton(battleButton)
elseif battleButton.isFollowed then elseif battleButton.isFollowed then
color = battleButtonColors.onFollowed color = battleButtonColors.onFollowed
end end
color = battleButton.isHovered and color.hovered or color.notHovered color = battleButton.isHovered and color.hovered or color.notHovered
if battleButton.isHovered or battleButton.isTarget or battleButton.isFollowed then if battleButton.isHovered or battleButton.isTarget or battleButton.isFollowed then
battleButton.creature:showStaticSquare(color) battleButton.creature:showStaticSquare(color)
battleButton:getChildById('creature'):setBorderWidth(1) battleButton:getChildById('creature'):setBorderWidth(1)
battleButton:getChildById('creature'):setBorderColor(color) battleButton:getChildById('creature'):setBorderColor(color)
battleButton:getChildById('label'):setColor(color) battleButton:getChildById('label'):setColor(color)
else else
battleButton.creature:hideStaticSquare() battleButton.creature:hideStaticSquare()
battleButton:getChildById('creature'):setBorderWidth(0) battleButton:getChildById('creature'):setBorderWidth(0)
battleButton:getChildById('label'):setColor(color) battleButton:getChildById('label'):setColor(color)
end end
if battleButton.isTarget or battleButton.isFollowed then if battleButton.isTarget or battleButton.isFollowed then
if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then
lastBattleButtonSwitched.isTarget = false lastBattleButtonSwitched.isTarget = false

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save