public bool FoldedEvents = false; //used by the inspector #endregion #region Methods /// <summary> /// Marks this object as being in one of three states that represent rotation /// in grid-axis space. Effectively all it does is swap the item's /// height and width, store a 'rotated' state flag, and rotate the UI image. /// </summary> /// <remarks> /// If the item is currently stored within a model then it may not be possible to /// rotate the item and have it remain within that model. The object will attempt /// to automatically adjust its position so that it can fit while still maintaining /// some vailence with its original position, however if it is not possible the operation /// will fail and the item will remain unrotated. The item will always succeed at being /// rotated if it is not currently within a model. /// </remarks> /// <returns><c>true</c> if the item was rotated, <c>false</c> otherwise.</returns> /// <param name="dir">The absolute direction to have the item's top rotated towards. </param> public bool Rotate(RotateDirection dir) { if (_RotatedDir == dir) { return(false); } if (CellWidth == CellHeight) { return(false); } PGIModel.Pos newPos = null; PGIModel model = this.Model; if (model != null && this.IsStored) { //If in a grid we'll have to check for viable 'vailence' positions for the rotated object. //i.e. positions that are still overlapping where the item was before it was rotated. //If we can't make the object fit roughly in the same place as before when rotated //then we'll have to fail. newPos = Model.FindVailencePosition(this, dir); if (newPos == null) { return(false); } } if (newPos != null && model != null) { PGIModel.RemoveItem(this, false); } //regarldess of where it is stored, the item needs some basic //stats changes and its image rotated. int temp = CellHeight; CellHeight = CellWidth; CellWidth = temp; _RotatedDir = dir; //This should only be called when the 'this.Model' is non-null and //the item is stored in the grid but we can safely assume for now //that if 'newPos' is non-null then this is the case. if (newPos != null && model != null) { PGIModel.StoreItem(this, model.GetCellModel(newPos.X, newPos.Y), 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); } }