Refactoring and flexibility changes

* Split game module into game and game_interface
* Move core_lib to corelib
* Move miniwindow to corelib
* Introduce init.lua script for initializing the client, giving much more flexibility
* OTClient is no longer Application derived and is much simpler
This commit is contained in:
Eduardo Bart
2012-06-19 21:15:56 -03:00
parent 9e72860178
commit 8761220deb
115 changed files with 448 additions and 363 deletions

View File

@@ -1,8 +1,8 @@
Client = {}
function Client.reloadScripts()
dofile '/otclientrc'
reloadModules()
dofile '/otclientrc'
local message = tr('All modules and scripts were reloaded.')
TextMessage.displayEventAdvance(message)
print(message)
@@ -35,16 +35,13 @@ function Client.init()
g_window.setTitle('OTClient')
g_window.setIcon(resolvepath('clienticon.png'))
-- show the only window after the first frame is rendered
scheduleEvent(function()
addEvent(function()
scheduleEvent(function()
g_window.show()
-- Play startup music (The Silver Tree, by Mattias Westlund)
g_sounds.playMusic("startup.ogg", 3)
connect(g_game, { onGameStart = function() g_sounds.stopMusic(3) end })
connect(g_game, { onGameEnd= function() g_sounds.playMusic("startup.ogg", 3) end })
end, 0)
end, 100)
end, 0)
end

View File

@@ -3,8 +3,6 @@ Module
description: Initialize the client and setups its main window
author: edubart
website: www.otclient.info
autoload: true
autoload-priority: 100
reloadable: false
load-later:

View File

@@ -47,9 +47,9 @@ function Locales.init()
local userLocaleName = Settings.get('locale')
if userLocaleName and Locales.setLocale(userLocaleName) then
--info('Using configured locale: ' .. userLocaleName)
pdebug('Using configured locale: ' .. userLocaleName)
else
--info('Using default locale: ' .. defaultLocaleName)
pdebug('Using default locale: ' .. defaultLocaleName)
Locales.setLocale(defaultLocaleName)
Settings.set('locale', defaultLocaleName)
end
@@ -100,7 +100,7 @@ end
function Locales.setLocale(name)
local locale = installedLocales[name]
if not locale then
warning("Locale " .. name .. ' does not exist.')
pwarning("Locale " .. name .. ' does not exist.')
return false
end
currentLocale = locale
@@ -125,7 +125,7 @@ function tr(text, ...)
local translation = currentLocale.translation[text]
if not translation then
if currentLocale.name ~= defaultLocaleName then
warning('Unable to translate: \"' .. text .. '\"')
pwarning('Unable to translate: \"' .. text .. '\"')
end
translation = text
end

View File

@@ -15,7 +15,8 @@ local function onSkinComboBoxOptionChange(self, optionText, optionData)
end
local function getSkinPath(name)
return g_modules.getModulesPath() .. g_lua.getCurrentSourcePath(0) .. '/skins/' .. string.lower(name) .. '/'
local current = getfsrcpath()
return g_resources.getRealDir(current) .. current .. '/skins/' .. string.lower(name)
end
-- public functions
@@ -30,9 +31,9 @@ function Skins.init()
local userSkinName = Settings.get('skin')
if userSkinName and Skins.setSkin(userSkinName) then
info('Using configured skin: ' .. userSkinName)
pdebug('Using configured skin: ' .. userSkinName)
else
info('Using default skin: ' .. defaultSkinName)
pdebug('Using default skin: ' .. defaultSkinName)
Skins.setSkin(defaultSkinName)
Settings.set('skin', defaultSkinName)
end
@@ -65,7 +66,7 @@ function Skins.installSkin(skin)
end
if installedSkins[skin.name] then
warning(skin.name .. ' has been replaced.')
pwarning(skin.name .. ' has been replaced.')
end
installedSkins[skin.name] = skin
@@ -79,12 +80,12 @@ end
function Skins.setSkin(name)
local skin = installedSkins[name]
if not skin then
warning("Skin " .. name .. ' does not exist.')
pwarning("Skin " .. name .. ' does not exist.')
return false
end
g_fonts.clearFonts()
g_ui.clearStyles()
g_ui.clearStyles()
if name ~= defaultSkinName then
local defaultSkin = installedSkins[defaultSkinName]

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 385 B

After

Width:  |  Height:  |  Size: 385 B

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 763 B

After

Width:  |  Height:  |  Size: 763 B

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

@@ -1,10 +1,8 @@
Module
name: core_lib
name: corelib
description: Contains core lua classes, functions and constants used by other modules
author: OTClient team
website: www.otclient.info
autoload: true
autoload-priority: 10
reloadable: false
@onLoad: |

View File

@@ -15,7 +15,9 @@ function translateKeyCombo(keyCombo)
end
local function retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc == nil then return nil end
if keyComboDesc == nil then
error('Unable to translate key combo \'' .. keyComboDesc .. '\'')
end
local keyCombo = {}
for i,currentKeyDesc in ipairs(keyComboDesc:split('+')) do
for keyCode, keyDesc in pairs(KeyCodeDescs) do
@@ -97,11 +99,7 @@ function Keyboard.bindKeyDown(keyComboDesc, callback, widget)
widget = widget or rootWidget
connectKeyDownEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyDownCombos[keyComboDesc] = callback
else
error('key combo \'' .. keyComboDesc .. '\' is failed')
end
widget.boundKeyDownCombos[keyComboDesc] = callback
end
function Keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
@@ -109,12 +107,8 @@ function Keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
widget = widget or rootWidget
connectKeyPressEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyPressCombos[keyComboDesc] = { callback = callback, autoRepeatDelay = autoRepeatDelay }
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
else
error('key combo \'' .. keyComboDesc .. '\' is failed')
end
widget.boundKeyPressCombos[keyComboDesc] = { callback = callback, autoRepeatDelay = autoRepeatDelay }
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
end
function Keyboard.unbindKeyDown(keyComboDesc, widget)

View File

@@ -45,7 +45,7 @@ function ToolTip.init()
onHoverChange = onWidgetHoverChange})
addEvent(function()
toolTipLabel = createWidget('Label', rootWidget)
toolTipLabel = createWidget('UILabel', rootWidget)
toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111cc')
toolTipLabel:setTextAlign(AlignCenter)

View File

@@ -6,18 +6,27 @@ function print(...)
g_logger.log(LogInfo, msg)
end
function info(msg)
function pinfo(msg)
g_logger.log(LogInfo, msg)
end
function warning(msg)
function perror(msg)
g_logger.log(LogError, msg)
end
function pwarning(msg)
g_logger.log(LogWarning, msg)
end
function pdebug(msg)
g_logger.log(LogDebug, msg)
end
function fatal(msg)
g_logger.log(LogFatal, msg)
end
exit = g_app.exit
quit = g_app.exit
@@ -161,3 +170,7 @@ function signalcall(param, ...)
end
return false
end
function tr(s)
return s
end

View File

@@ -1,15 +1,16 @@
Module
name: game
description: Create the game interface, where the ingame stuff starts
description: Contains game related classes
author: OTClient team
website: www.otclient.info
dependencies:
- client_extended
- game_tibiafiles
- client_background
- game_tibiafiles
load-later:
- game_interface
- game_textmessage
- game_console
- game_outfit
@@ -31,26 +32,9 @@ Module
- game_shaders
@onLoad: |
importStyle 'styles/items.otui'
importStyle 'styles/creatures.otui'
importStyle 'styles/miniwindow.otui'
importStyle 'styles/countwindow.otui'
dofile 'const'
dofile 'protocollogin'
dofile 'widgets/uigamemap'
dofile 'widgets/uiitem'
dofile 'widgets/uiminiwindow'
dofile 'widgets/uiminiwindowcontainer'
dofile 'creature'
dofile 'player'
dofile 'gameinterface'
GameInterface.init()
@onUnload: |
GameInterface.terminate()

View File

@@ -6,7 +6,7 @@ Module
icon: battle.png
dependencies:
- game
- game_interface
@onLoad: |
dofile 'battle'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'bugreport'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'combatcontrols'

View File

@@ -106,7 +106,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat
Console.addText(composedMessage, speaktype, channel, name)
elseif channelId ~= 0 then
-- server sent a message on a channel that is not open
warning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
pwarning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
end
end
end
@@ -272,7 +272,7 @@ function Console.clear()
local tab = consoleTabBar:getTab(channelname)
consoleTabBar:removeTab(tab)
end
channels = {}
consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
@@ -407,12 +407,12 @@ function Console.popupMenu(mousePos, mouseButton, creatureName, text)
end
--TODO select all
menu:addOption(tr('Copy message'), function () g_window.setClipboardText(text) end)
if RuleViolation.hasWindowAccess() then
menu:addSeparator()
menu:addOption(tr('Rule Violation'), function() RuleViolation.show(creatureName, text:match('.+%:%s(.+)')) end)
end
menu:addSeparator()
menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
else

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'console'

View File

@@ -17,7 +17,7 @@ ContainerWindow < MiniWindow
anchors.right: minimizeButton.left
margin-right: 3
size: 14 14
image-source: /game/images/miniwindowbuttons.png
image-source: /images/miniwindowbuttons.png
image-clip: 42 0 14 14
$hover:

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'containers'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'healthbar'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'hotkeys_manager'

View File

@@ -25,7 +25,7 @@ function GameInterface.init()
gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', 'images/logout.png', GameInterface.tryLogout)
logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', '/images/logout.png', GameInterface.tryLogout)
logoutButton:hide()
Keyboard.bindKeyPress('Up', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)

View File

@@ -1,15 +1,15 @@
GameSidePanel < UIMiniWindowContainer
image-source: images/sidepanel.png
image-source: /images/sidepanel.png
image-border: 4
padding: 4
GameBottomPanel < Panel
image-source: images/bottompanel.png
image-source: /images/bottompanel.png
image-border: 4
GameMapPanel < UIGameMap
padding: 4
image-source: images/mappanel.png
image-source: /images/mappanel.png
image-border: 4
UIWidget

View File

@@ -0,0 +1,21 @@
Module
name: game_interface
description: Create the game interface, where the ingame stuff starts
author: OTClient team
website: www.otclient.info
@onLoad: |
importStyle 'styles/items.otui'
importStyle 'styles/creatures.otui'
importStyle 'styles/miniwindow.otui'
importStyle 'styles/countwindow.otui'
dofile 'widgets/uigamemap'
dofile 'widgets/uiitem'
dofile 'gameinterface'
GameInterface.init()
@onUnload: |
GameInterface.terminate()

View File

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

View File

@@ -5,7 +5,7 @@ MiniWindow < UIMiniWindow
height: 200
text-offset: 24 5
text-align: topLeft
image-source: /game/images/miniwindow.png
image-source: /images/miniwindow.png
image-border: 4
image-border-top: 23
image-border-bottom: 4
@@ -22,7 +22,7 @@ MiniWindow < UIMiniWindow
margin-top: 5
margin-right: 5
size: 14 14
image-source: /game/images/miniwindowbuttons.png
image-source: /images/miniwindowbuttons.png
image-clip: 28 0 14 14
$hover:
@@ -37,7 +37,7 @@ MiniWindow < UIMiniWindow
anchors.right: closeButton.left
margin-right: 3
size: 14 14
image-source: /game/images/miniwindowbuttons.png
image-source: /images/miniwindowbuttons.png
image-clip: 0 0 14 14
$hover:

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'inventory'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'minimap'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'npctrade'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'outfit'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'playertrade'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'questlog'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'ruleviolation'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'shaders'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'skills'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'textbooks'

View File

@@ -5,7 +5,7 @@ Module
website: www.otclient.info
dependencies:
- game
- game_interface
@onLoad: |
dofile 'textmessage'