コード例 #1
0
ファイル: command.py プロジェクト: wcpe/mcedit2
    def __init__(self, editorSession, tileEntityRef):
        super(CommandBlockEditorWidget, self).__init__()
        assert tileEntityRef.id == self.tileEntityID

        self.editorSession = editorSession

        self.customNameLabel = QtGui.QLabel(self.tr("Custom Name: "))
        self.customNameField = QtGui.QLineEdit()

        self.trackOutputCheckbox = QtGui.QCheckBox(self.tr("Track Output"))
        self.successCountLabel = QtGui.QLabel(self.tr("Success Count: "))
        self.successCountSpinBox = QtGui.QSpinBox()

        self.gotoCommandButton = QtGui.QPushButton(self.tr("Go To Command"),
                                                   clicked=self.gotoCommand)
        self.gotoTargetButton = QtGui.QPushButton(self.tr("Go To Target"),
                                                  clicked=self.gotoTarget)
        self.gotoIndirectTargetButton = QtGui.QPushButton(
            self.tr("Go To Indirect Target"), clicked=self.gotoIndirectTarget)

        self.commandTextEdit = QtGui.QTextEdit()
        self.commandTextEdit.setAcceptRichText(False)

        self.commandGroup = QtGui.QGroupBox(self.tr("Command Text:"))
        self.commandGroup.setLayout(Column(self.commandTextEdit))
        self.setLayout(
            Column(
                Row(self.customNameLabel, self.customNameField),
                Row(self.trackOutputCheckbox, None, self.successCountLabel,
                    self.successCountSpinBox),
                Row(self.gotoCommandButton, self.gotoTargetButton,
                    self.gotoIndirectTargetButton), self.commandGroup))

        self.tileEntityRef = tileEntityRef

        self.commandTextEdit.setText(tileEntityRef.Command)
        self.customNameField.setText(tileEntityRef.CustomName)
        self.trackOutputCheckbox.setChecked(tileEntityRef.TrackOutput != 0)
        self.successCountSpinBox.setValue(tileEntityRef.SuccessCount)

        enabled = not editorSession.readonly

        self.trackOutputCheckbox.setEnabled(enabled)
        self.successCountSpinBox.setEnabled(enabled)
        self.commandTextEdit.setEnabled(enabled)
        self.customNameField.setEnabled(enabled)

        try:
            self.parsedCommand = ParseCommand(tileEntityRef.Command)
        except Exception:
            log.warn("Failed to parse command block.", exc_info=1)
            self.parsedCommand = None

            self.gotoTargetButton.setEnabled(False)
            self.gotoIndirectTarget.setEnabled(False)

        self.adjustSize()
コード例 #2
0
ファイル: __init__.py プロジェクト: wcpe/mcedit2
    def updateTileEntity(self):
        if self.blockEditorWidget:
            self.blockTabWidget.removeTab(0)
            self.blockEditorWidget = None

        pos = self.blockPos

        if pos is None:
            self.blockNBTEditor.setRootTagRef(None)
            return

        self.tileEntity = self.editorSession.currentDimension.getTileEntity(
            pos)
        log.info("Inspecting TileEntity %s at %s", self.tileEntity, pos)

        if self.tileEntity is not None:
            editorClass = tileEntityEditorClasses.get(self.tileEntity.id)
            if editorClass is not None:
                try:
                    self.blockEditorWidget = editorClass(
                        self.editorSession, self.tileEntity)
                except Exception as e:
                    self.blockEditorWidget = QtGui.QLabel(
                        "Failed to load TileEntity editor:\n%s\n%s" % (
                            e,
                            traceback.format_exc(),
                        ))
                    self.blockEditorWidget.displayName = "Error"

                displayName = getattr(self.blockEditorWidget, 'displayName',
                                      self.tileEntity.id)

                self.blockTabWidget.insertTab(0, self.blockEditorWidget,
                                              displayName)
                self.blockTabWidget.setCurrentIndex(0)

            self.blockNBTEditor.setRootTagRef(self.tileEntity)
        else:
            self.blockNBTEditor.setRootTagRef(None)

        self.removeTileEntityButton.setEnabled(
            self.tileEntity is not None and not self.editorSession.readonly)

        if self.tileEntity is not None:
            if self.tileEntity.id == "Control":
                try:
                    commandObj = ParseCommand(self.tileEntity.Command)
                    visuals = CommandVisuals(pos, commandObj)
                    self.commandBlockVisualsNode = visuals
                    self.overlayNode.addChild(visuals)
                    self.editorSession.updateView()
                except Exception as e:
                    log.warn("Failed to parse command.", exc_info=1)
コード例 #3
0
ファイル: command.py プロジェクト: mcedit/mcedit2
    def __init__(self, editorSession, tileEntityRef):
        super(CommandBlockEditorWidget, self).__init__()
        assert tileEntityRef.id == self.tileEntityID

        self.editorSession = editorSession

        self.customNameLabel = QtGui.QLabel(self.tr("Custom Name: "))
        self.customNameField = QtGui.QLineEdit()

        self.trackOutputCheckbox = QtGui.QCheckBox(self.tr("Track Output"))
        self.successCountLabel = QtGui.QLabel(self.tr("Success Count: "))
        self.successCountSpinBox = QtGui.QSpinBox()

        self.gotoCommandButton = QtGui.QPushButton(self.tr("Go To Command"), clicked=self.gotoCommand)
        self.gotoTargetButton = QtGui.QPushButton(self.tr("Go To Target"), clicked=self.gotoTarget)
        self.gotoIndirectTargetButton = QtGui.QPushButton(self.tr("Go To Indirect Target"), clicked=self.gotoIndirectTarget)

        self.commandTextEdit = QtGui.QTextEdit()
        self.commandTextEdit.setAcceptRichText(False)

        self.commandGroup = QtGui.QGroupBox(self.tr("Command Text:"))
        self.commandGroup.setLayout(Column(self.commandTextEdit))
        self.setLayout(Column(Row(self.customNameLabel, self.customNameField),
                              Row(self.trackOutputCheckbox, None,
                                  self.successCountLabel, self.successCountSpinBox),
                              Row(self.gotoCommandButton, self.gotoTargetButton, self.gotoIndirectTargetButton),
                              self.commandGroup))

        self.tileEntityRef = tileEntityRef

        self.commandTextEdit.setText(tileEntityRef.Command)
        self.customNameField.setText(tileEntityRef.CustomName)
        self.trackOutputCheckbox.setChecked(tileEntityRef.TrackOutput != 0)
        self.successCountSpinBox.setValue(tileEntityRef.SuccessCount)

        enabled = not editorSession.readonly

        self.trackOutputCheckbox.setEnabled(enabled)
        self.successCountSpinBox.setEnabled(enabled)
        self.commandTextEdit.setEnabled(enabled)
        self.customNameField.setEnabled(enabled)

        try:
            self.parsedCommand = ParseCommand(tileEntityRef.Command)
        except Exception:
            log.warn("Failed to parse command block.", exc_info=1)
            self.parsedCommand = None

            self.gotoTargetButton.setEnabled(False)
            self.gotoIndirectTarget.setEnabled(False)

        self.adjustSize()
コード例 #4
0
ファイル: command.py プロジェクト: brennced/mcedit2
class CommandBlockEditorWidget(QtGui.QWidget):
    tileEntityID = "Control"
    def __init__(self, editorSession, tileEntityRef):
        super(CommandBlockEditorWidget, self).__init__()
        assert tileEntityRef.id == self.tileEntityID

        self.editorSession = editorSession

        self.customNameLabel = QtGui.QLabel(self.tr("Custom Name: "))
        self.customNameField = QtGui.QLineEdit()

        self.trackOutputCheckbox = QtGui.QCheckBox(self.tr("Track Output"))
        self.successCountLabel = QtGui.QLabel(self.tr("Success Count: "))
        self.successCountSpinBox = QtGui.QSpinBox()

        self.gotoCommandButton = QtGui.QPushButton(self.tr("Go To Command"), clicked=self.gotoCommand)
        self.gotoTargetButton = QtGui.QPushButton(self.tr("Go To Target"), clicked=self.gotoTarget)
        self.gotoIndirectTargetButton = QtGui.QPushButton(self.tr("Go To Indirect Target"), clicked=self.gotoIndirectTarget)

        self.commandTextEdit = QtGui.QTextEdit()
        self.commandTextEdit.setAcceptRichText(False)

        self.commandGroup = QtGui.QGroupBox(self.tr("Command Text:"))
        self.commandGroup.setLayout(Column(self.commandTextEdit))
        self.setLayout(Column(Row(self.customNameLabel, self.customNameField),
                              Row(self.trackOutputCheckbox, None,
                                  self.successCountLabel, self.successCountSpinBox),
                              Row(self.gotoCommandButton, self.gotoTargetButton, self.gotoIndirectTargetButton),
                              self.commandGroup))

        self.tileEntityRef = tileEntityRef

        self.commandTextEdit.setText(tileEntityRef.Command)
        self.customNameField.setText(tileEntityRef.CustomName)
        self.trackOutputCheckbox.setChecked(tileEntityRef.TrackOutput != 0)
        self.successCountSpinBox.setValue(tileEntityRef.SuccessCount)

        try:
            self.parsedCommand = ParseCommand(tileEntityRef.Command)
        except Exception:
            log.warn("Failed to parse command block.", exc_info=1)
            self.parsedCommand = None

            self.gotoTargetButton.setEnabled(False)
            self.gotoIndirectTarget.setEnabled(False)

        self.adjustSize()

    def gotoCommand(self):
        self.editorSession.zoomToPoint(self.tileEntityRef.Position)

    def gotoTarget(self):
        if self.parsedCommand.name == "setblock":
            targetPos = self.parsedCommand.resolvePosition(self.tileEntityRef.Position)
            self.editorSession.zoomToPoint(targetPos)
        elif self.parsedCommand.name == "execute":
            selector = self.parsedCommand.targetSelector
            if selector.playerName is not None:
                return

            x, y, z = [selector.getArg(a) for a in 'xyz']

            if None in (x, y, z):
                log.warn("No selector coordinates for command %s", self.parsedCommand)
                return
            self.editorSession.zoomToPoint((x, y, z))

    def gotoIndirectTarget(self):
        if self.parsedCommand.name == "execute":
            targetPos = self.parsedCommand.resolvePosition(self.tileEntityRef.Position)
            subcommand = self.parsedCommand.subcommand

            if hasattr(subcommand, 'resolvePosition'):
                indirectPos = subcommand.resolvePosition(targetPos)
                self.editorSession.zoomToPoint(indirectPos)

            if hasattr(subcommand, 'resolveBoundingBox'):
                sourceBounds = subcommand.resolveBoundingBox(targetPos)
                self.editorSession.zoomToPoint(sourceBounds.center)
コード例 #5
0
ファイル: command.py プロジェクト: wcpe/mcedit2
class CommandBlockEditorWidget(QtGui.QWidget):
    tileEntityID = "Control"

    def __init__(self, editorSession, tileEntityRef):
        super(CommandBlockEditorWidget, self).__init__()
        assert tileEntityRef.id == self.tileEntityID

        self.editorSession = editorSession

        self.customNameLabel = QtGui.QLabel(self.tr("Custom Name: "))
        self.customNameField = QtGui.QLineEdit()

        self.trackOutputCheckbox = QtGui.QCheckBox(self.tr("Track Output"))
        self.successCountLabel = QtGui.QLabel(self.tr("Success Count: "))
        self.successCountSpinBox = QtGui.QSpinBox()

        self.gotoCommandButton = QtGui.QPushButton(self.tr("Go To Command"),
                                                   clicked=self.gotoCommand)
        self.gotoTargetButton = QtGui.QPushButton(self.tr("Go To Target"),
                                                  clicked=self.gotoTarget)
        self.gotoIndirectTargetButton = QtGui.QPushButton(
            self.tr("Go To Indirect Target"), clicked=self.gotoIndirectTarget)

        self.commandTextEdit = QtGui.QTextEdit()
        self.commandTextEdit.setAcceptRichText(False)

        self.commandGroup = QtGui.QGroupBox(self.tr("Command Text:"))
        self.commandGroup.setLayout(Column(self.commandTextEdit))
        self.setLayout(
            Column(
                Row(self.customNameLabel, self.customNameField),
                Row(self.trackOutputCheckbox, None, self.successCountLabel,
                    self.successCountSpinBox),
                Row(self.gotoCommandButton, self.gotoTargetButton,
                    self.gotoIndirectTargetButton), self.commandGroup))

        self.tileEntityRef = tileEntityRef

        self.commandTextEdit.setText(tileEntityRef.Command)
        self.customNameField.setText(tileEntityRef.CustomName)
        self.trackOutputCheckbox.setChecked(tileEntityRef.TrackOutput != 0)
        self.successCountSpinBox.setValue(tileEntityRef.SuccessCount)

        enabled = not editorSession.readonly

        self.trackOutputCheckbox.setEnabled(enabled)
        self.successCountSpinBox.setEnabled(enabled)
        self.commandTextEdit.setEnabled(enabled)
        self.customNameField.setEnabled(enabled)

        try:
            self.parsedCommand = ParseCommand(tileEntityRef.Command)
        except Exception:
            log.warn("Failed to parse command block.", exc_info=1)
            self.parsedCommand = None

            self.gotoTargetButton.setEnabled(False)
            self.gotoIndirectTarget.setEnabled(False)

        self.adjustSize()

    def gotoCommand(self):
        self.editorSession.zoomToPoint(self.tileEntityRef.Position)

    def gotoTarget(self):
        if self.parsedCommand.name == "setblock":
            targetPos = self.parsedCommand.resolvePosition(
                self.tileEntityRef.Position)
            self.editorSession.zoomToPoint(targetPos)
        elif self.parsedCommand.name == "execute":
            selector = self.parsedCommand.targetSelector
            if selector.playerName is not None:
                return

            x, y, z = [selector.getArg(a) for a in 'xyz']

            if None in (x, y, z):
                log.warn("No selector coordinates for command %s",
                         self.parsedCommand)
                return
            self.editorSession.zoomToPoint((x, y, z))

    def gotoIndirectTarget(self):
        if self.parsedCommand.name == "execute":
            targetPos = self.parsedCommand.resolvePosition(
                self.tileEntityRef.Position)
            subcommand = self.parsedCommand.subcommand

            if hasattr(subcommand, 'resolvePosition'):
                indirectPos = subcommand.resolvePosition(targetPos)
                self.editorSession.zoomToPoint(indirectPos)

            if hasattr(subcommand, 'resolveBoundingBox'):
                sourceBounds = subcommand.resolveBoundingBox(targetPos)
                self.editorSession.zoomToPoint(sourceBounds.center)
コード例 #6
0
    def inspectBlock(self, pos):
        self.clearVisuals()
        self.blockPos = pos
        self.entity = None

        self.stackedWidget.setCurrentWidget(self.pageInspectBlock)
        x, y, z = pos
        self.blockXSpinBox.setValue(x)
        self.blockYSpinBox.setValue(y)
        self.blockZSpinBox.setValue(z)

        blockID = self.editorSession.currentDimension.getBlockID(x, y, z)
        blockData = self.editorSession.currentDimension.getBlockData(x, y, z)
        blockLight = self.editorSession.currentDimension.getBlockLight(x, y, z)
        skyLight = self.editorSession.currentDimension.getSkyLight(x, y, z)

        self.blockIDLabel.setText(str(blockID))
        self.blockDataLabel.setText(str(blockData))
        self.blockLightLabel.setText(str(blockLight))
        self.skyLightLabel.setText(str(skyLight))

        block = self.editorSession.currentDimension.getBlock(x, y, z)

        self.blockNameLabel.setText(block.displayName)
        self.blockInternalNameLabel.setText(block.internalName)
        self.blockStateLabel.setText(str(block.blockState))

        if self.blockEditorWidget:
            self.blockTabWidget.removeTab(0)
            self.blockEditorWidget = None

        self.tileEntity = self.editorSession.currentDimension.getTileEntity(
            pos)
        log.info("Inspecting TileEntity %s at %s", self.tileEntity, pos)

        if self.tileEntity is not None:
            editorClass = tileEntityEditorClasses.get(self.tileEntity.id)
            if editorClass is not None:
                try:
                    self.blockEditorWidget = editorClass(
                        self.editorSession, self.tileEntity)
                except Exception as e:
                    self.blockEditorWidget = QtGui.QLabel(
                        "Failed to load TileEntity editor:\n%s\n%s" % (
                            e,
                            traceback.format_exc(),
                        ))
                    self.blockEditorWidget.displayName = "Error"

                displayName = getattr(self.blockEditorWidget, 'displayName',
                                      self.tileEntity.id)

                self.blockTabWidget.insertTab(0, self.blockEditorWidget,
                                              displayName)
                self.blockTabWidget.setCurrentIndex(0)

            self.blockNBTEditor.setRootTagRef(self.tileEntity)
        else:
            self.blockNBTEditor.setRootTagRef(None)

        self.removeTileEntityButton.setEnabled(self.tileEntity is not None)

        blockBox = BoundingBox((x, y, z), (1, 1, 1))

        self.selectionNode.selectionBox = blockBox
        if self.tileEntity is not None:
            if self.tileEntity.id == "Control":
                try:
                    commandObj = ParseCommand(self.tileEntity.Command)
                    visuals = CommandVisuals((x, y, z), commandObj)
                    self.commandBlockVisualsNode = visuals
                    self.overlayNode.addChild(visuals)
                    self.editorSession.updateView()
                except Exception as e:
                    log.warn("Failed to parse command.", exc_info=1)