Beispiel #1
0
    def destroyChunks(self, chunks=None):
        if "No" == ask("Really delete these chunks? This cannot be undone.", ("Yes", "No")):
            return
        if chunks is None:
            chunks = self.selectedChunks()
        chunks = list(chunks)

        def _destroyChunks():
            i = 0
            chunkCount = len(chunks)

            for cx, cz in chunks:
                i += 1
                yield (i, chunkCount)
                if self.editor.level.containsChunk(cx, cz):
                    try:
                        self.editor.level.deleteChunk(cx, cz)
                    except Exception as e:
                        print "Error during chunk delete: ", e

        with setWindowCaption("DELETING - "):
            showProgress("Deleting chunks...", _destroyChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.renderer.discardAllChunks()
Beispiel #2
0
    def confirm(self, tool):
        with setWindowCaption("Applying Macro..."):
            options = []
            filters = []
            for step in sorted(self._macro_data.keys()):
                if step != "Number of steps":
                    filters.append(
                        tool.filterModules[self._macro_data[step]["Name"]])
                    for module_input in self._macro_data[step]["Inputs"].keys(
                    ):
                        if not isinstance(
                                self._macro_data[step]["Inputs"][module_input],
                            (str, unicode)):
                            continue
                        if not self._macro_data[step]["Inputs"][
                                module_input].startswith("block-"):
                            continue
                        toFind = self._macro_data[step]["Inputs"][
                            module_input][6:].split(":")
                        block = tool.editor.materials.get(
                            (toFind[0], toFind[1]))
                        self._macro_data[step]["Inputs"][module_input] = block
                    options.append(self._macro_data[step]["Inputs"])

            op = MacroOperation(tool.editor, tool.editor.level,
                                tool.selectionBox(), filters, options)

            tool.editor.level.showProgress = showProgress

            tool.editor.addOperation(op)
            tool.editor.addUnsavedEdit()

            tool.editor.invalidateBox(tool.selectionBox())
Beispiel #3
0
    def confirm(self):
        box = self.selectionBox()
        if None is box:
            return

        with setWindowCaption("REPLACING - "):
            self.editor.freezeStatus("Replacing %0.1f million blocks" % (float(box.volume) / 1048576.,))

            self.blockInfo = self.panel.blockButton.blockInfo

            if self.replacing:
                self.replaceBlockInfo = self.panel.replaceBlockButton.blockInfo
                if self.blockInfo.wildcard:
                    print "Wildcard replace"
                    blocksToReplace = []
                    for i in range(16):
                        blocksToReplace.append(self.editor.level.materials.blockWithID(self.blockInfo.ID, i))
                else:
                    blocksToReplace = [self.blockInfo]

                op = BlockFillOperation(self.editor, self.editor.level, self.selectionBox(), self.replaceBlockInfo,
                                        blocksToReplace, noData=self.noData)

            else:
                blocksToReplace = []
                op = BlockFillOperation(self.editor, self.editor.level, self.selectionBox(), self.blockInfo,
                                        blocksToReplace)

        self.editor.addOperation(op)

        self.editor.addUnsavedEdit()
        self.editor.invalidateBox(box)
        self.editor.toolbar.selectTool(-1)
Beispiel #4
0
    def pruneChunks(self):
        if "No" == ask(
                "Save these chunks and remove the rest? This cannot be undone.",
            ("Yes", "No")):
            return
        self.editor.saveFile()

        def _pruneChunks():
            maxChunks = self.editor.level.chunkCount
            selectedChunks = self.selectedChunks()
            for i, cPos in enumerate(list(self.editor.level.allChunks)):
                if cPos not in selectedChunks:
                    try:
                        self.editor.level.deleteChunk(*cPos)

                    except Exception as e:
                        print "Error during chunk delete: ", e

                yield i, maxChunks

        with setWindowCaption("PRUNING - "):
            showProgress("Pruning chunks...", _pruneChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.discardAllChunks()
Beispiel #5
0
    def perform(self, recordUndo=True):
        if self.level.saving:
            alert(_("Cannot perform action while saving is taking place"))
            return

        if recordUndo:
            self.canUndo = True
            self.undoLevel = self.extractUndo(self.level, BoundingBox(self.destPoint, self.sourceBox.size))

        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(pymclevel.materials.id_limit)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(
                self.sourceLevel,
                self.sourceBox,
                self.destPoint,
                blocksToCopy,
                create=True,
                biomes=self.copyBiomes,
                staticCommands=self.staticCommands,
                moveSpawnerPos=self.moveSpawnerPos,
                regenerateUUID=self.regenerateUUID,
                first=False,
            )
            showProgress(_("Copying {0:n} blocks...").format(self.sourceBox.volume), i)
Beispiel #6
0
    def createChunks(self):
        panel = GeneratorPanel()
        col = [panel]
        label = Label(
            "Create chunks using the settings above? This cannot be undone.")
        col.append(Row([Label("")]))
        col.append(label)
        col = Column(col)
        if Dialog(client=col, responses=["OK",
                                         "Cancel"]).present() == "Cancel":
            return
        chunks = self.selectedChunks()

        createChunks = panel.generate(self.editor.level, chunks)

        try:
            with setWindowCaption("CREATING - "):
                showProgress("Creating {0} chunks...".format(len(chunks)),
                             createChunks,
                             cancel=True)
        except Exception as e:
            traceback.print_exc()
            alert(_("Failed to start the chunk generator. {0!r}").format(e))
        finally:
            self.editor.renderer.invalidateChunkMarkers()
            self.editor.renderer.loadNearbyChunks()
Beispiel #7
0
    def perform(self, recordUndo=True):
        sourceBox = self.sourceBox

        if recordUndo:
            self.undoLevel = self.extractUndo(
                self.level, BoundingBox(self.destPoint, self.sourceBox.size))

        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(pymclevel.materials.id_limit)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(
                self.sourceLevel,
                self.sourceBox,
                self.destPoint,
                blocksToCopy,
                create=True,
                biomes=self.copyBiomes,
                staticCommands=self.staticCommands,
                first=False)
            showProgress(
                _("Copying {0:n} blocks...").format(self.sourceBox.volume), i)
Beispiel #8
0
    def confirm(self, tool):
        with setWindowCaption("Applying Macro..."):
            options = []
            filters = []
            for step in sorted(self._macro_data.keys()):
                if step != "Number of steps":
                    filters.append(tool.filterModules[self._macro_data[step]["Name"]])
                    for module_input in self._macro_data[step]["Inputs"].keys():
                        if not isinstance(self._macro_data[step]["Inputs"][module_input], (str, unicode)):
                            continue
                        if not self._macro_data[step]["Inputs"][module_input].startswith("block-"):
                            continue
                        toFind = self._macro_data[step]["Inputs"][module_input][6:].split(":")
                        block = tool.editor.materials.get((toFind[0], toFind[1]))
                        self._macro_data[step]["Inputs"][module_input] = block
                    options.append(self._macro_data[step]["Inputs"])

            op = MacroOperation(tool.editor, tool.editor.level, tool.selectionBox(), filters, options)

            tool.editor.level.showProgress = showProgress

            tool.editor.addOperation(op)
            tool.editor.addUnsavedEdit()

            tool.editor.invalidateBox(tool.selectionBox())
Beispiel #9
0
    def confirm(self):
        box = self.selectionBox()
        if None is box:
            return

        with setWindowCaption("REPLACING - "):
            self.editor.freezeStatus("Replacing %0.1f million blocks" % (float(box.volume) / 1048576.,))

            self.blockInfo = self.panel.blockButton.blockInfo

            if self.replacing:
                self.replaceBlockInfo = self.panel.replaceBlockButton.blockInfo
                if self.blockInfo.wildcard:
                    print "Wildcard replace"
                    blocksToReplace = []
                    for i in range(16):
                        blocksToReplace.append(self.editor.level.materials.blockWithID(self.blockInfo.ID, i))
                else:
                    blocksToReplace = [self.blockInfo]

                op = BlockFillOperation(self.editor, self.editor.level, self.selectionBox(), self.replaceBlockInfo,
                                        blocksToReplace, noData=self.noData)

            else:
                blocksToReplace = []
                op = BlockFillOperation(self.editor, self.editor.level, self.selectionBox(), self.blockInfo,
                                        blocksToReplace)

        self.editor.addOperation(op)

        self.editor.addUnsavedEdit()
        self.editor.invalidateBox(box)
        self.editor.toolbar.selectTool(-1)
Beispiel #10
0
    def perform(self, recordUndo=True):
        if self.level.saving:
            alert(_("Cannot perform action while saving is taking place"))
            return

        if recordUndo:
            self.canUndo = True
            self.undoLevel = self.extractUndo(
                self.level, BoundingBox(self.destPoint, self.sourceBox.size))

        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(pymclevel.materials.id_limit)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(
                self.sourceLevel,
                self.sourceBox,
                self.destPoint,
                blocksToCopy,
                create=True,
                biomes=self.copyBiomes,
                staticCommands=self.staticCommands,
                moveSpawnerPos=self.moveSpawnerPos,
                regenerateUUID=self.regenerateUUID,
                first=False)
            showProgress(
                _("Copying {0:n} blocks...").format(self.sourceBox.volume), i)
Beispiel #11
0
    def destroyChunks(self, chunks=None):
        if "No" == ask("Really delete these chunks? This cannot be undone.",
                       ("Yes", "No")):
            return
        if chunks is None:
            chunks = self.selectedChunks()
        chunks = list(chunks)

        def _destroyChunks():
            i = 0
            chunkCount = len(chunks)

            for cx, cz in chunks:
                i += 1
                yield (i, chunkCount)
                if self.editor.level.containsChunk(cx, cz):
                    try:
                        self.editor.level.deleteChunk(cx, cz)
                    except Exception as e:
                        print "Error during chunk delete: ", e

        with setWindowCaption("DELETING - "):
            showProgress("Deleting chunks...", _destroyChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.renderer.discardAllChunks()
Beispiel #12
0
 def updateSchematic(self):
     # extract blocks
     with setWindowCaption("COPYING - "):
         self.editor.freezeStatus("Copying to clone buffer...")
         box = self.selectionBox()
         self.level = self.editor.level.extractSchematic(box)
         self.originalLevel = self.level
         # self.level.cloneToolScaleFactor = 1.0
         self.rescaleLevel(self.scaleFactor)
         self.setupPreview()
Beispiel #13
0
 def updateSchematic(self):
     # extract blocks
     with setWindowCaption("COPYING - "):
         self.editor.freezeStatus("Copying to clone buffer...")
         box = self.selectionBox()
         self.level = self.editor.level.extractSchematic(box)
         self.originalLevel = self.level
         # self.level.cloneToolScaleFactor = 1.0
         self.rescaleLevel(self.scaleFactor)
         self.setupPreview()
Beispiel #14
0
    def perform(self, recordUndo=True):
        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus("Copying %0.1f million blocks" % (float(self._dirtyBox.volume) / 1048576.,))
            if recordUndo:
                chunks = set()
                for op in self.blockCopyOps:
                    chunks.update(op.dirtyBox().chunkPositions)
                self.undoLevel = self.extractUndoChunks(self.level, chunks)

            [i.perform(False) for i in self.blockCopyOps]
            [i.perform(recordUndo) for i in self.selectionOps]
Beispiel #15
0
    def perform(self, recordUndo=True):
        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus(_("Copying %0.1f million blocks") % (float(self._dirtyBox.volume) / 1048576.,))
            if recordUndo:
                chunks = set()
                for op in self.blockCopyOps:
                    chunks.update(op.dirtyBox().chunkPositions)
                self.undoLevel = self.extractUndoChunks(self.level, chunks)

            [i.perform(False) for i in self.blockCopyOps]
            [i.perform(recordUndo) for i in self.selectionOps]
Beispiel #16
0
    def relightChunks(self):

        def _relightChunks():
            for i in self.editor.level.generateLightsIter(self.selectedChunks()):
                yield i

        with setWindowCaption("RELIGHTING - "):
            showProgress(_("Lighting {0} chunks...").format(len(self.selectedChunks())),
                         _relightChunks(), cancel=True)

            self.editor.invalidateChunks(self.selectedChunks())
            self.editor.addUnsavedEdit()
Beispiel #17
0
    def relightChunks(self):

        def _relightChunks():
            for i in self.editor.level.generateLightsIter(self.selectedChunks()):
                yield i

        with setWindowCaption("RELIGHTING - "):
            showProgress(_("Lighting {0} chunks...").format(len(self.selectedChunks())),
                         _relightChunks(), cancel=True)

            self.editor.invalidateChunks(self.selectedChunks())
            self.editor.addUnsavedEdit()
Beispiel #18
0
    def confirm(tool):
        with setWindowCaption("Applying Filter... - "):
            filterModule = tool.filterModules[tool.panel.filterSelect.selectedChoice]

            op = FilterOperation(tool.editor, tool.editor.level, tool.selectionBox(), filterModule,
                                 tool.panel.filterOptionsPanel.options)

            tool.editor.level.showProgress = showProgress

            tool.editor.addOperation(op)
            tool.editor.addUnsavedEdit()

            tool.editor.invalidateBox(tool.selectionBox())
Beispiel #19
0
    def confirm(tool):
        with setWindowCaption("Applying Filter... - "):
            filterModule = tool.filterModules[tool.panel.filterSelect.selectedChoice]

            op = FilterOperation(tool.editor, tool.editor.level, tool.selectionBox(), filterModule,
                                 tool.panel.filterOptionsPanel.options)

            tool.editor.level.showProgress = showProgress

            tool.editor.addOperation(op)
            tool.editor.addUnsavedEdit()

            tool.editor.invalidateBox(tool.selectionBox())
Beispiel #20
0
    def confirm(self):

        with setWindowCaption("APPLYING FILTER - "):
            filterModule = self.filterModules[self.panel.filterSelect.selectedChoice]

            op = FilterOperation(self.editor, self.editor.level, self.selectionBox(), filterModule, self.panel.filterOptionsPanel.options)

            self.editor.level.showProgress = showProgress

            self.editor.addOperation(op)
            self.editor.addUnsavedEdit()

            self.editor.invalidateBox(self.selectionBox())
Beispiel #21
0
    def confirm(self):

        with setWindowCaption("APPLYING FILTER - "):
            filterModule = self.filterModules[self.panel.filterSelect.selectedChoice]

            op = FilterOperation(self.editor, self.editor.level, self.selectionBox(), filterModule,
                                 self.panel.filterOptionsPanel.options)

            self.editor.level.showProgress = showProgress

            self.editor.addOperation(op)
            self.editor.addUnsavedEdit()

            self.editor.invalidateBox(self.selectionBox())
Beispiel #22
0
    def perform(self, recordUndo=True):
        if self.level.saving:
            alert(_("Cannot perform action while saving is taking place"))
            return
        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus(_("Copying %0.1f million blocks") % (float(self._dirtyBox.volume) / 1048576.0,))
            if recordUndo:
                chunks = set()
                for op in self.blockCopyOps:
                    chunks.update(op.dirtyBox().chunkPositions)
                self.undoLevel = self.extractUndoChunks(self.level, chunks)

            [i.perform(False) for i in self.blockCopyOps]
            [i.perform(recordUndo) for i in self.selectionOps]
            self.canUndo = True
Beispiel #23
0
    def perform(self, recordUndo=True):
        if self.level.saving:
            alert(_("Cannot perform action while saving is taking place"))
            return
        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus(_("Copying %0.1f million blocks") % (float(self._dirtyBox.volume) / 1048576.,))
            if recordUndo:
                chunks = set()
                for op in self.blockCopyOps:
                    chunks.update(op.dirtyBox().chunkPositions)
                self.undoLevel = self.extractUndoChunks(self.level, chunks)

            [i.perform(False) for i in self.blockCopyOps]
            [i.perform(recordUndo) for i in self.selectionOps]
            self.canUndo = True
Beispiel #24
0
    def createChunks(self):
        panel = GeneratorPanel()
        col = [panel]
        label = Label("Create chunks using the settings above? This cannot be undone.")
        col.append(Row([Label("")]))
        col.append(label)
        col = Column(col)
        if Dialog(client=col, responses=["OK", "Cancel"]).present() == "Cancel":
            return
        chunks = self.selectedChunks()

        createChunks = panel.generate(self.editor.level, chunks)

        try:
            with setWindowCaption("CREATING - "):
                showProgress("Creating {0} chunks...".format(len(chunks)), createChunks, cancel=True)
        except Exception, e:
            traceback.print_exc()
            alert(_("Failed to start the chunk generator. {0!r}").format(e))
Beispiel #25
0
    def perform(self, recordUndo=True):
        sourceBox = self.sourceBox

        if recordUndo:
            self.undoLevel = self.extractUndo(self.level, BoundingBox(self.destPoint, self.sourceBox.size))


        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(256)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(self.sourceLevel, self.sourceBox, self.destPoint, blocksToCopy, create=True)
            showProgress("Copying {0:n} blocks...".format(self.sourceBox.volume), i)
Beispiel #26
0
    def perform(self, recordUndo=True):
        sourceBox = self.sourceBox

        if recordUndo:
            self.undoLevel = self.extractUndo(self.level, BoundingBox(self.destPoint, self.sourceBox.size))

        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(pymclevel.materials.id_limit)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(self.sourceLevel, self.sourceBox, self.destPoint, blocksToCopy,
                                              create=True, biomes=self.copyBiomes, staticCommands=self.staticCommands, first=False)
            showProgress(_("Copying {0:n} blocks...").format(self.sourceBox.volume), i)
Beispiel #27
0
    def perform(self, recordUndo=True):
        sourceBox = self.sourceBox

        if recordUndo:
            self.undoLevel = self.extractUndo(self.level, BoundingBox(self.destPoint, self.sourceBox.size))


        blocksToCopy = None
        if not (self.copyAir and self.copyWater):
            blocksToCopy = range(256)
            if not self.copyAir:
                blocksToCopy.remove(0)
            if not self.copyWater:
                blocksToCopy.remove(8)
            if not self.copyWater:
                blocksToCopy.remove(9)

        with setWindowCaption("Copying - "):
            i = self.level.copyBlocksFromIter(self.sourceLevel, self.sourceBox, self.destPoint, blocksToCopy, create=True)
            showProgress("Copying {0:n} blocks...".format(self.sourceBox.volume), i)
Beispiel #28
0
    def confirm(self):
        destPoint = self.destPoint
        if destPoint is None:
            return

        sourceLevel = self.sourceLevel()
        sourceBox = sourceLevel.bounds

        destLevel = self.editor.level
        destVolume = BoundingBox(destPoint, sourceBox.size).volume

        op = CloneOperation(editor=self.editor,
                            sourceLevel=sourceLevel,
                            sourceBox=sourceBox,
                            originSourceBox=self.selectionBox(),
                            destLevel=destLevel,
                            destPoint=self.destPoint,
                            copyAir=self.copyAir,
                            copyWater=self.copyWater,
                            copyBiomes=self.copyBiomes,
                            repeatCount=self.repeatCount)

        self.editor.toolbar.selectTool(-1)  # deselect tool so that the clone tool's selection change doesn't update its schematic

        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus("Copying %0.1f million blocks" % (float(destVolume) / 1048576.,))
            self.performWithRetry(op)

        self.editor.addUnsavedEdit()

        self.editor.addOperation(op)

        dirtyBox = op.dirtyBox()
        if dirtyBox:
            self.editor.invalidateBox(dirtyBox)
        self.editor.renderer.invalidateChunkMarkers()

        self.editor.currentOperation = None

        self.destPoint = None
        self.level = None
Beispiel #29
0
    def confirm(self):
        destPoint = self.destPoint
        if destPoint is None:
            return

        sourceLevel = self.sourceLevel()
        sourceBox = sourceLevel.bounds

        destLevel = self.editor.level
        destVolume = BoundingBox(destPoint, sourceBox.size).volume

        op = CloneOperation(editor=self.editor,
                            sourceLevel=sourceLevel,
                            sourceBox=sourceBox,
                            originSourceBox=self.selectionBox(),
                            destLevel=destLevel,
                            destPoint=self.destPoint,
                            copyAir=self.copyAir,
                            copyWater=self.copyWater,
                            repeatCount=self.repeatCount)

        self.editor.toolbar.selectTool(-1)  # deselect tool so that the clone tool's selection change doesn't update its schematic

        with setWindowCaption("COPYING - "):
            self.editor.freezeStatus("Copying %0.1f million blocks" % (float(destVolume) / 1048576.,))
            self.performWithRetry(op)

        self.editor.addUnsavedEdit()

        self.editor.addOperation(op)

        dirtyBox = op.dirtyBox()
        if dirtyBox:
            self.editor.invalidateBox(dirtyBox)
        self.editor.renderer.invalidateChunkMarkers()

        self.editor.currentOperation = None

        self.destPoint = None
        self.level = None
Beispiel #30
0
    def pruneChunks(self):
        if "No" == ask("Save these chunks and remove the rest? This cannot be undone.", ("Yes", "No")):
            return
        self.editor.saveFile()

        def _pruneChunks():
            maxChunks = self.editor.level.chunkCount
            selectedChunks = self.selectedChunks()
            for i, cPos in enumerate(list(self.editor.level.allChunks)):
                if cPos not in selectedChunks:
                    try:
                        self.editor.level.deleteChunk(*cPos)

                    except Exception as e:
                        print "Error during chunk delete: ", e

                yield i, maxChunks

        with setWindowCaption("PRUNING - "):
            showProgress("Pruning chunks...", _pruneChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.discardAllChunks()
Beispiel #31
0
        self.editor.saveFile()

        def _pruneChunks():
            maxChunks = self.editor.level.chunkCount
            selectedChunks = self.selectedChunks()
            for i, cPos in enumerate(list(self.editor.level.allChunks)):
                if cPos not in selectedChunks:
                    try:
                        self.editor.level.deleteChunk(*cPos)

                    except Exception, e:
                        print "Error during chunk delete: ", e

                yield i, maxChunks

        with setWindowCaption("PRUNING - "):
            showProgress("Pruning chunks...", _pruneChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.discardAllChunks()

        # self.editor.addUnsavedEdit()

    @alertException
    def relightChunks(self):
        def _relightChunks():
            for i in self.editor.level.generateLightsIter(
                    self.selectedChunks()):
                yield i

        with setWindowCaption("RELIGHTING - "):
Beispiel #32
0
        self.editor.saveFile()

        def _pruneChunks():
            maxChunks = self.editor.level.chunkCount
            selectedChunks = self.selectedChunks()
            for i, cPos in enumerate(list(self.editor.level.allChunks)):
                if cPos not in selectedChunks:
                    try:
                        self.editor.level.deleteChunk(*cPos)

                    except Exception, e:
                        print "Error during chunk delete: ", e

                yield i, maxChunks

        with setWindowCaption("PRUNING - "):
            showProgress("Pruning chunks...", _pruneChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.discardAllChunks()

        # self.editor.addUnsavedEdit()

    @alertException
    def relightChunks(self):

        def _relightChunks():
            for i in self.editor.level.generateLightsIter(self.selectedChunks()):
                yield i

        with setWindowCaption("RELIGHTING - "):
Beispiel #33
0
class ChunkTool(EditorTool):
    toolIconName = "chunk"
    tooltipText = "Chunk Control"

    @property
    def statusText(self):
        return _(
            "Click and drag to select chunks. Hold {0} to deselect chunks. Hold {1} to select chunks."
        ).format(_(config.keys.deselectChunks.get()),
                 _(config.keys.selectChunks.get()))

    def toolEnabled(self):
        return isinstance(self.editor.level, pymclevel.ChunkedLevelMixin)

    _selectedChunks = None
    _displayList = None

    def drawToolMarkers(self):
        if self._displayList is None:
            self._displayList = DisplayList(self._drawToolMarkers)

        # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks)

        if self._selectedChunks != self.editor.selectedChunks or True:  # xxx
            self._selectedChunks = set(self.editor.selectedChunks)
            self._displayList.invalidate()

        self._displayList.call()

    def _drawToolMarkers(self):

        lines = (
            ((-1, 0), (0, 0, 0, 1), []),
            ((1, 0), (1, 0, 1, 1), []),
            ((0, -1), (0, 0, 1, 0), []),
            ((0, 1), (0, 1, 1, 1), []),
        )
        for ch in self._selectedChunks:
            cx, cz = ch
            for (dx, dz), points, positions in lines:
                n = (cx + dx, cz + dz)
                if n not in self._selectedChunks:
                    positions.append([ch])

        color = self.editor.selectionTool.selectionColor + (0.3, )
        GL.glColor(*color)
        with gl.glEnable(GL.GL_BLEND):

            import renderer

            sizedChunks = renderer.chunkMarkers(self._selectedChunks)
            for size, chunks in sizedChunks.iteritems():
                if not len(chunks):
                    continue
                chunks = numpy.array(chunks, dtype='float32')

                chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3),
                                            dtype='float32')
                chunkPosition[..., (0, 2)] = numpy.array(
                    ((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32')
                chunkPosition[..., (0, 2)] *= size
                chunkPosition[..., (0, 2)] += chunks[:, newaxis, :]
                chunkPosition *= 16
                chunkPosition[..., 1] = self.editor.level.Height
                GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel())
                # chunkPosition *= 8
                GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4)

        for d, points, positions in lines:
            if 0 == len(positions):
                continue
            vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32')
            vertexArray[..., [0, 2]] = positions
            vertexArray.shape = len(positions), 2, 2, 3

            vertexArray[..., 0, 0, 0] += points[0]
            vertexArray[..., 0, 0, 2] += points[1]
            vertexArray[..., 0, 1, 0] += points[2]
            vertexArray[..., 0, 1, 2] += points[3]
            vertexArray[..., 1, 0, 0] += points[2]
            vertexArray[..., 1, 0, 2] += points[3]
            vertexArray[..., 1, 1, 0] += points[0]
            vertexArray[..., 1, 1, 2] += points[1]

            vertexArray *= 16

            vertexArray[..., 1, :, 1] = self.editor.level.Height

            GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray)
            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
            GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4)
            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
            with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST):
                GL.glDepthMask(False)
                GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4)
                GL.glDepthMask(True)

    @property
    def worldTooltipText(self):
        box = self.editor.selectionTool.selectionBoxInProgress()
        if box:
            box = box.chunkBox(self.editor.level)
            l, w = box.length // 16, box.width // 16
            return _("%s x %s chunks") % (l, w)

    def toolSelected(self):

        self.editor.selectionToChunks()

        self.panel = ChunkToolPanel(self)

        self.panel.centery = self.editor.centery
        self.panel.left = 10

        self.editor.add(self.panel)

    def toolDeselected(self):
        self.editor.chunksToSelection()

    def cancel(self):
        self.editor.remove(self.panel)

    def selectedChunks(self):
        return self.editor.selectedChunks

    @alertException
    def destroyChunks(self, chunks=None):
        if "No" == ask("Really delete these chunks? This cannot be undone.",
                       ("Yes", "No")):
            return
        if chunks is None:
            chunks = self.selectedChunks()
        chunks = list(chunks)

        def _destroyChunks():
            i = 0
            chunkCount = len(chunks)

            for cx, cz in chunks:
                i += 1
                yield (i, chunkCount)
                if self.editor.level.containsChunk(cx, cz):
                    try:
                        self.editor.level.deleteChunk(cx, cz)
                    except Exception, e:
                        print "Error during chunk delete: ", e

        with setWindowCaption("DELETING - "):
            showProgress("Deleting chunks...", _destroyChunks())

        self.editor.renderer.invalidateChunkMarkers()
        self.editor.renderer.discardAllChunks()