Exemple #1
0
        public bool Load()
        {
            bool b = false;

            try
            {
                if (File.Exists(fullPath))
                {
                    ConfigNode node      = ConfigNode.Load(fullPath);
                    ConfigNode unwrapped = node.GetNode(GetType().Name);
                    ConfigNode.LoadObjectFromConfig(this, unwrapped);
                    b = true;
                }
                else
                {
                    BasicDeltaV.BasicLogging("Settings file could not be found [{0}]", fullPath);
                    b = false;
                }
            }
            catch (Exception e)
            {
                BasicDeltaV.BasicLogging("Error while loading settings file from [{0}]\n{1}", fullPath, e);
                b = false;
            }

            _labelColorHex   = ColorUtility.ToHtmlStringRGB(LabelColor);
            _readoutColorHex = ColorUtility.ToHtmlStringRGB(ReadoutColor);

            return(b);
        }
Exemple #2
0
        private void Awake()
        {
            if (loaded)
            {
                Destroy(gameObject);
                return;
            }

            DontDestroyOnLoad(gameObject);

            loaded = true;

            instance = this;

            fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName).Replace("\\", "/");

            if (Load())
            {
                BasicDeltaV.BasicLogging("Settings file loaded");
            }
            else
            {
                if (Save())
                {
                    BasicDeltaV.BasicLogging("New Settings files generated at:\n{0}", fullPath);
                }
            }

            SkillTypes = StringList(CrewRestrictionType);
        }
Exemple #3
0
        private void Awake()
        {
            if (instance != null)
            {
                Destroy(gameObject);
                return;
            }

            instance = this;

            SimManager.UpdateModSettings();
            SimManager.OnReady -= GetStageInfo;
            SimManager.OnReady += GetStageInfo;
        }
Exemple #4
0
        private ConfigNode AsConfigNode()
        {
            try
            {
                ConfigNode node = new ConfigNode(GetType().Name);

                node = ConfigNode.CreateConfigFromObject(this, node);
                return(node);
            }
            catch (Exception e)
            {
                BasicDeltaV.BasicLogging("Failed to generate settings file node...\n{0}", e);
                return(new ConfigNode(GetType().Name));
            }
        }
Exemple #5
0
        public bool Save()
        {
            bool b = false;

            try
            {
                ConfigNode node    = AsConfigNode();
                ConfigNode wrapper = new ConfigNode(GetType().Name);
                wrapper.AddNode(node);
                wrapper.Save(fullPath);
                b = true;
            }
            catch (Exception e)
            {
                BasicDeltaV.BasicLogging("Error while saving settings file from [{0}]\n{1}", fullPath, e);
                b = false;
            }

            return(b);
        }
Exemple #6
0
        private void OnDestroy()
        {
            instance = null;

            GameEvents.onVesselCrewWasModified.Remove(CrewModified);
            GameEvents.onVesselChange.Remove(CrewModified);
            GameEvents.onStageActivate.Remove(OnStage);
            GameEvents.onEditorShipModified.Remove(DeactivateEditorDeltaV);
            GameEvents.StageManager.OnGUIStageSequenceModified.Remove(OnStageModify);

            GameEvents.onPartPriorityChanged.Remove(TriggerSimulator);
            GameEvents.onPartResourceListChange.Remove(TriggerSimulator);
            GameEvents.onPartCrossfeedStateChange.Remove(TriggerSimulator);
            GameEvents.onPartFuelLookupStateChange.Remove(TriggerSimulator);

            GameEvents.onPartModuleAdjusterAdded.Remove(TriggerSimulator);
            GameEvents.onPartModuleAdjusterRemoved.Remove(TriggerSimulator);

            GameEvents.StageManager.OnGUIStageAdded.Remove(TriggerSimulator);
            GameEvents.StageManager.OnGUIStageRemoved.Remove(TriggerSimulator);
            GameEvents.StageManager.OnStagingSeparationIndices.Remove(TriggerSimulator);

            if (appLauncher != null)
            {
                Destroy(appLauncher);
            }

            if (panelHandler != null)
            {
                Destroy(panelHandler);
            }

            if (BasicDeltaV_Settings.Instance.Save())
            {
                BasicLogging("Settings file saved");
            }
        }
        private void Awake()
        {
            if (loaded)
            {
                Destroy(gameObject);
                return;
            }

            if (!spritesLoaded)
            {
                loadSprites();
            }

            if (!stageEditorGroupProcessed && HighLogic.LoadedSceneIsEditor)
            {
                processEditorStageGroup();
            }

            if (!stageFlightGroupProcessed && HighLogic.LoadedSceneIsFlight)
            {
                processFlightStageGroup();
            }

            if (!UIappsProcessed)
            {
                processUIApps();
            }

            if (!TMPLoaded && !UILoaded)
            {
                if (loadedPrefabs == null)
                {
                    string path = KSPUtil.ApplicationRootPath + bundlePath;

                    AssetBundle prefabs = AssetBundle.LoadFromFile(path + bundleName);

                    if (prefabs != null)
                    {
                        loadedPrefabs = prefabs.LoadAllAssets <GameObject>();
                    }
                }

                if (loadedPrefabs != null)
                {
                    if (!TMPLoaded)
                    {
                        processTMPPrefabs();
                    }

                    if (UISkinManager.defaultSkin != null && !UILoaded)
                    {
                        processUIPrefabs();
                    }
                }
            }

            if (TMPLoaded && UILoaded)
            {
                BasicDeltaV.BasicLogging("UI Loaded and processed");
            }

            if (TMPLoaded && UILoaded && spritesLoaded && stageEditorGroupProcessed && stageFlightGroupProcessed && UIappsProcessed)
            {
                loaded = true;
            }

            Destroy(gameObject);
        }
        private void processFlightStageGroup()
        {
            StageManager prefabFlight = null;

            var prefabs = Resources.FindObjectsOfTypeAll <StageManager>();

            for (int i = prefabs.Length - 1; i >= 0; i--)
            {
                var pre = prefabs[i];

                if (pre.name == "StageManager")
                {
                    prefabFlight = pre;
                }
            }

            if (prefabFlight == null)
            {
                return;
            }

            try
            {
                var fields = typeof(StageIcon).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToArray();

                StageIconInfoBox infoBar = fields[12].GetValue(prefabFlight.stageIconPrefab) as StageIconInfoBox;

                panelInfoBarPrefab = Instantiate(infoBar, BasicDeltaV_Settings.Instance.transform);
                panelInfoBarPrefab.gameObject.name = "BasicerDeltaV";

                RectTransform infoRect = panelInfoBarPrefab.GetComponent <RectTransform>();

                infoRect.anchorMin        = new Vector2(1, 1);
                infoRect.anchorMax        = new Vector2(1, 1);
                infoRect.anchoredPosition = new Vector2(25, 12);

                panelInfoBarPrefab.GetComponent <LayoutElement>().ignoreLayout = true;

                panelInfoBarPrefab.SetCaption(string.Format("<color=#{0}> ΔV</color>", BasicDeltaV.TextColor));
                panelInfoBarPrefab.SetProgressBarBgColor(new Color(0.51765f, 0.71765f, 0.003922f, 0.6f));
                panelInfoBarPrefab.SetProgressBarColor(new Color(1, 1, 0.078431f, 0.6f));

                Slider slider = panelInfoBarPrefab.GetComponentInChildren <Slider>();

                RectTransform sliderRect = slider.GetComponent <RectTransform>();

                sliderRect.sizeDelta        = new Vector2(sliderRect.sizeDelta.x, 16);
                sliderRect.anchoredPosition = new Vector2(sliderRect.anchoredPosition.x, -2);

                TextMeshProUGUI captionText = panelInfoBarPrefab.GetComponentsInChildren <TextMeshProUGUI>()[1];

                captionText.color = Color.white;

                RectTransform captionRect = captionText.rectTransform;

                captionRect.sizeDelta = new Vector2(captionRect.sizeDelta.x, 16);

                tooltipPrefab = panelInfoBarPrefab.GetComponent <TooltipController_Text>();

                //BasicDeltaV.BasicLogging("Toolip: Enabled: {0} tooltip prefab: {1} instance" , tool.enabled
                //    , tool.prefab == null ? "Null" : "Valid", tool.TooltipPrefabInstance == null ? "Null" : "Valid");

                tooltipPrefab.enabled          = true;
                tooltipPrefab.continuousUpdate = true;

                Destroy(panelInfoBarPrefab.GetComponentInChildren <TextMeshProUGUI>().gameObject);
                Destroy(panelInfoBarPrefab.GetComponentInChildren <Image>().gameObject);

                //BasicDeltaV.BasicLogging("DV Panel Prefab processed");
            }
            catch (Exception e)
            {
                panelInfoBarPrefab = null;

                BasicDeltaV.BasicLogging("Error in stage panel info box UI: {0}", e);
            }

            StageGroup group = prefabFlight.stageGroupPrefab;

            if (stageGroupSprite == null)
            {
                Transform layout = group.transform.Find("IconLayout");

                if (layout != null)
                {
                    stageGroupSprite = layout.GetComponent <Image>().sprite;
                }
            }

            group.gameObject.AddComponent <BasicDeltaV_StageGroupHandler>();

            stageFlightGroupProcessed = true;
        }
        private void loadSprites()
        {
            Texture2D twr = GameDatabase.Instance.GetTexture("BasicDeltaV/Resources/TWRGauge", false);

            twrGaugeSprite = Sprite.Create(twr, new Rect(0, 0, twr.width, twr.height), new Vector2(0.5f, 0.5f));

            ContractsApp prefab = null;

            var prefabs = Resources.FindObjectsOfTypeAll <ContractsApp>();

            for (int i = prefabs.Length - 1; i >= 0; i--)
            {
                var pre = prefabs[i];

                if (pre.name != "ContractsApp")
                {
                    continue;
                }

                prefab = pre;
                break;
            }

            if (prefab == null)
            {
                return;
            }

            GenericAppFrame      appFrame      = null;
            GenericCascadingList cascadingList = null;
            UIListItem_spacer    spacer        = null;

            try
            {
                var fields = typeof(ContractsApp).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToArray();

                appFrame = fields[7].GetValue(prefab) as GenericAppFrame;

                cascadingList = fields[9].GetValue(prefab) as GenericCascadingList;

                spacer = fields[11].GetValue(prefab) as UIListItem_spacer;
            }
            catch (Exception e)
            {
                BasicDeltaV.BasicLogging("Error in processing toolbar panel UI: {0}", e);
            }

            if (appFrame != null)
            {
                windowSprite = appFrame.gfxBg.sprite;
                titleSprite  = appFrame.gfxHeader.sprite;
                footerSprite = appFrame.gfxFooter.sprite;
            }

            if (cascadingList != null)
            {
                buttonSprite        = cascadingList.cascadeHeader.GetComponent <Image>().sprite;
                contentFooterSprite = cascadingList.cascadeFooter.GetComponent <Image>().sprite;
            }

            if (spacer != null)
            {
                componentSprite = spacer.GetComponent <Image>().sprite;
                UIStateImage stateImage = spacer.GetComponentInChildren <UIStateImage>();

                selectedSprite   = stateImage.states[1].sprite;
                unselectedSprite = stateImage.states[0].sprite;
            }

            spritesLoaded = true;
        }