public void RestoreState(object state) { //todo var slotStrings = (InventorySlotRecord[])state; for (var i = 0; i < inventorySize; i++) { _slots[i].Item = slotStrings[i].Item; _slots[i].Number = slotStrings[i].Number; } EventMediator eventMediator = FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.InventoryUpdated, this); eventMediator.Broadcast(GlobalHelper.EquipmentUpdated, this); eventMediator.Broadcast(GlobalHelper.PopulateCharacterSheet, this); }
/*public static InputController Instance; * * private void Start() * { * if (Instance == null) * { * Instance = this; * } * else if (Instance != this) * { * Destroy(gameObject); * } * * DontDestroyOnLoad(gameObject); * }*/ private void Update() { //todo this is temp -- should be able to configure the hotkeys on each window and popup //game dev tv inventory course shows how if (Input.GetKeyDown(KeyCode.I)) { var pauseMenu = GameObject.Find("PauseMenuMask"); if (GameManager.Instance.WindowActive(pauseMenu)) { return; } var partyWindow = GameObject.Find("PartyManagementWindowMask"); EventMediator eventMediator = FindObjectOfType <EventMediator>(); if (GameManager.Instance.WindowActive(partyWindow)) { eventMediator.Broadcast(GlobalHelper.HidePartyManagement, this); } else { eventMediator.Broadcast(GlobalHelper.ManageParty, this); } } /*else if (Input.GetKeyDown(KeyCode.Escape)) * { * var pauseMenu = GameObject.Find("PauseMenuMask"); * * EventMediator eventMediator = FindObjectOfType<EventMediator>(); * * if (GameManager.Instance.WindowActive(pauseMenu)) * { * eventMediator.Broadcast(GlobalHelper.HidePauseMenu, this); * } * else * { * eventMediator.Broadcast(GlobalHelper.ShowPauseMenu, this); * } * }*/ }
/// <summary> /// Remove a number of items from the given slot. Will never remove more /// than there are. /// </summary> public void RemoveFromSlot(int slot, int number) { _slots[slot].Number -= number; if (_slots[slot].Number <= 0) { _slots[slot].Number = 0; _slots[slot].Item = null; } EventMediator eventMediator = FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.InventoryUpdated, this); }
/// <summary> /// Attempt to add the items to the first available slot. /// </summary> /// <param name="item">The item to add.</param> /// <param name="number">The number to add.</param> /// <returns>Whether or not the item could be added.</returns> public bool AddToFirstEmptySlot(Item item, int number) { var i = FindSlot(item); if (i < 0) { return(false); } _slots[i].Item = item; _slots[i].Number += number; EventMediator eventMediator = FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.InventoryUpdated, this); return(true); }
/// <summary> /// Will add an item to the given slot if possible. If there is already /// a stack of this type, it will add to the existing stack. Otherwise, /// it will be added to the first empty slot. /// </summary> /// <param name="slot">The slot to attempt to add to.</param> /// <param name="item">The item type to add.</param> /// <param name="number">The number of items to add.</param> /// <returns>True if the item was added anywhere in the inventory.</returns> public bool AddItemToSlot(int slot, Item item, int number) { if (_slots[slot].Item != null) { return(AddToFirstEmptySlot(item, number)); } var i = FindStack(item); if (i >= 0) { slot = i; } _slots[slot].Item = item; _slots[slot].Number += number; EventMediator eventMediator = FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.InventoryUpdated, this); return(true); }