Esempio n. 1
0
 private static void GetUntooledPartsAndCost(out List <ModuleTooling> parts, out float toolingCost)
 {
     parts = EditorLogic.fetch.ship.Parts.Slinq().SelectMany(p => p.FindModulesImplementing <ModuleTooling>().Slinq())
             .Where(mt => !mt.IsUnlocked())
             .ToList();
     toolingCost = ModuleTooling.PurchaseToolingBatch(parts, isSimulation: true);
 }
Esempio n. 2
0
        private static void ToolAll()
        {
            GetUntooledPartsAndCost(out List <ModuleTooling> untooledParts, out float toolingCost);

            bool canAfford = Funding.Instance.Funds >= toolingCost;

            if (canAfford)
            {
                ModuleTooling.PurchaseToolingBatch(untooledParts);
                untooledParts.ForEach(mt =>
                {
                    mt.Events["ToolingEvent"].guiActiveEditor = false;
                });
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Checks whether two toolings are considered the same by checking their types and dimensions (if applicable).
        /// Dimension comparison is done with an error margin of 4%.
        /// </summary>
        /// <param name="a">Tooling 1</param>
        /// <param name="b">Tooling 2</param>
        /// <returns>True if toolings match</returns>
        public static bool IsSame(ModuleTooling a, ModuleTooling b)
        {
            if (a.ToolingType != b.ToolingType) return false;

            if (a is ModuleToolingDiamLen || b is ModuleToolingDiamLen)
            {
                var d1 = a as ModuleToolingDiamLen;
                var d2 = b as ModuleToolingDiamLen;
                if (d1 == null || d2 == null) return false;

                d1.GetDimensions(out float diam1, out float len1);
                d2.GetDimensions(out float diam2, out float len2);

                return ToolingDatabase.IsSameSize(diam1, len1, diam2, len2);
            }

            return true;
        }
Esempio n. 4
0
        public tabs toolingTab()
        {
            MaybeUpdate();

            if (!ToolingManager.Instance.toolingEnabled)
            {
                GUILayout.BeginHorizontal();
                try
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Part tooling is disabled", HighLogic.Skin.label);
                    GUILayout.FlexibleSpace();
                }
                finally
                {
                    GUILayout.EndHorizontal();
                }

                return(tabs.Tooling);
            }

            currentToolingType = null;
            GUILayout.BeginHorizontal();
            try {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Tooling Types", HighLogic.Skin.label);
                GUILayout.FlexibleSpace();
            } finally {
                GUILayout.EndHorizontal();
            }
            int counter = 0;

            GUILayout.BeginHorizontal();
            try {
                foreach (string type in ToolingDatabase.toolings.Keys)
                {
                    if (counter % 3 == 0 && counter != 0)
                    {
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                    }
                    counter++;
                    if (GUILayout.Button(type))
                    {
                        currentToolingType = type;
                    }
                }
            } finally {
                GUILayout.EndHorizontal();
            }

            if (untooledParts.Count > 0)
            {
                GUILayout.BeginHorizontal();
                try {
                    GUILayout.Label("Untooled Parts:", HighLogic.Skin.label, GUILayout.Width(312));
                    GUILayout.Label("Tooling cost", rightLabel, GUILayout.Width(72));
                    GUILayout.Label("Untooled", rightLabel, GUILayout.Width(72));
                    GUILayout.Label("Tooled", rightLabel, GUILayout.Width(72));
                } finally {
                    GUILayout.EndHorizontal();
                }
                untooledTypesScroll = GUILayout.BeginScrollView(untooledTypesScroll, GUILayout.Height(204), GUILayout.Width(572));
                try {
                    foreach (var uP in untooledParts)
                    {
                        GUILayout.BeginHorizontal();
                        try
                        {
                            GUILayout.Label(uP.name, boldLabel, GUILayout.Width(312));
                            GUILayout.Label($"{uP.toolingCost:N0}f", rightLabel, GUILayout.Width(72));
                            var untooledExtraCost = GetUntooledExtraCost(uP);
                            GUILayout.Label($"{uP.totalCost:N0}f", rightLabel, GUILayout.Width(72));
                            GUILayout.Label($"{(uP.totalCost - untooledExtraCost):N0}f", rightLabel, GUILayout.Width(72));
                        }
                        finally {
                            GUILayout.EndHorizontal();
                        }
                    }
                } finally {
                    GUILayout.EndScrollView();
                }
                GUILayout.BeginHorizontal();
                try {
                    GUILayout.Label($"Total vessel cost if all parts are tooled: {allTooledCost:N0}");
                } finally {
                    GUILayout.EndHorizontal();
                }
                GUILayout.BeginHorizontal();
                try {
                    if (GUILayout.Button("Tool All"))
                    {
                        var untooledParts = EditorLogic.fetch.ship.Parts.Slinq().SelectMany(p => p.FindModulesImplementing <ModuleTooling>().Slinq())
                                            .Where(mt => !mt.IsUnlocked())
                                            .ToList();

                        float totalToolingCost = ModuleTooling.PurchaseToolingBatch(untooledParts, isSimulation: true);
                        bool  canAfford        = Funding.Instance.Funds >= totalToolingCost;
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                     new Vector2(0.5f, 0.5f),
                                                     new MultiOptionDialog(
                                                         "ConfirmAllToolingsPurchase",
                                                         $"Tooling for all untooled parts will cost {totalToolingCost:N0} funds.",
                                                         "Tooling Purchase",
                                                         HighLogic.UISkin,
                                                         new Rect(0.5f, 0.5f, 150f, 60f),
                                                         new DialogGUIFlexibleSpace(),
                                                         new DialogGUIVerticalLayout(
                                                             new DialogGUIFlexibleSpace(),
                                                             new DialogGUIButton(canAfford ? "Purchase All Toolings" : "Can't Afford",
                                                                                 () =>
                        {
                            if (canAfford)
                            {
                                ModuleTooling.PurchaseToolingBatch(untooledParts);
                                untooledParts.ForEach(mt =>
                                {
                                    mt.Events["ToolingEvent"].guiActiveEditor = false;
                                });
                                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
                            }
                        }, 140.0f, 30.0f, true),
                                                             new DialogGUIButton("Close", () => { }, 140.0f, 30.0f, true)
                                                             )),
                                                     false,
                                                     HighLogic.UISkin);
                    }
                } finally {
                    GUILayout.EndHorizontal();
                }
            }
            return(currentToolingType == null ? tabs.Tooling : tabs.ToolingType);
        }