mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
move tooltip and messagebox to modules
This commit is contained in:
@@ -17,7 +17,5 @@ Module
|
||||
require 'widget'
|
||||
require 'ui'
|
||||
require 'gfx'
|
||||
require 'messagebox/messagebox'
|
||||
require 'tooltip/tooltip'
|
||||
return true
|
||||
|
||||
|
@@ -1,82 +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 = UI.loadAndDisplayLocked('/core/messagebox/messagebox.otui')
|
||||
window:setTitle(title)
|
||||
|
||||
local label = window:getChildById('messageBoxLabel')
|
||||
label:setStyle('Label')
|
||||
label:setText(text)
|
||||
label:resizeToText()
|
||||
|
||||
-- set window size based on label size
|
||||
window:setWidth(math.max(label:getWidth() + 48, 120))
|
||||
window:setHeight(label:getHeight() + 64)
|
||||
window:updateParentLayout()
|
||||
|
||||
-- setup messagebox first button
|
||||
local buttonRight = window:getChildById('messageBoxRightButton')
|
||||
|
||||
if flags == MessageBoxOk then
|
||||
buttonRight:setText("Ok")
|
||||
box.onOk = EmptyFunction
|
||||
buttonRight.onClick = function()
|
||||
box.onOk()
|
||||
box:destroy()
|
||||
end
|
||||
window.onEnter = buttonRight.onClick
|
||||
window.onEscape = buttonRight.onClick
|
||||
elseif flags == MessageBoxCancel then
|
||||
buttonRight:setText("Cancel")
|
||||
box.onCancel = EmptyFunction
|
||||
buttonRight.onClick = function()
|
||||
box.onCancel()
|
||||
box:destroy()
|
||||
end
|
||||
window.onEnter = buttonRight.onClick
|
||||
window.onEscape = buttonRight.onClick
|
||||
end
|
||||
|
||||
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,21 +0,0 @@
|
||||
Window
|
||||
id: messageBoxWindow
|
||||
anchors.centerIn: parent
|
||||
height: 80
|
||||
width: 120
|
||||
|
||||
Label
|
||||
id: messageBoxLabel
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
margin.top: 27
|
||||
margin.bottom : 27
|
||||
|
||||
Button
|
||||
id: messageBoxRightButton
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
margin.right: 10
|
||||
margin.bottom: 10
|
||||
width: 64
|
||||
visible: true
|
@@ -1,41 +0,0 @@
|
||||
ToolTip = {}
|
||||
|
||||
-- private variables
|
||||
local currentToolTip
|
||||
|
||||
-- private functions
|
||||
local function moveToolTip(tooltip)
|
||||
local pos = getMouseCursorPos()
|
||||
pos.y = pos.y + 1
|
||||
local xdif = getScreenSize().width - (pos.x + tooltip:getWidth())
|
||||
if xdif < 2 then
|
||||
pos.x = pos.x - tooltip:getWidth() - 3
|
||||
else
|
||||
pos.x = pos.x + 10
|
||||
end
|
||||
tooltip:moveTo(pos)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function ToolTip.display(text)
|
||||
ToolTip.hide()
|
||||
if text then
|
||||
currentToolTip = UI.loadAndDisplay('/core/tooltip/tooltip.otui', UI.root)
|
||||
currentToolTip.onMouseMove = moveToolTip
|
||||
local label = currentToolTip:getChildById('toolTipText')
|
||||
label:setText(text)
|
||||
label:resizeToText()
|
||||
local size = label:getSize()
|
||||
size.width = size.width + 4
|
||||
size.height = size.height + 4
|
||||
currentToolTip:setSize(size)
|
||||
moveToolTip(currentToolTip)
|
||||
end
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
if currentToolTip then
|
||||
currentToolTip:destroy()
|
||||
currentToolTip = nil
|
||||
end
|
||||
end
|
@@ -1,9 +0,0 @@
|
||||
RectPanel
|
||||
background-color: #111111bb
|
||||
size: 200 200
|
||||
id: toolTip
|
||||
focusable: false
|
||||
|
||||
Label
|
||||
id: toolTipText
|
||||
anchors.centerIn: parent
|
Reference in New Issue
Block a user