public void StoreItem(int itemId) { if (!BagModel.ItemList.ContainsKey(itemId)) { return; } Transform emptyGrid = bagview.GetEmptyGrid(); if (emptyGrid == null) { Debug.LogWarning("背包已满!!"); return; } Item temp = BagModel.ItemList[itemId]; GameObject itemPrefab = Resources.Load <GameObject>("Prefabs/UI/Item"); Sprite s = Resources.Load <Sprite>("Materials/" + temp.Icon); bagview.UpdateImage(itemPrefab, s); GameObject itemGo = GameObject.Instantiate(itemPrefab); itemGo.transform.SetParent(emptyGrid); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localScale = Vector3.one; BagModel.StoreItem(emptyGrid.name, temp); }
private void SolvePart2() { logger.Information("PART 2 - Calculating the number of bags inside the shiny gold bag"); var shinyBag = new BagModel("shiny gold"); this.AddAllInnersBags(shinyBag); logger.Information($"The {shinyBag.color} bag has {shinyBag.CountBagsInside()} bags inside it !"); }
public async Task <IActionResult> MakeOrder(BagModel input) { var user = await this.userManager.GetUserAsync(this.User); await this.bagService.MakeOrderAsync(user.BagId, input.Order); user.BagId = null; await this.userManager.UpdateAsync(user); this.TempData["orderSent"] = true; return(this.Redirect("/Products/Products")); }
private List <BagModel> FindInnerBags(BagModel bag, List <string> lines) { var innerBags = new List <BagModel>(); foreach (var line in lines.Where(l => l.Contains(bag.color))) { var colors = this.ParseColors(line); if (colors.FirstOrDefault().Equals(bag.color)) { innerBags = this.CreateBagsFromLine(line); } } return(innerBags); }
private void AddAllInnersBags(BagModel bag) { // Add it's own inner bags var newInnerBags = FindInnerBags(bag, this.input); foreach (var newInnerBag in newInnerBags) { bag.AddBags(newInnerBag, newInnerBag.count); } // Call same method on inner bags foreach (var innerBag in bag.innerBags) { AddAllInnersBags(innerBag); } }
/// <summary> /// Creates an instance of <see cref="ConvertMoneyViewModel"/> /// </summary> public ConvertMoneyViewModel(BagModel bagModel) { _bagModel = bagModel; foreach (Currency currency in Enum.GetValues(typeof(Currency))) { if (currency != Currency.None) { _currencyOptions.Add(new KeyValuePair <Currency, string>(currency, _stringService.GetString(currency))); } } _selectedFromCurrencyOption = _currencyOptions[0]; _selectedToCurrencyOption = _currencyOptions[0]; UpdateConversionResults(); }
public void handle(GameEvent e) { Variant data = e.data; foreach (Variant item in data._arr) { string id = item["id"]; if (id != itemid) { continue; } if (itemNum <= BagModel.getInstance().getItemNumById(id)) { onHanlde(e); } } }
/// <summary> /// Creates an instance of <see cref="BagViewModel"/> /// </summary> public BagViewModel(BagModel bagModel) : base() { _bagModel = bagModel; foreach (EquipmentModel equipmentModel in bagModel.Equipment.OrderBy(x => x.Name)) { EquipmentViewModel equipmentViewModel = new EquipmentViewModel(equipmentModel); equipmentViewModel.PropertyChanged += EquipmentViewModel_PropertyChanged; _equipment.Add(equipmentViewModel); } UpdateTotalWeight(); _showAddEquipmentDialogCommand = new RelayCommand(obj => true, obj => ShowAddEquipmentDialog()); _showAddPackDialogCommand = new RelayCommand(obj => true, obj => ShowAddPackDialog()); _showEditEquipmentDialogCommand = new RelayCommand(obj => true, obj => ShowEditEquipmentDialog((EquipmentViewModel)obj)); _removeEquipmentCommand = new RelayCommand(obj => true, obj => RemoveEquipment((EquipmentViewModel)obj)); _showUpdateMoneyDialogCommand = new RelayCommand(obj => true, obj => ShowUpdateMoneyDialog((Currency)obj)); }
public void GridUI_OnEnter(Transform gridTransform) { Debug.Log(gridTransform.name); Item item = BagModel.GetItem(gridTransform.name); if (item == null) { return; } Debug.Log(1); string text = GetTooltipText(item); bagview.UpdateTooltip(text); string text1 = GetPanelText(item); bagview.UpdatePanel(text1); IsOpened = true; ToolTipShow(); }
/// <summary> /// Shows create bag dialog /// </summary> public BagModel ShowCreateBagDialog(string title, BagModel bagModel) { ModalDialog modalDialog = new ModalDialog(); if (_parentWindow != null) { modalDialog.Owner = _parentWindow; } BagModel bagModelCopy = new BagModel(bagModel); CreateBagView createBagView = new CreateBagView(new BagViewModel(bagModelCopy)); modalDialog.WindowTitle = title; modalDialog.Body = createBagView; modalDialog.Confirmation = createBagView.ViewModel; bool?result = ShowDialog(modalDialog); return(result == true ? bagModelCopy : null); }
/// <summary> /// Shows convert money dialog /// </summary> public BagModel ShowConvertMoneyDialog(BagModel bagModel) { ModalDialog modalDialog = new ModalDialog(); if (_parentWindow != null) { modalDialog.Owner = _parentWindow; } BagModel bagModelCopy = new BagModel(bagModel); ConvertMoneyViewModel convertMoneyViewModel = new ConvertMoneyViewModel(bagModelCopy); ConvertMoneyView convertMoneyView = new ConvertMoneyView(convertMoneyViewModel); modalDialog.WindowTitle = "Convert Money"; modalDialog.Body = convertMoneyView; modalDialog.Confirmation = convertMoneyView.ViewModel; bool?result = ShowDialog(modalDialog); return(result == true ? bagModelCopy : null); }
public async Task <IActionResult> Bag() { var user = await this.userManager.GetUserAsync(this.User); var bagProducts = await this.bagService.GetProductsFromBagByIdAsync(user.BagId); var price = await this.bagService.TotalPriceOfBagAsync(user.BagId); var discount = await this.discountsService.ApplyDiscountIfNeedAsync(price); var output = new BagModel { Products = bagProducts, Price = price, PriceWithDiscount = discount == null ? price : discount.PriceWithDiscount, Percent = discount == null ? 0 : discount.Percent, DiscountOverPrice = discount == null ? 0 : discount.OverPrice, Discounts = await this.discountsService.GetDiscountsAsync(), }; return(this.View(output)); }