Ejemplo n.º 1
0
        public void Save()
        {
            HSUtils.DebugLog("saving settings");

            var t      = new ConfigNode();
            var config = t.AddNode(NODE_SETTINGS);

            var nodeWindowPositions = config.AddNode(NODE_WINDOW_POSITIONS);
            var nodeVisibilities    = config.AddNode(NODE_WINDOW_VISIBILITIES);
            var nodeBottomButtons   = config.AddNode(BOTTOM_BUTTONS);

            saveDicValuesToNode(windowPositions, nodeWindowPositions, WINDOW_POSITION,
                                (node, position) => node.AddNode(position.ToNode()));

            saveDicValuesToNode(windowVisibilities, nodeVisibilities, WINDOW_VISIBLE,
                                (node, visible) => node.AddValue(VALUE, visible));

            saveDicValuesToNode(bottomButtons, nodeBottomButtons, BUTTON_STATE, (node, value) => node.AddValue(VALUE, value));

            var nodeVesselTypeVisibility = config.AddNode(NODE_VESSEL_TYPE_VISIBILITY);

            var typeList = Resources.vesselTypesList;

            foreach (var type in typeList)
            {
                nodeVesselTypeVisibility.AddValue(type.name, type.visible);
            }

            t.Save(SettingsFile);
        }
Ejemplo n.º 2
0
        private string getDistanceText(ModuleDockingNode port)
        {
            var activeVessel = FlightGlobals.ActiveVessel;
            var distance     = Vector3.Distance(activeVessel.transform.position, port.GetTransform().position);

            return(string.Format("{0}m", HSUtils.ToSI(distance)));
        }
Ejemplo n.º 3
0
            private void OnAppLauncherReady()
            {
                if (this.appLauncherButton != null)
                {
                    HSUtils.DebugLog("application launcher button already exists");
                    return;
                }

                var appLauncher = ApplicationLauncher.Instance;

                if (appLauncher == null)
                {
                    HSUtils.DebugLog("application launcher instance is null");
                    //maybe run a coroutine to try again.
                    return;
                }



                this.appLauncherButton = appLauncher.AddModApplication(appLauncherButton_OnTrue, appLauncherButton_OnFalse,
                                                                       () => { },
                                                                       () => { },
                                                                       () => { },
                                                                       () => { },
                                                                       scenes,
                                                                       Resources.appLauncherIcon
                                                                       );
            }
Ejemplo n.º 4
0
        private string getPortName(ModuleDockingNode port)
        {
            HSUtils.DebugLog("DockingPortListView#getPortName: start");

            if (!namedDockingPortSupport)
            {
                return(port.part.partInfo.title.Trim());
            }

            PartModule found = null;

            for (int i = 0; i < port.part.Modules.Count; i++)
            {
                var module = port.part.Modules[i];
                if (module.GetType() == moduleDockingNodeNamedType)
                {
                    found = module;
                    break;
                }
            }

            if (found == null)
            {
                HSUtils.DebugLog(
                    "DockingPortListView#getPortName: named docking port support enabled but could not find the part module");
                return(port.part.partInfo.title);
            }

            var portName = (string)modulePortName.GetValue(found);

            HSUtils.DebugLog("DockingPortListView#getPortName: found name: {0}", portName);

            return(portName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Refresh list of vessels
        /// </summary>
        public void FetchVesselList()
        {
            this.vesselList = FlightGlobals.Vessels;

            if (this.vesselList == null)
            {
                HSUtils.DebugLog("vessel list is null");
                this.vesselList = new List <Vessel>();
            }

            this.updateActiveVessel();

            // count vessel types
            this.VesselTypeCounts.Clear();
            foreach (var vessel in vesselList)
            {
                var typeString = vessel.vesselType.ToString();

                if (this.VesselTypeCounts.ContainsKey(typeString))
                {
                    this.VesselTypeCounts[typeString]++;
                }
                else
                {
                    this.VesselTypeCounts.Add(typeString, 1);
                }
            }

            this.performFilters();
        }
Ejemplo n.º 6
0
        //blizzy toolbar
        private void setupToolbar()
        {
            HSUtils.DebugLog("HaystackResourceLoader#setupToolbar: toolbar detected, using it.");

            this.toolbarButton             = ToolbarManager.Instance.add("HaystackContinued", toolbarButtonId);
            this.toolbarButton.Visibility  = new GameScenesVisibility(GameScenes.FLIGHT, GameScenes.TRACKSTATION, GameScenes.SPACECENTER);
            this.toolbarButton.TexturePath = Resources.ToolbarIcon;
            this.toolbarButton.ToolTip     = "Haystack ReContinued";

            this.toolbarButton.OnClick += toolbarButton_OnClick;
        }
Ejemplo n.º 7
0
        private void drawDistance(Vessel vessel, Vessel activeVessel)
        {
            string distance = "";

            if (HSUtils.IsInFlight && vessel != activeVessel && vessel != null && activeVessel != null)
            {
                var calcDistance = Vector3.Distance(activeVessel.transform.position, vessel.transform.position);
                distance = HSUtils.ToSI(calcDistance) + "m";
            }

            GUILayout.Label(distance, Resources.textSituationStyle);
        }
Ejemplo n.º 8
0
 public void markVesselHidden(Vessel vessel, bool mark)
 {
     HSUtils.DebugLog("HaystackContinued#markVesselHidden: {0} {1}", vessel.name, mark);
     if (mark)
     {
         DataManager.Instance.HiddenVessels.AddVessel(vessel);
     }
     else
     {
         DataManager.Instance.HiddenVessels.RemoveVessle(vessel);
     }
 }
Ejemplo n.º 9
0
        public void OnDestory()
        {
            HSUtils.DebugLog("HaystackContinued#OnDestroy");

            GameEvents.onHideUI.Remove(this.onHideUI);
            GameEvents.onShowUI.Remove(this.onShowUI);
            GameEvents.onVesselChange.Remove(this.onVesselChange);
            GameEvents.onVesselWasModified.Remove(this.onVesselWasModified);
            GameEvents.onVesselRename.Remove(this.onVesselRenamed);

            DataManager.Instance.OnDataLoaded -= this.onDataLoadedHandler;
            this.expandedVesselInfo.Dispose();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Load images into corresponding textures
        /// </summary>
        public static void LoadTextures()
        {
            try
            {
                // LoadImage(ref appLauncherIcon, appLauncherIconPath);

                LoadImage(ref btnGo, btnGoFilePath);
                LoadImage(ref btnGoHover, btnGoHoverFilePath);
                LoadImage(ref btnTarg, btnGoTargFilePath);
                LoadImage(ref btnTargHover, btnGoTargHoverFilePth);
                //LoadImage(ref btnTargHover, "button_targ_hover.png"); // TODO: Create hover image, it is missing
                LoadImage(ref btnFold, btnFoldFilePath);
                LoadImage(ref btnFoldHover, btnFoldHoverFilePath);
                LoadImage(ref btnBodies, btnBodiesFilePath); // handled separate from vessels

                LoadImage(ref btnDownArrow, btnDownArrowFilePath);
                LoadImage(ref btnUpArrow, btnUpArrowFilePath);
                LoadImage(ref btnOrbitIcon, btnOrbitIconFilePath);
                LoadImage(ref btnHiddenIcon, btnHiddenIconFilePath);
                LoadImage(ref btnTargetAlpha, btnTargetAlphaFilePath);
                LoadImage(ref btnAscendingIcon, btnAscendingFilePath);
                LoadImage(ref btnDescendingIcon, btnDescendingFilePath);

                LoadImage(ref btnExtendedHoverBackground, btnExtendedHoverFilePath);
                LoadImage(ref btnExtendedPressedBackground, btnExtendedPressedFilePath);
                LoadImage(ref btnExtendedIconClose, btnExtendedIconCloseFilePath);
                LoadImage(ref btnExtendedIconOpen, btnExtendedIconOpenFilePath);

                LoadImage(ref btnFlatNormalBackground, btnFlatNormalFilePath);
                LoadImage(ref btnFlatHoverBackground, btnFlatHoverFilePath);
                LoadImage(ref btnFlatPressedBackground, btnFlatPressedFilePath);

                LoadImage(ref imgLine, imgLineFilePath);
                LoadImage(ref imgOutline, imgOutlineFilePath);
                LoadImage(ref imgVesselInfoHover, imgVesselInfoHoverFilePath);
                LoadImage(ref imgVesselInfoNormal, imgVesselInfoNormalFilePath);
                LoadImage(ref imgVesselInfoPressed, imgVesselInfoPressedFilePath);
                LoadImage(ref imgVesselInfoSelected, imgVesselInfoSelectedFilePath);

                LoadImage(ref imgVesselListButtonPressed, imgDockingPortButtonPressedFilePath);

                LoadImage(ref btnTerminateHoverBackground, btnTerminateFlatFilePath);
                LoadImage(ref btnTerminateNormalBackground, btnTerminateHoverFilePath);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                HSUtils.Log("Exception caught, probably failed to load file");
            }
        }
Ejemplo n.º 11
0
            public V this[string name]
            {
                get
                {
                    V ret;
                    return(index.TryGetValue(name, out ret) ? ret : defaultValueFactory());
                }

                set
                {
                    HSUtils.DebugLog(setDebugMessage, name, value);
                    this.index[name] = value;
                }
            }
Ejemplo n.º 12
0
        public void OnDisable()
        {
            HSUtils.DebugLog("HaystackContinued#OnDisable");
            CancelInvoke();

            GameEvents.onPlanetariumTargetChanged.Remove(this.onMapTargetChange);

            HaystackResourceLoader.Instance.DisplayButtonOnClick -= this.displayButtonClicked;

            HaystackResourceLoader.Instance.Settings.WindowPositions[this.SettingsName]    = this.WinRect;
            HaystackResourceLoader.Instance.Settings.WindowVisibilities[this.SettingsName] = this.WinVisible;
            this.bottomButtons.SaveSettings();

            HaystackResourceLoader.Instance.Settings.Save();
        }
Ejemplo n.º 13
0
        private void changeCameraTarget()
        {
            if (this.selectedVessel == null)
            {
                return;
            }

            if (HSUtils.IsTrackingCenterActive)
            {
                HSUtils.RequestCameraFocus(this.selectedVessel);
            }
            else
            {
                HSUtils.FocusMapObject(this.selectedVessel);
            }
        }
Ejemplo n.º 14
0
        public void Load(ConfigNode node)
        {
            ConfigNode loadNode = node.GetNode(this.GetType().Name);

            if (loadNode == null)
            {
                HSUtils.DebugLog("HiddenVessles#Load: node is null");
                return;
            }

            var ns = new NodeSeralizer();

            ConfigNode.LoadObjectFromConfig(ns, loadNode.GetNode(ns.GetType().FullName));

            this.hiddenVessels = ns.hiddenVessels;
        }
Ejemplo n.º 15
0
        public void OnEnable()
        {
            HSUtils.DebugLog("HaystackContinued#OnEnable");

            GameEvents.onPlanetariumTargetChanged.Add(this.onMapTargetChange);

            this.WinRect    = HaystackResourceLoader.Instance.Settings.WindowPositions[this.SettingsName];
            this.WinVisible = HaystackResourceLoader.Instance.Settings.WindowVisibilities[this.SettingsName];
            this.bottomButtons.LoadSettings();

            HaystackResourceLoader.Instance.DisplayButtonOnClick += this.displayButtonClicked;

            InvokeRepeating("IRFetchVesselList", 5.0F, 5.0F);
            InvokeRepeating("RefreshDataSaveSettings", 0, 30.0F);

            //HaystackResourceLoader.Instance.FixApplicationLauncherButtonDisplay(this.WinVisible);
        }
Ejemplo n.º 16
0
        public void Awake()
        {
            HSUtils.DebugLog("HaystackContinued#Awake");

            this.bottomButtons = new BottomButtons();
            this.bottomButtons.LoadSettings();

            this.vesselListController = new VesselListController(this, this.bottomButtons);
            this.defaultScrollerView  = new DefaultScrollerView(this, this.vesselListController);
            this.groupedScrollerView  = new GroupedScrollerView(this, this.vesselListController);
            this.expandedVesselInfo   = new ExpandedVesselInfo(this, this.bottomButtons, this.defaultScrollerView,
                                                               this.groupedScrollerView);
            this.resizeHandle = new ResizeHandle();


            windowId = Resources.rnd.Next(1000, 2000000);
        }
Ejemplo n.º 17
0
        private static IEnumerator SwitchToVessel(Vessel vessel)
        {
            yield return(new WaitForFixedUpdate());

            if (HSUtils.IsTrackingCenterActive)
            {
                HSUtils.TrackingSwitchToVessel(vessel);
            }
            else if (HSUtils.IsSpaceCenterActive)
            {
                HSUtils.SwitchAndFly(vessel);
            }
            else
            {
                FlightGlobals.SetActiveVessel(vessel);
            }
        }
Ejemplo n.º 18
0
        public void Save(ConfigNode node)
        {
            var ns = new NodeSeralizer {
                hiddenVessels = this.hiddenVessels
            };

            try
            {
                var        saveNode = new ConfigNode(this.GetType().Name);
                ConfigNode nsNode   = ConfigNode.CreateConfigFromObject(ns);

                saveNode.AddNode(nsNode);
                node.AddNode(saveNode);
            }
            catch (Exception e)
            {
                HSUtils.Log("HiddenVessles#Save: exception: " + e.Message);
            }
        }
Ejemplo n.º 19
0
        internal static void FocusMapObject(CelestialBody body)
        {
            if (!(IsMapActive || IsTrackingCenterActive))
            {
                return;
            }

            HSUtils.DebugLog("FocusMapObject(body)");

            var cam = getPlanetariumCamera();

            foreach (var mapObject in cam.targets)
            {
                if (mapObject.celestialBody != null && mapObject.celestialBody.GetInstanceID() == body.GetInstanceID())
                {
                    cam.SetTarget(mapObject);
                    return;
                }
            }
        }
Ejemplo n.º 20
0
            private void OnAppLauncherDestroyed()
            {
                var appLauncher = ApplicationLauncher.Instance;

                if (appLauncher == null)
                {
                    HSUtils.DebugLog("OnApplicationLauncherDestroyed: application launcher instance is null.");
                    return;
                }

                if (this.appLauncherButton == null)
                {
                    HSUtils.DebugLog("app launcher button is null.");
                    return;
                }


                appLauncher.RemoveModApplication(this.appLauncherButton);
                this.appLauncherButton = null;
            }
Ejemplo n.º 21
0
        private void setupScenarioModule()
        {
            ProtoScenarioModule protoScenarioModule =
                HighLogic.CurrentGame.scenarios.FirstOrDefault(i => i.moduleName == typeof(HaystackScenarioModule).Name);

            if (protoScenarioModule == null)
            {
                HSUtils.DebugLog("adding scenario module");
                HighLogic.CurrentGame.AddProtoScenarioModule(typeof(HaystackScenarioModule),
                                                             HaystackScenarioModule.Scenes);
            }
            else
            {
                var missing = HaystackScenarioModule.Scenes.Except(protoScenarioModule.targetScenes);
                foreach (var i in missing)
                {
                    HSUtils.DebugLog("missing scenario module scene: {0}", i);
                    protoScenarioModule.targetScenes.Add(i);
                }
            }
        }
Ejemplo n.º 22
0
        internal static void FocusMapObject(Vessel vessel)
        {
            if (!(IsMapActive || IsTrackingCenterActive))
            {
                return;
            }

            HSUtils.DebugLog("FocusMapObject(vessel)");

            var cam = getPlanetariumCamera();

            if (IsTrackingCenterActive)
            {
                foreach (var mapObject in cam.targets)
                {
                    if (mapObject.vessel != null && mapObject.vessel.GetInstanceID() == vessel.GetInstanceID())
                    {
                        cam.SetTarget(mapObject);
                        return;
                    }
                }
                return;
            }

            // else
            // in flight map mode the active vessel is the only vessel in the list of targets
            // don't know why but will attempt to maintain that
            cam.targets.RemoveAll(mapObject => mapObject.vessel != null);

            var activeVessel = FlightGlobals.ActiveVessel;

            if (activeVessel != null && activeVessel.GetInstanceID() != vessel.GetInstanceID())
            {
                cam.AddTarget(FlightGlobals.ActiveVessel.mapObject);
            }

            cam.AddTarget(vessel.mapObject);
            cam.SetTarget(vessel.mapObject);
        }
Ejemplo n.º 23
0
        static DockingPortListView()
        {
            try
            {
                Type result = null;
                AssemblyLoader.loadedAssemblies.TypeOperation(t =>
                {
                    if (t.FullName == "NavyFish.ModuleDockingNodeNamed")
                    {
                        result = t;
                    }
                });

                moduleDockingNodeNamedType = result;

                modulePortName = moduleDockingNodeNamedType.GetField("portName",
                                                                     BindingFlags.Instance | BindingFlags.Public);
            }
            catch (Exception e)
            {
                moduleDockingNodeNamedType = null;
                modulePortName             = null;
                HSUtils.DebugLog("exception getting docking port alignment indicator type");
                HSUtils.DebugLog("{0}", e.Message);
            }

            if (moduleDockingNodeNamedType != null && modulePortName != null)
            {
                namedDockingPortSupport = true;

                HSUtils.Log("Docking Port Alignment Indicator mod detected: using named docking node support.");
                HSUtils.DebugLog("{0} {1}", moduleDockingNodeNamedType.FullName,
                                 moduleDockingNodeNamedType.AssemblyQualifiedName);
            }
            else
            {
                HSUtils.DebugLog("Docking Port Alignment Indicator mod was not detected");
            }
        }
Ejemplo n.º 24
0
        private void convertToNewDirectory()
        {
            var oldSettingsFile = Resources.PathPlugin + "/settings.cfg";

            var oldSettingsExists = File.Exists(oldSettingsFile);
            var newSettingsExists = File.Exists(SettingsFile);

            System.IO.Directory.CreateDirectory(NewPluginDataDir);


            if (oldSettingsExists && !newSettingsExists)
            {
                HSUtils.Log("Moving settings file to new location.");

                File.Move(oldSettingsFile, SettingsFile);
            }
            else if (oldSettingsExists)
            {
                HSUtils.Log("Deleting old settings file.");

                File.Delete(oldSettingsFile);
            }
        }
Ejemplo n.º 25
0
        private void changeCameraTarget()
        {
            // don't do anything if we are in the space center since there is no map view to change.
            if (HSUtils.IsSpaceCenterActive)
            {
                return;
            }

            if (this.SelectedVessel != null)
            {
                if (HSUtils.IsTrackingCenterActive)
                {
                    HSUtils.RequestCameraFocus(this.SelectedVessel);
                }
                else
                {
                    HSUtils.FocusMapObject(this.selectedVessel);
                }
            }
            if (this.SelectedBody != null)
            {
                HSUtils.FocusMapObject(this.SelectedBody);
            }
        }
Ejemplo n.º 26
0
        private void Load()
        {
            HSUtils.Log("loading settings");
            HSUtils.DebugLog("Settings#Load: start");

            var load = ConfigNode.Load(SettingsFile) ?? new ConfigNode();

            if (!load.HasNode(NODE_SETTINGS))
            {
                HSUtils.DebugLog("Settings#Load: no settings node");
                return;
            }

            var config = load.GetNode(NODE_SETTINGS);

            var nodeWindowPositions = config.GetNode(NODE_WINDOW_POSITIONS) ?? new ConfigNode();

            var nodeWindowVisibility = config.GetNode(NODE_WINDOW_VISIBILITIES) ?? new ConfigNode();

            var bottomButtons = config.GetNode(BOTTOM_BUTTONS) ?? new ConfigNode();

            var defaultPos = new Rect(0, 0, 0, 0);

            foreach (var i in nodeWindowPositions.nodes)
            {
                var node     = (ConfigNode)i;
                var name     = node.name;
                var position = node.FromNode(WINDOW_POSITION, defaultPos);

                HSUtils.DebugLog("Settings#load name: {0} position: {1}", name, position);

                this.windowPositions[name] = position;
            }

            foreach (var n in nodeWindowVisibility.nodes)
            {
                var node    = (ConfigNode)n;
                var name    = node.name;
                var visible = node.FromNode(WINDOW_VISIBLE, false);

                HSUtils.DebugLog("Settings#Load name: {0} visible: {1}", name, visible);

                this.windowVisibilities[name] = visible;
            }

            foreach (var n in bottomButtons.nodes)
            {
                var node  = (ConfigNode)n;
                var name  = node.name;
                var value = node.FromNode(BUTTON_STATE, false);

                HSUtils.DebugLog("Settings#Load name: {0} value: {1}", name, value);

                this.bottomButtons[name] = value;
            }

            var nodeTypeVisibility = config.GetNode(NODE_VESSEL_TYPE_VISIBILITY) ?? new ConfigNode();

            foreach (var i in Resources.vesselTypesList)
            {
                i.visible = nodeTypeVisibility.GetBuiltinValue(i.name, true);
            }
        }