/// <summary> /// // Show the stat of the item selected in the user control /// </summary> /// <param name="item">The item we want to show</param> private void LoadItemsStatsToContent(EnchantedItem item, bool itemCanBeRemoved = false) { UcStatsItems uc = new UcStatsItems(); LoadItemToUserControlStats(item, uc, itemCanBeRemoved); CCtrlItemStats.Content = uc; }
/// <summary> /// Equip selected item when double click /// </summary> private void ItemsDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { UcStatsItems u = (UcStatsItems)CCtrlItemStats.Content; EquipItemToBuild(u.BtnEquip, null); } catch (Exception) { // Catch exception when the UcStatsItem is null } }
private void RemoveItemToBuild(object sender, RoutedEventArgs e) { // To access to the selected item we have to get the UcStatsItems that triggered this event Button btn = (Button)sender; Grid grid = (Grid)btn.Parent; UcStatsItems ucStatsParent = (UcStatsItems)grid.Parent; ActualBuild.RemoveItem(ucStatsParent.ActualItem); UcActualBuildStats.UpdateView(); }
/// <summary> /// // Create a modal form who contains the stats of the item selected /// </summary> /// <param name="item">The item we want to show</param> /// <param name="itemCanBeEquiped">If true, then the button for equiped the item will be showed. Else it will be the button for removing the item that will be showed</param> private void CreateModalOfItemStats(EnchantedItem item) { ModalItemStats modal = new ModalItemStats(); UcStatsItems uc = new UcStatsItems(); LoadItemToUserControlStats(item, uc); modal.CCtrlItemStats.Content = uc; modal.Show(); // We have to bring the modal form in front after displaying it modal.Topmost = true; }
/// <summary> /// Try to equip the selected item to the build /// </summary> private void EquipItemToBuild(object sender, RoutedEventArgs e) { // To access to the selected item we have to get the UcStatsItems that triggered this event Button btn = (Button)sender; Grid grid = (Grid)btn.Parent; UcStatsItems ucStatsParent = (UcStatsItems)grid.Parent; if (ucStatsParent.ActualItem.ConditionsRespected) { ucStatsParent.LblInfo.Content = String.Empty; // If it's not a ring, then we can try to equip it directly if (ucStatsParent.ActualItem.IdType != Build.ID_RING) { if (!ActualBuild.EquipItem(ucStatsParent.ActualItem)) { // TODO: show error message when the item can't be equiped } } else { // else we have to determine if the user want to equip the ring to the left or right hand FrmChooseSideRing frmChooseSideRing = new FrmChooseSideRing(this); frmChooseSideRing.ShowDialog(); if (InsertRingToLeft != null) { if (InsertRingToLeft == true) { ActualBuild.EquipRingLeft(ucStatsParent.ActualItem); } else { ActualBuild.EquipRingRight(ucStatsParent.ActualItem); } } } UcActualBuildStats.UpdateView(); } else { ucStatsParent.LblInfo.Content = "Pas assez d'éléments sélectionnées."; } }
/// <summary> /// Load the item selected with formated stats to the user control for stats /// </summary> private void LoadItemToUserControlStats(EnchantedItem item, UcStatsItems uc, bool itemCanBeRemoved = false) { uc.ActualItem = item; uc.LblItemName.Text = item.Name; uc.LblItemLvl.Content = "Niv." + item.Level; uc.LblItemRarity.Content = item.RarityName; uc.LblItemType.Content = item.Type; uc.ImgItemPicture.Source = Tools.LoadImage(item.Image); uc.ImgItemRarity.Source = Tools.LoadImage(item.RarityImage); uc.BtnEquip.Click += EquipItemToBuild; if (itemCanBeRemoved) { uc.BtnEquip.Content = "Modifier"; uc.BtnRemove.Visibility = Visibility.Visible; uc.BtnRemove.Click += RemoveItemToBuild; } // Customize the items of the listbox for each stats in the item loaded foreach (Stat stat in item.StatList) { if (stat.Type == "Coup Critique" || stat.Type == "Parade") { stat.Type = "% " + stat.Type.Trim(); } else { // When we add the space to the stat we have to trim it first for avoiding multiple space stat.Type = " " + stat.Type.Trim(); } // Create stackpanel for the stats StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; TextBlock tb = new TextBlock(); tb.Text = stat.Value + stat.Type; sp.Children.Add(tb); uc.LbxItemStats.Items.Add(sp); // If the stat correspond to multiplte elements of masteries or resistances, // then we must create an new StackPanel with checkbox for each elements if (GlobalConstants.IDS_ELEM_ARRAY.Contains(stat.Id)) { sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; // Save the actual item to the tag for recovering his properties later sp.Tag = item; // Define the name of the StackPanel with a string for masteries or resistances // This information will be needed later bool?elemForMasteries = GlobalConstants.IdForMasteriesOrResistances(stat.Id); if (elemForMasteries == true) { sp.Name = GlobalConstants.MASTERIES_STRING; } else if (elemForMasteries == false) { sp.Name = GlobalConstants.RESISTANCES_STRING; } else { Console.WriteLine("Unknown id of masteries or resistances for the tag of the stackpanel"); } // Add the checkbox to the stackpanel int cbxFireIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.FIRE_IMAGE_PATH, sp, stat.Id)); int cbxWaterIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.WATER_IMAGE_PATH, sp, stat.Id)); int cbxEarthIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.EARTH_IMAGE_PATH, sp, stat.Id)); int cbxAirIndex = sp.Children.Add(CreateCheckboxElement(GlobalConstants.AIR_IMAGE_PATH, sp, stat.Id)); // Check automatically the checkbox if no elements are selected if ((item.FireMastery == 0 && item.WaterMastery == 0 && item.EarthMastery == 0 && item.AirMastery == 0) || (item.FireResistance == 0 && item.WaterResistance == 0 && item.EarthResistance == 0 && item.AirResistance == 0)) { int nbElement = GlobalConstants.GetNbOfElementById(stat.Id); for (int i = 0; i < nbElement; i++) { CheckBox cbx; switch (DefaultMasteriesOrder.MasteriesOrder[i]) { case GlobalConstants.Elementary.Fire: cbx = (CheckBox)sp.Children[cbxFireIndex]; cbx.IsChecked = true; CbxItemElement_Click(cbx, null); break; case GlobalConstants.Elementary.Water: cbx = (CheckBox)sp.Children[cbxWaterIndex]; cbx.IsChecked = true; CbxItemElement_Click(cbx, null); break; case GlobalConstants.Elementary.Earth: cbx = (CheckBox)sp.Children[cbxEarthIndex]; cbx.IsChecked = true; CbxItemElement_Click(cbx, null); break; case GlobalConstants.Elementary.Air: cbx = (CheckBox)sp.Children[cbxAirIndex]; cbx.IsChecked = true; CbxItemElement_Click(cbx, null); break; default: break; } } } uc.LbxItemStats.Items.Add(sp); } } }