Compare commits

...

3 Commits

Author SHA1 Message Date
Sanjay Bhadra a82eddab75 Merge branch 'master' into rewrite-tevx 2020-05-18 09:29:17 -04:00
Josh Muir d4e72f6336 Merge remote-tracking branch 'origin/master' 2020-05-17 22:28:17 +01:00
Josh Muir a4b9b6d0f5 Make console draggable 2020-05-17 22:28:09 +01:00
2 changed files with 48 additions and 6 deletions

View File

@ -1,3 +1,6 @@
local shared = require("tevgit:core/teverseUI/shared.lua")
local draggableUi = shared.draggableUi
local container = teverse.construct("guiFrame", {
parent = teverse.coreInterface,
size = guiCoord(0.1, 150, 0.4, 200),
@ -9,19 +12,22 @@ local container = teverse.construct("guiFrame", {
visible = false
})
teverse.construct("guiTextBox", {
local top = teverse.construct("guiTextBox", {
parent = container,
size = guiCoord(1, -10, 0, 20),
position = guiCoord(0, 5, 0, 0),
backgroundAlpha = 0.0,
size = guiCoord(1, 0, 0, 20),
position = guiCoord(0, 0, 0, 0),
backgroundAlpha = 0.5,
textSize = 20,
textAlign = "middleLeft",
text = "Console"
-- bit hacky but works for slight indent
text = " Console",
backgroundColour = colour.rgb(112, 112, 112)
})
local logContainer = teverse.construct("guiScrollView", {
parent = container,
size = guiCoord(1, -10, 1, -22),
size = guiCoord(1, -10, 1, -27),
position = guiCoord(0, 5, 0, 20),
backgroundAlpha = 0.0,
canvasSize = guiCoord(1, -1, 10, 0),
@ -29,6 +35,8 @@ local logContainer = teverse.construct("guiScrollView", {
scrollbarRadius = 2
})
draggableUi(container, top)
local lastPos = 0
function addLog (msg, time)
local txt = teverse.construct("guiTextBox", {
@ -68,4 +76,5 @@ else
end
return container

33
core/teverseUI/shared.lua Normal file
View File

@ -0,0 +1,33 @@
function draggableUi (uiToMove, activator)
local mouseIsDown = false
if not uiToMove then
return error("Failed to create draggableUi: No UI provided!")
end
if not activator then
activator = uiToMove
end
local evA = activator:on("mouseLeftDown", function( mousePos )
mouseIsDown = true
local startPos = uiToMove.position:get2D(teverse.input.screenSize)
local offset = teverse.input.mousePosition - startPos
spawn(function ()
while mouseIsDown do
-- Calculate new position relative to the mouse pointer
local mousePos = teverse.input.mousePosition
local targetPos = mousePos - offset
uiToMove.position = guiCoord(0, targetPos.x, 0, targetPos.y)
sleep()
end
end)
end)
local evB = teverse.input:on("mouseLeftUp", function( mousePosition )
mouseIsDown = false
end)
end
return {
draggableUi = draggableUi
}