Пример #1
0
class LevelEditorWindow(MegaToplevel):
    notify = directNotify.newCategory('LevelEditorWindow')

    def __init__(self, editor, parent=None, **kwargs):
        MegaToplevel.__init__(self, parent)

        self.editor = editor

        self.hull = self.component('hull')
        self.hull.geometry('400x625')

        self.menuFrame = Frame(self.hull, relief=GROOVE, bd=2)
        self.menuFrame.pack(fill=X)

        self.menuBar = MenuBar(self.menuFrame, hotkeys=1)
        self.menuBar.pack(side=LEFT, expand=1, fill=X)
        self.menuBar.addmenu('File', 'File')
        self.menuBar.addmenuitem('File',
                                 'command',
                                 'Load resources from directory',
                                 label='Load resources',
                                 command=self.editor.loadResources)
        self.menuBar.addmenuitem('File',
                                 'command',
                                 'Create new world',
                                 label='New world',
                                 command=self.newWorld)
        self.menuBar.addmenuitem('File',
                                 'command',
                                 'Create new location',
                                 label='New location',
                                 command=self.newLocation)
        self.menuBar.addmenuitem('File',
                                 'command',
                                 'Open world',
                                 label='Open',
                                 command=self.editor.loadWorld)
        self.menuBar.addmenuitem('File',
                                 'command',
                                 'Save world',
                                 label='Save',
                                 command=self.editor.saveWorld)

        self.notebook = NoteBook(self.hull)
        self.notebook.pack(fill=BOTH, expand=1)

        self.currentModel = ''

        self.modelPage = self.notebook.add('Models')
        self.otherPage = self.notebook.add('Other')

        self.modelLabel = Label(self.modelPage,
                                text='Models',
                                font=('Segoe UI', 14, ''))
        self.modelLabel.pack(expand=0)

        self.otherLabel = Label(self.otherPage,
                                text='Other',
                                font=('Segoe UI', 14, ''))
        self.otherLabel.pack(expand=0)

        self.addFamilyButton = Button(self.otherPage,
                                    text='Add Family',
                                    command=self.addFamily)
        self.addFamilyButton.pack()
        self.addFamilyButton.configure(state='disable')

        self.addFamilyDialog = Dialog(buttons=('Add Family',),
                                     title='Add Family',
                                     command=self.editor.addFamily)
        self.addFamilyDialog.geometry('300x300')
        self.addFamilyDialog.withdraw()

        self.addFamilyLabel = Label(self.addFamilyDialog.interior(),
                                   text='Set the new family file')
        self.addFamilyLabel.pack()

        self.addFamilyField = EntryField(self.addFamilyDialog.interior())
        self.addFamilyField.pack(fill=BOTH, expand=1)

        self.addLinkButton = Button(self.otherPage,
                                    text='Add Link',
                                    command=self.addLink)
        self.addLinkButton.pack()
        self.addLinkButton.configure(state='disable')

        self.addLinkDialog = Dialog(buttons=('Add Link',),
                                     title='Add Link',
                                     command=self.editor.addLink)
        self.addLinkDialog.geometry('300x300')
        self.addLinkDialog.withdraw()

        self.addLinkLabel = Label(self.addLinkDialog.interior(),
                                   text='Set link name and select direction')
        self.addLinkLabel.pack()

        self.addLinkField = EntryField(self.addLinkDialog.interior())
        self.addLinkField.pack(fill=BOTH, expand=1)

        self.addLinkBox = Listbox(self.addLinkDialog.interior())
        self.addLinkBox.pack(fill=BOTH, expand=1)

        for item in ['Bi-directional', 'Direction 1', 'Direction 2']:
            self.addLinkBox.insert(END, item)

        self.addTableButton = Button(self.otherPage,
                                    text='Add Table',
                                    command=self.addTable)
        self.addTableButton.pack()
        self.addTableButton.configure(state='disable')

        self.addTableDialog = Dialog(buttons=('Add Table',),
                                     title='Add Table',
                                     command=self.editor.addTable)
        self.addTableDialog.geometry('300x300')
        self.addTableDialog.withdraw()

        self.addTableLabel = Label(self.addTableDialog.interior(),
                                   text='Set table name and data')
        self.addTableLabel.pack()

        self.addTableName = EntryField(self.addTableDialog.interior())
        self.addTableName.pack(fill=BOTH, expand=1)

        self.addTableData = EntryField(self.addTableDialog.interior())
        self.addTableData.pack(fill=BOTH, expand=1)

        self.updateObjButton = Button(self.otherPage,
                                    text='Update Object',
                                    command=self.updateObj)
        self.updateObjButton.pack()
        self.updateObjButton.configure(state='disable')

        self.updateObjDialog = Dialog(buttons=('Update Object',),
                                     title='Update Object',
                                     command=self.editor.updateObj)
        self.updateObjDialog.geometry('300x300')
        self.updateObjDialog.withdraw()

        self.updateObjLabel = Label(self.updateObjDialog.interior(),
                                   text='Set a field name then data in object')
        self.updateObjLabel.pack()

        self.updateObjName = EntryField(self.updateObjDialog.interior())
        self.updateObjName.pack(fill=BOTH, expand=1)

        self.updateObjData = EntryField(self.updateObjDialog.interior())
        self.updateObjData.pack(fill=BOTH, expand=1)

        self.loadModelButton = Button(self.modelPage,
                                      text='Load model',
                                      command=self.loadModel)
        self.loadModelButton.pack(padx=20, pady=10)
        self.loadModelButton.configure(state='disable')

        self.modelSelector = ComboBox(self.modelPage,
                                      dropdown=0,
                                      listheight=200,
                                      entry_width=30,
                                      selectioncommand=self.setModel)
        self.modelSelector.pack(expand=1, fill=BOTH)

        self.newWorldDialog = Dialog(buttons=('Create World',),
                                     title='New World',
                                     command=self.editor.newWorld)
        self.newWorldDialog.geometry('300x300')
        self.newWorldDialog.withdraw()

        self.newWorldLabel = Label(self.newWorldDialog.interior(),
                                   text='Set the name of the world')
        self.newWorldLabel.pack()

        self.newWorldField = EntryField(self.newWorldDialog.interior())
        self.newWorldField.pack(fill=BOTH, expand=1)

        self.newLocationDialog = Dialog(buttons=('Create Location',),
                                     title='New Location',
                                     command=self.editor.newLocation)
        self.newLocationDialog.geometry('350x100')
        self.newLocationDialog.withdraw()

        self.newLocationLabel = Label(self.newLocationDialog.interior(),
                                   text='Set the name then model of the location')
        self.newLocationLabel.pack()

        self.newLocationNameField = EntryField(self.newLocationDialog.interior())
        self.newLocationNameField.pack(fill=BOTH, expand=1)

        self.newLocationModelField = EntryField(self.newLocationDialog.interior())
        self.newLocationModelField.pack(fill=BOTH, expand=1)

        self.newModelDialog = Dialog(buttons=('Create Object',),
                                     title='New Model',
                                     command=self.editor.loadModel)
        self.newModelDialog.geometry('250x150')
        self.newModelDialog.withdraw()

        self.newModelHeight = 150

        self.newModelLabel = Label(self.newModelDialog.interior(),
                                   text='Set the type, name (optional), color (optional)\n of the object, and any other fields...')
        self.newModelLabel.pack()

        self.newModelType = EntryField(self.newModelDialog.interior())
        self.newModelType.pack(fill=BOTH, expand=1)

        self.newModelName = EntryField(self.newModelDialog.interior())
        self.newModelName.pack(fill=BOTH, expand=1)

        self.newModelColor = EntryField(self.newModelDialog.interior())
        self.newModelColor.pack(fill=BOTH, expand=1)

        self.newModelPlus = Button(self.newModelDialog.interior(),
                                   text='+',
                                   command=self.plusField)
        self.newModelPlus.pack(fill=BOTH, expand=1)

        self.newModelFields = []

        self.initialiseoptions(LevelEditorWindow)

    def setModel(self, model):
        if not model:
            return

        if model not in self.editor.modelPaths:
            self.modelSelector.delete(self.modelSelector.curselection()[0])
            return

        self.currentModel = model

    def loadModel(self):
        if not self.currentModel:
            return

        self.newModelDialog.activate()

    def newLocation(self):
        self.newLocationDialog.activate()

    def newWorld(self):
        self.newWorldDialog.activate()

    def addFamily(self):
        self.addFamilyDialog.activate()

    def addLink(self):
        self.editor.userSelect(2, self.addLinkSelected)

    def addLinkSelected(self):
        self.addLinkDialog.activate()

    def addTable(self):
        self.addTableDialog.activate()

    def updateObj(self):
        self.editor.userSelect(1, self.updateObjSelected)

    def updateObjSelected(self):
        self.updateObjDialog.activate()

    def plusField(self):
        _field = EntryField(self.newModelDialog.interior())
        _field.pack(fill=BOTH, expand=1)

        self.newModelHeight += 50
        self.newModelDialog.geometry('250x' + str(self.newModelHeight))
        self.newModelDialog.update_idletasks()

        self.newModelFields.append(_field)

    def showResources(self, paths=[]):
        if not paths:
            paths = self.editor.modelPaths
        else:
            for path in paths:
                self.editor.modelPaths.add(path)

        for resource in paths:
            oldItems = self.modelSelector.get()
            if isinstance(oldItems, str):
                oldItems = ()

            self.modelSelector.setlist(oldItems + (resource,))