Permalink
Browse files

Ruler rework, Layer tool removed.

No tools rely on the layer tool anymore, by utilizing the shift key in
tools that previously did.
  • Loading branch information...
Silverfeelin committed Aug 15, 2017
1 parent 6606b69 commit ae991eb8d943da69b144388c57e4d78cac4e07b0
@@ -49,22 +49,13 @@
"position": [25, 47],
"data": "WE_Ruler"
},
{
"baseImage": "/interface/wedit/compact/actions/layer.png",
"hoverImage": "/interface/wedit/compact/actions/layer.png?brightness=30",
"baseImageChecked": "/interface/wedit/compact/actions/layerSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/layerSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [47, 47],
"data": "WE_Layer"
},
{
"baseImage": "/interface/wedit/compact/actions/colorpicker.png",
"hoverImage": "/interface/wedit/compact/actions/colorpicker.png?brightness=30",
"baseImageChecked": "/interface/wedit/compact/actions/colorpickerSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/colorpickerSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [69, 47],
"position": [47, 47],
"data": "WE_ColorPicker"
},
{
@@ -73,7 +64,7 @@
"baseImageChecked": "/interface/wedit/compact/actions/blockpinnerSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/blockpinnerSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [91, 47],
"position": [69, 47],
"data": "WE_BlockPinner"
},
{
@@ -82,9 +73,18 @@
"baseImageChecked": "/interface/wedit/compact/actions/modpinnerSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/modpinnerSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [113, 47],
"position": [91, 47],
"data": "WE_ModPinner"
},
{
"baseImage": "/interface/wedit/compact/actions/dye.png",
"hoverImage": "/interface/wedit/compact/actions/dye.png?brightness=30",
"baseImageChecked": "/interface/wedit/compact/actions/dyeSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/dyeSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [113, 47],
"data": "WE_Dye"
},
{
"baseImage": "/interface/wedit/compact/actions/modifier.png",
"hoverImage": "/interface/wedit/compact/actions/modifier.png?brightness=30",
@@ -157,22 +157,13 @@
"position": [69, 25],
"data": "WE_Replace"
},
{
"baseImage": "/interface/wedit/compact/actions/dye.png",
"hoverImage": "/interface/wedit/compact/actions/dye.png?brightness=30",
"baseImageChecked": "/interface/wedit/compact/actions/dyeSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/dyeSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [91, 25],
"data": "WE_Dye"
},
{
"baseImage": "/interface/wedit/compact/actions/stamp.png",
"hoverImage": "/interface/wedit/compact/actions/stamp.png?brightness=30",
"baseImageChecked": "/interface/wedit/compact/actions/stampSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/stampSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [113, 25],
"position": [91, 25],
"data": "WE_Stamp"
},
{
@@ -181,7 +172,7 @@
"baseImageChecked": "/interface/wedit/compact/actions/schematicmakerSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/schematicmakerSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [135, 25],
"position": [113, 25],
"data": "WE_SchematicMaker"
},
{
@@ -190,7 +181,7 @@
"baseImageChecked": "/interface/wedit/compact/actions/flipSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/flipSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [157, 25],
"position": [135, 25],
"data": "WE_Flip"
},
{
@@ -199,7 +190,7 @@
"baseImageChecked": "/interface/wedit/compact/actions/undoSelected.png",
"hoverImageChecked": "/interface/wedit/compact/actions/undoSelected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [179, 25],
"position": [157, 25],
"data": "WE_Undo"
}
]
@@ -0,0 +1,20 @@
X position:
(3 + i * 22)
i = horizontal index (left to right)
---------------------------------------------------
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 3 | 25 | 47 | 69 | 91 | 113| 135| 157| 179| 201|
---------------------------------------------------
Y position:
(3 + rows * 22 - j * 22)
j = vertical index (top to bottom)
rows = 2
-----------
| 0 | 1 |
| 47 | 25 |
-----------
Body height is 46. Each row needs 22 more pixels vertically and each column 22 pixels horizontally.
View
@@ -86,22 +86,6 @@ function wedit.actions.WE_Select()
end
end
--- Function to set wedit.controller.layer.
function wedit.actions.WE_Layer()
wedit.controller.info("^shadow;^orange;WEdit: Layer Tool")
wedit.controller.info("^shadow;^yellow;Primary Fire: foreground.", {0,-1})
wedit.controller.info("^shadow;^yellow;Alt Fire: background", {0,-2})
wedit.controller.info("^shadow;^yellow;Current Layer: ^red;" .. wedit.controller.layer .. "^yellow;.", {0,-3})
if not wedit.controller.fireLocked and (wedit.controller.primaryFire or wedit.controller.altFire) then
-- Prioritizes LMB over RMB.
wedit.controller.layer = (wedit.controller.primaryFire and "foreground") or (wedit.controller.altFire and "background") or wedit.controller.layer
-- Prevents repeats until mouse buttons no longer held.
wedit.controller.fireLock()
end
end
--- Function to erase all blocks in the current selection.
function wedit.actions.WE_Erase()
wedit.controller.info("^shadow;^orange;WEdit: Eraser")
@@ -607,52 +591,65 @@ function wedit.actions.WE_Mod()
end
end
wedit.ruler = {}
--- Function to draw a line of blocks between two selected points
function wedit.actions.WE_Ruler()
wedit.controller.info("^shadow;^orange;WEdit: Ruler")
-- Line x - 1 reserved.
wedit.controller.info("^shadow;^yellow;Alt Fire: Fill selection.", {0,-2})
wedit.controller.info("^shadow;^yellow;Current Block: ^red;" .. wedit.controller.selectedBlockToString() .. "^yellow;.", {0,-3})
wedit.controller.info("^shadow;^yellow;Current Layer: ^red;" .. wedit.controller.layer .. "^yellow;.", {0,-4})
wedit.controller.info("^shadow;^yellow;Primary Fire: Fill foreground.", {0,-1})
wedit.controller.info("^shadow;^yellow;Alt Fire: Fill background.", {0,-2})
wedit.controller.info("^shadow;^yellow;Shift + Primary Fire: Create line.", {0,-3})
wedit.controller.info("^shadow;^yellow;Shift + Alt Fire: Clear line.", {0,-4})
wedit.controller.info("^shadow;^yellow;Current Block: ^red;" .. wedit.controller.selectedBlockToString() .. "^yellow;.", {0,-5})
local line = wedit.controller.line
local line = wedit.controller.lineSelection
-- Make selection (similar to WE_Select, but doesn't convert the two points to the bottom left and top right corner).
if wedit.controller.lineStage == 0 then
-- Select stage 0: Not selecting.
wedit.controller.info("^shadow;^yellow;Primary Fire: Create selection.", {0,-1})
-- Draw line
if not wedit.ruler.selecting and wedit.controller.shiftHeld and wedit.controller.primaryFire and not wedit.controller.shiftFireLocked then
wedit.controller.shiftFireLock()
if wedit.controller.primaryFire then
-- Start selection; set first point.
wedit.controller.lineStage = 1
line[2] = {}
line[1] = tech.aimPosition()
end
-- Set first point
line[1] = tech.aimPosition()
line[2] = {}
elseif wedit.controller.lineStage == 1 then
wedit.controller.info("^shadow;^yellow;Drag mouse and let go to finish the selection.", {0,-1})
-- Select stage 1: Selection started.
if wedit.controller.primaryFire then
-- Start selecting second point
wedit.ruler.selecting = true
wedit.ruler.bindA = Bind.create("primaryFire", function()
-- Dragging selection; update second point.
line[2] = tech.aimPosition()
-- Round each value down.
line[1][1] = math.floor(line[1][1])
line[2][1] = math.floor(line[2][1])
line[1][2] = math.floor(line[1][2])
line[2][2] = math.floor(line[2][2])
else
-- Selection ended; reset stage to allow next selection.
wedit.controller.lineStage = 0
end, true)
wedit.ruler.bindB = Bind.create("primaryFire=false", function()
wedit.ruler.bindA:unbind()
wedit.ruler.bindA = nil
wedit.ruler.bindB:unbind()
wedit.ruler.bindB = nil
wedit.ruler.selecting = false
end)
end
-- Fill / Clear line
if not wedit.controller.shiftFireLocked and not wedit.ruler.selecting then
if wedit.controller.shiftHeld and wedit.controller.altFire then
-- Clear line
wedit.controller.shiftFireLock()
wedit.controller.lineSelection = {{},{}}
elseif not wedit.controller.shiftHeld then
-- Fill line
local layer = wedit.controller.primaryFire and "foreground" or wedit.controller.altFire and "background" or nil
if layer and wedit.controller.validLine() then
wedit.controller.shiftFireLock()
wedit.line(line[1], line[2], wedit.controller.primaryFire and "foreground" or "background", wedit.controller.selectedBlockToString())
end
end
else
-- Select stage is not valid; reset it.
wedit.controller.lineStage = 0
end
-- Drawing and allowing RMB only works with a valid selection
if line[1] and line[1][1] and line[2] and line[2][1] then
-- Draw information
if wedit.controller.validLine() then
-- Draw boxes around every block in the current selection.
wedit.bresenham(line[1], line[2],
function(x, y)
@@ -665,13 +662,7 @@ function wedit.actions.WE_Ruler()
-- Calculate line length for display
local w, h = math.abs(line[1][1] - line[2][1]) + 1, math.abs(line[1][2] - line[2][2]) + 1
local length = w > h and w or h
wedit.controller.info("^shadow;^yellow;Current Length: ^red;" .. length .. " ^yellow;blocks ^red;(" .. w .. "x" .. h .. ")^yellow;.", {0,-5})
-- RMB : Fill selection.
if not wedit.controller.fireLocked and wedit.controller.altFire then
wedit.controller.fireLock()
wedit.line(line[1], line[2], wedit.controller.layer, wedit.controller.selectedBlockToString())
end
wedit.controller.info("^shadow;^yellow;Current Length: ^red;" .. length .. " ^yellow;blocks ^red;(" .. w .. "x" .. h .. ")^yellow;.", {0,-6})
end
end
@@ -53,9 +53,7 @@ controller.selection = {{},{}}
controller.lineStage = 0
-- Table used to store the current line selection coordinates.
-- [1] Starting point, [2] Ending point.
controller.line = {{},{}}
-- String used to determine what layer tools such as the Eraser, Color Picker, Paint Bucket and Pencil affect.
controller.layer = "foreground"
controller.lineSelection = {{},{}}
-- String used to hold the block used by tools such as the Pencil and Paint Bucket
controller.selectedBlock = "dirt"
-- Table used to store copies of areas prior to commands such as fill.
@@ -106,11 +104,9 @@ end
--- Sets the selected block to the one under the cursor.
-- controller.selectedBlock is set to the returned value.
-- @param[opt=controller.layer] layer Layer to select block from.
-- @param layer Layer to select block from.
-- @return Material name or false (air).
function controller.updateColor(layer)
if type(layer) ~= "string" then layer = controller.layer end
local tile = world.material(tech.aimPosition(), layer)
if tile then
controller.selectedBlock = tile
@@ -128,6 +124,12 @@ function controller.validSelection()
return next(controller.selection[1]) and next(controller.selection[2]) and true or false
end
function controller.validLine()
local line = controller.lineSelection
if not line then return false end
return not not (line[1] and line[1][1] and line[2] and line[2][1])
end
--- Draws rectangle(s) indicating the current selection and paste area.
function controller.showSelection()
-- Draw selections if they have been made.
Oops, something went wrong.

0 comments on commit ae991eb

Please sign in to comment.