예제 #1
0
        public void Unload(Vessel vessel, bool delete)
        {
            if (!vessel.isEVA)
            {
                EvaDebug.DebugWarning("Tried unloading a non eva.");
                return;
            }

            EvaDebug.DebugLog("Unload(" + vessel.name + ")");

            foreach (var item in collection)
            {
                if (item.flightID == vessel.id)
                {
                    if (delete)
                    {
                        item.status = Status.Removed;
                    }

                    //unload the vessel here.
                    item.Unload();
                    EvaSettings.SaveEva(item);


                    EvaDebug.DebugLog("Remove EVA: (" + vessel.name + ")");
                    collection.Remove(item);
                    break;
                }
            }
        }
예제 #2
0
        public static void SaveEva(EvaContainer container)
        {
            EvaDebug.DebugWarning("EvaSettings.SaveEva(" + container.Name + ")");

            if (container.status == Status.Removed)
            {
                if (collection.ContainsKey(container.flightID))
                {
                    collection.Remove(container.flightID);
                }
            }
            else
            {
                //The eva was already has a old save.
                if (collection.ContainsKey(container.flightID))
                {
                    //Replace the old save.
                    collection[container.flightID] = container.ToSave();
                }
                else
                {
                    //No save yet. Add it now.
                    collection.Add(container.flightID, container.ToSave());
                }
            }
        }
예제 #3
0
        public void Load(Vessel vessel)
        {
            if (!vessel.isEVA)
            {
                EvaDebug.DebugWarning("Tried loading a non eva.");
                return;
            }

            KerbalEVA currentEVA = vessel.GetComponent <KerbalEVA>();

            if (!Contains(vessel.id))
            {
                EvaContainer container = new EvaContainer(vessel.id);

                //load the vessel here.
                container.Load(currentEVA);
                EvaSettings.LoadEva(container);

                collection.Add(container);
            }
            else
            {
                //Reload
                EvaContainer container = GetEva(vessel.id);

                container.Load(currentEVA);
                EvaSettings.LoadEva(container);
            }
        }
예제 #4
0
        public void OnPartUnpack(Part part)
        {
            if (part.vessel.isEVA)
            {
                //save before pack
                EvaDebug.DebugWarning("Unpack: " + part.vessel.name);

                Load(part.vessel);
            }
        }
예제 #5
0
        public static void Load()
        {
            EvaDebug.DebugWarning("OnLoad()");
            if (displayLoadingKerbals)
            {
                ScreenMessages.PostScreenMessage("Loading Kerbals...", 3, ScreenMessageStyle.LOWER_CENTER);
            }

            LoadFunction();
        }
예제 #6
0
        public static void Load()
        {
            EvaDebug.DebugWarning("OnLoad()");
            if (HighLogic.CurrentGame.Parameters.CustomParams <EvaFollowerMiscSettings>().displayLoadingKerbals)
            {
                ScreenMessages.PostScreenMessage("Loading Kerbals...", 3, ScreenMessageStyle.LOWER_CENTER);
            }

            LoadFunction();
        }
예제 #7
0
        public void OnPartPack(Part part)
        {
            if (part.vessel.isEVA)
            {
                //save before pack
                EvaDebug.DebugWarning("Pack: " + part.vessel.name);

                Unload(part.vessel, false);
            }
        }
예제 #8
0
        public void Start()
        {
            EvaDebug.DebugWarning("EvaOrderController.Start()");

            //save config.
            //EvaSettings.SaveConfiguration();
            EvaSettings.LoadConfiguration();

            if (EvaSettings.displayDebugLines)
            {
                InitializeDebugLine();
            }

            InitializeCursor();
        }
예제 #9
0
        public void Load(KerbalEVA eva)
        {
            //Load KerbalEVA.
            this.eva = eva;
            loaded   = true;

            //Set Name
            this.Name = eva.name;

            //module on last.
            EvaModule module = (EvaModule)eva.GetComponent(typeof(EvaModule));

            module.Load(this);

            EvaDebug.DebugWarning("EvaContainer.Load(" + eva.name + ")");
        }
예제 #10
0
        public static void Save()
        {
            if (isLoaded)
            {
                EvaDebug.DebugWarning("OnSave()");

                if (displayLoadingKerbals)
                {
                    ScreenMessages.PostScreenMessage("Saving Kerbals...", 3, ScreenMessageStyle.LOWER_CENTER);
                }

                SaveFunction();

                isLoaded = false;
            }
        }
예제 #11
0
        public void OnDestroy()
        {
            EvaDebug.DebugWarning("EvaController.OnDestroy()");


            GameEvents.onPartPack.Remove(OnPartPack);
            GameEvents.onPartUnpack.Remove(OnPartUnpack);

            GameEvents.onCrewOnEva.Remove(OnCrewOnEva);
            GameEvents.onCrewBoardVessel.Remove(OnCrewBoardVessel);
//            GameEvents.onCrewKilled.Remove(OnCrewKilled);
            GameEvents.onVesselWillDestroy.Add(VesselDestroyed);

            GameEvents.onGameStateSave.Remove(OnSave);
            GameEvents.onFlightReady.Remove(onFlightReadyCallback);
        }
예제 #12
0
        public static void SaveConfiguration()
        {
            EvaDebug.DebugWarning("SaveConfiguration()");

            ConfigNode node = new ConfigNode();
            ConfigNode data = new ConfigNode();

            data.AddValue("selectMouseButton", selectMouseButton);
            data.AddValue("dispatchMouseButton", dispatchMouseButton);
            data.AddValue("selectKeyButton", selectKeyButton);
            data.AddValue("dispatchKeyButton", dispatchKeyButton);

            node.AddNode(NODENAME, data);

            Debug.Log("Saving to: " + ConfigFileName);
            node.Save(ConfigFileName);
        }
예제 #13
0
        public void Start()
        {
            EvaDebug.DebugWarning("EvaController.Start()");
            //initialize the singleton.
            instance = this;

            GameEvents.onPartPack.Add(OnPartPack);
            GameEvents.onPartUnpack.Add(OnPartUnpack);

            GameEvents.onCrewOnEva.Add(OnCrewOnEva);
            GameEvents.onCrewBoardVessel.Add(OnCrewBoardVessel);
//            GameEvents.onCrewKilled.Add(OnCrewKilled);
            GameEvents.onVesselWillDestroy.Add(VesselDestroyed);

            GameEvents.onGameStateSave.Add(OnSave);
            GameEvents.onFlightReady.Add(onFlightReadyCallback);
        }
예제 #14
0
        public static void LoadConfiguration()
        {
            if (FileExcist("Config.cfg"))
            {
                KSP.IO.TextReader tr    = KSP.IO.TextReader.CreateForType <EvaSettings>("Config.cfg");
                string[]          lines = tr.ReadToEnd().Split('\n');

                foreach (var line in lines)
                {
                    string[] parts = line.Split('=');

                    try
                    {
                        if (parts.Length > 1)
                        {
                            string name  = parts[0].Trim();
                            string value = parts[1].Trim();

                            switch (name)
                            {
                            case "ShowDebugLines": { displayDebugLinesSetting = bool.Parse(value); } break;

                            case "ShowLoadingKerbals": { displayLoadingKerbals = bool.Parse(value); } break;

                            case "EnableHelmetToggle": { displayToggleHelmet = bool.Parse(value); } break;

                            case "SelectMouseButton": { selectMouseButton = int.Parse(value); } break;

                            case "DispatchMouseButton": { dispatchMouseButton = int.Parse(value); } break;

                            case "SelectKey": { selectKeyButton = value; } break;

                            case "DispatchKey": { dispatchKeyButton = value; } break;

                            case "TargetVesselBySelection": { targetVesselBySelection = bool.Parse(value); } break;
                            }
                        }
                    }
                    catch
                    {
                        EvaDebug.DebugWarning("[EFX] Config loading error ");
                    }
                }
                displayDebugLines = displayDebugLinesSetting;
            }
        }
예제 #15
0
        public static void LoadEva(EvaContainer container)
        {
            EvaDebug.DebugWarning("EvaSettings.LoadEva(" + container.Name + ")");

            //The eva was already has a old save.
            //Load it.
            if (collection.ContainsKey(container.flightID))
            {
                //string evaString = collection[container.flightID];
                //EvaDebug.DebugWarning(evaString);

                container.FromSave(collection[container.flightID]);
            }
            else
            {
                //No save yet.
            }
        }
예제 #16
0
        public void Update()
        {
            if (!FlightGlobals.ready || PauseMenu.isOpen)
            {
                return;
            }

            // Replace this with a check to see if GUI is hidden
            if (Input.GetKeyDown(KeyCode.F2) && EvaSettings.displayDebugLinesSetting)
            {
                EvaSettings.displayDebugLines = !EvaSettings.displayDebugLines;
                foreach (EvaContainer container in EvaController.instance.collection)
                {
                    container.togglePatrolLines();
                }
            }

            if (Input.GetKeyDown(KeyCode.B))
            {
                foreach (EvaContainer container in EvaController.instance.collection)
                {
                    container.EVA.PackToggle();
                }
            }

            try
            {
                foreach (EvaContainer eva in EvaController.instance.collection.ToArray())
                {
                    if (eva == null)
                    {
                        //is this possible ?
                        EvaDebug.DebugWarning("eva == null");
                        continue;
                    }

                    //skip unloaded vessels
                    if (!eva.Loaded)
                    {
                        continue;
                    }

                    //Turn the lights on when dark.
                    //Skip for now, too buggy..
                    //eva.UpdateLamps();

                    if (eva.mode == Mode.None)
                    {
                        //Nothing to do here.
                        continue;
                    }

                    //Recover from ragdoll, if possible.
                    if (eva.IsRagDoll)
                    {
                        eva.RecoverFromRagdoll();
                        continue;
                    }

                    Vector3d move = -eva.Position;

                    //Get next Action, Formation or Patrol
                    Vector3d target = eva.GetNextTarget();

                    // Path Finding
                    //todo: check if the target is occopied.
                    move += target;

                    double sqrDist = move.sqrMagnitude;
                    float  speed   = TimeWarp.deltaTime;

                    if (eva.OnALadder)
                    {
                        eva.ReleaseLadder();
                    }

                    #region Break Free Code

                    if (eva.IsActive)
                    {
                        Mode mode = eva.mode;

                        if (Input.GetKeyDown(KeyCode.W))
                        {
                            mode = EvaFollower.Mode.None;
                        }
                        if (Input.GetKeyDown(KeyCode.S))
                        {
                            mode = EvaFollower.Mode.None;
                        }
                        if (Input.GetKeyDown(KeyCode.A))
                        {
                            mode = EvaFollower.Mode.None;
                        }
                        if (Input.GetKeyDown(KeyCode.D))
                        {
                            mode = EvaFollower.Mode.None;
                        }
                        if (Input.GetKeyDown(KeyCode.Q))
                        {
                            mode = EvaFollower.Mode.None;
                        }
                        if (Input.GetKeyDown(KeyCode.E))
                        {
                            mode = EvaFollower.Mode.None;
                        }

                        if (mode == Mode.None)
                        {
                            //break free!
                            eva.mode = mode;
                            continue;
                        }
                    }
                    #endregion

                    //Animation Logic
                    eva.UpdateAnimations(sqrDist, ref speed);

                    move.Normalize();

                    //Distance Logic
                    eva.CheckDistance(move, speed, sqrDist);

                    //Reset Animation Mode Events
                    eva.CheckModeIsNone();
                }
            }
            catch (Exception exp)
            {
                EvaDebug.DebugWarning("[EFX] EvaLogic: " + exp.Message + ":" + exp.ToString());
            }
        }
예제 #17
0
 public void OnDestroy()
 {
     EvaDebug.DebugWarning("EvaLogic.OnDestroy()");
 }
예제 #18
0
 public void Start()
 {
     EvaDebug.DebugWarning("EvaLogic.Start()");
 }
예제 #19
0
 public static void ProfileEnd(string name)
 {
     EndTimer();
     EvaDebug.DebugWarning(string.Format("Profile: {0}: {1}ms", name, Elapsed));
 }
예제 #20
0
        public void Update()
        {
            if (!FlightGlobals.ready || PauseMenu.isOpen)
            {
                return;
            }

            try
            {
                angle += 0.1;

                #region Update selected kerbals
                foreach (EvaContainer eva in EvaController.instance.collection)
                {
                    if (!eva.Loaded)
                    {
                        continue;
                    }

                    if (eva.Selected)
                    {
                        UpdateSelectionLine(eva);
                    }
                }
                #endregion


                if (!FlightGlobals.ActiveVessel.Landed && FlightGlobals.ActiveVessel.GetHeightFromSurface() > 25)
                {
                    DisableCursor();
                    return;
                }

                if (HighLogic.LoadedScene != GameScenes.FLIGHT || MapView.MapIsEnabled)
                {
                    return;
                }

                //add here something to change the selection ui in space.


                #region Handle Cursor...
                if (showCursor)
                {
                    if (!_animatedCursor)
                    {
                        //ray every time ?
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out _cursorHit))
                        {
                            _cursorPosition = _cursorHit.point;
                            _cursorRotation = FlightGlobals.ActiveVessel.transform.rotation;
                        }
                    }

                    SetCursorProperties();
                }
                #endregion

                #region Select Multiple Kerbals

                if (Input.GetMouseButtonDown(EvaSettings.selectMouseButton) ||
                    Input.GetKeyDown(EvaSettings.selectKeyButton))
                {
                    _startClick = Input.mousePosition;
                }
                else if (Input.GetMouseButtonUp(EvaSettings.selectMouseButton) ||
                         Input.GetKeyUp(EvaSettings.selectKeyButton))
                {
                    if (_selection.width < 0)
                    {
                        _selection.x    += _selection.width;
                        _selection.width = -_selection.width;
                    }
                    if (_selection.height < 0)
                    {
                        _selection.y     += _selection.height;
                        _selection.height = -_selection.height;
                    }

                    _startClick = -Vector3.one;
                }

                if (Input.GetMouseButton(EvaSettings.selectMouseButton) ||
                    Input.GetKey(EvaSettings.selectKeyButton))
                {
                    _selection = new Rect(_startClick.x, InvertY(_startClick.y),
                                          Input.mousePosition.x - _startClick.x, InvertY(Input.mousePosition.y) - InvertY(_startClick.y));
                }

                if (Input.GetMouseButton(EvaSettings.selectMouseButton) ||
                    Input.GetKey(EvaSettings.selectKeyButton))
                {
                    if (_selection.width != 0 && _selection.height != 0)
                    {
                        Rect _temp = new Rect(_selection.x, _selection.y, _selection.width, _selection.height);
                        if (_temp.width < 0)
                        {
                            _temp.x    += _temp.width;
                            _temp.width = -_temp.width;
                        }
                        if (_selection.height < 0)
                        {
                            _temp.y     += _temp.height;
                            _temp.height = -_temp.height;
                        }

                        //get the kerbals in the selection.
                        foreach (EvaContainer container in EvaController.instance.collection)
                        {
                            if (!container.Loaded)
                            {
                                //Can't select what isn't there.
                                continue;
                            }

                            Vector3 camPos = Camera.main.WorldToScreenPoint(container.EVA.transform.position);
                            camPos.y = InvertY(camPos.y);

                            if (_temp.Contains(camPos))
                            {
                                SelectEva(container);
                            }
                            else
                            {
                                if (container.Selected)
                                {
                                    DeselectEva(container);
                                }
                            }
                        }
                    }

                    #region targetVesselBySelection
                    if (EvaSettings.targetVesselBySelection)
                    {
                        if (_selection.width != 0 && _selection.height != 0)
                        {
                            Vessel target  = null;
                            float  longest = 0;
                            //Scan a targetable vessel is avaible.
                            foreach (Vessel vessel in FlightGlobals.Vessels)
                            {
                                if (!vessel.loaded)
                                {
                                    return;
                                }

                                var camera = GetComponent <Camera>();

                                //Calculate distance.
                                var distance = Mathf.Abs(
                                    Vector3.Distance(vessel.GetWorldPos3D(), camera.transform.position));

                                if (target == null)
                                {
                                    longest = distance;
                                    target  = vessel;
                                }
                                else
                                {
                                    if (distance > longest)
                                    {
                                        longest = distance;
                                        target  = vessel;
                                    }
                                }
                            }

                            if (target != null)
                            {
                                Vector3 camPos = Camera.main.WorldToScreenPoint(target.transform.position);
                                camPos.y = InvertY(camPos.y);

                                if (_selection.Contains(camPos))
                                {
                                    //target the vessel.
                                    FlightGlobals.fetch.SetVesselTarget(target);
                                }
                            }
                        }
                    }

                    #endregion
                }
                #endregion



                #region Select Single Kerbal

                bool leftButton  = Input.GetMouseButtonDown(EvaSettings.selectMouseButton) || Input.GetKeyDown(EvaSettings.selectKeyButton);
                bool rightButton = Input.GetMouseButtonDown(EvaSettings.dispatchMouseButton) || Input.GetKeyDown(EvaSettings.dispatchKeyButton);

                if (leftButton == false && rightButton == false)
                {
                    return;
                }

                RaycastHit hitInfo = new RaycastHit();
                bool       hit     = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);

                if (!hit)
                {
                    DisableCursor();
                    return; //nothing to check.
                }

                var evaCollision = hitInfo.transform.gameObject.GetComponent <KerbalEVA>();

                if (leftButton)
                {
                    DeselectAllKerbals();

                    if (evaCollision != null)
                    {
                        EvaContainer eva = EvaController.instance.GetEva(evaCollision.vessel.id);

                        if (!eva.Loaded)
                        {
                            throw new Exception("[EFX] Impossibre!");
                        }

                        SelectEva(eva);
                    }
                    else
                    {
                        DisableCursor();
                    }
                }
                #endregion

                #region Handle Mouse Controls
                if (rightButton) //Middle button.
                {
                    var offset   = (FlightGlobals.ActiveVessel).GetWorldPos3D();
                    var position = (Vector3d)hitInfo.point;

                    foreach (var item in EvaController.instance.collection.ToArray())
                    {
                        if (!item.Loaded)
                        {
                            return;
                        }

                        if (item.Selected)
                        {
                            //Remove current mode.
                            if (item.mode == Mode.Patrol)
                            {
                                item.EndPatrol();
                            }

                            if (EvaSettings.displayDebugLines)
                            {
                                setLine(position, offset);
                            }

                            EvaDebug.DebugLog(string.Format("Target: {0}", position));

                            item.Order(position, offset);
                            item.Selected = false;
                            item.mode     = Mode.Order;

                            _animatedCursor = true;

                            //destroy circle line
                            DestroyLine(item.flightID);
                        }
                    }
                }
                #endregion

                #region Cursor Visible...
                //Show the cursor if more than one kerbal is selected.
                if (selectedKerbals > 0)
                {
                    ShowCursor();
                }
                else
                {
                    DisableCursor();
                }
                #endregion
            }
            catch (Exception exp)
            {
                EvaDebug.DebugWarning("[EFX] EvaOrderController: " + exp.Message);
            }
        }
예제 #21
0
 public void OnDestroy()
 {
     EvaDebug.DebugWarning("EvaOrderController.OnDestroy()");
 }
예제 #22
0
 public void Unload()
 {
     EvaDebug.DebugWarning("EvaContainer.Unload(" + eva.name + ")");
     loaded = false;
 }
예제 #23
0
 public void Start()
 {
     EvaDebug.DebugWarning("EvaLogic.Start()");
     GameEvents.onHideUI.Add(onHideUI);
 }
예제 #24
0
 public void OnDestroy()
 {
     EvaDebug.DebugWarning("EvaLogic.OnDestroy()");
     GameEvents.onHideUI.Remove(onHideUI);
 }