Esempio n. 1
0
    // add the specified amount of the element to storage
    public void Add(int elementId, int volume)
    {
        var elementReference = Find(elementId);

        if (elementReference == null)
        {
            // we didn't find it in storage so create a new element reference
            elementReference = new PD_ElementReference(elementId, volume);

            // add the element to the storage
            m_elementList.Add(elementReference);
        }
        else
        {
            // we found it - update the volume of the element already in storage
            elementReference.AddVolume(volume);
        }

        // update the volume used
        m_volumeUsed += volume;
    }
Esempio n. 2
0
    // call this whenever we change state or do something that would result in something changing on the screen
    void UpdateScreen()
    {
        if (m_currentState == State.ErrorMessage)
        {
            // turn on the error message display
            m_errorPanel.SetActive(true);
            m_overlayPanel.SetActive(true);

            // turn off the other popup panels
            m_amountGameObject.SetActive(false);
            m_confirmAnalyzePanel.SetActive(false);
            m_analyzePanel.SetActive(false);
        }
        else
        {
            // turn off the error message display
            m_errorPanel.SetActive(false);
            m_overlayPanel.SetActive(false);

            if (m_currentState == State.MenuBar)
            {
                // all we need to do in this state is hide the trade screen and show the welcome screen
                m_welcomeGameObject.SetActive(true);
                m_tradeGameObject.SetActive(false);
                m_amountGameObject.SetActive(false);
                m_confirmAnalyzePanel.SetActive(false);
                m_analyzePanel.SetActive(false);
            }
            else
            {
                // hide the welcome screen and show the trade screen
                m_welcomeGameObject.SetActive(false);
                m_tradeGameObject.SetActive(true);

                // get access to the game data
                GameData gameData = DataController.m_instance.m_gameData;

                // get access to the player data
                PlayerData playerData = DataController.m_instance.m_playerData;

                // check if we are needing the buy or sell amount
                if ((m_currentState == State.BuyAmount) || (m_currentState == State.SellAmount))
                {
                    // display the amount input
                    m_amountGameObject.SetActive(true);
                    m_overlayPanel.SetActive(true);

                    // get the currently selected element id
                    int elementId = m_itemList[m_currentItemIndex].m_id;

                    // figure out the maximum amount the player can buy
                    int maximumAmount = 0;

                    if (m_currentState == State.BuyAmount)
                    {
                        maximumAmount = GetMaximumBuyAmountDueToCurrentBalance(elementId);

                        if (maximumAmount == 0)
                        {
                            // the player is broke and cannot buy anything - so immediately block the player
                            m_currentState = State.BuyItem;
                            SwitchToErrorMessageState("Insufficient funds");
                            return;
                        }

                        int remainingVolume = playerData.m_playerShip.GetRemainingVolme();

                        if (remainingVolume == 0)
                        {
                            // the cargo hold is full and the player cannot buy anything - so immediately block the player
                            m_currentState = State.BuyItem;
                            SwitchToErrorMessageState("Insufficient cargo space");
                            return;
                        }

                        // the maximum amount the player can buy is the lesser of the funds remaining or the cargo hold space remaining
                        if (remainingVolume < maximumAmount)
                        {
                            maximumAmount = remainingVolume;
                        }
                    }
                    else
                    {
                        // the maximum amount is however much the player has in the ships cargo hold
                        PD_ElementReference elementReference = playerData.m_playerShip.m_elementStorage.Find(elementId);

                        maximumAmount = elementReference.m_volume;
                    }

                    // update the amount label
                    m_amountLabelText.text = "Transfer how many cubic meters? (0.0 to " + (maximumAmount / 10) + "." + (maximumAmount % 10) + ")";
                }
                else
                {
                    // hide the amount input
                    m_amountGameObject.SetActive(false);
                }

                // check if we are confirming analysis of an artifact
                if (m_currentState == State.AnalyzeConfirm)
                {
                    // show the confirm analyze panel
                    m_confirmAnalyzePanel.SetActive(true);
                    m_overlayPanel.SetActive(true);
                }
                else
                {
                    // hide the confirm analyze panel
                    m_confirmAnalyzePanel.SetActive(false);
                }

                // check if we are showing the analysis of an artifact
                if (m_currentState == State.AnalyzeShow)
                {
                    // show the analyze panel
                    m_analyzePanel.SetActive(true);
                    m_overlayPanel.SetActive(true);
                }
                else
                {
                    // hide the analyze panel
                    m_analyzePanel.SetActive(false);
                }

                // reset the trade item list
                m_itemList = new List <Item>();

                // clear out the text
                m_itemListText.text      = "";
                m_volumeListText.text    = "";
                m_unitValueListText.text = "";

                m_rowCount = 0;

                if ((m_currentState != State.AnalyzeItem) && (m_currentState != State.AnalyzeConfirm) && (m_currentState != State.AnalyzeShow))
                {
                    // add elements heading
                    m_itemListText.text      += "<color=#A35514>Elements</color>" + Environment.NewLine;
                    m_volumeListText.text    += Environment.NewLine;
                    m_unitValueListText.text += Environment.NewLine;

                    m_rowCount++;

                    // get access to the ship cargo data for elements
                    PD_ElementStorage elementStorage = playerData.m_playerShip.m_elementStorage;

                    if ((m_currentState == State.BuyItem) || (m_currentState == State.BuyAmount))
                    {
                        // add all elements available to buy in starport
                        for (int elementId = 0; elementId < gameData.m_elementList.Length; elementId++)
                        {
                            GD_Element elementGameData = gameData.m_elementList[elementId];

                            if (elementGameData.m_availableInStarport)
                            {
                                m_itemListText.text += elementGameData.m_name + Environment.NewLine;

                                PD_ElementReference elementReference = elementStorage.Find(elementId);

                                if (elementReference == null)
                                {
                                    m_volumeListText.text += "0.0" + Environment.NewLine;
                                }
                                else
                                {
                                    m_volumeListText.text += (elementReference.m_volume / 10) + "." + (elementReference.m_volume % 10) + Environment.NewLine;
                                }

                                m_unitValueListText.text += elementGameData.m_starportPrice + Environment.NewLine;

                                m_itemList.Add(new Item(m_rowCount++, 0, elementId, 0));
                            }
                        }
                    }
                    else if ((m_currentState == State.SellItem) || (m_currentState == State.SellAmount))
                    {
                        // add all elements in the ship cargo hold
                        foreach (PD_ElementReference elementReference in elementStorage.m_elementList)
                        {
                            GD_Element elementGameData = elementReference.GetElementGameData();

                            m_itemListText.text      += elementGameData.m_name + Environment.NewLine;
                            m_volumeListText.text    += (elementReference.m_volume / 10) + "." + (elementReference.m_volume % 10) + Environment.NewLine;
                            m_unitValueListText.text += elementGameData.m_starportPrice + Environment.NewLine;

                            m_itemList.Add(new Item(m_rowCount++, 0, elementReference.m_elementId, 0));
                        }
                    }
                }

                if ((m_currentState == State.BuyItem) || (m_currentState == State.BuyAmount) || (m_currentState == State.AnalyzeItem) || (m_currentState == State.AnalyzeConfirm) || (m_currentState == State.AnalyzeShow))
                {
                    // add artifacts heading
                    m_itemListText.text      += "<color=#A35514>Artifacts</color>" + Environment.NewLine;
                    m_volumeListText.text    += Environment.NewLine;
                    m_unitValueListText.text += Environment.NewLine;

                    m_rowCount++;

                    // get access to the starport data for artifacts
                    PD_ArtifactStorage artifactStorage = playerData.m_starport.m_artifactStorage;

                    // add all artifacts available to buy in starport
                    foreach (PD_ArtifactReference artifactReference in artifactStorage.m_artifactList)
                    {
                        GD_Artifact artifactGameData = artifactReference.GetArtifactGameData();

                        m_itemListText.text      += artifactGameData.m_name + Environment.NewLine;
                        m_volumeListText.text    += (artifactGameData.m_volume / 10) + "." + (artifactGameData.m_volume % 10) + Environment.NewLine;
                        m_unitValueListText.text += artifactGameData.m_starportPrice + Environment.NewLine;

                        m_itemList.Add(new Item(m_rowCount++, 1, artifactReference.m_artifactId, 0));
                    }
                }

                if ((m_currentState == State.SellItem) || (m_currentState == State.SellAmount) || (m_currentState == State.AnalyzeItem) || (m_currentState == State.AnalyzeConfirm) || (m_currentState == State.AnalyzeShow))
                {
                    // add artifacts heading
                    m_itemListText.text      += "<color=#A35514>Artifacts</color>" + Environment.NewLine;
                    m_volumeListText.text    += Environment.NewLine;
                    m_unitValueListText.text += Environment.NewLine;

                    m_rowCount++;

                    // get access to the ship storage for artifacts
                    PD_ArtifactStorage artifactStorage = playerData.m_playerShip.m_artifactStorage;

                    // add all artifacts in the ship cargo hold
                    foreach (PD_ArtifactReference artifactReference in artifactStorage.m_artifactList)
                    {
                        GD_Artifact artifactGameData = artifactReference.GetArtifactGameData();

                        m_itemListText.text      += artifactGameData.m_name + Environment.NewLine;
                        m_volumeListText.text    += (artifactGameData.m_volume / 10) + "." + (artifactGameData.m_volume % 10) + Environment.NewLine;
                        m_unitValueListText.text += artifactGameData.m_actualValue + Environment.NewLine;

                        m_itemList.Add(new Item(m_rowCount++, 1, artifactReference.m_artifactId, 0));
                    }
                }

                // add end of list heading
                m_itemListText.text      += "<color=#A35514>End of List</color>" + Environment.NewLine;
                m_volumeListText.text    += Environment.NewLine;
                m_unitValueListText.text += Environment.NewLine;

                m_rowCount++;

                // make sure we have something in the list
                if (m_itemList.Count == 0)
                {
                    // there is nothing sell or analyze - so immediately block the player
                    SwitchToMenuBarState();
                    return;
                }

                // keep the current selection index within bounds
                if (m_currentItemIndex >= m_itemList.Count)
                {
                    m_currentItemIndex = m_itemList.Count - 1;
                }

                // force the text object to update (so we can get the correct height)
                m_itemListText.ForceMeshUpdate();

                // force the canvas to update
                Canvas.ForceUpdateCanvases();

                // show the up arrow only if the first item is not selected
                m_upArrowImage.gameObject.SetActive((m_currentItemIndex > 0));

                // show the down arrow only if the last part is not selected
                m_downArrowImage.gameObject.SetActive(m_currentItemIndex < (m_itemList.Count - 1));

                // get the row number of the currently selected item
                int row = m_itemList[m_currentItemIndex].m_row;

                // get the height of the item list viewport
                float viewportHeight = m_itemListMask.GetComponent <RectTransform>().rect.height;

                // calculate height of each text row
                float rowHeight = m_itemListText.renderedHeight / m_rowCount;

                // figure out the offset for the selection box
                float selectionBoxOffset;

                while (true)
                {
                    selectionBoxOffset = (row + m_currentRowOffset) * rowHeight;

                    if ((selectionBoxOffset + rowHeight * 2) >= viewportHeight)
                    {
                        m_currentRowOffset--;
                    }
                    else if (selectionBoxOffset < rowHeight)
                    {
                        m_currentRowOffset++;
                    }
                    else
                    {
                        break;
                    }
                }

                // put the item selection box in the right place
                RectTransform rectTransform = m_selectionXform.GetComponent <RectTransform>();
                rectTransform.offsetMin = m_baseSelectionOffsetMin + new Vector3(0.0f, -selectionBoxOffset, 0.0f);
                rectTransform.offsetMax = m_baseSelectionOffsetMax + new Vector3(0.0f, -selectionBoxOffset, 0.0f);

                // calculate the offset for the text
                float textOffset = m_currentRowOffset * rowHeight;

                // move the text in all 3 columns
                m_itemListText.rectTransform.offsetMax      = new Vector3(0.0f, -textOffset, 0.0f);
                m_volumeListText.rectTransform.offsetMax    = new Vector3(0.0f, -textOffset, 0.0f);
                m_unitValueListText.rectTransform.offsetMax = new Vector3(0.0f, -textOffset, 0.0f);

                // update bank balance amount
                m_currentBalanceText.text = "Your account balance is: " + playerData.m_bank.m_currentBalance + " M.U.";
            }
        }

        // enable or disable buttons now
        bool enableButtons = (m_currentState == State.MenuBar);

        m_buyButton.interactable     = enableButtons;
        m_sellButton.interactable    = enableButtons;
        m_analyzeButton.interactable = enableButtons;
        m_exitButton.interactable    = enableButtons;
    }
Esempio n. 3
0
    // unity update
    public override void Update()
    {
        // get to the player data
        PlayerData playerData = DataController.m_instance.m_playerData;

        // update the date
        m_values.text = playerData.m_general.m_currentStardateDHMY + "\n";

        // TODO: do actual damage text
        m_values.text += "None\n";

        // update the cargo usage
        // TODO: change the color depending on how full the storage is
        float cargoUsage = (float)playerData.m_playerShip.m_volumeUsed / (float)playerData.m_playerShip.m_volume * 100.0f;

        m_values.text += cargoUsage.ToString("N1") + "% Full\n";

        // get to the endurium in the ship storage
        PD_ElementReference elementReference = playerData.m_playerShip.m_elementStorage.Find(5);

        // update the amount of energy remaining
        if (elementReference == null)
        {
            m_values.text += "None\n";
        }
        else
        {
            float energyAmount = (float)elementReference.m_volume / 10.0f;

            // TODO: change the color depending on the amount remaining
            m_values.text += energyAmount.ToString("N1") + "M<sup>3</sup>\n";
        }

        // do we have shields?
        if (playerData.m_playerShip.m_shieldingClass == 0)
        {
            // no
            m_values.text += "None\n";

            // hide the shield outline
            m_shieldOutline.SetActive(false);
        }
        else
        {
            // are our shields up?
            if (playerData.m_playerShip.m_shieldsAreUp)
            {
                // yes
                m_values.text += "Up\n";

                // show the shield outline
                m_shieldOutline.SetActive(true);
            }
            else
            {
                // no
                m_values.text += "Down\n";

                // hide the shield outline
                m_shieldOutline.SetActive(false);
            }
        }

        // do we have weapons?
        if ((playerData.m_playerShip.m_missileLauncherClass == 0) && (playerData.m_playerShip.m_laserCannonClass == 0))
        {
            // no
            m_values.text += "None\n";
        }
        else
        {
            // are the weapons armed?
            if (playerData.m_playerShip.m_weaponsAreArmed)
            {
                //
                m_values.text += "Armed\n";
            }
            else
            {
                m_values.text += "Unarmed\n";
            }
        }

        // update the shield gauge
        m_shieldGauge.anchorMax = new Vector2(1.0f, Mathf.Lerp(0.0f, 1.0f, playerData.m_playerShip.m_shieldPoints / 2500.0f));

        // update the armor gauge
        m_armorGauge.anchorMax = new Vector2(1.0f, Mathf.Lerp(0.0f, 1.0f, playerData.m_playerShip.m_armorPoints / 1500.0f));
    }