Summary description for BorderPanelFactory.
Inheritance: IOverlayElementFactory
Ejemplo n.º 1
0
        public void PopulateUpgradePanel()
        {
            var upgradeCounter = 0;
            overlay.Hide();

            // (Re)create cost-sorted collections.
            upgradePanelsByCost = new Dictionary<int, List<BorderPanel>>();
            upgradesByCost = playerShip.UpgradeGroup.GetUpgradesByCost();
            foreach (var cost in upgradesByCost.Keys)
                upgradePanelsByCost.Add(cost, new List<BorderPanel>());

            // Clear upgrades.
            masterUpgradePanel.Children.Clear();
            costSelectorPanels.Clear();

            // UpgradeHUD panel.
            masterUpgradePanel.MetricsMode = MetricsMode.Relative;
            masterUpgradePanel.VerticalAlignment = VerticalAlignment.Bottom;
            masterUpgradePanel.HorizontalAlignment = HorizontalAlignment.Center;
            masterUpgradePanel.Top = -0.09f;
            masterUpgradePanel.Left = -0.5f;
            masterUpgradePanel.Width = 1.0f;
            masterUpgradePanel.Height = 0.09f;
            overlay.AddElement(masterUpgradePanel);

            // Cost indicators.
            foreach (var list in upgradesByCost)
            {
                var indicatorPanel = new BorderPanelFactory().Create("Cost Indicator " + list.Key) as BorderPanel;
                if (indicatorPanel == null) return;
                indicatorPanel.MetricsMode = MetricsMode.Relative;
                indicatorPanel.BorderMaterialName = whiteMaterialName;
                indicatorPanel.SetBorderSize(0.0005f, 0.0005f, 0.0005f, 0f);
                indicatorPanel.Top = 0f;
                indicatorPanel.Left = masterUpgradePanel.Width * upgradeCounter / UpgradeGroup.NumberOfUpgrades + 0.006f;
                indicatorPanel.Width = masterUpgradePanel.Width * list.Value.Count / UpgradeGroup.NumberOfUpgrades - 0.012f;
                indicatorPanel.Height = 0.015f;
                indicatorPanel.IsVisible = false;
                masterUpgradePanel.AddChild(indicatorPanel);
                costSelectorPanels.Add(list.Key, indicatorPanel);

                var indicatorLabel = new TextAreaFactory().Create(list.Key + " Indicator Label") as TextArea;
                if (indicatorLabel == null) return;
                indicatorLabel.MetricsMode = MetricsMode.Pixels;
                indicatorLabel.FontName = "Candara";
                indicatorLabel.Text = list.Key.ToString();
                indicatorLabel.TextAlign = HorizontalAlignment.Center;
                indicatorLabel.HorizontalAlignment = HorizontalAlignment.Center;
                indicatorLabel.VerticalAlignment = VerticalAlignment.Top;
                indicatorLabel.CharHeight = 36;
                indicatorLabel.Top = -28.0f;
                indicatorLabel.Left = 0.0f;
                indicatorLabel.Width = indicatorPanel.Width;
                indicatorLabel.Height = indicatorPanel.Height;
                indicatorLabel.Color = white;
                indicatorLabel.IsVisible = false;
                indicatorPanel.AddChild(indicatorLabel);

                // Upgrades.
                for (var i = 0; i < list.Value.Count; i++)
                {
                    var panel = new BorderPanelFactory().Create("Upgrade " + list.Value[i].Name) as BorderPanel;
                    if (panel == null) return;
                    panel.MetricsMode = MetricsMode.Relative;
                    panel.BorderMaterialName = whiteMaterialName;
                    panel.SetBorderSize(0.0005f, 0.0005f, 0.0005f, 0.004f);
                    panel.Top = 0.02f;
                    panel.Left = masterUpgradePanel.Width * upgradeCounter / UpgradeGroup.NumberOfUpgrades + 0.002f;
                    panel.Width = masterUpgradePanel.Width / UpgradeGroup.NumberOfUpgrades - 0.004f;
                    panel.Height = masterUpgradePanel.Height - 0.04f;
                    masterUpgradePanel.AddChild(panel);
                    upgradePanelsByCost[list.Key].Add(panel);

                    var text = new TextAreaFactory().Create(list.Value[i].Name + " Text") as TextArea;
                    if (text == null) return;
                    text.MetricsMode = MetricsMode.Pixels;
                    text.FontName = "Candara";
                    text.Text = list.Value[i].Name;
                    text.TextAlign = HorizontalAlignment.Center;
                    text.HorizontalAlignment = HorizontalAlignment.Center;
                    text.VerticalAlignment = VerticalAlignment.Bottom;
                    text.CharHeight = 28;
                    text.Top = -28.0f;
                    text.Left = 0.0f;
                    text.Width = panel.Width;
                    text.Height = panel.Height;
                    text.Color = white;
                    panel.AddChild(text);

                    upgradeCounter++;
                }
            }

            SetAvailableUpgradePoints(playerShip.AvailableUpgradePoints);
            overlay.Show();
        }