public ContainerItem(string name, string caption, Vector2 position, Shape shape, int stackSize, int count) : base(name, position, shape) { this.StackSize = stackSize; this.Count = count; this.Caption = caption; this.State = UIContentState.Floating; }
/// <summary> /// Dock the content at a container /// </summary> /// <param name="container"></param> public virtual void Dock(Container container) { if (!CanDockAt(container) || !container.CanAccept(this)) { if (LastContainer != null) { MoveTo(LastContainer); } else { MoveTo(LastPosition); } return; } ContainerItem other = container.GetContentAt(this.Position); if (other != null) { //its not empty, check if it is the same and then try to stack if (this.StackSize > 1 && this.Name == other.Name) { int s = other.Count + this.Count; if (s <= other.StackSize) { //this stacks fits with the other stack this.Destroyed = true; other.Count = s; other.StackSizeChanged(); } else { //return any left-overs other.Count = other.StackSize; other.StackSizeChanged(); this.Count = s - other.StackSize; this.StackSizeChanged(); if (LastContainer != null) { MoveTo(LastContainer); } else { MoveTo(LastPosition); } } return; } } this.Container = container; if (this.Parent != null) { this.Parent.RemoveComponent(this); } container.AddComponent(this); State = UIContentState.Docked; }
/// <summary> /// Move the content to a specific target container /// </summary> /// <param name="container"></param> public virtual void MoveTo(Container container) { if (this.Container != null) { Undock(); } State = UIContentState.Moving; tween = 1; moveOrigin = this.Position; targetContainer = container; targetPosition = container.Position; }
/// <summary> /// Call undock to start dragging/moving a content /// </summary> public virtual void Undock() { this.LastContainer = this.Container; LastPosition = Position; if (this.Container != null) { this.Container.RemoveComponent(this); this.Container.GetAncestor <UILayer>().AddComponent(this); this.Container = null; } State = UIContentState.Dragged; }
/// <summary> /// Drop the content at a specific location /// </summary> /// <param name="position"></param> public virtual void DropAt(Vector2 position) { if (!CanFloat && LastContainer != null) { MoveTo(LastContainer); } else { HandleMessage(Messages.SetPosition, Position); State = UIContentState.Floating; LastContainer = null; } }
/// <summary> /// Move the content to a specific target position /// </summary> /// <param name="position"></param> public virtual void MoveTo(Vector2 position) { if (this.Container != null) { Undock(); } State = UIContentState.Moving; tween = 1; moveOrigin = this.Position; targetContainer = null; targetPosition = position; Selected = 0; }