public override void OnSubmit() { SourceCharacter.HasTraded = true; SourceCharacter.HasMoved = true; if (CurrentSide == Side.SOURCE) { TradeMenuItem tradeMenuItem = TradeSourceMenuItems[SourceItemsIndex]; _ = SourceCharacter.Items.Remove(tradeMenuItem.Item); _ = TradeSourceMenuItems.Remove(tradeMenuItem); DestinationCharacter.Items.Add(tradeMenuItem.Item); TradeDestinationMenuItems.Add(new TradeMenuItem(TradeDestinationPanel, tradeMenuItem.Item)); Destroy(tradeMenuItem.Text.gameObject); if (SourceCharacter.Items.Count == 0) { CurrentSide = Side.DESTINATION; SetItemsTextsIndex(TradeDestinationMenuItems, ref _destinationItemsIndex); } else { Debug.LogFormat("Setting source index from {0} to {1}", SourceItemsIndex, Mathf.Min(SourceItemsIndex, TradeSourceMenuItems.Count - 1)); SetItemsTextsIndex(TradeSourceMenuItems, ref _sourceItemsIndex, Mathf.Min(SourceItemsIndex, TradeSourceMenuItems.Count - 1)); } } else { TradeMenuItem tradeMenuItem = TradeDestinationMenuItems[DestinationItemsIndex]; _ = DestinationCharacter.Items.Remove(tradeMenuItem.Item); _ = TradeDestinationMenuItems.Remove(tradeMenuItem); SourceCharacter.Items.Add(tradeMenuItem.Item); TradeSourceMenuItems.Add(new TradeMenuItem(TradeSourcePanel, tradeMenuItem.Item)); Destroy(tradeMenuItem.Text.gameObject); if (DestinationCharacter.Items.Count == 0) { CurrentSide = Side.SOURCE; SetItemsTextsIndex(TradeSourceMenuItems, ref _sourceItemsIndex); } else { SetItemsTextsIndex(TradeDestinationMenuItems, ref _destinationItemsIndex, Mathf.Min(DestinationItemsIndex, TradeDestinationMenuItems.Count - 1)); } } }
/// <summary> /// Show the trade detail panel between two characters /// </summary> /// <param name="sourceCharacter"></param> /// <param name="destinationCharacter"></param> public void Show(Character sourceCharacter, Character destinationCharacter) { SourceCharacter = sourceCharacter; SourceText.text = sourceCharacter.CharacterName; Debug.LogFormat("Source character: {0} with {1} items", sourceCharacter, sourceCharacter.Items.Count); DestinationCharacter = destinationCharacter; DestinationText.text = destinationCharacter.CharacterName; Debug.LogFormat("Destination character: {0} with {1} items", destinationCharacter, destinationCharacter.Items.Count); foreach (Item item in sourceCharacter.Items) { Debug.LogFormat("Adding source item {0}", item); TradeSourceMenuItems.Add(new TradeMenuItem(TradeSourcePanel, item)); } foreach (Item item in destinationCharacter.Items) { Debug.LogFormat("Adding destination item {0}", item); TradeDestinationMenuItems.Add(new TradeMenuItem(TradeDestinationPanel, item)); } if (SourceCharacter.Items.Count > 0) { CurrentSide = Side.SOURCE; SetItemsTextsIndex(TradeSourceMenuItems, ref _sourceItemsIndex); } else if (DestinationCharacter.Items.Count > 0) { CurrentSide = Side.DESTINATION; SetItemsTextsIndex(TradeDestinationMenuItems, ref _destinationItemsIndex); } else { Debug.LogError("Neither character has items to trade."); } transform.position = sourceCharacter.transform.position; Focus(); transform.gameObject.SetActive(true); }