Beispiel #1
0
        private static void ShowAddShipPanel()
        {
            if (GetCurrentSquadCost() < 89)
            {
                GameObject prefab             = (GameObject)Resources.Load("Prefabs/SquadBuilder/ShipWithUpgradesPanel", typeof(GameObject));
                GameObject addShipButtonPanel = MonoBehaviour.Instantiate(prefab, GameObject.Find("UI/Panels/SquadBuilderPanel/Panel/Centered/SquadListPanel").transform);
                AddShipButtonPanel = new ShipWithUpgradesPanel(null, addShipButtonPanel);

                prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/AddShipButton", typeof(GameObject));
                GameObject addShipButton = MonoBehaviour.Instantiate(prefab, addShipButtonPanel.transform);

                Sprite factionSprite = GameObject.Find("UI/Panels").transform.Find("SelectFactionPanel").Find("Panel").Find("FactionPanels").Find("Button" + CurrentSquadList.SquadFaction.ToString()).GetComponent <Image>().sprite;
                addShipButton.GetComponent <Image>().sprite = factionSprite;

                EventTrigger       trigger = addShipButton.AddComponent <EventTrigger>();
                EventTrigger.Entry entry   = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.PointerClick;
                entry.callback.AddListener(delegate { OpenSelectShip(); });
                trigger.triggers.Add(entry);
            }
            else
            {
                AddShipButtonPanel = null;
            }
        }
Beispiel #2
0
        private static void AddShipWithUpgradesPanel(SquadBuilderShip ship)
        {
            GameObject            prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/ShipWithUpgradesPanel", typeof(GameObject));
            GameObject            shipWithUpgradesPanelGO = MonoBehaviour.Instantiate(prefab, GameObject.Find("UI/Panels/SquadBuilderPanel/Panel/Centered/SquadListPanel").transform);
            ShipWithUpgradesPanel shipWithUpgradesPanel   = new ShipWithUpgradesPanel(ship, shipWithUpgradesPanelGO);

            ShipWithUpgradesPanels.Add(shipWithUpgradesPanel);
            ship.Panel = shipWithUpgradesPanel;

            Transform     contentTransform       = ship.Panel.Panel.transform;
            RectTransform contentRect            = contentTransform.GetComponent <RectTransform>();
            int           installedUpgradesCount = ship.Instance.UpgradeBar.GetUpgradesAll().Count;

            contentRect.sizeDelta = new Vector2(PILOT_CARD_WIDTH + (UPGRADE_CARD_WIDTH + DISTANCE_SMALL) * installedUpgradesCount, contentRect.sizeDelta.y);

            prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/PilotPanel", typeof(GameObject));
            GameObject pilotPanel = MonoBehaviour.Instantiate(prefab, shipWithUpgradesPanelGO.transform);

            pilotPanel.transform.localPosition = Vector3.zero;

            PilotPanelSquadBuilder script = pilotPanel.GetComponent <PilotPanelSquadBuilder>();

            script.Initialize(ship.Instance, OpenShipInfo);

            ShowUpgradesOfPilot(ship);
        }
Beispiel #3
0
        private static Dictionary <ShipWithUpgradesPanel, int> GetArrangeShipsWithUpgradesIntoRowNumbers()
        {
            Dictionary <ShipWithUpgradesPanel, int> result = new Dictionary <ShipWithUpgradesPanel, int>();

            bool isAddShipPanelVisible = AddShipButtonPanel != null;

            ShipWithUpgradesPanel maxSizePanel = ShipWithUpgradesPanels.Find(n => n.Size.x == ShipWithUpgradesPanels.Max(m => m.Size.x));

            result.Add(maxSizePanel, 1);

            float maxWidth = ShipWithUpgradesPanels.Sum(n => n.Size.x) - maxSizePanel.Size.x;

            if (isAddShipPanelVisible)
            {
                maxWidth += AddShipButtonPanel.Size.x;
            }
            float difference = Mathf.Abs(maxWidth - maxSizePanel.Size.x);

            bool finished = false;

            while (!finished)
            {
                List <ShipWithUpgradesPanel> shipPanelsNotProcessed = ShipWithUpgradesPanels.Where(n => !result.ContainsKey(n)).ToList();
                ShipWithUpgradesPanel        minSizePanel           = shipPanelsNotProcessed.Find(n => n.Size.x == shipPanelsNotProcessed.Min(m => m.Size.x));

                if (minSizePanel == null)
                {
                    return(result);
                }

                float firstRowWidth  = result.Where(n => n.Value == 1).Sum(n => n.Key.Size.x) + minSizePanel.Size.x;
                float secondRowWidth = maxWidth - result.Where(n => n.Value == 1).Sum(n => n.Key.Size.x);
                float newDifference  = Mathf.Abs(firstRowWidth - secondRowWidth);

                if (newDifference > difference)
                {
                    foreach (ShipWithUpgradesPanel panel in shipPanelsNotProcessed)
                    {
                        if (!result.ContainsKey(panel))
                        {
                            result.Add(panel, 2);
                        }
                    }
                    finished = true;
                }
                else
                {
                    result.Add(minSizePanel, 1);
                    difference -= minSizePanel.Size.x;
                    maxWidth   -= minSizePanel.Size.x;
                }
            }

            return(result);
        }