Exemple #1
0
    def __init__(self, parent=None):
        super(BlockReplacementButton, self).__init__()

        self.replacementList = BlockReplacementList()
        self.replacementDialog = QtGui.QDialog(QtGui.qApp.mainWindow)

        self.replacementOk = QtGui.QPushButton(self.tr("OK"))
        self.replacementOk.clicked.connect(self.replacementDialog.accept)

        self.replacementDialog.setWindowTitle(self.tr("Choose blocks to replace"))
        self.replacementDialog.setLayout(Column(self.replacementList,
                                                Row(None, self.replacementOk)))

        self.oldBlockButton = BlockTypeButton(multipleSelect=True)
        self.newBlockButton = BlockTypeButton()
        self.advancedButton = QtGui.QPushButton(self.tr("Advanced..."))

        self.simpleButton = QtGui.QPushButton(self.tr("No, simple!"))
        self.simpleButton.setVisible(False)
        self.simpleButton.clicked.connect(self.goSimple)

        self.setLayout(Column(self.oldBlockButton,
                              self.newBlockButton,
                              self.advancedButton,
                              self.simpleButton,
                              margin=0))

        self.oldBlockButton.blocksChanged.connect(self.simpleBlocksChanged)
        self.newBlockButton.blocksChanged.connect(self.simpleBlocksChanged)
        self.advancedButton.clicked.connect(self.displayDialog)
Exemple #2
0
    def addRow(self, oldBlocks, newBlock):
        assert self.editorSession is not None, "Must set BlockReplacementList.editorSession before using"

        row = self.findReplaceTable.rowCount() - 1

        self.findReplaceTable.insertRow(row)
        log.info("Row inserted")

        left = QtGui.QTableWidgetItem()
        right = QtGui.QTableWidgetItem()
        log.info("Items created")

        def frameButton(button, withRemove=False):
            frame = QtGui.QFrame()
            frame.button = button
            layout = QtGui.QVBoxLayout()
            layout.addStretch(1)
            if withRemove:
                removeButton = QtGui.QPushButton("", flat=True)
                removeButton.setIcon(
                    QtGui.QIcon(
                        resourcePath(
                            "mcedit2/assets/mcedit2/icons/remove.png")))
                removeButton.setIconSize(QtCore.QSize(24, 24))

                def _clicked():
                    self.removeRow(self.findReplaceTable.row(left))

                removeButton.__clicked = _clicked
                removeButton.clicked.connect(_clicked)
                layout.addLayout(Row((button, 1), removeButton))
            else:
                layout.addWidget(button)
            layout.addStretch(1)
            frame.setLayout(layout)
            return frame

        leftButton = BlockTypeButton(flat=True, multipleSelect=True)
        leftButton.editorSession = self.editorSession
        leftButton.blocks = oldBlocks
        leftFramedButton = frameButton(leftButton)
        left.setSizeHint(leftFramedButton.sizeHint())
        log.info("Left button")

        rightButton = BlockTypeButton(flat=True)
        rightButton.editorSession = self.editorSession
        rightButton.block = newBlock
        rightFramedButton = frameButton(rightButton, True)
        right.setSizeHint(rightFramedButton.sizeHint())
        log.info("Right button")
        self.findReplaceTable.setItem(row, 0, left)
        self.findReplaceTable.setItem(row, 1, right)
        self.findReplaceTable.setCellWidget(row, 0, leftFramedButton)
        self.findReplaceTable.setCellWidget(row, 1, rightFramedButton)
        self.findReplaceTable.resizeRowsToContents()
        #self.findReplaceTable.resizeColumnsToContents()
        log.info("Done")
Exemple #3
0
    def __init__(self, editorSession, *args, **kwargs):
        super(FloodFillTool, self).__init__(editorSession, *args, **kwargs)

        toolWidget = QtGui.QWidget()
        self.toolWidget = toolWidget

        self.blockTypeWidget = BlockTypeButton()
        self.blockTypeWidget.block = self.editorSession.worldEditor.blocktypes[
            "stone"]
        self.blockTypeWidget.editorSession = self.editorSession

        toolWidget.setLayout(
            Column(Row(QtGui.QLabel("Block:"), self.blockTypeWidget), None))
Exemple #4
0
    def __init__(self, brushTool):
        super(Fill, self).__init__(brushTool)
        self.displayName = self.tr("Fill")

        self.optionsWidget = QtGui.QWidget()
        label = QtGui.QLabel(self.tr("Fill Block:"))
        self.blockTypeButton = BlockTypeButton()
        self.blockTypeButton.editorSession = brushTool.editorSession
        self.blockTypeButton.block = brushTool.editorSession.worldEditor.blocktypes[
            'minecraft:stone']
        self.blockTypeButton.blocksChanged.connect(brushTool.updateCursor)

        self.optionsWidget.setLayout(Row(label, self.blockTypeButton,
                                         margin=0))
Exemple #5
0
    def createOptionsWidget(self, brushTool):
        if self.optionsWidget:
            return self.optionsWidget

        self.optionsWidget = QtGui.QWidget()
        label = QtGui.QLabel(self.tr("Fill Block:"))
        self.blockTypeButton = BlockTypeButton()
        self.blockTypeButton.editorSession = brushTool.editorSession
        self.blockTypeButton.block = brushTool.editorSession.worldEditor.blocktypes['minecraft:stone']
        self.blockTypeButton.blocksChanged.connect(brushTool.updateCursor)

        self.optionsWidget.setLayout(Column(
            Row(label, self.blockTypeButton, margin=0),
            None, margin=0))
        return self.optionsWidget
    def __init__(self, editorSession, *args, **kwargs):
        super(FloodFillTool, self).__init__(editorSession, *args, **kwargs)

        toolWidget = QtGui.QWidget()
        self.toolWidget = toolWidget

        self.blockTypeWidget = BlockTypeButton()
        self.blockTypeWidget.block = self.editorSession.worldEditor.blocktypes[
            "stone"]
        self.blockTypeWidget.textureAtlas = self.editorSession.textureAtlas

        self.indiscriminateCheckBox = QtGui.QCheckBox("Ignore block meta")
        self.indiscriminateCheckBox.setChecked(False)

        toolWidget.setLayout(
            Column(Row(QtGui.QLabel("Block:"), self.blockTypeWidget),
                   self.indiscriminateCheckBox, None))
Exemple #7
0
    def getOptionsWidget(self):
        if self._optionsWidget:
            return self._optionsWidget

        widget = self._optionsWidget = QtGui.QWidget()

        self.blockTypeButton = BlockTypeButton()
        self.blockTypeButton.editorSession = self.editorSession
        self.blockTypeButton.block = "minecraft:stone"
        self.blockTypeButton.blocksChanged.connect(self.updatePreview)

        layout = QtGui.QFormLayout()
        layout.addRow(self.tr("Iterations"), self.iterationsSlider)
        layout.addRow(self.tr("Block"), self.blockTypeButton)

        widget.setLayout(layout)
        return widget
Exemple #8
0
    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

        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),
                   Row(self.hoverCheckbox, self.indiscriminateCheckBox),
                   floodDirsLayout, None))
Exemple #9
0
    def widgetFromOptDict(self, optDict):
        self.optIdx += 1

        type = optDict.get('type')
        if type is None or not isinstance(type, basestring):
            raise ValueError("Option dict must have 'type' key")

        if type in ('int', 'float'):
            minimum = optDict.get('min', None)
            maximum = optDict.get('max', None)

            value = optDict.get('value', 0)
            increment = optDict.get('increment', None)

            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            if minimum is None or maximum is None:
                if type == 'float':
                    widget = QtGui.QDoubleSpinBox(value=value)
                else:
                    widget = QtGui.QSpinBox(value=value)
                if minimum is not None:
                    widget.setMinimum(minimum)
                else:
                    widget.setMinimum(-2000000000)
                if maximum is not None:
                    widget.setMaximum(maximum)
                else:
                    widget.setMaximum(2000000000)

                if increment is not None:
                    widget.setSingleStep(increment)
            else:
                widget = SpinSlider(double=(type == 'float'),
                                    minimum=minimum,
                                    maximum=maximum,
                                    value=value,
                                    increment=increment)

            self.widgets.append(widget)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.value

        elif type == 'bool':
            value = optDict.get('value', False)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QCheckBox()
            widget.setChecked(value)
            self.widgets.append(widget)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.isChecked

        elif type == 'text':
            value = optDict.get('value', '')
            name = optDict.get('name', None)
            placeholder = optDict.get('placeholder', None)

            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QLineEdit()
            self.widgets.append(widget)
            if placeholder:
                widget.setPlaceholderText(placeholder)
            if value:
                widget.setText(value)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.text

        elif type == 'choice':
            value = optDict.get('value', None)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            choices = optDict.get('choices', [])

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QComboBox()
            self.widgets.append(widget)

            for label, key in choices:
                widget.addItem(label, key)
                if key == value:
                    widget.setCurrentIndex(widget.count() - 1)

            def getChoiceKey():
                return widget.itemData(widget.currentIndex())

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = getChoiceKey

        elif type == 'blocktype':
            value = optDict.get('value', None)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = BlockTypeButton()
            widget.editorSession = self.editorSession
            self.widgets.append(widget)

            if value is not None:
                if not isinstance(value, BlockType):
                    value = self.editorSession.worldEditor.blocktypes[value]
                widget.block = value

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = lambda: widget.block

        elif type == 'label':
            text = optDict.get('text', None)
            if not text:
                raise ValueError(
                    "Option dict for type 'label' must have 'text' key.")
            widget = QtGui.QLabel(text, wordWrap=True)
            self.widgets.append(widget)

            self.formLayout.addRow("", widget)

        elif type == 'nbt':
            widget = QtGui.QLabel("Not Implemented")
            self.widgets.append(widget)

            self.formLayout.addRow("NBT Option: ", widget)
        else:
            raise ValueError("Unknown type %s for option dict" % type)