Пример #1
0
    private void updateTransportPanel()
    {
        Debug.Log("Begin Updating Transport Panel");
        App    app                   = UnityEngine.Object.FindObjectOfType <App>();
        Nation player                = State.getNations()[app.GetHumanIndex()];
        int    transportFlow         = PlayerCalculator.calculateTransportFlow(player);
        int    totalNumberProv       = PlayerCalculator.getTotalNumberOfProvinces(player);
        int    realTransportCapacity = PlayerCalculator.calculateMaxTransportFlow(player);

        Debug.Log("Transport Flow: " + transportFlow);
        Debug.Log("Current Transport Capacity: " + realTransportCapacity);
        // player.industry.setTransportFlow(PlayerCalculator.calculateTransportFlow(player));
        float coalUsedForTransport = (transportFlow - totalNumberProv) * 0.2f;

        transportCapacity.text = transportFlow.ToString() + "/" + realTransportCapacity.ToString();
        coalCapacity.text      = player.getNumberResource(MyEnum.Resources.coal).ToString();
        int remainingFlow = realTransportCapacity - transportFlow;

        Debug.Log("Remaining Flow Capacity: " + remainingFlow);

        if (PlayerCalculator.canBuildTrain(player))
        {
            addTransportCapacityButton.interactable = true;
        }
        else
        {
            addTransportCapacityButton.interactable = false;
        }

        // Counter used for switching from first to second table in Production GUI
        int counter = 0;

        foreach (MyEnum.Resources res in Enum.GetValues(typeof(MyEnum.Resources)))
        {
            int producing   = PlayerCalculator.getResourceProducing(player, res);
            int currentFlow = player.getResTransportFlow(res);
            Debug.Log("Resource is: " + res + "---------------------------------------------");
            Debug.Log("Producing: " + producing);
            Debug.Log("Current Flow: " + currentFlow);
            //int systemFlow = player.industry.getTransportFlow();
            int capacity = Math.Min(producing - currentFlow, remainingFlow);
            Debug.Log("Remaining " + res + " capacity: " + capacity);
            int max = currentFlow + capacity;
            Debug.Log("Max: " + max);
            if (counter <= 5)
            {
                Debug.Log("check 2553");
                Text   resFlow   = resourceTableA.Rows[counter].Cells[1].GetComponentInChildren <Text>();
                Slider resSlider = resourceTableA.Rows[counter].Cells[2].GetComponentInChildren <Slider>();
                resFlow.text = currentFlow + "/" + producing;
                if (max == currentFlow && max < producing)
                {
                    Debug.Log("poop");
                    resFlow.color = new Color32(170, 12, 12, 255);
                }
                else
                {
                    resFlow.color = new Color32(0, 0, 0, 255);
                }
                resSlider.maxValue = max;
                resSlider.minValue = 0;
                resSlider.value    = currentFlow;
                Debug.Log("check 2569");
            }
            else
            {
                Debug.Log("check 2573");
                Text   resFlow   = resourceTableB.Rows[counter % 6].Cells[1].GetComponentInChildren <Text>();
                Slider resSlider = resourceTableB.Rows[counter % 6].Cells[2].GetComponentInChildren <Slider>();
                resFlow.text = currentFlow + "/" + producing;
                if (max == currentFlow && max < producing)
                {
                    Debug.Log("poop");
                    resFlow.color = new Color32(170, 12, 12, 255);
                }
                else
                {
                    resFlow.color = new Color32(0, 0, 0, 255);
                }
                resSlider.maxValue = max;
                resSlider.minValue = 0;
                resSlider.value    = currentFlow;
            }
            counter++;
            Debug.Log("Counter: " + counter);
        }
    }
Пример #2
0
    void CreateTable()
    {
        App app         = UnityEngine.Object.FindObjectOfType <App>();
        int playerIndex = app.GetHumanIndex();

        Debug.Log(playerIndex);
        Nation player = State.getNations()[playerIndex];
        Market market = State.market;

        tableLayout.ClearRows();
        int turn = State.turn;

        High.interactable   = false;
        Medium.interactable = false;
        Low.interactable    = false;

        plus.interactable  = false;
        minus.interactable = false;

        foreach (MyEnum.Resources resource in Enum.GetValues(typeof(MyEnum.Resources)))
        {
            if (resource == MyEnum.Resources.gold)
            {
                continue;
            }
            if (resource == MyEnum.Resources.rubber && !player.GetTechnologies().Contains("electricity"))
            {
                continue;
            }
            if (resource == MyEnum.Resources.oil && !player.GetTechnologies().Contains("oil_drilling"))
            {
                continue;
            }
            TableRow newRow = Instantiate <TableRow>(testRow);
            //  var fieldGameObject = new GameObject("Field", typeof(RectTransform));
            newRow.gameObject.SetActive(true);
            newRow.preferredHeight = 30;
            newRow.name            = resource.ToString();
            tableLayout.AddRow(newRow);
            scrollviewContent.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (tableLayout.transform as RectTransform).rect.height);
            Transform res    = newRow.Cells[0].transform.GetChild(0);
            Image     resImg = res.GetComponent <Image>();
            resImg.preserveAspect = true;
            resImg.sprite         = Resources.Load("Resource/" + resource.ToString(), typeof(Sprite)) as Sprite;
            Text resText = newRow.Cells[0].GetComponentInChildren <Text>();
            resText.text = resource.ToString();
            //newRow.Cells[0].GetComponentInChildren<Image>().sprite = Resources.Load("Resource/" + resource.ToString(), typeof(Sprite)) as Sprite;
            newRow.Cells[1].GetComponentInChildren <Text>().text = player.getNumberResource(resource).ToString();
            if (turn == 1)
            {
                newRow.Cells[2].GetComponentInChildren <Text>().text = "3";
            }
            else
            {
                newRow.Cells[2].GetComponentInChildren <Text>().text =
                    market.getPriceOfResource(resource).ToString();
            }
            Transform chg     = newRow.Cells[3].transform.GetChild(0);
            Image     chgImg  = chg.GetComponent <Image>();
            Text      chgText = newRow.Cells[3].GetComponentInChildren <Text>();
            chgText.text          = "flat";
            chgImg.preserveAspect = true;
            if (turn < 2)
            {
                chgImg.sprite = Resources.Load("Sprites/flat", typeof(Sprite)) as Sprite;
            }
            else
            {
                float currentTurnPrice = market.getPriceOfResource(resource);
                float lastTurnPrice    = market.getResourcePriceHistory(resource)[State.turn - 1];
                if (currentTurnPrice > lastTurnPrice)
                {
                    chgImg.sprite = Resources.Load("Sprites/greenUp", typeof(Sprite)) as Sprite;
                    chgText.text  = "up";
                }
                else if (currentTurnPrice < lastTurnPrice)
                {
                    chgImg.sprite = Resources.Load("Sprites/redDown", typeof(Sprite)) as Sprite;
                    chgText.text  = "down";
                }
            }
            float producing = PlayerCalculator.getResourceProducing(player, resource);
            newRow.Cells[4].GetComponentInChildren <Text>().text = producing.ToString("F2");
        }
        foreach (MyEnum.Goods good in Enum.GetValues(typeof(MyEnum.Goods)))
        {
            if (good == MyEnum.Goods.chemicals && !player.GetTechnologies().Contains("chemistry"))
            {
                continue;
            }
            if (good == MyEnum.Goods.gear && !player.GetTechnologies().Contains("electricity"))
            {
                continue;
            }
            if (good == MyEnum.Goods.telephone && !player.GetTechnologies().Contains("telephone"))
            {
                continue;
            }
            if (good == MyEnum.Goods.auto && !player.GetTechnologies().Contains("automobile"))
            {
                continue;
            }
            if (good == MyEnum.Goods.fighter && !player.GetTechnologies().Contains("flight"))
            {
                continue;
            }
            if (good == MyEnum.Goods.tank && !player.GetTechnologies().Contains("mobile_warfare"))
            {
                continue;
            }
            TableRow newRow = Instantiate <TableRow>(testRow);
            newRow.gameObject.SetActive(true);
            newRow.preferredHeight = 30;
            newRow.name            = good.ToString();
            tableLayout.AddRow(newRow);
            scrollviewContent.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
                                                        (tableLayout.transform as RectTransform).rect.height);
            List <TableCell> cells = newRow.Cells;

            Transform res    = newRow.Cells[0].transform.GetChild(0);
            Image     resImg = res.GetComponent <Image>();
            resImg.preserveAspect = true;
            resImg.sprite         = Resources.Load("FinishedGoods/" + good.ToString(), typeof(Sprite)) as Sprite;
            newRow.Cells[1].GetComponentInChildren <Text>().text = player.getNumberGood(good).ToString();
            if (turn == 1)
            {
                newRow.Cells[2].GetComponentInChildren <Text>().text = "5";
            }
            else
            {
                newRow.Cells[2].GetComponentInChildren <Text>().text =
                    market.getPriceOfGood(good).ToString();
            }
            Transform chg    = newRow.Cells[3].transform.GetChild(0);
            Image     chgImg = chg.GetComponent <Image>();
            chgImg.preserveAspect = true;
            if (turn < 2)
            {
                chgImg.sprite = Resources.Load("Sprites/flat", typeof(Sprite)) as Sprite;
            }
            else
            {
                float currentTurnPrice = market.getPriceOfGood(good);
                float lastTurnPrice    = market.getGoodPriceHistory(good)[turn - 1];
                if (currentTurnPrice > lastTurnPrice)
                {
                    chgImg.sprite = Resources.Load("Sprites/greenUp", typeof(Sprite)) as Sprite;
                }
                else if (currentTurnPrice < lastTurnPrice)
                {
                    chgImg.sprite = Resources.Load("Sprites/redDown", typeof(Sprite)) as Sprite;
                }
            }
            float producing = player.industry.getGoodProducing(good);
            newRow.Cells[4].GetComponentInChildren <Text>().text = producing.ToString();
        }
        itemImage.sprite = Resources.Load("Resources/" + currentItem, typeof(Sprite)) as Sprite;

        if (State.turn > 1)
        {
            offeredLastTurn.text = "Offered Last Turn: " +
                                   market.getNumberOfResourcesOffered(MyEnum.Resources.wheat).ToString();
            soldLastTurn.text = "Sold Last Turn: " + market.getNumberResourcesSold(MyEnum.Resources.wheat).ToString();
            priceHistory      = market.getResourcePriceHistory(MyEnum.Resources.wheat);
        }
        else
        {
            offeredLastTurn.text = "Offered Last Turn: 0";
            soldLastTurn.text    = "Sold Last Turn: 0";
        }
    }