/// <summary> /// Create a CheckBox corresponding to an element for a specifical StackPanel /// </summary> /// <param name="imageSourcePath">Path that correspond to an element</param> /// <param name="sp">The StackPanel parent of the CheckBox</param> /// <returns></returns> private CheckBox CreateCheckboxElement(string imageSourcePath, StackPanel sp, int idStat) { ImageSourceConverter converter = new ImageSourceConverter(); CheckBox cbx = new CheckBox(); // Recover the item stocked in the StackPanel tag EnchantedItem item = (EnchantedItem)sp.Tag; // Create the image for the checkbox Image img = new Image(); img.Source = (ImageSource)converter.ConvertFromString(imageSourcePath); cbx.Content = img; // Create the event click for the checkbox and save the differents informations that needed // Saving the stackpanel to the tag of the checkbox allows to save the two objects in one properties cbx.Tag = sp; cbx.Name = GlobalConstants.GetElemStringFromImagePath(imageSourcePath); cbx.Click += CbxItemElement_Click; // Check automatically the checkbox if atleast one element is already 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) { switch (imageSourcePath) { case GlobalConstants.FIRE_IMAGE_PATH: if (sp.Name == GlobalConstants.MASTERIES_STRING && item.FireMastery > 0) { cbx.IsChecked = true; } if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.FireResistance > 0) { cbx.IsChecked = true; } break; case GlobalConstants.WATER_IMAGE_PATH: if (sp.Name == GlobalConstants.MASTERIES_STRING && item.WaterMastery > 0) { cbx.IsChecked = true; } if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.WaterResistance > 0) { cbx.IsChecked = true; } break; case GlobalConstants.EARTH_IMAGE_PATH: if (sp.Name == GlobalConstants.MASTERIES_STRING && item.EarthMastery > 0) { cbx.IsChecked = true; } if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.EarthResistance > 0) { cbx.IsChecked = true; } break; case GlobalConstants.AIR_IMAGE_PATH: if (sp.Name == GlobalConstants.MASTERIES_STRING && item.AirMastery > 0) { cbx.IsChecked = true; } if (sp.Name == GlobalConstants.RESISTANCES_STRING && item.AirResistance > 0) { cbx.IsChecked = true; } break; default: break; } } return(cbx); }
/// <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); } } }