public void LoadUnitTemplates() { FileStream fs = null; try { XmlSerializer serializer = new XmlSerializer(typeof(ModelClasses.Units)); fs = new FileStream(unitsFile, FileMode.Open); definedUnits = (ModelClasses.Units)serializer.Deserialize(fs); fs.Close(); } catch (Exception excp) { if (fs != null) { fs.Dispose(); } } }
public void DrawTab(TabPage selectedPage) { if (selectedPage != null) { selectedPage.AutoScroll = true; selectedPage.Controls.Clear(); int startX = 5; int startY = 5; String battleRole = selectedPage.Text; ModelClasses.Units filteredUnits = new ModelClasses.Units(); foreach (ModelClasses.Unit unit in definedUnits) { if (unit.Faction.Name == selectedDetachment.Faction && unit.BattleRole.Name == battleRole) { filteredUnits.Add(unit); } } ModelClasses.Slot selectedSlot = selectedDetachment.Slots.Where(x => x.BattleRole.Name == battleRole).Distinct().First(); if (selectedSlot != null) { if (selectedSlot.BattleRole.Name == "Transport") { selectedSlot.MinimumUnits = 0; selectedSlot.MaximumUnits = selectedDetachment.GetNumberOfTransportSlots(); } int existingEntries = 0; if (selectedSlot.CreatedUnits == null || !selectedSlot.CreatedUnits.Any()) { existingEntries = 0; } else { int num = 0; foreach (ModelClasses.Unit existingUnit in selectedSlot.CreatedUnits) { CustomControls.UcSlot ucSlot = new CustomControls.UcSlot(filteredUnits, num + 1, existingUnit); if (num < selectedSlot.MinimumUnits) { ucSlot.IsRequired = true; } else { ucSlot.IsRequired = false; } ucSlot.SetPos(new Point(startX, startY)); ucSlot.OnUnitChanged += UcSlot_OnUnitChanged; selectedPage.Controls.Add(ucSlot); startY += ucSlot.Height + 5; num += 1; } existingEntries = selectedSlot.CreatedUnits.Count(); } for (int i = existingEntries; i < selectedSlot.MaximumUnits; i++) { CustomControls.UcSlot ucSlot = new CustomControls.UcSlot(filteredUnits, i + 1); if (i < selectedSlot.MinimumUnits) { ucSlot.IsRequired = true; } else { ucSlot.IsRequired = false; } ucSlot.SetPos(new Point(startX, startY)); ucSlot.OnUnitChanged += UcSlot_OnUnitChanged; selectedPage.Controls.Add(ucSlot); startY += ucSlot.Height + 5; } } } }