コード例 #1
0
        public override void Select(MainForm frm)
        {
            if (frm.grpUnit.Text == ToString() && frm.MainTab.SelectedTab == frm.tabUnit)
            {
                return;
            }
            Program.MakeSelected(frm.tabUnit, frm.lstUnit, this);

            try
            {
                frm.grpUnit.Text = ToString();
                frm.grpUnit.Show();
#if DEBUG
                frm.grpUnit.Text += $" - ID: {Id}";
#endif

                frm.lblUnitName.Text    = Name;
                frm.lblUnitAltName.Text = AltName;
                frm.lblUnitCoords.Text  = $"({Coords.X}, {Coords.Y}, {Coords.Z})";
                frm.lblUnitSex.Text     = Sex.ToString();
                frm.lblUnitCiv.Data     = Civ;
                frm.lblUnitPop.Data     = Population;
                frm.lblUnitMood.Text    = Mood.ToString();
                frm.lblUnitHF.Data      = HistFigure;
                frm.lblUnitRace.Data    = Race;
                frm.lblUnitCaste.Text   = CasteID.HasValue ? HistoricalFigure.Castes[CasteID.Value] : "";
                if (ProfessionId.HasValue)
                {
                    frm.lblUnitProfession.Text    = JobTypes[ProfessionId.Value];
                    frm.lblUnitProfession.Visible = true;
                }
                else
                {
                    frm.lblUnitProfession.Visible = false;
                }
                frm.lblUnitSquad.Data    = Squad;
                frm.lblUnitOpponent.Data = Opponent;

                frm.grpUnitFlags.Visible = Flag != null;
                frm.lstUnitFlags.Items.Clear();
                if (frm.grpUnitFlags.Visible)
                {
                    frm.lstUnitFlags.Items.AddRange(Flag.Distinct().Select(x => Flags[x].ToLower().Replace("_", " ").ToTitleCase()).ToArray());
                }

                frm.grpUnitLabors.Visible = Labor != null;
                frm.lstUnitLabors.Items.Clear();
                if (frm.grpUnitLabors.Visible && Labor.Any())
                {
                    frm.lstUnitLabors.Items.AddRange(Labor.Distinct().Select(x => Labors[x].ToLower().Replace("_", " ").ToTitleCase()).ToArray());
                }

                frm.grpUnitRelations.Visible = Relations != null;
                frm.lstUnitRelations.Items.Clear();
                if (Relations != null && Relations.Any())
                {
                    frm.lstUnitRelations.Items.AddRange(Relations.Select(x => x.Value).ToArray());
                }

                frm.grpUnitHealth.Visible = HealthFlag != null;
                frm.lstUnitHealth.Items.Clear();
                if (HealthFlag != null && HealthFlag.Any())
                {
                    frm.lstUnitHealth.Items.AddRange(HealthFlag.Distinct().Select(x => HealthFlags[x].ToLower().Replace("_", " ").ToTitleCase()).ToArray());
                }

                frm.grpUnitItems.Visible = OwnedItemIds != null || TradedItemIds != null || UsedItemIds != null;
                frm.trvUnitItems.Nodes.Clear();
                if (frm.grpUnitItems.Visible)
                {
                    if (OwnedItemIds != null)
                    {
                        var node = new TreeNode("Owned Items");
                        foreach (var itemId in OwnedItemIds.Where(i => World.Items.ContainsKey(i)))
                        {
                            node.Nodes.Add(new TreeNode(World.Items[itemId].ToString())
                            {
                                Tag = World.Items[itemId]
                            });
                        }
                        frm.trvUnitItems.Nodes.Add(node);
                    }
                    if (TradedItemIds != null)
                    {
                        var node = new TreeNode("Traded Items");
                        foreach (var itemId in TradedItemIds.Where(i => World.Items.ContainsKey(i)))
                        {
                            node.Nodes.Add(new TreeNode(World.Items[itemId].ToString())
                            {
                                Tag = World.Items[itemId]
                            });
                        }
                        frm.trvUnitItems.Nodes.Add(node);
                    }
                    if (UsedItemIds != null)
                    {
                        var node = new TreeNode("Used Items");
                        foreach (var itemId in UsedItemIds.Where(i => World.Items.ContainsKey(i)))
                        {
                            node.Nodes.Add(new TreeNode(World.Items[itemId].ToString())
                            {
                                Tag = World.Items[itemId]
                            });
                        }
                        frm.trvUnitItems.Nodes.Add(node);
                    }
                }

                frm.grpUnitInventory.FillListboxWith(frm.lstUnitInventory, InventoryItems);
                frm.grpUnitReferences.FillListboxWith(frm.lstUnitReferences, References);

                frm.grpUnitOwnedBuildings.Visible = OwnedBuildingIds != null;
                frm.lstUnitOwnedBuildings.Items.Clear();
                if (OwnedBuildingIds != null)
                {
                    frm.lstUnitOwnedBuildings.Items.AddRange(
                        OwnedBuildingIds.Where(x => World.Buildings.ContainsKey(x))
                        .Select(x => World.Buildings[x]).ToArray());
                }
            }
            finally
            {
                Program.MakeSelected(frm.tabUnit, frm.lstUnit, this);
            }
        }