//Calls object in hand to use it public void throwHeldItem(Vector2 tarGet) { if (handObject != null) { Timing.RunCoroutine(handObject.GetComponent <Material>().Throw(tarGet, 30).CancelWith(handObject), Segment.FixedUpdate); if (newlyHeldObject == true) { handObject = null; handScript = null; if (itemsInInventory() > 0) { makeHandObject(); } newlyHeldObject = false; } else { //If this was an object in your inventory, update Memento ItemMemento tempMemento = handScript.GetMemento() as ItemMemento; if (tempMemento != null) { tempMemento.setParent(handScript); tempMemento.setInInventory(false, handIndex); } //If object was an object from the inventory, remove it from the inventory Remove(handIndex); } //Update UI UpdateUI(); } }
public async void ItemSelectionChanged(object sender, EventArgs e) { // update status bar this._view.StatusText = "Please Wait..."; this._view.ItemsDisplayedText = string.Empty; // delete item button enabled if item is selected this._view.DeleteItemButtonEnabled = this._view.IsItemSelected; int selectedItemId = this._view.SelectedItemId; if (selectedItemId == 0) { // nothing is selected // nothing to do return; } // show spinner // and disable things the user shouldn't play with at this point this._view.ItemDetailsSpinner = true; this._view.FilterGroupEnabled = false; this._view.CategoryGroupEnabled = false; this._view.AddItemEnabled = false; this._view.SearchBooksButtonEnabled = false; this._view.ViewStatisticsEnabled = false; this._view.TagsButtonEnabled = false; this._view.WishlistButtonEnabled = false; this._view.DeleteItemButtonEnabled = false; if (this._view.CategoryDropDownSelectedIndex == 0) { this._view.SelectedItem = await this._bookService.GetById(selectedItemId); } else { this._view.SelectedItem = await this._mediaItemService.GetById(selectedItemId); } this._selectedItemMemento = this._view.SelectedItem.GetMemento(); this._view.DiscardSelectedItemChangesButtonEnabled = false; this._view.SelectedItemDetailsBoxEntry = this._view.SelectedItem.ToString(); // update status bar this._view.StatusText = "Ready."; this._view.ItemsDisplayedText = SetItemsDisplayedStatusText(this._view.NumberOfItemsSelected, this._view.DisplayedItems.Rows.Count, this._allItems.Rows.Count); // hide spinner // and re-enable controls this._view.ItemDetailsSpinner = false; this._view.FilterGroupEnabled = true; this._view.CategoryGroupEnabled = true; this._view.AddItemEnabled = true; this._view.SearchBooksButtonEnabled = true; this._view.ViewStatisticsEnabled = true; this._view.TagsButtonEnabled = true; this._view.WishlistButtonEnabled = true; this._view.DeleteItemButtonEnabled = true; }//ItemSelectionChanged
//This is a secondary add tool used when a PickedUp item is toggled left or right protected bool AddAt(int index, ConcreteItem itemObj) { Item item = itemObj.GetItem(); if (items.Count >= space) { // Send GUI message to Player here (todo), return false. return(false); } // Otherwise we can pick up the item, return true. items.Insert(index, item); //If item has a memento, update it to know the object is now in the players' inventory ItemMemento tempMemento = itemObj.GetMemento() as ItemMemento; if (tempMemento != null) { itemObj.setInInventory(true, handIndex); tempMemento.setParent(null); ItemMementos.Insert(index, tempMemento); } else { ItemMementos.Insert(index, null); } //Create a new ItemBox at index CreateItemBox(index); //Destroy old handObject to make new one if (handObject != null) { Destroy(handObject); } makeHandObject(); return(true); }
public void Restore_Test_NullMemento() { // arrange MockItem item = new MockItem(); // act ItemMemento memento = null; item.Restore(memento); // assert Assert.AreEqual(null, item.Notes); Assert.AreEqual(null, item.Image); }
public void Restore_Test() { // arrange MockItem item = new MockItem(); // act ItemMemento memento = new ItemMemento("test", Encoding.ASCII.GetBytes("test")); item.Restore(memento); // assert Assert.AreEqual("test", item.Notes); Assert.AreEqual(Encoding.ASCII.GetBytes("test"), item.Image); }
public void ItemMemento_Test_ctor() { // arrange string notes = "test"; byte[] bytes = Encoding.ASCII.GetBytes("test"); // act ItemMemento memento = new ItemMemento(notes, bytes); // assert Assert.AreEqual(notes, memento.Notes); Assert.AreEqual(bytes, memento.Image); }
public void GetMemento_Test() { // arrange MockItem item = new MockItem { Notes = "test", Image = Encoding.ASCII.GetBytes("test") }; // act ItemMemento memento = item.GetMemento(); // assert Assert.AreEqual("test", memento.Notes); Assert.AreEqual(Encoding.ASCII.GetBytes("test"), memento.Image); }
//If the object is a one-use, the concreteItem method will call this method to destroy it public void destroyHandObject() { ItemMemento handMemento = handScript.GetMemento() as ItemMemento; if (handMemento) { handMemento.setInInventory(false, 0); } if (newlyHeldObject == true) { handScript.Destroy(); makeHandObject(); newlyHeldObject = false; } else { handScript.Destroy(); Remove(handIndex); } }
public void SaveInventory(QuickLife script) { for (int i = 0; i < items.Count; i++) { if (i == handIndex) { ConcreteItem itemInHand = handScript as ConcreteItem; if (itemInHand) { ItemMementos[i] = itemInHand.CreateInventoryMemento(); //The item in your hand will already be saved in the QuickLife script by the timeVibration script.SaveMemento(ItemMementos[i]); } } else { ItemMemento newMemento = Instantiate(MementoType).GetComponent <ItemMemento>(); newMemento.InitializeInventory(i); script.SaveMemento(newMemento); //Place memento into a list of Mementos ItemMementos[i] = newMemento; } } }