Remove BrushMode.createOptionsWidget; start on Replace mode
This commit is contained in:
parent
7a29eb745e
commit
1b49c25b36
@ -106,10 +106,9 @@ class BrushTool(EditorTool):
|
|||||||
self.brushMode = None
|
self.brushMode = None
|
||||||
self.brushLoader = None
|
self.brushLoader = None
|
||||||
|
|
||||||
self.brushModesByName = {cls.name:cls() for cls in BrushModeClasses}
|
self.brushModesByName = {cls.name:cls(self) for cls in BrushModeClasses}
|
||||||
modes = self.brushModesByName.values()
|
brushModes = self.brushModesByName.values()
|
||||||
modes.sort(key=lambda m: m.name)
|
self.toolWidget.brushModeInput.setModes(brushModes)
|
||||||
self.toolWidget.brushModeInput.setModes(modes)
|
|
||||||
BrushModeSetting.connectAndCall(self.modeSettingChanged)
|
BrushModeSetting.connectAndCall(self.modeSettingChanged)
|
||||||
|
|
||||||
self.cursorWorldScene = None
|
self.cursorWorldScene = None
|
||||||
@ -228,9 +227,8 @@ class BrushTool(EditorTool):
|
|||||||
stack = self.toolWidget.modeOptionsStack
|
stack = self.toolWidget.modeOptionsStack
|
||||||
while stack.count():
|
while stack.count():
|
||||||
stack.removeWidget(stack.widget(0))
|
stack.removeWidget(stack.widget(0))
|
||||||
widget = self.brushMode.createOptionsWidget(self)
|
if self.brushMode.optionsWidget:
|
||||||
if widget:
|
stack.addWidget(self.brushMode.optionsWidget)
|
||||||
stack.addWidget(widget)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brushShape(self):
|
def brushShape(self):
|
||||||
|
@ -15,18 +15,25 @@ from mceditlib.selection import BoundingBox
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BrushMode(QtCore.QObject):
|
class BrushMode(QtCore.QObject):
|
||||||
optionsWidget = None
|
optionsWidget = None
|
||||||
|
|
||||||
def brushBoundingBox(self, center, options={}):
|
def __init__(self, brushTool):
|
||||||
|
super(BrushMode, self).__init__()
|
||||||
|
self.brushTool = brushTool
|
||||||
|
|
||||||
|
def brushBoundingBox(self, center, options=None):
|
||||||
# Return a box of size options['brushSize'] centered around point.
|
# Return a box of size options['brushSize'] centered around point.
|
||||||
# also used to position the preview cursor
|
# also used to position the preview cursor
|
||||||
|
options = options or {}
|
||||||
size = options['brushSize']
|
size = options['brushSize']
|
||||||
x, y, z = size
|
x, y, z = size
|
||||||
origin = Vector(*center) - (Vector(x, y, z) / 2) + Vector((x % 2) * 0.5, (y % 2) * 0.5, (z % 2) * 0.5)
|
origin = Vector(*center) - (Vector(x, y, z) / 2) + Vector((x % 2) * 0.5, (y % 2) * 0.5, (z % 2) * 0.5)
|
||||||
return BoundingBox(origin, size)
|
return BoundingBox(origin, size)
|
||||||
|
|
||||||
|
def brushBoxForPoint(self, point, options):
|
||||||
|
return self.brushBoundingBox(point, options)
|
||||||
|
|
||||||
def applyToPoint(self, command, point):
|
def applyToPoint(self, command, point):
|
||||||
"""
|
"""
|
||||||
Called by BrushCommand for brush modes that can't be implemented using applyToChunk
|
Called by BrushCommand for brush modes that can't be implemented using applyToChunk
|
||||||
@ -55,18 +62,6 @@ class BrushMode(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def createOptionsWidget(self, brushTool):
|
|
||||||
"""
|
|
||||||
Called by BrushTool to create a widget to display for this mode in the brush options panel.
|
|
||||||
|
|
||||||
Shouldn't the widget be created in __init__? When are BrushModes created? On module load,
|
|
||||||
I think.
|
|
||||||
|
|
||||||
:param brushTool:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
return None
|
|
||||||
|
|
||||||
def createCursorLevel(self, brushTool):
|
def createCursorLevel(self, brushTool):
|
||||||
"""
|
"""
|
||||||
Called by BrushTool to create a MaskLevel (or WorldEditorDimension?) to use for the cursor.
|
Called by BrushTool to create a MaskLevel (or WorldEditorDimension?) to use for the cursor.
|
||||||
@ -82,14 +77,10 @@ class BrushMode(QtCore.QObject):
|
|||||||
class Fill(BrushMode):
|
class Fill(BrushMode):
|
||||||
name = "fill"
|
name = "fill"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, brushTool):
|
||||||
super(Fill, self).__init__()
|
super(Fill, self).__init__(brushTool)
|
||||||
self.displayName = self.tr("Fill")
|
self.displayName = self.tr("Fill")
|
||||||
|
|
||||||
def createOptionsWidget(self, brushTool):
|
|
||||||
if self.optionsWidget:
|
|
||||||
return self.optionsWidget
|
|
||||||
|
|
||||||
self.optionsWidget = QtGui.QWidget()
|
self.optionsWidget = QtGui.QWidget()
|
||||||
label = QtGui.QLabel(self.tr("Fill Block:"))
|
label = QtGui.QLabel(self.tr("Fill Block:"))
|
||||||
self.blockTypeButton = BlockTypeButton()
|
self.blockTypeButton = BlockTypeButton()
|
||||||
@ -100,7 +91,6 @@ class Fill(BrushMode):
|
|||||||
self.optionsWidget.setLayout(Column(
|
self.optionsWidget.setLayout(Column(
|
||||||
Row(label, self.blockTypeButton, margin=0),
|
Row(label, self.blockTypeButton, margin=0),
|
||||||
None, margin=0))
|
None, margin=0))
|
||||||
return self.optionsWidget
|
|
||||||
|
|
||||||
def getOptions(self):
|
def getOptions(self):
|
||||||
return {'blockInfo': self.blockTypeButton.block}
|
return {'blockInfo': self.blockTypeButton.block}
|
||||||
@ -112,9 +102,6 @@ class Fill(BrushMode):
|
|||||||
"""
|
"""
|
||||||
return command.editorSession.currentDimension.fillBlocksIter(selection, command.options['blockInfo'])
|
return command.editorSession.currentDimension.fillBlocksIter(selection, command.options['blockInfo'])
|
||||||
|
|
||||||
def brushBoxForPoint(self, point, options):
|
|
||||||
return self.brushBoundingBox(point, options)
|
|
||||||
|
|
||||||
def createCursorLevel(self, brushTool):
|
def createCursorLevel(self, brushTool):
|
||||||
box = self.brushBoxForPoint((0, 0, 0), brushTool.options)
|
box = self.brushBoxForPoint((0, 0, 0), brushTool.options)
|
||||||
selection = brushTool.brushShape.createShapedSelection(box,
|
selection = brushTool.brushShape.createShapedSelection(box,
|
||||||
@ -125,20 +112,24 @@ class Fill(BrushMode):
|
|||||||
return cursorLevel
|
return cursorLevel
|
||||||
|
|
||||||
|
|
||||||
|
class Replace(BrushMode):
|
||||||
|
name = 'replace'
|
||||||
|
|
||||||
|
def __init__(self, brushTool):
|
||||||
|
super(Replace, self).__init__(brushTool)
|
||||||
|
self.displayName = self.tr("Replace")
|
||||||
|
|
||||||
|
def applyToSelection(self, command, selection):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Biome(BrushMode):
|
class Biome(BrushMode):
|
||||||
name = "biome"
|
name = "biome"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, brushTool):
|
||||||
super(Biome, self).__init__(*args, **kwargs)
|
super(Biome, self).__init__(brushTool)
|
||||||
self.displayName = self.tr("Biome")
|
self.displayName = self.tr("Biome")
|
||||||
|
|
||||||
def getOptions(self):
|
|
||||||
return {'biomeID': self.biomeTypeBox.itemData(self.biomeTypeBox.currentIndex())}
|
|
||||||
|
|
||||||
def createOptionsWidget(self, brushTool):
|
|
||||||
if self.optionsWidget:
|
|
||||||
return self.optionsWidget
|
|
||||||
|
|
||||||
self.optionsWidget = QtGui.QWidget()
|
self.optionsWidget = QtGui.QWidget()
|
||||||
label = QtGui.QLabel(self.tr("Fill Biome:"))
|
label = QtGui.QLabel(self.tr("Fill Biome:"))
|
||||||
self.biomeTypeBox = QtGui.QComboBox()
|
self.biomeTypeBox = QtGui.QComboBox()
|
||||||
@ -148,7 +139,9 @@ class Biome(BrushMode):
|
|||||||
|
|
||||||
self.biomeTypeBox.activated.connect(brushTool.updateCursor)
|
self.biomeTypeBox.activated.connect(brushTool.updateCursor)
|
||||||
self.optionsWidget.setLayout(Column(Row(label, self.biomeTypeBox, margin=0), None, margin=0))
|
self.optionsWidget.setLayout(Column(Row(label, self.biomeTypeBox, margin=0), None, margin=0))
|
||||||
return self.optionsWidget
|
|
||||||
|
def getOptions(self):
|
||||||
|
return {'biomeID': self.biomeTypeBox.itemData(self.biomeTypeBox.currentIndex())}
|
||||||
|
|
||||||
def applyToSelection(self, command, selection):
|
def applyToSelection(self, command, selection):
|
||||||
biomeID = command.options['biomeID']
|
biomeID = command.options['biomeID']
|
||||||
@ -202,4 +195,4 @@ class Biome(BrushMode):
|
|||||||
return cursorLevel
|
return cursorLevel
|
||||||
|
|
||||||
|
|
||||||
BrushModeClasses = [Fill, Biome]
|
BrushModeClasses = [Fill, Replace, Biome]
|
||||||
|
Reference in New Issue
Block a user