Example #1
0
        public CAssetEntryViewModel(CAsset asset, CAssetBrowserViewModel viewModel)
        {
            Asset       = asset;
            m_viewModel = viewModel;
            TypeName    = asset.GetTypeName();
            Color       = EditorConversionUtility.ConvertEngineColorToSystem(asset.GetTypeColor());
            BorderColor = new SolidColorBrush(Color);

            Name     = Asset.Name;
            EditName = Name;

            DeleteAssetCommand   = new CRelayCommand(OnDeleteAsset);
            MouseLeftDownCommand = new CRelayCommand(OnMouseLeftDown);
        }
Example #2
0
        public CDirectoryEntry(string directoryPath, CAssetBrowserViewModel viewModel, CDirectoryEntry parent = null)
        {
            ParentDirectory = parent;
            m_viewModel     = viewModel;
            Path            = directoryPath;
            string        absolutePath = ProjectDefinitions.GetAbsolutePath(directoryPath);
            DirectoryInfo dirInfo      = new DirectoryInfo(absolutePath);

            Name     = string.IsNullOrWhiteSpace(directoryPath) ? "Project" : dirInfo.Name;
            EditName = Name;

            UpdateSubDirectories();

            SelectCommand       = new CRelayCommand(OnDirectoryClicked);
            DragEnterCommand    = new CRelayCommand(OnDragEnter);
            DragOverCommand     = new CRelayCommand(OnDragOver);
            DropCommand         = new CRelayCommand(OnDrop);
            AddFolderCommand    = new CRelayCommand(OnAddFolder);
            DeleteFolderCommand = new CRelayCommand(OnDeleteFolder);
        }
Example #3
0
        private void InitializeEntityMenues()
        {
            List <CAddComponentEntryViewModel> tempList = new List <CAddComponentEntryViewModel>(128);
            Dictionary <string, List <CAddComponentEntryViewModel> > components = new Dictionary <string, List <CAddComponentEntryViewModel> >(12);

            foreach (var type in CKlaxScriptRegistry.Instance.Types)
            {
                if (type.Type.IsSubclassOf(typeof(CEntityComponent)))
                {
                    KlaxComponentAttribute attribute = type.Type.GetCustomAttribute <KlaxComponentAttribute>();

                    if (attribute.HideInEditor)
                    {
                        continue;
                    }

                    CAddComponentEntryViewModel vm = new CAddComponentEntryViewModel(type.Name, type.Type);

                    if (components.TryGetValue(attribute.Category, out List <CAddComponentEntryViewModel> list))
                    {
                        list.Add(vm);
                    }
                    else
                    {
                        List <CAddComponentEntryViewModel> newList = new List <CAddComponentEntryViewModel>(8);
                        components.Add(attribute.Category, newList);

                        newList.Add(vm);
                    }
                }
            }

            List <CAddComponentCategoryViewModel> orderedList = new List <CAddComponentCategoryViewModel>(components.Count);

            foreach (var entry in components)
            {
                CAddComponentCategoryViewModel vm = new CAddComponentCategoryViewModel(entry.Key, entry.Value);
                orderedList.Add(vm);
            }

            orderedList = orderedList.OrderBy(p => p.Name).ToList();
            //Always show Common on top
            for (int i = 0, count = orderedList.Count; i < count; i++)
            {
                if (orderedList[i].Name == "Common")
                {
                    ContainerUtilities.Swap(orderedList, i, 0);
                    break;
                }
            }

            m_addComponentMenuCategories = new ObservableCollection <CAddComponentCategoryViewModel>(orderedList);

            m_entityCommands = new ObservableCollection <CEntityCommandViewModel>();
            m_entityCommands.Add(new CEntityCommandViewModel("Save as Asset", new CRelayCommand((obj) =>
            {
                EntityCommandsMenuOpen = false;

                CAssetBrowserViewModel assetBrowser = CWorkspace.Instance.GetTool <CAssetBrowserViewModel>();
                string assetPath = assetBrowser.ActiveDirectory;
                SEntityId id     = m_selectedObject.GetTargetEntityId();

                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    CEntity entity = id.GetEntity();
                    CEntityAsset <CEntity> .CreateFromEntity(entity, assetPath);
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        assetBrowser.UpdateShownAssets();
                    }));
                });
            })));
        }