Example #1
0
        private static void AddPropertyAndSyncEntityId(string id, out ValueSync <long, AutopilotTerminal> sync, string fieldName)
        {
            MyTerminalControlProperty <MyShipController, string> property = new MyTerminalControlProperty <MyShipController, string>(id);

            FieldInfo field = typeof(AutopilotTerminal).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            sync = new ValueSync <long, AutopilotTerminal>(id, GenerateGetter <long>(field), GenerateSetter <long>(field), false);
            ValueSync <long, AutopilotTerminal> syncRef = sync;

            property.Getter = (block) => {
                AutopilotTerminal autopilot;
                if (!Registrar.TryGetValue(block, out autopilot))
                {
                    if (!Globals.WorldClosed)
                    {
                        Logger.AlwaysLog("failed lookup of block: " + block.getBestName(), Logger.severity.WARNING);
                    }
                    return(default(string));
                }

                long      entityId = syncRef.GetValue(autopilot);
                IMyEntity entity;
                if (!MyAPIGateway.Entities.TryGetEntityById(entityId, out entity))
                {
                    Logger.DebugLog("Failed to get entity for " + entityId, Logger.severity.WARNING);
                    return("Unknown Entity");
                }
                return(entity.GetNameForDisplay(autopilot.m_block.OwnerId));
            };

            AddControl(property, false);
        }
Example #2
0
        private static void AddPropertyAndSync(string id, out StringBuilderSync <AutopilotTerminal> sync, string fieldName)
        {
            MyTerminalControlProperty <MyShipController, StringBuilder> property = new MyTerminalControlProperty <MyShipController, StringBuilder>(id);

            FieldInfo field = typeof(AutopilotTerminal).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            sync = new StringBuilderSync <AutopilotTerminal>(id, GenerateGetter <StringBuilder>(field), GenerateSetter <StringBuilder>(field), false);
            StringBuilderSync <AutopilotTerminal> syncRef = sync;

            property.Getter = syncRef.GetValue;

            AddControl(property, false);
        }
Example #3
0
        private static void AddPropertyAndSync <TSync, TYield>(string id, out ValueSync <TSync, AutopilotTerminal> sync, string fieldName)
            where TSync : TYield
        {
            MyTerminalControlProperty <MyShipController, TYield> property = new MyTerminalControlProperty <MyShipController, TYield>(id);

            FieldInfo field = typeof(AutopilotTerminal).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            sync = new ValueSync <TSync, AutopilotTerminal>(id, GenerateGetter <TSync>(field), GenerateSetter <TSync>(field), false);
            ValueSync <TSync, AutopilotTerminal> syncRef = sync;

            property.Getter = (block) => syncRef.GetValue(block);

            AddControl(property, false);
        }
Example #4
0
        private static void AddPropertyAndSync(AutopilotFlags flag)
        {
            MyTerminalControlProperty <MyShipController, bool> property = new MyTerminalControlProperty <MyShipController, bool>("ArmsAp_" + flag);

            property.Getter = (block) => {
                AutopilotTerminal autopilot;
                if (!Registrar.TryGetValue(block, out autopilot))
                {
                    if (!Globals.WorldClosed)
                    {
                        Logger.AlwaysLog("failed lookup of block: " + block.getBestName(), Logger.severity.WARNING);
                    }
                    return(default(bool));
                }
                return((autopilot.value_autopilotFlags & flag) != 0);
            };

            AddControl(property, false);
        }
Example #5
0
            public StaticVariables()
            {
                Logger.DebugLog("entered", Logger.severity.TRACE);
                TerminalControlHelper.EnsureTerminalControlCreated <MyCockpit>();
                TerminalControlHelper.EnsureTerminalControlCreated <MyRemoteControl>();

                AddControl(new MyTerminalControlSeparator <MyShipController>()
                {
                    Enabled = ShipAutopilot.IsAutopilotBlock, Visible = ShipAutopilot.IsAutopilotBlock
                });

                autopilotControl = new MyTerminalControlCheckbox <MyShipController>("ArmsAp_OnOff", MyStringId.GetOrCompute("ARMS Autopilot"), MyStringId.GetOrCompute("Enable ARMS Autopilot"));
                new ValueSync <bool, AutopilotTerminal>(autopilotControl, "value_autopilotControl");
                AddControl(autopilotControl);
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_OnOff", new StringBuilder("ARMS Autopilot On/Off"), @"Textures\GUI\Icons\Actions\Toggle.dds")
                {
                    Action = ToggleAutopilotControl
                });
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_On", new StringBuilder("ARMS Autopilot On"), @"Textures\GUI\Icons\Actions\SwitchOn.dds")
                {
                    Action = block => SetAutopilotControl(block, true)
                });
                AddAction(new MyTerminalAction <MyShipController>("ArmsAp_Off", new StringBuilder("ARMS Autopilot Off"), @"Textures\GUI\Icons\Actions\SwitchOff.dds")
                {
                    Action = block => SetAutopilotControl(block, false)
                });

                autopilotCommands = new MyTerminalControlTextbox <MyShipController>("ArmsAp_Commands", MyStringId.GetOrCompute("Autopilot Commands"), MyStringId.NullOrEmpty);
                new StringBuilderSync <AutopilotTerminal>(autopilotCommands, (autopilot) => autopilot.value_autopilotCommands, (autopilot, value) => {
                    autopilot.value_autopilotCommands = value;
                    AutopilotCommands.GetOrCreate(autopilot.m_block)?.OnCommandsChanged();
                });
                AddControl(autopilotCommands);

                MyTerminalControlButton <MyShipController> gooeyProgram = new MyTerminalControlButton <MyShipController>("ArmsAp_GuiProgram", MyStringId.GetOrCompute("Program Autopilot"), MyStringId.GetOrCompute("Interactive programming for autopilot"), GooeyProgram);

                gooeyProgram.Enabled = ShipAutopilot.IsAutopilotBlock;
                AddControl(gooeyProgram);

                AddPropertyAndSync <ShipAutopilot.State, Enum>("ArmsAp_Status", out autopilotStatus, "value_autopilotStatus");

                FieldInfo value_autopilotFlags = typeof(AutopilotTerminal).GetField("value_autopilotFlags", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                autopilotFlags = new ValueSync <AutopilotFlags, AutopilotTerminal>("ArmsAp_AutopilotFlags", GenerateGetter <AutopilotFlags>(value_autopilotFlags), GenerateSetter <AutopilotFlags>(value_autopilotFlags), false);
                foreach (AutopilotFlags flag in Enum.GetValues(typeof(AutopilotFlags)))
                {
                    if (flag != 0)
                    {
                        AddPropertyAndSync(flag);
                    }
                }

                AddPropertyAndSync <Pathfinder.State, Enum>("ArmsAp_PathStatus", out pathfinderState, "value_pathfinderState");
                AddPropertyAndSync <GridFinder.ReasonCannotTarget, Enum>("ArmsAp_ReasonCannotTarget", out reasonCannotTarget, "value_reasonCannotTarget");
                AddPropertyAndSync <InfoString.StringId, Enum>("ArmsAp_Complaint", out complaint, "value_complaint");
                AddPropertyAndSync <InfoString.StringId_Jump, Enum>("ArmsAp_JumpComplaint", out jumpComplaint, "value_jumpComplaint");
                AddPropertyAndSync("ArmsAp_WaitUntil", out waitUntil, "value_waitUntil");
                AddPropertyAndSyncEntityId("ArmsAp_BlockedBy", out blockedBy, "value_blockedBy");

                FieldInfo value_distance = typeof(AutopilotTerminal).GetField("value_distance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                distance = new ValueSync <long, AutopilotTerminal>("ArmsAp_Distance", GenerateGetter <long>(value_distance), GenerateSetter <long>(value_distance), false);
                MyTerminalControlProperty <MyShipController, float> linearDistance = new MyTerminalControlProperty <MyShipController, float>("ArmsAp_LinearDistance")
                {
                    Getter = GetLinearDistance
                };

                AddControl(linearDistance, false);
                MyTerminalControlProperty <MyShipController, float> angularDistance = new MyTerminalControlProperty <MyShipController, float>("ArmsAp_AngularDistance")
                {
                    Getter = GetAngularDistance
                };

                AddControl(angularDistance, false);

                AddPropertyAndSyncEntityId("ArmsAp_EnemyFinderBestTarget", out enemyFinderBestTarget, "value_enemyFinderBestTarget");
                AddPropertyAndSync("ArmsAp_WelderUnfinishedBlocks", out welderUnfinishedBlocks, "value_welderUnfinishedBlocks");
                AddPropertyAndSync("ArmsAp_NavigatorMover", out prevNavMover, "value_prevNavMover");
                AddPropertyAndSync("ArmsAp_NavigatorRotator", out prevNavRotator, "value_prevNavRotator");
                AddPropertyAndSync("ArmsAp_NavigatorMoverInfo", out prevNavMoverInfo, "value_prevNavMoverInfo");
                AddPropertyAndSync("ArmsAp_NavigatorRotatorInfo", out prevNavRotatorInfo, "value_prevNavRotatorInfo");
            }