Skip to content

Commit

Permalink
Ruler rework, Layer tool removed.
Browse files Browse the repository at this point in the history
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 ae991eb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 83 deletions.
41 changes: 16 additions & 25 deletions interface/wedit/compact/compact.config
Expand Up @@ -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"
},
{
Expand All @@ -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"
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -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"
},
{
Expand All @@ -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"
},
{
Expand All @@ -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"
},
{
Expand All @@ -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"
}
]
Expand Down
20 changes: 20 additions & 0 deletions interface/wedit/compact/coordinates.txt
@@ -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.
93 changes: 42 additions & 51 deletions scripts/weditActions.lua
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
14 changes: 8 additions & 6 deletions scripts/weditController.lua
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit ae991eb

Please sign in to comment.