示例#1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    public void UpdateSelectionWheelItemCounters()
    {
        // Get selection wheel reference
        SelectionWheel selectionWheel = null;

        if (GameManager.Instance._IsRadialMenu)
        {
            selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
        }
        else
        {
            selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
        }

        // Update each item counter in the selection wheel based off the current building queue
        List <AbstractionCounter> absCounter = new List <AbstractionCounter>();

        absCounter = GetAmountOfEachUnits();
        for (int i = 0; i < selectionWheel._WheelButtons.Count; i++)
        {
            SelectionWheelUnitRef wheelUnitRef = selectionWheel._WheelButtons[i].GetComponent <SelectionWheelUnitRef>();

            if (absCounter != null)
            {
                if (absCounter.Count > 0)
                {
                    // Button item has a valid abstraction reference
                    Abstraction absRef = wheelUnitRef.AbstractRef;
                    if (absRef != null)
                    {
                        for (int k = 0; k < absCounter.Count; k++)
                        {
                            // Button item abstraction type matches the building queue abstraction type
                            if (absRef.GetType() == absCounter[k]._Abstraction.GetType())
                            {
                                // Update button item counter
                                wheelUnitRef.SetQueueCounter(absCounter[k]._AbsCount);
                                break;
                            }

                            // Reached the end of the absCounter array
                            if (k == absCounter.Count - 1)
                            {
                                // Button item abstraction counter is 0
                                wheelUnitRef.SetQueueCounter(0);
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    wheelUnitRef.SetQueueCounter(0);
                }
            }
        }
    }
示例#2
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="selectable"></param>
    public void UpdateListWithBuildables(List <Abstraction> selectable, BuildingSlot buildingSlotInFocus)
    {
        _BuildingSlotInstigator = buildingSlotInFocus;

        // Reset button click events for all buttons
        foreach (var button in _WheelButtons)
        {
            // Icon button defaults
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => RefreshButtons(selectable));

            // Update slice button defaults
            Button slice = button.GetComponent <SelectionWheelUnitRef>().RadialSliceButton;
            slice.onClick.RemoveAllListeners();
            slice.onClick.AddListener(() => RefreshButtons(selectable));
        }

        // Clear list & update
        _BuildingList.Clear();
        int i = 0;

        foreach (var obj in selectable)
        {
            if (obj != null)
            {
                // If slot is an upgrade
                UpgradeTree upgrade = obj.GetComponent <UpgradeTree>();
                if (upgrade != null)
                {
                    // Dont update wheel with this button since its the upgrade is maxed out
                    if (upgrade.HasMaxUpgrade())
                    {
                        continue;
                    }
                }

                // Update list with new slots
                _BuildingList.Add(obj);

                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = obj.GetComponent <Abstraction>();

                // Update button click event
                _WheelButtons[i].onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                unitRef.RadialSliceButton.onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
            }

            // No selectable reference for this button item so give it an empty slot description
            else
            {
                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = null;
            }
            ++i;
        }
        RefreshButtons(selectable);
    }
示例#3
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="selectables"></param>
    public void UpdateListWithBuildings(List <Abstraction> selectables, BuildingSlot buildingSlotInFocus)
    {
        _BuildingSlotInstigator = buildingSlotInFocus;

        // Reset button click events for all buttons
        foreach (var button in _WheelButtons)
        {
            // Icon button defaults
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => HideSelectionWheel());

            // Update slice button defaults
            Button slice = button.GetComponent <SelectionWheelUnitRef>().RadialSliceButton;
            slice.onClick.RemoveAllListeners();
            slice.onClick.AddListener(() => HideSelectionWheel());
        }

        // Clear list & update
        _BuildingList.Clear();
        int i = 0;

        foreach (var obj in selectables)
        {
            if (obj != null)
            {
                // Update list with new slots
                Building building = obj.GetComponent <Building>();
                if (building != null)
                {
                    _BuildingList.Add(building);

                    // Update reference unit
                    SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                    unitRef.AbstractRef = building;

                    // Update button click event
                    _WheelButtons[i].onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                    unitRef.RadialSliceButton.onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                }
            }

            // No selectable reference for this button item so give it an empty slot description
            else
            {
                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = null;
            }
            ++i;
        }
        RefreshButtons(selectables);
    }
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when this gameObject is created.
    /// </summary>
    private void Start()
    {
        // Get component references
        _ObjectRefComponent = GetComponent <SelectionWheelUnitRef>();
        _ButtonComponent    = GetComponent <Button>();
        if (PCHotkeyObj != null)
        {
            _TextComponent = PCHotkeyObj.GetComponent <TMP_Text>();

            // Store colours set by the inspector
            _PCHotkeyColour = _TextComponent.color;
            _OriginalColour = _PCHotkeyColour;
        }
    }
示例#5
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="list"></param>
    public void RefreshButtons(List <Abstraction> list)
    {
        int i = 0;

        foreach (var button in _WheelButtons)
        {
            // If valid
            if (list.Count > i)
            {
                if (list[i] != null)
                {
                    // Update button text
                    Text txtComp = button.GetComponentInChildren <Text>();
                    txtComp.text = list[i].ObjectName;

                    // Update button interactibility state
                    SelectionWheelUnitRef unitRef = button.GetComponent <SelectionWheelUnitRef>();
                    if (unitRef.AbstractRef != null)
                    {
                        Player      player = GameManager.Instance.Players[0];
                        Abstraction item   = unitRef.AbstractRef;

                        bool unlock      = player.Level >= item.CostTechLevel;
                        bool purchasable = player.SuppliesCount >= item.CostSupplies &&
                                           player.PowerCount >= item.CostPower &&
                                           (player.MaxPopulation - player.PopulationCount) >= item.CostPopulation;

                        button.interactable = unlock && purchasable;
                    }

                    // If theres no unit reference in the button, just disable it by default
                    else
                    {
                        button.interactable = false;
                    }

                    // Update item visibility
                    ButtonVisibility(button.gameObject, true);
                }

                else
                {
                    ButtonVisibility(button.gameObject, false);
                }

                ++i;
            }
        }
    }
示例#6
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    /// <param name="abs"></param>
    public void UpdateLogoSliders(Abstraction abs)
    {
        for (int i = 0; i < _WheelButtons.Count; i++)
        {
            // Find matching slider
            SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
            if (unitRef.AbstractRef != null)
            {
                if (unitRef.AbstractRef.GetType() == abs.GetType())
                {
                    // Match found - update the slider attached to this button
                    unitRef.SetCurrentBuildProgress(abs.GetBuildPercentage());
                }
                else
                {
                    unitRef.SetCurrentBuildProgress(0f);
                }
            }
        }
    }
示例#7
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="selectables"></param>
    public void UpdateListWithBuildings(List <Abstraction> selectables, BuildingSlot buildingSlotInFocus)
    {
        // Reset button click events for all buttons
        foreach (var button in _WheelButtons)
        {
            // Clear
            button.onClick.RemoveAllListeners();

            // Add defaults
            button.onClick.AddListener(() => HideSelectionWheel());
        }

        // Clear list & update
        _BuildingList.Clear();
        int i = 0;

        foreach (var obj in selectables)
        {
            if (obj != null)
            {
                // Update list with new slots
                Building building = obj.GetComponent <Building>();
                if (building != null)
                {
                    _BuildingList.Add(building);

                    // Update reference unit
                    SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                    unitRef.AbstractRef = building;

                    // Update button click event
                    _WheelButtons[i].onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                }
            }
            ++i;
        }
        RefreshButtons(selectables);
    }
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when this gameObject is created.
    /// </summary>
    private void Start()
    {
        // Get component references
        _ObjectRefComponent = GetComponent <SelectionWheelUnitRef>();
        _ButtonComponent    = GetComponent <Button>();
    }
示例#9
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="list"></param>
    public void RefreshButtons(List <Abstraction> list)
    {
        // Update radial wheel building queue item counters
        if (_BuildingSlotInstigator != null)
        {
            Building building = _BuildingSlotInstigator.GetBuildingOnSlot();
            if (building != null)
            {
                if (building.GetBuildingQueueUI() != null)
                {
                    building.GetBuildingQueueUI().UpdateSelectionWheelItemCounters();
                }
            }
        }

        int i = 0;

        foreach (var button in _WheelButtons)
        {
            // If valid
            if (list.Count > i)
            {
                if (list[i] != null)
                {
                    // Update button
                    SelectionWheelUnitRef unitRef = button.GetComponent <SelectionWheelUnitRef>();
                    if (unitRef.AbstractRef != null)
                    {
                        Player      player = GameManager.Instance.Players[0];
                        Abstraction item   = unitRef.AbstractRef;

                        // Update button image
                        unitRef.UpdateUnitRefLogo();

                        // Check whether the button should be interactable or not
                        bool unlock      = player.Level >= item.CostTechLevel;
                        bool purchasable = player.SuppliesCount >= item.CostSupplies &&
                                           player.PowerCount >= item.CostPower &&
                                           (player.MaxPopulation - player.PopulationCount) >= item.CostPopulation;
                        button.interactable = unlock && purchasable;

                        // Update locked icon for the element
                        unitRef.LockedImage.enabled = !unlock;

                        // Update image colour based on state
                        if (!unlock)
                        {
                            button.image.color = ColorLocked;
                        }
                        else if (!purchasable)
                        {
                            button.image.color = ColorExpensive;
                        }
                        else
                        {
                            button.image.color = ColorAvailiable;
                        }
                    }

                    // If theres no unit reference in the button, just disable it by default
                    else
                    {
                        button.interactable = false;
                    }

                    // Update item visibility
                    ButtonVisibility(button.gameObject, true);
                }

                else
                {
                    ButtonVisibility(button.gameObject, false);
                }

                ++i;
            }
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    /// <param name="eventdata"></param>
    public void OnPointerEnter(PointerEventData eventdata)
    {
        if (SelectionWheel != null && _ObjectRefComponent != null && _ButtonComponent != null)
        {
            // Update the highlight text in the selection wheel
            if (_ObjectRefComponent.AbstractRef != null)
            {
                // Get selection wheel reference
                SelectionWheel selectionWheel = null;
                if (GameManager.Instance._IsRadialMenu)
                {
                    selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
                }
                else
                {
                    selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
                }
                selectionWheel.ShowItemPurchaseInfoPanel();

                // Detail window
                SelectionWheel.DetailedHighlightTitle.text            = _ObjectRefComponent.AbstractRef.ObjectName.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionShort.text = _ObjectRefComponent.AbstractRef.ObjectDescriptionShort.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionLong.text  = _ObjectRefComponent.AbstractRef.ObjectDescriptionLong;

                // Center panel
                SelectionWheel.CenterHighlightTitle.text = _ObjectRefComponent.AbstractRef.ObjectName;
                SelectionWheel.CenterTechLevelText.text  = _ObjectRefComponent.AbstractRef.CostTechLevel.ToString();
                SelectionWheel.CenterSupplyText.text     = _ObjectRefComponent.AbstractRef.CostSupplies.ToString();
                SelectionWheel.CenterPowerText.text      = _ObjectRefComponent.AbstractRef.CostPower.ToString();
                SelectionWheel.CenterPopulationText.text = _ObjectRefComponent.AbstractRef.CostPopulation.ToString();

                Player player = GameManager.Instance.Players[0];
                SelectionWheelUnitRef unitRef = GetComponent <SelectionWheelUnitRef>();
                Abstraction           item    = unitRef.AbstractRef;

                bool unlock      = player.Level >= item.CostTechLevel;
                bool purchasable = player.SuppliesCount >= item.CostSupplies &&
                                   player.PowerCount >= item.CostPower &&
                                   (player.MaxPopulation - player.PopulationCount) >= item.CostPopulation;

                // Update selection marker colours
                if (selectionWheel.SelectionMarkerImage)
                {
                    if (!unlock)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.red;
                    }
                    if (!purchasable)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.red;
                    }
                    else if (unlock)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.green;
                    }
                    else
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.grey;
                    }
                }

                // Update cost texts colour based on state
                /// Tech level
                if (player.Level >= item.CostTechLevel)
                {
                    selectionWheel.CenterTechLevelText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterTechLevelText.color = Color.red;
                }

                /// Population
                if ((player.MaxPopulation - player.PopulationCount) >= item.CostPopulation)
                {
                    selectionWheel.CenterPopulationText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterPopulationText.color = Color.red;
                }

                /// Supplies
                if (player.SuppliesCount >= item.CostSupplies)
                {
                    selectionWheel.CenterSupplyText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterSupplyText.color = Color.red;
                }

                /// Power
                if (player.PowerCount >= item.CostPower)
                {
                    selectionWheel.CenterPowerText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterPowerText.color = Color.red;
                }

                // Play hover button sound
                SoundManager.Instance.PlaySound("SFX/_SFX_Back_Alt", 1f, 1f, false);
            }
            else
            {
                // Get selection wheel reference
                SelectionWheel selectionWheel = null;
                if (GameManager.Instance._IsRadialMenu)
                {
                    selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
                }
                else
                {
                    selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
                }
                selectionWheel.ShowItemPurchaseInfoPanel();

                // Detail window
                SelectionWheel.DetailedHighlightTitle.text            = SelectionWheel.GetBuildingSlotInstigator().ObjectName.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionShort.text = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionShort.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionLong.text  = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionLong;

                // Center panel
                SelectionWheel.CenterHighlightTitle.text = SelectionWheel.GetBuildingSlotInstigator().ObjectName;
                SelectionWheel.CenterTechLevelText.text  = "1";
                SelectionWheel.CenterSupplyText.text     = "0";
                SelectionWheel.CenterPowerText.text      = "0";
                SelectionWheel.CenterPopulationText.text = "0";

                // Update selection marker colour
                selectionWheel.SelectionMarkerImage.color = Color.grey;
            }
        }
    }