Merge pull request from joritochip/master

Drag tool gridlock, improved output, added commands
This commit is contained in:
lnneth 2019-05-24 14:41:22 -04:00 committed by GitHub
commit 4cd58b0248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 168 additions and 202 deletions

View File

@ -1,10 +0,0 @@
return {
echo = {
commands = {"echo", "repeat"}; -- Allows for aliases
arguments = {"textToEcho"};
description = "Echoes the given text back to you in the console - Used as a test command";
execute = function(args)
print(args[1]) --// prints the contents of the first argument
end;
};
}

View File

@ -3,15 +3,12 @@
-- Author(s) joritochip, TheCakeChicken
local consoleController = {}
local themeController = require("tevgit:create/controllers/theme.lua")
local uiController = require("tevgit:create/controllers/ui.lua")
consoleController.outputLines = {}
print("Workshop", engine.workshop)
consoleController.commands = require("tevgit:create/console/commands.lua")
function stringSplit(inputStr, sep)
if sep == nil then
sep = "%s"
@ -23,205 +20,169 @@ function stringSplit(inputStr, sep)
return t
end
local windowObject = uiController.create("guiFrame", engine.workshop.interface, {
name = "outputConsole",
visible = false,
size = guiCoord(0.5, 0, 0.5, 0),
position = guiCoord(0.25, 0, 0.25, 0)
})
function stringCount(inputStr, pat)
if inputStr == nil or pat == nil then return end
return select(2, string.gsub(inputStr, pat, ""))
end
consoleController.consoleObject = windowObject
consoleController.createConsole = function()
local windowObject = uiController.create("guiFrame", engine.workshop.interface, {
name = "outputConsole",
visible = false,
draggable = true,
size = guiCoord(0.5, 0, 0.5, 0),
position = guiCoord(0.25, 0, 0.25, 0)
})
local topbar = uiController.create("guiFrame", windowObject, {
size = guiCoord(1, 0, 0, 25),
name = "topbar"
}, "primary")
consoleController.consoleObject = windowObject
local titleText = uiController.create("guiTextBox", topbar, {
size = guiCoord(0.2, 0, 1, -10),
position = guiCoord(0, 10, 0, 5),
text = "Console",
fontSize = 20,
readOnly = true,
name = "windowTitle"
}, "primary")
local topbar = uiController.create("guiFrame", windowObject, {
size = guiCoord(1, 0, 0, 25),
name = "topbar"
}, "primary")
local closeButton = uiController.create("guiTextBox", topbar, {
backgroundColour = colour:fromRGB(255, 0, 0),
text = "X",
size = guiCoord(0, 25, 0, 25),
align = enums.align.middle,
position = guiCoord(1, -25, 0, 0),
name = "closeButton",
readOnly = true
}, "primary")
local titleText = uiController.create("guiTextBox", topbar, {
size = guiCoord(0.2, 0, 1, -10),
position = guiCoord(0, 10, 0, 5),
text = "Console",
fontSize = 20,
readOnly = true,
name = "windowTitle"
}, "primary")
local scrollView = uiController.create("guiScrollView", windowObject, {
size = guiCoord(1, 0, 1, -50),
position = guiCoord(0, 0, 0, 25),
canvasSize = guiCoord(1, 0, 0, 0)
})
local closeButton = uiController.create("guiTextBox", topbar, {
backgroundColour = colour:fromRGB(255, 0, 0),
text = "X",
size = guiCoord(0, 25, 0, 25),
align = enums.align.middle,
position = guiCoord(1, -25, 0, 0),
name = "closeButton",
readOnly = true
}, "primary")
local entryLabel = uiController.create("guiTextBox", scrollView, {
size = guiCoord(1, -10, 0, 50),
position = guiCoord(0, 0, 0, 0),
name = "entryLabel",
wrap = true,
multiline = true,
readOnly = true,
align = enums.align.topLeft,
fontSize = 20,
textColour = colour(1, 1, 1)
}, "default")
local scrollView = uiController.create("guiScrollView", windowObject, {
size = guiCoord(1, 0, 1, -50),
position = guiCoord(0, 0, 0, 25),
canvasSize = guiCoord(1, 0, 0, 0)
})
local cmdInput = uiController.create("guiFrame", windowObject, {
size = guiCoord(1, 0, 0, 25),
position = guiCoord(0, 0, 1, -25),
name = "cmdInput"
}, "secondary")
local entryLabel = uiController.create("guiTextBox", scrollView, {
size = guiCoord(1, -10, 0, 50),
position = guiCoord(0, 0, 0, 0),
name = "entryLabel",
wrap = true,
multiline = true,
readOnly = true,
align = enums.align.topLeft,
fontSize = 20,
textColour = colour(1, 1, 1)
}, "default")
local cmdDecorText = uiController.create("guiTextBox", cmdInput, {
size = guiCoord(0, 20, 1, 0),
position = guiCoord(0, 5, 0, 0),
readOnly = true,
multiline = false,
text = ">",
align = enums.align.middle,
fontSize = 20,
textColour = colour(1, 1, 1),
name = "cmdDecorText"
}, "secondary")
local cmdInput = uiController.create("guiFrame", windowObject, {
size = guiCoord(1, 0, 0, 25),
position = guiCoord(0, 0, 1, -25),
name = "cmdInput"
}, "secondary")
local cmdInputText = uiController.create("guiTextBox", cmdInput, {
size = guiCoord(1, -30, 1, 0),
position = guiCoord(0, 25, 0, 0),
multiline = false,
text = "Type a command",
align = enums.align.middleLeft,
fontSize = 20,
textColour = colour(1, 1, 1),
name = "cmdInputText"
}, "secondary")
local cmdDecorText = uiController.create("guiTextBox", cmdInput, {
size = guiCoord(0, 20, 1, 0),
position = guiCoord(0, 5, 0, 0),
readOnly = true,
multiline = false,
text = ">",
align = enums.align.middle,
fontSize = 20,
textColour = colour(1, 1, 1),
name = "cmdDecorText"
}, "secondary")
closeButton:mouseLeftPressed(function()
consoleController.consoleObject.visible = false
end)
local cmdInputText = uiController.create("guiTextBox", cmdInput, {
size = guiCoord(1, -30, 1, 0),
position = guiCoord(0, 25, 0, 0),
multiline = false,
text = "Enter a script",
align = enums.align.middleLeft,
fontSize = 20,
textColour = colour(1, 1, 1),
name = "cmdInputText"
}, "secondary")
local cmdBarActive = false
closeButton:mouseLeftPressed(function()
consoleController.consoleObject.visible = false
end)
local commandHistoryIndex = 0
local commandHistory = {}
local cmdBarActive = false
cmdInputText:keyFocused(function()
cmdBarActive = true
if cmdInputText.text == "Type a command" then cmdInputText.text = "" end
end)
local commandHistoryIndex = 0
local commandHistory = {}
cmdInputText:keyUnfocused(function()
cmdBarActive = false
end)
cmdInputText:keyFocused(function()
cmdBarActive = true
if cmdInputText.text == "Enter a script" then cmdInputText.text = "" end
end)
engine.input:keyPressed(function(inputObj)
if inputObj.key == enums.key.f12 then
if inputObj.systemHandled then return end
consoleController.consoleObject.visible = not consoleController.consoleObject.visible
elseif cmdBarActive == true then
if inputObj.key == enums.key["return"] then
if cmdInputText.text ~= "Type a command" and cmdInputText.text ~= "" then
table.insert(commandHistory, cmdInputText.text)
commandHistoryIndex = #commandHistory + 1
print("> "..cmdInputText.text)
local args = stringSplit(cmdInputText.text, " ")
local cmd = args[1]
table.remove(args, 1)
for key, command in next, consoleController.commands do
for _, alias in next, command.commands do
if string.lower(cmd) == string.lower(alias) then
local newArgs = {}
for index, arg in next, args do
if #command.arguments == index then
local concat = arg
for i, toConcat in next, args do
if i > #command.arguments then concat = concat .. " " .. toConcat end
end
table.insert(newArgs, concat)
else
table.remove(args, index)
table.insert(newArgs, arg)
end
end
command.execute(newArgs)
end
end
cmdInputText:keyUnfocused(function()
cmdBarActive = false
end)
engine.input:keyPressed(function(inputObj)
if inputObj.key == enums.key.f12 then
if inputObj.systemHandled then return end
consoleController.consoleObject.visible = not consoleController.consoleObject.visible
elseif cmdBarActive == true then
if inputObj.key == enums.key["return"] then
if cmdInputText.text ~= "Enter a script" and cmdInputText.text ~= "" then
table.insert(commandHistory, cmdInputText.text)
commandHistoryIndex = #commandHistory + 1
print("> "..cmdInputText.text)
engine.workshop:loadString(cmdInputText.text)
cmdInputText.text = ""
end
cmdInputText.text = ""
end
elseif inputObj.key == enums.key.up and #commandHistory > 0 then
if commandHistoryIndex - 1 > 0 then
commandHistoryIndex = commandHistoryIndex - 1
cmdInputText.text = commandHistory[commandHistoryIndex]
end
elseif inputObj.key == enums.key.down and #commandHistory > 0 then
if commandHistoryIndex < #commandHistory + 1 then
commandHistoryIndex = commandHistoryIndex + 1
if commandHistoryIndex > #commandHistory then
cmdInputText.text = ""
else
elseif inputObj.key == enums.key.up and #commandHistory > 0 then
if commandHistoryIndex - 1 > 0 then
commandHistoryIndex = commandHistoryIndex - 1
cmdInputText.text = commandHistory[commandHistoryIndex]
end
elseif inputObj.key == enums.key.down and #commandHistory > 0 then
if commandHistoryIndex < #commandHistory + 1 then
commandHistoryIndex = commandHistoryIndex + 1
if commandHistoryIndex > #commandHistory then
cmdInputText.text = ""
else
cmdInputText.text = commandHistory[commandHistoryIndex]
end
end
end
end
end
end)
end)
engine.debug:output(function(msg, type)
if #consoleController.outputLines > 100 then
table.remove(consoleController.outputLines, 1)
end
table.insert(consoleController.outputLines, {msg, type})
local text = ""
for _,v in pairs (consoleController.outputLines) do
local colour = (v[2] == 1) and "#ff0000" or "#ffffff"
if text ~= "" then
text = string.format("%s\n%s", text, v[1])
else
text = v[1]
engine.debug:output(function(msg, type)
if #consoleController.outputLines > 100 then
table.remove(consoleController.outputLines, 1)
end
end
table.insert(consoleController.outputLines, {msg, type})
local text = ""
entryLabel.text = text
for _,v in pairs (consoleController.outputLines) do
local colour = (v[2] == 1) and "#ff0000" or "#ffffff"
if text ~= "" then
text = string.format("%s\n%s%s", text, colour, v[1])
else
text = string.format("%s%s", colour, v[1])
end
end
local textSize = entryLabel.textSize
entryLabel.size = guiCoord(1, -10, 1, textSize.y)
scrollView.canvasSize = guiCoord(0, 0, 1, textSize.y)
end)
if engine.debug.error then --error event may not exist, future update.
engine.debug:error(function(errorInfo)
--if errorInfo.action ~= "disconnection" then
local errorWarning = uiController.create("guiTextBox", engine.workshop.interface, {
text = "Error Captured (CLICK TO CLOSE)\n - - - - - - \nThread: " .. errorInfo.threadName .. " [" .. errorInfo.thread .. "]\nMessage: ".. errorInfo.message.."\nTraceback:\n"..errorInfo.traceback;
align = enums.align.topLeft;
size = guiCoord(0, 600, 0, 200);
readOnly = true;
position = guiCoord(1, 0, 1, -220);
name = "errorMessage";
fontSize = 14;
guiStyle = enums.guiStyle.rounded;
}, "secondary")
engine.tween:begin(errorWarning, .5, {position=guiCoord(1,-610,1,-220)}, "inOutQuad")
errorWarning:mouseLeftPressed(function ()
errorWarning:destroy()
end)
--end
end)
-- deprecated but it's the only way to do color afaik
entryLabel:setText(text)
local size = stringCount(text, "\n")*20+20
entryLabel.size = guiCoord(1, -10, 0, size)
scrollView.canvasSize = guiCoord(0, 0, 0, size)
end)
end
return consoleController

View File

@ -13,6 +13,7 @@ return function(workshop)
}
controllers.ui.createMainInterface(workshop)
controllers.console.createConsole()
local tools = {
add = require("tevgit:create/tools/add.lua"),

View File

@ -1,7 +1,7 @@
--[[
Copyright 2019 Teverse
@File add.lua
@Author(s) Jay, Ly
@Author(s) Jay, Ly, joritochip
@Updated 5/8/19
--]]
@ -57,7 +57,9 @@ local function onToolActivated(toolId)
newBlock.parent = engine.workspace
end
tool.data.mouseDownEvent = engine.input:mouseLeftPressed(function()
tool.data.mouseDownEvent = engine.input:mouseLeftPressed(function(input)
if input.systemHandled then return end
placeBlock()
local curTime = os.clock()
mouseDown = curTime
@ -69,7 +71,9 @@ local function onToolActivated(toolId)
end
end)
tool.data.mouseUpEvent = engine.input:mouseLeftReleased(function()
tool.data.mouseUpEvent = engine.input:mouseLeftReleased(function(input)
if input.systemHandled then return end
mouseDown = 0
end)

View File

@ -1,7 +1,7 @@
--[[
Copyright 2019 Teverse
@File select.lua
@Author(s) Jay
@Author(s) Jay, joritochip
--]]
-- TODO: Create a UI that allows the user to input a step size
@ -13,18 +13,19 @@ TOOL_DESCRIPTION = "Use this select and move primitives."
local toolsController = require("tevgit:create/controllers/tool.lua")
local selectionController = require("tevgit:create/controllers/select.lua")
-- TODo: move this to a helper module
local roundToMultiple = function(number, multiple)
if multiple == 0 then
return number
end
return ((number % multiple) > multiple/2) and number + multiple - number%multiple or number - number%multiple
end
-- TODO: move this to a helper module
function roundToMultiple(number, multiple)
if multiple == 0 then
return number
end
return ((number % multiple) > multiple/2) and number + multiple - number%multiple or number - number%multiple
end
local function onToolActivated(toolId)
local mouseDown = 0
local applyRot = 0
local gridStep = 1
toolsController.tools[toolId].data.mouseDownEvent = engine.input:mouseLeftPressed(function ( inp )
if not inp.systemHandled and #selectionController.selection > 0 then
@ -41,7 +42,6 @@ local function onToolActivated(toolId)
if mouseDown == currentTime then
--user held mouse down for 0.25 seconds,
--initiate drag
local gridStep = 1
selectionController.selectable = false
@ -115,6 +115,14 @@ local function onToolActivated(toolId)
toolsController.tools[toolId].data.mouseUpEvent = engine.input:mouseLeftReleased(function ( inp )
mouseDown = 0
end)
toolsController.tools[toolId].data.keyPressedEvent = engine.input:keyPressed(function(input)
if input.systemHandled then return end
if input.key == enums.key.r then
gridStep = gridStep == 1 and 0 or 1
end
end)
end
local function onToolDeactviated(toolId)
@ -123,6 +131,8 @@ local function onToolDeactviated(toolId)
toolsController.tools[toolId].data.mouseDownEvent = nil
toolsController.tools[toolId].data.mouseUpEvent:disconnect()
toolsController.tools[toolId].data.mouseUpEvent = nil
toolsController.tools[toolId].data.keyPressedEvent:disconnect()
toolsController.tools[toolId].data.keyPressedEvent = nil
end
return toolsController:register({