Added 3D Print system integration / switched app to windowed mode

This commit is contained in:
Igor Timofeev 2019-02-14 14:37:44 +03:00
parent b880b8444c
commit 08d696dac2
19 changed files with 341 additions and 196 deletions

View File

@ -0,0 +1,14 @@
local filesystem = require("Filesystem")
local GUI = require("GUI")
local paths = require("Paths")
local system = require("System")
local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...)
local localization = system.getSystemLocalization()
menu:addItem(localization.print3D, not component.isAvailable("printer3d")).onTouch = function()
system.execute(paths.system.applicationPrint3D, icon.path, "-p")
end
system.addUploadToPastebinMenuItem(menu, icon.path)

Binary file not shown.

View File

@ -1,15 +1,16 @@
{ {
exit = "Exit", file = "File",
new = "New", new = "New",
open = "Open", open = "Open",
save = "Save", save = "Save",
saveAs = "Save as",
disabled = "Disabled", disabled = "Disabled",
enabled = "Enabled", enabled = "Enabled",
add = "Add", add = "Add",
remove = "Remove", remove = "Remove",
rotate = "Rotate", rotate = "Rotate",
flip = "Flip", flip = "Flip",
color = "Color", color = "C",
offset = "Offset", offset = "Offset",
scale = "Scale", scale = "Scale",
projectorEnabled = "Enabled", projectorEnabled = "Enabled",
@ -26,7 +27,6 @@
tintColor = "Tint color", tintColor = "Tint color",
texture = "Texture", texture = "Texture",
print = "Print", print = "Print",
modelSettings = "Application",
blockSettings = "Model properties", blockSettings = "Model properties",
projectorSettings = "Projector properties", projectorSettings = "Projector properties",
elementSettings = "Shape properties", elementSettings = "Shape properties",

View File

@ -1,15 +1,16 @@
{ {
exit = "Sortie", file = "File",
new = "Nouveau", new = "New",
open = "Ouvrir", open = "Open",
save = "Sauvegarder", save = "Save",
saveAs = "Save as",
disabled = "Désactivé", disabled = "Désactivé",
enabled = "Activée", enabled = "Activée",
add = "Ajouter", add = "Ajouter",
remove = "Retirer", remove = "Retirer",
rotate = "Tourner", rotate = "Tourner",
flip = "Retourner", flip = "Retourner",
color = "Couleur", color = "C",
offset = "Décalage", offset = "Décalage",
scale = "Échelle", scale = "Échelle",
projectorEnabled = "Activée", projectorEnabled = "Activée",
@ -26,7 +27,6 @@
tintColor = "Couleur de teinte", tintColor = "Couleur de teinte",
texture = "Texture", texture = "Texture",
print = "Print", print = "Print",
modelSettings = "Application",
blockSettings = "Propriétés du modèle", blockSettings = "Propriétés du modèle",
projectorSettings = "Propriétés du projecteur", projectorSettings = "Propriétés du projecteur",
elementSettings = "Propriétés de forme", elementSettings = "Propriétés de forme",

View File

@ -1,15 +1,16 @@
{ {
exit = "Выйти", file = "Файл",
new = "Создать", new = "Новый",
open = "Открыть", open = "Открыть",
save = "Сохранить", save = "Сохранить",
saveAs = "Сохранить как",
disabled = "Пассив", disabled = "Пассив",
enabled = "Актив", enabled = "Актив",
add = "Добавить", add = "Добавить",
remove = "Удалить", remove = "Удалить",
rotate = "Повернуть", rotate = "Повернуть",
flip = "Отразить", flip = "Отразить",
color = "Цвет", color = "Ц",
offset = "Отступ", offset = "Отступ",
scale = "Масштаб", scale = "Масштаб",
projectorEnabled = "Включить", projectorEnabled = "Включить",
@ -26,7 +27,6 @@
tintColor = "Цвет оттенка", tintColor = "Цвет оттенка",
texture = "Текстура", texture = "Текстура",
print = "Напечатать", print = "Напечатать",
modelSettings = "Приложение",
blockSettings = "Параметры блока", blockSettings = "Параметры блока",
projectorSettings = "Параметры проектора", projectorSettings = "Параметры проектора",
elementSettings = "Параметры элемента", elementSettings = "Параметры элемента",

View File

@ -1,15 +1,16 @@
{ {
exit = "Вийти", file = "Фа",
new = "Створити", new = "Новiй",
open = "Відкрити", open = "Відкрити",
save = "Зберегти", save = "Зберегти",
saveAs = "Зберегти как",
disabled = "Пасив", disabled = "Пасив",
enabled = "Актив", enabled = "Актив",
add = "Додати", add = "Додати",
remove = "Видалити", remove = "Видалити",
rotate = "Повернути", rotate = "Повернути",
flip = "Відобразити", flip = "Відобразити",
color = "Колір", color = "Ц",
offset = "Відступ", offset = "Відступ",
scale = "Масштаб", scale = "Масштаб",
projectorEnabled = "Увімкнути", projectorEnabled = "Увімкнути",
@ -26,7 +27,6 @@
tintColor = "Колір відтінку", tintColor = "Колір відтінку",
texture = "Текстура", texture = "Текстура",
print = "Надрукувати", print = "Надрукувати",
modelSettings = "Додаток",
blockSettings = "Параметри блоку", blockSettings = "Параметри блоку",
projectorSettings = "Параметри проектора", projectorSettings = "Параметри проектора",
elementSettings = "Параметри елемента", elementSettings = "Параметри елемента",

View File

@ -4,18 +4,78 @@ local GUI = require("GUI")
local screen = require("Screen") local screen = require("Screen")
local color = require("Color") local color = require("Color")
local system = require("System") local system = require("System")
local paths = require("Paths")
local bigLetters = require("BigLetters") local bigLetters = require("BigLetters")
local filesystem = require("Filesystem") local filesystem = require("Filesystem")
--------------------------------------------------------------------------------
local args, options = system.parseArguments(...) local args, options = system.parseArguments(...)
local proxies = {}
local function updateProxy(name)
proxies[name] = component.list(name)()
if proxies[name] then
proxies[name] = component.proxy(proxies[name])
return true
end
end
local function print(model)
local proxy = proxies.printer3d
proxy.reset()
if model.label then
proxy.setLabel(model.label)
end
if model.tooltip then
proxy.setTooltip(model.tooltip)
end
if model.collidable then
proxy.setCollidable(model.collidable[1], model.collidable[2])
end
if model.lightLevel then
proxy.setLightLevel(model.lightLevel)
end
if model.emitRedstone then
proxy.setRedstoneEmitter(model.emitRedstone)
end
if model.buttonMode then
proxy.setButtonMode(model.buttonMode)
end
for i = 1, #model.shapes do
local shape = model.shapes[i]
proxy.addShape(shape[1], shape[2], shape[3], shape[4], shape[5], shape[6], shape.texture or "empty", shape.state, shape.tint)
end
local success, reason = proxy.commit(1)
if not success then
GUI.alert(localization.failedToPrint .. ": " .. reason)
end
end
-- Just printing without UI
if options.p then
updateProxy("printer3d")
print(filesystem.readTable(args[1]))
return
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local localization = system.getCurrentScriptLocalization() local localization = system.getCurrentScriptLocalization()
local currentLayer = 0 local currentLayer = 0
local model local model
local savePath
local shapeLimit = 24 local shapeLimit = 24
local proxies = {}
local viewPixelWidth, viewPixelHeight = 4, 2 local viewPixelWidth, viewPixelHeight = 4, 2
local colors, hue, hueStep = {}, 0, 360 / shapeLimit local colors, hue, hueStep = {}, 0, 360 / shapeLimit
@ -24,12 +84,12 @@ for i = 1, shapeLimit do
hue = hue + hueStep hue = hue + hueStep
end end
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 92, 32, 0x1E1E1E))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace = GUI.workspace() local toolPanel = window:addChild(GUI.panel(1, 1, 28, 1, 0x2D2D2D))
local toolLayout = window:addChild(GUI.layout(1, 1, toolPanel.width, 1, 1, 1))
local toolPanel = workspace:addChild(GUI.panel(1, 1, 28, workspace.height, 0x2D2D2D))
local toolLayout = workspace:addChild(GUI.layout(1, 1, toolPanel.width, toolPanel.height - 3, 1, 1))
toolLayout:setAlignment(1, 1, GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) toolLayout:setAlignment(1, 1, GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
toolLayout:setMargin(1, 1, 0, 1) toolLayout:setMargin(1, 1, 0, 1)
@ -40,43 +100,78 @@ local function addSeparator(text)
end end
end end
local function newButton(...)
local button = GUI.button(1, 1, toolLayout.width - 2, 1, 0x3C3C3C, 0xA5A5A5, 0xE1E1E1, 0x3C3C3C, ...)
button.colors.disabled.background = 0x3C3C3C
button.colors.disabled.text = 0x5A5A5A
return button
end
local function addButton(...) local function addButton(...)
return toolLayout:addChild(GUI.button(1, 1, toolLayout.width - 2, 1, 0x3C3C3C, 0xA5A5A5, 0xE1E1E1, 0x3C3C3C, ...)) return toolLayout:addChild(newButton(...))
end end
local function addColorSelector(...) local function addObjectsTo(layout, objects)
return toolLayout:addChild(GUI.colorSelector(1, 1, toolLayout.width - 2, 1, ...)) layout:setGridSize(#objects * 2 - 1, 1)
for i = 1, #objects do
layout:setColumnWidth(i * 2 - 1, GUI.SIZE_POLICY_RELATIVE, 1 / #objects)
if i < #objects then
layout:setColumnWidth(i * 2, GUI.SIZE_POLICY_ABSOLUTE, 1)
end
layout:setPosition(i * 2 - 1, 1, layout:addChild(objects[i]))
layout:setFitting(i * 2 - 1, 1, true, false)
end
end end
local printButton = workspace:addChild(GUI.button(1, workspace.height - 2, toolLayout.width, 3, 0x4B4B4B, 0xD2D2D2, 0xE1E1E1, 0x3C3C3C, localization.print)) local function addObjectsWithLayout(objects)
addObjectsTo(toolLayout:addChild(GUI.layout(1, 1, toolLayout.width - 2, 1, 1, 1)), objects)
end
toolLayout:addChild(GUI.object(1, 1, toolLayout.width, 5)).draw = function(object) local function addSwitch(...)
return toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0x787878, ...)).switch
end
local function addInput(...)
return toolLayout:addChild(GUI.input(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x5A5A5A, 0x1E1E1E, 0xE1E1E1, ...))
end
local function addSlider(...)
return toolLayout:addChild(GUI.slider(1, 1, toolLayout.width - 2, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0x787878, ...))
end
local function addComboBox(...)
return toolLayout:addChild(GUI.comboBox(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x3C3C3C, 0x696969))
end
local bigContainer = toolLayout:addChild(GUI.container(1, 1, toolLayout.width, 5))
bigContainer:addChild(GUI.object(1, 1, bigContainer.width, bigContainer.height)).draw = function(object)
local text = tostring(math.floor(currentLayer)) local text = tostring(math.floor(currentLayer))
local width = bigLetters.getTextSize(text) local width = bigLetters.getTextSize(text)
bigLetters.drawText(math.floor(object.x + object.width / 2 - width / 2), object.y, 0xE1E1E1, text) bigLetters.drawText(math.floor(object.x + object.width / 2 - width / 2), object.y, 0xE1E1E1, text)
end end
addSeparator(localization.modelSettings) window.actionButtons:remove()
bigContainer:addChild(window.actionButtons)
window.actionButtons.localY = 1
local newButton = addButton(localization.new) local fileItem = menu:addContextMenuItem(localization.file)
local openButton = addButton(localization.open)
addButton(localization.save).onTouch = function() local newItem = fileItem:addItem(localization.new, false, "^N")
local filesystemDialog = GUI.addFilesystemDialog(workspace, true, 50, math.floor(workspace.height * 0.8), "Save", "Cancel", "File name", "/") local openItem = fileItem:addItem(localization.open, false, "^O")
filesystemDialog:setMode(GUI.IO_MODE_SAVE, GUI.IO_MODE_FILE) fileItem:addSeparator()
filesystemDialog:addExtensionFilter(".3dm") local saveItem = fileItem:addItem(localization.save, true, "^S")
filesystemDialog.onSubmit = function(path) local saveAsItem = fileItem:addItem(localization.saveAs, false, "^⇧S")
filesystem.writeTable(path, model, true) fileItem:addSeparator()
end local printItem = fileItem:addItem(localization.print)
filesystemDialog:show()
end
addButton(localization.exit).onTouch = function() local function updateSavePath(path)
if hologram then savePath = path
hologram.clear() saveItem.disabled = not savePath
end
workspace:stop()
end end
addSeparator(localization.elementSettings) addSeparator(localization.elementSettings)
@ -87,33 +182,32 @@ modelList:setDirection(GUI.DIRECTION_HORIZONTAL)
local disabledListItem = modelList:addItem(localization.disabled) local disabledListItem = modelList:addItem(localization.disabled)
local enabledListItem = modelList:addItem(localization.enabled) local enabledListItem = modelList:addItem(localization.enabled)
local elementComboBox = toolLayout:addChild(GUI.comboBox(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x3C3C3C, 0x696969)) local elementComboBox = addComboBox()
local textureInput = toolLayout:addChild(GUI.input(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x696969, 0x1E1E1E, 0xE1E1E1, "", localization.texture, true)) local textureInput = addInput("", localization.texture, true)
local tintColorSelector = addColorSelector(0x330040, localization.tintColor) local tintColorSelector = toolLayout:addChild(GUI.colorSelector(1, 1, toolLayout.width - 2, 1, 0x330040, localization.tintColor))
local tintSwitch = toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, localization.tintEnabled .. ":", false)).switch local tintSwitch = addSwitch(localization.tintEnabled .. ":", false)
local addShapeButton = addButton(localization.add)
local function checkShapeState(shape) local function checkShapeState(shape)
return modelList.selectedItem == 1 and not shape.state or modelList.selectedItem == 2 and shape.state return modelList.selectedItem == 1 and not shape.state or modelList.selectedItem == 2 and shape.state
end end
local removeShapeButton = addButton(localization.remove) local addShapeButton, removeShapeButton = newButton(localization.add), newButton(localization.remove)
addObjectsWithLayout({addShapeButton, removeShapeButton})
addSeparator(localization.blockSettings) addSeparator(localization.blockSettings)
local labelInput = toolLayout:addChild(GUI.input(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x696969, 0x1E1E1E, 0xE1E1E1, "", localization.label, true)) local labelInput = addInput("", localization.label, true)
local tooltipInput = toolLayout:addChild(GUI.input(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x696969, 0x1E1E1E, 0xE1E1E1, "", localization.tooltip, true)) local tooltipInput = addInput("", localization.tooltip, true)
local buttonModeSwitch = toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, localization.buttonMode .. ":", false)).switch local buttonModeSwitch = addSwitch(localization.buttonMode .. ":", false)
local collisionSwitch = toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, localization.collidable .. ":", true)).switch local collisionSwitch = addSwitch(localization.collidable .. ":", true)
local redstoneSwitch = toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, localization.emitRedstone .. ":", true)).switch local redstoneSwitch = addSwitch(localization.emitRedstone .. ":", true)
local lightLevelSlider = toolLayout:addChild(GUI.slider(1, 1, toolLayout.width - 2, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, 0, 15, 0, false, localization.lightLevel .. ": ", "")) local lightLevelSlider = addSlider(0, 15, 0, false, localization.lightLevel .. ": ", "")
lightLevelSlider.height = 2 lightLevelSlider.height = 2
lightLevelSlider.roundValues = true lightLevelSlider.roundValues = true
local axisComboBox = toolLayout:addChild(GUI.comboBox(1, 1, toolLayout.width - 2, 1, 0x1E1E1E, 0xA5A5A5, 0x3C3C3C, 0x696969)) local axisComboBox = addComboBox()
axisComboBox:addItem(localization.xAxis) axisComboBox:addItem(localization.xAxis)
axisComboBox:addItem(localization.yAxis) axisComboBox:addItem(localization.yAxis)
axisComboBox:addItem(localization.zAxis) axisComboBox:addItem(localization.zAxis)
@ -126,36 +220,21 @@ local function fixShape(shape)
end end
end end
local rotateButton = addButton(localization.rotate) local rotateButton, flipButton = newButton(localization.rotate), newButton(localization.flip)
local flipButton = addButton(localization.flip) addObjectsWithLayout({rotateButton, flipButton})
addSeparator(localization.projectorSettings) addSeparator(localization.projectorSettings)
local function updateProxies() local projectorSwitch = addSwitch(localization.projectorEnabled .. ": ", true)
local function updateProxy(name)
proxies[name] = component.list(name)()
if proxies[name] then
proxies[name] = component.proxy(proxies[name])
return true
end
end
updateProxy("hologram") local projectorScaleSlider = addSlider(0.33, 3, proxies.hologram and proxies.hologram.getScale() or 1, false, localization.scale .. ": ", "")
printButton.disabled = not updateProxy("printer3d")
end
updateProxies()
local projectorSwitch = toolLayout:addChild(GUI.switchAndLabel(1, 1, toolLayout.width - 2, 6, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, localization.projectorEnabled .. ": ", true)).switch
local projectorScaleSlider = toolLayout:addChild(GUI.slider(1, 1, toolLayout.width - 2, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, 0.33, 3, proxies.hologram and proxies.hologram.getScale() or 1, false, localization.scale .. ": ", ""))
projectorScaleSlider.onValueChanged = function() projectorScaleSlider.onValueChanged = function()
if proxies.hologram then if proxies.hologram then
proxies.hologram.setScale(projectorScaleSlider.value) proxies.hologram.setScale(projectorScaleSlider.value)
end end
end end
local projectorOffsetSlider = toolLayout:addChild(GUI.slider(1, 1, toolLayout.width - 2, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xA5A5A5, 0, 1, proxies.hologram and select(2, proxies.hologram.getTranslation()) or 0, false, localization.offset .. ": ", "")) local projectorOffsetSlider = addSlider(0, 1, proxies.hologram and select(2, proxies.hologram.getTranslation()) or 0, false, localization.offset .. ": ", "")
projectorOffsetSlider.height = 2 projectorOffsetSlider.height = 2
projectorOffsetSlider.onValueChanged = function() projectorOffsetSlider.onValueChanged = function()
if proxies.hologram then if proxies.hologram then
@ -163,24 +242,39 @@ projectorOffsetSlider.onValueChanged = function()
end end
end end
if proxies.hologram then local hologramWidgetsLayout = toolLayout:addChild(GUI.layout(1, 1, toolLayout.width - 2, 1, 1, 1))
for i = 1, proxies.hologram.maxDepth() == 1 and 1 or 3 do
local selector = addColorSelector(proxies.hologram and proxies.hologram.getPaletteColor(i) or 0x0, localization.color .. " " .. i) local function updateHologramWidgets()
selector.onColorSelected = function() local objects = {}
for i = 1, (proxies.hologram and proxies.hologram.maxDepth() == 1 and 1 or 3) or 3 do
objects[i] = GUI.colorSelector(1, 1, 1, 1, proxies.hologram and proxies.hologram.getPaletteColor(i) or 0x0, localization.color .. i)
objects[i].onColorSelected = function()
if proxies.hologram then if proxies.hologram then
proxies.hologram.setPaletteColor(i, selector.color) proxies.hologram.setPaletteColor(i, objects[i].color)
workspace:draw() workspace:draw()
end end
end end
end end
hologramWidgetsLayout:removeChildren()
addObjectsTo(hologramWidgetsLayout, objects)
end end
local function updateProxies()
updateProxy("hologram")
updateHologramWidgets()
printItem.disabled = not updateProxy("printer3d")
end
updateProxies()
local function getCurrentShapeIndex() local function getCurrentShapeIndex()
local item = elementComboBox:getItem(elementComboBox.selectedItem) local item = elementComboBox:getItem(elementComboBox.selectedItem)
return item and item.shapeIndex return item and item.shapeIndex
end end
local function updateOnHologram() local function updateHologram()
if proxies.hologram and projectorSwitch.state then if proxies.hologram and projectorSwitch.state then
local initialX = 17 local initialX = 17
local initialY = 2 local initialY = 2
@ -261,30 +355,50 @@ end
local function load(path) local function load(path)
model = filesystem.readTable(path) model = filesystem.readTable(path)
updateSavePath(path)
updateComboBoxFromModel() updateComboBoxFromModel()
updateWidgetsFromModel() updateWidgetsFromModel()
updateAddRemoveButtonsState() updateAddRemoveButtonsState()
end end
openButton.onTouch = function() local function save(path)
local filesystemDialog = GUI.addFilesystemDialog(workspace, true, 50, math.floor(workspace.height * 0.8), "Open", "Cancel", "File name", "/") filesystem.writeTable(path, model, true)
updateSavePath(path)
end
saveItem.onTouch = function()
save(savePath)
end
saveAsItem.onTouch = function()
local filesystemDialog = GUI.addFilesystemDialog(workspace, true, 50, math.floor(window.height * 0.8), "Save", "Cancel", "File name", "/")
filesystemDialog:setMode(GUI.IO_MODE_SAVE, GUI.IO_MODE_FILE)
filesystemDialog:addExtensionFilter(".3dm")
filesystemDialog:expandPath(paths.user.desktop)
filesystemDialog.filesystemTree.selectedItem = paths.user.desktop
filesystemDialog.onSubmit = function(path)
save(path)
end
filesystemDialog:show()
end
openItem.onTouch = function()
local filesystemDialog = GUI.addFilesystemDialog(workspace, true, 50, math.floor(window.height * 0.8), "Open", "Cancel", "File name", "/")
filesystemDialog:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE) filesystemDialog:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE)
filesystemDialog:addExtensionFilter(".3dm") filesystemDialog:addExtensionFilter(".3dm")
filesystemDialog:expandPath(paths.user.desktop)
filesystemDialog.onSubmit = function(path) filesystemDialog.onSubmit = function(path)
load(path) load(path)
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
filesystemDialog:show() filesystemDialog:show()
end end
workspace:addChild(GUI.panel(toolPanel.width + 1, 1, workspace.width - toolPanel.width, toolPanel.height, 0x1E1E1E)) local view = window:addChild(GUI.object(1, 1, 16 * viewPixelWidth, 16 * viewPixelHeight))
local view = workspace:addChild(GUI.object(1, 1, 16 * viewPixelWidth, 16 * viewPixelHeight))
view.localX = math.floor(toolLayout.width + (workspace.width - toolLayout.width) / 2 - view.width / 2)
view.localY = math.floor(workspace.height / 2 - view.height / 2)
view.draw = function() view.draw = function()
local x, y, step = view.x, view.y, true local x, y, step = view.x, view.y, true
for j = 1, 16 do for j = 1, 16 do
@ -327,35 +441,28 @@ end
toolLayout.eventHandler = function(workspace, toolLayout, e1, e2, e3, e4, e5) toolLayout.eventHandler = function(workspace, toolLayout, e1, e2, e3, e4, e5)
if e1 == "scroll" then if e1 == "scroll" then
local cell = toolLayout.cells[1][1] local h, v = toolLayout:getMargin(1, 1)
if e5 > 0 then if e5 > 0 then
if cell.verticalMargin < 1 then if v < 1 then
cell.verticalMargin = cell.verticalMargin + 1 v = v + 1
toolLayout:setMargin(1, 1, h, v)
workspace:draw() workspace:draw()
end end
else else
local child = toolLayout.children[#toolLayout.children] local child = toolLayout.children[#toolLayout.children]
if child.localY + child.height - 1 >= toolLayout.localY + toolLayout.height - 1 then if child.localY + child.height - 1 >= toolLayout.localY + toolLayout.height - 1 then
cell.verticalMargin = cell.verticalMargin - 1 v = v - 1
toolLayout:setMargin(1, 1, h, v)
workspace:draw() workspace:draw()
end end
end end
end end
end end
local touchX, touchY, shapeX, shapeY, shapeZ local shapeX, shapeY, shapeZ
view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5) view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5)
if e1 == "touch" or e1 == "drag" then if e1 == "touch" or e1 == "drag" then
if e5 > 0 then
if e1 == "touch" then
touchX, touchY = e3, e4
elseif touchX then
view.localX, view.localY = view.localX + e3 - touchX, view.localY + e4 - touchY
touchX, touchY = e3, e4
workspace:draw()
end
else
local shapeIndex = getCurrentShapeIndex() local shapeIndex = getCurrentShapeIndex()
if shapeIndex then if shapeIndex then
local shape = model.shapes[shapeIndex] local shape = model.shapes[shapeIndex]
@ -375,10 +482,9 @@ view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5)
workspace:draw() workspace:draw()
end end
end
elseif e1 == "drop" then elseif e1 == "drop" then
touchX, touchY, shapeX, shapeY, shapeZ = nil, nil, nil, nil, nil shapeX, shapeY, shapeZ = nil, nil, nil
updateOnHologram() updateHologram()
elseif e1 == "scroll" then elseif e1 == "scroll" then
local function fix() local function fix()
local shapeIndex = getCurrentShapeIndex() local shapeIndex = getCurrentShapeIndex()
@ -397,7 +503,7 @@ view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5)
fix() fix()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
else else
if currentLayer > 0 then if currentLayer > 0 then
@ -405,12 +511,14 @@ view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5)
fix() fix()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
end end
elseif e1 == "component_added" or e1 == "component_removed" then elseif e1 == "component_added" or e1 == "component_removed" then
updateProxies() updateProxies()
updateOnHologram() workspace:draw()
updateHologram()
end end
end end
@ -430,7 +538,7 @@ rotateButton.onTouch = function()
end end
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
flipButton.onTouch = function() flipButton.onTouch = function()
@ -453,7 +561,7 @@ flipButton.onTouch = function()
end end
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
disabledListItem.onTouch = function() disabledListItem.onTouch = function()
@ -462,7 +570,7 @@ disabledListItem.onTouch = function()
updateAddRemoveButtonsState() updateAddRemoveButtonsState()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
enabledListItem.onTouch = disabledListItem.onTouch enabledListItem.onTouch = disabledListItem.onTouch
@ -479,20 +587,21 @@ end
local function new() local function new()
model = {shapes = {}} model = {shapes = {}}
addShape() addShape()
updateSavePath()
end end
newButton.onTouch = function() newItem.onTouch = function()
new() new()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
addShapeButton.onTouch = function() addShapeButton.onTouch = function()
addShape() addShape()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
removeShapeButton.onTouch = function() removeShapeButton.onTouch = function()
@ -503,52 +612,18 @@ removeShapeButton.onTouch = function()
updateAddRemoveButtonsState() updateAddRemoveButtonsState()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
printButton.onTouch = function() printItem.onTouch = function()
proxies.printer3d.reset() print(model)
if model.label then
proxies.printer3d.setLabel(model.label)
end
if model.tooltip then
proxies.printer3d.setTooltip(model.tooltip)
end
if model.collidable then
proxies.printer3d.setCollidable(model.collidable[1], model.collidable[2])
end
if model.lightLevel then
proxies.printer3d.setLightLevel(model.lightLevel)
end
if model.emitRedstone then
proxies.printer3d.setRedstoneEmitter(model.emitRedstone)
end
if model.buttonMode then
proxies.printer3d.setButtonMode(model.buttonMode)
end
for i = 1, #model.shapes do
local shape = model.shapes[i]
proxies.printer3d.addShape(shape[1], shape[2], shape[3], shape[4], shape[5], shape[6], shape.texture or "empty", shape.state, shape.tint)
end
local success, reason = proxies.printer3d.commit(1)
if not success then
GUI.alert(localization.failedToPrint .. ": " .. reason)
end
end end
elementComboBox.onItemSelected = function() elementComboBox.onItemSelected = function()
updateWidgetsFromModel() updateWidgetsFromModel()
workspace:draw() workspace:draw()
updateOnHologram() updateHologram()
end end
labelInput.onInputFinished = updateModelFromWidgets labelInput.onInputFinished = updateModelFromWidgets
@ -561,14 +636,36 @@ textureInput.onInputFinished = updateModelFromWidgets
tintSwitch.onStateChanged = updateModelFromWidgets tintSwitch.onStateChanged = updateModelFromWidgets
tintColorSelector.onColorSelected = updateModelFromWidgets tintColorSelector.onColorSelected = updateModelFromWidgets
-- Overriding window removing for clearing hologram
local overrideWindowRemove = window.remove
window.remove = function(...)
overrideWindowRemove(...)
if proxies.hologram then
proxies.hologram.clear()
end
end
window.onResize = function(width, height)
window.backgroundPanel.localX = toolPanel.width + 1
window.backgroundPanel.width = width - toolPanel.width
window.backgroundPanel.height = height
toolPanel.height = height
toolLayout.height = height
view.localX = math.floor(1 + toolPanel.width + window.backgroundPanel.width / 2 - view.width / 2)
view.localY = math.floor(1 + height / 2 - view.height / 2)
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
if (options.o or options.open) and args[1] then if args[1] and options.o then
load(args[1]) load(args[1])
else else
new() new()
end end
window:resize(window.width, window.height)
workspace:draw() workspace:draw()
updateOnHologram()
workspace:start()

View File

@ -7,11 +7,6 @@ local system = require("System")
local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...) local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...)
local localization = system.getSystemLocalization() local localization = system.getSystemLocalization()
menu:addItem(localization.uploadToPastebin, not component.isAvailable("internet")).onTouch = function()
system.uploadToPastebin(icon.path)
end
menu:addItem(localization.flashEEPROM, not component.isAvailable("eeprom") or filesystem.size(icon.path) > 4096).onTouch = function() menu:addItem(localization.flashEEPROM, not component.isAvailable("eeprom") or filesystem.size(icon.path) > 4096).onTouch = function()
local container = GUI.addBackgroundContainer(workspace, true, true, localization.flashEEPROM) local container = GUI.addBackgroundContainer(workspace, true, true, localization.flashEEPROM)
container.layout:addChild(GUI.label(1, 1, container.width, 1, 0x969696, localization.flashingEEPROM)):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) container.layout:addChild(GUI.label(1, 1, container.width, 1, 0x969696, localization.flashingEEPROM)):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
@ -26,3 +21,5 @@ end
menu:addItem(localization.launchWithArguments).onTouch = function() menu:addItem(localization.launchWithArguments).onTouch = function()
system.launchWithArguments(workspace, icon.path) system.launchWithArguments(workspace, icon.path)
end end
system.addUploadToPastebinMenuItem(menu, icon.path)

View File

@ -0,0 +1,21 @@
local filesystem = require("Filesystem")
local GUI = require("GUI")
local paths = require("Paths")
local system = require("System")
local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...)
local localization = system.getSystemLocalization()
menu:addItem(localization.setAsWallpaper).onTouch = function()
local userSettings = system.getUserSettings()
userSettings.interfaceWallpaperPath = icon.path
userSettings.interfaceWallpaperEnabled = true
system.updateWallpaper()
workspace:draw()
system.saveUserSettings()
end
system.addUploadToPastebinMenuItem(menu, icon.path)

View File

@ -532,8 +532,6 @@ end
fileItem:addItem("Save as", false, "^⇧S").onTouch = saveAs fileItem:addItem("Save as", false, "^⇧S").onTouch = saveAs
fileItem:addSeparator()
menu:addItem("View").onTouch = function() menu:addItem("View").onTouch = function()
local container = GUI.addBackgroundContainer(workspace, true, true, "View") local container = GUI.addBackgroundContainer(workspace, true, true, "View")

View File

@ -140,6 +140,15 @@
"Applications/Settings.app/Localizations/Ukrainian.lang", "Applications/Settings.app/Localizations/Ukrainian.lang",
"Applications/Settings.app/Localizations/German.lang", "Applications/Settings.app/Localizations/German.lang",
"Applications/Settings.app/Localizations/Italian.lang", "Applications/Settings.app/Localizations/Italian.lang",
-- 3D Print
{ path="Applications/3D Print.app/Main.lua", id=859, shortcut = true },
"Applications/3D Print.app/Icon.pic",
"Applications/3D Print.app/Localizations/English.lang",
"Applications/3D Print.app/Localizations/Russian.lang",
"Applications/3D Print.app/Localizations/French.lang",
"Applications/3D Print.app/Localizations/Ukrainian.lang",
"Applications/3D Print.app/Extensions/.3dm/Icon.pic",
"Applications/3D Print.app/Extensions/.3dm/Context menu.lua",
}, },
optional = { optional = {
{ path="Libraries/JSON.lua", id=103 }, { path="Libraries/JSON.lua", id=103 },
@ -161,14 +170,6 @@
-- Lua interpreter -- Lua interpreter
{ path="Applications/Lua.app/Main.lua", id=1077, shortcut = true }, { path="Applications/Lua.app/Main.lua", id=1077, shortcut = true },
"Applications/Lua.app/Icon.pic", "Applications/Lua.app/Icon.pic",
-- 3D Print
{ path="Applications/3D Print.app/Main.lua", id=859, shortcut = true },
"Applications/3D Print.app/Icon.pic",
"Applications/3D Print.app/Localizations/English.lang",
"Applications/3D Print.app/Localizations/Russian.lang",
"Applications/3D Print.app/Localizations/French.lang",
"Applications/3D Print.app/Localizations/Ukrainian.lang",
"Applications/3D Print.app/Extensions/.3dm/Icon.pic",
-- Weather -- Weather
{ path="Applications/Weather.app/Main.lua", id=240, shortcut = true }, { path="Applications/Weather.app/Main.lua", id=240, shortcut = true },
"Applications/Weather.app/Icon.pic", "Applications/Weather.app/Icon.pic",

View File

@ -21,6 +21,7 @@ paths.system.applicationMineCodeIDE = paths.system.applications .. "MineCode IDE
paths.system.applicationFinder = paths.system.applications .. "Finder.app/Main.lua" paths.system.applicationFinder = paths.system.applications .. "Finder.app/Main.lua"
paths.system.applicationPictureEdit = paths.system.applications .. "Picture Edit.app/Main.lua" paths.system.applicationPictureEdit = paths.system.applications .. "Picture Edit.app/Main.lua"
paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua" paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua"
paths.system.applicationPrint3D = paths.system.applications .. "3D Print.app/Main.lua"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -686,7 +686,7 @@ local function iconOnDoubleClick(icon)
workspace:draw() workspace:draw()
end end
function system.uploadToPastebin(path) local function uploadToPastebin(path)
local container = addBackgroundContainerWithInput("", localization.uploadToPastebin, localization.pasteName) local container = addBackgroundContainerWithInput("", localization.uploadToPastebin, localization.pasteName)
local result, reason local result, reason
@ -727,6 +727,12 @@ function system.uploadToPastebin(path)
workspace:draw() workspace:draw()
end end
function system.addUploadToPastebinMenuItem(menu, path)
menu:addItem(localization.uploadToPastebin, not component.isAvailable("internet")).onTouch = function()
uploadToPastebin(path)
end
end
local function iconOnRightClick(icon, e1, e2, e3, e4) local function iconOnRightClick(icon, e1, e2, e3, e4)
icon.selected = true icon.selected = true
workspace:draw() workspace:draw()
@ -823,7 +829,7 @@ local function iconOnRightClick(icon, e1, e2, e3, e4)
else else
local function addDefault() local function addDefault()
contextMenu:addItem(localization.uploadToPastebin, not component.isAvailable("internet")).onTouch = function() contextMenu:addItem(localization.uploadToPastebin, not component.isAvailable("internet")).onTouch = function()
system.uploadToPastebin(icon.path) uploadToPastebin(icon.path)
end end
contextMenu:addSeparator() contextMenu:addSeparator()
end end
@ -1531,7 +1537,11 @@ end
function system.addWindow(window, dontAddToDock, preserveCoordinates) function system.addWindow(window, dontAddToDock, preserveCoordinates)
-- Чекаем коорды -- Чекаем коорды
if not preserveCoordinates then if not preserveCoordinates then
window.x, window.y = math.floor(desktopWindowsContainer.width / 2 - window.width / 2), math.floor(desktopWindowsContainer.height / 2 - window.height / 2) window.x, window.y =
math.floor(desktopWindowsContainer.width / 2 - window.width / 2),
math.floor(desktopWindowsContainer.height / 2 - window.height / 2)
window.x, window.y = window.x > 0 and window.x or 1, window.y > 0 and window.y or 1
end end
-- Ебурим окно к окнам -- Ебурим окно к окнам

View File

@ -84,6 +84,7 @@
showContainingFolder = "Show containing folder", showContainingFolder = "Show containing folder",
flashEEPROM = "Flash to EEPROM", flashEEPROM = "Flash to EEPROM",
flashingEEPROM = "Flashing in progress. Don't turn off computer...", flashingEEPROM = "Flashing in progress. Don't turn off computer...",
print3D = "Print model",
sortBy = "Sort", sortBy = "Sort",
sortByType = "By type", sortByType = "By type",

View File

@ -84,6 +84,7 @@
showContainingFolder = "Afficher le dossier contenant", showContainingFolder = "Afficher le dossier contenant",
flashEEPROM = "Flasher vers l'EEPROM", flashEEPROM = "Flasher vers l'EEPROM",
flashingEEPROM = "Flash en cours. Ne pas éteindre l'ordinateur...", flashingEEPROM = "Flash en cours. Ne pas éteindre l'ordinateur...",
print3D = "Imprimer le modèle",
sortBy = "Trier", sortBy = "Trier",
sortByType = "Par type", sortByType = "Par type",

View File

@ -84,6 +84,7 @@
showContainingFolder = "Enthaltenden Ordner anzeigen", showContainingFolder = "Enthaltenden Ordner anzeigen",
flashEEPROM = "Flash zu EEPROM", flashEEPROM = "Flash zu EEPROM",
flashingEEPROM = "Blinkt im Gange. Computer nicht ausschalten...", flashingEEPROM = "Blinkt im Gange. Computer nicht ausschalten...",
print3D = "Modell drucken",
sortBy = "Sortieren", sortBy = "Sortieren",
sortByType = "Nach Typ", sortByType = "Nach Typ",

View File

@ -84,6 +84,7 @@
showContainingFolder = "Mostra cartella contenente", showContainingFolder = "Mostra cartella contenente",
flashEEPROM = "Flash su EEPROM", flashEEPROM = "Flash su EEPROM",
flashingEEPROM = "Lampeggiante in corso. Non spegnere il computer...", flashingEEPROM = "Lampeggiante in corso. Non spegnere il computer...",
print3D = "Stampa modello",
sortBy = "Genere", sortBy = "Genere",
sortByType = "Per tipo", sortByType = "Per tipo",

View File

@ -84,6 +84,7 @@
showContainingFolder = "Открыть содержащую папку", showContainingFolder = "Открыть содержащую папку",
flashEEPROM = "Записать на EEPROM", flashEEPROM = "Записать на EEPROM",
flashingEEPROM = "Идет запись на EEPROM. Не отключайте компьютер...", flashingEEPROM = "Идет запись на EEPROM. Не отключайте компьютер...",
print3D = "Распечатать модель",
sortBy = "Упорядочить", sortBy = "Упорядочить",
sortByType = "По типу", sortByType = "По типу",

View File

@ -84,6 +84,7 @@
showContainingFolder = "Показати папку", showContainingFolder = "Показати папку",
flashEEPROM = "Спалах до EEPROM", flashEEPROM = "Спалах до EEPROM",
flashingEEPROM = "Блимає в процесі. Не вимикати комп'ютер...", flashingEEPROM = "Блимає в процесі. Не вимикати комп'ютер...",
print3D = "Роздрукувати модель",
sortBy = "Роду", sortBy = "Роду",
sortByType = "За типом", sortByType = "За типом",