예제 #1
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());
                 }
             }
         });
     }
 }
예제 #2
0
        private void HackButton_Click(object sender, RoutedEventArgs e)
        {
            int    texindex = TextureIndex.Value.Value;
            string texname  = TextureRoughSettor.Text;

            EditorSubsystemManaged.getInstance().QueueAction(new Action(() => {
                foreach (GameObject g in EngineManagerViewModel.instance.SelectedGameObjects)
                {
                    CMeshRenderer cm = CastingHelper.CastTo <CMeshRenderer>(g.GetComponentByName("CMeshRenderer"));
                    if (cm != null)
                    {
                        Material mat = cm.GetMaterial() as Material;
                        MaterialAttribNodeMap map = mat.mMaterialData.mAttributeMetaLookup;
                        ObservableCollection <MaterialNodeModel> out_nodes = new ObservableCollection <MaterialNodeModel>();
                        MaterialAttribNodeVector nodes = map.Values.ElementAt(1);
                        {
                            MatAttribNode node = nodes[texindex];

                            object castedObj = null;
                            castedObj        = CastingHelper.CastTo <TextureNode>(node);
                            if (castedObj != null)
                            {
                                (castedObj as TextureNode).SetTexture(AssetManager.getInstance().GetAsset(texname));
                            }
                            else
                            {
                                MessageBox.Show("You f****d up the node, this ain't no texture node dummy");
                            }
                        }
                    }
                }
            }));
        }
예제 #3
0
 public void LoadPrefabs()
 {
     EditorSubsystemManaged.getInstance().QueueAction(new Action(() => {
         GameObject g = GameObject.From(ObjectFactory.getInstance().Instantiate(_item.filename));
         Application.Current.Dispatcher.BeginInvoke(new Action(() =>
         {
             EngineManagerViewModel.instance.SelectedGameObjects.Replace(g);
         }));
     }));
 }
예제 #4
0
        private void Detach(GameObject g)
        {
            EditorSubsystemManaged.getInstance().QueueAction(() =>
            {
                g.transform.SetParent(null);

                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    GameObjectViewControl.instance.generate_hierarchytree();
                }));
            });
        }
예제 #5
0
 public void LoadLevels()
 {
     EngineManagerViewModel.instance.SelectedGameObjects.Clear();
     EditorSubsystemManaged.getInstance().QueueAction(() =>
     {
         GameObjectVector v = new GameObjectVector();
         EditorSubsystem.getInstance().SetSelectedObjects(v);
         Map.LoadMap(_item.filepath);
         EditorSettings.AddRecentMap(_item.filepath);
     });
     EngineManagerViewModel.instance.currentLoadedMap = _item.filepath;
     // EngineManagerViewModel.instance.BusyMessage = null;
 }
        public static void CMD_DeleteObjects()
        {
            if (EditorSubsystem.getInstance().IsTesting())
            {
                Logger.Log("Cannot delete in testing mode.");
                return;
            }
            List <GameObject> objsToDel = EngineManagerViewModel.instance.SelectedGameObjects.ToList();

            EngineManagerViewModel.instance.SelectedGameObjects.Clear();
            foreach (GameObject g in objsToDel)
            {
                EditorSubsystemManaged.getInstance().QueueAction(() => { g.Destroy(); });
                HierarchyControlSelectionManager.HierarchyControlStateManager.RequestRemoval(g);
            }
        }
        private void MakePrefabButton_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder ss = new StringBuilder();

            EditorSubsystemManaged.getInstance().QueueActionAndBlock(new Action(() =>
            {
                foreach (GameObject g in Models.EngineManagerModel.instance._selectedGameObjects)
                {
                    MochaInterface.Prefab.MakePrefabFrom(g);
                    ss.AppendLine(g.GetName());
                }
            }));

            Controls.ModernModalWindow mmw = new Controls.ModernModalWindow("Prefabs created: " + ss.ToString());
            mmw.ShowDialog();
        }
예제 #8
0
        private void RemoveCompButton_Click(object sender, RoutedEventArgs e)
        {
            Component c = (DataContext as Component);

            EditorSubsystemManaged.getInstance().QueueAction(() => { c.Destroy(); });
            EditorSubsystemManaged.getInstance().QueueWaitFrame();
            EditorSubsystemManaged.getInstance().QueueAction(() => {
                Dispatcher.Invoke(new Action(() =>
                {
                    var dc = EngineManagerViewModel.instance.SelectedGameObjects;
                    EngineManagerViewModel.instance.SelectedGameObjects = null;
                    EngineManagerViewModel.instance.SelectedGameObjects = dc;
                }));
            });
            RemoveCompButton.IsEnabled = false;
        }
        private void DetachButton_Click(object sender, RoutedEventArgs e)
        {
            GameObject g = ApplyButton.DataContext as GameObject;

            if (g == null)
            {
                return;
            }
            if (g.linkedPrefab == null)
            {
                return;
            }

            EditorSubsystemManaged.getInstance().QueueAction(new Action(() =>
            {
                g.DetachFromPrefab();
            }));
        }
예제 #10
0
        private void StopTestingButton_Click(object sender, RoutedEventArgs e)
        {
            if ((DataContext as EngineManagerViewModel).IsConnected)
            {
                if (!EditorSubsystem.getInstance().IsTesting())
                {
                    return;
                }
                EditorSubsystemManaged.getInstance().QueueAction(() =>
                {
                    EditorSubsystem.getInstance().EndTesting();
                    Dispatcher.Invoke(() => SetTestButtonStates(false));
                });

                Input.SetMouseVisible(true);
                Input.SetMouseLock(false);
            }
        }
        private void AlignViewButton_Click(object sender, RoutedEventArgs e)
        {
            EngineManagerViewModel view = (this.DataContext as EngineManagerViewModel);

            e.Handled = true;
            if (view.SelectedGameObjects.Count == 0)
            {
                return;
            }
            EditorSubsystemManaged.getInstance().QueueAction(() =>
            {
                foreach (GameObject g in view.SelectedGameObjects)
                {
                    MochaInterface.GameObject ed_cam = EditorSubsystem.getInstance().EditorCamera().gameObject;
                    g.transform.SetPosition(ed_cam.transform.position + (Vector3)ed_cam.transform.GetForwardVector() * 5);
                }
            });
        }
        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();
        }
예제 #13
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();
         });
     }
 }
예제 #14
0
        private void NotifyChange_CurrentGameObjects(object o, EventArgs e)
        {
            if (!IsConnected || GSM.getInstance().getActiveState() == null)
            {
                _model._currentGameObjects.Clear();
            }
            else
            {
                EditorSubsystemManaged.getInstance().QueueAction(new Action(() => {
                    uint objs = GSM.getInstance().getActiveState().GetManagedObjectsSlotTable().GetNumberOfObjects();
                    //we're also going to check the first id in the list as a sort-of secondary measure in case the entire list has been dup'ed
                    IntPtr firstIDiter = GSM.getInstance().getActiveState().GetManagedObjectsSlotTable().GetAllocatedObjects().create_iterator_begin();
                    uint firstID       = GSM.getInstance().getActiveState().GetManagedObjectsSlotTable().GetAllocatedObjects().get_next_key(firstIDiter).GetID();
                    if ((objs != _previousGameObjects || (_model._currentGameObjects.Count != 0) &&
                         (objs != 0 && firstID != _model._currentGameObjects.ElementAt(0).GetID())))
                    {
                        //rebuild
                        List <GameObject> newItems = new List <GameObject>();
                        GameObjectIterator iter    = new GameObjectIterator(GSM.getInstance().getActiveState());
                        while (true)
                        {
                            GameObject g = GameObject.From(iter.Next());
                            if (g == null)
                            {
                                break;
                            }
                            newItems.Add(g);
                        }

                        _previousGameObjects = objs;

                        //change ui
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            _model._currentGameObjects.Clear(false);
                            _model._currentGameObjects.AddRange(newItems);
                            OnPropertyChanged("NumberOfObjects");
                        }));
                    }
                }));
            }
        }
        public static int gridExtent = 30;          //number of grid lines

        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;        }
        }
        private void GroundSnapButton_Click(object sender, RoutedEventArgs e)
        {
            EngineManagerViewModel view = (this.DataContext as EngineManagerViewModel);

            e.Handled = true;
            if (view.SelectedGameObjects.Count == 0)
            {
                return;
            }
            EditorSubsystemManaged.getInstance().QueueAction(() =>
            {
                foreach (GameObject g in view.SelectedGameObjects)
                {
                    RayCastResult result = PhysicEngine.getInstance().RayCast3D_Output(g.transform.position, Vector3.Down, 1000);
                    if (result.hit)
                    {
                        g.transform.SetPosition(result.intersection);
                    }
                }
            });
        }
 void box_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         string name = (sender as TextBox).Text;
         if (String.IsNullOrWhiteSpace(name))
         {
             return;
         }
         EditorSubsystemManaged.getInstance().QueueAction(() =>
         {
             GameObject g = GameObject.From(ObjectFactory.getInstance().MakeNewGameObject(name, GSM.getInstance().getActiveState()));
             g.transform.SetPosition(EditorSubsystem.getInstance().EditorCamera().gameObject.transform.GetGlobalPosition().Add(
                                         EditorSubsystem.getInstance().EditorCamera().gameObject.transform.GetForwardVector().Mul(3.0f)));
             Dispatcher.Invoke(() =>
             {
                 NewObject_Button.Content = newObject_button_orig_content;
                 HierarchyControlSelectionManager.HierarchyControlStateManager.GObjSelectRefresh(g);
             });
         });
     }
 }
예제 #18
0
        private void TextBlock_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("assetFormat"))
            {
                var thisHandle = (this.DataContext as PropertyValueConverter.PropertyInfo).PropertyValue as AssetHandle;

                AssetItem asset = e.Data.GetData("assetFormat") as AssetItem;
                if (asset.CanDropOn(thisHandle))
                {
                    e.Effects   = DragDropEffects.None;
                    this.Effect = null;

                    EditorSubsystemManaged.getInstance().QueueAction(() => {
                        Dispatcher.Invoke(() =>
                        {
                            this.Set_Handle(AssetManager.getInstance().GetAsset(asset.fileid));
                            (sender as TextBlock).GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
                        });
                    });
                }
            }
        }
 public static void CMD_DuplicateObjects()
 {
     EditorSubsystemManaged.getInstance().QueueAction(() =>
     {
         List <GameObject> selgobj  = EngineManagerViewModel.instance.SelectedGameObjects.ToList();
         List <GameObject> newObjgs = new List <GameObject>();
         foreach (GameObject g in selgobj)
         {
             GameObject newg = GameObject.From(g.Duplicate());
             CMD_AppendNumber(newg);
             newObjgs.Add(newg);
         }
         System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
         {
             HierarchyControlSelectionManager.HierarchyControlStateManager.DeSelectAll();
             foreach (GameObject g in newObjgs)
             {
                 HierarchyControlSelectionManager.HierarchyControlStateManager.GObjAdditiveSelectRefresh(g);
             }
         }));
     });
 }
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            GameObject g = ApplyButton.DataContext as GameObject;

            if (g == null)
            {
                return;
            }
            if (g.linkedPrefab == null)
            {
                return;
            }

            EditorSubsystemManaged.getInstance().QueueAction(new Action(() =>
            {
                g.WriteToPrefab();
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    EngineManagerViewModel.instance.ForceRefreshGameObjects();
                }));
            }));
        }
예제 #21
0
        private void AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            object obj = null;

            if (ci.GetParameters().Count() > 0)
            {
                obj = ci.Invoke(new object[] { new char[] { ' ' } });
            }
            else
            {
                obj = ci.Invoke(null);
            }
            MethodInfo mi = (this.DataContext.GetType().GetMethod("Add"));

            if (mi == null)
            {
                WPFHelper.InvalidateControl(this, "No Add Function on Container");
            }
            object cont = (this.DataContext);

            object[] prms = { obj };
            EditorSubsystemManaged.getInstance().QueueAction(() => { mi.Invoke(cont, prms); });
        }
        void menu_item_Click(object sender, RoutedEventArgs e)
        {
            var menuitem = e.Source as MenuItem;
            EngineManagerViewModel view = (this.DataContext as EngineManagerViewModel);

            e.Handled = true;
            if (view.SelectedGameObjects.Count == 0)
            {
                return;
            }
            string compname = menuitem.DataContext as String;

            EditorSubsystemManaged.getInstance().QueueAction(() =>
            {
                foreach (GameObject g in view.SelectedGameObjects)
                {
                    g.RequireComponentByName(compname);
                }
                Dispatcher.Invoke(() =>
                {
                    ComponentListViewControl.GetBindingExpression(ListView.ItemsSourceProperty).UpdateTarget();
                });
            });
        }