public void TrashItem(PGISlotItem item, PGIModel inv, PGISlot slot) { //This helper method will handle all of the magic for us. //It makes sure the item is unequipped and removed from the inventory //and triggers all of the necessary events. inv.Drop(item); }
public void OnUnequip(PGISlotItem item, PGIModel inv, PGISlot slot) { foreach (var dis in disableSlots) { dis.Blocked = true; } }
/// <summary> /// Triggered just before this item is equipped. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void CanUnequip(PGISlotItem item, PGIModel inv, PGISlot slot) { if (ShowDebugCanMessages) { Debug.Log("<color=yellow>Can unequip</color> " + this.gameObject.name + " from " + slot.gameObject.name + " in " + inv.gameObject.name + "?"); } }
/// <summary> /// Initializes all cells so that the are filled appropriate based on the model. /// Note that blocked cells are marked as filled. /// </summary> public void Init(PGIModel model) { for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { var item = model.GetCellContents(x, y); Grid[x, y] = item == null ? false : true; if (Grid[x, y] && (model.IsCellBlocked(x, y) || model.IsCellDisabled(x, y))) { Grid[x, y] = true; } } } for (int i = 0; i < Equipment.Length; i++) { var item = model.GetEquipmentContents(i); Equipment[i] = item == null ? false : true; if (Equipment[i] && model.IsCellBlocked(i)) { Equipment[i] = true; } } }
public CellModel(int x, int y, PGIModel model) { EquipIndex = -1; xPos = x; yPos = y; Model = model; }
public void OnEquip(PGISlotItem item, PGIModel inv, PGISlot slot) { if (!this.enabled) { return; } //Check to see if the equipped item has an ItemType component ItemType type = item.GetComponent <ItemType>(); if (type != null)//type.TypeName.Equals("Two-handed Weapon")) { //It does. So we need to block if (LowerLinkedSlots != null) { foreach (PGISlot linked in LowerLinkedSlots) { linked.Blocked = true; //HACK ALERT: //This is a work-around for a bug introduced with the advent of 3D mesh icons. //This simply ensures the linked slot's default icon is restored as it should be. linked.gameObject.SetActive(false); linked.gameObject.SetActive(true); } } } }
/// <summary> /// Triggered when this item fails to equip. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void StoreInInventoryFailed(PGISlotItem item, PGIModel inv) { if (ShowDebugMessages) { Debug.Log("<color=red>Failed to store</color> " + this.gameObject.name + " in " + inv.gameObject.name); } }
public CellModel(int index, PGIModel model) { EquipIndex = index; xPos = -1; yPos = -1; Model = model; }
/// <summary> /// Triggered when this item is unequipped. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void Unequip(PGISlotItem item, PGIModel inv, PGISlot dest) { if (ShowDebugMessages) { Debug.Log("<color=cyan>Unequipped</color> " + this.gameObject.name + " from " + dest.gameObject.name + " in " + inv.gameObject.name); } }
/// <summary> /// Triggered when this item fails to equip. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void EquipFailed(PGISlotItem item, PGIModel inv, PGISlot failedDest) { if (ShowDebugMessages) { Debug.Log("<color=red>Failed to equip</color> " + this.gameObject.name + " to " + failedDest.gameObject.name + " in " + inv.gameObject.name); } }
/// <summary> /// Triggered when this item is equipped. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void Equip(PGISlotItem item, PGIModel inv, PGISlot from) { if (ShowDebugMessages) { Debug.Log("<color=blue>Equipped</color> " + this.gameObject.name + " to " + from.gameObject.name + " in " + inv.gameObject.name); } }
public void CanEquip(PGISlotItem item, PGIModel inv, PGISlot slot) { //If we are equipping on of the filter's types, then we need to see if //any of the linked slots are full or blocked. if (LinkedSlots != null) { ItemType type = item.GetComponent <ItemType>(); if (type != null && TypesThatUseMultiSlots != null) { if (TypesThatUseMultiSlots.Contains(type.TypeName)) { foreach (PGISlot linked in LinkedSlots) { if (linked.Item != null || linked.Blocked) { //disallow equipping inv.CanPerformAction = false; return; } } } } } //Either the item is not using multiple slots or, if it is, //the linked slots are all empty and unblocked. Good to go! return; }
public void OnUnequip(PGISlotItem item, PGIModel inv, PGISlot slot) { if (!this.enabled) { return; } if (LowerLinkedSlots != null) { foreach (PGISlot linked in LowerLinkedSlots) { //Warning, we are making the assumption that nothing else //had previously blocked this slot. //HACK ALERT: We need to check for Blocked stat before changing it here //due to the changes made for the 3D icon system and the highlight colors //used by items when equipped to slots. if (linked.Blocked) { linked.Blocked = false; } if (linked.Item != null && !toggleAll) { break; } } } }
/// <summary> /// Used to trigger any OnStoreInInventoryFailed events for this item, /// and the associated inventory. /// <seealso cref="PGISlotItem.OnStoreInInventoryFailed"/> /// <seealso cref="PGIModel.OnStoreItemFailed"/> /// </summary> /// <param name="storage">The <see cref="PGIModel"/> whose inventory this item had attempted to enter.</param> public void TriggerStoreFailedEvents(PGIModel storage) { OnStoreInInventoryFailed.Invoke(this, storage); if (storage != null) { storage.OnStoreItemFailed.Invoke(this, storage); } }
/// <summary> /// Used to trigger any OnRemoved events for this item, /// and the associated inventory. /// <seealso cref="PGISlotItem.OnRemoveFromInventory"/> /// <seealso cref="PGIMode.OnRemoveItem"/> /// </summary> /// <param name="storage">The <see cref="PGIModel"/> whose inventory this item is being removed from.</param> public void TriggerRemoveEvents(PGIModel storage) { OnRemoveFromInventory.Invoke(this, storage); if (storage != null) { storage.OnRemoveItem.Invoke(this, storage); } }
/// <summary> /// Used to trigger any 'CanRemove' events in the item, or inventory just before dropping this item. /// If any attached handler wishes to invalidate this check they must /// set the <see cref="PGIModel.CanPerformAction"/> flag to <c>false</c> /// in the provided model parameter. /// <seealso cref="PGISlotItem.OnCanRemove"/> /// <seealso cref="PGIModel.OnCanRemoveItem"/> /// </summary> /// <param name="storage">The <see cref="PGIModel"/> whose inventory this item is being removed from.</param> public void TriggerCanRemoveEvents(PGIModel storage) { OnCanRemove.Invoke(this, storage); if (storage != null) { storage.OnCanStoreItem.Invoke(this, storage); } }
/// <summary> /// Triggered just before this item is unequipped. /// If you wish to stop the action set the passed PGIModel's /// 'CanPerformAction' flag to false. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void CanEquip(PGISlotItem item, PGIModel inv, PGISlot slot) { inv.CanPerformAction = true; if (ShowDebugCanMessages) { Debug.Log("<color=yellow>Can equip</color> " + this.gameObject.name + " to " + slot.gameObject.name + " in " + inv.gameObject.name + "?"); } }
/// <summary> /// Used to mark this item as being stored within a grid /// at the given location. This usually gets called internally /// by a <see cref="PGIModel"/> when storing an item. /// </summary> /// <param name="storage">The <see cref="PGIModel"/> that this item is being stored in.</param> /// <param name="x">The x coordinate in the gird or -1.</param> /// <param name="y">The y coordinate in the grid or -1.</param> public void ProcessStorage(PGIModel storage, int x, int y) { Equipped = -1; xInvPos = x; yInvPos = y; Model = storage; SetNewParentTransform(Model); }
/// <summary> /// Makes sure we close the container if we remove it from our inventory. /// </summary> /// <param name="item">The item being equipped.</param> /// <param name="model">The model the item is being equipped within.</param> public void OnDrop(PGISlotItem item, PGIModel model) { //POINT OF INTERNEST: The view being closed would normally return the DraggedItem (i.e. this item) //to it's model when it is disabled. However, a slight delay in the view's //internal OnDisable() method allows us the time we need to actually drop //this item and finish up processing. ContainerPanel.SetActive(false); }
public void TrashItem(PGISlotItem item, PGIModel inv, PGISlot slot) { //This helper method will handle all of the magic for us. //It makes sure the item is unequipped and removed from the inventory //and triggers all of the necessary events. inv.Drop(item); PGIModel.PostMovementEvents(item, null, slot.CorrespondingCell.Model); //this is a workaround for the fact that the item doesn't have a model currently due to the way drag n drop works }
/// <summary> /// Triggered after this item is removed from the given inventory. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void DropFromInventory(PGISlotItem item, PGIModel inv) { if (ShowDebugMessages) { Debug.Log("<color=grey>Dropping</color> " + this.gameObject.name + " from " + inv.gameObject.name); } SetPhysicalManifestation(true); }
/// <summary> /// Marks this item as being equipped to an equipment slot /// with the given index. This usually gets called internally /// by a <see cref="PGIModel"/> when equipping an item. /// <seealso cref="PGIModel.Equipment"/> /// </summary> /// <param name="storage">The <see cref="PGIModel"/> that this item is being stored in.</param> /// <param name="equipIndex">The index of the equipment slot in the <see cref="PGIModel"/>.</param> public void ProcessEquip(PGIModel storage, int equipIndex) { Equipped = equipIndex; xInvPos = -1; yInvPos = -1; Model = storage; SetNewParentTransform(Model); }
/// <summary> /// Triggered after this item is being stored in the given inventory. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void StoreInInventory(PGISlotItem item, PGIModel inv) { if (ShowDebugMessages) { Debug.Log("<b>Storing</b> " + this.gameObject.name + " in " + inv.gameObject.name); } SetPhysicalManifestation(false); }
/// <summary> /// Triggered just before this item is leaves the inventory. /// If you wish to stop the action set the passed PGIModel's /// 'CanPerformAction' flag to false. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void CanRemove(PGISlotItem item, PGIModel inv) { //we must set this flag or the item will not be able to be moved. if (ShowDebugCanMessages) { Debug.Log("<color=yellow>Can remove</color> " + this.gameObject.name + " from " + inv.gameObject.name + "?"); } }
/// <summary> /// Returns the state of a PGIModel's space. /// </summary> /// <param name="model"></param> public SimulatedModelSpace(PGIModel model) { Assert.IsNotNull(model); Equipment = new bool[model.EquipmentCellsCount]; Width = model.GridCellsX; Height = model.GridCellsY; Grid = new bool[Width, Height]; }
/// <summary> /// Used to trigger any 'CanUnequip' events in the item, slot, or inventory just before unequipping the item. /// If any attached handler wishes to invalidate this check they must /// set the <see cref="PGIModel.CanPerformAction"/> flag to <c>false</c> /// in the provided model parameter. /// <seealso cref="PGISlotItem.OnCanUnequip"/> /// <seealso cref="PGIModel.OnCanUnequipItem"/> /// <seealso cref="PGISlot.OnCanUnequipItem"/> /// </summary> /// <returns><c>true</c> if this instance can equip the specified storage destSlot; otherwise, <c>false</c>.</returns> /// <param name="storage">The <see cref="PGIModel"/> whose equipment slot this item is being removed from.</param> /// <param name="destSlot">The <see cref="PGISlot"/> that this item is being unequipped from.</param> public void TriggerCanUnequipEvents(PGIModel storage, PGISlot destSlot) { OnCanUnequip.Invoke(this, storage, destSlot); destSlot.OnCanUnequipItem.Invoke(this, storage, destSlot); if (storage != null) { storage.OnCanUnequipItem.Invoke(this, storage, destSlot); } }
/// <summary> /// Triggered just before this item is enters the inventory. /// If you wish to stop the action set the passed PGIModel's /// 'CanPerformAction' flag to false. /// </summary> /// <param name="item">Item.</param> /// <param name="inv">Inv.</param> public void CanStore(PGISlotItem item, PGIModel inv) { inv.CanPerformAction = true; //we must set this flag or the item will not be able to be moved. if (ShowDebugCanMessages) { Debug.Log("<color=yellow>Can store</color> " + this.gameObject.name + " in " + inv.gameObject.name + "?"); } }
public void OnStore(PGISlotItem item, PGIModel model) { gameObject.SetActive(false); gameObject.transform.position = model.transform.position; if (PickupSound != null) { AudioSource.PlayClipAtPoint(PickupSound, transform.position); } }
/// <summary> /// Loads a PGIModel from a given file path and replaces this component's model with it. /// </summary> /// <param name="path"></param> public void Load(string path) { if (!string.IsNullOrEmpty(path)) { XmlDocument doc = new XmlDocument(); doc.InnerXml = File.ReadAllText(path); PGIModel.LoadModel(doc.InnerXml, 1, ref Model); } }
/// <summary> /// Loads a PGIModel from a given file path relative to the persistent data path /// and replaces this component's model with it. /// </summary> /// <param name="path"></param> public void LoadFromPersistentPath(string path) { if (!string.IsNullOrEmpty(Application.persistentDataPath + "/" + path)) { XmlDocument doc = new XmlDocument(); doc.InnerXml = File.ReadAllText(Application.persistentDataPath + "/" + path); PGIModel.LoadModel(doc.InnerXml, 1, ref Model); } }
public void OnStoreItem( PGISlotItem item, PGIModel model ) { if( !enabled ) { return; } // Don't bother if we are disabled if( item.GetComponent<ModuleItem>() != null ) { UpdatePreview(); } }
/// <summary> /// Updates the <see cref="PlayerSaveData" /> to matcha a change in the <see cref="PGIModel" />. /// </summary> /// <param name="arg0">The item removed.</param> /// <param name="pgiModel">The model ???</param> private void OnRemoveItem( PGISlotItem arg0, PGIModel pgiModel ) { if( !m_keepSyncedWithInventory ) { return; } PlayerData_Unsub(); UnitItem unitItem = arg0.GetComponent<UnitItem>(); if( unitItem != null ) { m_saveData.UnitDefinitions.Remove( unitItem.Unit ); m_saveData.NotifyChanges(); } PlayerData_Sub(); }
/// <summary> /// Updates the <see cref="PlayerSaveData" /> to matcha a change in the <see cref="PGIModel" />. /// </summary> /// <param name="arg0">The item removed.</param> /// <param name="pgiModel">The model ???</param> private void OnRemoveItem( PGISlotItem arg0, PGIModel pgiModel ) { if( !m_keepSyncedWithInventory ) { return; } PlayerData_Unsub(); ModuleItem moduleItem = arg0.GetComponent<ModuleItem>(); if( moduleItem != null ) { m_saveData.Modules.Remove( moduleItem.Module ); m_saveData.NotifyChanges(); } PlayerData_Sub(); }