@ -1,3 +1,3 @@
|
||||
[submodule "data/tibiafiles"]
|
||||
path = data/tibiafiles
|
||||
[submodule "modules/tibiafiles"]
|
||||
path = modules/tibiafiles
|
||||
url = https://github.com/Baxnie/otclient-tibiafiles.git
|
||||
|
@ -1,10 +0,0 @@
|
||||
glyph-height: 14
|
||||
glyph-spacing: [1, 1]
|
||||
top-margin: 2
|
||||
image: helvetica-11px-bold.png
|
||||
image-glyph-size: [16, 16]
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
65: 8
|
||||
|
@ -1,9 +0,0 @@
|
||||
glyph-height: 14
|
||||
glyph-spacing: [1, 1]
|
||||
top-margin: 1
|
||||
image: helvetica-11px.png
|
||||
image-glyph-size: [16, 16]
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
|
@ -1,10 +0,0 @@
|
||||
glyph-height: 16
|
||||
glyph-spacing: [1, 1]
|
||||
top-margin: 2
|
||||
image: helvetica-12px-bold.png
|
||||
image-glyph-size: [18, 18]
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
65: 9
|
||||
|
@ -1,9 +0,0 @@
|
||||
glyph-height: 15
|
||||
glyph-spacing: [1, 1]
|
||||
top-margin: 1
|
||||
image: helvetica-12px.png
|
||||
image-glyph-size: [16, 16]
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
65: 8
|
@ -1,10 +0,0 @@
|
||||
glyph-height: 16
|
||||
glyph-spacing: [1, 1]
|
||||
top-margin: 2
|
||||
image: helvetica-14px-bold.png
|
||||
image-glyph-size: [20, 20]
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
65: 9
|
||||
|
@ -1,3 +0,0 @@
|
||||
require 'constants'
|
||||
require 'util'
|
||||
require 'messagebox'
|
@ -1,16 +0,0 @@
|
||||
require 'entergame'
|
||||
|
||||
function initializeApplication()
|
||||
mainMenu = loadUI("ui/mainmenu", rootUI)
|
||||
end
|
||||
|
||||
function terminateApplication()
|
||||
exit()
|
||||
end
|
||||
|
||||
-- here is where everything starts
|
||||
if not initialized then
|
||||
initializeApplication()
|
||||
onClose = terminateApplication
|
||||
initialized = true
|
||||
end
|
@ -1,80 +0,0 @@
|
||||
default font: helvetica-12px
|
||||
default font color: [210, 210, 210, 255]
|
||||
|
||||
buttons:
|
||||
default:
|
||||
font: helvetica-11px-bold
|
||||
font color: [240, 173, 77, 255]
|
||||
default size: [106, 24]
|
||||
|
||||
bordered image:
|
||||
source: button.png
|
||||
border: 5
|
||||
|
||||
hover state:
|
||||
bordered image:
|
||||
source: button_hover.png
|
||||
border: 5
|
||||
|
||||
down state:
|
||||
text translate: [1, 1]
|
||||
bordered image:
|
||||
source: button_down.png
|
||||
border: 5
|
||||
panels:
|
||||
default:
|
||||
# the default panel is empty
|
||||
|
||||
mainMenuBackground:
|
||||
image: background.png
|
||||
antialised: true
|
||||
|
||||
roundedGridPanel:
|
||||
bordered image:
|
||||
source: panel_rounded.png
|
||||
border: 4
|
||||
|
||||
flatPanel:
|
||||
bordered image:
|
||||
source: panel_flat.png
|
||||
border: 1
|
||||
|
||||
labels:
|
||||
default:
|
||||
|
||||
large:
|
||||
font: helvetica-12px-bold
|
||||
|
||||
windows:
|
||||
default:
|
||||
font: helvetica-11px-bold
|
||||
font color: [240, 173, 77, 255]
|
||||
head:
|
||||
height: 20
|
||||
bordered image:
|
||||
source: window.png
|
||||
size: [256, 19]
|
||||
border: 4
|
||||
bottom: 3
|
||||
|
||||
body:
|
||||
bordered image:
|
||||
source: window.png
|
||||
size: [256, 237]
|
||||
offset: [0, 19]
|
||||
border: 4
|
||||
top: 0
|
||||
|
||||
text edits:
|
||||
default:
|
||||
default size: [86, 20]
|
||||
text margin: 3
|
||||
bordered image:
|
||||
source: panel_flat.png
|
||||
border: 1
|
||||
|
||||
line decorations:
|
||||
default:
|
||||
bordered image:
|
||||
source: horizontal_separator.png
|
||||
top: 2
|
@ -1 +0,0 @@
|
||||
Subproject commit a25c238959eb660a187e614eb5c794e0da302bac
|
@ -0,0 +1,23 @@
|
||||
Module
|
||||
name: core
|
||||
description: Contains lua classes, functions and constants used by other modules
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
dependencies:
|
||||
- core_fonts
|
||||
- core_ui
|
||||
|
||||
onLoad: |
|
||||
require 'constants'
|
||||
require 'util'
|
||||
require 'widget'
|
||||
require 'messagebox'
|
||||
|
||||
rootWidget = getRootWidget()
|
||||
return true
|
||||
|
||||
onUnload: |
|
||||
rootWidget = nil
|
||||
|
@ -0,0 +1,19 @@
|
||||
function UIWidget:setMargin(...)
|
||||
local params = {...}
|
||||
if #params == 1 then
|
||||
self.marginTop = params[1]
|
||||
self.marginRight = params[1]
|
||||
self.marginBottom = params[1]
|
||||
self.marginLeft = params[1]
|
||||
elseif #params == 2 then
|
||||
self.marginTop = params[1]
|
||||
self.marginRight = params[2]
|
||||
self.marginBottom = params[1]
|
||||
self.marginLeft = params[2]
|
||||
elseif #params == 4 then
|
||||
self.marginTop = params[1]
|
||||
self.marginRight = params[2]
|
||||
self.marginBottom = params[3]
|
||||
self.marginLeft = params[4]
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
Module
|
||||
name: core_fonts
|
||||
description: Contains fonts used by core
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
onLoad: |
|
||||
importFont('helvetica-11px-bold')
|
||||
importFont('helvetica-11px')
|
||||
importFont('helvetica-12px-bold')
|
||||
importFont('helvetica-12px')
|
||||
importFont('helvetica-14px-bold')
|
||||
|
||||
setDefaultFont('helvetica-12px')
|
||||
return true
|
||||
|
@ -0,0 +1,12 @@
|
||||
Font
|
||||
name: helvetica-11px-bold
|
||||
height: 14
|
||||
spacing: 1 1
|
||||
top margin: 2
|
||||
texture: helvetica-11px-bold.png
|
||||
glyph size: 16 16
|
||||
|
||||
glyph widths:
|
||||
32: 4
|
||||
65: 8
|
||||
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
@ -0,0 +1,11 @@
|
||||
Font
|
||||
name: helvetica-11px
|
||||
height: 14
|
||||
spacing: 1 1
|
||||
top margin: 1
|
||||
texture: helvetica-11px.png
|
||||
glyph size: 16 16
|
||||
|
||||
glyph widths:
|
||||
32: 4
|
||||
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
@ -0,0 +1,12 @@
|
||||
Font
|
||||
name: helvetica-12px-bold
|
||||
height: 16
|
||||
spacing: 1 1
|
||||
top margin: 2
|
||||
texture: helvetica-12px-bold.png
|
||||
glyph size: 18 18
|
||||
|
||||
glyph widths:
|
||||
32: 4
|
||||
65: 9
|
||||
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
@ -0,0 +1,11 @@
|
||||
Font
|
||||
name: helvetica-12px
|
||||
height: 15
|
||||
spacing: 1 1
|
||||
top margin: 1
|
||||
texture: helvetica-12px.png
|
||||
glyph size: 16 16
|
||||
|
||||
glyph widths:
|
||||
32: 4
|
||||
65: 8
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
@ -0,0 +1,12 @@
|
||||
Font
|
||||
name: helvetica-14px-bold
|
||||
height: 16
|
||||
spacing: 1 1
|
||||
top margin: 2
|
||||
texture: helvetica-14px-bold.png
|
||||
glyph size: 20 20
|
||||
|
||||
glyph widths:
|
||||
32: 4
|
||||
65: 9
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@ -0,0 +1,19 @@
|
||||
Button < UIButton
|
||||
font: helvetica-11px-bold
|
||||
color: 240 173 77 255
|
||||
size: 106 24
|
||||
border-image:
|
||||
source: /core_ui/images/button.png
|
||||
border: 5
|
||||
|
||||
state.hover:
|
||||
border-image:
|
||||
source: /core_ui/images/button_hover.png
|
||||
border: 5
|
||||
|
||||
state.down:
|
||||
text-translate: 1 1
|
||||
border-image:
|
||||
source: /core_ui/images/button_down.png
|
||||
border: 5
|
||||
|
@ -0,0 +1,18 @@
|
||||
Module
|
||||
name: core_ui
|
||||
description: Contains ui styles used by other modules
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
dependencies:
|
||||
- core_fonts
|
||||
onLoad: |
|
||||
importStyles('buttons.otui')
|
||||
importStyles('labels.otui')
|
||||
importStyles('panels.otui')
|
||||
importStyles('separators.otui')
|
||||
importStyles('lineedits.otui')
|
||||
importStyles('windows.otui')
|
||||
return true
|
||||
|
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: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 151 B |
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
@ -0,0 +1,5 @@
|
||||
Label < UILabel
|
||||
|
||||
LargerLabel < Label
|
||||
font: helvetica-12px-bold
|
||||
|
@ -0,0 +1,7 @@
|
||||
LineEdit < UILineEdit
|
||||
size: 86 20
|
||||
text-margin: 3
|
||||
border-image:
|
||||
source: /core_ui/images/panel_flat.png
|
||||
border: 1
|
||||
|
@ -0,0 +1,11 @@
|
||||
Panel < UIWidget
|
||||
|
||||
FlatPanel < Panel
|
||||
border-image:
|
||||
source: /core_ui/images/panel_flat.png
|
||||
border: 4
|
||||
|
||||
RoundedGridPanel < Panel
|
||||
border-image:
|
||||
source: /core_ui/images/panel_rounded.png
|
||||
border: 4
|
@ -0,0 +1,4 @@
|
||||
HorizontalSeparator < UIWidget
|
||||
border-image:
|
||||
source: /core_ui/images/horizontal_separator.png
|
||||
border.top: 2
|
@ -0,0 +1,20 @@
|
||||
Window < UIWindow
|
||||
size: 200 100
|
||||
head:
|
||||
height: 20
|
||||
border-image:
|
||||
source: /core_ui/images/window.png
|
||||
size: 256 19
|
||||
border: 4
|
||||
border.bottom: 3
|
||||
|
||||
body:
|
||||
border-image:
|
||||
source: /core_ui/images/window.png
|
||||
size: 256 237
|
||||
offset: 0 19
|
||||
border: 4
|
||||
border.top: 0
|
||||
|
||||
MainWindow < Window
|
||||
anchors.centerIn: parent
|
@ -0,0 +1,26 @@
|
||||
Module
|
||||
name: mainmenu
|
||||
description: Create the game mainmenu, where everything starts
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
dependencies:
|
||||
- core
|
||||
|
||||
onLoad: |
|
||||
require('entergame')
|
||||
|
||||
if not initialized then
|
||||
mainMenu = loadUI("/mainmenu/ui/mainmenu.otui")
|
||||
getRootWidget():addChild(mainMenu)
|
||||
initialized = true
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
onUnload: |
|
||||
mainMenu:destroy()
|
||||
mainMenu = nil
|
||||
initialized = false
|
||||
|
Before Width: | Height: | Size: 1.9 MiB After Width: | Height: | Size: 1.9 MiB |
@ -1,42 +1,47 @@
|
||||
%panel#background
|
||||
Panel
|
||||
skin: mainMenuBackground
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
%panel#mainMenu
|
||||
Panel
|
||||
id: mainMenu
|
||||
skin: roundedGridPanel
|
||||
size: [144, 162]
|
||||
size: 144 162
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin.left: 60
|
||||
margin.bottom: 70
|
||||
|
||||
%button#enterGameButton
|
||||
Button
|
||||
id: enterGameButton
|
||||
text: Enter Game
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 18
|
||||
onClick: loadUI("entergamewindow", rootUI)
|
||||
onClick: rootWidget:addChild(loadUI("entergamewindow"))
|
||||
|
||||
%button#optionsButton
|
||||
Button
|
||||
id: optionsButton
|
||||
text: Options
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 10
|
||||
onClick: loadUI("optionswindow", rootUI)
|
||||
onClick: rootWidget:addChild(loadUI("optionswindow"))
|
||||
|
||||
%button#infoButton
|
||||
Button
|
||||
id: infoButton
|
||||
text: Info
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 10
|
||||
onClick: loadUI("infowindow", rootUI)
|
||||
onClick: rootWidget:addChild(loadUI("infowindow"))
|
||||
|
||||
%button#exitGameButton
|
||||
Button
|
||||
id: exitGameButton
|
||||
text: Exit
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 10
|
||||
onClick: terminateApplication()
|
||||
onClick: exit()
|
@ -0,0 +1,38 @@
|
||||
MenuButton < Button
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 10
|
||||
|
||||
Panel
|
||||
id: mainMenuBackground
|
||||
image:
|
||||
source: /mainmenu/ui/background.png
|
||||
smooth: true
|
||||
anchors.fill: parent
|
||||
|
||||
RoundedGridPanel
|
||||
id: mainMenu
|
||||
size: 144 162
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin.left: 60
|
||||
margin.bottom: 70
|
||||
|
||||
MenuButton
|
||||
text: Enter Game
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 18
|
||||
onClick: rootWidget:addChild(loadUI("/mainmenu/ui/entergamewindow.otui"))
|
||||
|
||||
MenuButton
|
||||
text: Options
|
||||
onClick: rootWidget:addChild(loadUI("/mainmenu/ui/optionswindow.otui"))
|
||||
|
||||
MenuButton
|
||||
text: Info
|
||||
onClick: rootWidget:addChild(loadUI("/mainmenu/ui/infowindow.otui"))
|
||||
|
||||
MenuButton
|
||||
text: Exit
|
||||
onClick: exit()
|
@ -0,0 +1 @@
|
||||
Subproject commit 8bb3b7d6d86e561be4622fbe7dbef208446a0319
|
@ -1,11 +0,0 @@
|
||||
rootUI = App.getRootContainer()
|
||||
|
||||
-- AnchorPoint
|
||||
AnchorNone = 0
|
||||
AnchorTop = 1
|
||||
AnchorBottom = 2
|
||||
AnchorLeft = 3
|
||||
AnchorRight = 4
|
||||
AnchorVerticalCenter = 5
|
||||
AnchorHorizontalCenter = 6
|
||||
|
@ -1,3 +0,0 @@
|
||||
require 'constants'
|
||||
require 'util'
|
||||
require 'messagebox'
|
@ -1,86 +0,0 @@
|
||||
MessageBox = {}
|
||||
MessageBox.__index = MessageBox
|
||||
|
||||
-- messagebox flags
|
||||
MessageBoxOk = 1
|
||||
MessageBoxCancel = 2
|
||||
|
||||
function MessageBox.create(title, text, flags)
|
||||
local box = {}
|
||||
setmetatable(box, MessageBox)
|
||||
|
||||
-- create messagebox window
|
||||
local window = UIWindow.new("messageBoxWindow", rootUI)
|
||||
window.title = title
|
||||
window:centerIn(rootUI)
|
||||
window:setLocked()
|
||||
|
||||
-- create messagebox label
|
||||
local label = UILabel.new("messageBoxLabel", window)
|
||||
label.text = text
|
||||
label:addAnchor(AnchorHorizontalCenter, window, AnchorHorizontalCenter)
|
||||
label:addAnchor(AnchorTop, window, AnchorTop)
|
||||
label:setMargin(27, 0)
|
||||
|
||||
-- set window size based on label size
|
||||
window.width = label.width + 40
|
||||
window.height = label.height + 64
|
||||
|
||||
-- setup messagebox first button
|
||||
local buttonText
|
||||
local button1 = UIButton.new("messageBoxButton1", window)
|
||||
button1:addAnchor(AnchorBottom, window, AnchorBottom)
|
||||
button1:addAnchor(AnchorRight, window, AnchorRight)
|
||||
button1:setMargin(10)
|
||||
|
||||
if flags == MessageBoxOk then
|
||||
buttonText = "Ok"
|
||||
box.onOk = createEmptyFunction()
|
||||
button1.onClick = function()
|
||||
box.onOk()
|
||||
box:destroy()
|
||||
end
|
||||
elseif flags == MessageBoxCancel then
|
||||
buttonText = "Cancel"
|
||||
box.onCancel = createEmptyFunction()
|
||||
button1.onClick = function()
|
||||
box.onCancel()
|
||||
box:destroy()
|
||||
end
|
||||
end
|
||||
button1.text = buttonText
|
||||
|
||||
box.window = window
|
||||
return box
|
||||
end
|
||||
|
||||
function MessageBox:destroy()
|
||||
if self.onDestroy then
|
||||
self.onDestroy()
|
||||
self.onDestroy = nil
|
||||
end
|
||||
if self.window then
|
||||
self.window:destroy()
|
||||
self.window = nil
|
||||
end
|
||||
self.onOk = nil
|
||||
self.onCancel = nil
|
||||
end
|
||||
|
||||
-- shortcuts for creating message boxes
|
||||
function displayMessageBox(title, text, flags)
|
||||
return MessageBox.create(title, text, flags)
|
||||
end
|
||||
|
||||
function displayErrorBox(title, text)
|
||||
return MessageBox.create(title, text, MessageBoxOk)
|
||||
end
|
||||
|
||||
function displayInfoBox(title, text)
|
||||
return MessageBox.create(title, text, MessageBoxOk)
|
||||
end
|
||||
|
||||
function displayCancelBox(title, text)
|
||||
return MessageBox.create(title, text, MessageBoxCancel)
|
||||
end
|
||||
|
@ -1,9 +0,0 @@
|
||||
title: Core
|
||||
description: Core utilities used by other modules
|
||||
author: otclient
|
||||
version: 1
|
||||
website: https://github.com/edubart/otclient
|
||||
enabled: true
|
||||
dependencies: [core_fonts, core_styles]
|
||||
script: core.lua
|
||||
|
@ -1,5 +0,0 @@
|
||||
function createEmptyFunction()
|
||||
local emptyFunction = function() end
|
||||
return emptyFunction
|
||||
end
|
||||
|
@ -1,4 +0,0 @@
|
||||
-- load default fonts
|
||||
App.loadFont("fonts/helvetica-11px")
|
||||
App.loadFont("fonts/helvetica-11px-bold")
|
||||
|
@ -1,9 +0,0 @@
|
||||
glyph-height: 14
|
||||
glyph-spacing: 1 1
|
||||
top-margin: 2
|
||||
image: helvetica-11px-bold.png
|
||||
image-glyph-size: 16 16
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
|
Before Width: | Height: | Size: 8.3 KiB |
@ -1,9 +0,0 @@
|
||||
glyph-height: 14
|
||||
glyph-spacing: 1 1
|
||||
top-margin: 1
|
||||
image: helvetica-11px.png
|
||||
image-glyph-size: 16 16
|
||||
|
||||
glyph-widths:
|
||||
32: 4
|
||||
|
Before Width: | Height: | Size: 8.1 KiB |
@ -1,9 +0,0 @@
|
||||
title: Fonts
|
||||
description: Fonts package
|
||||
author: otclient
|
||||
version: 1
|
||||
website: https://github.com/edubart/otclient
|
||||
enabled: true
|
||||
dependencies: []
|
||||
script: fonts.lua
|
||||
|
@ -1,9 +0,0 @@
|
||||
title: Core styles
|
||||
description: Core styles used by other modules
|
||||
author: otclient
|
||||
version: 1
|
||||
website: https://github.com/edubart/otclient
|
||||
enabled: true
|
||||
dependencies: [core_fonts]
|
||||
script: styles.lua
|
||||
|
@ -1,12 +0,0 @@
|
||||
-- set default font
|
||||
App.setDefaultFont("helvetica-11px")
|
||||
App.setDefaultFontColor(Color("#f0ad4dff"))
|
||||
|
||||
-- load styles
|
||||
App.loadStyle("styles/utilities")
|
||||
App.loadStyle("styles/panels")
|
||||
App.loadStyle("styles/buttons")
|
||||
App.loadStyle("styles/labels")
|
||||
App.loadStyle("styles/textedits")
|
||||
App.loadStyle("styles/windows")
|
||||
App.loadStyle("styles/linedecorations")
|
Before Width: | Height: | Size: 825 B |
Before Width: | Height: | Size: 833 B |
Before Width: | Height: | Size: 859 B |
@ -1,25 +0,0 @@
|
||||
button
|
||||
font: helvetica-11px-bold
|
||||
font-color: #f0ad4dff
|
||||
size: 106 24
|
||||
bordered-image: { source: button_standard.png; border: 5 }
|
||||
|
||||
button:hover
|
||||
bordered-image: { source: tibia_flash/button_standard_hover.png; border: 5 }
|
||||
|
||||
button:down
|
||||
text-translate: 1 1
|
||||
bordered-image: { source: tibia_flash/button_standard_down.png; border: 5 }
|
||||
|
||||
button.small
|
||||
width: 64
|
||||
|
||||
button.large
|
||||
width: 144
|
||||
|
||||
button.notImplemented
|
||||
onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
button.closeParent
|
||||
onClick: self.parent:destroy()
|
||||
|
@ -1,57 +0,0 @@
|
||||
function EnterGame_connectToLoginServer()
|
||||
-- create login protocol
|
||||
local protocolLogin = ProtocolLogin.new()
|
||||
|
||||
-- used to recreate enter game window
|
||||
local recreateEnterGame = function()
|
||||
loadUI("ui/entergamewindow")
|
||||
end
|
||||
|
||||
-- display loading message box
|
||||
local loadBox = displayCancelBox("Please wait", "Connecting..")
|
||||
|
||||
-- cancel loading callback
|
||||
loadBox.onCancel = function()
|
||||
-- cancel protocol and reacreate enter game window
|
||||
protocolLogin:cancel()
|
||||
recreateEnterGame()
|
||||
end
|
||||
|
||||
-- error callback
|
||||
protocolLogin.onError = function(error)
|
||||
-- destroy loading message box
|
||||
loadBox:destroy()
|
||||
|
||||
-- display error message
|
||||
local errorBox = displayErrorBox("Login Error", error)
|
||||
|
||||
-- cancel protocol and reacreate enter game window
|
||||
self.cancel()
|
||||
errorBox.onOk = recreateEnterGame
|
||||
end
|
||||
|
||||
-- motd callback
|
||||
protocolLogin.onMotd = function(motd)
|
||||
-- destroy loading message box
|
||||
loadBox:destroy()
|
||||
|
||||
-- display motd
|
||||
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
|
||||
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
|
||||
local motdBox = displayInfoBox("Message of the day", motdText)
|
||||
|
||||
-- cancel protocol and reacreate enter game window
|
||||
self.cancel()
|
||||
motdBox.onOk = recreateEnterGame
|
||||
end
|
||||
|
||||
-- get account and password then login
|
||||
local enterGameWindow = rootUI:child("enterGameWindow")
|
||||
local account = enterGameWindow:child("accountNameTextEdit").text
|
||||
local password = enterGameWindow:child("passwordTextEdit").text
|
||||
protocolLogin:login(account, password)
|
||||
|
||||
-- destroy enter game window
|
||||
enterGameWindow:destroy()
|
||||
end
|
||||
|
@ -1,16 +0,0 @@
|
||||
require 'entergame'
|
||||
|
||||
function initializeApplication()
|
||||
mainMenu = loadUI("ui/mainmenu")
|
||||
end
|
||||
|
||||
function terminateApplication()
|
||||
App.exit()
|
||||
end
|
||||
|
||||
-- here is where everything starts
|
||||
if not initialized then
|
||||
initializeApplication()
|
||||
App.onClose = terminateApplication
|
||||
initialized = true
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
title: Main menu
|
||||
description: Used to create the main menu
|
||||
author: otclient
|
||||
version: 1
|
||||
website: https://github.com/edubart/otclient
|
||||
enabled: true
|
||||
dependencies: [core]
|
||||
script: init.lua
|
||||
|
Before Width: | Height: | Size: 1.9 MiB |
@ -1,63 +0,0 @@
|
||||
Window
|
||||
id: enterGameWindow
|
||||
title: Enter Game
|
||||
size: 236 178
|
||||
anchor.centerIn: parent
|
||||
lockOnLoad: true
|
||||
|
||||
Label
|
||||
text: Account name
|
||||
position: 18 33
|
||||
|
||||
Label
|
||||
text: "Password:"
|
||||
position: 18 62
|
||||
|
||||
Label
|
||||
text:
|
||||
[[If you don't have
|
||||
an account yet]]
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin: 87 18
|
||||
|
||||
Button
|
||||
text: Create Account
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin: 94 18
|
||||
onClick:
|
||||
function(self)
|
||||
displayErrorBox("Error", "Not implemented yet")
|
||||
self.parent:destroy()
|
||||
end
|
||||
|
||||
SmallButton
|
||||
text: Ok
|
||||
anchors.bottomRight: parent.bottomRight
|
||||
margin: 10 66
|
||||
onClick: EnterGame_connectToLoginServer()
|
||||
|
||||
SmallButton
|
||||
text: Cancel
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
margin: 10 13
|
||||
onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
TextEdit
|
||||
id: accountNameTextEdit
|
||||
text: tibialua0
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin: 32 18
|
||||
|
||||
TextEdit
|
||||
id: passwordTextEdit
|
||||
text: lua123456
|
||||
text-hidden: true
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin: 61 18
|
||||
|
@ -1,54 +0,0 @@
|
||||
%window#infoWindow
|
||||
title: Info
|
||||
size: 244 221
|
||||
anchor.centerIn: parent
|
||||
lockOnLoad: true
|
||||
|
||||
%panel.flat
|
||||
size: 208 129
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin: 32 18
|
||||
|
||||
%label
|
||||
align: center
|
||||
text: |-
|
||||
OTClient
|
||||
Version 0.2.0
|
||||
Created by edubart
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
margin.top: 20
|
||||
|
||||
%element.bottomSeparator
|
||||
size: 190 2
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin: 83 9
|
||||
|
||||
%label
|
||||
text: Official Website
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
margin: 14 9
|
||||
|
||||
%button
|
||||
text: Github Page
|
||||
size: 80 22
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
margin: 9
|
||||
|
||||
%element.bottomSeparator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 40 13
|
||||
|
||||
%button.closeParent
|
||||
text: Ok
|
||||
size: 43 20
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin: 191 188
|
||||
|
@ -1,63 +0,0 @@
|
||||
@import "additional_elements"
|
||||
|
||||
Panel
|
||||
id: "mainBackground"
|
||||
image:
|
||||
source: "background.png"
|
||||
antialised: true
|
||||
anchor.fill: parent
|
||||
|
||||
lista:
|
||||
- valor1
|
||||
- valor2
|
||||
- valor3
|
||||
|
||||
FlatPanel
|
||||
id: mainMenuPanel
|
||||
size: {117, 171}
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
margin: {70, 60}
|
||||
|
||||
// enter game button
|
||||
Button
|
||||
text: "Enter Game"
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 16
|
||||
onClick: |
|
||||
function(self)
|
||||
if not mainMenu:getChild("enterGameWindow") then
|
||||
local enterGame = loadUI("entergamewindow")
|
||||
enterGame:setLocked(true)
|
||||
end
|
||||
end
|
||||
|
||||
Button
|
||||
text: "Access Account"
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 6
|
||||
onClick: loadUI("entergamewindow")
|
||||
|
||||
Button
|
||||
text: "Options"
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 6
|
||||
onClick: loadUI("optionswindow")
|
||||
|
||||
Button
|
||||
text: "Info"
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 6
|
||||
onClick: loadUI("infowindow")
|
||||
|
||||
Button
|
||||
text: "Exit"
|
||||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 6
|
||||
onClick: terminateApplication()
|
||||
|
@ -1,82 +0,0 @@
|
||||
%window#optionsWindow
|
||||
title: Options
|
||||
size: 286 262
|
||||
anchor.centerIn: parent
|
||||
lockOnLoad: true
|
||||
|
||||
panel
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin.left: 18
|
||||
margin.top: 3
|
||||
height: 30
|
||||
|
||||
button
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin.top: 3
|
||||
onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
label
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin.top: 99
|
||||
|
||||
%panel
|
||||
anchors.top: parent.top
|
||||
margin.top: 29
|
||||
|
||||
%button { text: General }
|
||||
%label { text: "Change general\ngame options" }
|
||||
|
||||
%panel
|
||||
%button { text: Graphics }
|
||||
%label { text: "Change graphics and\nperformance settings" }
|
||||
|
||||
%panel
|
||||
%button { text: Console }
|
||||
%label { text: Customise the console }
|
||||
|
||||
%panel
|
||||
%button { text: Hotkeys }
|
||||
%label { text: Edit your hotkey texts }
|
||||
|
||||
%element.horizontalSeparator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 97 18
|
||||
|
||||
%panel
|
||||
anchors.top: ~
|
||||
anchors.bottom: parent.bottom
|
||||
margin.top: 29
|
||||
|
||||
%button
|
||||
text: Motd
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 60 18
|
||||
|
||||
%label
|
||||
text: |
|
||||
Show the most recent
|
||||
Message of the Day
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 56 117
|
||||
|
||||
%element.horizontalSeparator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 40 13
|
||||
|
||||
%button.closeParent
|
||||
text: Ok
|
||||
size: 43 20
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin: 13 10
|
||||
|
@ -0,0 +1,35 @@
|
||||
#include "configmanager.h"
|
||||
#include "resourcemanager.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
|
||||
ConfigManager g_configs;
|
||||
|
||||
bool ConfigManager::load(const std::string& fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
|
||||
if(!g_resources.fileExists(fileName))
|
||||
return false;
|
||||
|
||||
try {
|
||||
OTMLDocumentPtr doc = OTMLDocument::parse(fileName);
|
||||
for(const OTMLNodePtr& child : doc->childNodes())
|
||||
m_confsMap[child->tag()] = child->value();
|
||||
} catch(std::exception& e) {
|
||||
logError("ERROR: could not load configurations: ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigManager::save()
|
||||
{
|
||||
if(!m_fileName.empty()) {
|
||||
OTMLDocumentPtr doc = OTMLDocument::create();
|
||||
doc->write(m_confsMap);
|
||||
return doc->save(m_fileName);
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#include "configs.h"
|
||||
#include "resources.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
|
||||
Configs g_configs;
|
||||
|
||||
bool Configs::load(const std::string& fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
|
||||
if(!g_resources.fileExists(fileName))
|
||||
return false;
|
||||
|
||||
std::stringstream fin;
|
||||
if(!g_resources.loadFile(fileName, fin))
|
||||
return false;
|
||||
|
||||
try {
|
||||
OTMLParser parser(fin, fileName);
|
||||
parser.getDocument()->read(&m_confsMap);
|
||||
} catch(OTMLException e) {
|
||||
logError("ERROR: Malformed config file: ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Configs::save()
|
||||
{
|
||||
if(!m_fileName.empty()) {
|
||||
OTMLEmitter emitter;
|
||||
emitter.createDocument()->write(m_confsMap);
|
||||
g_resources.saveFile(m_fileName, emitter.emitDocument());
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#include "dispatcher.h"
|
||||
#include "engine.h"
|
||||
|
||||
Dispatcher g_dispatcher;
|
||||
|
||||
void Dispatcher::cleanup()
|
||||
{
|
||||
while(!m_scheduledTaskList.empty()) {
|
||||
ScheduledTask *task = m_scheduledTaskList.top();
|
||||
m_scheduledTaskList.pop();
|
||||
delete task;
|
||||
}
|
||||
}
|
||||
|
||||
void Dispatcher::poll()
|
||||
{
|
||||
while(!m_taskList.empty()) {
|
||||
m_taskList.front()();
|
||||
m_taskList.pop_front();
|
||||
}
|
||||
|
||||
while(!m_scheduledTaskList.empty()) {
|
||||
ScheduledTask *task = m_scheduledTaskList.top();
|
||||
if(g_engine.getCurrentFrameTicks() < task->ticks)
|
||||
break;
|
||||
m_scheduledTaskList.pop();
|
||||
task->callback();
|
||||
delete task;
|
||||
}
|
||||
}
|
||||
|
||||
void Dispatcher::scheduleTask(const std::function<void()>& callback, int delay)
|
||||
{
|
||||
m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback));
|
||||
}
|
||||
|
||||
void Dispatcher::addTask(const std::function<void()>& callback, bool pushFront)
|
||||
{
|
||||
if(pushFront)
|
||||
m_taskList.push_front(callback);
|
||||
else
|
||||
m_taskList.push_back(callback);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef DISPATCHER_H
|
||||
#define DISPATCHER_H
|
||||
|
||||
#include <global.h>
|
||||
#include <queue>
|
||||
|
||||
struct ScheduledTask {
|
||||
ScheduledTask(const std::function<void()>& _callback) : ticks(0), callback(_callback) { }
|
||||
ScheduledTask(int _ticks, const std::function<void()>& _callback) : ticks(_ticks), callback(_callback) { }
|
||||
bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; }
|
||||
int ticks;
|
||||
std::function<void()> callback;
|
||||
};
|
||||
|
||||
struct lessScheduledTask : public std::binary_function<ScheduledTask*&, ScheduledTask*&, bool> {
|
||||
bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); }
|
||||
};
|
||||
|
||||
class Dispatcher
|
||||
{
|
||||
public:
|
||||
Dispatcher() { }
|
||||
|
||||
/// Cleanup scheduled events
|
||||
void cleanup();
|
||||
|
||||
/// Execute scheduled events
|
||||
void poll();
|
||||
|
||||
/// Add an event
|
||||
void addTask(const std::function<void()>& callback, bool pushFront = false);
|
||||
|
||||
/// Schedula an event
|
||||
void scheduleTask(const std::function<void()>& callback, int delay);
|
||||
|
||||
private:
|
||||
std::list<std::function<void()>> m_taskList;
|
||||
std::priority_queue<ScheduledTask*, std::vector<ScheduledTask*>, lessScheduledTask> m_scheduledTaskList;
|
||||
};
|
||||
|
||||
extern Dispatcher g_dispatcher;
|
||||
|
||||
#endif // DISPATCHER_H
|
@ -1,155 +0,0 @@
|
||||
#include "engine.h"
|
||||
#include "platform.h"
|
||||
#include "dispatcher.h"
|
||||
#include <graphics/graphics.h>
|
||||
#include <graphics/fonts.h>
|
||||
#include <graphics/textures.h>
|
||||
#include <ui/uicontainer.h>
|
||||
#include <ui/uiskins.h>
|
||||
#include <script/luainterface.h>
|
||||
#include <net/connection.h>
|
||||
#include <../game.h>
|
||||
#include <../item.h>
|
||||
|
||||
Engine g_engine;
|
||||
|
||||
void Engine::init()
|
||||
{
|
||||
// initialize stuff
|
||||
g_graphics.init();
|
||||
g_fonts.init();
|
||||
g_lua.init();
|
||||
}
|
||||
|
||||
void Engine::terminate()
|
||||
{
|
||||
// destroy root ui
|
||||
UIContainer::getRoot()->destroy();
|
||||
|
||||
// cleanup script stuff
|
||||
g_lua.terminate();
|
||||
|
||||
// poll remaning events
|
||||
g_engine.poll();
|
||||
|
||||
// terminate stuff
|
||||
g_fonts.terminate();
|
||||
g_graphics.terminate();
|
||||
g_dispatcher.cleanup();
|
||||
}
|
||||
|
||||
void Engine::poll()
|
||||
{
|
||||
// poll platform events
|
||||
Platform::poll();
|
||||
|
||||
// poll diaptcher tasks
|
||||
g_dispatcher.poll();
|
||||
|
||||
// poll network events
|
||||
Connection::poll();
|
||||
}
|
||||
|
||||
void Engine::run()
|
||||
{
|
||||
// check if root container has elements
|
||||
const UIContainerPtr& rootContainer = UIContainer::getRoot();
|
||||
if(rootContainer->getChildCount() == 0)
|
||||
logFatal("FATAL ERROR: no ui loaded at all, no reason to continue running");
|
||||
|
||||
std::string fpsText;
|
||||
Size fpsTextSize;
|
||||
FontPtr defaultFont = g_uiSkins.getDefaultFont();
|
||||
|
||||
m_lastFrameTicks = Platform::getTicks();
|
||||
int lastFpsTicks = m_lastFrameTicks;
|
||||
int frameCount = 0;
|
||||
int fps = 0;
|
||||
m_running = true;
|
||||
|
||||
while(!m_stopping) {
|
||||
m_lastFrameTicks = Platform::getTicks();
|
||||
|
||||
poll();
|
||||
|
||||
// render only when visible
|
||||
if(Platform::isWindowVisible()) {
|
||||
// calculate fps
|
||||
if(m_calculateFps) {
|
||||
frameCount++;
|
||||
if(m_lastFrameTicks - lastFpsTicks >= 1000) {
|
||||
lastFpsTicks = m_lastFrameTicks;
|
||||
fps = frameCount;
|
||||
frameCount = 0;
|
||||
|
||||
// update fps text
|
||||
fpsText = make_string("FPS: ", fps);
|
||||
fpsTextSize = defaultFont->calculateTextRectSize(fpsText);
|
||||
}
|
||||
}
|
||||
|
||||
// render
|
||||
g_graphics.beginRender();
|
||||
|
||||
rootContainer->render();
|
||||
|
||||
// todo remove. render map
|
||||
g_game.getMap()->draw(0, 0);
|
||||
|
||||
// todo remove. view items
|
||||
static Item *item = NULL;
|
||||
if(!item) {
|
||||
item = new Item();
|
||||
item->setId(8377);
|
||||
}
|
||||
//item->draw(1, 1, 7);
|
||||
|
||||
// render fps
|
||||
if(m_calculateFps)
|
||||
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
|
||||
|
||||
g_graphics.endRender();
|
||||
|
||||
// swap buffers
|
||||
Platform::swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
m_stopping = false;
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void Engine::stop()
|
||||
{
|
||||
m_stopping = true;
|
||||
}
|
||||
|
||||
void Engine::onClose()
|
||||
{
|
||||
g_lua.getGlobal("onClose")->call("onClose");
|
||||
}
|
||||
|
||||
void Engine::onResize(const Size& size)
|
||||
{
|
||||
g_graphics.resize(size);
|
||||
UIContainer::getRoot()->setSize(size);
|
||||
}
|
||||
|
||||
void Engine::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
UIContainer::getRoot()->onInputEvent(event);
|
||||
|
||||
ProtocolGame *protocol = g_game.getProtocol();
|
||||
if(protocol) {
|
||||
if(event.type == EV_KEY_DOWN) {
|
||||
if(event.keycode == KC_UP)
|
||||
protocol->sendWalkNorth();
|
||||
if(event.keycode == KC_RIGHT)
|
||||
protocol->sendWalkEast();
|
||||
if(event.keycode == KC_DOWN)
|
||||
protocol->sendWalkSouth();
|
||||
if(event.keycode == KC_LEFT)
|
||||
protocol->sendWalkWest();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include <global.h>
|
||||
#include "input.h"
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
Engine() : m_stopping(false),
|
||||
m_running(false),
|
||||
m_calculateFps(false) { }
|
||||
|
||||
void init();
|
||||
void terminate();
|
||||
|
||||
/// Poll events
|
||||
void poll();
|
||||
/// Main loop
|
||||
void run();
|
||||
|
||||
/// Stops main loop
|
||||
void stop();
|
||||
|
||||
/// Change current game state
|
||||
bool isRunning() const { return m_running; }
|
||||
bool isStopping() const { return m_stopping; }
|
||||
|
||||
/// Fired by platform on window close
|
||||
void onClose();
|
||||
/// Fired by platform on window resize
|
||||
void onResize(const Size& size);
|
||||
/// Fired by platform on mouse/keyboard input
|
||||
void onInputEvent(const InputEvent& event);
|
||||
|
||||
/// Enable FPS counter on screen
|
||||
void enableFpsCounter(bool enable = true) { m_calculateFps = enable; };
|
||||
|
||||
/// Return the current ticks on this frame
|
||||
int getCurrentFrameTicks() const { return m_lastFrameTicks; }
|
||||
|
||||
private:
|
||||
bool m_stopping;
|
||||
bool m_running;
|
||||
bool m_calculateFps;
|
||||
|
||||
int m_lastFrameTicks;
|
||||
};
|
||||
|
||||
extern Engine g_engine;
|
||||
|
||||
#endif // ENGINE_H
|
||||
|
@ -0,0 +1,45 @@
|
||||
#include "eventdispatcher.h"
|
||||
#include <core/platform.h>
|
||||
|
||||
EventDispatcher g_dispatcher;
|
||||
|
||||
void EventDispatcher::init()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
void EventDispatcher::terminate()
|
||||
{
|
||||
// clean scheduled events
|
||||
while(!m_scheduledEventList.empty())
|
||||
m_scheduledEventList.pop();
|
||||
}
|
||||
|
||||
void EventDispatcher::poll()
|
||||
{
|
||||
while(!m_eventList.empty()) {
|
||||
m_eventList.front()();
|
||||
m_eventList.pop_front();
|
||||
}
|
||||
|
||||
while(!m_scheduledEventList.empty()) {
|
||||
if(g_platform.getTicks() < m_scheduledEventList.top().ticks)
|
||||
break;
|
||||
SimpleCallback callback = std::move(m_scheduledEventList.top().callback);
|
||||
m_scheduledEventList.pop();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::scheduleEvent(const SimpleCallback& callback, int delay)
|
||||
{
|
||||
m_scheduledEventList.push(ScheduledEvent(g_platform.getTicks() + delay, callback));
|
||||
}
|
||||
|
||||
void EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront)
|
||||
{
|
||||
if(pushFront)
|
||||
m_eventList.push_front(callback);
|
||||
else
|
||||
m_eventList.push_back(callback);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#ifndef EVENTDISPATCHER_H
|
||||
#define EVENTDISPATCHER_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
struct ScheduledEvent {
|
||||
ScheduledEvent(int ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
|
||||
bool operator<(const ScheduledEvent& other) const { return ticks > other.ticks; }
|
||||
int ticks;
|
||||
SimpleCallback callback;
|
||||
};
|
||||
|
||||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
/// Initialize dispatcher
|
||||
void init();
|
||||
|
||||
/// Cleanup scheduled events
|
||||
void terminate();
|
||||
|
||||
/// Execute scheduled events
|
||||
void poll();
|
||||
|
||||
/// Add an event
|
||||
void addEvent(const SimpleCallback& callback, bool pushFront = false);
|
||||
|
||||
/// Schedule an event
|
||||
void scheduleEvent(const SimpleCallback& callback, int delay);
|
||||
|
||||
private:
|
||||
std::list<SimpleCallback> m_eventList;
|
||||
std::priority_queue<ScheduledEvent> m_scheduledEventList;
|
||||
};
|
||||
|
||||
extern EventDispatcher g_dispatcher;
|
||||
|
||||
#endif
|
@ -0,0 +1,73 @@
|
||||
#include "module.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
#include <luascript/luainterface.h>
|
||||
#include "modulemanager.h"
|
||||
|
||||
void Module::discover(const OTMLNodePtr& moduleNode)
|
||||
{
|
||||
m_description = moduleNode->readAt<std::string>("description");
|
||||
m_author = moduleNode->readAt<std::string>("author");
|
||||
m_website = moduleNode->readAt<std::string>("website");
|
||||
m_version = moduleNode->readAt<std::string>("version");
|
||||
|
||||
if(OTMLNodePtr node = moduleNode->get("dependencies")) {
|
||||
for(const OTMLNodePtr& tmp : node->childNodes())
|
||||
m_dependencies.push_back(tmp->value());
|
||||
}
|
||||
|
||||
// set onLoad callback
|
||||
if(OTMLNodePtr node = moduleNode->get("onLoad")) {
|
||||
g_lua.loadFunction(node->read<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
g_lua.useValue();
|
||||
m_loadCallback = g_lua.polymorphicPop<BooleanCallback>();
|
||||
}
|
||||
|
||||
// set onUnload callback
|
||||
if(OTMLNodePtr node = moduleNode->get("onUnload")) {
|
||||
g_lua.loadFunction(node->read<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
g_lua.useValue();
|
||||
m_unloadCallback = g_lua.polymorphicPop<SimpleCallback>();
|
||||
}
|
||||
|
||||
// load if autoLoad is set
|
||||
m_autoLoad = moduleNode->readAt<bool>("autoLoad", false);
|
||||
}
|
||||
|
||||
bool Module::load()
|
||||
{
|
||||
for(const std::string& depName : m_dependencies) {
|
||||
ModulePtr dep = g_modules.getModule(depName);
|
||||
if(!dep) {
|
||||
logError("ERROR: failed to load module '",m_name,"': could not find module dependency '",depName,"'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!dep->isLoaded()) {
|
||||
if(!dep->load()) {
|
||||
logError("ERROR: failed to load module '",m_name,"': a dependency has failed to load");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(m_loadCallback) {
|
||||
m_loaded = m_loadCallback();
|
||||
if(!m_loaded) {
|
||||
logError("ERROR: failed to load module '",m_name, "': onLoad returned false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
logInfo("Loaded module '", m_name, "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
void Module::unload()
|
||||
{
|
||||
if(m_loaded) {
|
||||
if(m_unloadCallback)
|
||||
m_unloadCallback();
|
||||
m_loaded = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include <otml/otmldeclarations.h>
|
||||
|
||||
class Module;
|
||||
typedef std::shared_ptr<Module> ModulePtr;
|
||||
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
Module(const std::string& name) : m_loaded(false), m_autoLoad(false), m_name(name) { }
|
||||
void discover(const OTMLNodePtr& moduleNode);
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
bool isLoaded() const { return m_loaded; }
|
||||
|
||||
std::string getDescription() const { return m_description; }
|
||||
std::string getName() const { return m_name; }
|
||||
std::string getAuthor() const { return m_author; }
|
||||
std::string getWebsite() const { return m_website; }
|
||||
std::string getVersion() const { return m_version; }
|
||||
bool autoLoad() const { return m_autoLoad; }
|
||||
|
||||
private:
|
||||
bool m_loaded;
|
||||
bool m_autoLoad;
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
std::string m_author;
|
||||
std::string m_website;
|
||||
std::string m_version;
|
||||
BooleanCallback m_loadCallback;
|
||||
SimpleCallback m_unloadCallback;
|
||||
std::list<std::string> m_dependencies;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,58 @@
|
||||
#include "modulemanager.h"
|
||||
#include "resourcemanager.h"
|
||||
#include <otml/otml.h>
|
||||
|
||||
ModuleManager g_modules;
|
||||
|
||||
void ModuleManager::discoverAndLoadModules()
|
||||
{
|
||||
auto moduleDirs = g_resources.listDirectoryFiles("/");
|
||||
for(const std::string& moduleDir : moduleDirs) {
|
||||
auto moduleFiles = g_resources.listDirectoryFiles("/" + moduleDir);
|
||||
for(const std::string& file : moduleFiles) {
|
||||
if(boost::ends_with(file, ".otmod"))
|
||||
discoverModule("/" + moduleDir + "/" + file);
|
||||
}
|
||||
}
|
||||
|
||||
// auto load modules
|
||||
for(const ModulePtr& module : m_modules) {
|
||||
if(!module->isLoaded() && module->autoLoad())
|
||||
module->load();
|
||||
}
|
||||
}
|
||||
|
||||
bool ModuleManager::discoverModule(const std::string& file)
|
||||
{
|
||||
ModulePtr module;
|
||||
try {
|
||||
OTMLDocumentPtr doc = OTMLDocument::parse(file);
|
||||
OTMLNodePtr moduleNode = doc->at("Module");
|
||||
|
||||
std::string name = moduleNode->readAt<std::string>("name");
|
||||
if(getModule(name))
|
||||
throw OTMLException(moduleNode, "a module with the same name is already discovered, did you duplicate module names?");
|
||||
|
||||
module = ModulePtr(new Module(name));
|
||||
module->discover(moduleNode);
|
||||
m_modules.push_back(module);
|
||||
} catch(std::exception& e) {
|
||||
logError("ERROR: failed to load module from '", file, "':\n", e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModuleManager::unloadModules()
|
||||
{
|
||||
for(const ModulePtr& module : m_modules)
|
||||
module->unload();
|
||||
}
|
||||
|
||||
ModulePtr ModuleManager::getModule(const std::string& moduleName)
|
||||
{
|
||||
for(const ModulePtr& module : m_modules)
|
||||
if(module->getName() == moduleName)
|
||||
return module;
|
||||
return nullptr;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef MODULEMANAGER_H
|
||||
#define MODULEMANAGER_H
|
||||
|
||||
#include "module.h"
|
||||
|
||||
class ModuleManager
|
||||
{
|
||||
public:
|
||||
void discoverAndLoadModules();
|
||||
bool discoverModule(const std::string& file);
|
||||
void unloadModules();
|
||||
|
||||
ModulePtr getModule(const std::string& moduleName);
|
||||
|
||||
private:
|
||||
std::vector<ModulePtr> m_modules;
|
||||
};
|
||||
|
||||
extern ModuleManager g_modules;
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
#include "packages.h"
|
||||
|
||||
#include <core/resources.h>
|
||||
#include <script/luainterface.h>
|
||||
|
||||
Packages g_packages;
|
||||
|
||||
void Packages::loadPackages()
|
||||
{
|
||||
std::list<std::string> packages = g_resources.listDirectoryFiles("modules");
|
||||
foreach(const std::string& package, packages) {
|
||||
std::string dir = make_string("modules/", package);
|
||||
g_resources.pushCurrentPath(dir);
|
||||
|
||||
std::list<std::string> packagesFiles = g_resources.listDirectoryFiles();
|
||||
foreach(const std::string& packageFile, packagesFiles) {
|
||||
if(boost::ends_with(packageFile, ".lua")) {
|
||||
g_lua.runScript(packageFile);
|
||||
}
|
||||
}
|
||||
|
||||
g_resources.popCurrentPath();
|
||||
}
|
||||
}
|
||||
|
||||
void Packages::terminate()
|
||||
{
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef PACKAGES_H
|
||||
#define PACKAGES_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
class Packages
|
||||
{
|
||||
public:
|
||||
void loadPackages();
|
||||
void terminate();
|
||||
};
|
||||
|
||||
extern Packages g_packages;
|
||||
|
||||
#endif // MODULES_H
|