Пример #1
0
        protected void drawFlightRefinery(ref WBIRefineryResource refineryResource, PartResourceDefinition resourceDef)
        {
            GUILayout.BeginVertical(guiStyles["blockBackground"]);

            //Resource name
            GUILayout.Label(string.Format(refineryResource.kResourceName, resourceDef.displayName), guiStyles["stdText"]);

            //Send to refinery
            refineryResource.sendToRefinery = GUILayout.Toggle(refineryResource.sendToRefinery, WBIRefinery.ksendToRefinery, guiStyles["toggleButton"]);

            //Current/Max amounts
            GUILayout.Label(string.Format(WBIRefinery.kStorage, refineryResource.amount, refineryResource.maxAmount), guiStyles["productionStat"], unitCostOptions);

            GUILayout.BeginHorizontal();

            //Fill tanks
            if (FlightGlobals.ActiveVessel.LandedInKSC)
            {
                if (GUILayout.Button(WBIRefinery.kFillTanks))
                {
                    fillTanks(refineryResource);
                }

                //Empty tanks
                if (GUILayout.Button(WBIRefinery.kEmptyTanks))
                {
                    emptyTanks(refineryResource);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Пример #2
0
        protected void emptyTanks(WBIRefineryResource refineryResource)
        {
            double amountAvailable = 0f;
            double maxAmount       = 0;

            //Determine how much resource the vessel has
            FlightGlobals.ActiveVessel.rootPart.GetConnectedResourceTotals(refineryResource.resourceDef.id, out amountAvailable, out maxAmount, true);
            if (maxAmount <= 0)
            {
                return;
            }

            //Calculate how much to add to the refinery
            double amountToAdd    = amountAvailable;
            double spaceAvailable = refineryResource.maxAmount - refineryResource.amount;

            if (amountToAdd > spaceAvailable)
            {
                amountToAdd = spaceAvailable;
            }

            //Fill the tanks
            FlightGlobals.ActiveVessel.rootPart.RequestResource(refineryResource.resourceDef.id, amountToAdd, ResourceFlowMode.ALL_VESSEL);

            //Update the refinery
            refineryResource.amount += amountToAdd;
        }
Пример #3
0
        public override void OnAwake()
        {
            base.OnAwake();
            Instance = this;
            GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecoveryRequested);

            if (HighLogic.LoadedSceneIsEditor)
            {
                EditorLogic.fetch.launchBtn.onClick.AddListener(new UnityEngine.Events.UnityAction(launchVessel));
            }

            //Get the list of refinery resources
            refineryResourceMap = WBIRefineryResource.LoadRefineryResources();
            if (refineryResourceMap.Keys.Count > 0)
            {
                refineryResources = refineryResourceMap.Values.ToArray();
            }

            //Upgrade to max tier if needed
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER && HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX)
            {
                foreach (WBIRefineryResource refineryResource in refineryResourceMap.Values)
                {
                    refineryResource.UpgradeToMaxTier();
                }
            }
        }
Пример #4
0
        protected void drawSpaceCenterRefinery(WBIRefineryResource refineryResource, PartResourceDefinition resourceDef)
        {
            GUILayout.BeginVertical(guiStyles["blockBackground"]);

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            //Resource name
            GUILayout.Label(string.Format(refineryResource.kResourceName, resourceDef.displayName), guiStyles["stdText"]);

            //Production Tier
            GUILayout.Label(string.Format(refineryResource.kProductionLevel, refineryResource.currentTier + 1), guiStyles["stdText"]);

            //Send to refinery
            refineryResource.sendToRefinery = GUILayout.Toggle(refineryResource.sendToRefinery, WBIRefinery.ksendToRefinery, guiStyles["toggleButton"]);

            //Limited production run
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER && refineryResource.IsUnlocked)
            {
                //Enabled?
                refineryResource.limitProduction = GUILayout.Toggle(refineryResource.limitProduction, WBIRefinery.kLimitProduction, guiStyles["toggleButton"]);

                GUILayout.BeginHorizontal();

                //Production amount
                if (GUILayout.RepeatButton("<<<", buttonOptions))
                {
                    refineryResource.unitsToProduce -= 100;
                    if (refineryResource.unitsToProduce <= 0)
                    {
                        refineryResource.unitsToProduce = 0;
                    }
                }
                if (GUILayout.RepeatButton("<<", buttonOptions))
                {
                    refineryResource.unitsToProduce -= 10;
                    if (refineryResource.unitsToProduce <= 0)
                    {
                        refineryResource.unitsToProduce = 0;
                    }
                }
                if (GUILayout.Button("<", buttonOptions))
                {
                    refineryResource.unitsToProduce -= 1;
                    if (refineryResource.unitsToProduce <= 0)
                    {
                        refineryResource.unitsToProduce = 0;
                    }
                }

                //Label
                string unitsFormat = "{0:f2}";
                if (!validNumber)
                {
                    unitsFormat = "<color=red>{0:f2}</color>";
                }
                string productionUnitsStr = string.Format(unitsFormat, refineryResource.unitsToProduce);
                productionUnitsStr = GUILayout.TextField(productionUnitsStr, wideLabelOptions);
                double productionUnits;
                validNumber = double.TryParse(productionUnitsStr, out productionUnits);
                if (validNumber)
                {
                    refineryResource.unitsToProduce = productionUnits;
                }

                //Increment buttons
                if (GUILayout.Button(">", buttonOptions))
                {
                    refineryResource.unitsToProduce += 1;
                }
                if (GUILayout.RepeatButton(">>", buttonOptions))
                {
                    refineryResource.unitsToProduce += 10;
                }
                if (GUILayout.RepeatButton(">>>", buttonOptions))
                {
                    refineryResource.unitsToProduce += 100;
                }

                GUILayout.EndHorizontal();

                //Cost
                double productionCost = refineryResource.unitsToProduce * refineryResource.resourceDef.unitCost;
                GUILayout.Label(string.Format(WBIRefinery.kProductionCost, productionCost), guiStyles["productionStat"], unitCostOptions);
            }

            //Enable production
            if (refineryResource.unitsPerDay > 0f && refineryResource.IsUnlocked)
            {
                refineryResource.isRunning = GUILayout.Toggle(refineryResource.isRunning, WBIRefinery.kEnableRefinery, guiStyles["toggleButton"]);
            }

            GUILayout.EndVertical();

            //Upgrade button: max tier
            bool showNextTierStats = false;
            WBIRefineryResource nextRefineryResource = new WBIRefineryResource(refineryResource.GetNextTier());

            //Need to account for the first tier unlock status as well as the next tier.
            bool isTechUnlocked = refineryResource.IsTechUnlocked();

            if (refineryResource.IsUnlocked && nextRefineryResource.productionTiers.Count > 0)
            {
                isTechUnlocked = nextRefineryResource.IsTechUnlocked();
            }

            //Need to account for the first tier afforadbility as well as the next tier.
            bool canAffordUnlock = refineryResource.CanAffordUnlock();

            if (refineryResource.IsUnlocked && nextRefineryResource.productionTiers.Count > 0)
            {
                canAffordUnlock = nextRefineryResource.CanAffordUnlock();
            }

            if (refineryResource.IsMaxTier())
            {
                GUILayout.BeginHorizontal(guiStyles["statusBackground"], upgradeStatusWidth);
                GUILayout.FlexibleSpace();
                GUILayout.Label(WBIRefinery.kFullyUpgraded, guiStyles["upgradeStatusText"], upgradeStatusHeight);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            //Upgrade button: tech unlocked
            else if (!isTechUnlocked)
            {
                GUILayout.BeginHorizontal(guiStyles["statusBackground"], upgradeStatusWidth);
                GUILayout.FlexibleSpace();
                GUILayout.Label(WBIRefinery.kInsufficientTech, guiStyles["upgradeStatusText"], upgradeStatusHeight);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            //Upgarde button: can afford
            else if (!canAffordUnlock)
            {
                GUILayout.BeginHorizontal(guiStyles["statusBackground"], upgradeStatusWidth);
                GUILayout.FlexibleSpace();
                GUILayout.Label(WBIRefinery.kInsufficientFunds, guiStyles["upgradeStatusText"], upgradeStatusHeight);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            //Allow purchase/upgrade
            else
            {
                string buttonLabel = string.Format(WBIRefinery.kUpgradeButton, refineryResource.unlockCost);
                if (!refineryResource.IsUnlocked)
                {
                    buttonLabel = string.Format(WBIRefinery.kPurchaseButton, refineryResource.unlockCost);
                }
                if (GUILayout.Button(buttonLabel, guiStyles["button"]))
                {
                    refineryResource.UnlockNextTier();
                }
                if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    showNextTierStats = true;
                }
            }

            GUILayout.EndHorizontal();

            //Production values
            GUILayout.BeginVertical(guiStyles["blockBackground"]);
            GUILayout.BeginHorizontal();

            //If we moused over the upgrade button, get the next tier and fake it's running so we can see its stats.
            if (showNextTierStats)
            {
                //Set current amount so players don't freak out.
                nextRefineryResource.amount = refineryResource.amount;

                //Fake the running state so we can get cost and such.
                nextRefineryResource.isRunning = true;
            }

            //Production rate
            if (!showNextTierStats && refineryResource.unitsPerDay > 0f)
            {
                GUILayout.Label(formatRate(refineryResource.UnitsPerSec), guiStyles["productionStat"], wideLabelOptions);
            }
            else if (showNextTierStats && nextRefineryResource.unitsPerDay > 0f)
            {
                GUILayout.Label(formatRate(nextRefineryResource.UnitsPerSec), guiStyles["upgradeText"], wideLabelOptions);
            }

            //Current/Max units
            GUILayout.FlexibleSpace();
            if (!showNextTierStats)
            {
                GUILayout.Label(string.Format(WBIRefinery.kStorage, refineryResource.amount, refineryResource.maxAmount), guiStyles["productionStat"], wideLabelOptions);
            }
            else
            {
                GUILayout.Label(string.Format(WBIRefinery.kStorage, nextRefineryResource.amount, nextRefineryResource.maxAmount), guiStyles["upgradeText"], wideLabelOptions);
            }
            GUILayout.EndHorizontal();

            //Production cost
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                if (!showNextTierStats)
                {
                    GUILayout.Label(WBIRefinery.kCost + formatRate(refineryResource.CostPerSec, "£"), guiStyles["productionStat"], wideLabelOptions);
                }
                else
                {
                    GUILayout.Label(WBIRefinery.kCost + formatRate(nextRefineryResource.CostPerSec, "£"), guiStyles["upgradeText"], wideLabelOptions);
                }
            }

            GUILayout.EndVertical();

            GUILayout.EndVertical();
        }