示例#1
0
        private IEnumerable <IdleStatus> finishInitialization()
        {
            splashScreen.updateStatus(10, "Loading Solution");
            yield return(IdleStatus.Ok);

            //Load the config file and set the resource root up.
            VirtualFileSystem.Instance.addArchive(solution.ResourceRoot);

            resourceController = new ResourceController(this);

            solution.loadExternalFiles(this);

            MyGUIPlugin.ResourceManager.Instance.load("Anomaly.Resources.AnomalyImagesets.xml");

            //Initialize controllers
            instanceBuilder = new InstanceBuilder();
            sceneController.initialize(this);
            sceneController.OnSceneLoaded    += sceneController_OnSceneLoaded;
            sceneController.OnSceneUnloading += sceneController_OnSceneUnloading;
            simObjectController = new SimObjectController(this);

            fixedUpdate = new FullSpeedUpdateListener(sceneController);
            mainTimer.addUpdateListener(fixedUpdate);

            splashScreen.updateStatus(60, "Creating GUI");
            yield return(IdleStatus.Ok);

            propertiesEditor = new PropertiesEditor("Properties", "Anomaly.GUI.Properties", false);
            guiManager.addManagedDialog(propertiesEditor);

            interfaceRenderer = new EditInterfaceRendererController(pluginManager.RendererPlugin, mainTimer, sceneController, propertiesEditor);

            solutionWindow = new SolutionWindow();
            guiManager.addManagedDialog(solutionWindow);

            mainObjectEditor = new PropertiesEditor("Object Editor", "Anomaly.GUI.ObjectEditor", true);
            mainObjectEditor.AllowedDockLocations = DockLocation.Floating;
            mainObjectEditor.CurrentDockLocation  = DockLocation.Floating;
            guiManager.addManagedDialog(mainObjectEditor);

            solutionController = new SolutionController(solution, solutionWindow, this, propertiesEditor);

            //Initialize the windows
            propertiesEditor.AutoExpand = true;

            //Create GUI
            consoleWindow = new LogWindow();
            guiManager.addManagedDialog(consoleWindow);
            Log.Default.addLogListener(consoleWindow);

            debugVisualizer = new DebugVisualizer(pluginManager, sceneController);
            guiManager.addManagedDialog(debugVisualizer);


            if (File.Exists(AnomalyConfig.WindowsFile))
            {
                ConfigFile configFile = new ConfigFile(AnomalyConfig.WindowsFile);
                configFile.loadConfigFile();
                guiManager.loadSavedUI(configFile, new Version("1.0.0.0"));

                //Show Windows Default
                solutionWindow.Visible   = true;
                propertiesEditor.Visible = true;
                consoleWindow.Visible    = true;
                debugVisualizer.Visible  = true;
            }
            else
            {
                //Show Windows Default
                solutionWindow.Visible = true;
                propertiesEditor.showRelativeTo(solutionWindow, WindowAlignment.Right);
                consoleWindow.Visible   = true;
                debugVisualizer.Visible = true;
            }

            yield return(IdleStatus.Ok);

            splashScreen.updateStatus(80, "Building Scene");

            buildScene();
            yield return(IdleStatus.Ok);

            splashScreen.updateStatus(100, "Loaded");

            splashScreen.hide();
            yield return(IdleStatus.Ok);

            if (FullyLoaded != null)
            {
                FullyLoaded.Invoke(this);
            }
        }
        public void initialize(StandaloneController standaloneController)
        {
            GUIManager guiManager = standaloneController.GUIManager;

            //UI Helpers
            gridProperties = new GridPropertiesDialog(standaloneController.MeasurementGrid);
            guiManager.addManagedDialog(gridProperties);

            developerRenderer = new DeveloperRenderPropertiesDialog(standaloneController.SceneViewController, standaloneController.ImageRenderer, guiManager, standaloneController.NotificationManager);
            guiManager.addManagedDialog(developerRenderer);

            discControl = new DiscControl();
            guiManager.addManagedDialog(discControl);

            advancedMandibleMovement = new AdvancedMandibleMovementDialog(standaloneController.MovementSequenceController, standaloneController.MusclePositionController);
            guiManager.addManagedDialog(advancedMandibleMovement);

            performanceGui = new PerformanceGui(standaloneController);
            guiManager.addManagedDialog(performanceGui);

            measurementGUI = new MeasurementGUI(standaloneController);
            guiManager.addManagedDialog(measurementGUI);

            debugVisualizer = new DebugVisualizer(standaloneController);
            guiManager.addManagedDialog(debugVisualizer);

            advancedCameraGui = new AdvancedCameraGui(standaloneController.SceneViewController);
            guiManager.addManagedDialog(advancedCameraGui);

            libRocketDebugger = new ShowLibRocketDebugger(guiManager, "ShowLibRocketDebugger", "Show LibRocket Debugger", "Developer.libRocketDebugger", "Developer");

            resolutionGui = new ResolutionGui(standaloneController.MainWindow);
            guiManager.addManagedDialog(resolutionGui);

            RocketInterface.Instance.FileInterface.addExtension(new RocketAssemblyResourceLoader(this.GetType().Assembly));

            changeRenderingMode = new ChangeRenderingMode(standaloneController.SceneViewController);
            disablePhysics      = new DisablePhysicsTask(int.MaxValue);

            //Task Controller
            TaskController taskController = standaloneController.TaskController;

            taskController.addTask(new MDIDialogOpenTask(developerRenderer, "Developer.DeveloperRender", "Render", "AnomalousMedical/RenderIcon", TaskMenuCategories.Create));

            if (MedicalConfig.ShowDeveloperTools)
            {
                taskController.addTask(new MDIDialogOpenTask(discControl, "Medical.DiscEditor", "Disc Editor", "Developer.DiscEditorIcon", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(advancedMandibleMovement, "Medical.AdvancedMandibleMovement", "Advanced Mandible Movement", "Developer.MovementIcon", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(gridProperties, "Medical.GridProperties", "Grid", "Developer.GridIcon", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(performanceGui, "Medical.Performance", "Performance", "Developer.StatisticsIcon", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(measurementGUI, "Developer.Measurement", "Measurements", "Developer.Measurements", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(debugVisualizer, "Developer.DebugVisualizer", "Debug Visualizer", "Developer.DebugVisualizer", TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(advancedCameraGui, "Developer.AdvancedCameraGui", "Advanced Camera Settings", CommonResources.NoIcon, TaskMenuCategories.Developer));
                taskController.addTask(new MDIDialogOpenTask(resolutionGui, "Developer.SetResolution", "Set Resolution", CommonResources.NoIcon, TaskMenuCategories.Developer));
                taskController.addTask(libRocketDebugger);
                taskController.addTask(new SaveMicrocodeCacheTask());
                taskController.addTask(new CallbackTask("Developer.SaveToMax", "Save to 3ds Max", "Developer.MaxDumpIcon", TaskMenuCategories.Developer, (item) =>
                {
                    if (!item.Active)
                    {
                        item.setActive(true);
                        MaxExport maxExport = new MaxExport(standaloneController);
                        guiManager.addManagedDialog(maxExport);
                        maxExport.Visible = true;
                        maxExport.Closed += (evt, args) =>
                        {
                            maxExport.Dispose();
                            item.setActive(false);
                            item.closeTask();
                        };
                    }
                }));

                taskController.addTask(new CallbackTask("Developer.TogglePhysicalTextures", "Toggle Physical Textures", CommonResources.NoIcon, TaskMenuCategories.Developer, (item) =>
                {
                    if (standaloneController.VirtualTextureManager.Active)
                    {
                        standaloneController.VirtualTextureManager.suspend();
                    }
                    else
                    {
                        standaloneController.VirtualTextureManager.resume();
                    }
                }));

                taskController.addTask(new CallbackTask("Developer.ToggleCompactMode", "Toggle Compact Mode", CommonResources.NoIcon, TaskMenuCategories.Developer, item =>
                {
                    standaloneController.GUIManager.CompactMode = !standaloneController.GUIManager.CompactMode;
                    standaloneController.GUIManager.layout();
                }));

                taskController.addTask(new CallbackTask("Developer.SpawnTestSplint", "Spawn Test Splint", CommonResources.NoIcon, TaskMenuCategories.Developer, item =>
                {
                    GenericSimObjectDefinition def = new GenericSimObjectDefinition("TestSplint" + Guid.NewGuid());
                    def.addElement(new SceneNodeDefinition("Node"));
                    var rigidBody = new ReshapeableRigidBodyDefinition("RigidBody");
                    def.addElement(rigidBody);
                    MultiProp multiProp = new MultiProp();
                    def.addElement(new BehaviorDefinition("MultiProp", multiProp));
                    DynamicSplint splint = new DynamicSplint()
                    {
                        MultiPropName = "MultiProp",
                    };
                    def.addElement(new BehaviorDefinition("Behavior", splint));

                    PositionCollection positions;
                    using (var stream = VirtualFileSystem.Instance.openStream("Plugins/SplintProps/PartModels/SplintSpace.positions", Engine.Resources.FileMode.Open))
                    {
                        positions = new PositionCollection(stream);
                    }

                    Position position;
                    if (false)
                    {
                        position                       = positions.getPosition("MaxillaryGroup");
                        splint.StartIndex              = 1;
                        splint.EndIndex                = 17;
                        rigidBody.Mass                 = 0;
                        rigidBody.CollisionFilterMask  = -3;
                        rigidBody.CollisionFilterGroup = 1;
                    }
                    else
                    {
                        position                       = positions.getPosition("MandibularGroup");
                        splint.StartIndex              = 17;
                        splint.EndIndex                = 33;
                        rigidBody.Mass                 = 1;
                        rigidBody.CollisionFilterMask  = -5;
                        rigidBody.CollisionFilterGroup = 1;

                        var joint = new Generic6DofConstraintDefinition(Splint.JointName)
                        {
                            RigidBodyASimObject = "Mandible",
                            RigidBodyAElement   = "Actor",
                            RigidBodyBSimObject = "this",
                            RigidBodyBElement   = "RigidBody",
                        };

                        joint.TranslationMotor.LowerLimit = Vector3.Zero;
                        joint.TranslationMotor.UpperLimit = Vector3.Zero;
                        joint.XRotMotor.LoLimit           = 0;
                        joint.XRotMotor.HiLimit           = 0;
                        joint.YRotMotor.LoLimit           = 0;
                        joint.YRotMotor.HiLimit           = 0;
                        joint.ZRotMotor.LoLimit           = 0;
                        joint.ZRotMotor.HiLimit           = 0;

                        def.addElement(joint);

                        def.addElement(new BehaviorDefinition("JointHandler", new MultiPropJointHandler(joint.Name, multiProp.Name)));

                        //def.addElement(new BehaviorDefinition(Splint.SplintBehaviorName, new Splint()
                        //{

                        //}));
                    }

                    def.Translation = position.Translation;
                    def.Rotation    = position.Rotation;

                    PropDefinition propDef = new PropDefinition(def);
                    standaloneController.PropFactory.addDefinition(propDef);

                    Vector3 translationOffset = Quaternion.quatRotate(MandibleController.StartRotation.inverse(), position.Translation - MandibleController.StartTranslation);
                    SimObject mandibleObject  = MandibleController.Mandible.Owner;
                    Vector3 trans             = mandibleObject.Translation + Quaternion.quatRotate(mandibleObject.Rotation, translationOffset);
                    Quaternion rotation       = mandibleObject.Rotation;

                    standaloneController.PropFactory.createProp(def.Name, trans, rotation);

                    //SimObjectBase instance = def.register(standaloneController.MedicalController.CurrentScene.getDefaultSubScene());
                    //standaloneController.MedicalController.addSimObject(instance);
                    //standaloneController.MedicalController.CurrentScene.buildScene();

                    //if (SimObjectErrorManager.HasErrors)
                    //{
                    //    standaloneController.NotificationManager.showCallbackNotification("Errors loading the prop.\nClick for details.", MessageBoxIcons.Error, () =>
                    //    {
                    //        SceneErrorWindow errorGui = new SceneErrorWindow(guiManager);
                    //        errorGui.Visible = true;
                    //    });
                    //}
                }));

                taskController.addTask(disablePhysics);
                taskController.addTask(changeRenderingMode);

#if ALLOW_CRASH_PROGRAM
                taskController.addTask(new CallbackTask("Developer.Crash", "Crash The Program", CommonResources.NoIcon, TaskMenuCategories.Developer, (item) =>
                {
                    throw new Exception("Manually crashed program");
                }));
#endif
            }

            standaloneController.ViewHostFactory.addFactory(new WizardComponentViews());

            if (PlatformConfig.AllowFullscreenToggle && MedicalConfig.ShowDeveloperTools)
            {
                CallbackTask toggleBorderless = new CallbackTask("Developer.ToggleBorderless", "Toggle Borderless", "AnomalousMedical/ToggleFullscreen", TaskMenuCategories.Developer, int.MaxValue, false, (item) =>
                {
                    MainWindow.Instance.toggleBorderless();
                });
                taskController.addTask(toggleBorderless);
            }

            if (standaloneController.VirtualTextureManager != null && MedicalConfig.ShowDeveloperTools)
            {
                virtualTextureDebugger = new VirtualTextureDebugger(standaloneController.VirtualTextureManager);
                guiManager.addManagedDialog(virtualTextureDebugger);

                taskController.addTask(new MDIDialogOpenTask(virtualTextureDebugger, "Developer.VirtualTextureDebugger", "Virtual Texture Debugger", CommonResources.NoIcon, TaskMenuCategories.Developer));
            }

            var screenshotButtonEvent = new ButtonEvent(EventLayers.Gui, frameUp: (evtMgr) =>
            {
                try
                {
                    String screenshotFolder = Path.Combine(MedicalConfig.UserDocRoot, "Screenshots");
                    if (!Directory.Exists(screenshotFolder))
                    {
                        Directory.CreateDirectory(screenshotFolder);
                    }

                    OgreInterface.Instance.OgrePrimaryWindow.OgreRenderTarget.writeContentsToTimestampedFile(Path.Combine(screenshotFolder, "Screenshot"), ".png");
                }
                catch (Exception ex)
                {
                    MessageBox.show(String.Format("{0} saving screenshot. Message {1}", ex.GetType().Name, ex.Message), "Error saving screenshot", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
                }
            });
            screenshotButtonEvent.addButton(KeyboardButtonCode.KC_F8);
            screenshotButtonEvent.addButton(KeyboardButtonCode.KC_LSHIFT);
            standaloneController.MedicalController.EventManager.addEvent(screenshotButtonEvent);
        }