Flood fill tool now has hover and flood direction options.
This commit is contained in:
parent
dbbacea7a8
commit
7bdcd2c044
@ -8,6 +8,7 @@ import collections
|
||||
import time
|
||||
from mcedit2.editortools import EditorTool
|
||||
from mcedit2.command import SimplePerformCommand
|
||||
from mcedit2.editortools.select import SelectionCursor
|
||||
from mcedit2.util.showprogress import showProgress
|
||||
from mcedit2.widgets.blockpicker import BlockTypeButton
|
||||
from mcedit2.widgets.layout import Column, Row
|
||||
@ -20,15 +21,49 @@ class FloodFillTool(EditorTool):
|
||||
iconName = "flood_fill"
|
||||
|
||||
def mousePress(self, event):
|
||||
command = FloodFillCommand(self.editorSession, event.blockPosition, self.blockTypeWidget.block, self.indiscriminateCheckBox.isChecked())
|
||||
pos = event.blockPosition
|
||||
if self.hoverCheckbox.isChecked():
|
||||
pos = pos + event.blockFace.vector
|
||||
|
||||
command = FloodFillCommand(self.editorSession,
|
||||
pos,
|
||||
self.blockTypeWidget.block,
|
||||
self.indiscriminateCheckBox.isChecked(),
|
||||
self.getFloodDirs())
|
||||
self.editorSession.pushCommand(command)
|
||||
|
||||
def mouseMove(self, event):
|
||||
self.mouseDrag(event)
|
||||
|
||||
def mouseDrag(self, event):
|
||||
self.cursorNode.point = event.blockPosition
|
||||
self.cursorNode.face = event.blockFace
|
||||
|
||||
def __init__(self, editorSession, *args, **kwargs):
|
||||
super(FloodFillTool, self).__init__(editorSession, *args, **kwargs)
|
||||
|
||||
toolWidget = QtGui.QWidget()
|
||||
self.toolWidget = toolWidget
|
||||
|
||||
self.cursorNode = SelectionCursor()
|
||||
|
||||
self.floodXPosCheckbox = QtGui.QCheckBox(self.tr("X+"), checked=True)
|
||||
self.floodXNegCheckbox = QtGui.QCheckBox(self.tr("X-"), checked=True)
|
||||
self.floodYPosCheckbox = QtGui.QCheckBox(self.tr("Y+"), checked=True)
|
||||
self.floodYNegCheckbox = QtGui.QCheckBox(self.tr("Y-"), checked=True)
|
||||
self.floodZPosCheckbox = QtGui.QCheckBox(self.tr("Z+"), checked=True)
|
||||
self.floodZNegCheckbox = QtGui.QCheckBox(self.tr("Z-"), checked=True)
|
||||
|
||||
floodDirsLayout = Column(Row(
|
||||
self.floodXPosCheckbox,
|
||||
self.floodYPosCheckbox,
|
||||
self.floodZPosCheckbox,
|
||||
), Row(
|
||||
self.floodXNegCheckbox,
|
||||
self.floodYNegCheckbox,
|
||||
self.floodZNegCheckbox,
|
||||
), )
|
||||
|
||||
self.blockTypeWidget = BlockTypeButton()
|
||||
self.blockTypeWidget.block = self.editorSession.worldEditor.blocktypes["stone"]
|
||||
self.blockTypeWidget.editorSession = self.editorSession
|
||||
@ -36,19 +71,30 @@ class FloodFillTool(EditorTool):
|
||||
self.indiscriminateCheckBox = QtGui.QCheckBox("Ignore block meta")
|
||||
self.indiscriminateCheckBox.setChecked(False)
|
||||
|
||||
self.hoverCheckbox = QtGui.QCheckBox("Hover")
|
||||
toolWidget.setLayout(Column(Row(QtGui.QLabel("Block:"),
|
||||
self.blockTypeWidget),
|
||||
self.indiscriminateCheckBox,
|
||||
Row(self.hoverCheckbox, self.indiscriminateCheckBox),
|
||||
floodDirsLayout,
|
||||
None))
|
||||
|
||||
|
||||
def getFloodDirs(self):
|
||||
return {f: c.isChecked() for f, c in
|
||||
((faces.FaceXIncreasing, self.floodXPosCheckbox),
|
||||
(faces.FaceYIncreasing, self.floodYPosCheckbox),
|
||||
(faces.FaceZIncreasing, self.floodZPosCheckbox),
|
||||
(faces.FaceXDecreasing, self.floodXNegCheckbox),
|
||||
(faces.FaceYDecreasing, self.floodYNegCheckbox),
|
||||
(faces.FaceZDecreasing, self.floodZNegCheckbox))}
|
||||
|
||||
|
||||
class FloodFillCommand(SimplePerformCommand):
|
||||
def __init__(self, editorSession, point, blockInfo, indiscriminate):
|
||||
def __init__(self, editorSession, point, blockInfo, indiscriminate, floodDirs):
|
||||
super(FloodFillCommand, self).__init__(editorSession)
|
||||
self.blockInfo = blockInfo
|
||||
self.point = point
|
||||
self.indiscriminate = indiscriminate
|
||||
self.floodDirs = floodDirs
|
||||
|
||||
def perform(self):
|
||||
dim = self.editorSession.currentDimension
|
||||
@ -58,6 +104,7 @@ class FloodFillCommand(SimplePerformCommand):
|
||||
doomedBlockData = dim.getBlockData(*point)
|
||||
checkData = (doomedBlock not in (8, 9, 10, 11)) # always ignore data when replacing water/lava xxx forge fluids?
|
||||
indiscriminate = self.indiscriminate
|
||||
floodDirs = self.floodDirs
|
||||
|
||||
log.info("Flood fill: replacing %s with %s", (doomedBlock, doomedBlockData), self.blockInfo)
|
||||
|
||||
@ -79,6 +126,8 @@ class FloodFillCommand(SimplePerformCommand):
|
||||
|
||||
for (x, y, z) in coords:
|
||||
for face, offsets in faces.faceDirections:
|
||||
if not floodDirs[face]:
|
||||
continue
|
||||
dx, dy, dz = offsets
|
||||
p = (x + dx, y + dy, z + dz)
|
||||
|
||||
|
Reference in New Issue
Block a user