public UIElementViewModel ProvideViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign) { if (editor == null) { throw new ArgumentNullException(nameof(editor)); } if (elementDesign == null) { throw new ArgumentNullException(nameof(elementDesign)); } var elementViewModelType = typeof(UIElementViewModel); // try to get the viewmodel type var elementType = elementDesign.UIElement.GetType(); while (elementType != null) { if (elementViewModelTypes.ContainsKey(elementType)) { elementViewModelType = elementViewModelTypes[elementType]; break; } elementType = elementType.BaseType; } return((UIElementViewModel)Activator.CreateInstance(elementViewModelType, editor, asset, elementDesign)); }
protected UIHierarchyItemViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [CanBeNull] IEnumerable <UIElementDesign> children) : base(editor, asset) { if (children != null) { AddItems(children.Select(child => (UIElementViewModel)Editor.CreatePartViewModel(Asset, child))); } }
// Note: constructor needed by UIElementViewModelFactory public PanelViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign) : base(editor, asset, elementDesign, GetOrCreateChildPartDesigns((UIAssetBase)asset.Asset, elementDesign)) { childrenNode = editor.NodeContainer.GetOrCreateNode(AssetSidePanel)[nameof(Panel.Children)].Target; childrenNode.ItemChanged += ChildrenContentChanged; ChangeLayoutTypeCommand = new AnonymousCommand <IUIElementFactory>(ServiceProvider, ChangeLayoutType); UngroupCommand = new AnonymousCommand(ServiceProvider, Ungroup); }
protected UIElementViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign, [CanBeNull] IEnumerable <UIElementDesign> children) : base(editor, asset, children) { AssetSideUIElement = elementDesign.UIElement; ElementType = AssetSideUIElement.GetType(); UIElementDesign = elementDesign; var assetNode = editor.NodeContainer.GetOrCreateNode(elementDesign.UIElement); nameNodeBinding = new MemberGraphNodeBinding <string>(assetNode[nameof(UIElement.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService); propagator = new GameEditorChangePropagator <UIElementDesign, UIElement, UIElementViewModel>(Editor, this, elementDesign.UIElement); PanelCommand = new AnonymousCommand <PanelCommandMode>(ServiceProvider, PanelCommandImpl); RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true); UpdateSourceLibrary(); var basePrefabNode = Editor.NodeContainer.GetNode(UIElementDesign)[nameof(UIElementDesign.Base)]; basePrefabNode.ValueChanged += BaseElementChanged; }
// Note: constructor needed by UIElementViewModelFactory public ContentControlViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign) : base(editor, asset, elementDesign, GetOrCreateChildPartDesigns((UIAssetBase)asset.Asset, elementDesign)) { contentNode = editor.NodeContainer.GetOrCreateNode(AssetSideUIElement)[nameof(ContentControl.Content)]; contentNode.ValueChanged += ContentChanged; }
public void ChangeChildElementLayoutProperties([NotNull] UIElement child, PanelCommandMode mode) { if (child == null) { throw new ArgumentNullException(nameof(child)); } using (var transaction = Editor.UndoRedoService.CreateTransaction()) { var canvas = AssetSidePanel as Canvas; if (canvas != null) { var pinOrigin = GetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey); switch (mode) { case PanelCommandMode.PinTopLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinTop: pinOrigin.X = 0.5f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinTopRight: pinOrigin.X = 1.0f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinCenter: pinOrigin.X = 0.5f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinRight: pinOrigin.X = 1.0f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinBottomLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinBottom: pinOrigin.X = 0.5f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinBottomRight: pinOrigin.X = 1.0f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinFront: pinOrigin.Z = 1.0f; break; case PanelCommandMode.PinMiddle: pinOrigin.Z = 0.5f; break; case PanelCommandMode.PinBack: pinOrigin.Z = 0.0f; break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } SetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey, pinOrigin); Editor.UndoRedoService.SetName(transaction, $"Change Pin Origin of {UIEditorBaseViewModel.GetDisplayName(child)}"); return; } var grid = AssetSidePanel as GridBase; if (grid != null) { PropertyKey <int> propertyKey; int offset; switch (mode) { case PanelCommandMode.MoveUp: propertyKey = GridBase.RowPropertyKey; offset = -1; break; case PanelCommandMode.MoveDown: propertyKey = GridBase.RowPropertyKey; offset = 1; break; case PanelCommandMode.MoveLeft: propertyKey = GridBase.ColumnPropertyKey; offset = -1; break; case PanelCommandMode.MoveRight: propertyKey = GridBase.ColumnPropertyKey; offset = 1; break; case PanelCommandMode.MoveBack: propertyKey = GridBase.LayerPropertyKey; offset = -1; break; case PanelCommandMode.MoveFront: propertyKey = GridBase.LayerPropertyKey; offset = 1; break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } var currentValue = GetDependencyPropertyValue(child, propertyKey); var newValue = Math.Max(0, currentValue + offset); SetDependencyPropertyValue(child, propertyKey, newValue); Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}"); return; } var stackPanel = AssetSidePanel as StackPanel; if (stackPanel != null) { var collection = AssetSidePanel.Children; var index = collection.IndexOf(child); if (index == -1) { throw new InvalidOperationException("The given element is not a child of this panel."); } int newIndex; switch (mode) { case PanelCommandMode.MoveDown: newIndex = index + 1; if (newIndex >= collection.Count) { return; } break; case PanelCommandMode.MoveUp: newIndex = index - 1; if (newIndex < 0) { return; } break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } // FIXME: review if this is fine doing it that way or if we need to do it the same way as when moving elements around childrenNode.Remove(child, new NodeIndex(index)); childrenNode.Add(child, new NodeIndex(newIndex)); Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}"); } } }
protected UIRootViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, IEnumerable <UIElementDesign> rootElements) : base(editor, asset, rootElements) { rootPartsNode = Editor.NodeContainer.GetNode(UIAsset.Hierarchy)[nameof(AssetCompositeHierarchyData <UIElementDesign, UIElement> .RootParts)].Target; rootPartsNode.ItemChanged += RootUIElementsChanged; }
// Note: constructor needed by UIElementViewModelFactory public UIElementViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign) : this(editor, asset, elementDesign, null) { }