public formEditor() { InitializeComponent(); AllowDrop = true; StaticEditorMode.LevelInstance = new Level(); objectsUnderCursor = new List <BaseActor>(); MouseWheel += editorControl_GameView_OnMouseWheel; editorControl_GameView.MouseMove += editorControl_GameView.UpdateCoords; StaticEditorMode.SelectionChanged += o => { if (propertyGrid1.SelectedObject is BaseActor actor) { actor.PropertyChanged -= OnSelectedValueChanged; } propertyGrid1.SelectedObject = o; if (propertyGrid1.SelectedObject is BaseActor newActor) { newActor.PropertyChanged += OnSelectedValueChanged; treeViewHierarchy.SelectedNode = treeViewHierarchy.Nodes.Find(newActor.Id, true).First() ?? treeViewHierarchy.TopNode; } }; hScrollBar1.Minimum = editorControl_GameView.Width / 2; hScrollBar1.Maximum = 3000; vScrollBar1.Minimum = editorControl_GameView.Height / 2; vScrollBar1.Maximum = 3000; StaticGlobalInput.InitialiseInputHandlers(editorControl_GameView); _propertyGridRefreshTimer = new Timer(); _propertyGridRefreshTimer.Interval = _propertyGridRefreshInterval; _propertyGridRefreshTimer.Tick += delegate { _canRefreshPropertyGrid = true; }; _propertyGridRefreshTimer.Start(); PopulateTree(); }
private void editorControl_GameView_OnMouseWheel(object sender, MouseEventArgs e) { StaticGlobalInput.HandleMouseWheel(e); if (editorControl_GameView.Focused) { if (e.Delta > 0) { editorControl_GameView.Camera.Zoom += 0.05f; } else if (e.Delta < 0) { editorControl_GameView.Camera.Zoom -= 0.05f; } UpdateZoomTracker(); } }
private void editorControl_GameView_MouseUp(object sender, MouseEventArgs e) { StaticGlobalInput.HandleMouseButtons(e, false); _ScaleInprogress = false; }
private void editorControl_GameView_MouseMove(object sender, MouseEventArgs e) { StaticGlobalInput.HandleMouseMovement(e); var p = GetMouseVPos(); objectsUnderCursor.Clear(); SetObjectsUnderPoint(p); switch (StaticEditorMode.EditorMode) { case EditorMode.ScaleMode: { if (IsSomethingSelected()) { // Do not rescale unless the mouse is over the object if (objectsUnderCursor.Contains(StaticEditorMode.SelectedObject) || _ScaleInprogress) { Cursor = Cursors.SizeNWSE; if ((StaticGlobalInput.currentMouse.LeftButton == ButtonState.Pressed)) { _ScaleInprogress = true; StaticEditorMode.SelectedObject.Scale += (StaticGlobalInput.GetMousePosDelta().ToVector2() * 0.01f); StaticEditorMode.SelectedObject.Scale += (StaticGlobalInput.GetMousePosDelta().ToVector2() * 0.01f); break; } } } if (objectsUnderCursor.Count == 0) { Cursor = Cursors.Default; } break; } case EditorMode.Selectmode: { Cursor = objectsUnderCursor.Count > 0 ? Cursors.Hand : Cursors.Default; break; } case EditorMode.MoveAsset: { Cursor = objectsUnderCursor.Count > 0 ? Cursors.NoMove2D : Cursors.Default; if (IsSomethingSelected()) { foreach (var actor in StaticEditorMode.LevelInstance.Assets) { if (actor.BoundingBox.Contains(p)) { objectsUnderCursor.Add(actor); } } // Do not move unless the mouse is over the object if ((StaticGlobalInput.currentMouse.LeftButton == ButtonState.Pressed) && objectsUnderCursor.Contains(StaticEditorMode.SelectedObject)) { // As the treeview is already populated, use it to quickly get all children and move them var itemRoot = treeViewHierarchy.Nodes.Find(StaticEditorMode.SelectedObject.Id, true).FirstOrDefault(); if (itemRoot != null) { ExecuteOnActorAndAllTreeChildren(itemRoot, (node, actor) => { actor.Position = actor.Position + (StaticGlobalInput.GetMousePosDelta().ToVector2() * (1f / editorControl_GameView.Camera.Zoom)); }); } } } else { Cursor = Cursors.Default; } break; } case EditorMode.AssetPlacement: { //TODO Add placement break; } } if (StaticGlobalInput.currentMouse.MiddleButton == ButtonState.Pressed) { editorControl_GameView.Camera.Pos -= StaticGlobalInput.GetMousePosDelta().ToVector2(); editorControl_GameView.Camera.Pos = Vector2.Clamp(editorControl_GameView.Camera.Pos, new Vector2(hScrollBar1.Minimum, vScrollBar1.Minimum), new Vector2(hScrollBar1.Maximum, vScrollBar1.Maximum)); hScrollBar1.Value = (int)editorControl_GameView.Camera.Pos.X; vScrollBar1.Value = (int)editorControl_GameView.Camera.Pos.Y; } }
private void editorControl_GameView_MouseDown(object sender, MouseEventArgs e) { StaticGlobalInput.HandleMouseButtons(e, true); var p = GetMouseVPos(); //if (!StaticGlobalInput.IsNewLeftClick()) { // return; //} // Right click should not place an object if (StaticGlobalInput.IsNewRightClick()) { editorControl_GameView.Camera.Zoom = 1.0f; UpdateZoomTracker(); return; } switch (StaticEditorMode.EditorMode) { case EditorMode.Selectmode: { StaticEditorMode.SelectedObject = objectsUnderCursor.OrderByDescending(actor => actor.Depth).LastOrDefault(); break; } case EditorMode.AssetPlacement: { if ((StaticGlobalInput.currentMouse.LeftButton == ButtonState.Pressed)) { if (listBox_Assets.SelectedItem == null) { MessageBox.Show(Resources.SelectAssetError, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (IsValidContent(listBox_Assets.SelectedItem.ToString(), typeof(Texture2D))) { if (listBox_Assets.SelectedItem != null) { var asset = new Asset(StaticEditorMode.ContentManager, listBox_Assets.SelectedItem.ToString(), p.ToVector2()); StaticEditorMode.LevelInstance.Assets.Add(asset); AddTreeNodeFromAsset(asset); StaticEditorMode.SelectedObject = asset; } } else { MessageBox.Show(string.Format(Resources.InvalidAssetType, typeof(Texture2D)), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } break; } case EditorMode.MoveAsset: { if (!objectsUnderCursor.Contains(StaticEditorMode.SelectedObject)) { StaticEditorMode.SelectedObject = objectsUnderCursor.OrderByDescending(actor => actor.Depth).LastOrDefault(); } break; } } }