Esempio n. 1
0
        private static void InvokePartAction(BaseField baseField, bool ignoreDelay)
        {
            var field = (baseField as UIPartActionMenuPatcher.WrappedField);

            if (field == null)
            {
                return;
            }

            var v = FlightGlobals.ActiveVessel;

            if (v == null || v.isEVA || RTCore.Instance == null)
            {
                field.Invoke();
                return;
            }

            VesselSatellite vs = null;

            if (RTCore.Instance != null)
            {
                vs = RTCore.Instance.Satellites[v];
            }

            if (vs == null || vs.HasLocalControl)
            {
                field.Invoke();
            }

            else if (FieldWhiteList.Contains(baseField.name))
            {
                field.Invoke();
            }
            else if (vs.FlightComputer != null && vs.FlightComputer.InputAllowed)
            {
                if (ignoreDelay)
                {
                    field.Invoke();
                }
                else
                {
                    // queue command into FC
                    vs.SignalProcessor.FlightComputer.Enqueue(PartActionCommand.Field(baseField, field.NewValue));
                }
            }
            else if (field.host is PartModule && ((PartModule)field.host).part.Modules.OfType <IAntenna>().Any() &&
                     !((PartModule)field.host).part.Modules.OfType <ModuleRTAntennaPassive>().Any() &&
                     RTSettings.Instance.ControlAntennaWithoutConnection)
            {
                field.Invoke();
            }
            else
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#RT_ModuleUI_SPU_Msg"), 4.0f, ScreenMessageStyle.UPPER_LEFT));//"No connection to send command on."
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load and creates a command after saving a command. Returns null if no object
        /// has been loaded.
        /// </summary>
        /// <param name="n">Node with the command infos</param>
        /// <param name="fc">Current flightcomputer</param>
        public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
        {
            ICommand command = null;

            // switch the different commands
            switch (n.name)
            {
            case "AttitudeCommand":       { command = new AttitudeCommand(); break; }

            case "ActionGroupCommand":    { command = new ActionGroupCommand(); break; }

            case "BurnCommand":           { command = new BurnCommand(); break; }

            case "ManeuverCommand":       { command = new ManeuverCommand(); break; }

            case "CancelCommand":         { command = new CancelCommand(); break; }

            case "TargetCommand":         { command = new TargetCommand(); break; }

            case "EventCommand":          { command = new EventCommand(); break; }

            case "DriveCommand":          { command = new DriveCommand(); break; }

            case "ExternalAPICommand":    { command = new ExternalAPICommand(); break; }

            case "PartActionCommand":     { command = new PartActionCommand(); break; }

            case "StockAutopilotCommand": { command = new StockAutopilotCommand(); break; }

            case "HibernationCommand":    { command = new HibernationCommand(); break; }

            case "AxisGroupCommand":      { command = new AxisGroupCommand(); break; }

            case "PIDCommand":            { command = new PIDCommand(); break; }

            case "FlightControlCommand":  { command = new FlightControlCommand(); break; }
            }

            if (command != null)
            {
                ConfigNode.LoadObjectFromConfig(command, n);
                // additional loadings
                var result = command.Load(n, fc);
                RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result);
                // delete command if we can't load the command correctlys
                if (result == false)
                {
                    command = null;
                }
            }

            return(command);
        }
        /// <summary>
        /// Load and creates a command after saving a command. Returns null if no object
        /// has been loaded.
        /// </summary>
        /// <param name="n">Node with the command infos</param>
        /// <param name="fc">Current flightcomputer</param>
        public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
        {
            ICommand command = null;

            // switch the different commands
            switch (n.name)
            {
                case "AttitudeCommand":     { command = new AttitudeCommand(); break; }
                case "ActionGroupCommand":  { command = new ActionGroupCommand(); break; }
                case "BurnCommand":         { command = new BurnCommand(); break; }
                case "ManeuverCommand":     { command = new ManeuverCommand(); break; }
                case "CancelCommand":       { command = new CancelCommand(); break; }
                case "TargetCommand":       { command = new TargetCommand(); break; }
                case "EventCommand":        { command = new EventCommand(); break; }
                case "DriveCommand":        { command = new DriveCommand(); break; }
                case "ExternalAPICommand":  { command = new ExternalAPICommand(); break; }
                case "PartActionCommand":   { command = new PartActionCommand(); break; }
            }

            if (command != null)
            {
                ConfigNode.LoadObjectFromConfig(command, n);
                // additional loadings
                var result = command.Load(n, fc);
                RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result);
                // delete command if we can't load the command correctlys
                if (result == false)
                    command = null;
            }

            return command;
        }