Exemplo n.º 1
0
 protected virtual void StoreFailedInternal(PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         StoreFailed(item, dest);
     }
 }
Exemplo n.º 2
0
 protected virtual void RemoveInternal(PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         Remove(item, dest);
     }
 }
Exemplo n.º 3
0
 public override void CanStore(UnityAction onFailed, PGISlotItem item, CellModel dest)
 {
     if (!TestFilter(item))
     {
         onFailed();
     }
 }
Exemplo n.º 4
0
 protected virtual void CanRemoveInternal(UnityAction onFailed, PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         CanRemove(onFailed, item, dest);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Helper used to rotate images to match orientation but only if it is for grid.
        /// Equipment is ignored since it doesn't affect anything non-visual.
        /// </summary>
        void OrientIcon(PGISlotItem item)
        {
            if (!this.IsEquipmentSlot)
            {
                UIRotate rotateEffect = IconImage.GetComponent <UIRotate>();
                if (rotateEffect != null)
                {
                    switch (item.RotatedDir)
                    {
                    case PGISlotItem.RotateDirection.None:
                    {
                        rotateEffect.EulerAngles = Vector3.zero;
                        break;
                    }

                    case PGISlotItem.RotateDirection.CW:
                    {
                        rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 270.0f);
                        break;
                    }

                    case PGISlotItem.RotateDirection.CCW:
                    {
                        rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 90.0f);
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    } //end switch
                }     //end null check
            }         //end if
        }
Exemplo n.º 6
0
        /// <summary>
        /// Runs a simulation of pushing the item into a model.
        /// </summary>
        /// <param name="item">The item to test storing.</param>
        public bool PushStore(PGISlotItem item, bool allowEquipment, bool equipmentFirst, out SpaceState state)
        {
            if (!allowEquipment)
            {
                equipmentFirst = false;
            }


            SpaceState space = SpaceState.Invalid;

            if (equipmentFirst)
            {
                space = FindFirstEquipmentLocation();
            }
            if (space.IsInvalid)
            {
                space = FindFirstAvailableGridLocation(item);
            }
            if (space.IsInvalid && allowEquipment)
            {
                space = FindFirstEquipmentLocation();
            }

            if (Push(space, item))
            {
                state = History.Peek();
                return(true);
            }
            else
            {
                state = SpaceState.Invalid;
                return(false);
            }
        }
Exemplo n.º 7
0
 public SpaceState(int i, PGISlotItem it)
 {
     item  = null;
     index = i;
     area  = new Area(-1, -1, -1, -1);
     item  = it;
 }
Exemplo n.º 8
0
 void HandleItemDisappeared(PGISlotItem item, PGISlot dest)
 {
     if (dest == LinkedSlot)
     {
         CheckForDisconnect(item);
     }
 }
Exemplo n.º 9
0
 public SpaceState(Area a, PGISlotItem it)
 {
     item  = null;
     index = -1;
     area  = a;
     item  = it;
 }
Exemplo n.º 10
0
 protected override void CanRemoveInternal(UnityAction onFailed, PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         CanRemove(onFailed, item, dest);
         OnCanRemove.Invoke(onFailed, item, dest);
     }
 }
Exemplo n.º 11
0
 protected override void RemoveInternal(PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         Remove(item, dest);
         OnRemove.Invoke(item, dest);
     }
 }
Exemplo n.º 12
0
 protected override void StoreFailedInternal(PGISlotItem item, CellModel dest)
 {
     if (dest == Cell && dest != null)
     {
         StoreFailed(item, dest);
         OnStoreFailed.Invoke(item, dest);
     }
 }
Exemplo n.º 13
0
 void CanHandleMove(UnityAction onFailed, PGISlotItem item, PGISlot dest)
 {
     //don't allow linking through directly setting. Must have a source slot
     if (dest == null || dest.CorrespondingCell == null)
     {
         onFailed();
         return;
     }
 }
Exemplo n.º 14
0
 public void CheckForDisconnect(PGISlotItem item)
 {
     if (LinkedSlot != null)
     {
         //reset if dest not us and item is no longer in our reference spot
         LinkedSlot.OnRemoveItem.RemoveListener(HandleItemDisappeared);
         LinkedSlot = null;
         OnUnlink.Invoke(item, this);
     }
 }
Exemplo n.º 15
0
 bool Push(int index, PGISlotItem item)
 {
     if (!HasSpaceAt(index))
     {
         return(false);
     }
     History.Push(new SpaceState(index, item));
     Equipment[index] = true;
     return(true);
 }
Exemplo n.º 16
0
 bool Push(Area area, PGISlotItem item)
 {
     if (!HasSpaceAt(area))
     {
         return(false);
     }
     History.Push(new SpaceState(area, item));
     Set(area, true);
     return(true);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Sets the state for a given item in the simulation model.
 /// Remember that <c>true</c> means 'occupied' and <c>false</c>
 /// means 'empty'.
 /// </summary>
 public void Set(PGISlotItem item, bool state)
 {
     if (item == null)
     {
         return;
     }
     if (item.IsEquipped)
     {
         Set(item.Equipped, state);
     }
     else
     {
         Set(new Area(item.xInvPos, item.yInvPos, item.CellWidth, item.CellHeight), state);
     }
 }
Exemplo n.º 18
0
        SpaceState FindFirstAvailableGridLocation(PGISlotItem item)
        {
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Area a = new Area(x, y, item.CellWidth, item.CellHeight);
                    if (HasSpaceAt(a))
                    {
                        return(new SpaceState(a, item));
                    }
                }
            }

            return(SpaceState.Invalid);
        }
Exemplo n.º 19
0
 bool Push(SpaceState space, PGISlotItem item)
 {
     space.item = item;
     if (space.IsInvalid)
     {
         return(false);
     }
     if (space.IsEquipment)
     {
         return(Push(space.index, item));
     }
     else
     {
         return(Push(space.area, item));
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Compares this slot item's size to another slot item's size.
        /// Items with bigger sizes come before items with smaller sizes.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            PGISlotItem other = obj as PGISlotItem;

            if (other == null)
            {
                return(1);
            }
            if (SortByWidth)
            {
                return(other.CellWidth - this.CellWidth);
            }
            else
            {
                return(other.CellHeight - this.CellHeight);
            }
        }
Exemplo n.º 21
0
        bool TestFilter(PGISlotItem item)
        {
            //filter out what can and can't be stored
            if (AllowedIds != null && AllowedIds.Length > 0)
            {
                var type = item.GetComponent <ItemType>();
                if (type == null)
                {
                    return(false);
                }

                if (HashedString.DoNotContain(AllowedIds, type.TypeName.Hash))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Overrides the base implementation and feeds the item back to the source if any.
        /// This allows us to keep the item in both places at once.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        void HandleMove(PGISlotItem item, PGISlot dest, PGISlot src)
        {
            if (dest == this)
            {
                var srcModel = src.CorrespondingCell;
                if (srcModel != null)
                {
                    //place the item back into the source it came from
                    PGIModel.RemoveItem(item, false);
                    PGIModel.StoreItem(item, srcModel, false);

                    //link ourself to the source
                    OriginalCell.Item = null;
                    LinkedSlot        = src;
                    src.OnRemoveItem.AddListener(HandleItemDisappeared);

                    OnLink.Invoke(item, this);
                }
            }
            else
            {
                CheckForDisconnect(item);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Assigns the item to this slot. This will set both the <see cref="PGISlot.Item"/>
        /// property and <see cref="PGISlot.IconImage"/>'s sprite or <see cref="PGISlot.IconMesh"/>'s mesh and material property.
        /// </summary>
        /// <param name="item">The <see cref="PGISlotItem"/> to assign.</param>
        public virtual void AssignItem(PGISlotItem item, bool setIcon = true)
        {
            if (!Ready)
            {
                return;
            }
            //TODO: We probably can skip this entire process if the incoming item matches
            //the one already stored in this slot. This needs testing though!

            var oldItem = Item;

            Item = item;

            //set the icon
            if (Item == null)
            {
                //if (!Blocked && View != null) this.HighlightColor = this.View.NormalColor;
                SetDefaultIcon();
            }
            else
            {
                //make sure default color is removed - otherwise we might tint our icon incorrectly
                IconImage.color = Color.white;

                //we need to check for this so we don't override another color set by the view.
                //if (!Blocked && oldItem == null) this.HighlightColor = item.Highlight;

                //trigger stacksize UI element to update
                if (this._Item != null)
                {
                    StackCount = _Item.StackCount;
                }
                else if (LastStackCount != 0)
                {
                    //this will reset our stack count when the slot goes empty
                    StackCount = 0;
                }

                //set icon data
                if (item.IconType == PGISlotItem.IconAssetType.Sprite && IconImage != null)
                {
                    Icon = item.Icon;
                    IconMesh.material = null;
                    IconMesh.Rotation = item.IconOrientation;
                    Icon3D            = null;

                    IconImage.enabled = true;
                    IconMesh.enabled  = false;

                    //the second instance of this component is for the rotation of the slot item
                    //regardless of the orientation in the model (i.e. arbitrary visual rotation)
                    UIRotate[] rot = IconImage.GetComponents <UIRotate>();
                    if (rot != null && rot.Length > 1)
                    {
                        rot[1].EulerAngles = item.IconOrientation;
                    }
                }
                else if (item.IconType == PGISlotItem.IconAssetType.Mesh && IconMesh != null)
                {
                    Icon = null;
                    IconMesh.material = item.IconMaterial;
                    IconMesh.Rotation = item.IconOrientation;
                    Icon3D            = item.Icon3D;

                    IconImage.enabled = false;
                    IconMesh.enabled  = true;
                }

                //fallback in case we are somehow missing a sprite *and* a mesh for this item's icon.
                else
                {
                    SetDefaultIcon();
                }

                //rotate image to match orientation but only if it is for grid
                if (!this.IsEquipmentSlot)
                {
                    UIRotate rotateEffect = IconImage.GetComponent <UIRotate>();
                    if (rotateEffect != null)
                    {
                        switch (item.RotatedDir)
                        {
                        case PGISlotItem.RotateDirection.None:
                        {
                            rotateEffect.EulerAngles = Vector3.zero;
                            break;
                        }

                        case PGISlotItem.RotateDirection.CW:
                        {
                            rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 270.0f);
                            break;
                        }

                        case PGISlotItem.RotateDirection.CCW:
                        {
                            rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 90.0f);
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        } //end switch
                    }     //end null check
                }         //end if
            }
        }
Exemplo n.º 24
0
 public virtual void CanRemove(UnityAction onFailed, PGISlotItem item, CellModel dest)
 {
 }
Exemplo n.º 25
0
 public virtual void Remove(PGISlotItem item, CellModel src)
 {
 }
Exemplo n.º 26
0
 public virtual void StoreFailed(PGISlotItem item, CellModel dest)
 {
 }