mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 15:26:49 +01:00
lua console and some changes
This commit is contained in:
74
modules/console/console.lua
Normal file
74
modules/console/console.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
Console = { }
|
||||
local console
|
||||
local logLocked = false
|
||||
|
||||
function Console.onLog(level, message, time)
|
||||
-- avoid logging while reporting logs (would cause a infinite loop)
|
||||
if not logLocked then
|
||||
logLocked = true
|
||||
|
||||
local color
|
||||
if level == LogDebug then
|
||||
color = '#5555ff'
|
||||
elseif level == LogInfo then
|
||||
color = '#55ff55'
|
||||
elseif level == LogWarning then
|
||||
color = '#ffff00'
|
||||
else
|
||||
color = '#ff0000'
|
||||
end
|
||||
|
||||
Console.addLine(message, color)
|
||||
|
||||
logLocked = false
|
||||
end
|
||||
end
|
||||
|
||||
function Console.addLine(text, color)
|
||||
-- create new label
|
||||
local label = UILabel.create()
|
||||
label:setStyle('ConsoleLabel')
|
||||
label:setText(text)
|
||||
label:setForegroundColor(color)
|
||||
|
||||
console:insertChild(label, -1)
|
||||
end
|
||||
|
||||
function Console.create()
|
||||
console = loadUI("/console/console.otui")
|
||||
rootWidget:addChild(console)
|
||||
console:hide()
|
||||
|
||||
Logger.setOnLog(Console.onLog)
|
||||
Logger.fireOldMessages()
|
||||
end
|
||||
|
||||
function Console.destroy()
|
||||
console:destroy()
|
||||
console = nil
|
||||
end
|
||||
|
||||
function Console.show()
|
||||
console.parent:lockChild(console)
|
||||
console.visible = true
|
||||
end
|
||||
|
||||
function Console.hide()
|
||||
console.parent:unlockChild(console)
|
||||
console.visible = false
|
||||
end
|
||||
|
||||
function Console.executeCommand(command)
|
||||
Console.addLine(">> " .. command, "#ffffff")
|
||||
local func, err = loadstring("return (" .. command .. ")", "@")
|
||||
if func then
|
||||
local ok, ret = pcall(func)
|
||||
if ok then
|
||||
Logger.log(LogDebug, "=> " .. tostring(ret))
|
||||
else
|
||||
Logger.log(LogError, 'command failed: ' .. ret)
|
||||
end
|
||||
else
|
||||
Logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5))
|
||||
end
|
||||
end
|
||||
17
modules/console/console.otmod
Normal file
17
modules/console/console.otmod
Normal file
@@ -0,0 +1,17 @@
|
||||
Module
|
||||
name: console
|
||||
description: Console for executing lua functions
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
dependencies:
|
||||
- core
|
||||
|
||||
onLoad: |
|
||||
require 'console'
|
||||
Console.create()
|
||||
return true
|
||||
|
||||
onUnload: |
|
||||
Console.destroy()
|
||||
35
modules/console/console.otui
Normal file
35
modules/console/console.otui
Normal file
@@ -0,0 +1,35 @@
|
||||
ConsoleLabel < UILabel
|
||||
font: terminus-14px-bold
|
||||
height: 16
|
||||
anchors.bottom: next.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
margin.left: 2
|
||||
|
||||
RectPanel
|
||||
id: consolePanel
|
||||
background-color: #000000
|
||||
opacity: 216
|
||||
anchors.fill: parent
|
||||
|
||||
UILabel
|
||||
size: 18 20
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
margin.left: 2
|
||||
font: terminus-14px-bold
|
||||
text: >>
|
||||
|
||||
UILineEdit
|
||||
id: commandBox
|
||||
height: 20
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
margin.left: 2
|
||||
font: terminus-14px-bold
|
||||
onAction: |
|
||||
function(self)
|
||||
Console.executeCommand(self:getText())
|
||||
self:clearText()
|
||||
end
|
||||
@@ -6,3 +6,11 @@ AnchorLeft = 3
|
||||
AnchorRight = 4
|
||||
AnchorVerticalCenter = 5
|
||||
AnchorHorizontalCenter = 6
|
||||
|
||||
LogDebug = 0
|
||||
LogInfo = 1
|
||||
LogWarning = 2
|
||||
LogError = 3
|
||||
LogFatal = 4
|
||||
|
||||
EmptyFunction = function() end
|
||||
@@ -11,45 +11,48 @@ function MessageBox.create(title, text, flags)
|
||||
|
||||
-- create messagebox window
|
||||
local window = UIWindow.create()
|
||||
window.id = "messageBoxWindow"
|
||||
window.title = title
|
||||
window:setStyle('Window')
|
||||
window:setId("messageBoxWindow")
|
||||
window:setTitle(title)
|
||||
window:centerIn("parent")
|
||||
rootWidget:addChild(window)
|
||||
window:lock()
|
||||
rootWidget:lockChild(window)
|
||||
|
||||
-- create messagebox label
|
||||
local label = UILabel.create()
|
||||
label.id = "messageBoxLabel"
|
||||
label.text = text
|
||||
label:addAnchor(AnchorHorizontalCenter, window.id, AnchorHorizontalCenter)
|
||||
label:addAnchor(AnchorTop, window.id, AnchorTop)
|
||||
label:setStyle('Label')
|
||||
label:setId("messageBoxLabel")
|
||||
label:setText(text)
|
||||
label:addAnchor(AnchorHorizontalCenter, window:getId(), AnchorHorizontalCenter)
|
||||
label:addAnchor(AnchorTop, window:getId(), AnchorTop)
|
||||
label:setMargin(27, 0)
|
||||
label:resizeToText()
|
||||
window:addChild(label)
|
||||
|
||||
-- set window size based on label size
|
||||
window.width = label.width + 60
|
||||
window.height = label.height + 64
|
||||
window:setWidth(label:getWidth() + 60)
|
||||
window:setHeight(label:getHeight() + 64)
|
||||
|
||||
-- setup messagebox first button
|
||||
local button1 = UIButton.create()
|
||||
button1.id = "messageBoxButton1"
|
||||
button1:addAnchor(AnchorBottom, window.id, AnchorBottom)
|
||||
button1:addAnchor(AnchorRight, window.id, AnchorRight)
|
||||
button1:setStyle('Button')
|
||||
button1:setId("messageBoxButton1")
|
||||
button1:addAnchor(AnchorBottom, window:getId(), AnchorBottom)
|
||||
button1:addAnchor(AnchorRight, window:getId(), AnchorRight)
|
||||
button1:setMargin(10)
|
||||
button1.width = 64
|
||||
button1:setWidth(64)
|
||||
window:addChild(button1)
|
||||
|
||||
if flags == MessageBoxOk then
|
||||
button1.text = "Ok"
|
||||
box.onOk = createEmptyFunction()
|
||||
button1:setText("Ok")
|
||||
box.onOk = EmptyFunction
|
||||
button1.onClick = function()
|
||||
box.onOk()
|
||||
box:destroy()
|
||||
end
|
||||
elseif flags == MessageBoxCancel then
|
||||
button1.text = "Cancel"
|
||||
box.onCancel = createEmptyFunction()
|
||||
button1:setText("Cancel")
|
||||
box.onCancel = EmptyFunction
|
||||
button1.onClick = function()
|
||||
box.onCancel()
|
||||
box:destroy()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
function createEmptyFunction()
|
||||
local emptyFunction = function() end
|
||||
return emptyFunction
|
||||
end
|
||||
|
||||
function print(...)
|
||||
local msg = ""
|
||||
for i,v in ipairs(arg) do
|
||||
msg = msg .. tostring(v) .. "\t"
|
||||
end
|
||||
Logger.log(LogInfo, msg)
|
||||
end
|
||||
@@ -1,19 +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]
|
||||
self:setMarginTop(params[1])
|
||||
self:setMarginRight(params[1])
|
||||
self:setMarginBottom(params[1])
|
||||
self:setMarginLeft(params[1])
|
||||
elseif #params == 2 then
|
||||
self.marginTop = params[1]
|
||||
self.marginRight = params[2]
|
||||
self.marginBottom = params[1]
|
||||
self.marginLeft = params[2]
|
||||
self:setMarginTop(params[1])
|
||||
self:setMarginRight(params[2])
|
||||
self:setMarginBottom(params[1])
|
||||
self:setMarginLeft(params[2])
|
||||
elseif #params == 4 then
|
||||
self.marginTop = params[1]
|
||||
self.marginRight = params[2]
|
||||
self.marginBottom = params[3]
|
||||
self.marginLeft = params[4]
|
||||
self:setMarginTop(params[1])
|
||||
self:setMarginRight(params[2])
|
||||
self:setMarginBottom(params[3])
|
||||
self:setMarginLeft(params[4])
|
||||
end
|
||||
end
|
||||
@@ -11,6 +11,7 @@ Module
|
||||
importFont('helvetica-12px-bold')
|
||||
importFont('helvetica-12px')
|
||||
importFont('helvetica-14px-bold')
|
||||
importFont('terminus-14px-bold')
|
||||
|
||||
setDefaultFont('helvetica-12px')
|
||||
return true
|
||||
|
||||
9
modules/core_fonts/terminus-14px-bold.otfont
Normal file
9
modules/core_fonts/terminus-14px-bold.otfont
Normal file
@@ -0,0 +1,9 @@
|
||||
Font
|
||||
name: terminus-14px-bold
|
||||
height: 16
|
||||
spacing: 0 0
|
||||
top margin: 2
|
||||
texture: terminus-14px-bold.png
|
||||
glyph size: 16 16
|
||||
fixed glyph width: 8
|
||||
|
||||
BIN
modules/core_fonts/terminus-14px-bold.png
Normal file
BIN
modules/core_fonts/terminus-14px-bold.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
@@ -1,6 +1,6 @@
|
||||
Button < UIButton
|
||||
font: helvetica-11px-bold
|
||||
font-color: #f0ad4dff
|
||||
color: #f0ad4dff
|
||||
size: 106 24
|
||||
border-image:
|
||||
source: /core_ui/images/button.png
|
||||
|
||||
BIN
modules/core_ui/images/empty_rect.png
Normal file
BIN
modules/core_ui/images/empty_rect.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 191 B |
@@ -1,5 +1,8 @@
|
||||
Label < UILabel
|
||||
font: helvetica-12px
|
||||
color: #ffffff
|
||||
|
||||
LargerLabel < Label
|
||||
font: helvetica-12px-bold
|
||||
color: #ffffff
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
LineEdit < UILineEdit
|
||||
font: helvetica-12px
|
||||
size: 86 20
|
||||
text-margin: 3
|
||||
border-image:
|
||||
|
||||
@@ -12,4 +12,4 @@ RoundedPanel < Panel
|
||||
border: 4
|
||||
|
||||
RectPanel < UIWidget
|
||||
image: /core_ui/images/emptyrect.png
|
||||
image: /core_ui/images/empty_rect.png
|
||||
@@ -1,4 +1,5 @@
|
||||
Window < UIWindow
|
||||
font: helvetica-12px-bold
|
||||
size: 200 200
|
||||
head:
|
||||
height: 20
|
||||
@@ -17,5 +18,4 @@ Window < UIWindow
|
||||
border.top: 0
|
||||
|
||||
MainWindow < Window
|
||||
anchors.centerIn: parent
|
||||
onLoad: function(self) self:lock() end
|
||||
anchors.centerIn: parent
|
||||
@@ -3,7 +3,7 @@ GFX = { }
|
||||
function GFX.fadeIn(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 250 end
|
||||
widget.opacity = math.min((255*elapsed)/time, 255)
|
||||
widget:setOpacity(math.min((255*elapsed)/time, 255))
|
||||
if elapsed < time then
|
||||
scheduleEvent(function()
|
||||
GFX.fadeIn(widget, time, elapsed + 30)
|
||||
@@ -14,7 +14,7 @@ end
|
||||
function GFX.fadeOut(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 250 end
|
||||
widget.opacity = (255*(time - elapsed))/time
|
||||
widget:setOpacity((255*(time - elapsed))/time)
|
||||
if elapsed < time then
|
||||
scheduleEvent(function()
|
||||
GFX.fadeOut(widget, time, elapsed + 30)
|
||||
|
||||
@@ -31,8 +31,8 @@ function EnterGame_connectToLoginServer()
|
||||
end
|
||||
|
||||
local enterGameWindow = rootWidget:getChild("enterGameWindow")
|
||||
local account = enterGameWindow:getChild("accountNameLineEdit").text
|
||||
local password = enterGameWindow:getChild("accountPasswordLineEdit").text
|
||||
local account = enterGameWindow:getChild("accountNameLineEdit"):getText()
|
||||
local password = enterGameWindow:getChild("accountPasswordLineEdit"):getText()
|
||||
protocolLogin:login(account, password)
|
||||
|
||||
enterGameWindow:destroy()
|
||||
|
||||
@@ -50,4 +50,4 @@ MainWindow
|
||||
anchors.bottom: parent.bottom
|
||||
margin.bottom: 16
|
||||
margin.right: 16
|
||||
onClick: function(self) GFX.fadeOut(self.parent) end
|
||||
onClick: function(self) GFX.fadeOut(self:getParent()) end
|
||||
|
||||
@@ -58,4 +58,4 @@ MainWindow
|
||||
anchors.top: parent.top
|
||||
margin.top: 191
|
||||
margin.left: 188
|
||||
onClick: function(self) self.parent:destroy() end
|
||||
onClick: function(self) self:getParent():destroy() end
|
||||
|
||||
@@ -113,4 +113,4 @@ MainWindow
|
||||
anchors.bottom: parent.bottom
|
||||
margin.right: 10
|
||||
margin.bottom: 13
|
||||
onClick: function(self) self.parent:destroy() end
|
||||
onClick: function(self) self:getParent():destroy() end
|
||||
|
||||
Reference in New Issue
Block a user