Exemple #1
0
	def onLoad( self ):
		#UI
		self.container = self.requestDockWindow( 'QuestSessionManager',
			title     = 'Quest',
			size      = (120,120),
			minSize   = (120,120),
			dock      = 'left',
			toolWindow =  False
		)

		self.window = window = self.container.addWidgetFromFile(
			_getModulePath('container.ui')
		)

		#Components
		leftLayout = QtWidgets.QVBoxLayout( window.containerLeft )
		leftLayout.setSpacing( 0 )
		leftLayout.setContentsMargins( 0 , 0 , 0 , 0 )

		rightLayout = QtWidgets.QVBoxLayout( window.containerRight )
		rightLayout.setSpacing( 0 )
		rightLayout.setContentsMargins( 0 , 0 , 0 , 0 )

		self.treeFilter = GenericTreeFilter( window.containerRight )
		self.treeFilter.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed )
		self.tree = QuestSchemeTreeWidget( window.containerLeft )
		self.treeFilter.setTargetTree( self.tree )
		self.toolbar = QtWidgets.QToolBar( window.containerLeft )
		self.toolbar.setOrientation( Qt.Horizontal )
		self.toolbar.setMaximumHeight( 32 )

		self.graphView = QuestSchemeGraphView( 
			parent = window.containerRight,
			use_gl = False,
			antialias = True
		)

		leftLayout.addWidget( self.toolbar )
		leftLayout.addWidget( self.treeFilter )
		leftLayout.addWidget( self.tree )

		rightLayout.addWidget( self.graphView )

		self.addToolBar( 'quest_session_manager', self.toolbar )
		self.addTool( 'quest_session_manager/add_session',     label = 'Add', icon = 'add_folder' )
		self.addTool( 'quest_session_manager/----' )
		self.addTool( 'quest_session_manager/add_scheme',      label = 'Add', icon = 'add' )
		self.addTool( 'quest_session_manager/remove_scheme',   label = 'Remove', icon = 'remove' )
		self.addTool( 'quest_session_manager/----' )
		self.addTool( 'quest_session_manager/refresh', label = 'Refresh', icon = 'refresh' )

		
		self.portalRegistry = None
		self.showAllScenePortals = False
		self.updatingSelection = False

		self.currentSchemeEntry = None
		self.currentSession = None
Exemple #2
0
class GizmoVisiblityManagerWidget(QtWidgets.QWidget):
    def __init__(self, *args):
        super(GizmoVisiblityManagerWidget, self).__init__(*args)
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)
        # self.setWindowModality( Qt.ApplicationModal )

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(5, 5, 5, 5)
        layout.setSpacing(5)
        self.buttonReset = QtWidgets.QToolButton(self)
        self.buttonReset.setText('Reset All')
        self.buttonReset.clicked.connect(self.onButtonReset)
        self.treeFilter = GenericTreeFilter(self)
        self.tree = GizmoVisiblityTreeWidget(self)
        label = QtWidgets.QLabel(self)
        label.setText('Gizmo Visiblity:')
        layout.addWidget(label)
        layout.addWidget(self.buttonReset)
        layout.addWidget(self.treeFilter)
        layout.addWidget(self.tree)
        self.treeFilter.setTargetTree(self.tree)
        self.setMinimumSize(250, 400)
        self.setMaximumWidth(250)

    def onButtonReset(self):
        self.view.resetGizmoVisibility()
        self.tree.refreshNodeContent(self.tree.getRootNode(),
                                     updateChildren=True)

    def setParentView(self, view):
        self.view = view
        self.tree.view = view

    def start(self):
        pos = QtGui.QCursor.pos()
        self.move(pos)
        restrainWidgetToScreen(self)
        self.tree.rebuild()
        self.show()
        self.raise_()
        self.tree.setFocus()
        #fit size

    def event(self, ev):
        e = ev.type()
        if e == QEvent.KeyPress and ev.key() == Qt.Key_Escape:
            self.hide()
            self.view.setFocus()

        elif e == QEvent.WindowDeactivate:
            self.hide()
            self.view.setFocus()

        return super(GizmoVisiblityManagerWidget, self).event(ev)
Exemple #3
0
    def onLoad(self):
        #UI
        self.windowTitle = 'Layers'
        self.window = self.requestDockWindow('LayerManager',
                                             title='Layers',
                                             size=(120, 120),
                                             minSize=(120, 120),
                                             dock='left')

        #Components
        self.treeFilter = self.window.addWidget(GenericTreeFilter(),
                                                expanding=False)
        self.tree = self.window.addWidget(
            LayerTreeWidget(self.window,
                            multiple_selection=False,
                            sorting=False,
                            editable=True,
                            drag_mode='internal'))
        self.tree.hasSoloLayer = False
        self.treeFilter.setTargetTree(self.tree)

        self.tool = self.addToolBar('layer_manager', self.window.addToolBar())
        self.delegate = MOAILuaDelegate(self)
        self.delegate.load(_getModulePath('LayerManager.lua'))

        self.addTool('layer_manager/add', label='add', icon='add')
        self.addTool('layer_manager/remove', label='remove', icon='remove')
        self.addTool('layer_manager/up', label='up', icon='arrow-up')
        self.addTool('layer_manager/down', label='down', icon='arrow-down')

        #SIGNALS
        signals.connect('moai.clean', self.onMoaiClean)
Exemple #4
0
    def onLoad(self):
        #UI
        self.window = self.requestDockWindow('GlobalObjectManager',
                                             title='Global Objects',
                                             size=(120, 120),
                                             minSize=(120, 120),
                                             dock='left')

        #Components
        self.treeFilter = self.window.addWidget(GenericTreeFilter(),
                                                expanding=False)
        self.tree = self.window.addWidget(
            GlobalObjectTreeWidget(multiple_selection=True,
                                   editable=True,
                                   drag_mode='internal'))
        self.treeFilter.setTargetTree(self.tree)

        self.tool = self.addToolBar('global_object_manager',
                                    self.window.addToolBar())
        self.delegate = MOAILuaDelegate(self)
        self.delegate.load(_getModulePath('GlobalObjectManager.lua'))

        # self.creatorMenu=self.addMenu(
        # 	'global_object_create',
        # 	{ 'label':'Create Global Object' }
        # 	)

        self.addTool('global_object_manager/add', label='Add', icon='add')
        self.addTool('global_object_manager/remove',
                     label='Remove',
                     icon='remove')
        self.addTool('global_object_manager/clone',
                     label='Clone',
                     icon='clone')
        self.addTool('global_object_manager/add_group',
                     label='Add Group',
                     icon='add_folder')
        self.addTool('global_object_manager/----')
        self.addTool('global_object_manager/refresh',
                     label='Refresh',
                     icon='refresh')

        # self.addMenuItem( 'main/find/find_global_object',
        # 	dict( label = 'Find In Global Objects', shortcut = 'ctrl+alt+f' ) )

        #SIGNALS
        signals.connect('moai.clean', self.onMoaiClean)

        signals.connect('global_object.added', self.onObjectAdded)
        signals.connect('global_object.removed', self.onObjectRemoved)
        signals.connect('global_object.renamed', self.onObjectRenamed)

        if self.getModule('introspector'):
            from . import GlobalObjectNodeEditor

        registerSearchEnumerator(globalObjectNameSearchEnumerator)
        registerSearchEnumerator(globalObjectSearchEnumerator)
Exemple #5
0
    def onLoad(self):
        self.container = self.requestDocumentWindow(
            "MockTextureManager",
            title="TextureManager",
            size=(500, 300),
            minSize=(500, 300),
            # allowDock = False
        )
        self.toolbar = self.addToolBar("texture_manager", self.container.addToolBar())

        self.window = window = self.container.addWidgetFromFile(_getModulePath("TextureManager.ui"))

        self.tree = addWidgetWithLayout(
            TextureTreeWidget(
                window.containerTree, drag_mode="internal", editable=True, multiple_selection=True, expanded=False
            )
        )
        self.tree.module = self

        self.treeFilter = GenericTreeFilter(window.containerTree)
        window.containerTree.layout().insertWidget(0, self.treeFilter)
        self.treeFilter.setTargetTree(self.tree)

        self.propEditor = addWidgetWithLayout(PropertyEditor(window.containerProp))

        self.canvas = addWidgetWithLayout(MOAIEditCanvas(window.containerPreview))
        self.canvas.loadScript(_getModulePath("TextureManager.lua"))

        self.addMenuItem("main/asset/----")
        self.addMenuItem(
            "main/asset/texture_manager", {"label": "Texture Manager", "on_click": lambda menu: self.setFocus()}
        )

        self.addTool("asset/show_texture_manager", label="Texture Manager", on_click=lambda item: self.setFocus())

        self.addTool("texture_manager/add_group", label="Add Group", icon="add")
        self.addTool("texture_manager/remove_group", label="Remove Group", icon="remove")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/assign_group", label="Assign Group", icon="in")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/assign_processor", label="Assign Processor", icon="compose")
        self.addTool("texture_manager/clear_processor", label="Clear Processor", icon="remove")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/rebuild", label="Rebuild", icon="refresh")

        self.addShortcut(self.container, "=", self.regroupTo)
        self.addShortcut(self.container, "-", self.regroup, "default")

        self.propEditor.propertyChanged.connect(self.onPropertyChanged)

        signals.connect("texture.add", self.onTextureAdd)
        signals.connect("texture.remove", self.onTextureRemove)

        registerSearchEnumerator(textureGroupSearchEnumerator)
Exemple #6
0
    def __init__(self, *args):
        super(GizmoVisiblityManagerWidget, self).__init__(*args)
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)
        # self.setWindowModality( Qt.ApplicationModal )

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(5, 5, 5, 5)
        layout.setSpacing(5)
        self.buttonReset = QtWidgets.QToolButton(self)
        self.buttonReset.setText('Reset All')
        self.buttonReset.clicked.connect(self.onButtonReset)
        self.treeFilter = GenericTreeFilter(self)
        self.tree = GizmoVisiblityTreeWidget(self)
        label = QtWidgets.QLabel(self)
        label.setText('Gizmo Visiblity:')
        layout.addWidget(label)
        layout.addWidget(self.buttonReset)
        layout.addWidget(self.treeFilter)
        layout.addWidget(self.tree)
        self.treeFilter.setTargetTree(self.tree)
        self.setMinimumSize(250, 400)
        self.setMaximumWidth(250)
Exemple #7
0
    def __init__(self, *args, **kwargs):
        super(ControlVariableEditorWidget, self).__init__(*args, **kwargs)

        self.target = None

        layout = QtWidgets.QVBoxLayout(self)
        layout.setSpacing(0)
        layout.setContentsMargins(1, 1, 1, 1)
        self.tree = ControlVariableSetTreeWidget(self)
        self.tree.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                QtWidgets.QSizePolicy.Expanding)
        self.filter = GenericTreeFilter(self)
        self.filter.setTargetTree(self.tree)
        self.toolbar = QtWidgets.QToolBar(self)
        self.toolbar.setIconSize(QtCore.QSize(16, 16))
        self.actionAddI = self.toolbar.addAction(getIcon('var_int'), 'Add Int')
        self.actionAddB = self.toolbar.addAction(getIcon('var_boolean'),
                                                 'Add Boolean')
        self.actionAddN = self.toolbar.addAction(getIcon('var_number'),
                                                 'Add Number')
        self.actionAddS = self.toolbar.addAction(getIcon('var_string'),
                                                 'Add String')
        self.actionRemove = self.toolbar.addAction(getIcon('remove'), 'Remove')
        self.toolbar.addSeparator()
        self.actionRefresh = self.toolbar.addAction(getIcon('refresh'),
                                                    'Refresh')
        layout.addWidget(self.toolbar)
        layout.addWidget(self.filter)
        layout.addWidget(self.tree)

        self.actionAddI.triggered.connect(self.onActionAddI)
        self.actionAddN.triggered.connect(self.onActionAddN)
        self.actionAddB.triggered.connect(self.onActionAddB)
        self.actionAddS.triggered.connect(self.onActionAddS)
        self.actionRemove.triggered.connect(self.onActionRemove)
        self.actionRefresh.triggered.connect(self.onActionRefresh)
Exemple #8
0
    def onLoad(self):
        self.updateScheduled = False

        self.searchFilterRootGroup = SearchFilterGroup()
        self.searchFilterRootGroup.setName('__root__')

        self.searchFilter = SearchFilter()
        self.filtering = False
        self.initialSelection = None

        self.currentFolders = []

        self.updatingSelection = False

        self.window = self.requestDockWindow('SceneSearch',
                                             title='Scene Search',
                                             dock='bottom',
                                             minSize=(200, 200))
        self.window.hide()
        ui = self.window.addWidgetFromFile(_getModulePath('SceneSearch.ui'))

        self.splitter = ui.splitter

        #Tree filter
        self.treeSearchFilter = GenericTreeFilter(self.window)
        self.treeSearch = SceneSearchTreeWidget(sorting=True,
                                                multiple_selection=False
                                                # drag_mode = 'internal',
                                                )

        self.treeSearchFilter.setTargetTree(self.treeSearch)
        self.treeSearch.owner = self

        ##
        self.detailList = SceneSearchDetailListWidget()
        self.searchFilterWidget = SceneSearchTagFilterWidget()
        self.statusBar = SceneSearchStatusBar()

        filterToolbar = QtWidgets.QToolBar()
        contentToolbar = QtWidgets.QToolBar()

        self.detailList.owner = self
        self.searchFilterWidget.owner = self
        self.statusBar.owner = self

        self.detailList.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.detailList.customContextMenuRequested.connect(
            self.onItemContextMenu)

        ##
        self.detailListFilter = GenericTreeFilter(self.window)
        self.detailListFilter.setFoldButtonsVisible(False)
        self.detailListFilter.setTargetTree(self.detailList)

        layoutLeft = QtWidgets.QVBoxLayout(ui.containerTree)
        layoutLeft.setSpacing(0)
        layoutLeft.setContentsMargins(0, 0, 0, 0)

        layoutLeft.addWidget(filterToolbar)
        layoutLeft.addWidget(self.treeSearchFilter)
        layoutLeft.addWidget(self.treeSearch)

        layoutRight = QtWidgets.QVBoxLayout(ui.containerRight)
        layoutRight.setSpacing(0)
        layoutRight.setContentsMargins(0, 0, 0, 0)

        layoutRight.addWidget(contentToolbar)
        layoutRight.addWidget(self.detailListFilter)
        layoutRight.addWidget(self.searchFilterWidget)
        layoutRight.addWidget(self.detailList)
        layoutRight.addWidget(self.statusBar)

        ##Tool bar
        self.filterToolBar = self.addToolBar(None, filterToolbar, owner=self)
        self.contentToolBar = self.addToolBar(None, contentToolbar, owner=self)

        self.filterToolBar.addTools([
            dict(name='create_filter', label='Add Filter', icon='add'),
            dict(name='create_filter_group',
                 label='Add Filter Group',
                 icon='add_folder'),
        ])

        self.contentToolBar.addTools([
            dict(name='locate_entity', label='Locate Entity', icon='search'),
        ])

        signals.connect('selection.changed', self.onSelectionChanged)
        signals.connect('scene.change', self.onSceneChange)
        signals.connect('scene.update', self.onSceneUpdate)

        signals.connect('entity.added', self.onEntityAdded)
        signals.connect('entity.removed', self.onEntityRemoved)
        signals.connect('component.added', self.onComponentAdded)
        signals.connect('component.removed', self.onComponentRemoved)
        signals.connect('entity.renamed', self.onEntityModified)
        signals.connect('entity.modified', self.onEntityModified)
        signals.connect('entity.visible_changed', self.onEntityModified)
        signals.connect('entity.pickable_changed', self.onEntityModified)

        self.setSearchFilter(None)
        self.window.show()
        self.loadConfig()
Exemple #9
0
class SceneSearch(SceneEditorModule):
    name = 'scene_search'
    dependency = ['scenegraph_editor']

    def onLoad(self):
        self.updateScheduled = False

        self.searchFilterRootGroup = SearchFilterGroup()
        self.searchFilterRootGroup.setName('__root__')

        self.searchFilter = SearchFilter()
        self.filtering = False
        self.initialSelection = None

        self.currentFolders = []

        self.updatingSelection = False

        self.window = self.requestDockWindow('SceneSearch',
                                             title='Scene Search',
                                             dock='bottom',
                                             minSize=(200, 200))
        self.window.hide()
        ui = self.window.addWidgetFromFile(_getModulePath('SceneSearch.ui'))

        self.splitter = ui.splitter

        #Tree filter
        self.treeSearchFilter = GenericTreeFilter(self.window)
        self.treeSearch = SceneSearchTreeWidget(sorting=True,
                                                multiple_selection=False
                                                # drag_mode = 'internal',
                                                )

        self.treeSearchFilter.setTargetTree(self.treeSearch)
        self.treeSearch.owner = self

        ##
        self.detailList = SceneSearchDetailListWidget()
        self.searchFilterWidget = SceneSearchTagFilterWidget()
        self.statusBar = SceneSearchStatusBar()

        filterToolbar = QtWidgets.QToolBar()
        contentToolbar = QtWidgets.QToolBar()

        self.detailList.owner = self
        self.searchFilterWidget.owner = self
        self.statusBar.owner = self

        self.detailList.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.detailList.customContextMenuRequested.connect(
            self.onItemContextMenu)

        ##
        self.detailListFilter = GenericTreeFilter(self.window)
        self.detailListFilter.setFoldButtonsVisible(False)
        self.detailListFilter.setTargetTree(self.detailList)

        layoutLeft = QtWidgets.QVBoxLayout(ui.containerTree)
        layoutLeft.setSpacing(0)
        layoutLeft.setContentsMargins(0, 0, 0, 0)

        layoutLeft.addWidget(filterToolbar)
        layoutLeft.addWidget(self.treeSearchFilter)
        layoutLeft.addWidget(self.treeSearch)

        layoutRight = QtWidgets.QVBoxLayout(ui.containerRight)
        layoutRight.setSpacing(0)
        layoutRight.setContentsMargins(0, 0, 0, 0)

        layoutRight.addWidget(contentToolbar)
        layoutRight.addWidget(self.detailListFilter)
        layoutRight.addWidget(self.searchFilterWidget)
        layoutRight.addWidget(self.detailList)
        layoutRight.addWidget(self.statusBar)

        ##Tool bar
        self.filterToolBar = self.addToolBar(None, filterToolbar, owner=self)
        self.contentToolBar = self.addToolBar(None, contentToolbar, owner=self)

        self.filterToolBar.addTools([
            dict(name='create_filter', label='Add Filter', icon='add'),
            dict(name='create_filter_group',
                 label='Add Filter Group',
                 icon='add_folder'),
        ])

        self.contentToolBar.addTools([
            dict(name='locate_entity', label='Locate Entity', icon='search'),
        ])

        signals.connect('selection.changed', self.onSelectionChanged)
        signals.connect('scene.change', self.onSceneChange)
        signals.connect('scene.update', self.onSceneUpdate)

        signals.connect('entity.added', self.onEntityAdded)
        signals.connect('entity.removed', self.onEntityRemoved)
        signals.connect('component.added', self.onComponentAdded)
        signals.connect('component.removed', self.onComponentRemoved)
        signals.connect('entity.renamed', self.onEntityModified)
        signals.connect('entity.modified', self.onEntityModified)
        signals.connect('entity.visible_changed', self.onEntityModified)
        signals.connect('entity.pickable_changed', self.onEntityModified)

        self.setSearchFilter(None)
        self.window.show()
        self.loadConfig()

    def onStart(self):
        self.treeSearch.rebuild()
        #search mode
        self.treeSearch.selectNode(self.searchFilter)
        self.searchFilterWidget.rebuild()

    def onStop(self):
        self.saveConfig()

    def saveConfig(self):
        self.saveFilterConfig()
        self.setWorkspaceConfig('splitter_sizes', self.splitter.sizes())

    def loadConfig(self):
        filterData = self.getConfig('filters', None)
        if filterData:
            self.getFilterRootGroup().load(filterData)
        splitterSizes = self.getWorkspaceConfig('splitter_sizes', None)
        if splitterSizes:
            if splitterSizes[0] == 0:
                splitterSizes[0] = 80
            self.splitter.setSizes(splitterSizes)

    def saveFilterConfig(self):
        filterData = self.getFilterRootGroup().save()
        self.setConfig('filters', filterData)

    def setFocus(self):
        self.window.raise_()
        self.detailList.setFocus()

    def onSceneChange(self):
        self.scheduleRebuildItemView()

    def onSceneUpdate(self):
        if self.updateScheduled:
            self.updateScheduled = False
            self.rebuildItemView()

    def onEntityModified(self, entity, *args):
        self.detailList.refreshNodeContent(entity)

    def onEntityAdded(self, entity, context=None):
        self.scheduleRebuildItemView()

    def onEntityRemoved(self, entity):
        self.scheduleRebuildItemView()

    def onComponentAdded(self, com, entity):
        self.scheduleRebuildItemView()

    def onComponentRemoved(self, com, entity):
        self.scheduleRebuildItemView()

    def onSelectionChanged(self, selection, context):
        if context != 'scene': return
        if self.updatingSelection: return
        self.updatingSelection = True
        self.detailList.selectNode(selection)
        self.updatingSelection = False

    def onItemContextMenu(self, point):
        pass

    def getItemSelection(self):
        return self.detailList.getSelection()

    def scheduleRebuildItemView(self):
        self.updateScheduled = True

    def rebuildItemView(self):
        self.updatingSelection = True
        self.detailList.rebuild()
        self.detailListFilter.refresh()
        #sync selection
        self.detailList.selectNode(self.getSelection())
        self.updatingSelection = False

    def onListSelectionChanged(self):
        if self.updatingSelection: return
        self.updatingSelection = True
        selection = self.getItemSelection()
        self.updatingSelection = False
        self.updateStatusBar()
        self.changeSelection(selection)

    def clearSelection(self):
        if self.updatingSelection: return
        self.updatingSelection = True
        self.detailList.selectNode(None)
        self.updatingSelection = False

    def onActivateNode(self, node, src):
        self.doCommand('scene_editor/focus_selection')

    def updateStatusBar(self):
        self.statusBar.hide()
        # self.statusBar.setText( 'no selection' )

    def getEntityInList(self):
        searchFilter = self.searchFilter
        searchFilter.updateRule()
        game = _MOCK.game
        scene = game.getMainScene(game)
        result = []
        for entity in scene.entities.keys():
            if entity.FLAG_EDITOR_OBJECT: continue
            if entity.FLAG_INTERNAL: continue
            info = buildEntitySearchInfo(entity)
            if searchFilter.evaluate(info):
                result.append(entity)
        return result

    def locateEntity(self, entity, **args):
        pass

    def updateTagFilter(self):
        prevFiltering = self.filtering
        self.searchFilter.updateRule()
        self.filtering = self.searchFilter.isFiltering()
        if self.filtering != prevFiltering:
            self.detailList.setProperty('filtered', self.filtering)
            repolishWidget(self.detailList)
        self.rebuildItemView()

    #tool
    def onTool(self, tool):
        name = tool.name
        if name == 'locate_entity':
            self.doCommand('scene_editor/focus_selection')

        elif name in ('create_filter', 'create_filter_group'):
            node = self.treeSearch.getFirstSelection()
            if not node:
                contextGroup = self.getFilterRootGroup()
            elif isinstance(node, SearchFilterGroup):
                contextGroup = node
            else:
                contextGroup = node.getParent()
            if name == 'create_filter':
                node = SearchFilter()
                node.setName('filter')
            else:
                node = SearchFilterGroup()
                node.setName('group')

            contextGroup.addChild(node)

            self.treeSearch.addNode(node)
            self.treeSearch.editNode(node)
            self.treeSearch.selectNode(node)

    def getFilterRootGroup(self):
        return self.searchFilterRootGroup

    def setSearchFilter(self, f):
        if isinstance(f, SearchFilterGroup):
            return

        elif isinstance(f, SearchFilter):
            self.searchFilter = f
            self.searchFilterWidget.setTargetFilter(self.searchFilter)
            self.rebuildItemView()

        else:
            self.searchFilter = SearchFilter()
            self.searchFilterWidget.setTargetFilter(self.searchFilter)

    def renameFilter(self, node, name):
        node.setName(name)
        self.saveFilterConfig()

    def onFilterRequestDelete(self, node):
        if requestConfirm('Confirm Deletion', 'Delete this filter (group)?'):
            node.remove()
        self.setSearchFilter(None)
        self.saveFilterConfig()
        self.searchFilterWidget.rebuild()
        self.treeSearch.rebuild()
Exemple #10
0
    def onLoad(self):
        #UI
        self.windowTitle = 'Scenegraph'
        self.container = self.requestDockWindow('SceneGraphEditor',
                                                title='Scenegraph',
                                                size=(200, 200),
                                                minSize=(200, 200),
                                                dock='left')

        #Components
        self.treeFilter = self.container.addWidget(GenericTreeFilter(
            self.container),
                                                   expanding=False)
        self.tree = self.container.addWidget(
            SceneGraphTreeWidget(self.container,
                                 sorting=True,
                                 editable=True,
                                 multiple_selection=True,
                                 drag_mode='internal'))
        self.treeFilter.setTargetTree(self.tree)
        self.tree.module = self
        self.tool = self.addToolBar('scene_graph', self.container.addToolBar())
        self.delegate = MOAILuaDelegate(self)
        self.delegate.load(getModulePath('SceneGraphEditor.lua'))

        self.entityCreatorMenu = self.addMenu('main/scene/entity_create',
                                              {'label': 'Create Entity'})

        self.componentCreatorMenu = self.addMenu('main/scene/component_create',
                                                 {'label': 'Create Component'})

        #menu
        self.addMenuItem('main/file/open_scene',
                         dict(label='Open Scene', shortcut='ctrl+shift+o'))

        self.addMenuItem('main/file/close_scene',
                         dict(label='Close Scene', shortcut='Ctrl+W'))
        self.addMenuItem('main/scene/save_scene',
                         dict(label='Save', shortcut='Ctrl+S'))
        self.addMenuItem('main/scene/locate_scene_asset',
                         dict(label='Locate Scene Asset'))

        self.addMenu('main/scene/----')

        self.addMenu('component_context', dict(label='Selected Component'))
        self.addMenuItem('component_context/remove_component',
                         dict(label='Remove'))

        self.addMenuItem('component_context/----')

        self.addMenuItem('component_context/copy_component',
                         dict(label='Copy'))
        self.addMenuItem('component_context/paste_component',
                         dict(label='Paste Component Here'))
        self.addMenuItem('component_context/----')

        self.addMenuItem('component_context/move_component_up',
                         dict(label='Move Up'))

        self.addMenuItem('component_context/move_component_down',
                         dict(label='Move Down'))

        self.addMenuItem('component_context/----')
        self.addMenuItem('component_context/edit_component_alias',
                         dict(label='Edit Alias'))

        self.addMenu('main/entity', dict(label='Entity'))
        self.addMenuItem('main/entity/add_empty_entity',
                         dict(label='Create Empty', shortcut='ctrl+alt+N'))
        self.addMenuItem('main/entity/add_entity',
                         dict(label='Create', shortcut='ctrl+shift+N'))
        self.addMenuItem('main/entity/----')
        self.addMenuItem('main/entity/group_entity',
                         dict(label='Group Entites', shortcut='ctrl+G'))
        self.addMenuItem(
            'main/entity/create_group',
            dict(label='Create Empty Group', shortcut='ctrl+shift+G'))
        self.addMenuItem('main/entity/----')
        self.addMenuItem(
            'main/entity/load_prefab',
            dict(label='Load Prefab', shortcut='ctrl+alt+shift+N'))
        self.addMenuItem(
            'main/entity/load_prefab_in_container',
            dict(label='Load Prefab In Container', shortcut='ctrl+shift+='))
        self.addMenuItem('main/entity/----')
        self.addMenuItem('main/entity/remove_entity', dict(label='Remove'))
        self.addMenuItem('main/entity/clone_entity',
                         dict(label='Clone', shortcut='ctrl+d'))
        self.addMenuItem('main/entity/----')
        self.addMenuItem('main/entity/add_component',
                         dict(label='Add Component', shortcut='ctrl+alt+='))
        self.addMenuItem('main/entity/assign_layer',
                         dict(label='Assign Layer', shortcut='ctrl+alt+L'))
        self.addMenuItem('main/entity/toggle_visibility',
                         dict(label='Toggle Visibility', shortcut='ctrl+/'))
        self.addMenuItem('main/entity/freeze_entity_pivot',
                         dict(label='Freeze Pivot'))

        self.addMenuItem('main/entity/----')
        self.addMenuItem('main/find/find_entity',
                         dict(label='Find In Scene', shortcut='ctrl+f'))
        self.addMenuItem('main/find/find_entity_in_group',
                         dict(label='Find In Group', shortcut='ctrl+shift+f'))
        self.addMenuItem('main/find/find_entity_group',
                         dict(label='Find Group', shortcut='ctrl+alt+f'))

        #Toolbars
        self.addTool('scene_graph/select_scene',
                     label='Select Scene',
                     icon='settings')
        self.addTool('scene_graph/----')
        self.addTool('scene_graph/create_group',
                     label='+ Group',
                     icon='add_folder')
        self.addTool('scene_graph/----')
        self.addTool('scene_graph/make_proto',
                     label='Convert To Proto',
                     icon='proto_make')
        self.addTool('scene_graph/create_proto_instance',
                     label='Create Proto Instance',
                     icon='proto_instantiate')
        self.addTool('scene_graph/create_proto_container',
                     label='Create Proto Container',
                     icon='proto_container')
        self.addTool('scene_graph/----')
        self.addTool('scene_graph/fold_all', label='F')
        self.addTool('scene_graph/unfold_all', label='U')
        self.addTool('scene_graph/refresh_tree', label='R')
        # self.addTool( 'scene_graph/load_prefab', label = '+ P' )
        # self.addTool( 'scene_graph/save_prefab', label = '>>P' )

        self.addTool('scene/refresh', label='refresh', icon='refresh')

        #SIGNALS
        signals.connect('moai.clean', self.onMoaiClean)

        signals.connect('scene.clear', self.onSceneClear)
        signals.connect('scene.change', self.onSceneChange)

        signals.connect('selection.changed', self.onSelectionChanged)
        signals.connect('selection.hint', self.onSelectionHint)

        signals.connect('preview.start', self.onPreviewStart)
        signals.connect('preview.stop', self.onPreviewStop)

        # signals.connect( 'animator.start',     self.onAnimatorStart     )
        # signals.connect( 'animator.stop' ,     self.onAnimatorStop      )

        signals.connect('entity.added', self.onEntityAdded)
        signals.connect('entity.removed', self.onEntityRemoved)
        signals.connect('entity.renamed', self.onEntityRenamed)
        signals.connect('entity.modified', self.onEntityModified)
        signals.connect('entity.visible_changed', self.onEntityVisibleChanged)
        signals.connect('entity.pickable_changed',
                        self.onEntityPickableChanged)

        signals.connect('prefab.unlink', self.onPrefabUnlink)
        signals.connect('prefab.relink', self.onPrefabRelink)
        signals.connect('proto.unlink', self.onPrefabUnlink)
        signals.connect('proto.relink', self.onPrefabRelink)

        signals.connect('app.ready', self.postAppReady)

        signals.connect('component.added', self.onComponentAdded)
        signals.connect('component.removed', self.onComponentRemoved)

        signals.connect('project.presave', self.preProjectSave)

        registerSearchEnumerator(sceneObjectSearchEnumerator)
        registerSearchEnumerator(entityNameSearchEnumerator)
        registerSearchEnumerator(componentNameSearchEnumerator)
        registerSearchEnumerator(layerNameSearchEnumerator)
Exemple #11
0
class TextureManager(SceneEditorModule):
    """docstring for MockStyleSheetEditor"""
    def __init__(self):
        super(TextureManager, self).__init__()

    def getName(self):
        return 'mock.texture_manager'

    def getDependency(self):
        return ['qt', 'moai', 'texture_library']

    def onLoad(self):
        self.container = self.requestDocumentWindow(
            'MockTextureManager',
            title='TextureManager',
            size=(500, 300),
            minSize=(500, 300),
            # allowDock = False
        )
        self.toolbar = self.addToolBar('texture_manager',
                                       self.container.addToolBar())

        self.window = window = self.container.addWidgetFromFile(
            _getModulePath('TextureManager.ui'))

        self.tree = addWidgetWithLayout(
            TextureTreeWidget(window.containerTree,
                              drag_mode='internal',
                              editable=True,
                              multiple_selection=True,
                              expanded=False))
        self.tree.module = self

        self.treeFilter = GenericTreeFilter(window.containerTree)
        window.containerTree.layout().insertWidget(0, self.treeFilter)
        self.treeFilter.setTargetTree(self.tree)

        self.propEditor = addWidgetWithLayout(
            PropertyEditor(window.containerProp))

        self.canvas = addWidgetWithLayout(
            MOCKEditCanvas(window.containerPreview))
        self.canvas.loadScript(_getModulePath('TextureManager.lua'))

        self.addMenuItem('main/asset/----')
        self.addMenuItem('main/asset/texture_manager', {
            'label': 'Texture Manager',
            'on_click': lambda menu: self.setFocus()
        })

        self.addTool('texture_manager/rebuild',
                     label='Rebuild',
                     icon='refresh')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/add_group',
                     label='Add Group',
                     icon='add')
        self.addTool('texture_manager/remove_group',
                     label='Remove Group',
                     icon='remove')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/assign_group',
                     label='Assign Group',
                     icon='in')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/assign_processor',
                     label='Assign Processor',
                     icon='compose')
        self.addTool('texture_manager/clear_processor',
                     label='Clear Processor',
                     icon='remove')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/apply', label='Apply Changes')

        self.addShortcut(self.container, '=', self.regroupTo)
        self.addShortcut(self.container, '-', self.regroup, 'default')

        self.propEditor.propertyChanged.connect(self.onPropertyChanged)

        registerSearchEnumerator(textureGroupSearchEnumerator)

    def onStart(self):
        #test data
        lib = self.getModule('texture_library').getLibrary()
        self.canvas.callMethod('preview', 'setLibrary', lib)
        self.tree.rebuild()

        signals.connect('texture.add', self.onTextureAdd)
        signals.connect('texture.remove', self.onTextureRemove)

    def onSetFocus(self):
        self.container.show()
        self.container.raise_()

    def onAssetRegister(self, node):
        if not node.isType('texture'): return
        # self.tree.addNode( node )

    def onAssetUnregister(self, node):
        if not node.isType('texture'): return
        # self.tree.removeNode( node )

    def onPropertyChanged(self, obj, id, value):
        if id in ('name', 'processor'):
            self.tree.refreshNodeContent(obj)
        obj.onFieldChanged(obj, id)

    def onTool(self, tool):
        name = tool.name
        if name == 'add_group':
            g = self.canvas.callMethod('preview', 'addGroup')
            self.tree.addNode(g)
            self.tree.editNode(g)
            self.tree.selectNode(g)

        elif name == 'remove_group':
            self.removeSelectedGroup()

        elif name == 'assign_group':
            self.regroupTo()

        elif name == 'assign_processor':
            requestSearchView(info='select processor to assign',
                              context='asset',
                              type='texture_processor',
                              on_selection=self.assignProcessor)

        elif name == 'clear_processor':
            self.assignProcessor(None)

        elif name == 'rebuild':
            texLib = self.getModule('texture_library')
            assetLib = self.getAssetLibrary()
            for node in self.tree.getSelection():
                clasName = node.getClassName(node)
                if clasName == 'TextureGroup':
                    texLib.scheduleUpdateGroup(node, 'file')
                    # for tex in node.textures.values():
                    # 	assetNode = assetLib.getAssetNode( tex.path )
                    # 	assetNode.markModified()
                    # 	assetLib.scheduleScanProject()
                else:
                    texLib.scheduleUpdateTexture(node, True)
                    # assetNode = assetLib.getAssetNode( node.path )
                    # assetNode.markModified()
                    # assetLib.scheduleScanProject()
        elif name == 'apply':
            texLib = self.getModule('texture_library')
            texLib.scheduleUpdate()

    def onTextureAdd(self, texNode):
        self.tree.addNode(texNode)

    def onTextureRemove(self, texNode):
        self.tree.removeNode(texNode)

    def regroupTo(self):
        requestSearchView(info='select texture group to assign',
                          context='texture_group',
                          on_selection=self.regroup)

    def assignProcessor(self, assetNode):
        path = assetNode and assetNode.getNodePath() or False
        for node in self.tree.getSelection():
            node.processor = path
            self.tree.refreshNodeContent(node)
            if node == self.propEditor.getTarget():
                self.propEditor.refreshAll()

    def getLibrary(self):
        return self.canvas.callMethod('preview', 'getLibrary')

    def getTextureGroups(self):
        lib = self.getLibrary()
        return [group for group in lib.groups.values()]

    def changeSelection(self):
        selection = self.tree.getSelection()
        self.canvas.callMethod('preview', 'changeSelection', selection)
        if len(selection) == 1:
            self.propEditor.setTarget(selection[0])
        else:
            self.propEditor.setTarget(None)

    def renameGroup(self, group, newName):
        group.name = newName

    def removeSelectedGroup(self):
        for node in self.tree.getSelection():
            clasName = node.getClassName(node)
            if clasName == 'TextureGroup':
                if node.default: continue
                #remove groupp, put texutres to default
                self.canvas.callMethod('preview', 'removeGroup', node)
                defaultGroup = self.getLibrary().defaultGroup
                self.tree.removeNode(node)
                self.tree.refreshNode(defaultGroup)
            else:
                #move selected texture to default
                self.canvas.callMethod('preview', 'moveTextureToDefaultGroup',
                                       node)
                self.tree.refreshNode(node)

    def regroup(self, group, refreshTree=True):
        if group == 'default':
            group = self.getLibrary().defaultGroup

        for node in self.tree.getSelection():
            clasName = node.getClassName(node)
            if clasName == 'TextureGroup': continue
            self.canvas.callMethod('preview', 'regroup', node, group)

        if refreshTree:
            self.tree.rebuild()
Exemple #12
0
class ControlVariableEditorWidget(QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super(ControlVariableEditorWidget, self).__init__(*args, **kwargs)

        self.target = None

        layout = QtWidgets.QVBoxLayout(self)
        layout.setSpacing(0)
        layout.setContentsMargins(1, 1, 1, 1)
        self.tree = ControlVariableSetTreeWidget(self)
        self.tree.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                QtWidgets.QSizePolicy.Expanding)
        self.filter = GenericTreeFilter(self)
        self.filter.setTargetTree(self.tree)
        self.toolbar = QtWidgets.QToolBar(self)
        self.toolbar.setIconSize(QtCore.QSize(16, 16))
        self.actionAddI = self.toolbar.addAction(getIcon('var_int'), 'Add Int')
        self.actionAddB = self.toolbar.addAction(getIcon('var_boolean'),
                                                 'Add Boolean')
        self.actionAddN = self.toolbar.addAction(getIcon('var_number'),
                                                 'Add Number')
        self.actionAddS = self.toolbar.addAction(getIcon('var_string'),
                                                 'Add String')
        self.actionRemove = self.toolbar.addAction(getIcon('remove'), 'Remove')
        self.toolbar.addSeparator()
        self.actionRefresh = self.toolbar.addAction(getIcon('refresh'),
                                                    'Refresh')
        layout.addWidget(self.toolbar)
        layout.addWidget(self.filter)
        layout.addWidget(self.tree)

        self.actionAddI.triggered.connect(self.onActionAddI)
        self.actionAddN.triggered.connect(self.onActionAddN)
        self.actionAddB.triggered.connect(self.onActionAddB)
        self.actionAddS.triggered.connect(self.onActionAddS)
        self.actionRemove.triggered.connect(self.onActionRemove)
        self.actionRefresh.triggered.connect(self.onActionRefresh)

    def refresh(self):
        self.tree.rebuild()

    def setTarget(self, target):
        self.target = target
        self.tree.setTarget(target)
        self.toolbar.setEnabled(target and True or False)

    def onActionAddI(self):
        self.onActionAdd('int')

    def onActionAddB(self):
        self.onActionAdd('boolean')

    def onActionAddN(self):
        self.onActionAdd('number')

    def onActionAddS(self):
        self.onActionAdd('string')

    def onActionAdd(self, vtype):
        if not self.target: return
        target = self.target
        newVar = target.addVar(target, 'Var', vtype)
        self.tree.addNode(newVar)
        self.tree.editNode(newVar)
        self.tree.selectNode(newVar)

    def onActionRemove(self):
        if not self.target: return
        selection = self.tree.getSelection()
        for var in selection:
            self.target.removeVar(self.target, var)  #lua
            self.tree.removeNode(var)

    def onActionRefresh(self):
        if not self.target: return
        self.tree.refreshAllContent()
Exemple #13
0
class QuestSessionManager( SceneEditorModule ):
	name = 'quest_session_manager'
	dependency = [ 'mock' ]

	def onLoad( self ):
		#UI
		self.container = self.requestDockWindow( 'QuestSessionManager',
			title     = 'Quest',
			size      = (120,120),
			minSize   = (120,120),
			dock      = 'left',
			toolWindow =  False
		)

		self.window = window = self.container.addWidgetFromFile(
			_getModulePath('container.ui')
		)

		#Components
		leftLayout = QtWidgets.QVBoxLayout( window.containerLeft )
		leftLayout.setSpacing( 0 )
		leftLayout.setContentsMargins( 0 , 0 , 0 , 0 )

		rightLayout = QtWidgets.QVBoxLayout( window.containerRight )
		rightLayout.setSpacing( 0 )
		rightLayout.setContentsMargins( 0 , 0 , 0 , 0 )

		self.treeFilter = GenericTreeFilter( window.containerRight )
		self.treeFilter.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed )
		self.tree = QuestSchemeTreeWidget( window.containerLeft )
		self.treeFilter.setTargetTree( self.tree )
		self.toolbar = QtWidgets.QToolBar( window.containerLeft )
		self.toolbar.setOrientation( Qt.Horizontal )
		self.toolbar.setMaximumHeight( 32 )

		self.graphView = QuestSchemeGraphView( 
			parent = window.containerRight,
			use_gl = False,
			antialias = True
		)

		leftLayout.addWidget( self.toolbar )
		leftLayout.addWidget( self.treeFilter )
		leftLayout.addWidget( self.tree )

		rightLayout.addWidget( self.graphView )

		self.addToolBar( 'quest_session_manager', self.toolbar )
		self.addTool( 'quest_session_manager/add_session',     label = 'Add', icon = 'add_folder' )
		self.addTool( 'quest_session_manager/----' )
		self.addTool( 'quest_session_manager/add_scheme',      label = 'Add', icon = 'add' )
		self.addTool( 'quest_session_manager/remove_scheme',   label = 'Remove', icon = 'remove' )
		self.addTool( 'quest_session_manager/----' )
		self.addTool( 'quest_session_manager/refresh', label = 'Refresh', icon = 'refresh' )

		
		self.portalRegistry = None
		self.showAllScenePortals = False
		self.updatingSelection = False

		self.currentSchemeEntry = None
		self.currentSession = None

	def onAppReady( self ):
		self.tree.rebuild()

	def setCurrentSelection( self, session, schemeEntry ):
		self.currentSession = session
		self.currentSchemeEntry = schemeEntry
		self.graphView.clear()
		if schemeEntry:
			parser = YEdGraphMLParser()
			assetPath = schemeEntry.path
			assetNode = self.getAssetLibrary().getAssetNode( assetPath )
			g = parser.parse( assetNode.getAbsFilePath() )
			if g:
				self.graphView.loadGraph( g )
				self.graphView.fitAll()

	def addSession( self ):
		mgr = _MOCK.getQuestManager()
		session = mgr.addSession( mgr )
		self.tree.addNode( session )
		self.tree.editNode( session )
		return session

	def removeSession( self, session ):
		mgr = _MOCK.getQuestManager()
		mgr.removeSession( mgr, session )
		self.tree.removeNode( session )

	def renameSession( self, session, name ):
		mgr = _MOCK.getQuestManager()
		mgr.renameSession( mgr, session, name )
		self.tree.refreshNodeContent( session )

	def addSchemeEntry( self, assetNode ):
		if not self.currentSession:
			logging.warn( 'no quest session specified' )
			return False
		session = self.currentSession
		schemeEntry = session.addSchemeEntry( session, assetNode.getPath() )
		self.updateQuestNodeList()
		if schemeEntry:
			self.tree.addNode( schemeEntry )
			return schemeEntry

	def updateQuestNodeList( self ):
		pass

	def removeSchemeEntry( self, schemeEntry ):
		if not self.currentSession:
			logging.warn( 'no quest session specified' )
			return False
		self.tree.removeNode( schemeEntry )
		session = self.currentSession
		session.removeSchemeEntry( session, schemeEntry )

	def enumerateSelectableGraphs( self, typeId, context, option ):
		result = []
		session = self.currentSession
		if not session: return []
		for asset in self.getAssetLibrary().iterAssets():
			if asset.getType() != 'quest_scheme': continue
			path = asset.getPath()
			if session.hasScheme( session, path ): continue
			entry = ( asset, path, 'quest_scheme', 'quest_scheme' )
			result.append( entry )
		return result

	def onTool( self, tool ):
		name = tool.name
		if name == 'add_session':
			self.addSession()

		elif name == 'add_scheme':
			if not self.currentSession:
				logging.warn( 'no quest session specified' )
				return False
			requestSearchView( 
				info    = 'select quest scheme to add',
				context = 'quest_scheme',
				on_search = self.enumerateSelectableGraphs,
				on_selection = self.addSchemeEntry
			)

		elif name == 'remove_scheme':
			if not self.currentSession:
				logging.warn( 'no quest session specified' )
				return False
			for node in self.tree.getSelection():
				if isMockInstance( node, 'QuestSessionSchemeEntry' ):
					self.removeSchemeEntry( node )
				elif isMockInstance( node, 'QuestSession' ):
					self.removeSession( node )

		elif name == 'refresh':
			self.tree.rebuild()
Exemple #14
0
    def onLoad(self):
        userSettings = app.getProject().getUserSetting('locale_manager', {})
        self._isAdmin = userSettings.get('is_admin')

        self.currentPackEntry = None
        self.windowTitle = 'Locale Pack Manager'
        self.container = self.requestDocumentWindow('localepackmanager',
                                                    title='Locale Packs',
                                                    size=(500, 300),
                                                    minSize=(500, 300)
                                                    # allowDock = False
                                                    )

        self.tool = self.addToolBar('locale_pack_manager',
                                    self.container.addToolBar())
        self.addTool('locale_pack_manager/refresh',
                     label='Refresh',
                     icon='refresh')
        self.addTool('locale_pack_manager/----')
        self.addTool('locale_pack_manager/locate',
                     label='Locate',
                     icon='search')

        if self._isAdmin:
            self.addTool('locale_pack_manager/----')
            self.addTool('locale_pack_manager/build_source',
                         label='Build Source')
            #self.addTool( 'locale_pack_manager/update_remote',   label = 'Update Remote' )
            self.addTool('locale_pack_manager/----')
            self.addTool('locale_pack_manager/sync_external',
                         label='Sync External')

        self.window = window = self.container.addWidgetFromFile(
            _getModulePath('window.ui'))

        treePacksFilter = addWidgetWithLayout(
            GenericTreeFilter(window.containerLeft))
        self.treePacks = treePacks = addWidgetWithLayout(
            LocalePackTreeWidget(window.containerLeft))
        self.treePacks.module = self
        treePacks.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                QtWidgets.QSizePolicy.Expanding)
        treePacksFilter.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                      QtWidgets.QSizePolicy.Fixed)
        treePacksFilter.setTargetTree(self.treePacks)

        treeItemsFilter = addWidgetWithLayout(
            GenericTreeFilter(window.containerRight))
        self.treeItems = treeItems = addWidgetWithLayout(
            LocalePackItemTreeWidget(window.containerRight))
        self.treeItems.module = self
        treeItems.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                QtWidgets.QSizePolicy.Expanding)
        treeItemsFilter.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                      QtWidgets.QSizePolicy.Fixed)
        treeItemsFilter.setTargetTree(self.treeItems)

        self.addMenuItem('main/asset/----')
        self.addMenuItem(
            'main/asset/locale_pack_manager', {
                'label': 'Locale Pack Manager',
                'on_click': lambda menu: self.setFocus()
            })

        self.mockLocaleManager = None
Exemple #15
0
class ScenePortalManager(SceneEditorModule):
    name = 'scene_portal_manager'
    dependency = ['mock']

    def onLoad(self):
        #UI
        self.container = self.requestDockWindow('ScenePortalManager',
                                                title='Scene Portals',
                                                size=(120, 120),
                                                minSize=(120, 120),
                                                dock='left',
                                                toolWindow=False)

        self.window = window = self.container.addWidgetFromFile(
            _getModulePath('container.ui'))

        #Components
        leftLayout = QtWidgets.QVBoxLayout(window.containerLeft)
        leftLayout.setSpacing(0)
        leftLayout.setContentsMargins(0, 0, 0, 0)

        rightLayout = QtWidgets.QVBoxLayout(window.containerRight)
        rightLayout.setSpacing(0)
        rightLayout.setContentsMargins(0, 0, 0, 0)

        self.treeGraphsFilter = GenericTreeFilter(window.containerRight)
        self.treeGraphsFilter.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Fixed)
        self.treeGraphs = ScenePortalGraphListWidget(window.containerLeft)
        self.treeGraphsFilter.setTargetTree(self.treeGraphs)
        self.treeGraphs.setIndentation(0)
        self.toolbarGraph = QtWidgets.QToolBar(window.containerLeft)
        self.toolbarGraph.setOrientation(Qt.Horizontal)
        self.toolbarGraph.setMaximumHeight(32)

        self.graphView = ScenePortalGraphView(parent=window.containerRight,
                                              use_gl=False,
                                              antialias=True)

        leftLayout.addWidget(self.toolbarGraph)
        leftLayout.addWidget(self.treeGraphsFilter)
        leftLayout.addWidget(self.treeGraphs)

        rightLayout.addWidget(self.graphView)

        self.addToolBar('scene_portal_graph', self.toolbarGraph)
        self.addTool('scene_portal_graph/refresh',
                     label='Refresh',
                     icon='refresh')
        self.addTool('scene_portal_graph/----')
        self.addTool('scene_portal_graph/add_graph', label='Add', icon='add')
        self.addTool('scene_portal_graph/remove_graph',
                     label='Remove',
                     icon='remove')

        self.addMenuItem('main/scene/rebuild_portal_registry',
                         dict(label='Rebuild Portal Data'))

        self.addMenuItem('main/scene/portal_jump',
                         dict(label='Portal Jump', shortcut='Ctrl+Alt+J'))

        signals.connect('selection.changed', self.onSelectionChanged)
        signals.connect('scene.change', self.onSceneChange)

        self.portalRegistry = None
        self.showAllScenePortals = False
        self.updatingSelection = False

    def onStart(self):
        signals.connect('asset.register', self.onAssetRegister)
        signals.connect('asset.unregister', self.onAssetUnregister)
        signals.connect('asset.modified', self.onAssetModified)
        self.loadRegistry()

    def onAppReady(self):
        self.treeGraphs.rebuild()

    def onStop(self):
        self.saveRegistry()

    def clearRegistry(self):
        self.portalRegistry = {}

    def loadRegistry(self):
        self.portalRegistry = JSONHelper.tryLoadJSON(
            self.getProject().getGameConfigPath(_GII_PORTAL_DATA_NAME),
            'portal data')
        if not self.portalRegistry:
            self.portalRegistry = {}
            self.scanPortals()

    def saveRegistry(self):
        JSONHelper.trySaveJSON(
            self.portalRegistry,
            self.getProject().getGameConfigPath(_GII_PORTAL_DATA_NAME),
            'portal data')
        reg = _MOCK.getScenePortalRegistry()
        reg.markDirty(reg)

    def scanPortals(self):
        assetLib = self.getAssetLibrary()
        for assetNode in assetLib.iterAssets():
            if assetNode.getType() == 'scene':
                self.processScenePortal(assetNode)
        self.saveRegistry()

    def clearScenePortal(self, scenePath):
        registry = self.portalRegistry
        toRemove = []
        for key, entry in list(registry.items()):
            if entry['scene'] == scenePath: toRemove.append(key)
        for key in toRemove:
            del registry[key]

    def processScenePortal(self, sceneNode):
        if sceneNode.getType() != 'scene': return
        self.clearScenePortal(sceneNode.getPath())
        if sceneNode.hasTag('deprecated'): return
        registry = self.portalRegistry
        sceneFilePath = sceneNode.getFilePath()
        if os.path.isfile(sceneFilePath):
            sceneData = JSONHelper.tryLoadJSON(sceneFilePath)
        elif os.path.isdir(sceneFilePath):
            sceneData = JSONHelper.tryLoadJSON(sceneFilePath +
                                               '/scene_index.json')

        configData = sceneData and sceneData.get('config', None)
        if not configData: return
        managerData = configData.get('managers', None)
        if not managerData: return
        scenePortalData = managerData.get('ScenePortalManager', None)
        if not scenePortalData: return
        scenePath = sceneNode.getPath()
        prior = sceneNode.getInheritedMetaData('scene_portal_priority', 0)
        for portalData in scenePortalData.get('portals', []):
            name = portalData['name']
            fullname = portalData['fullname']
            prevEntry = registry.get(fullname, None)
            if prevEntry:
                prevScene = prevEntry['scene']
                if prevScene != scenePath:
                    prior0 = prevEntry['priority']
                    if prior < prior0:
                        logging.info(
                            'ignore duplicated portal(low priority): %s @ %s' %
                            (fullname, scenePath))
                        continue
                    elif prior == prior0:
                        #TODO: warn about duplicated portal
                        logging.warning(
                            'duplicated portal ID: %s, found in %s and %s' %
                            (fullname, scenePath, prevScene))
                        continue
            newEntry = {
                'fullname': fullname,
                'name': name,
                'scene': scenePath,
                'data': portalData,
                'priority': prior
            }
            registry[fullname] = newEntry
            logging.info('add portal: %s @ %s' % (fullname, scenePath))

    def locatePortalGroup(self, groupName):
        registry = _MOCK.getScenePortalRegistry()
        scenePath = registry.getPortalGroupDefaultScene(registry, groupName)
        if not scenePath:
            alertMessage('No scene for portal group',
                         'No default scene found for group:' + groupName)
            return False

        node = self.getAssetLibrary().getAssetNode(scenePath)
        if not node:
            alertMessage('No scene found',
                         'Target scene not found:' + scenePath)
            return False

        node.edit()

    def locatePortal(self, portalInfo, select=False):
        if self.updatingSelection: return
        if isinstance(portalInfo, str):  #ID?
            registry = _MOCK.getScenePortalRegistry()
            portalInfo = registry.getPortalInfo(registry, portalInfo)
        if not portalInfo:
            return False
        scenePath = portalInfo.scene
        sceneNode = self.getAssetLibrary().getAssetNode(scenePath)
        if sceneNode:
            guid = portalInfo.data.guid
            editor = self.getModule('scenegraph_editor')
            if editor.getActiveSceneNode() == sceneNode:
                editor.locateEntityByGUID(guid)
            else:
                # if editor.getActiveSceneNode() and ( not requestConfirm( 'Changing Scene', 'opening another scene, proceed?' ) ):
                # 	return
                callLocating = signals.callOnce(
                    'scene.change', lambda: editor.locateEntityByGUID(guid))
                if not editor.openScene(sceneNode):
                    signals.dropCall(callLocating)

    def setCurrentGraph(self, graphNode):
        self.currentGraphNode = graphNode
        if graphNode:
            parser = YEdGraphMLParser()
            assetPath = graphNode.path
            assetNode = self.getAssetLibrary().getAssetNode(assetPath)
            g = parser.parse(assetNode.getAbsFilePath())
            if g:
                self.graphView.loadGraph(g)
                self.graphView.fitAll()
            else:
                self.graphView.clear()

    def locateGraph(self, graph):
        self.getModule('asset_browser').locateAsset(graph.path)

    def getPortalList(self):
        if self.showAllScenePortals:
            registry = _MOCK.getScenePortalRegistry()
            return [info for info in list(registry.portals.values())]
        else:
            return self.getCurrentScenePortals()

    def getCurrentScenePortals(self):
        registry = _MOCK.getScenePortalRegistry()
        editor = self.getModule('scenegraph_editor')
        sceneNode = editor.getActiveSceneNode()
        if not sceneNode: return []
        result = []
        for info in list(registry.portals.values()):
            if info.scene == sceneNode.getPath():
                result.append(info)
        return result

    def onSelectionChanged(self, selection, key):
        #TODO
        pass

    def onSceneChange(self):
        pass

    def onAssetRegister(self, assetNode):
        if assetNode.getType() == 'scene':
            self.processScenePortal(assetNode)
            self.saveRegistry()

    def onAssetUnregister(self, assetNode):
        if assetNode.getType() == 'scene':
            self.clearScenePortal(assetNode.getPath())
            self.saveRegistry()

    def onAssetModified(self, assetNode):
        if assetNode.getType() == 'scene':
            self.processScenePortal(assetNode)
            self.saveRegistry()

    def enumerateSelectableGraphs(self, typeId, context, option):
        result = []
        registry = _MOCK.getScenePortalRegistry()
        for asset in self.getAssetLibrary().iterAssets():
            if asset.getType() != 'scene_portal_graph': continue
            path = asset.getPath()
            if registry.hasGraph(registry, path): continue
            entry = (asset, path, 'portal_graph', 'portal_graph')
            result.append(entry)
        return result

    def promptProtalJump(self):
        entries = [(portal.id, portal.id, 'portal', 'portal')
                   for portal in self.getCurrentScenePortals()]

        def _locateConnectedPortal(id):
            if not self.locateConnectedPortal(id):
                alertMessage('No connection', 'No connected portal found')

        def _locatePortal(selections):
            pass

        requestSearchView(info='select portal to jump',
                          selections=entries,
                          on_selection=_locateConnectedPortal,
                          on_change=_locatePortal)

    def locateConnectedPortal(self, portalId):
        registry = _MOCK.getScenePortalRegistry()
        targetId = registry.findConnectedPortal(registry, portalId)
        if targetId:
            self.locatePortal(targetId)
            return True
        return False

    def addGraph(self, assetNode):
        registry = _MOCK.getScenePortalRegistry()
        graphNode = registry.addGraph(registry, assetNode.getPath())
        self.treeGraphs.addNode(graphNode)

    def removeGraph(self, graphNode):
        registry = _MOCK.getScenePortalRegistry()
        registry.removeGraph(registry, graphNode.getPath(graphNode))
        self.treeGraphs.removeNode(graphNode)

    def onTool(self, tool):
        name = tool.name
        if name == 'add_graph':
            requestSearchView(info='select portal graph to add',
                              context='portal_graph',
                              on_search=self.enumerateSelectableGraphs,
                              on_selection=self.addGraph)

        elif name == 'remove_graph':
            for node in self.treeGraphs.getSelection():
                self.removeGraph(node)

        elif name == 'refresh':
            self.treeGraphs.rebuild()

    def onMenu(self, menu):
        if menu.name == 'rebuild_portal_registry':
            self.clearRegistry()
            self.scanPortals()
            print('done')
        elif menu.name == 'portal_jump':
            self.promptProtalJump()
Exemple #16
0
    def onLoad(self):
        self.container = self.requestDocumentWindow(
            'MockTextureManager',
            title='TextureManager',
            size=(500, 300),
            minSize=(500, 300),
            # allowDock = False
        )
        self.toolbar = self.addToolBar('texture_manager',
                                       self.container.addToolBar())

        self.window = window = self.container.addWidgetFromFile(
            _getModulePath('TextureManager.ui'))

        self.tree = addWidgetWithLayout(
            TextureTreeWidget(window.containerTree,
                              drag_mode='internal',
                              editable=True,
                              multiple_selection=True,
                              expanded=False))
        self.tree.module = self

        self.treeFilter = GenericTreeFilter(window.containerTree)
        window.containerTree.layout().insertWidget(0, self.treeFilter)
        self.treeFilter.setTargetTree(self.tree)

        self.propEditor = addWidgetWithLayout(
            PropertyEditor(window.containerProp))

        self.canvas = addWidgetWithLayout(
            MOCKEditCanvas(window.containerPreview))
        self.canvas.loadScript(_getModulePath('TextureManager.lua'))

        self.addMenuItem('main/asset/----')
        self.addMenuItem('main/asset/texture_manager', {
            'label': 'Texture Manager',
            'on_click': lambda menu: self.setFocus()
        })

        self.addTool('texture_manager/rebuild',
                     label='Rebuild',
                     icon='refresh')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/add_group',
                     label='Add Group',
                     icon='add')
        self.addTool('texture_manager/remove_group',
                     label='Remove Group',
                     icon='remove')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/assign_group',
                     label='Assign Group',
                     icon='in')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/assign_processor',
                     label='Assign Processor',
                     icon='compose')
        self.addTool('texture_manager/clear_processor',
                     label='Clear Processor',
                     icon='remove')
        self.addTool('texture_manager/----')
        self.addTool('texture_manager/apply', label='Apply Changes')

        self.addShortcut(self.container, '=', self.regroupTo)
        self.addShortcut(self.container, '-', self.regroup, 'default')

        self.propEditor.propertyChanged.connect(self.onPropertyChanged)

        registerSearchEnumerator(textureGroupSearchEnumerator)
Exemple #17
0
    def onLoad(self):
        #UI
        self.container = self.requestDockWindow('ScenePortalManager',
                                                title='Scene Portals',
                                                size=(120, 120),
                                                minSize=(120, 120),
                                                dock='left',
                                                toolWindow=False)

        self.window = window = self.container.addWidgetFromFile(
            _getModulePath('container.ui'))

        #Components
        leftLayout = QtWidgets.QVBoxLayout(window.containerLeft)
        leftLayout.setSpacing(0)
        leftLayout.setContentsMargins(0, 0, 0, 0)

        rightLayout = QtWidgets.QVBoxLayout(window.containerRight)
        rightLayout.setSpacing(0)
        rightLayout.setContentsMargins(0, 0, 0, 0)

        self.treeGraphsFilter = GenericTreeFilter(window.containerRight)
        self.treeGraphsFilter.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Fixed)
        self.treeGraphs = ScenePortalGraphListWidget(window.containerLeft)
        self.treeGraphsFilter.setTargetTree(self.treeGraphs)
        self.treeGraphs.setIndentation(0)
        self.toolbarGraph = QtWidgets.QToolBar(window.containerLeft)
        self.toolbarGraph.setOrientation(Qt.Horizontal)
        self.toolbarGraph.setMaximumHeight(32)

        self.graphView = ScenePortalGraphView(parent=window.containerRight,
                                              use_gl=False,
                                              antialias=True)

        leftLayout.addWidget(self.toolbarGraph)
        leftLayout.addWidget(self.treeGraphsFilter)
        leftLayout.addWidget(self.treeGraphs)

        rightLayout.addWidget(self.graphView)

        self.addToolBar('scene_portal_graph', self.toolbarGraph)
        self.addTool('scene_portal_graph/refresh',
                     label='Refresh',
                     icon='refresh')
        self.addTool('scene_portal_graph/----')
        self.addTool('scene_portal_graph/add_graph', label='Add', icon='add')
        self.addTool('scene_portal_graph/remove_graph',
                     label='Remove',
                     icon='remove')

        self.addMenuItem('main/scene/rebuild_portal_registry',
                         dict(label='Rebuild Portal Data'))

        self.addMenuItem('main/scene/portal_jump',
                         dict(label='Portal Jump', shortcut='Ctrl+Alt+J'))

        signals.connect('selection.changed', self.onSelectionChanged)
        signals.connect('scene.change', self.onSceneChange)

        self.portalRegistry = None
        self.showAllScenePortals = False
        self.updatingSelection = False
Exemple #18
0
class TextureManager(SceneEditorModule):
    """docstring for MockStyleSheetEditor"""

    def __init__(self):
        super(TextureManager, self).__init__()

    def getName(self):
        return "mock.texture_manager"

    def getDependency(self):
        return ["qt", "moai", "texture_library"]

    def onLoad(self):
        self.container = self.requestDocumentWindow(
            "MockTextureManager",
            title="TextureManager",
            size=(500, 300),
            minSize=(500, 300),
            # allowDock = False
        )
        self.toolbar = self.addToolBar("texture_manager", self.container.addToolBar())

        self.window = window = self.container.addWidgetFromFile(_getModulePath("TextureManager.ui"))

        self.tree = addWidgetWithLayout(
            TextureTreeWidget(
                window.containerTree, drag_mode="internal", editable=True, multiple_selection=True, expanded=False
            )
        )
        self.tree.module = self

        self.treeFilter = GenericTreeFilter(window.containerTree)
        window.containerTree.layout().insertWidget(0, self.treeFilter)
        self.treeFilter.setTargetTree(self.tree)

        self.propEditor = addWidgetWithLayout(PropertyEditor(window.containerProp))

        self.canvas = addWidgetWithLayout(MOAIEditCanvas(window.containerPreview))
        self.canvas.loadScript(_getModulePath("TextureManager.lua"))

        self.addMenuItem("main/asset/----")
        self.addMenuItem(
            "main/asset/texture_manager", {"label": "Texture Manager", "on_click": lambda menu: self.setFocus()}
        )

        self.addTool("asset/show_texture_manager", label="Texture Manager", on_click=lambda item: self.setFocus())

        self.addTool("texture_manager/add_group", label="Add Group", icon="add")
        self.addTool("texture_manager/remove_group", label="Remove Group", icon="remove")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/assign_group", label="Assign Group", icon="in")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/assign_processor", label="Assign Processor", icon="compose")
        self.addTool("texture_manager/clear_processor", label="Clear Processor", icon="remove")
        self.addTool("texture_manager/----")
        self.addTool("texture_manager/rebuild", label="Rebuild", icon="refresh")

        self.addShortcut(self.container, "=", self.regroupTo)
        self.addShortcut(self.container, "-", self.regroup, "default")

        self.propEditor.propertyChanged.connect(self.onPropertyChanged)

        signals.connect("texture.add", self.onTextureAdd)
        signals.connect("texture.remove", self.onTextureRemove)

        registerSearchEnumerator(textureGroupSearchEnumerator)

    def onStart(self):
        # test data
        lib = self.getModule("texture_library").getLibrary()
        self.canvas.callMethod("preview", "setLibrary", lib)
        self.tree.rebuild()

    def onSetFocus(self):
        self.container.show()
        self.container.raise_()

    def onAssetRegister(self, node):
        if not node.isType("texture"):
            return
        # self.tree.addNode( node )

    def onAssetUnregister(self, node):
        if not node.isType("texture"):
            return
        # self.tree.removeNode( node )

    def onPropertyChanged(self, obj, id, value):
        if id in ("name", "processor"):
            self.tree.refreshNodeContent(obj)

    def onTool(self, tool):
        name = tool.name
        if name == "add_group":
            g = self.canvas.callMethod("preview", "addGroup")
            self.tree.addNode(g)
            self.tree.editNode(g)
            self.tree.selectNode(g)

        elif name == "remove_group":
            self.removeSelectedGroup()

        elif name == "assign_group":
            self.regroupTo()

        elif name == "assign_processor":
            requestSearchView(
                info="select processor to assign",
                context="asset",
                type="texture_processor",
                on_selection=self.assignProcessor,
            )

        elif name == "clear_processor":
            self.assignProcessor(None)

        elif name == "rebuild":
            texLib = self.getModule("texture_library")
            assetLib = self.getAssetLibrary()
            for node in self.tree.getSelection():
                clasName = node.getClassName(node)
                if clasName == "TextureGroup":
                    for tex in node.textures.values():
                        assetNode = assetLib.getAssetNode(tex.path)
                        assetNode.markModified()
                        assetLib.scheduleScanProject()
                else:
                    assetNode = assetLib.getAssetNode(node.path)
                    assetNode.markModified()
                    assetLib.scheduleScanProject()

    def onTextureAdd(self, texNode):
        self.tree.addNode(texNode)

    def onTextureRemove(self, texNode):
        self.tree.removeNode(texNode)

    def regroupTo(self):
        requestSearchView(info="select texture group to assign", context="texture_group", on_selection=self.regroup)

    def assignProcessor(self, assetNode):
        path = assetNode and assetNode.getNodePath() or False
        for node in self.tree.getSelection():
            node.processor = path
            self.tree.refreshNodeContent(node)
            if node == self.propEditor.getTarget():
                self.propEditor.refreshAll()

    def getLibrary(self):
        return self.canvas.callMethod("preview", "getLibrary")

    def getTextureGroups(self):
        lib = self.getLibrary()
        return [group for group in lib.groups.values()]

    def changeSelection(self):
        selection = self.tree.getSelection()
        self.canvas.callMethod("preview", "changeSelection", selection)
        if len(selection) == 1:
            self.propEditor.setTarget(selection[0])
        else:
            self.propEditor.setTarget(None)

    def renameGroup(self, group, newName):
        group.name = newName

    def removeSelectedGroup(self):
        for node in self.tree.getSelection():
            clasName = node.getClassName(node)
            if clasName == "TextureGroup":
                if node.default:
                    continue
                # remove groupp, put texutres to default
                self.canvas.callMethod("preview", "removeGroup", node)
                defaultGroup = self.getLibrary().defaultGroup
                self.tree.removeNode(node)
                self.tree.refreshNode(defaultGroup)
            else:
                # move selected texture to default
                self.canvas.callMethod("preview", "moveTextureToDefaultGroup", node)
                self.tree.refreshNode(node)

    def regroup(self, group, refreshTree=True):
        if group == "default":
            group = self.getLibrary().defaultGroup

        for node in self.tree.getSelection():
            clasName = node.getClassName(node)
            if clasName == "TextureGroup":
                continue
            self.canvas.callMethod("preview", "regroup", node, group)

        if refreshTree:
            self.tree.rebuild()