mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
merge total remake
This commit is contained in:
8
modules/core/constants.lua
Normal file
8
modules/core/constants.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- AnchorPoint
|
||||
AnchorNone = 0
|
||||
AnchorTop = 1
|
||||
AnchorBottom = 2
|
||||
AnchorLeft = 3
|
||||
AnchorRight = 4
|
||||
AnchorVerticalCenter = 5
|
||||
AnchorHorizontalCenter = 6
|
23
modules/core/core.otmod
Normal file
23
modules/core/core.otmod
Normal file
@@ -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
|
||||
|
92
modules/core/messagebox.lua
Normal file
92
modules/core/messagebox.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
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.create()
|
||||
window.id = "messageBoxWindow"
|
||||
window.title = title
|
||||
window:centerIn("parent")
|
||||
--window:setLocked(true)
|
||||
rootWidget:addChild(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: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
|
||||
|
||||
-- setup messagebox first button
|
||||
local button1 = UIButton.create()
|
||||
button1.id = "messageBoxButton1"
|
||||
button1:addAnchor(AnchorBottom, window.id, AnchorBottom)
|
||||
button1:addAnchor(AnchorRight, window.id, AnchorRight)
|
||||
button1:setMargin(10)
|
||||
button1.width = 64
|
||||
window:addChild(button1)
|
||||
|
||||
if flags == MessageBoxOk then
|
||||
button1.text = "Ok"
|
||||
box.onOk = createEmptyFunction()
|
||||
button1.onClick = function()
|
||||
box.onOk()
|
||||
box:destroy()
|
||||
end
|
||||
elseif flags == MessageBoxCancel then
|
||||
button1.text = "Cancel"
|
||||
box.onCancel = createEmptyFunction()
|
||||
button1.onClick = function()
|
||||
box.onCancel()
|
||||
box:destroy()
|
||||
end
|
||||
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
|
||||
|
5
modules/core/util.lua
Normal file
5
modules/core/util.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
function createEmptyFunction()
|
||||
local emptyFunction = function() end
|
||||
return emptyFunction
|
||||
end
|
||||
|
19
modules/core/widget.lua
Normal file
19
modules/core/widget.lua
Normal file
@@ -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
|
Reference in New Issue
Block a user