Compare commits

...

2 Commits

Author SHA1 Message Date
Jay 16a239d526 stop reloading workshop when selecting a theme, that's stupid! 2020-01-25 21:18:17 +00:00
Peter-Crawley 201adf1469 theme presets, import and export, better theme gui (#62)
* Remember the theme and allow the user to reset it.

* Fix the title bar

* level with master

* Update settings.lua

* theme presets, import and export, better theme gui
2020-01-25 20:51:54 +00:00
7 changed files with 519 additions and 88 deletions

View File

@ -50,16 +50,24 @@ local function addTab(tabName, tabFrame)
table.insert(tabs, {tabFrame, tabBtn})
end
--local generalPage = ui.create("guiFrame", window.content, {
-- size = guiCoord(0.65, 0, 1, 0),
-- position = guiCoord(0.35, 0, 0, 0)
--}, "background")
local generalPage = ui.create("guiFrame", window.content, {
size = guiCoord(0.65, 0, 1, 0),
position = guiCoord(0.35, 0, 0, 0)
}, "background")
--addTab("General", generalPage)
local syncThread = autoSave.Sync() -- Establish thread
local autoSaveToggle = ui.button(generalPage, autoSave.Enabled and "Disable Auto-Save" or "Enabled Auto-Save", guiCoord(0, 200, 0, 30), guiCoord(0, 10, 0, 10), "secondary")
autoSaveToggle:mouseLeftPressed(function()
autoSave.Enabled = not autoSave.Enabled
autoSaveToggle.label.text = autoSave.Enabled and "Disable Auto-Save" or "Enabled Auto-Save"
end)
addTab("General", generalPage)
local themePage = ui.create("guiScrollView", window.content, {
size = guiCoord(0.65, 0, 1, 0),
position = guiCoord(0.35, 0, 0, 0)
position = guiCoord(0.35, 0, 0, 0),
canvasSize = guiCoord(1,0,0,560)
}, "background")
require("tevgit:workshop/controllers/ui/components/themePreviewer.lua").parent = themePage
@ -79,37 +87,38 @@ if shared.developerMode then
}, "backgroundText")
local createReload = ui.button(developmentPage, "Reload Workshop", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 50))
local createReload = ui.button(developmentPage, "Reload Workshop", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 50))
createReload:mouseLeftPressed(function ()
shared.workshop:reloadCreate()
end)
local shaderReload = ui.button(developmentPage, "Reload Shaders", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 90), "secondary")
local shaderReload = ui.button(developmentPage, "Reload Shaders", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 90), "secondary")
shaderReload:mouseLeftPressed(function ()
shared.workshop:reloadShaders()
end)
local physicsDebugEnabled = false
local physicsAABBs = ui.button(developmentPage, "Enable Physics AABBs", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 130), "secondary")
local physicsAABBs = ui.button(developmentPage, "Enable Physics AABBs", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 130), "secondary")
physicsAABBs:mouseLeftPressed(function ()
physicsDebugEnabled = not physicsDebugEnabled
shared.workshop:setPhysicsDebug(physicsDebugEnabled)
physicsAABBs.label.text = physicsDebugEnabled and "Disable Physics AABBs" or "Enable Physics AABBs"
end)
local runScriptBtn = ui.button(developmentPage, "Run Lua", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 170), "secondary")
local runScriptBtn = ui.button(developmentPage, "Run Lua", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 170), "secondary")
runScriptBtn:mouseLeftPressed(function ()
shared.windows.runLua.visible = not shared.windows.runLua.visible
end)
local printDump = ui.button(developmentPage, "Print Dump", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 210), "secondary")
local printDump = ui.button(developmentPage, "Print Dump", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 210), "secondary")
printDump:mouseLeftPressed(function()
local dump = shared.workshop:apiDump()
print(engine.json:encode(dump))
end)
local physicsEnabled = engine.physics.running
local physicsToggle= ui.button(developmentPage, physicsEnabled and "Stop Simulating Physics" or "Simulate Physics", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 250), "secondary")
local physicsToggle= ui.button(developmentPage, physicsEnabled and "Stop Simulating Physics" or "Simulate Physics", guiCoord(0, 190, 0, 30), guiCoord(0, 15, 0, 250), "secondary")
physicsToggle:mouseLeftPressed(function ()
physicsEnabled = not physicsEnabled
if physicsEnabled then
@ -120,21 +129,6 @@ if shared.developerMode then
physicsToggle.label.text = physicsEnabled and "Stop Simulating Physics" or "Simulate Physics"
end)
-- Auto Save / Sync
local syncThread = autoSave.Sync() -- Establish thread
local autoSaveToggle = ui.button(developmentPage, autoSave.Enabled and "Disable Auto-Save" or "Enabled Auto-Save", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 290), "secondary")
autoSaveToggle:mouseLeftPressed(function()
autoSave.Enabled = not autoSave.Enabled
autoSaveToggle.label.text = autoSave.Enabled and "Disable Auto-Save" or "Enabled Auto-Save"
end)
local resetTheme = ui.button(developmentPage, "Reset Theme (this will restart workshop)", guiCoord(0, 320, 0, 30), guiCoord(0, 15, 0, 330), "secondary")
resetTheme:mouseLeftPressed(function()
shared.workshop:setSettings("themeType", "Default")
shared.workshop:setSettings("customTheme", nil)
shared.workshop:reloadCreate()
end)
addTab("Development", developmentPage)
--local dump = globalWorkshop:apiDump()

View File

@ -1,69 +1,249 @@
-- Returns a frame with the different theme colours
-- Useful for overviewing a theme?
local ui = require("tevgit:workshop/controllers/ui/core/ui.lua")
local shared = require("tevgit:workshop/controllers/shared.lua")
local themer = require("tevgit:workshop/controllers/ui/core/themer.lua")
local colourPicker = require("tevgit:workshop/controllers/ui/components/colourPicker.lua")
ui = require("tevgit:workshop/controllers/ui/core/ui.lua")
shared = require("tevgit:workshop/controllers/shared.lua")
themer = require("tevgit:workshop/controllers/ui/core/themer.lua")
colourPicker = require("tevgit:workshop/controllers/ui/components/colourPicker.lua")
local container = ui.create("guiFrame", shared.workshop.interface, {
size = guiCoord(1, -10, 1, 0),
presets = {
{"default", "Classic (default)"},
{"black", "Tev Dark"},
{"white", "Tev Light"},
{"ow", "ow my eyes"},
{"custom", "Custom"}
}
container = ui.create("guiFrame", shared.workshop.interface, {
size = guiCoord(1, -10, 0, 560),
position = guiCoord(0, 10, 0, 10)
}, "background")
local theme = themer.getTheme()
local y = 0
for _,prop in pairs(themer.types) do
local themeProperty = engine.construct("guiFrame", container, {
size = guiCoord(1, 0, 0, 40),
position = guiCoord(0, 0, 0, y),
backgroundAlpha = 0
})
ui.create("guiTextBox", themeProperty, {
size = guiCoord(1, -10, 0, 16),
position = guiCoord(0, 6, 0, 2),
text = prop,
fontSize = 16,
align = enums.align.middleLeft,
fontFile = "local:OpenSans-SemiBold.ttf"
}, "backgroundText")
presetMenu = ui.create("guiFrame", container, {
position = guiCoord(0, 0, 0, 0),
size = guiCoord(0.5, 0, 0, 140),
borderRadius = 3
}, "primary")
local count = 0
for _,v in pairs(theme[prop]) do if type(v) == "colour" then count = count + 1 end end
importWindow = ui.window(shared.workshop.interface,
"Import Theme",
guiCoord(0, 420, 0, 230), --size
guiCoord(0.5, -210, 0.5, -25), --pos
false, --dockable
true -- hidable
)
importWindow.visible = false
importWindow.xIndex = 1000
local size = 1/count
local i = 0
frame = ui.create("guiFrame", importWindow.content, {
size = guiCoord(1, -20, 1, -60),
position = guiCoord(0, 10, 0, 10),
cropChildren = true,
backgroundAlpha = 0
})
importInput = ui.create("guiTextBox", frame, {
size = guiCoord(1, 0, 1, 0),
position = guiCoord(0, 0, 0, 0),
readOnly = false,
wrap = true,
fontSize = 16,
zIndex = 100
}, "secondary")
for k,v in pairs(theme[prop]) do
if type(v) == "colour" then
local ch,cs,cv = v:getHSV()
local btn = ui.create("guiTextBox", themeProperty, {
size = guiCoord(size, -10, 0, 20),
position = guiCoord(size*i, 5, 0, 20),
text = k,
fontSize = 16,
align = enums.align.middle,
backgroundColour = v,
textColour = cv > 0.5 and colour:black() or colour:white(),
borderRadius = 4,
borderColour = colour:black(),
borderAlpha = 0.3
}, prop)
btn:mouseLeftReleased(function()
print(theme, prop, k)
colourPicker.prompt(theme[prop][k], function(c)
theme[prop][k] = c
themer.setTheme(theme)
end)
end)
i = i + 1
end
end
y = y + 44
function attemptCustom()
import = importInput.text
import = string.gsub(import,"\\","")
themer.setTheme(engine.json:decode(import))
end
importConfirmButton = ui.button(importWindow.content, "Import", guiCoord(0.5, 0, 0, 30), guiCoord(0.25, 0, 1, -40), "primary")
importButton = ui.create("guiButton", container, {
size = guiCoord(0.5, -20, 0, 30),
position = guiCoord(0.5, 10, 0, 40),
borderRadius = 3,
text = "Import Theme",
align = enums.align.middle
},"primaryVariant"):mouseLeftReleased(function()
importWindow.visible = true
end)
exportWindow = ui.window(shared.workshop.interface,
"Export Theme",
guiCoord(0, 420, 0, 230), --size
guiCoord(0.5, -210, 0.5, -25), --pos
false, --dockable
true -- hidable
)
exportWindow.visible = false
eframe = ui.create("guiFrame", exportWindow.content, {
size = guiCoord(1, -20, 1, -20),
position = guiCoord(0, 10, 0, 10),
cropChildren = true,
backgroundAlpha = 0
})
exportInput = ui.create("guiTextBox", eframe, {
size = guiCoord(1, 0, 1, 0),
position = guiCoord(0, 0, 0, 0),
readOnly = false,
wrap = true,
fontSize = 16,
zIndex = 100
}, "secondary")
THISISTHERESETBUTTON = ui.create("guiButton", container, {
size = guiCoord(0.5, -20, 0, 30),
position = guiCoord(0.5, 10, 0, 80),
borderRadius = 3,
text = "Export Theme",
align = enums.align.middle,
visible = false
},"primaryVariant")
THISISTHERESETBUTTON:mouseLeftReleased(function()
exportInput.text = shared.workshop:getSettings("customTheme")
exportWindow.visible = true
end)
customUI = ui.create("guiFrame", container, {
size = guiCoord(1, -10, 2, 0),
position = guiCoord(0, 0, 0, 150),
visible = false
}, "background")
theme = themer.getTheme()
function themeReload()
theme = null
theme = themer.getTheme()
end
function generateEditor()
customUI:destroyAllChildren()
local y = 0
for _,prop in pairs(themer.types) do
themeProperty = engine.construct("guiFrame", customUI, {
size = guiCoord(1, 0, 0, 40),
position = guiCoord(0, 0, 0, y),
backgroundAlpha = 0
})
ui.create("guiTextBox", themeProperty, {
size = guiCoord(1, -10, 0, 16),
position = guiCoord(0, 6, 0, 2),
text = prop,
fontSize = 16,
align = enums.align.middleLeft,
fontFile = "local:OpenSans-SemiBold.ttf"
}, "backgroundText")
count = 0
for _,v in pairs(theme[prop]) do if type(v) == "colour" then count = count + 1 end end
size = 1/count
i = 0
for k,v in pairs(theme[prop]) do
if type(v) == "colour" then
local ch,cs,cv = v:getHSV()
btn = ui.create("guiTextBox", themeProperty, {
size = guiCoord(size, -10, 0, 20),
position = guiCoord(size*i, 5, 0, 20),
text = k,
fontSize = 16,
align = enums.align.middle,
backgroundColour = v,
textColour = cv > 0.5 and colour:black() or colour:white(),
borderRadius = 4,
borderColour = colour:black(),
borderAlpha = 0.3
}, prop)
btn:mouseLeftReleased(function()
colourPicker.prompt(theme[prop][k], function(c)
theme[prop][k] = c
themer.setTheme(theme)
exportInput.text = engine.json:decode(shared.workshop:getSettings("customTheme"))
themeReload()
end)
end)
i = i + 1
end
end
y = y + 44
end
end
function canvasSet(size)
container.parent.canvasSize = size
container.size = size
end
function makePresetMenu()
preset = shared.workshop:getSettings("themeType")
THISISTHERESETBUTTON.visible = false
customUI.visible = false
pcall(canvasSet, guiCoord(1, 0, 1, 0))
if shared.workshop:getSettings("themeType") == "custom" then
THISISTHERESETBUTTON.visible = true
customUI.visible = true
generateEditor()
pcall(canvasSet, guiCoord(1, 0, 0, 560))
end
presetMenu:destroyAllChildren()
local y = 0
for i = 1, #presets do
if preset == presets[i][1] then background = 1 else background = 0 end
preset = ui.create("guiButton", presetMenu, {
size = guiCoord(1, 0, 0, 20),
position = guiCoord(0, 0, 0, y),
backgroundAlpha = background,
text = " " .. presets[i][2],
borderRadius = 3
},"secondary"):mouseLeftReleased(function()
if presets[i][1] == "custom" then
shared.workshop:setSettings("themeType", presets[i][1])
shared.workshop:setSettings("customTheme", engine.json:encodeWithTypes(theme))
themer.setTheme(theme)
themeReload()
else
shared.workshop:setSettings("themeType", presets[i][1])
themer.setThemePreset(require("tevgit:workshop/controllers/ui/themes/" .. presets[i][1] .. ".lua"))
themeReload()
end
makePresetMenu()
end)
y = y + 20
end
end
importConfirmButton:mouseLeftReleased(function()
success, message = pcall(attemptCustom)
if success then
makePresetMenu()
importWindow.visible = false
importInput.text = ""
else
ui.prompt("The given theme is invalid, the theme has not been changed.")
end
end)
resetButton = ui.create("guiButton", container, {
size = guiCoord(0.5, -20, 0, 30),
position = guiCoord(0.5, 10, 0, 0),
borderRadius = 3,
text = "Reset Theme",
align = enums.align.middle
},"secondary"):mouseLeftReleased(function()
shared.workshop:setSettings("themeType", "default")
themer.setThemePreset(require("tevgit:workshop/controllers/ui/themes/default.lua"))
themeReload()
makePresetMenu()
end)
makePresetMenu()
return container

View File

@ -7,12 +7,19 @@ local currentTheme = nil
local registeredGuis = {}
local themeType = shared.workshop:getSettings("themeType")
local customTheme = shared.workshop:getSettings("customTheme")
customTheme = shared.workshop:getSettings("customTheme")
if themeType == "Custom" then
if themeType == "custom" then
currentTheme = engine.json:decode(customTheme)
elseif themeType == "black" then
currentTheme = require("tevgit:workshop/controllers/ui/themes/black.lua")
elseif themeType == "white" then
currentTheme = require("tevgit:workshop/controllers/ui/themes/white.lua")
elseif themeType == "ow" then
currentTheme = require("tevgit:workshop/controllers/ui/themes/ow.lua")
else
currentTheme = require("tevgit:workshop/controllers/ui/themes/default.lua")
shared.workshop:setSettings("themeType", "default")
end
local function themeriseGui(gui)
@ -38,6 +45,7 @@ return {
primary = "primary",
primaryVariant = "primaryVariant",
primaryText = "primaryText",
primaryImage = "primaryImage",
secondary = "secondary",
secondaryVariant = "secondaryVariant",
@ -66,12 +74,33 @@ return {
end
-- Save the theme
shared.workshop:setSettings("themeType", "Custom")
shared.workshop:setSettings("themeType", "custom")
shared.workshop:setSettings("customTheme", engine.json:encodeWithTypes(currentTheme))
end,
resetTheme = function(theme)
-- change the current theme AND re-themerise all guis
currentTheme = require("tevgit:workshop/controllers/ui/themes/default.lua")
for gui,v in pairs(registeredGuis) do
themeriseGui(gui)
end
-- Save the theme
shared.workshop:setSettings("themeType", "default")
shared.workshop:setSettings("customTheme", null)
end,
setThemePreset = function(theme)
-- change the current theme AND re-themerise all guis
currentTheme = theme
for gui,v in pairs(registeredGuis) do
themeriseGui(gui)
end
shared.workshop:setSettings("customTheme", null)
end,
getTheme = function()
return currentTheme
end
}

View File

@ -95,8 +95,8 @@ return {
local titleBar = create("guiFrame", container, {
name = "titleBar",
position = guiCoord(0, 0, 0, -4),
size = guiCoord(1, 0, 0, 25),
position = guiCoord(0, -1, 0, -4),
size = guiCoord(1, 2, 0, 25),
borderRadius = 4,
hoverCursor = "fa:s-hand-pointer"
}, themer.types.primary)

View File

@ -0,0 +1,76 @@
-- Copyright 2020 Teverse.com
return {
primary = {
backgroundColour = colour:fromRGB(8, 8, 8),
textColour = colour:fromRGB(255, 255, 255),
},
primaryVariant = {
backgroundColour = colour:fromRGB(16, 16, 16),
textColour = colour:fromRGB(255, 255, 255),
},
primaryText = {
textColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
primaryImage = {
imageColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
secondary = {
backgroundColour = colour:fromRGB(32, 32, 32),
textColour = colour:fromRGB(255, 255, 255),
},
secondaryVariant = {
backgroundColour = colour:fromRGB(48, 48, 48),
textColour = colour:fromRGB(255, 255, 255),
},
secondaryText = {
textColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
secondaryImage = {
imageColour = colour:fromRGB(255, 255, 25),
backgroundAlpha = 0
},
error = {
backgroundColour = colour:fromRGB(176, 0, 16),
textColour = colour:fromRGB(255, 255, 255),
},
errorText = {
textColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
errorImage = {
imageColour = colour:fromRGB(176, 100, 116),
backgroundAlpha = 0
},
success = {
backgroundColour = colour:fromRGB(0, 176, 16),
textColour = colour:fromRGB(255, 255, 255),
},
successText = {
textColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
successImage = {
imageColour = colour:fromRGB(100, 176, 116),
backgroundAlpha = 0
},
background = {
backgroundColour = colour:fromRGB(64, 64, 64),
textColour = colour:fromRGB(255, 255, 255),
},
backgroundText = {
textColour = colour:fromRGB(255, 255, 255),
backgroundAlpha = 0
},
backgroundImage = {
imageColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
}
}

View File

@ -0,0 +1,76 @@
-- Copyright 2020 Teverse.com
return {
primary = {
backgroundColour = colour:fromRGB(255,0,0),
textColour = colour:fromRGB(255,255,0),
},
primaryVariant = {
backgroundColour = colour:fromRGB(255,255,255),
textColour = colour:fromRGB(0, 255, 0),
},
primaryText = {
textColour = colour:fromRGB(0, 255, 255),
backgroundAlpha = 0
},
primaryImage = {
imageColour = colour:fromRGB(255, 0, 0),
backgroundAlpha = 0
},
secondary = {
backgroundColour = colour:fromRGB(255, 255, 0),
textColour = colour:fromRGB(255, 255, 255),
},
secondaryVariant = {
backgroundColour = colour:fromRGB(0, 255, 0),
textColour = colour:fromRGB(0, 255, 255),
},
secondaryText = {
textColour = colour:fromRGB(255, 0, 0),
backgroundAlpha = 0
},
secondaryImage = {
imageColour = colour:fromRGB(255, 255, 0),
backgroundAlpha = 0
},
error = {
backgroundColour = colour:fromRGB(255,255,255),
textColour = colour:fromRGB(0, 255, 0),
},
errorText = {
textColour = colour:fromRGB(0, 255, 255),
backgroundAlpha = 0
},
errorImage = {
imageColour = colour:fromRGB(255, 0, 0),
backgroundAlpha = 0
},
success = {
backgroundColour = colour:fromRGB(255, 255, 0),
textColour = colour:fromRGB(255, 0, 0),
},
successText = {
textColour = colour:fromRGB(255, 255, 0),
backgroundAlpha = 0
},
successImage = {
imageColour = colour:fromRGB(255,255,255),
backgroundAlpha = 0
},
background = {
backgroundColour = colour:fromRGB(0, 255, 0),
textColour = colour:fromRGB(0, 255, 255),
},
backgroundText = {
textColour = colour:fromRGB(255, 0, 0),
backgroundAlpha = 0
},
backgroundImage = {
imageColour = colour:fromRGB(255,255,255),
backgroundAlpha = 0
}
}

View File

@ -0,0 +1,76 @@
-- Copyright 2020 Teverse.com
return {
primary = {
backgroundColour = colour:fromRGB(255, 255, 255),
textColour = colour:fromRGB(0, 0, 0),
},
primaryVariant = {
backgroundColour = colour:fromRGB(239, 239, 239),
textColour = colour:fromRGB(0, 0, 0),
},
primaryText = {
textColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
primaryImage = {
imageColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
secondary = {
backgroundColour = colour:fromRGB(223, 223, 223),
textColour = colour:fromRGB(0, 0, 0),
},
secondaryVariant = {
backgroundColour = colour:fromRGB(207, 207, 207),
textColour = colour:fromRGB(0, 0, 0),
},
secondaryText = {
textColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
secondaryImage = {
imageColour = colour:fromRGB(0, 0, 25),
backgroundAlpha = 0
},
error = {
backgroundColour = colour:fromRGB(176, 0, 239),
textColour = colour:fromRGB(0, 0, 0),
},
errorText = {
textColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
errorImage = {
imageColour = colour:fromRGB(176, 100, 1239),
backgroundAlpha = 0
},
success = {
backgroundColour = colour:fromRGB(0, 176, 239),
textColour = colour:fromRGB(0, 0, 0),
},
successText = {
textColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
successImage = {
imageColour = colour:fromRGB(100, 176, 1239),
backgroundAlpha = 0
},
background = {
backgroundColour = colour:fromRGB(191, 191, 191),
textColour = colour:fromRGB(0, 0, 0),
},
backgroundText = {
textColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
},
backgroundImage = {
imageColour = colour:fromRGB(0, 0, 0),
backgroundAlpha = 0
}
}