private void PlaceBone(JointVM firstJoint, JointVM secondJoint) { var bone = new Bone(firstJoint.Model, secondJoint.Model); var boneVM = new BoneVM(bone); if (CanvasVM.Creature.CreatureStructureVM.BoneCollectionVM.Any(b => { if (b.FirstJoint.Model.Tracker == firstJoint.Model.Tracker && b.SecondJoint.Model.Tracker == secondJoint.Model.Tracker) { return(true); } if (b.FirstJoint.Model.Tracker == secondJoint.Model.Tracker && b.SecondJoint.Model.Tracker == firstJoint.Model.Tracker) { return(true); } return(false); })) { var infoMessage = new InfoMessage("Bone already placed between those joints", TimeSpan.FromSeconds(2), Brushes.Red); InfoMessageCollection.AddInfoMessageWithoutTracking(infoMessage); return; } var changeOperation = new ChangeOperation(c => { c.Creature.CreatureStructureVM.BoneCollectionVM.Add(boneVM); }, c => { c.Creature.CreatureStructureVM.BoneCollectionVM.Remove(boneVM); }); CanvasVM.HistoryStack.AddOperation(changeOperation); Reset(); FirstJoint = secondJoint; CanvasVM.PreviewBone.From = FirstJoint.Position; }
/// <inheritdoc /> public override void OnSelected() { var jointMessage = new InfoMessage("By pressing the Ctrl-Key you will only select joints", TimeSpan.FromSeconds(10)); var boneMessage = new InfoMessage("By pressing the Alt-Key you will only select bones", TimeSpan.FromSeconds(10)); var shiftMessage = new InfoMessage("By pressing the Shift-Key you can select multiple elements", TimeSpan.FromSeconds(10)); var panMessage = new InfoMessage("Hold down the middle mouse button to move the canvas around", TimeSpan.FromSeconds(10)); if (!InfoMessageCollection.HasShownMessage(jointMessage)) { InfoMessageCollection.AddInfoMessage(jointMessage); } if (!InfoMessageCollection.HasShownMessage(boneMessage)) { InfoMessageCollection.AddInfoMessage(boneMessage); } if (!InfoMessageCollection.HasShownMessage(shiftMessage)) { InfoMessageCollection.AddInfoMessage(shiftMessage); } if (!InfoMessageCollection.HasShownMessage(panMessage)) { InfoMessageCollection.AddInfoMessage(panMessage); } }
/// <inheritdoc /> public override bool OnCanvasMouseUp(MouseInfo mouseInfo, CreatureStructureEditorCanvasVM canvasVM, ModifierKeys modifierKeys) { CanvasVM = CanvasVM ?? canvasVM; if (base.OnCanvasMouseUp(mouseInfo, canvasVM, modifierKeys)) { return(true); } if (mouseInfo.RightMouseButtonDown) { bool block = FirstJoint != null; Reset(); return(block); } var mousePosition = new Vector2(mouseInfo.RelativePosition.X, mouseInfo.RelativePosition.Y); var jointCollectionVM = canvasVM.Creature.CreatureStructureVM.JointCollectionVM; var closestJointInRange = (from jointVM in jointCollectionVM let distance = (jointVM.Position - mousePosition).Length where distance < DistanceThreshold orderby distance select jointVM).FirstOrDefault(); if (closestJointInRange == null) { if (FirstJoint != null) { var infoMessage = new InfoMessage("To cancel the bone placement just right click anywhere on the canvas", TimeSpan.FromSeconds(5)); if (!InfoMessageCollection.InfoMessages.Any(m => string.Equals(m.Message, infoMessage.Message, StringComparison.Ordinal))) { InfoMessageCollection.AddInfoMessageWithoutTracking(infoMessage); } } else { var infoMessage = new InfoMessage("To place a bone, first place joints with the respective tool and then connect them with this tool", TimeSpan.FromSeconds(5)); if (!InfoMessageCollection.InfoMessages.Any(m => string.Equals(m.Message, infoMessage.Message, StringComparison.Ordinal))) { InfoMessageCollection.AddInfoMessageWithoutTracking(infoMessage); } } return(true); } canvasVM.PreviewBone.To = mousePosition; if (FirstJoint == null) { FirstJoint = closestJointInRange; canvasVM.PreviewBone.From = FirstJoint.Position; } else { PlaceBone(FirstJoint, closestJointInRange); } return(false); }
/// <inheritdoc /> public override void OnSelected() { var shortCut = new InfoMessage("You can quickly switch between tools via their shortcuts. Just hover over the icons to see them", TimeSpan.FromSeconds(10)); if (!InfoMessageCollection.HasShownMessage(shortCut)) { InfoMessageCollection.AddInfoMessage(shortCut); } }