private void Buy(InventoryEntry entry, InventoryActionClickedArgs e, UIElement clickedControl)
        {
            if (_player.Credits >= e.Credits)
            {
                _player.Credits -= e.Credits;
            }
            else
            {
                // Not enough money
                PlayFailSound(clickedControl);
                return;
            }

            RemoveFrom_Mineral_Part_Ship(entry);

            if (e.Inventory.Ship != null)
            {
                StoreIn_Hangar_Nearby(e.Inventory, e.Name);
            }
            else
            {
                StoreIn_Cargo_Hangar_Nearby(e.Inventory, e.Name);
            }
        }
        private void Sell(InventoryEntry entry, InventoryActionClickedArgs e)
        {
            _player.Credits += e.Credits;

            RemoveFrom_Cargo_Hangar_Neaby(entry);
            StoreIn_Mineral_Part_Ship(entry.Inventory);
        }
        private void InventoryEntry_ActionClicked(object sender, InventoryActionClickedArgs e)
        {
            try
            {
                InventoryEntry entry = sender as InventoryEntry;
                if (entry == null)
                {
                    throw new ApplicationException("Expected sender to be InventoryEntry: " + sender == null ? "<null>" : sender.GetType().ToString());
                }

                switch (e.Action)
                {
                    case ACTION_BUY:
                        #region Buy

                        Buy(entry, e, sender as UIElement);

                        #endregion
                        break;

                    case ACTION_SELL:
                        #region Sell

                        Sell(entry, e);

                        #endregion
                        break;

                    case ACTION_SCRAP:
                        if (e.Inventory.Ship != null)
                        {
                            ScrapShip(entry);
                        }
                        else
                        {
                            throw new ApplicationException("can only scrap ships");     // should also warn the user that scrapping can't be reversed
                        }
                        break;

                    case ACTION_USE:
                        #region Use

                        if (e.Inventory.Ship != null)
                        {
                            SwapShip(entry);
                        }
                        else
                        {
                            throw new ApplicationException("finish this");
                        }

                        // The other two should just be stored in the ship's cargo

                        #endregion
                        break;

                    case ACTION_HANGAR:
                        #region Hangar

                        if (_station.PurchasedVolume - _station.UsedVolume < entry.Inventory.Volume)
                        {
                            PlayFailSound(sender as UIElement);
                            return;
                        }

                        RemoveFrom_Cargo_Hangar_Neaby(entry);
                        StoreIn_Hangar_Nearby(entry.Inventory, e.Name);        // it won't go in nearby, because the if statement made sure the hangar has room

                        #endregion
                        break;

                    case ACTION_REMOVE:
                        #region Nearby

                        RemoveFrom_Cargo_Hangar_Neaby(entry);
                        StoreIn_Nearby(entry.Inventory, e.Name);

                        #endregion
                        break;

                    case ACTION_VIEW:
                        throw new ApplicationException("finish this: " + e.Action);

                    default:
                        throw new ApplicationException("Unknown action: " + e.Action);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }