Example #1
0
 private void TestStartButton_Click(object sender, RoutedEventArgs e)
 {
     if ((DataContext as EngineManagerViewModel).IsConnected)
     {
         if (EditorSubsystem.getInstance().IsTesting())
             return;
         EditorSubsystemManaged.getInstance().QueueAction(() =>
         {
             StateSerializer ss = new StateSerializer(); ss.SaveCurrentState("_Testing_Temp.mocha");
         });
         EditorSubsystemManaged.getInstance().QueueAction(() =>
         {
             BeginTest();
         });
     }
 }
Example #2
0
 private void TestCurrentPosButton_Click(object sender, RoutedEventArgs e)
 {
     if ((DataContext as EngineManagerViewModel).IsConnected)
     {
         if (EditorSubsystem.getInstance().IsTesting())
             return;
         EditorSubsystemManaged.getInstance().QueueAction(() =>
         {
             StateSerializer ss = new StateSerializer(); ss.SaveCurrentState("_Testing_Temp.mocha");
         });
         EditorSubsystemManaged.getInstance().QueueAction(() =>
         {
             if (BeginTest())
             {
                 GameObject playerObj = GameObject.From(GameObject.GetGameObjectWithTag("Player"));
                 if (playerObj == null)
                     MessageBox.Show("Test from Current Position requires\nan object with the \'Player\' tag set.");
                 else
                     playerObj.transform.SetPosition(EditorSubsystem.getInstance().EditorCamera().gameObject.transform.GetGlobalPosition());
             }
         });
     }
 }
Example #3
0
 public static void CMD_SaveMapAs()
 {
     if (EditorSubsystem.getInstance().IsTesting())
     {
         Logger.Log("Cannot save in testing mode.");
         return;
     }
     System.Windows.Application.Current.Dispatcher.Invoke(() =>
     {
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.OverwritePrompt = false;
         dlg.DefaultExt = ".mocha";
         dlg.Filter = "Mocha Map Files (.mocha)|*.mocha";
         DialogResult result = dlg.ShowDialog();
         if (result == DialogResult.OK)
         {
             // EngineManagerViewModel.instance.BusyMessage = "... Saving Map ...";
             string filename = dlg.FileName;
             Dispatcher.CurrentDispatcher.Invoke(() => { EngineManagerViewModel.instance.SelectedGameObjects.Clear(); });
             EditorSubsystemManaged.getInstance().QueueAction(() =>
             {
                 StateSerializer ss = new StateSerializer(); ss.SaveCurrentState(filename);
             });
             Dispatcher.CurrentDispatcher.Invoke(() => { EngineManagerViewModel.instance.currentLoadedMap = filename; });
             // EngineManagerViewModel.instance.BusyMessage = null;
         }
     });
 }
Example #4
0
        public void Tick()
        {
            if (!hasInit)
                Init();

            while (actionQueue.Count != 0)
            {
                EditorAction a = actionQueue.Dequeue();
                //Dispatcher.CurrentDispatcher.Invoke(a, DispatcherPriority.Normal);
                if (a == null)  //wait frame
                    break;
                a.a();
                if (a.mres != null)
                {
                    a.mres.Set();
                    a.mres.Dispose();
                }
            }

            if (!EditorSubsystem.getInstance().IsTesting())
            {

                //draw grid lines
                if (EngineCommandBindings.DrawGrid && EngineCommandBindings.GridSize > 0)
                {
                    Vector3 camPos = EditorSubsystem.getInstance().EditorCamera().gameObject.transform.GetGlobalPosition();
                    float startX = camPos.X;
                    float startY = camPos.Y;
                    float startZ = camPos.Z;
                    startX = startX - (startX % EngineCommandBindings.GridSize);
                    if (startY > 0)
                        startY = startY - (startY % EngineCommandBindings.GridSize);
                    else
                        startY = startY + (startY % EngineCommandBindings.GridSize);
                    startZ = startZ - (startZ % EngineCommandBindings.GridSize);

                    for (int y = (int)startY; y <= (int)startY + EngineCommandBindings.gridExtent / 2; y += EngineCommandBindings.GridSize)
                    {
                        //for every y, draw an x,z plane
                        for (int x = (int)startX - EngineCommandBindings.gridExtent; x <= (int)startX + EngineCommandBindings.gridExtent; x += EngineCommandBindings.GridSize)
                        {
                            //draw z
                            Renderer.getInstance().DrawLinePerma(new Vector3(x, y, startZ - EngineCommandBindings.gridExtent), new Vector3(x, y, startZ + EngineCommandBindings.gridExtent),
                                new Color(0.39f, 0.60f, 0.93f, .5f));
                            for (int z = (int)startZ - EngineCommandBindings.gridExtent; z <= (int)startZ + EngineCommandBindings.gridExtent; z += EngineCommandBindings.GridSize)
                            {
                                //draw x
                                Renderer.getInstance().DrawLinePerma(new Vector3(x - EngineCommandBindings.gridExtent, y, z), new Vector3(x + EngineCommandBindings.gridExtent, y, z),
                                        new Color(.4f, .4f, 0.0f, .3f));
                            }
                        }
                    }
                }

                //save occasionally
                autoSaveTimer += FrameController.DT();
                if (autoSaveTimer > 30.0f)
                {
                    QueueAction(() =>
                    {
                        try
                        {
                            StateSerializer ss = new StateSerializer();
                            ss.DoRecoverySave();
                        }
                        catch (Exception e)
                        {
                            Logger.Log("FAILED TO SAVE RECOVERY SAVE: " + e.Message);
                        }
                    });
                    autoSaveTimer = 0;
                }

                //occasionally check for available assets
                ++checkforChangedAssetsTimer;
                if (checkforChangedAssetsTimer > CHECKFORCHANGEDASSETS_TIME)
                {
                    AssetManager.getInstance().CheckForChangedAssets();
                    checkforChangedAssetsTimer = 0;
                }

                //do standard updates
                if (Input.GetIsMouseInWindow(true) && EngineManagerViewModel.instance.EngineEmbedHasVisibility && EngineManagerViewModel.instance._isFocused)
                {
                    //run sub systems
                    auto_builder.Update();

                    //set tooltips
                    mouseTooltipText.gameObject.transform.SetPosition(Input.GetMouseX(true) - Engine.getInstance().GetGameWnd().GetWindowWidth() * 0.5f,
                       -(Input.GetMouseY(true) - Engine.getInstance().GetGameWnd().GetWindowHeight() * 0.5f), 0);
                    editorStatusText.gameObject.transform.SetPosition(-Engine.getInstance().GetGameWnd().GetWindowWidth() * 0.49f,
                       Engine.getInstance().GetGameWnd().GetWindowHeight() * 0.44f, 0);
                    editorStatusText.mText = "--- STATUS ---\\n" +
                        "Arrow Keys Snap Prec.: " + arrowSnapPrecision.ToString("0.0") +
                        "\\nFPS: " + (1.0f / FrameController.DT()).ToString("0.0") +
                        "\\n---------------";

                    CCamera editorCamera = EditorSubsystem.getInstance().EditorCamera();
                    if (Input.GetTriggered(0, "F2") == 1.0f)
                    {
                        //duplicate
                        EngineCommandBindings.CMD_DuplicateObjects();
                    }

                    //select objects naively
                        GameObject gobj = GameObject.From(PhysicEngine.getInstance().RayCast3D(editorCamera.gameObject.transform.position,
                        editorCamera.gameObject.transform.GetForwardVector(), editorCamera, Input.GetMouseX(true),
                            Input.GetMouseY(true), 10000.0f));
                    if (gobj != null && gobj.GetFlag("ArtWidget"))
                    {
                        //select widget's actual object
                        gobj = GameObject.From(EditorSubsystem.getInstance().widgetManager.GetAttachedObjFromWidgetObj(gobj));
                    }
                    if (gobj != null && !gobj.GetFlag("Widget"))
                    {
                        //show tooltip if mouse over
                        mouseTooltipText.mText = gobj.GetName();

                        //select if clicked on
                        if (Input.GetTriggered(0, "MouseLClick") == 1.0f)
                        {
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                try
                                {
                                    if (Input.GetHeld(0, "AdditiveMod") == 1.0f)
                                    {
                                        GameObjectSelectionManager.RequestAdditiveSelect(gobj);
                                    }
                                    else
                                    {
                                        GameObjectSelectionManager.RequestSelect(gobj);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Consumed Error in Hierarchy: " + e.ToString());
                                }
                            }
                            ));
                        }
                    }
                    else
                    {
                        mouseTooltipText.mText = "";
                    }

                    //rotate camera and move camera
                    float dt = FrameController.getInstance().GetDeltaTime();
                    if (Input.GetHeld(0, "MoveFaster") == 1.0f)
                        dt *= 3;
                    Vector3 velocityThisFrame = new Vector3();
                    if (Input.GetHeld(0, "MouseRCLick") == 1.0f)
                    {
                        float dx = 0.25f * (Input.GetMouseDeltaX() * (3.14f / 180.0f));
                        float dy = 0.25f * (Input.GetMouseDeltaY() * (3.14f / 180.0f));
                        editorCamera.Pitch(dy);
                        editorCamera.RotateY(dx);

                        float val = Input.GetValue(0, "up");
                        velocityThisFrame.Z += val;
                        val = Input.GetValue(0, "right");
                        velocityThisFrame.X += val;
                        val = Input.GetValue(0, "down");
                        velocityThisFrame.Z -= val;
                        val = Input.GetValue(0, "left");
                        velocityThisFrame.X -= val;
                        cameraVelocity += velocityThisFrame;
                        //cameraVelocity = cameraVelocity.Add(velocityThisFrame);
                        //MathHelper.Clamp
                        cameraVelocity.X = MathHelper.Clamp(cameraVelocity.X, -6, 6);
                        cameraVelocity.Y = MathHelper.Clamp(cameraVelocity.Y, -6, 6);
                        cameraVelocity.Z = MathHelper.Clamp(cameraVelocity.Z, -6, 6);
                        //cameraVelocity.Clamp(-6.0f, 6.0f);
                    }
                    if (velocityThisFrame.X == 0)
                        cameraVelocity.X *= 0.9f;
                    if (velocityThisFrame.Z == 0)
                        cameraVelocity.Z *= 0.9f;
                    editorCamera.Walk(cameraVelocity.Z * dt);
                    editorCamera.Strafe(cameraVelocity.X * dt);

                    //look at
                    if (_lookTimer != 0)
                        _lookTimer += FrameController.DT();
                    if (_lookTimer > 1.3f)
                        _lookTimer = 0;
                    if (Input.GetTriggered(0, "LookAt") == 1.0f)
                    {
                        if (EngineManagerViewModel.instance.SelectedGameObjects.Count == 0)
                            return;
                        GameObject selobj = EngineManagerViewModel.instance.SelectedGameObjects[0];
                        if (_lookTimer == 0)
                        {
                            _lookTimer = 1; //force the setup
                            if (selobj != null)
                                editorCamera.gameObject.transform.LookAt(selobj.transform.position);
                        }
                        else
                        {
                            editorCamera.gameObject.transform.LookAt(selobj.transform.position);
                            Vector3 forw = editorCamera.gameObject.transform.GetForwardVector();
                            editorCamera.gameObject.transform.SetPosition(selobj.transform.position - (forw * 8));
                            _lookTimer = 0;
                        }
                    }

                    //arrow keys moving
                    if (Input.GetTriggered(0, "Add") > 0)
                        arrowSnapPrecision += 0.1f;
                    if (Input.GetTriggered(0, "Sub") > 0)
                        arrowSnapPrecision -= 0.1f;
                    if (Input.GetTriggered(0, "ArrowUp") > 0)
                        foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects)
                            selobj.transform.SetPositionZ(selobj.transform.position.z + arrowSnapPrecision);
                    if (Input.GetTriggered(0, "ArrowDown") > 0)
                        foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects)
                            selobj.transform.SetPositionZ(selobj.transform.position.z - arrowSnapPrecision);
                    if (Input.GetTriggered(0, "ArrowRight") > 0)
                        foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects)
                            selobj.transform.SetPositionX(selobj.transform.position.x + arrowSnapPrecision);
                    if (Input.GetTriggered(0, "ArrowLeft") > 0)
                        foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects)
                            selobj.transform.SetPositionX(selobj.transform.position.x - arrowSnapPrecision);
                }
            }
        }
Example #5
0
 public static void CMD_SaveMap()
 {
     if (EditorSubsystem.getInstance().IsTesting())
     {
         Logger.Log("Cannot save in testing mode.");
         return;
     }
     //EngineManagerViewModel.instance.BusyMessage = "... Saving Map ...";
     EngineManagerViewModel.instance.SelectedGameObjects.Clear();     //safety check, remove the selected object so no weird binding happens
     string currentLoadedMap = EngineManagerViewModel.instance.currentLoadedMap;
     if (currentLoadedMap != null)
         EditorSubsystemManaged.getInstance().QueueAction(() => { StateSerializer ss = new StateSerializer(); ss.SaveCurrentState(currentLoadedMap); });
     else
         System.Windows.MessageBox.Show("Save As, Before Saving...");
     // EngineManagerViewModel.instance.BusyMessage = null;        }
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StateSerializer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #7
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StateSerializer obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Example #8
0
        public MergeMapWindow(string filename)
        {
            objects = new Containers.SuppressableObservableCollection<MergeMap.Object>();

            List<MergeMap.Object> temp_merge = new List<MergeMap.Object>();
            EditorSubsystemManaged.getInstance().QueueActionAndBlock(new Action(() =>
            {
                StateSerializer ss = new StateSerializer();
                StateObjDescVector objs = ss.LoadStateInformation(filename, false);

                foreach (StateObjDesc desc in objs)
                {
                    temp_merge.Add(new MergeMap.Object
                    {
                        Name = desc.name,
                        HasParent = desc.hasParent,
                        ShouldMerge = true
                    });
                }

            }));
            objects.AddRange(temp_merge);

            InitializeComponent();
        }
Example #9
0
        private void MergeButton_Click(object sender, RoutedEventArgs e)
        {
            EditorSubsystemManaged.getInstance().QueueActionAndBlock(new Action(() =>
               {
               StateSerializer ss = new StateSerializer();
               BaseState cur_state = GSM.getInstance().getStateUnderActive();
               BaseState new_state = GSM.getInstance().getActiveState();
               BoolVector mergeMask = new BoolVector();
               foreach (var obj in objects)
                   mergeMask.Add(obj.ShouldMerge);

               ss.MergeStates(new_state, cur_state, mergeMask);
               }));

            this.Close();
        }