mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
side panel splitter
This commit is contained in:
@@ -9,7 +9,7 @@ local LabelHeight = 16
|
||||
local MaxHistory = 1000
|
||||
|
||||
-- private variables
|
||||
local terminalWidget
|
||||
local terminalWindow
|
||||
local terminalButton
|
||||
local logLocked = false
|
||||
local commandEnv = newenv()
|
||||
@@ -107,22 +107,36 @@ end
|
||||
|
||||
-- public functions
|
||||
function Terminal.init()
|
||||
terminalWidget = displayUI('terminal.otui')
|
||||
terminalWidget:setVisible(false)
|
||||
terminalWindow = displayUI('terminal.otui')
|
||||
terminalWindow:setVisible(false)
|
||||
|
||||
local poped = false
|
||||
terminalWindow.onDoubleClick = function(self)
|
||||
if poped then
|
||||
self:fill('parent')
|
||||
poped = false
|
||||
else
|
||||
self:breakAnchors()
|
||||
self:resize(g_window.getWidth()/2, g_window.getHeight()/2)
|
||||
self:move(g_window.getWidth()/2, g_window.getHeight()/2)
|
||||
poped = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
|
||||
Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle)
|
||||
|
||||
commandHistory = Settings.getList('terminal-history')
|
||||
|
||||
commandLineEdit = terminalWidget:getChildById('commandLineEdit')
|
||||
commandLineEdit = terminalWindow:getChildById('commandLineEdit')
|
||||
Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit)
|
||||
Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit)
|
||||
Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit)
|
||||
Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit)
|
||||
Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWidget)
|
||||
Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWindow)
|
||||
|
||||
terminalBuffer = terminalWidget:getChildById('terminalBuffer')
|
||||
terminalBuffer = terminalWindow:getChildById('terminalBuffer')
|
||||
g_logger.setOnLog(onLog)
|
||||
g_logger.fireOldMessages()
|
||||
end
|
||||
@@ -135,14 +149,14 @@ function Terminal.terminate()
|
||||
terminalButton = nil
|
||||
commandLineEdit = nil
|
||||
terminalBuffer = nil
|
||||
terminalWidget:destroy()
|
||||
terminalWidget = nil
|
||||
terminalWindow:destroy()
|
||||
terminalWindow = nil
|
||||
commandEnv = nil
|
||||
Terminal = nil
|
||||
end
|
||||
|
||||
function Terminal.toggle()
|
||||
if terminalWidget:isVisible() then
|
||||
if terminalWindow:isVisible() then
|
||||
Terminal.hide()
|
||||
else
|
||||
Terminal.show()
|
||||
@@ -150,13 +164,13 @@ function Terminal.toggle()
|
||||
end
|
||||
|
||||
function Terminal.show()
|
||||
terminalWidget:show()
|
||||
terminalWidget:raise()
|
||||
terminalWidget:focus()
|
||||
terminalWindow:show()
|
||||
terminalWindow:raise()
|
||||
terminalWindow:focus()
|
||||
end
|
||||
|
||||
function Terminal.hide()
|
||||
terminalWidget:hide()
|
||||
terminalWindow:hide()
|
||||
end
|
||||
|
||||
function Terminal.addLine(text, color)
|
||||
|
@@ -1,16 +1,21 @@
|
||||
TerminalLabel < UILabel
|
||||
font: terminus-14px-bold
|
||||
height: 16
|
||||
text-wrap: true
|
||||
text-auto-resize: true
|
||||
|
||||
UIWidget
|
||||
id: terminalWidget
|
||||
UIWindow
|
||||
id: terminalWindow
|
||||
background-color: #000000
|
||||
opacity: 0.85
|
||||
clipping: true
|
||||
anchors.fill: parent
|
||||
|
||||
Panel
|
||||
id: terminalBuffer
|
||||
layout: verticalBox
|
||||
layout:
|
||||
type: verticalBox
|
||||
align-bottom: true
|
||||
focusable: false
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
@@ -35,3 +40,5 @@ UIWidget
|
||||
anchors.right: parent.right
|
||||
margin-left: 5
|
||||
font: terminus-14px-bold
|
||||
|
||||
|
||||
|
@@ -2,8 +2,9 @@ Effects = {}
|
||||
|
||||
function Effects.fadeIn(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 250 end
|
||||
if not time then time = 300 end
|
||||
widget:setOpacity(math.min(elapsed/time, 1))
|
||||
removeEvent(widget.fadeEvent)
|
||||
if elapsed < time then
|
||||
removeEvent(widget.fadeEvent)
|
||||
widget.fadeEvent = scheduleEvent(function()
|
||||
@@ -16,19 +17,20 @@ end
|
||||
|
||||
function Effects.fadeOut(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 250 end
|
||||
if not time then time = 300 end
|
||||
elapsed = math.max((1 - widget:getOpacity()) * time, elapsed)
|
||||
removeEvent(widget.fadeEvent)
|
||||
widget:setOpacity(math.max((time - elapsed)/time, 0))
|
||||
if elapsed < time then
|
||||
removeEvent(widget.fadeEvent)
|
||||
widget.fadeEvent = scheduleEvent(function()
|
||||
Effects.fadeOut(widget, time, elapsed + 30)
|
||||
end, 30)
|
||||
else
|
||||
widget.fadeEvent = nil
|
||||
widget:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
function Effects.cancelFade(widget)
|
||||
removeEvent(widget.fadeEvent)
|
||||
widget.fadeEvent = nil
|
||||
end
|
||||
|
@@ -74,12 +74,12 @@ function ToolTip.display(text)
|
||||
toolTipLabel:show()
|
||||
toolTipLabel:raise()
|
||||
toolTipLabel:enable()
|
||||
Effects.fadeIn(toolTipLabel, 100)
|
||||
moveToolTip(toolTipLabel)
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
|
||||
toolTipLabel:hide()
|
||||
Effects.fadeOut(toolTipLabel, 100)
|
||||
end
|
||||
|
||||
-- UIWidget extensions
|
||||
|
@@ -3,6 +3,7 @@ UISplitter = extends(UIWidget)
|
||||
function UISplitter.create()
|
||||
local splitter = UISplitter.internalCreate()
|
||||
splitter:setFocusable(false)
|
||||
splitter.relativeMargin = 'bottom'
|
||||
return splitter
|
||||
end
|
||||
|
||||
@@ -15,17 +16,22 @@ function UISplitter:onHoverChange(hovered)
|
||||
Mouse.setHorizontalCursor()
|
||||
self.vertical = false
|
||||
end
|
||||
elseif not self:isPressed() then
|
||||
Mouse.restoreCursor()
|
||||
if not self:isPressed() then
|
||||
Effects.fadeIn(self)
|
||||
end
|
||||
else
|
||||
if not self:isPressed() then
|
||||
Mouse.restoreCursor()
|
||||
Effects.fadeOut(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function UISplitter:onMouseMove(mousePos, mouseMoved)
|
||||
if self:isPressed() then
|
||||
--local currentmargin, newmargin, delta
|
||||
if self.vertical then
|
||||
local delta = mousePos.y - self:getY()
|
||||
local currentMargin = self:getMarginBottom()
|
||||
local delta = mousePos.y - self:getY() - self:getHeight()/2
|
||||
local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
|
||||
if newMargin ~= currentMargin then
|
||||
self.newMargin = newMargin
|
||||
@@ -36,7 +42,16 @@ function UISplitter:onMouseMove(mousePos, mouseMoved)
|
||||
end
|
||||
end
|
||||
else
|
||||
--TODO
|
||||
local delta = mousePos.x - self:getX() - self:getWidth()/2
|
||||
local newMargin = self:canUpdateMargin(self:getMarginRight() - delta)
|
||||
if newMargin ~= currentMargin then
|
||||
self.newMargin = newMargin
|
||||
if not self.event or self.event:isExecuted() then
|
||||
self.event = addEvent(function()
|
||||
self:setMarginRight(self.newMargin)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -45,14 +60,14 @@ end
|
||||
function UISplitter:onMouseRelease(mousePos, mouseButton)
|
||||
if not self:isHovered() then
|
||||
Mouse.restoreCursor()
|
||||
Effects.fadeOut(self)
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:onStyleApply(styleName, styleNode)
|
||||
--TODO: relative margins
|
||||
--if styleNode['relative-margin'] then
|
||||
--- self.relativeMargin = styleNode['relative-margin']
|
||||
--end
|
||||
if styleNode['relative-margin'] then
|
||||
self.relativeMargin = styleNode['relative-margin']
|
||||
end
|
||||
end
|
||||
|
||||
function UISplitter:canUpdateMargin(newMargin)
|
||||
|
@@ -29,3 +29,4 @@ Module
|
||||
importStyle 'styles/spinboxes.otui'
|
||||
importStyle 'styles/messageboxes.otui'
|
||||
importStyle 'styles/scrollbars.otui'
|
||||
importStyle 'styles/splitters.otui'
|
||||
|
@@ -17,7 +17,7 @@ Window < UIWindow
|
||||
$disabled:
|
||||
color: #aaaaaa88
|
||||
|
||||
$pressed:
|
||||
$dragging:
|
||||
opacity: 0.8
|
||||
|
||||
MainWindow < Window
|
||||
|
@@ -24,34 +24,13 @@ UIWidget
|
||||
anchors.bottom: gameBottomPanel.top
|
||||
focusable: false
|
||||
|
||||
UISplitter
|
||||
id: mapSplitter
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.bottom: parent.bottom
|
||||
relative-margin: bottom
|
||||
margin-bottom: 172
|
||||
height: 4
|
||||
margin-top: -2
|
||||
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
|
||||
@onGeometryChange: function(self) self:setMarginBottom(math.min(self:getParent():getHeight() - 300, self:getMarginBottom())) end
|
||||
|
||||
GameBottomPanel
|
||||
id: gameBottomPanel
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.top: mapSplitter.top
|
||||
anchors.top: bottomSplitter.top
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
GameSidePanel
|
||||
id: gameRightPanel
|
||||
width: 190
|
||||
layout: verticalBox
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
focusable: false
|
||||
|
||||
GameSidePanel
|
||||
id: gameLeftPanel
|
||||
width: 0
|
||||
@@ -61,6 +40,35 @@ UIWidget
|
||||
anchors.bottom: parent.bottom
|
||||
focusable: false
|
||||
|
||||
GameSidePanel
|
||||
id: gameRightPanel
|
||||
layout: verticalBox
|
||||
anchors.left: rightSplitter.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
focusable: false
|
||||
|
||||
Splitter
|
||||
id: bottomSplitter
|
||||
anchors.left: gameLeftPanel.right
|
||||
anchors.right: gameRightPanel.left
|
||||
anchors.bottom: parent.bottom
|
||||
relative-margin: bottom
|
||||
margin-bottom: 172
|
||||
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
|
||||
@onGeometryChange: function(self) self:setMarginBottom(math.min(self:getParent():getHeight() - 300, self:getMarginBottom())) end
|
||||
|
||||
Splitter
|
||||
id: rightSplitter
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
relative-margin: right
|
||||
margin-right: 190
|
||||
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 150), self:getParent():getWidth() - 300) end
|
||||
@onGeometryChange: function(self) self:setMarginRight(math.min(self:getParent():getWidth() - 300, self:getMarginRight())) end
|
||||
|
||||
UIWidget
|
||||
id: mouseGrabber
|
||||
focusable: false
|
||||
|
@@ -59,6 +59,8 @@ local function createTextMessageLabel(id, parent)
|
||||
label:setTextAlign(AlignCenter)
|
||||
label:setId(id)
|
||||
label:setMarginBottom(2)
|
||||
label:setTextWrap(true)
|
||||
label:setTextAutoResize(true)
|
||||
label:setVisible(false)
|
||||
return label
|
||||
end
|
||||
|
@@ -2,6 +2,7 @@ CenterLabel < GameLabel
|
||||
font: verdana-11px-rounded
|
||||
height: 64
|
||||
text-align: center
|
||||
text-wrap: true
|
||||
anchors.centerIn: parent
|
||||
size: 360 264
|
||||
|
||||
@@ -11,5 +12,4 @@ BottomLabel < GameLabel
|
||||
text-align: center
|
||||
margin-bottom: 2
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
Reference in New Issue
Block a user