private TreeNode AddNode(TreeNode parent, string propname, object obj) { if (obj == null) { return(parent.AddItemWithImage(propname ?? "<null>", obj, null)); } return(parent.AddItemWithImage(propname ?? obj.ToSpacedString().Capitalize(), obj, obj is IPictorial ? (obj as IPictorial).Icon : null)); }
/// <summary> /// Binds the tree nodes for a planet's cargo or a ship's cargo. /// </summary> /// <param name="cc"></param> /// <param name="ccnode"></param> private void BindUnitsIn(ICargoContainer cc, TreeNode ccnode) { foreach (var ur in cc.Cargo.Units.GroupBy(u => u.Design.Role)) { // unit roles var urnode = ccnode.AddItemWithImage(ur.Count() + "x " + ur.Key, ur.Key, ur.Majority(u => u.Icon)); foreach (var ud in ur.GroupBy(u => u.Design)) { // unit designs var udnode = urnode.AddItemWithImage(ud.Count() + "x " + ud.Key.Name, ud.Key, ud.Key.Icon); foreach (var u in ud) { // units var unode = udnode.AddItemWithImage(u.Name, u, u.Icon); var orders = Empire.Current.Commands.OfType <AddOrderCommand>() .Where(x => x.Order is RecycleFacilityOrCargoOrder o && x.Executor == cc && o.Target == u) .Select(x => ((RecycleFacilityOrCargoOrder)x.Order).Behavior.Verb); if (orders.Any()) { unode.Text += $" ({string.Join(", ", orders)})"; var n = unode.Parent; while (n != null) { if (!n.Text.EndsWith("*")) { n.Text += " *"; } n = n.Parent; } } } } } }
private TreeNode CreateNode(TreeNode parent, IMobileSpaceObject v) { TreeNode node; node = parent.AddItemWithImage(v.Name + ": " + CalculateStatus(v), v, v.Icon); if (v is Fleet) { foreach (var sub in ((Fleet)v).Vehicles) { CreateNode(node, sub); } } return(node); }
public void Bind() { tree.Initialize(32); var unitTypes = new List <VehicleTypes> { VehicleTypes.Drone, VehicleTypes.Fighter, VehicleTypes.Mine, VehicleTypes.Satellite, VehicleTypes.Troop, VehicleTypes.WeaponPlatform }; if (CargoContainer != null) { var cargo = CargoContainer.Cargo; var used = cargo.Size; var total = CargoContainer.CargoStorage; var free = used - total; TreeNode typesNode; if (ShowAllUnitsAndPopulationAlways) { typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var vt in unitTypes) { typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt)); } typesNode.Expand(); } if (CargoContainer.AllUnits.Any()) { if (!ShowAllUnitsAndPopulationAlways) { typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType)) { typesNode.AddItemWithImage($"All {ug.Key}s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key)); } typesNode.Expand(); } foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType)) { var typeNode = tree.GetAllNodes().First(x => x.Tag.ToString() == ug.Key.ToString()); foreach (var ug2 in ug.GroupBy(u => u.Design)) { var designNode = typeNode.AddItemWithImage(ug.Count() + "x \"" + ug2.Key.Name + "\" " + ug2.Key.VehicleTypeName + " (" + ug2.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.First().Icon); foreach (var u in ug2) { designNode.AddItemWithImage(u.Name, u, u.Icon); } } } var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.Role)) { rolesNode.AddItemWithImage(ug.Count() + "x " + ug.Key, ug.Key, ug.First().Icon); } rolesNode.Expand(); } TreeNode popNode = null; if (ShowAllUnitsAndPopulationAlways) { popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon); } if (CargoContainer.AllPopulation.Any()) { if (popNode == null) { popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon); } foreach (var pop in CargoContainer.AllPopulation) { popNode.AddItemWithImage(pop.Value.ToUnitString(true) + " " + pop.Key + " Population", pop.Key, pop.Key.Icon); } popNode.Expand(); } lblTonnage.Text = "Cargo Storage Free: " + CargoContainer.CargoStorageFree().Kilotons() + "\n" + "Population Storage Free: " + CargoContainer.PopulationStorageFree.ToUnitString(true); } else if (CargoDelta != null) { TreeNode typesNode; if (ShowAllUnitsAndPopulationAlways) { typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var vt in unitTypes) { typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt)); } typesNode.Expand(); } else { if (CargoDelta.UnitTypeTonnage.Any()) { typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var ug in CargoDelta.UnitTypeTonnage) { typesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key.ToSpacedString() + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key)); } typesNode.Expand(); } } if (CargoDelta.UnitRoleTonnage.Any()) { var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var ug in CargoDelta.UnitRoleTonnage) { rolesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); } rolesNode.Expand(); } if (CargoDelta.UnitDesignTonnage.Any()) { var designsNode = tree.AddItemWithImage("Units - Designs", "Designs", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var ug in CargoDelta.UnitDesignTonnage) { designsNode.AddItemWithImage(ug.Value.Kilotons("All") + " \"" + ug.Key.Name + "\" " + ug.Key.VehicleType + "s + (" + ug.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.Key.Icon); } designsNode.Expand(); } if (CargoDelta.Units.Any()) { var unitsNode = tree.AddItemWithImage("Units - Individual (" + CargoDelta.Units.Count + ")", "Units", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath)); foreach (var u in CargoDelta.Units) { unitsNode.AddItemWithImage(u.Name, u, u.Icon); } // don't expand the units node, there's probably tons of stuff there! } TreeNode popNode = null; if (ShowAllUnitsAndPopulationAlways || CargoDelta.AllPopulation) { popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon); popNode.Expand(); } if (CargoDelta.RacePopulation.Any() || CargoDelta.AnyPopulation != 0) { if (popNode == null) { popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon); } foreach (var pop in CargoDelta.RacePopulation) { popNode.AddItemWithImage(pop.Value.ToUnitString(true, 4, "All") + " " + pop.Key + " Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", pop.Key, pop.Key.Icon); } if (CargoDelta.AnyPopulation != 0) { popNode.AddItemWithImage(CargoDelta.AnyPopulation.ToUnitString(true, 4) + " Population of Any Race (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Total", Pictures.GetGenericImage(typeof(Race))); } popNode.Expand(); } // TODO - estimate tonnage based on available cargo, but we'd need the cargo transfer target for that... lblTonnage.Text = "Estimated Tonnage: " + CargoDelta.EstimatedTonnage.Kilotons("Unknown"); } }