Esempio n. 1
0
    public void BuyUpgrade(UpgradeNode upgradeClicked)
    {
        //Comprobar si tengo exp suficiente
        if (currentCharacterUpgrading.unitPowerLevel <= GameManager.Instance.currentExp)
        {
            //Gastar Exp
            GameManager.Instance.currentExp -= currentCharacterUpgrading.unitPowerLevel;

            //Avisar al nodo de mejora de que ha sido comprado  y Desbloquear los siguientes nodos
            upgradeClicked.UpgradeBought();

            //Aumentar power level del personaje
            //Añadir id a la lista del personaje
            currentCharacterUpgrading.UpgradeAcquired(upgradeClicked.upgradeCost, upgradeClicked.idUpgrade);

            UITM.UpdateProgresionBook(currentCharacterUpgrading);

            //Comprobar logros
            GameManager.Instance.CheckUpgradeAchievements();
        }

        else
        {
            //¿Dar feedback de que no hay suficiente exp?
            Debug.Log("No hay suficiente xp");
        }
    }
 public override void OnOpen()
 {
     base.OnOpen();
     selectedNode = null;
     resizeCheck  = false;
     mainTex      = null;
 }
Esempio n. 3
0
    public void ConfirmateUpgrade(bool _showConfirmation, UpgradeNode _upgradeClicked)
    {
        confirmateUpgrade.SetActive(_showConfirmation);

        //Aviso rama se bloqueará
        if (currentSkillTreeObj.GetComponent <SkillTree>().firstUpgradesInTree.Contains(_upgradeClicked))
        {
            warningBlockUpgrade.SetActive(true);
        }

        else
        {
            warningBlockUpgrade.SetActive(false);
        }

        lastUpgradeClicked = _upgradeClicked;
    }
        private void DrawCostItems(UpgradeNode node = null)
        {
            int   i      = 0;
            float offset = 0;

            if (node is null)
            {
                offset = 25f;
                foreach (IngredientFilter ingredient in SelPawnUpgrade.CompUpgradeTree.NodeUnlocking.ingredients.Where(i => i.IsFixedIngredient))
                {
                    string  itemCount = $"{SelPawnUpgrade.CompUpgradeTree.NodeUnlocking.itemContainer.TotalStackCountOfDef(ingredient.FixedIngredient)}/{ingredient.count}";
                    Vector2 textSize  = Text.CalcSize(itemCount);

                    Rect itemCostRect = new Rect((LeftWindowEdge / 2) - (textSize.x / 2), ((BottomWindowEdge - TopViewPadding) / 2) + offset, 20f, 20f);
                    GUI.DrawTexture(itemCostRect, ingredient.FixedIngredient.uiIcon);

                    Rect itemLabelRect = new Rect(itemCostRect.x + 25f, itemCostRect.y, textSize.x, 20f);
                    Widgets.Label(itemLabelRect, itemCount);
                    i++;
                    offset += textSize.y + 5;
                }
            }
            else
            {
                Rect   timeRect       = new Rect(5f, screenHeight - SideDisplayedOffset * 2, LeftWindowEdge, 20f);
                string timeForUpgrade = VehicleMod.settings.main.useInGameTime ? RimWorldTime.TicksToGameTime(node.UpgradeTimeParsed) : RimWorldTime.TicksToRealTime(node.UpgradeTimeParsed);
                Widgets.Label(timeRect, timeForUpgrade);
                foreach (IngredientFilter ingredient in node.ingredients)
                {
                    Rect itemCostRect = new Rect(5f + offset, screenHeight - SideDisplayedOffset - 23f, 20f, 20f);
                    GUI.DrawTexture(itemCostRect, ingredient.FixedIngredient.uiIcon);
                    string  itemCount     = "x" + ingredient.count;
                    Vector2 textSize      = Text.CalcSize(itemCount);
                    Rect    itemLabelRect = new Rect(25f + offset, itemCostRect.y, textSize.x, 20f);
                    Widgets.Label(itemLabelRect, itemCount);
                    i++;
                    offset += textSize.x + 30f;
                }
            }
        }
Esempio n. 5
0
        protected override void FillTab()
        {
            Rect rect  = new Rect(0f, TopPadding, size.x, size.y - TopPadding);
            Rect rect2 = rect.ContractedBy(10f);

            GUI.BeginGroup(rect2);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            float num = 0f;

            UpgradeNode additionalStatNode    = null;
            UpgradeNode highlightedPreMetNode = null;

            Rect upgradeButtonRect = new Rect(screenWidth - BottomDisplayedOffset - 80f, BottomWindowEdge - 30f, 75, 25f);
            Rect displayRect       = new Rect(Comp.Props.displayUICoord.x, Comp.Props.displayUICoord.y, Comp.Props.displayUISize.x, Comp.Props.displayUISize.y);

            if (RimShipMod.mod.settings.debugDrawNodeGrid)
            {
                DrawBackgroundGrid();
            }
            if (Prefs.DevMode)
            {
                var font = Text.Font;
                Text.Font = GameFont.Tiny;
                Rect screenInfo = new Rect(LeftWindowEdge + 5f, GridSpacing.y + 3f, screenWidth - LeftWindowEdge - 10f, 50f);
                Widgets.Label(screenInfo, $"Screen Size: ({this.size.x},{this.size.y}) \nBottomEdge: {BottomWindowEdge}px \nLeftWindowEdge: {LeftWindowEdge}px");
                Text.Font = font;
            }

            if (selectedNode != null)
            {
                float imageWidth   = TotalIconSizeScalar / selectedNode.UpgradeImage.width;
                float imageHeight  = TotalIconSizeScalar / selectedNode.UpgradeImage.height;
                Rect  selectedRect = new Rect(GridOrigin.x + (GridSpacing.x * selectedNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * selectedNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                selectedRect.ContractedBy(3f);
                GUI.DrawTexture(selectedRect, BaseContent.WhiteTex);
            }

            if (Widgets.ButtonText(upgradeButtonRect, "Upgrade".Translate()) && selectedNode != null && !selectedNode.upgradeActive)
            {
                if (Comp.Disabled(selectedNode))
                {
                    Messages.Message("DisabledFromOtherNode".Translate(), MessageTypeDefOf.RejectInput, false);
                }
                else if (Comp.PrerequisitesMet(selectedNode))
                {
                    SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(SelPawnUpgrade.Map);
                    SoundDefOf.Building_Complete.PlayOneShot(SelPawnUpgrade);

                    Comp.StartUnlock(selectedNode);
                    selectedNode.upgradePurchased = true;
                    selectedNode = null;
                }
                else
                {
                    Messages.Message("MissingPrerequisiteUpgrade".Translate(), MessageTypeDefOf.RejectInput, false);
                }
            }

            foreach (UpgradeNode upgradeNode in Comp.upgradeList)
            {
                if (upgradeNode.prerequisiteNodes?.Any() ?? false)
                {
                    foreach (UpgradeNode prerequisite in Comp.upgradeList.FindAll(x => upgradeNode.prerequisiteNodes.Contains(x.upgradeID)))
                    {
                        Vector2 start = new Vector2(GridOrigin.x + (GridSpacing.x * prerequisite.GridCoordinate.x), GridOrigin.y + (GridSpacing.y * prerequisite.GridCoordinate.z) + (TopPadding * 2));
                        Vector2 end   = new Vector2(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) + (TopPadding * 2));
                        Color   color = Color.grey;
                        if (upgradeNode.upgradeActive)
                        {
                            color = Color.white;
                        }
                        else if (!string.IsNullOrEmpty(upgradeNode.disableIfUpgradeNodeEnabled))
                        {
                            try
                            {
                                UpgradeNode preUpgrade     = Comp.upgradeList.First(x => x.upgradeID == upgradeNode.disableIfUpgradeNodeEnabled);
                                float       imageWidth     = TotalIconSizeScalar / preUpgrade.UpgradeImage.width;
                                float       imageHeight    = TotalIconSizeScalar / preUpgrade.UpgradeImage.height;
                                Rect        preUpgradeRect = new Rect(GridOrigin.x + (GridSpacing.x * preUpgrade.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * preUpgrade.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                                if (preUpgrade.upgradePurchased)
                                {
                                    color = Color.black;
                                }
                                else if (Mouse.IsOver(preUpgradeRect))
                                {
                                    color = Color.red;
                                }
                            }
                            catch
                            {
                                Log.Error($"Unable to find UpgradeNode {upgradeNode.disableIfUpgradeNodeEnabled} on iteration. Are you referencing the proper upgradeID?");
                            }
                        }
                        Widgets.DrawLine(start, end, color, 2f);
                    }
                }
            }
            bool preDrawingDescriptions = false;

            for (int i = 0; i < Comp.upgradeList.Count; i++)
            {
                UpgradeNode upgradeNode = Comp.upgradeList[i];
                float       imageWidth  = TotalIconSizeScalar / upgradeNode.UpgradeImage.width;
                float       imageHeight = TotalIconSizeScalar / upgradeNode.UpgradeImage.height;

                Rect upgradeRect = new Rect(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                Widgets.DrawTextureFitted(upgradeRect, upgradeNode.UpgradeImage, 1);

                if (!upgradeNode.prerequisiteNodes.Any())
                {
                    if (!string.IsNullOrEmpty(upgradeNode.rootNodeLabel))
                    {
                        Rect nodeLabelRect = new Rect(upgradeRect.x, upgradeRect.y - 20f, 10f * upgradeNode.rootNodeLabel.Count(), 25f);
                        Widgets.Label(nodeLabelRect, upgradeNode.rootNodeLabel);
                    }
                }
                Rect buttonRect = new Rect(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);

                Rect     infoLabelRect = new Rect(5f, BottomWindowEdge, LeftWindowEdge, 150f);
                GUIStyle infoLabelFont = new GUIStyle(Text.CurFontStyle);
                infoLabelFont.fontStyle = FontStyle.Bold;

                if (Mouse.IsOver(upgradeRect))
                {
                    preDrawingDescriptions = true;

                    if (!upgradeNode.upgradePurchased)
                    {
                        additionalStatNode    = upgradeNode;
                        highlightedPreMetNode = upgradeNode;
                    }
                    HelperMethods.LabelStyled(infoLabelRect, upgradeNode.label, infoLabelFont);

                    Widgets.Label(new Rect(infoLabelRect.x, infoLabelRect.y + 20f, infoLabelRect.width, 140f), upgradeNode.informationHighlighted);
                }

                if ((Mouse.IsOver(upgradeRect) || upgradeNode.upgradePurchased) && Comp.PrerequisitesMet(upgradeNode))
                {
                    GUI.DrawTexture(upgradeRect, TexUI.HighlightTex);
                }

                if (!upgradeNode.upgradePurchased && Comp.PrerequisitesMet(upgradeNode))
                {
                    if (Widgets.ButtonInvisible(buttonRect, true))
                    {
                        if (selectedNode != upgradeNode)
                        {
                            selectedNode = upgradeNode;
                            SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                        }
                        else
                        {
                            selectedNode = null;
                            SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                        }
                    }
                }
            }
            Rect     selectedLabelRect = new Rect(5f, BottomWindowEdge, LeftWindowEdge, 150f);
            GUIStyle selectedLabelFont = new GUIStyle(Text.CurFontStyle);

            selectedLabelFont.fontStyle = FontStyle.Bold;

            if (selectedNode != null && !preDrawingDescriptions)
            {
                if (!selectedNode.upgradePurchased)
                {
                    additionalStatNode = selectedNode;
                }

                HelperMethods.LabelStyled(selectedLabelRect, selectedNode.label, selectedLabelFont);

                Widgets.Label(new Rect(selectedLabelRect.x, selectedLabelRect.y + 20f, selectedLabelRect.width, 140f), selectedNode.informationHighlighted);
            }

            Rect labelRect = new Rect(0f, 0f, rect2.width - 16f, 20f);

            num += labelRect.height;
            if (!RimShipMod.mod.settings.debugDrawNodeGrid)
            {
                Widgets.Label(labelRect, SelPawnUpgrade.Label);
            }

            Color lineColor = GUI.color;

            GUI.color = new Color(0.3f, 0.3f, 0.3f, 1f);

            Widgets.DrawLineHorizontal(0, num, screenWidth);
            Widgets.DrawLineHorizontal(0, BottomWindowEdge, screenWidth);
            Widgets.DrawLineHorizontal(0, screenHeight - SideDisplayedOffset - 1f, screenWidth);

            Widgets.DrawLineVertical(0, num, screenHeight);
            Widgets.DrawLineVertical(screenWidth - BottomDisplayedOffset - 1f, num, screenHeight);

            if (RimShipMod.mod.settings.drawUpgradeInformationScreen)
            {
                Widgets.DrawLineVertical(LeftWindowEdge, num, screenHeight);
            }
            GUI.color = lineColor;

            if (RimShipMod.mod.settings.drawUpgradeInformationScreen)
            {
                if (SelPawnUpgrade != null)
                {
                    try
                    {
                        Texture2D tex = ContentFinder <Texture2D> .Get(SelPawnUpgrade.kindDef.lifeStages.FirstOrDefault().bodyGraphicData.texPath + "_north", true);

                        GUI.DrawTexture(displayRect, tex);

                        if (RimShipMod.mod.settings.debugDrawCannonGrid)
                        {
                            Widgets.DrawLineHorizontal(displayRect.x, displayRect.y, displayRect.width);
                            Widgets.DrawLineHorizontal(displayRect.x, displayRect.y + displayRect.height, displayRect.width);
                            Widgets.DrawLineVertical(displayRect.x, displayRect.y, displayRect.height);
                            Widgets.DrawLineVertical(displayRect.x + displayRect.width, displayRect.y, displayRect.height);
                            if (screenWidth - (displayRect.x + displayRect.width) < 0)
                            {
                                Resize      = new Vector2(screenWidth + displayRect.x, screenHeight);
                                resizeCheck = true;
                            }
                        }
                        if (RimShipMod.mod.settings.debugDrawNodeGrid)
                        {
                            Widgets.DrawLineHorizontal(LeftWindowEdge, 70f, screenWidth - LeftWindowEdge);
                            int lineCount = (int)(screenWidth - LeftWindowEdge) / 10;

                            for (int i = 1; i <= lineCount; i++)
                            {
                                Widgets.DrawLineVertical(LeftWindowEdge + 10 * i, 70f, (i % 5 == 0) ? 10 : 5);
                            }
                            var color = GUI.color;
                            GUI.color = Color.red;
                            Widgets.DrawLineVertical(LeftWindowEdge + (((screenWidth - BottomDisplayedOffset) - LeftWindowEdge) / 2), 70f, 12f);
                            GUI.color = color;
                        }

                        foreach (CannonHandler cannon in Comp.upgradeList.Where(x => x.upgradeActive && (x.cannonsUnlocked?.Any() ?? false)).SelectMany(y => y.cannonsUnlocked))
                        {
                            PawnKindLifeStage biggestStage = SelPawnUpgrade.kindDef.lifeStages.MaxBy(x => x.bodyGraphicData?.drawSize ?? Vector2.zero);
                            float             baseWidth    = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonDrawSize.x;
                            float             baseHeight   = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonDrawSize.y;

                            float xBase = displayRect.x + (displayRect.width / 2) - (baseWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonRenderLocation.x);
                            float yBase = displayRect.y + (displayRect.height / 2) - (baseHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonRenderLocation.y);

                            Rect baseCannonDrawnRect = new Rect(xBase, yBase, baseWidth, baseHeight);
                            GUI.DrawTexture(baseCannonDrawnRect, cannon.CannonBaseTexture);

                            float cannonWidth  = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonTurretDrawSize.x;
                            float cannonHeight = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonTurretDrawSize.y;

                            float xCannon = displayRect.x + (displayRect.width / 2) - (cannonWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonRenderLocation.x);
                            float yCannon = displayRect.y + (displayRect.height / 2) - (cannonHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonRenderLocation.y);

                            Rect cannonDrawnRect = new Rect(xCannon, yCannon, cannonWidth, cannonHeight);
                            GUI.DrawTexture(cannonDrawnRect, cannon.CannonTexture);

                            if (RimShipMod.mod.settings.debugDrawCannonGrid)
                            {
                                Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.width);
                                Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y + cannonDrawnRect.height, cannonDrawnRect.width);
                                Widgets.DrawLineVertical(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.height);
                                Widgets.DrawLineVertical(cannonDrawnRect.x + cannonDrawnRect.width, cannonDrawnRect.y, cannonDrawnRect.height);
                            }
                        }
                        if (selectedNode?.cannonsUnlocked?.Any() ?? false)
                        {
                            foreach (CannonHandler cannon in selectedNode.cannonsUnlocked)
                            {
                                PawnKindLifeStage biggestStage = SelPawnUpgrade.kindDef.lifeStages.MaxBy(x => x.bodyGraphicData?.drawSize ?? Vector2.zero);
                                float             baseWidth    = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonDrawSize.x;
                                float             baseHeight   = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonDrawSize.y;
                                float             test         = ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonRenderLocation.y);

                                float xBase = displayRect.x + (displayRect.width / 2) - (baseWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonRenderLocation.x);
                                float yBase = displayRect.y + (displayRect.height / 2) - (baseHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonRenderLocation.y);

                                Rect baseCannonDrawnRect = new Rect(xBase, yBase, baseWidth, baseHeight);
                                GUI.DrawTexture(baseCannonDrawnRect, cannon.CannonBaseTexture);

                                float cannonWidth  = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonTurretDrawSize.x;
                                float cannonHeight = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonTurretDrawSize.y;

                                float xCannon = displayRect.x + (displayRect.width / 2) - (cannonWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonRenderLocation.x);
                                float yCannon = displayRect.y + (displayRect.height / 2) - (cannonHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonRenderLocation.y);

                                Rect cannonDrawnRect = new Rect(xCannon, yCannon, cannonWidth, cannonHeight);
                                GUI.DrawTexture(cannonDrawnRect, cannon.CannonTexture);

                                if (RimShipMod.mod.settings.debugDrawCannonGrid)
                                {
                                    Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.width);
                                    Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y + cannonDrawnRect.height, cannonDrawnRect.width);
                                    Widgets.DrawLineVertical(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.height);
                                    Widgets.DrawLineVertical(cannonDrawnRect.x + cannonDrawnRect.width, cannonDrawnRect.y, cannonDrawnRect.height);
                                }
                            }
                        }
                        else if ((highlightedPreMetNode?.cannonsUnlocked?.Any() ?? false) && !highlightedPreMetNode.upgradeActive)
                        {
                            foreach (CannonHandler cannon in highlightedPreMetNode.cannonsUnlocked)
                            {
                                PawnKindLifeStage biggestStage = SelPawnUpgrade.kindDef.lifeStages.MaxBy(x => x.bodyGraphicData?.drawSize ?? Vector2.zero);
                                float             baseWidth    = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonDrawSize.x;
                                float             baseHeight   = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonDrawSize.y;

                                float xBase = displayRect.x + (displayRect.width / 2) - (baseWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.baseCannonRenderLocation.x);
                                float yBase = displayRect.y + (displayRect.height / 2) - (baseHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.baseCannonRenderLocation.y);

                                Rect baseCannonDrawnRect = new Rect(xBase, yBase, baseWidth, baseHeight);
                                GUI.DrawTexture(baseCannonDrawnRect, cannon.CannonBaseTexture);

                                float cannonWidth  = (Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonTurretDrawSize.x;
                                float cannonHeight = (Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonTurretDrawSize.y;

                                float xCannon = displayRect.x + (displayRect.width / 2) - (cannonWidth / 2) - ((Comp.Props.displayUISize.x / biggestStage.bodyGraphicData.drawSize.x) * cannon.cannonRenderLocation.x);
                                float yCannon = displayRect.y + (displayRect.height / 2) - (cannonHeight / 2) - ((Comp.Props.displayUISize.y / biggestStage.bodyGraphicData.drawSize.y) * cannon.cannonRenderLocation.y);

                                Rect cannonDrawnRect = new Rect(xCannon, yCannon, cannonWidth, cannonHeight);
                                GUI.DrawTexture(cannonDrawnRect, cannon.CannonTexture);

                                if (RimShipMod.mod.settings.debugDrawCannonGrid)
                                {
                                    Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.width);
                                    Widgets.DrawLineHorizontal(cannonDrawnRect.x, cannonDrawnRect.y + cannonDrawnRect.height, cannonDrawnRect.width);
                                    Widgets.DrawLineVertical(cannonDrawnRect.x, cannonDrawnRect.y, cannonDrawnRect.height);
                                    Widgets.DrawLineVertical(cannonDrawnRect.x + cannonDrawnRect.width, cannonDrawnRect.y, cannonDrawnRect.height);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorOnce($"Unable to display {SelPawnUpgrade.def.LabelCap} Texture on Upgrade Screen. Error: {ex.Message} \n StackTrace: {ex.StackTrace}", SelPawnUpgrade.thingIDNumber, true);
                    }
                }
            }

            DrawStats(additionalStatNode);

            GUI.EndGroup();

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Esempio n. 6
0
        private void DrawStats(UpgradeNode nodeRect)
        {
            float barWidth = screenWidth - LeftWindowEdge - EdgePadding * 2 - BottomDisplayedOffset - 1f; //219

            float armorAdded   = 0f;
            float speedAdded   = 0f;
            float cargoAdded   = 0f;
            float fuelEffAdded = 0f;
            float fuelCapAdded = 0f;

            if (nodeRect != null)
            {
                foreach (KeyValuePair <StatUpgrade, float> stat in nodeRect.values)
                {
                    switch (stat.Key)
                    {
                    case StatUpgrade.Armor:
                        armorAdded = stat.Value;
                        break;

                    case StatUpgrade.Speed:
                        speedAdded = stat.Value;
                        break;

                    case StatUpgrade.CargoCapacity:
                        cargoAdded = stat.Value;
                        break;

                    case StatUpgrade.FuelConsumptionRate:
                        fuelEffAdded = stat.Value;
                        break;

                    case StatUpgrade.FuelCapacity:
                        fuelCapAdded = stat.Value;
                        break;
                    }
                }
            }

            Rect armorStatRect = new Rect(LeftWindowEdge + EdgePadding, BottomWindowEdge + EdgePadding, barWidth, 20f);

            HelperMethods.FillableBarLabeled(armorStatRect, BoatComp.ArmorPoints / MaxArmorValueDisplayed, "BoatMaxArmor".Translate(), StatUpgrade.Armor, HelperMethods.FillableBarInnerTex, HelperMethods.FillableBarBackgroundTex, BoatComp.ArmorPoints, armorAdded, armorAdded / MaxArmorValueDisplayed);

            Rect speedStatRect = new Rect(LeftWindowEdge + EdgePadding, armorStatRect.y + 25f, barWidth, 20f);

            HelperMethods.FillableBarLabeled(speedStatRect, BoatComp.ActualMoveSpeed / MaxSpeedValueDisplayed, "BoatMaxSpeed".Translate(), StatUpgrade.Speed, HelperMethods.FillableBarInnerTex, HelperMethods.FillableBarBackgroundTex, BoatComp.ActualMoveSpeed, speedAdded, speedAdded / MaxSpeedValueDisplayed);

            Rect cargoCapacityStatRect = new Rect(LeftWindowEdge + EdgePadding, speedStatRect.y + 25f, barWidth, 20f);

            HelperMethods.FillableBarLabeled(cargoCapacityStatRect, BoatComp.CargoCapacity / MaxCargoValueDisplayed, "BoatCargoCapacity".Translate(), StatUpgrade.CargoCapacity, HelperMethods.FillableBarInnerTex, HelperMethods.FillableBarBackgroundTex, BoatComp.CargoCapacity, cargoAdded, cargoAdded / MaxCargoValueDisplayed);

            if (SelPawnUpgrade.TryGetComp <CompFueledTravel>() != null)
            {
                Rect fuelEfficiencyStatRect = new Rect(LeftWindowEdge + EdgePadding, cargoCapacityStatRect.y + 25f, barWidth, 20f);
                HelperMethods.FillableBarLabeled(fuelEfficiencyStatRect, SelPawnUpgrade.GetComp <CompFueledTravel>().FuelEfficiency / MaxFuelEffValueDisplayed,
                                                 "BoatFuelCost".Translate(), StatUpgrade.FuelConsumptionRate, HelperMethods.FillableBarInnerTex, HelperMethods.FillableBarBackgroundTex, SelPawnUpgrade.GetComp <CompFueledTravel>().FuelEfficiency, fuelEffAdded, fuelEffAdded / MaxFuelEffValueDisplayed);

                Rect fuelCapacityStatRect = new Rect(LeftWindowEdge + EdgePadding, fuelEfficiencyStatRect.y + 25f, barWidth, 20f);
                HelperMethods.FillableBarLabeled(fuelCapacityStatRect, SelPawnUpgrade.GetComp <CompFueledTravel>().FuelCapacity / MaxFuelCapValueDisplayed,
                                                 "BoatFuelCapacity".Translate(), StatUpgrade.FuelCapacity, HelperMethods.FillableBarInnerTex, HelperMethods.FillableBarBackgroundTex, SelPawnUpgrade.GetComp <CompFueledTravel>().FuelCapacity, fuelCapAdded, fuelCapAdded / MaxFuelCapValueDisplayed);
            }
        }
        protected override void FillTab()
        {
            Rect rect  = new Rect(0f, TopPadding, size.x, size.y - TopPadding);
            Rect rect2 = rect.ContractedBy(10f);

            GUI.BeginGroup(rect2);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;

            UpgradeNode additionalStatNode    = null;
            UpgradeNode highlightedPreMetNode = null;

            Rect upgradeButtonRect = new Rect(screenWidth - BottomDisplayedOffset - 80f, BottomWindowEdge - 30f, 75f, 25f);
            Rect cancelButtonRect  = new Rect(LeftWindowEdge + 5f, BottomWindowEdge - 30f, 75f, 25f);
            Rect displayRect       = new Rect(SelPawnUpgrade.VehicleDef.drawProperties.upgradeUICoord.x, SelPawnUpgrade.VehicleDef.drawProperties.upgradeUICoord.y, SelPawnUpgrade.VehicleDef.drawProperties.upgradeUISize.x, SelPawnUpgrade.VehicleDef.drawProperties.upgradeUISize.y);

            if (VehicleMod.settings.debug.debugDrawNodeGrid)
            {
                DrawBackgroundGrid();
            }
            if (Prefs.DevMode)
            {
                var font = Text.Font;
                Text.Font = GameFont.Tiny;
                Rect screenInfo = new Rect(LeftWindowEdge + 5f, GridSpacing.y + 3f, screenWidth - LeftWindowEdge - 10f, 50f);
                Widgets.Label(screenInfo, $"Screen Size: ({size.x},{size.y}) \nBottomEdge: {BottomWindowEdge}px \nLeftWindowEdge: {LeftWindowEdge}px");
                Text.Font = font;
            }

            if (selectedNode != null && !SelPawnUpgrade.CompUpgradeTree.CurrentlyUpgrading)
            {
                float imageWidth   = TotalIconSizeScalar / selectedNode.UpgradeImage.width;
                float imageHeight  = TotalIconSizeScalar / selectedNode.UpgradeImage.height;
                Rect  selectedRect = new Rect(GridOrigin.x + (GridSpacing.x * selectedNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * selectedNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                selectedRect = selectedRect.ExpandedBy(2f);
                GUI.DrawTexture(selectedRect, BaseContent.WhiteTex);
            }

            if (Widgets.ButtonText(upgradeButtonRect, "Upgrade".Translate()) && selectedNode != null && !selectedNode.upgradeActive)
            {
                if (SelPawnUpgrade.CompUpgradeTree.Disabled(selectedNode))
                {
                    Messages.Message("DisabledFromOtherNode".Translate(), MessageTypeDefOf.RejectInput, false);
                }
                else if (SelPawnUpgrade.CompUpgradeTree.PrerequisitesMet(selectedNode))
                {
                    SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(SelPawnUpgrade.Map);
                    SoundDefOf.Building_Complete.PlayOneShot(SelPawnUpgrade);

                    SelPawnUpgrade.drafter.Drafted = false;
                    if (DebugSettings.godMode)
                    {
                        SelPawnUpgrade.CompUpgradeTree.FinishUnlock(selectedNode);
                    }
                    else
                    {
                        SelPawnUpgrade.CompUpgradeTree.StartUnlock(selectedNode);
                    }
                    selectedNode.upgradePurchased = true;
                    selectedNode = null;
                }
                else
                {
                    Messages.Message("MissingPrerequisiteUpgrade".Translate(), MessageTypeDefOf.RejectInput, false);
                }
            }

            if (SelPawnUpgrade.CompUpgradeTree.CurrentlyUpgrading)
            {
                if (Widgets.ButtonText(cancelButtonRect, "CancelUpgrade".Translate()))
                {
                    SelPawnUpgrade.CompUpgradeTree.CancelUpgrade();
                }
            }
            else if (selectedNode != null && SelPawnUpgrade.CompUpgradeTree.NodeListed(selectedNode).upgradeActive&& SelPawnUpgrade.CompUpgradeTree.LastNodeUnlocked(selectedNode))
            {
                if (Widgets.ButtonText(cancelButtonRect, "RefundUpgrade".Translate()))
                {
                    SelPawnUpgrade.CompUpgradeTree.RefundUnlock(SelPawnUpgrade.CompUpgradeTree.NodeListed(selectedNode));
                    selectedNode = null;
                }
            }
            else
            {
                Widgets.ButtonText(cancelButtonRect, string.Empty);
            }

            foreach (UpgradeNode upgradeNode in SelPawnUpgrade.CompUpgradeTree.upgradeList)
            {
                if (!upgradeNode.prerequisiteNodes.NullOrEmpty())
                {
                    foreach (UpgradeNode prerequisite in SelPawnUpgrade.CompUpgradeTree.upgradeList.FindAll(x => upgradeNode.prerequisiteNodes.Contains(x.upgradeID)))
                    {
                        Vector2 start = new Vector2(GridOrigin.x + (GridSpacing.x * prerequisite.GridCoordinate.x), GridOrigin.y + (GridSpacing.y * prerequisite.GridCoordinate.z) + (TopPadding * 2));
                        Vector2 end   = new Vector2(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) + (TopPadding * 2));
                        Color   color = Color.grey;
                        if (upgradeNode.upgradeActive)
                        {
                            color = Color.white;
                        }
                        else if (!string.IsNullOrEmpty(upgradeNode.disableIfUpgradeNodeEnabled))
                        {
                            try
                            {
                                UpgradeNode preUpgrade     = SelPawnUpgrade.CompUpgradeTree.NodeListed(upgradeNode.disableIfUpgradeNodeEnabled);
                                float       imageWidth     = TotalIconSizeScalar / preUpgrade.UpgradeImage.width;
                                float       imageHeight    = TotalIconSizeScalar / preUpgrade.UpgradeImage.height;
                                Rect        preUpgradeRect = new Rect(GridOrigin.x + (GridSpacing.x * preUpgrade.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * preUpgrade.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                                if (!SelPawnUpgrade.CompUpgradeTree.CurrentlyUpgrading)
                                {
                                    if (preUpgrade.upgradePurchased)
                                    {
                                        color = Color.black;
                                    }
                                    else if (Mouse.IsOver(preUpgradeRect))
                                    {
                                        color = Color.red;
                                    }
                                }
                            }
                            catch
                            {
                                Log.Error($"Unable to find UpgradeNode {upgradeNode.disableIfUpgradeNodeEnabled} on iteration. Are you referencing the proper upgradeID?");
                            }
                        }
                        Widgets.DrawLine(start, end, color, 2f);
                    }
                }
            }

            bool preDrawingDescriptions = false;

            for (int i = 0; i < SelPawnUpgrade.CompUpgradeTree.upgradeList.Count; i++)
            {
                UpgradeNode upgradeNode = SelPawnUpgrade.CompUpgradeTree.upgradeList[i];
                float       imageWidth  = TotalIconSizeScalar / upgradeNode.UpgradeImage.width;
                float       imageHeight = TotalIconSizeScalar / upgradeNode.UpgradeImage.height;

                Rect upgradeRect = new Rect(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);
                Widgets.DrawTextureFitted(upgradeRect, upgradeNode.UpgradeImage, 1);

                if (!SelPawnUpgrade.CompUpgradeTree.PrerequisitesMet(upgradeNode))
                {
                    Widgets.DrawBoxSolid(upgradeRect, PrerequisitesNotMetColor);
                }
                else if (!upgradeNode.upgradeActive || !upgradeNode.upgradePurchased)
                {
                    Widgets.DrawBoxSolid(upgradeRect, NotUpgradedColor);
                }

                if (!upgradeNode.prerequisiteNodes.NotNullAndAny())
                {
                    if (!string.IsNullOrEmpty(upgradeNode.rootNodeLabel))
                    {
                        float textWidth     = Text.CalcSize(upgradeNode.rootNodeLabel).x;
                        Rect  nodeLabelRect = new Rect(upgradeRect.x - (textWidth - upgradeRect.width) / 2, upgradeRect.y - 20f, 10f * upgradeNode.rootNodeLabel.Length, 25f);
                        Widgets.Label(nodeLabelRect, upgradeNode.rootNodeLabel);
                    }
                }
                Rect buttonRect = new Rect(GridOrigin.x + (GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), GridOrigin.y + (GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (TopPadding * 2), imageWidth, imageHeight);

                Rect     infoLabelRect = new Rect(5f, BottomWindowEdge, LeftWindowEdge, 150f);
                GUIStyle infoLabelFont = new GUIStyle(Text.CurFontStyle);
                infoLabelFont.fontStyle = FontStyle.Bold;

                if (!SelPawnUpgrade.CompUpgradeTree.CurrentlyUpgrading)
                {
                    if (Mouse.IsOver(upgradeRect))
                    {
                        preDrawingDescriptions = true;

                        if (!upgradeNode.upgradePurchased)
                        {
                            additionalStatNode    = upgradeNode;
                            highlightedPreMetNode = upgradeNode;
                        }
                        UIElements.LabelStyled(infoLabelRect, upgradeNode.label, infoLabelFont);

                        Widgets.Label(new Rect(infoLabelRect.x, infoLabelRect.y + 20f, infoLabelRect.width, 140f), upgradeNode.informationHighlighted);
                    }

                    if ((Mouse.IsOver(upgradeRect)) && SelPawnUpgrade.CompUpgradeTree.PrerequisitesMet(upgradeNode) && !upgradeNode.upgradeActive)
                    {
                        GUI.DrawTexture(upgradeRect, TexUI.HighlightTex);
                    }

                    if (SelPawnUpgrade.CompUpgradeTree.PrerequisitesMet(upgradeNode))
                    {
                        if (Widgets.ButtonInvisible(buttonRect, true))
                        {
                            if (selectedNode != upgradeNode)
                            {
                                selectedNode = upgradeNode;
                                SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                            }
                            else
                            {
                                selectedNode = null;
                                SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                            }
                        }
                    }
                }
            }
            Rect     selectedLabelRect = new Rect(5f, BottomWindowEdge, LeftWindowEdge, 150f);
            GUIStyle selectedLabelFont = new GUIStyle(Text.CurFontStyle);

            selectedLabelFont.fontStyle = FontStyle.Bold;

            if (selectedNode != null && !preDrawingDescriptions)
            {
                if (!selectedNode.upgradePurchased)
                {
                    additionalStatNode = selectedNode;
                }

                UIElements.LabelStyled(selectedLabelRect, selectedNode.label, selectedLabelFont);

                Widgets.Label(new Rect(selectedLabelRect.x, selectedLabelRect.y + 20f, selectedLabelRect.width, 140f), selectedNode.informationHighlighted);
            }

            Rect labelRect = new Rect(0f, 0f, rect2.width - 16f, 20f);

            if (!VehicleMod.settings.debug.debugDrawNodeGrid)
            {
                Widgets.Label(labelRect, SelPawnUpgrade.Label);
            }

            Color lineColor = GUI.color;

            GUI.color = new Color(0.3f, 0.3f, 0.3f, 1f);

            Widgets.DrawLineHorizontal(0, TopViewPadding, screenWidth);
            Widgets.DrawLineHorizontal(0, BottomWindowEdge, screenWidth);
            Widgets.DrawLineHorizontal(0, screenHeight - SideDisplayedOffset - 1f, screenWidth);

            Widgets.DrawLineVertical(0, TopViewPadding, screenHeight);
            Widgets.DrawLineVertical(screenWidth - BottomDisplayedOffset - 1f, TopViewPadding, screenHeight);

            if (VehicleMod.settings.main.drawUpgradeInformationScreen)
            {
                Widgets.DrawLineVertical(LeftWindowEdge, TopViewPadding, screenHeight);
            }
            GUI.color = lineColor;

            if (VehicleMod.settings.main.drawUpgradeInformationScreen)
            {
                if (SelPawnUpgrade != null)
                {
                    try
                    {
                        Vector2 display = SelPawnUpgrade.VehicleDef.drawProperties.upgradeUICoord;
                        float   UISizeX = SelPawnUpgrade.VehicleDef.drawProperties.upgradeUISize.x;
                        float   UISizeY = SelPawnUpgrade.VehicleDef.drawProperties.upgradeUISize.y;
                        RenderHelper.DrawVehicleTex(new Rect(display.x, display.y, UISizeX, UISizeY), VehicleTexture, SelPawnUpgrade,
                                                    SelPawnUpgrade.pattern, true, SelPawnUpgrade.DrawColor, SelPawnUpgrade.DrawColorTwo, SelPawnUpgrade.DrawColorThree);

                        if (VehicleMod.settings.debug.debugDrawCannonGrid)
                        {
                            Widgets.DrawLineHorizontal(displayRect.x, displayRect.y, displayRect.width);
                            Widgets.DrawLineHorizontal(displayRect.x, displayRect.y + displayRect.height, displayRect.width);
                            Widgets.DrawLineVertical(displayRect.x, displayRect.y, displayRect.height);
                            Widgets.DrawLineVertical(displayRect.x + displayRect.width, displayRect.y, displayRect.height);
                            if (screenWidth - (displayRect.x + displayRect.width) < 0)
                            {
                                Resize      = new Vector2(screenWidth + displayRect.x, screenHeight);
                                resizeCheck = true;
                            }
                        }
                        if (VehicleMod.settings.debug.debugDrawNodeGrid)
                        {
                            Widgets.DrawLineHorizontal(LeftWindowEdge, 70f, screenWidth - LeftWindowEdge);
                            int lineCount = (int)(screenWidth - LeftWindowEdge) / 10;

                            for (int i = 1; i <= lineCount; i++)
                            {
                                Widgets.DrawLineVertical(LeftWindowEdge + 10 * i, 70f, (i % 5 == 0) ? 10 : 5);
                            }
                            var color = GUI.color;
                            GUI.color = Color.red;
                            Widgets.DrawLineVertical(LeftWindowEdge + (((screenWidth - BottomDisplayedOffset) - LeftWindowEdge) / 2), 70f, 12f);
                            GUI.color = color;
                        }

                        SelPawnUpgrade.CompUpgradeTree.upgradeList.Where(u => u.upgradePurchased && u.upgradeActive).ForEach(u => u.DrawExtraOnGUI(new Rect(display.x, display.y, UISizeX, UISizeY)));
                        if (selectedNode != null)
                        {
                            selectedNode.DrawExtraOnGUI(new Rect(display.x, display.y, UISizeX, UISizeY));
                        }
                        if (highlightedPreMetNode != null)
                        {
                            highlightedPreMetNode.DrawExtraOnGUI(new Rect(display.x, display.y, UISizeX, UISizeY));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorOnce($"Unable to display {SelPawnUpgrade.def.LabelCap} Texture on Upgrade Screen. Error: {ex.Message} \n StackTrace: {ex.StackTrace}", SelPawnUpgrade.thingIDNumber);
                    }
                }
            }
            if (additionalStatNode != null)
            {
                DrawCostItems(additionalStatNode);
            }
            else if (selectedNode != null)
            {
                DrawCostItems(selectedNode);
            }

            DrawStats(additionalStatNode as StatUpgrade);

            if (SelPawnUpgrade.CompUpgradeTree.CurrentlyUpgrading)
            {
                Rect greyedViewRect = new Rect(0, TopViewPadding, LeftWindowEdge, BottomWindowEdge - TopViewPadding);
                Widgets.DrawBoxSolid(greyedViewRect, LockScreenColor);
                Rect   greyedLabelRect = new Rect(LeftWindowEdge / 2 - 17f, (BottomWindowEdge - TopViewPadding) / 2, 100f, 100f);
                string timeFormatted   = VehicleMod.settings.main.useInGameTime ? RimWorldTime.TicksToGameTime(SelPawnUpgrade.CompUpgradeTree.TimeLeftUpgrading) : RimWorldTime.TicksToRealTime(SelPawnUpgrade.CompUpgradeTree.TimeLeftUpgrading);
                timeFormatted = SelPawnUpgrade.CompUpgradeTree.TimeLeftUpgrading.ToString();
                Widgets.Label(greyedLabelRect, timeFormatted);

                DrawCostItems(null);
            }

            GUI.EndGroup();

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }