protected virtual void StoreFailedInternal(PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { StoreFailed(item, dest); } }
protected virtual void RemoveInternal(PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { Remove(item, dest); } }
public override void CanStore(UnityAction onFailed, PGISlotItem item, CellModel dest) { if (!TestFilter(item)) { onFailed(); } }
protected virtual void CanRemoveInternal(UnityAction onFailed, PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { CanRemove(onFailed, item, dest); } }
/// <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 }
/// <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); } }
public SpaceState(int i, PGISlotItem it) { item = null; index = i; area = new Area(-1, -1, -1, -1); item = it; }
void HandleItemDisappeared(PGISlotItem item, PGISlot dest) { if (dest == LinkedSlot) { CheckForDisconnect(item); } }
public SpaceState(Area a, PGISlotItem it) { item = null; index = -1; area = a; item = it; }
protected override void CanRemoveInternal(UnityAction onFailed, PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { CanRemove(onFailed, item, dest); OnCanRemove.Invoke(onFailed, item, dest); } }
protected override void RemoveInternal(PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { Remove(item, dest); OnRemove.Invoke(item, dest); } }
protected override void StoreFailedInternal(PGISlotItem item, CellModel dest) { if (dest == Cell && dest != null) { StoreFailed(item, dest); OnStoreFailed.Invoke(item, dest); } }
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; } }
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); } }
bool Push(int index, PGISlotItem item) { if (!HasSpaceAt(index)) { return(false); } History.Push(new SpaceState(index, item)); Equipment[index] = true; return(true); }
bool Push(Area area, PGISlotItem item) { if (!HasSpaceAt(area)) { return(false); } History.Push(new SpaceState(area, item)); Set(area, true); return(true); }
/// <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); } }
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); }
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)); } }
/// <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); } }
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); }
/// <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); } }
/// <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 } }
public virtual void CanRemove(UnityAction onFailed, PGISlotItem item, CellModel dest) { }
public virtual void Remove(PGISlotItem item, CellModel src) { }
public virtual void StoreFailed(PGISlotItem item, CellModel dest) { }