Exemplo n.º 1
0
 def backupWorldFromList(self, filename):
     NotImplementedYet()
Exemplo n.º 2
0
 def createNewWorld(self):
     NotImplementedYet()
Exemplo n.º 3
0
 def repairWorldFromList(self, filename):
     NotImplementedYet()
Exemplo n.º 4
0
    def __init__(self,
                 filename,
                 versionInfo,
                 readonly=False,
                 progressCallback=None):
        progressMax = 7  # fixme
        if progressCallback is None:

            def progress(status):
                pass
        else:

            def progress(status):
                progressCallback(progress.progressCount, progressMax, status)
                progress.progressCount += 1

            progress.progressCount = 0

        QtCore.QObject.__init__(self)
        self.undoStack = MCEUndoStack()

        self.filename = filename
        self.dockWidgets = []
        self.undoBlock = None
        self.currentTool = None
        self.dirty = False

        self.copiedSchematic = None
        """:type : WorldEditor"""

        self.versionInfo = versionInfo

        # --- Open world editor ---
        try:
            progress("Creating WorldEditor...")
            self.worldEditor = WorldEditor(filename, readonly=readonly)
        except UndoFolderExists:
            msgBox = QtGui.QMessageBox()
            msgBox.setIcon(QtGui.QMessageBox.Warning)
            msgBox.setWindowTitle(self.tr("MCEdit tech demo"))
            msgBox.setText(
                self.tr("This world was not properly closed by MCEdit."))
            msgBox.setInformativeText(
                self.
                tr("MCEdit may have crashed. An undo history was found for this world. You may try to resume editing "
                   "with the saved undo history, or start over with the current state of the world."
                   ))
            resumeBtn = msgBox.addButton("Resume Editing",
                                         QtGui.QMessageBox.ApplyRole)
            msgBox.addButton("Discard History",
                             QtGui.QMessageBox.DestructiveRole)
            # msgBox.exec_()
            # clicked = msgBox.clickedButton()
            clicked = None  # xxxxx
            resume = clicked is resumeBtn
            try:
                self.worldEditor = WorldEditor(filename,
                                               readonly=readonly,
                                               resume=resume)
            except NotImplementedError:
                NotImplementedYet()
                raise IOError("Uh-oh")

        self.worldEditor.requireRevisions()
        self.currentDimension = None

        progress("Creating menus...")

        # --- Menus ---

        self.menus = []

        # - Edit -

        self.menuEdit = QtGui.QMenu(self.tr("Edit"))
        self.menuEdit.setObjectName("menuEdit")

        self.actionCut = QtGui.QAction(self.tr("Cut"),
                                       self,
                                       triggered=self.cut,
                                       enabled=False)
        self.actionCut.setShortcut(QtGui.QKeySequence.Cut)
        self.actionCut.setObjectName("actionCut")

        self.actionCopy = QtGui.QAction(self.tr("Copy"),
                                        self,
                                        triggered=self.copy,
                                        enabled=False)
        self.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
        self.actionCopy.setObjectName("actionCopy")

        self.actionPaste = QtGui.QAction(self.tr("Paste"),
                                         self,
                                         triggered=self.paste,
                                         enabled=False)
        self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
        self.actionPaste.setObjectName("actionPaste")

        self.actionPaste_Blocks = QtGui.QAction(self.tr("Paste Blocks"),
                                                self,
                                                triggered=self.pasteBlocks,
                                                enabled=False)
        self.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
        self.actionPaste_Blocks.setObjectName("actionPaste_Blocks")

        self.actionPaste_Entities = QtGui.QAction(self.tr("Paste Entities"),
                                                  self,
                                                  triggered=self.pasteEntities,
                                                  enabled=False)
        self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
        self.actionPaste_Entities.setObjectName("actionPaste_Entities")

        self.actionClear = QtGui.QAction(self.tr("Delete"),
                                         self,
                                         triggered=self.deleteSelection,
                                         enabled=False)
        self.actionClear.setShortcut(QtGui.QKeySequence.Delete)
        self.actionClear.setObjectName("actionClear")

        self.actionDeleteBlocks = QtGui.QAction(self.tr("Delete Blocks"),
                                                self,
                                                triggered=self.deleteBlocks,
                                                enabled=False)
        self.actionDeleteBlocks.setShortcut(QtGui.QKeySequence("Shift+Del"))
        self.actionDeleteBlocks.setObjectName("actionDeleteBlocks")

        self.actionDeleteEntities = QtGui.QAction(
            self.tr("Delete Entities"),
            self,
            triggered=self.deleteEntities,
            enabled=False)
        self.actionDeleteEntities.setShortcut(
            QtGui.QKeySequence("Shift+Alt+Del"))
        self.actionDeleteEntities.setObjectName("actionDeleteEntities")

        self.actionFill = QtGui.QAction(self.tr("Fill"),
                                        self,
                                        triggered=self.fill,
                                        enabled=False)
        self.actionFill.setShortcut(QtGui.QKeySequence("Shift+Ctrl+F"))
        self.actionFill.setObjectName("actionFill")

        self.actionFindReplace = QtGui.QAction(self.tr("Find/Replace"),
                                               self,
                                               triggered=self.findReplace,
                                               enabled=True)
        self.actionFindReplace.setShortcut(QtGui.QKeySequence.Find)
        self.actionFindReplace.setObjectName("actionFindReplace")

        undoAction = self.undoStack.createUndoAction(self.menuEdit)
        undoAction.setShortcut(QtGui.QKeySequence.Undo)
        redoAction = self.undoStack.createRedoAction(self.menuEdit)
        redoAction.setShortcut(QtGui.QKeySequence.Redo)

        self.menuEdit.addAction(undoAction)
        self.menuEdit.addAction(redoAction)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionCut)
        self.menuEdit.addAction(self.actionCopy)
        self.menuEdit.addAction(self.actionPaste)
        self.menuEdit.addAction(self.actionPaste_Blocks)
        self.menuEdit.addAction(self.actionPaste_Entities)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionClear)
        self.menuEdit.addAction(self.actionDeleteBlocks)
        self.menuEdit.addAction(self.actionDeleteEntities)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionFill)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionFindReplace)

        self.menus.append(self.menuEdit)

        # - Select -

        self.menuSelect = QtGui.QMenu(self.tr("Select"))

        self.actionSelectAll = QtGui.QAction(self.tr("Select All"),
                                             self,
                                             triggered=self.selectAll)
        self.actionSelectAll.setShortcut(QtGui.QKeySequence.SelectAll)
        self.menuSelect.addAction(self.actionSelectAll)

        self.actionDeselect = QtGui.QAction(self.tr("Deselect"),
                                            self,
                                            triggered=self.deselect)
        self.actionDeselect.setShortcut(QtGui.QKeySequence("Ctrl+D"))
        self.menuSelect.addAction(self.actionDeselect)

        self.menus.append(self.menuSelect)

        # - Import/Export -

        self.menuImportExport = QtGui.QMenu(self.tr("Import/Export"))

        self.actionExport = QtGui.QAction(self.tr("Export"),
                                          self,
                                          triggered=self.export)
        self.actionExport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+E"))
        self.menuImportExport.addAction(self.actionExport)

        self.actionImport = QtGui.QAction(self.tr("Import"),
                                          self,
                                          triggered=self.import_)
        self.actionImport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+D"))
        self.menuImportExport.addAction(self.actionImport)

        self.actionImport = QtGui.QAction(
            self.tr("Show Exports Library"),
            self,
            triggered=QtGui.qApp.libraryDockWidget.toggleViewAction().trigger)

        self.actionImport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+L"))
        self.menuImportExport.addAction(self.actionImport)

        self.menus.append(self.menuImportExport)

        # --- Resources ---

        progress("Loading resources...")

        i, v, p = self.versionInfo
        self.resourceLoader = i.getResourceLoader(v, p)
        self.geometryCache = GeometryCache()
        self.blockModels = BlockModels(self.worldEditor.blocktypes,
                                       self.resourceLoader)
        self.textureAtlas = TextureAtlas(self.worldEditor, self.resourceLoader,
                                         self.blockModels)

        self.editorOverlay = scenegraph.Node()

        # --- Panels ---
        progress("Loading panels...")

        self.playerPanel = PlayerPanel(self)
        self.panels = [self.playerPanel]

        # --- Tools ---

        progress("Loading tools...")

        self.toolClasses = list(editortools.ToolClasses())
        self.toolActionGroup = QtGui.QActionGroup(self)
        self.tools = [cls(self) for cls in self.toolClasses]
        self.toolActions = [tool.pickToolAction() for tool in self.tools]
        self.actionsByName = {
            action.toolName: action
            for action in self.toolActions
        }
        for tool in self.tools:
            tool.toolPicked.connect(self.chooseTool)
        for action in self.toolActions:
            self.toolActionGroup.addAction(action)

        self.selectionTool = self.getTool("Select")
        self.moveTool = self.getTool("Move")

        # --- Dimensions ---

        def _dimChanged(f):
            def _changed():
                self.gotoDimension(f)

            return _changed

        dimButton = self.changeDimensionButton = QtGui.QToolButton()
        dimButton.setText(self.dimensionMenuLabel(""))
        dimAction = self.changeDimensionAction = QtGui.QWidgetAction(self)
        dimAction.setDefaultWidget(dimButton)
        dimMenu = self.dimensionsMenu = QtGui.QMenu()

        for dimName in self.worldEditor.listDimensions():
            displayName = self.dimensionDisplayName(dimName)
            action = dimMenu.addAction(displayName)
            action._changed = _dimChanged(dimName)
            action.triggered.connect(action._changed)

        dimButton.setMenu(dimMenu)
        dimButton.setPopupMode(dimButton.InstantPopup)

        progress("Loading overworld dimension")
        self.gotoDimension("")

        # --- Editor stuff ---
        progress("Creating EditorTab...")

        self.editorTab = EditorTab(self)
        self.toolChanged.connect(self.toolDidChange)

        self.undoStack.indexChanged.connect(self.undoIndexChanged)

        self.findReplaceDialog = FindReplaceDialog(self)
        for resultsWidget in self.findReplaceDialog.resultsWidgets:
            self.dockWidgets.append((Qt.BottomDockWidgetArea, resultsWidget))

        self.inspectorWidget = InspectorWidget(self)
        self.inspectorDockWidget = QtGui.QDockWidget(self.tr("Inspector"),
                                                     objectName="inspector")
        self.inspectorDockWidget.setWidget(self.inspectorWidget)
        self.inspectorDockWidget.hide()
        self.dockWidgets.append(
            (Qt.RightDockWidgetArea, self.inspectorDockWidget))

        if len(self.toolActions):
            self.toolActions[0].trigger(
            )  # Must be called after toolChanged is connected to editorTab

        if hasattr(progress,
                   'progressCount') and progress.progressCount != progressMax:
            log.info("Update progressMax to %d, please.",
                     progress.progressCount)
Exemplo n.º 5
0
 def pasteEntities(self):
     NotImplementedYet()
Exemplo n.º 6
0
 def pasteBlocks(self):
     NotImplementedYet()
Exemplo n.º 7
0
    def __init__(self, filename, versionInfo, readonly=False):
        QtCore.QObject.__init__(self)
        self.undoStack = MCEUndoStack()

        self.filename = filename
        self.dockWidgets = []
        self.undoBlock = None
        self.currentTool = None
        self.dirty = False

        self.copiedSchematic = None
        """:type : WorldEditor"""

        self.versionInfo = versionInfo

        # --- Open world editor ---
        try:
            self.worldEditor = WorldEditor(filename, readonly=readonly)
        except UndoFolderExists:
            msgBox = QtGui.QMessageBox()
            msgBox.setIcon(QtGui.QMessageBox.Warning)
            msgBox.setWindowTitle(self.tr("MCEdit tech demo"))
            msgBox.setText(
                self.tr("This world was not properly closed by MCEdit."))
            msgBox.setInformativeText(
                self.
                tr("MCEdit may have crashed. An undo history was found for this world. You may try to resume editing "
                   "with the saved undo history, or start over with the current state of the world."
                   ))
            resumeBtn = msgBox.addButton("Resume Editing",
                                         QtGui.QMessageBox.ApplyRole)
            msgBox.addButton("Discard History",
                             QtGui.QMessageBox.DestructiveRole)
            # msgBox.exec_()
            # clicked = msgBox.clickedButton()
            clicked = None  # xxxxx
            resume = clicked is resumeBtn
            try:
                self.worldEditor = WorldEditor(filename,
                                               readonly=readonly,
                                               resume=resume)
            except NotImplementedError:
                NotImplementedYet()
                raise IOError("Uh-oh")

        self.worldEditor.requireRevisions()
        self.currentDimension = self.worldEditor.getDimension()
        self.loader = chunkloader.ChunkLoader(self.currentDimension)

        self.loader.chunkCompleted.connect(self.chunkDidComplete)
        self.loader.allChunksDone.connect(
            lambda: self.editorTab.currentView().update())

        # --- Menus ---

        self.menus = []

        self.menuEdit = QtGui.QMenu(self.tr("Edit"))
        self.menuEdit.setObjectName("menuEdit")
        self.actionCut = QtGui.QAction(self.tr("Cut"),
                                       self,
                                       triggered=self.cut,
                                       enabled=False)
        self.actionCut.setObjectName("actionCut")
        self.actionCopy = QtGui.QAction(self.tr("Copy"),
                                        self,
                                        triggered=self.copy,
                                        enabled=False)
        self.actionCopy.setObjectName("actionCopy")
        self.actionPaste = QtGui.QAction(self.tr("Paste"),
                                         self,
                                         triggered=self.paste,
                                         enabled=False)
        self.actionPaste.setObjectName("actionPaste")
        self.actionPaste_Blocks = QtGui.QAction(self.tr("Paste Blocks"),
                                                self,
                                                triggered=self.pasteBlocks,
                                                enabled=False)
        self.actionPaste_Blocks.setObjectName("actionPaste_Blocks")
        self.actionPaste_Entities = QtGui.QAction(self.tr("Paste Entities"),
                                                  self,
                                                  triggered=self.pasteEntities,
                                                  enabled=False)
        self.actionPaste_Entities.setObjectName("actionPaste_Entities")
        self.actionClear = QtGui.QAction(self.tr("Clear"),
                                         self,
                                         triggered=self.clear,
                                         enabled=False)
        self.actionClear.setObjectName("actionClear")

        undoAction = self.undoStack.createUndoAction(self.menuEdit)
        undoAction.setShortcut(QtGui.QKeySequence.Undo)
        redoAction = self.undoStack.createRedoAction(self.menuEdit)
        redoAction.setShortcut(QtGui.QKeySequence.Redo)
        self.menuEdit.addAction(undoAction)
        self.menuEdit.addAction(redoAction)
        self.menuEdit.addSeparator()
        self.menuEdit.addAction(self.actionCut)
        self.menuEdit.addAction(self.actionCopy)
        self.menuEdit.addAction(self.actionPaste)
        self.menuEdit.addAction(self.actionPaste_Blocks)
        self.menuEdit.addAction(self.actionPaste_Entities)
        self.menuEdit.addAction(self.actionClear)

        self.actionCut.setShortcut(QtGui.QKeySequence.Cut)
        self.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
        self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
        self.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
        self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
        self.actionClear.setShortcut(QtGui.QKeySequence.Quit)

        self.menus.append(self.menuEdit)

        # --- Resources ---

        i, v, p = self.versionInfo
        self.resourceLoader = i.getResourceLoader(v, p)
        self.geometryCache = GeometryCache()
        self.blockModels = BlockModels(self.worldEditor.blocktypes,
                                       self.resourceLoader)
        self.textureAtlas = TextureAtlas(self.worldEditor, self.resourceLoader,
                                         self.blockModels)

        self.editorOverlay = scenegraph.Node()

        # --- Panels ---

        self.playerPanel = PlayerPanel(self)
        self.panels = [self.playerPanel]

        # --- Tools ---
        def PickToolAction(tool):
            name = tool.name
            iconName = tool.iconName
            if iconName:
                iconPath = resourcePath(
                    "mcedit2/assets/mcedit2/toolicons/%s.png" % iconName)
                if not os.path.exists(iconPath):
                    log.error("Tool icon %s not found", iconPath)
                    icon = None
                else:
                    icon = QtGui.QIcon(iconPath)
            else:
                icon = None

            def _triggered():
                self.chooseTool(name)

            action = QtGui.QAction(
                self.tr(name),
                self,
                #shortcut=self.toolShortcut(name),  # xxxx coordinate with view movement keys
                triggered=_triggered,
                checkable=True,
                icon=icon,
            )
            action.toolName = name
            action._triggered = _triggered  # Needed because connecting _triggered doesn't increase its refcount

            self.toolActionGroup.addAction(action)
            return action

        self.toolClasses = list(editortools.ToolClasses())
        self.toolActionGroup = QtGui.QActionGroup(self)
        self.toolActions = [PickToolAction(cls) for cls in self.toolClasses]
        self.actionsByName = {
            action.toolName: action
            for action in self.toolActions
        }
        self.tools = {cls.name: cls(self) for cls in self.toolClasses}

        self.selectionTool = self.tools["Select"]
        self.moveTool = self.tools["Move"]

        # --- Editor stuff ---
        self.editorTab = EditorTab(self)
        self.toolChanged.connect(self.editorTab.toolDidChange)

        self.undoStack.indexChanged.connect(self.undoIndexChanged)

        if len(self.toolActions):
            self.toolActions[0].trigger(
            )  # Must be called after toolChanged is connected to editorTab