Beispiel #1
0
        private async void Sell(object sender, RoutedEventArgs e)
        {
            if (isSelling)
            {
                return;
            }

            if (item.Stock == 0)
            {
                MessageBox.Show("This item is not in stock.");
                return;
            }

            isSelling = true;

            string      priceString = Item_NewPrice.Text;
            PriceSuffix suffix      = (PriceSuffix)Item_NewPriceSuffix.SelectedItem;

            try
            {
                Price price = priceString.ToPrice(suffix);
                item.Sell(price);
                Item_NewPrice.Clear();
            }
            catch
            {
                MessageBox.Show("Please enter a valid price.");
            }

            await Task.Delay(sameActionTimeout);

            isSelling = false;
        }
Beispiel #2
0
        private async void LogEncounter(object sender, RoutedEventArgs e)
        {
            if (isLogging)
            {
                return;
            }

            isLogging = true;

            string      priceString = Item_NewPrice.Text;
            PriceSuffix suffix      = (PriceSuffix)Item_NewPriceSuffix.SelectedItem;

            try
            {
                Price price = priceString.ToPrice(suffix);
                item.Log(price);
                Item_NewPrice.Clear();
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter a valid price.");
            }

            await Task.Delay(sameActionTimeout);

            isLogging = false;
        }
        private async void AddNewItem(object sender, RoutedEventArgs e)
        {
            if (isAddingItem)
            {
                return;
            }

            isAddingItem = true;
            string      name        = NewItem_Name.Text;
            string      priceString = NewItem_Price.Text;
            PriceSuffix suffix      = (PriceSuffix)NewItem_PriceSuffix.SelectedItem;
            Color?      colour      = NewItem_Colour.SelectedColor;
            string      hex         = colour?.ToString();
            bool        isPurchase  = (bool)NewItem_IsPurchase.IsChecked;

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("Item name can't be empty.");
                return;
            }

            if (string.IsNullOrEmpty(priceString))
            {
                Shop.AddNewItem(name, hex);
            }

            else
            {
                try
                {
                    Price price = priceString.ToPrice(suffix);
                    Shop.AddNewItem(name, price, isPurchase, hex);
                }
                catch (Exception)
                {
                    MessageBox.Show("Please enter a valid price.");
                    return;
                }
            }

            NewItem_Name.Clear();
            NewItem_Price.Clear();
            NewItem_PriceSuffix.SelectedIndex = 0;
            NewItem_Colour.SelectedColor      = default;
            NewItem_IsPurchase.IsChecked      = false;
            Inventory.Items.Refresh(); // hackery to force refresh items

            MessageBox.Show($"Added {name}!");

            await Task.Delay(addItemTimeout);

            isAddingItem = false;
        }
Beispiel #4
0
 private float GetRawPrice(float num, PriceSuffix suffix)
 {
     return(suffix.Equals(PriceSuffix.k) ? num * 1000 : num * 1000000);
 }
Beispiel #5
0
        private float GetShortPrice(float rawNum, PriceSuffix suffix)
        {
            float value = suffix.Equals(PriceSuffix.k) ? rawNum / 1000 : rawNum / 1000000;

            return(value);
        }
Beispiel #6
0
 public Price(float num, PriceSuffix suffix)
 {
     RawPrice = GetRawPrice(num, suffix);
     priceK   = GetShortPrice(RawPrice, PriceSuffix.k);
     priceM   = GetShortPrice(RawPrice, PriceSuffix.m);
 }