Beispiel #1
0
 private async Task HandleVendorDeleted(VendorItemRow arg)
 {
     if (ContentDialogResult.Primary == await this.messageDialog.ShowAsync())
     {
         arg.ItemDeleteClicked -= HandleVendorDeleted;
         this.vendors.Remove(arg);
         await this.vendorRepository.Delete(arg.Vendor);
     }
 }
Beispiel #2
0
 private void populateVendors()
 {
     this.clearVendors();
     foreach (var vendor in this.vendorRepository.GetAllVendors())
     {
         VendorItemRow vendorItemRow = new VendorItemRow
         {
             Vendor = vendor
         };
         vendorItemRow.ItemDeleteClicked += HandleVendorDeleted;
         this.vendors.Add(vendorItemRow);
     }
 }
Beispiel #3
0
    internal void OnVendorRowClicked(VendorItemRow vendorItemRow)
    {
        if (selectedRow)
        {
            selectedRow.HideSelection();
        }

        selectedRow = vendorItemRow;
        selectedRow.ShowSelection();

        btnBuy.interactable  = CanBuySelectedItem();
        btnSell.interactable = CanSellSelectedItem();
    }
Beispiel #4
0
    private int ClearSelection()
    {
        var selectedId = -1;

        if (selectedRow)
        {
            selectedId = selectedRow.Item.Id;
            selectedRow.HideSelection();
            selectedRow          = null;
            btnBuy.interactable  = CanBuySelectedItem();
            btnSell.interactable = CanSellSelectedItem();
        }
        return(selectedId);
    }
Beispiel #5
0
    internal void Show(int npcId, string npcName, string shopName, int[] itemId, int[] itemPrice, int[] itemStock)
    {
        vendorActive = true;

        // ensure we update the can buy / can sell states
        // by clearing out previous state. But keep the last ID so we can re-select it.
        var previousSelection = ClearSelection();

        if (!itemManager)
        {
            itemManager = FindObjectOfType <ItemManager>();
        }

        targetNpcId = npcId;

        if (!string.IsNullOrEmpty(shopName))
        {
            lblShopName.text = shopName;
        }

        gameObject.SetActive(true);

        while (itemRows.Count < itemId.Length)
        {
            var itemRow = Instantiate(vendorItemRowPrefab, itemsPanel).GetComponent <VendorItemRow>();
            itemRows.Add(itemRow);
        }

        for (var i = 0; i < itemRows.Count; ++i)
        {
            var active = i < itemId.Length;
            itemRows[i].gameObject.SetActive(active);
            if (active)
            {
                var item = itemManager.GetItemById(itemId[i]);
                itemRows[i].SetData(item, itemPrice[i], itemStock[i]);

                if (previousSelection == itemRows[i].Item.Id)
                {
                    selectedRow = itemRows[i];
                    selectedRow.ShowSelection();
                }
            }
        }

        btnBuy.interactable  = CanBuySelectedItem();
        btnSell.interactable = CanSellSelectedItem();
    }
Beispiel #6
0
 private void HandleCellEditEnded(DataGridCellEditEndingEventArgs obj)
 {
     if (obj.EditingElement is TextBox textBox && obj.EditAction == DataGridEditAction.Commit)
     {
         string        column         = obj.Column.Tag.ToString();
         int           rowIndex       = obj.Row.GetIndex();
         VendorItemRow existingVendor = Vendors[rowIndex];
         existingVendor.Vendor.GetType().GetProperty(column).SetValue(existingVendor.Vendor, textBox.Text);
         existingVendor.ItemDeleteClicked -= this.HandleVendorDeleted;
         VendorItemRow vendorItem = new VendorItemRow
         {
             Vendor = existingVendor.Vendor
         };
         vendorItem.ItemDeleteClicked += this.HandleVendorDeleted;
         this.Vendors.RemoveAt(rowIndex);
         this.Vendors.Add(vendorItem);
         this.vendorRepository.Create(existingVendor.Vendor);
     }
 }