mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
add a new folder structure redesign organized by packages
This commit is contained in:
11
packages/core/constants.lua
Normal file
11
packages/core/constants.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
rootUI = UI.getRootContainer()
|
||||
|
||||
-- AnchorPoint
|
||||
AnchorNone = 0
|
||||
AnchorTop = 1
|
||||
AnchorBottom = 2
|
||||
AnchorLeft = 3
|
||||
AnchorRight = 4
|
||||
AnchorVerticalCenter = 5
|
||||
AnchorHorizontalCenter = 6
|
||||
|
3
packages/core/core.lua
Normal file
3
packages/core/core.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
require 'constants'
|
||||
require 'util'
|
||||
require 'messagebox'
|
86
packages/core/messagebox.lua
Normal file
86
packages/core/messagebox.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
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
|
||||
|
9
packages/core/package.otml
Normal file
9
packages/core/package.otml
Normal file
@@ -0,0 +1,9 @@
|
||||
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
|
||||
|
5
packages/core/util.lua
Normal file
5
packages/core/util.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
function createEmptyFunction()
|
||||
local emptyFunction = function() end
|
||||
return emptyFunction
|
||||
end
|
||||
|
Reference in New Issue
Block a user