Beispiel #1
0
        private void OnAction(Action action)
        {
            if (action == null)
            {
                return;
            }

            if (action.Id == "CbpChanged")
            {
                Console.WriteLine("CBP project file changed!");
                if (ProjectModel != null)
                {
                    ProjectModel.UpdateFromCbp();
                    MetaComponentsManager.Instance.UnregisterAllMetaComponents();
                    Parallel.Invoke(
                        () => LoadSdkMetaFiles(),
                        () => GenerateProjectMetaFiles()
                        );
                    if (m_buildPage != null)
                    {
                        m_buildPage.RefreshContent();
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.RebuildList();
                    }
                }
            }
            else if (action.Id == "EditorCbpChanged")
            {
                Console.WriteLine("Editor CBP project file changed!");
                if (m_buildPage != null && !m_buildPage.IsBatchProcessRunning && ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorCbpPath))
                {
                    if (m_scenePage != null)
                    {
                        m_scenePage.SaveSceneBackup();
                    }
                    SceneViewPlugin.Unload();
                    m_buildPage.BatchOperationProject(
                        BuildPageControl.BatchOperationMode.Rebuild,
                        null,
                        ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorCbpPath
                        );
                }
            }
            else if (action.Id == "SceneViewPluginChanged")
            {
                Console.WriteLine("Editor components plugin changed!");
                if (ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorPluginPath))
                {
                    string pluginPath = ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorPluginPath;
                    SceneViewPlugin.Unload();
                    if (SceneViewPlugin.Load(pluginPath))
                    {
                        if (m_scenePage != null)
                        {
                            m_scenePage.ReinitializeRenderer();
                        }
                        List <string> clist = SceneViewPlugin.ListComponents();
                        if (clist != null && clist.Count > 0)
                        {
                            foreach (string c in clist)
                            {
                                Console.WriteLine("Registered component: " + c);
                            }
                        }
                        if (m_scenePage != null)
                        {
                            m_scenePage.OpenSceneBackup();
                        }
                    }
                }
            }
            else if (action.Id == "LoadMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-component for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string        json = File.ReadAllText(metaPath);
                        MetaComponent meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaComponent>(json);
                        MetaComponentsManager.Instance.UnregisterMetaComponent(meta);
                        ProjectModel.MetaComponentPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaComponentsManager.Instance.RegisterMetaComponent(meta);
                            ProjectModel.MetaComponentPaths.Add(path, meta);
                            if (meta.Properties != null && meta.Properties.Count > 0)
                            {
                                foreach (MetaProperty prop in meta.Properties)
                                {
                                    if (PropertyEditorsManager.Instance.FindPropertyEditor(prop.ValueType) == null)
                                    {
                                        Console.WriteLine("Property editor for type: \"{0}\" (component: \"{1}\", property: \"{2}\") not found!", prop.ValueType, meta.Name, prop.Name);
                                    }
                                }
                            }
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaComponentPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-component for: \"{0}\"", path);
                    MetaComponentsManager.Instance.UnregisterMetaComponent(ProjectModel.MetaComponentPaths[path]);
                    ProjectModel.MetaComponentPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "LoadMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-asset for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string    json = File.ReadAllText(metaPath);
                        MetaAsset meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaAsset>(json);
                        MetaAssetsManager.Instance.UnregisterMetaAsset(meta);
                        ProjectModel.MetaAssetsPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaAssetsManager.Instance.RegisterMetaAsset(meta);
                            ProjectModel.MetaAssetsPaths.Add(path, meta);
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaAssetsPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-asset for: \"{0}\"", path);
                    MetaAssetsManager.Instance.UnregisterMetaAsset(ProjectModel.MetaAssetsPaths[path]);
                    ProjectModel.MetaAssetsPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "GameObjectIdChanged" && action.Params != null && action.Params.Length > 0)
            {
                if (m_scenePage != null)
                {
                    m_scenePage.SceneTreeChangeGameObjectId((int)action.Params[0]);
                }
            }
        }
Beispiel #2
0
        private int AddAsset(string id, string meta, string tags, ProjectModel projectModel, out Asset_PropertyEditor outEditor, int y)
        {
            m_properties[id] = "null";
            Asset_PropertyEditor editor = null;

            if (m_type == SceneViewPlugin.AssetType.Texture)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("path", typeof(Path_PropertyEditor))
                },
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("smooth", typeof(Bool_PropertyEditor)),
                    new Asset_PropertyEditor.ItemEditorInfo("repeated", typeof(Bool_PropertyEditor))
                }, id, meta, tags);
                Path_PropertyEditor pathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("path");
                if (pathEditor != null)
                {
                    pathEditor.FileFilter = "Texture files (*.png)|*.png";
                    if (projectModel != null)
                    {
                        pathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            else if (m_type == SceneViewPlugin.AssetType.Shader)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("vspath", typeof(Path_PropertyEditor)),
                    new Asset_PropertyEditor.ItemEditorInfo("fspath", typeof(Path_PropertyEditor))
                }, null, id, meta, tags);
                Path_PropertyEditor vspathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("vspath");
                if (vspathEditor != null)
                {
                    vspathEditor.FileFilter = "Vertex shader files (*.vs)|*.vs";
                    if (projectModel != null)
                    {
                        vspathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
                Path_PropertyEditor fspathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("fspath");
                if (fspathEditor != null)
                {
                    fspathEditor.FileFilter = "Fragment shader files (*.fs)|*.fs";
                    if (projectModel != null)
                    {
                        fspathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            else if (m_type == SceneViewPlugin.AssetType.Sound)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("path", typeof(Path_PropertyEditor))
                }, null, id, meta, tags);
                Path_PropertyEditor pathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("path");
                if (pathEditor != null)
                {
                    pathEditor.FileFilter = "Sound files (*.mp3)|*.mp3";
                    if (projectModel != null)
                    {
                        pathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            else if (m_type == SceneViewPlugin.AssetType.Music)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("path", typeof(Path_PropertyEditor))
                }, null, id, meta, tags);
                Path_PropertyEditor pathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("path");
                if (pathEditor != null)
                {
                    pathEditor.FileFilter = "Music files (*.mp3)|*.mp3";
                    if (projectModel != null)
                    {
                        pathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            else if (m_type == SceneViewPlugin.AssetType.Font)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("path", typeof(Path_PropertyEditor))
                }, null, id, meta, tags);
                Path_PropertyEditor pathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("path");
                if (pathEditor != null)
                {
                    pathEditor.FileFilter = "Font files (*.ttf)|*.ttf";
                    if (projectModel != null)
                    {
                        pathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            else if (m_type == SceneViewPlugin.AssetType.CustomAsset)
            {
                editor = new Asset_PropertyEditor(m_properties, id, m_type,
                                                  new Asset_PropertyEditor.ItemEditorInfo[] {
                    new Asset_PropertyEditor.ItemEditorInfo("type", typeof(EnumPropertyEditor)),
                    new Asset_PropertyEditor.ItemEditorInfo("path", typeof(Path_PropertyEditor))
                }, null, id, meta, tags);
                EnumPropertyEditor typeEditor = editor == null ? null : editor.GetMetaEditor <EnumPropertyEditor>("type");
                if (typeEditor != null)
                {
                    List <string> values = SceneViewPlugin.ListCustomAssets();
                    typeEditor.ValuesSource = values == null ? null : values.ToArray();
                }
                Path_PropertyEditor pathEditor = editor == null ? null : editor.GetMetaEditor <Path_PropertyEditor>("path");
                if (pathEditor != null)
                {
                    pathEditor.FileFilter = "Custom asset files (*.*)|*.*";
                    if (projectModel != null)
                    {
                        pathEditor.RootPath = projectModel.WorkingDirectory + @"\" + projectModel.ActiveTargetWorkingDirectory;
                    }
                }
            }
            if (editor != null)
            {
                editor.Text = id;
                editor.UpdateEditorValue();
                editor.Top    = y;
                editor.Width  = Width;
                editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(editor);
                editor.EditorJsonValueChangedCallback = this;
                y = editor.Bottom;
            }
            outEditor = editor;
            return(y + DEFAULT_SEPARATOR + DEFAULT_SEPARATOR);
        }
        public ConfigControl(string path, ProjectModel model)
        {
            m_path = path;
            string json = File.ReadAllText(m_path);

            ConfigControl.Config config = null;
            try { config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigControl.Config>(json); }
            catch { config = new Config(); }

            MetroSkinManager.ApplyMetroStyle(this);

            m_properties["windowColor"]        = Newtonsoft.Json.JsonConvert.SerializeObject(config.window.color);
            m_properties["windowWidth"]        = Newtonsoft.Json.JsonConvert.SerializeObject(config.window.videoMode.width);
            m_properties["windowHeight"]       = Newtonsoft.Json.JsonConvert.SerializeObject(config.window.videoMode.height);
            m_properties["windowStyles"]       = Newtonsoft.Json.JsonConvert.SerializeObject(config.window.style);
            m_properties["windowName"]         = Newtonsoft.Json.JsonConvert.SerializeObject(config.window.name);
            m_properties["lifeCycleFixedFps"]  = Newtonsoft.Json.JsonConvert.SerializeObject(config.lifeCycle.fixedFps);
            m_properties["lifeCycleFixedStep"] = Newtonsoft.Json.JsonConvert.SerializeObject(config.lifeCycle.fixedStep);
            m_properties["scenes"]             = Newtonsoft.Json.JsonConvert.SerializeObject(config.scenes);

            int y = DEFAULT_SEPARATOR;

            m_reloadButton = new MetroButton();
            MetroSkinManager.ApplyMetroStyle(m_reloadButton);
            m_reloadButton.Text   = "Reload config";
            m_reloadButton.Width  = Width;
            m_reloadButton.Top    = y;
            m_reloadButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            m_reloadButton.Click += m_reloadButton_Click;
            Controls.Add(m_reloadButton);
            y = m_reloadButton.Bottom + DEFAULT_SEPARATOR;

            m_saveButton = new MetroButton();
            MetroSkinManager.ApplyMetroStyle(m_saveButton);
            m_saveButton.Text   = "Save config";
            m_saveButton.Width  = Width;
            m_saveButton.Top    = y;
            m_saveButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            m_saveButton.Click += m_saveButton_Click;
            Controls.Add(m_saveButton);
            y = m_saveButton.Bottom + DEFAULT_SEPARATOR;

            m_saveAsButton = new MetroButton();
            MetroSkinManager.ApplyMetroStyle(m_saveAsButton);
            m_saveAsButton.Text   = "Save config as...";
            m_saveAsButton.Width  = Width;
            m_saveAsButton.Top    = y;
            m_saveAsButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            m_saveAsButton.Click += m_saveAsButton_Click;
            Controls.Add(m_saveAsButton);
            y = m_saveAsButton.Bottom + DEFAULT_SEPARATOR;

            m_windowColor        = new Color_PropertyEditor(m_properties, "windowColor");
            m_windowColor.Text   = "Window Color";
            m_windowColor.Width  = Width;
            m_windowColor.Top    = y;
            m_windowColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_windowColor);
            m_windowColor.EditorJsonValueChangedCallback = this;
            y = m_windowColor.Bottom + DEFAULT_SEPARATOR;

            m_windowWidth        = new ParsablePropertyEditor <uint>(m_properties, "windowWidth");
            m_windowWidth.Text   = "Window Width";
            m_windowWidth.Width  = Width;
            m_windowWidth.Top    = y;
            m_windowWidth.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_windowWidth);
            m_windowWidth.EditorJsonValueChangedCallback = this;
            y = m_windowWidth.Bottom + DEFAULT_SEPARATOR;

            m_windowHeight        = new ParsablePropertyEditor <uint>(m_properties, "windowHeight");
            m_windowHeight.Text   = "Window Height";
            m_windowHeight.Width  = Width;
            m_windowHeight.Top    = y;
            m_windowHeight.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_windowHeight);
            m_windowHeight.EditorJsonValueChangedCallback = this;
            y = m_windowHeight.Bottom + DEFAULT_SEPARATOR;

            m_windowName        = new String_PropertyEditor(m_properties, "windowName");
            m_windowName.Text   = "Window Name";
            m_windowName.Width  = Width;
            m_windowName.Top    = y;
            m_windowName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_windowName);
            m_windowName.EditorJsonValueChangedCallback = this;
            y = m_windowName.Bottom + DEFAULT_SEPARATOR;

            m_windowStyles        = new ArrayStylePropertyEditor(m_properties, "windowStyles");
            m_windowStyles.Text   = "Window Styles";
            m_windowStyles.Width  = Width;
            m_windowStyles.Top    = y;
            m_windowStyles.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_windowStyles);
            m_windowStyles.EditorJsonValueChangedCallback = this;
            y = m_windowStyles.Bottom + DEFAULT_SEPARATOR;

            m_lifeCycleFixedFps        = new ParsablePropertyEditor <float>(m_properties, "lifeCycleFixedFps");
            m_lifeCycleFixedFps.Text   = "Life Cycle Fixed Fps";
            m_lifeCycleFixedFps.Width  = Width;
            m_lifeCycleFixedFps.Top    = y;
            m_lifeCycleFixedFps.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_lifeCycleFixedFps);
            m_lifeCycleFixedFps.EditorJsonValueChangedCallback = this;
            y = m_lifeCycleFixedFps.Bottom + DEFAULT_SEPARATOR;

            m_lifeCycleFixedStep        = new ParsablePropertyEditor <float>(m_properties, "lifeCycleFixedStep");
            m_lifeCycleFixedStep.Text   = "Life Cycle Fixed Step";
            m_lifeCycleFixedStep.Width  = Width;
            m_lifeCycleFixedStep.Top    = y;
            m_lifeCycleFixedStep.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_lifeCycleFixedStep);
            m_lifeCycleFixedStep.EditorJsonValueChangedCallback = this;
            y = m_lifeCycleFixedStep.Bottom + DEFAULT_SEPARATOR;

            m_scenes        = new StringMapPathPropertyEditor(m_properties, "scenes", model == null ? null : model.WorkingDirectory + @"\" + model.ActiveTargetWorkingDirectory);
            m_scenes.Text   = "Scenes";
            m_scenes.Width  = Width;
            m_scenes.Top    = y;
            m_scenes.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Controls.Add(m_scenes);
            m_scenes.EditorJsonValueChangedCallback = this;
            y = m_scenes.Bottom + DEFAULT_SEPARATOR;

            m_windowColor.UpdateEditorValue();
            m_windowWidth.UpdateEditorValue();
            m_windowHeight.UpdateEditorValue();
            m_windowName.UpdateEditorValue();
            m_windowStyles.UpdateEditorValue();
            m_lifeCycleFixedFps.UpdateEditorValue();
            m_lifeCycleFixedStep.UpdateEditorValue();
            m_scenes.UpdateEditorValue();
        }