private void ApplyEdit(bool isDone) { // If the edit rectangle isn't null, we have at least one selection. if (_edit.Rect != null) { using (IEnumerator <Entity> e = _selectedEntities.ToList().GetEnumerator()) { e.MoveNext(); var first = e.Current; Sidebar.Put(); var rect = _edit.Rect !.Value; var newRect = rect; string hoveredX = $"{rect.X}"; string hoveredY = $"{rect.Y}"; string hoveredWidth = $"{rect.Width}"; string hoveredHeight = $"{rect.Height}"; string type = $"{(int)first.Type}"; Label.Put("X"); Textbox.Put(ref hoveredX); Label.Put("Y"); Textbox.Put(ref hoveredY); if (_selectedEntities.Count() == 1) { Label.Put("Width"); Textbox.Put(ref hoveredWidth); Label.Put("Height"); Textbox.Put(ref hoveredHeight); Label.Put("Type"); Textbox.Put(ref type); } if (float.TryParse(hoveredX, out float newX)) { newRect.X = newX; } if (float.TryParse(hoveredY, out float newY)) { newRect.Y = newY; } if (float.TryParse(hoveredWidth, out float newWidth)) { if (newWidth > 0) { newRect.Width = newWidth; } } if (float.TryParse(hoveredHeight, out float newHeight)) { if (newHeight > 0) { newRect.Height = newHeight; } } if (int.TryParse(type, out int newType)) { if (newType != first.Type) { HistoryTypeEntity(first.Id, first.Type, newType); } } if (rect.X != newRect.X || rect.Y != newRect.Y || rect.Width != newRect.Width || rect.Height != newRect.Height) { _edit.Rect = new RectangleF(newRect.X, newRect.Y, newRect.Width, newRect.Height); isDone = true; } Sidebar.Pop(); if (!isDone) { if (_editRectStartXY != (Vector2)_edit.Rect.Value.Position || _editRectStartSize != (Vector2)_edit.Rect.Value.Size) { _editRectStartXY = _edit.Rect.Value.Position; _editRectStartSize = _edit.Rect.Value.Size; Vector2 offset = _editAnchor + _edit.Rect.Value.Position; if (!isDone) { RectangleF oldInset = first.Inset; if (_selectedEntities.Count() == 1) { first.Inset = new RectangleF(first.Offset + offset, _edit.Rect.Value.Size); } else { first.Inset = new RectangleF(first.Offset + offset, first.Inset.Size); } UpdateEntityStorage(first, oldInset); while (e.MoveNext()) { var current = e.Current; oldInset = current.Inset; current.Inset = new RectangleF(current.Offset + offset, current.Inset.Size); UpdateEntityStorage(current, oldInset); } } } } else if (_editRectInitialStartXY != (Vector2)_edit.Rect.Value.Position || _editRectInitialStartSize != (Vector2)_edit.Rect.Value.Size) { _editRectStartXY = _edit.Rect.Value.Position; _editRectStartSize = _edit.Rect.Value.Size; Vector2 oldOffset = _editAnchor + _editRectInitialStartXY; Vector2 newOffset = _editAnchor + _edit.Rect.Value.Position; _historyHandler.AutoCommit = false; HistoryMoveEntity(first.Id, first.Offset + oldOffset, first.Offset + newOffset); if (_selectedEntities.Count() == 1) { HistoryResizeEntity(first.Id, _editRectInitialStartSize, _edit.Rect.Value.Size); } while (e.MoveNext()) { var current = e.Current; HistoryMoveEntity(current.Id, current.Offset + oldOffset, current.Offset + newOffset); } _historyHandler.Commit(); _historyHandler.AutoCommit = true; _editRectInitialStartXY = _edit.Rect.Value.Position; _editRectInitialStartSize = _edit.Rect.Value.Size; } if (_selectedEntities.Count() == 1 && !_edit.IsDragged) { _edit.Rect = first.Inset; _editRectInitialStartSize = first.Inset.Size; } } } }
public void Update(GameTime gameTime) { GuiHelper.CurrentIMGUI = _ui; _ui.UpdateAll(gameTime); if (Triggers.RectDrag.Pressed(false)) { _ui.GrabFocus(null); } Sidebar.Put(isLeftSide: true); string gridSizeString = $"{_gridSize}"; string gridLockString = $"{(_gridLock ? 1 : 0)}"; Label.Put(""); Label.Put("Lock Grid"); Textbox.Put(ref gridLockString); if (Int32.TryParse(gridLockString, out int newGridLock)) { _gridLock = newGridLock == 0 ? false : true; } Label.Put("Grid Size"); if (_gridLock) { Label.Put(gridSizeString); } else { Textbox.Put(ref gridSizeString); if (float.TryParse(gridSizeString, out float newGridSize)) { _gridSize = newGridSize; _gridWorld = _gridSize * Camera.ScreenToWorldScale; _adaptiveGrid = MathF.Max(GetAdaptiveGrid(_gridSize, _gridWorld), _gridSize); } } Label.Put("Adaptive Size"); Label.Put($"{_adaptiveGrid}"); Label.Put("Focal length"); string fl = $"{Camera.FocalLength}"; Textbox.Put(ref fl); if (float.TryParse(fl, out float focalLength)) { var temp = Camera.Z / Camera.FocalLength; Camera.FocalLength = focalLength; Camera.Z = focalLength * temp; } Sidebar.Pop(); bool addModifier = false; bool removeModifier = false; bool skipEditModifier = false; if (!_edit.IsDragged) { addModifier = Triggers.AddModifier.Held(); removeModifier = Triggers.RemoveModifier.Held(); skipEditModifier = Triggers.SkipEditModifier.Held(); } Camera.UpdateInput(); Camera.Update(); if (Triggers.Redo.Pressed()) { _historyHandler.Redo(); ComputedSelectionBounds(); } if (Triggers.Undo.Pressed()) { _historyHandler.Undo(); ComputedSelectionBounds(); } bool isEditDone = false; if (!addModifier && !removeModifier && !skipEditModifier) { if (Triggers.AlignToGrid.Held()) { isEditDone = _edit.UpdateInput(Camera.MouseWorld, false, grid: new Vector2(_adaptiveGrid)); } else { isEditDone = _edit.UpdateInput(Camera.MouseWorld, false); } } var isSelectionDone = _selection.UpdateInput(Camera.MouseWorld); ApplyEdit(isEditDone); SingleHover(); if (Triggers.Create.Pressed()) { Create(); isSelectionDone = true; } if (Triggers.CreateStuff.Pressed()) { CreateStuff(); isSelectionDone = true; } if (Triggers.Paste.Pressed()) { Paste(Camera.MouseWorld); isSelectionDone = true; } if (isSelectionDone) { ApplySelection(addModifier, removeModifier); } if (Triggers.ResetOrder.Pressed()) { ResetOrder(); } if (Triggers.ResetResize.Pressed()) { ResetResize(); } if (Triggers.Remove.Pressed()) { Remove(); } if (Triggers.Cut.Pressed()) { Cut(); } if (Triggers.Copy.Pressed()) { Copy(); } if (Triggers.ToggleLilypads.Pressed()) { _activeLayers ^= World.LayerType.Lilypads; } if (Triggers.ToggleWoods.Pressed()) { _activeLayers ^= World.LayerType.Woods; } if (Triggers.ToggleClouds.Pressed()) { _activeLayers ^= World.LayerType.Clouds; } _pathEditor.UpdateInput(); }