Beispiel #1
0
        protected override void AddValueControl(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls)
        {
            IMyTerminalControlColor colour = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, Sandbox.ModAPI.Ingame.IMyShipController>("ColourValue");

            colour.Title   = MyStringId.GetOrCompute("Value");
            colour.Tooltip = MyStringId.GetOrCompute("Value to set propety to");
            colour.Getter  = (block) => m_value;
            colour.Setter  = (block, value) => {
                m_value    = value;
                m_hasValue = true;
            };
            controls.Add(colour);

            MyTerminalControlSlider <MyShipController> alpha = new MyTerminalControlSlider <MyShipController>("AlphaChannel", MyStringId.GetOrCompute("A"), MyStringId.NullOrEmpty);

            alpha.DefaultValue = 255f;
            alpha.Normalizer   = Normalizer;
            alpha.Denormalizer = Denormalizer;
            alpha.Writer       = (block, sb) => sb.Append(m_value.A);
            IMyTerminalValueControl <float> valueControl = alpha;

            valueControl.Getter = block => m_value.A;
            valueControl.Setter = (block, value) => {
                m_value.A  = (byte)value;
                m_hasValue = true;
                colour.UpdateVisual();
            };
            controls.Add(alpha);
        }
Beispiel #2
0
            public StaticVariables()
            {
                Logger.DebugLog("entered", Logger.severity.TRACE);
                MyAPIGateway.Session.DamageSystem.RegisterAfterDamageHandler((int)MyDamageSystemPriority.Low, AfterDamageHandler);

                TerminalControlHelper.EnsureTerminalControlCreated <MySpaceProjector>();

                TermControls.Add(new MyTerminalControlSeparator <MySpaceProjector>());

                AddCheckbox("HoloDisplay", "Holographic Display", "Holographically display this ship and nearby detected ships", Option.OnOff);
                AddCheckbox("HD_This_Ship", "This Ship", "Holographically display this ship", Option.ThisShip);
                AddCheckbox("HD_Owner", "Owned Ships", "Holographically display ships owned by this block's owner", Option.Owner);
                AddCheckbox("HD_Faction", "Faction Ships", "Holographically display faction owned ships", Option.Faction);
                AddCheckbox("HD_Neutral", "Neutral Ships", "Holographically display neutral ships", Option.Neutral);
                AddCheckbox("HD_Enemy", "Enemy Ships", "Holographically display enemy ships", Option.Enemy);

                MyTerminalControlSlider <MySpaceProjector> slider = new MyTerminalControlSlider <MySpaceProjector>("HD_RangeDetection", MyStringId.GetOrCompute("Detection Range"), MyStringId.GetOrCompute("Maximum distance of detected entity"));
                ValueSync <float, Projector> tvsRange             = new ValueSync <float, Projector>(slider, (proj) => proj.m_rangeDetection, (proj, value) => proj.m_rangeDetection = value);

                slider.DefaultValue = DefaultRangeDetection;
                slider.Normalizer   = (block, value) => Normalizer(MinRangeDetection, MaxRangeDetection, block, value);
                slider.Denormalizer = (block, value) => Denormalizer(MinRangeDetection, MaxRangeDetection, block, value);
                slider.Writer       = (block, sb) => WriterMetres(tvsRange.GetValue(block), sb);
                TermControls.Add(slider);

                slider = new MyTerminalControlSlider <MySpaceProjector>("HD_RadiusHolo", MyStringId.GetOrCompute("Hologram Radius"), MyStringId.GetOrCompute("Maximum radius of hologram"));
                ValueSync <float, Projector> tvsRadius = new ValueSync <float, Projector>(slider, (proj) => proj.m_radiusHolo, (proj, value) => proj.m_radiusHolo = value);

                slider.DefaultValue = DefaultRadiusHolo;
                slider.Normalizer   = (block, value) => Normalizer(MinRadiusHolo, MaxRadiusHolo, block, value);
                slider.Denormalizer = (block, value) => Denormalizer(MinRadiusHolo, MaxRadiusHolo, block, value);
                slider.Writer       = (block, sb) => WriterMetres(tvsRadius.GetValue(block), sb);
                TermControls.Add(slider);

                slider = new MyTerminalControlSlider <MySpaceProjector>("HD_EntitySizeScale", MyStringId.GetOrCompute("Entity Size Scale"), MyStringId.GetOrCompute("Larger value causes entities to appear larger"));
                ValueSync <float, Projector> tvsScale = new ValueSync <float, Projector>(slider, (proj) => proj.m_sizeDistScale, (proj, value) => proj.m_sizeDistScale = value);

                slider.DefaultValue = DefaultSizeScale;
                slider.Normalizer   = (block, value) => Normalizer(MinSizeScale, MaxSizeScale, block, value);
                slider.Denormalizer = (block, value) => Denormalizer(MinSizeScale, MaxSizeScale, block, value);
                slider.Writer       = (block, sb) => sb.Append(tvsScale.GetValue(block));
                TermControls.Add(slider);

                TermControls.Add(new MyTerminalControlSeparator <MySpaceProjector>());

                MyTerminalControlCheckbox <MySpaceProjector> control = new MyTerminalControlCheckbox <MySpaceProjector>("HD_MouseControls", MyStringId.GetOrCompute("Mouse Controls"),
                                                                                                                        MyStringId.GetOrCompute("Allow manipulation of hologram with mouse. User-specific setting."));
                IMyTerminalValueControl <bool> valueControlBool = control;

                valueControlBool.Getter = block => MouseControls;
                valueControlBool.Setter = (block, value) => MouseControls = value;
                TermControls.Add(control);

                control                 = new MyTerminalControlCheckbox <MySpaceProjector>("HD_ShowBoundary", MyStringId.GetOrCompute("Show Boundary"), MyStringId.GetOrCompute("Show the boundaries of the hologram. User-specific setting."));
                valueControlBool        = control;
                valueControlBool.Getter = block => ShowBoundary;
                valueControlBool.Setter = (block, value) => ShowBoundary = value;
                TermControls.Add(control);

                control        = new MyTerminalControlCheckbox <MySpaceProjector>("HD_ShowOffset", MyStringId.GetOrCompute("Show Offset Controls"), MyStringId.GetOrCompute("Display controls that can be used to adjust the position of the hologram. User-specific setting."));
                control.Getter = block => ShowOffset;
                control.Setter = (block, value) => {
                    ShowOffset = value;
                    block.RebuildControls();
                };
                TermControls.Add(control);

                AddOffsetSlider("HD_OffsetX", "Right/Left Offset", "+ve moves hologram to the right, -ve moves hologram to the left", 0);
                AddOffsetSlider("HD_OffsetY", "Up/Down Offset", "+ve moves hologram up, -ve moves hologram down", 1);
                AddOffsetSlider("HD_OffsetZ", "Back/Fore Offset", "+ve moves hologram back, -ve moves hologram forward", 2);

                TermControls_Offset.Add(new MyTerminalControlSeparator <MySpaceProjector>());

                AddCheckbox("HD_IntegrityColour", "Colour by Integrity", "Colour blocks according to their integrities", Option.IntegrityColours);

                IMyTerminalControlColor colour = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyProjector>("HD_FullIntegriyColour");

                colour.Title   = MyStringId.GetOrCompute("Whole");
                colour.Tooltip = MyStringId.GetOrCompute("Colour when block has full integrity. User-specific setting.");
                colour.Getter  = (block) => IntegrityFull;
                colour.Setter  = (block, value) => IntegrityFull = value;
                TermControls_Colours.Add(colour);

                colour         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyProjector>("HD_CriticalIntegriyColour");
                colour.Title   = MyStringId.GetOrCompute("Func.");
                colour.Tooltip = MyStringId.GetOrCompute("Colour when block is just above critical integrity. User-specific setting.");
                colour.Getter  = (block) => IntegrityFunctional;
                colour.Setter  = (block, value) => IntegrityFunctional = value;
                TermControls_Colours.Add(colour);

                colour         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyProjector>("HD_CriticalIntegriyColour");
                colour.Title   = MyStringId.GetOrCompute("Broken");
                colour.Tooltip = MyStringId.GetOrCompute("Colour when block is just below critical integrity. User-specific setting.");
                colour.Getter  = (block) => IntegrityDamaged;
                colour.Setter  = (block, value) => IntegrityDamaged = value;
                TermControls_Colours.Add(colour);

                colour         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyProjector>("HD_ZeroIntegriyColour");
                colour.Title   = MyStringId.GetOrCompute("Razed");
                colour.Tooltip = MyStringId.GetOrCompute("Colour when block has zero integrity. User-specific setting.");
                colour.Getter  = (block) => IntegrityZero;
                colour.Setter  = (block, value) => IntegrityZero = value;
                TermControls_Colours.Add(colour);

                new ValueSync <long, Projector>("CentreEntity",
                                                (script) => script.m_centreEntityId,
                                                (script, value) => {
                    script.m_centreEntityId = value;
                    script.m_centreEntityId_AfterValueChanged();
                });
            }
        private void CreateTerminalControls()
        {
            // Just to make sure we're not subscribing twice without using locks

            MyAPIGateway.TerminalControls.CustomControlGetter -= CustomControlGetter;
            MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlGetter;

            IMyTerminalControlCheckbox checkbox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyThrust>("LockFlameColors");

            checkbox.Title  = MyStringId.GetOrCompute("Lock Flame Colors");
            checkbox.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(false);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                return(logic != null ? logic.m_flameColorsLocked : false);
            };

            checkbox.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_flameColorsLocked = value;

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };

            checkbox.SupportsMultipleBlocks = true;

            m_customControls.Add(checkbox);

            // FlameIdleColor

            IMyTerminalControlColor color = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyThrust>("FlameIdleColor");

            color.Title = MyStringId.GetOrCompute("Idle");

            color.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return((Vector4)Color.Black);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? logic.m_flameIdleColor : (Vector4)Color.Black);
            };

            color.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    Vector3 v = value.ToVector3();
                    logic.m_flameIdleColor = new Vector4(v.X, v.Y, v.Z, logic.m_flameIdleColor.W);

                    if (logic.m_renderMode == RenderMode.Linked)
                    {
                        logic.m_flameFullColor = logic.m_flameIdleColor;
                    }

                    foreach (var control in m_customControls)
                    {
                        if (control.Id == "FlameFullColor")
                        {
                            control.UpdateVisual();
                        }
                    }

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };
            m_customControls.Add(color);

            IMyTerminalControlSlider alpha = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameIdleColorAlpha");

            alpha.Title = MyStringId.GetOrCompute("Alpha");
            alpha.SetLimits(0f, 1f);
            alpha.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(1f);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? logic.m_flameIdleColor.W : 1f);
            };
            alpha.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_flameIdleColor.W = value;

                    if (logic.m_renderMode == RenderMode.Linked)
                    {
                        logic.m_flameFullColor.W = logic.m_flameIdleColor.W;
                    }

                    foreach (var control in m_customControls)
                    {
                        if (control.Id == "FlameFullColorAlpha" || control.Id == "FlameFullColor" || control.Id == "FlameIdleColor")
                        {
                            control.UpdateVisual();
                        }
                    }

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };
            m_customControls.Add(alpha);

            var propertyIC = MyAPIGateway.TerminalControls.CreateProperty <Color, IMyThrust>("FlameIdleColorOverride");

            propertyIC.SupportsMultipleBlocks = false;
            propertyIC.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(Vector4.Zero);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? (Color)logic.FlameIdleColor : Color.Transparent);
            };

            propertyIC.Setter = (block, value) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_flameIdleColor = value.ToVector4();
                    // logic.m_flameIdleColor.W = 0.75f;

                    if (logic.m_renderMode == RenderMode.Linked)
                    {
                        logic.FlameFullColor = logic.FlameIdleColor;
                    }
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyIC);

            // FlameFullColor

            color = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyThrust>("FlameFullColor");

            color.Title   = MyStringId.GetOrCompute("Full");
            color.Enabled = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(false);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? (logic.m_renderMode != RenderMode.Linked) : false);
            };

            color.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return((Vector4)Color.Black);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? logic.m_flameFullColor : (Vector4)Color.Black);
            };

            color.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    Vector3 v = value.ToVector3();
                    logic.m_flameFullColor = new Vector4(v.X, v.Y, v.Z, logic.m_flameFullColor.W);

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };
            m_customControls.Add(color);

            alpha       = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameFullColorAlpha");
            alpha.Title = MyStringId.GetOrCompute("Alpha");
            alpha.SetLimits(0f, 1f);
            alpha.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(1f);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? logic.m_flameFullColor.W : 1f);
            };
            alpha.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_flameFullColor.W = value;

                    if (logic.m_renderMode == RenderMode.Linked)
                    {
                        logic.m_flameIdleColor.W = logic.m_flameFullColor.W;
                    }

                    foreach (var control in m_customControls)
                    {
                        if (control.Id == "FlameIdleColorAlpha" || control.Id == "FlameFullColor" || control.Id == "FlameIdleColor")
                        {
                            control.UpdateVisual();
                        }
                    }

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };
            m_customControls.Add(alpha);

            var propertyFC = MyAPIGateway.TerminalControls.CreateProperty <Color, IMyThrust>("FlameFullColorOverride");

            propertyFC.SupportsMultipleBlocks = false;
            propertyFC.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(Vector4.Zero);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? (Color)logic.FlameFullColor : Color.Transparent);
            };

            propertyFC.Setter = (block, value) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null && logic.m_renderMode != RenderMode.Linked)
                {
                    logic.m_flameFullColor = value.ToVector4();
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyFC);

            IMyTerminalControlSlider renderMode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameRenderMode");

            renderMode.Title = MyStringId.GetOrCompute("Flame Render Mode");
            renderMode.SetLimits(0, 2);
            renderMode.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return((int)m_renderMode);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                return(logic != null ? (int)logic.m_renderMode : 0);
            };

            renderMode.Setter = (block, value) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_renderMode = (RenderMode)value;

                    if (logic.m_renderMode == RenderMode.Linked)
                    {
                        logic.m_flameFullColor = logic.m_flameIdleColor;
                    }

                    logic.UpdateFlames();
                    logic.UpdateCustomData();

                    foreach (var control in m_customControls)
                    {
                        if (control.Id == "FlameFullColor")
                        {
                            control.UpdateVisual();
                        }
                    }
                }
            };

            renderMode.Writer = (block, sb) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    sb.Append(logic.m_renderMode.ToString());
                }
            };

            renderMode.SupportsMultipleBlocks = true;

            m_customControls.Add(renderMode);

            var hideFlamesCheckbox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyThrust>("HideThrustFlames");

            hideFlamesCheckbox.Title  = MyStringId.GetOrCompute("Hide Thrust Flames");
            hideFlamesCheckbox.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(false);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                return(logic != null ? logic.m_hideFlames : false);
            };

            hideFlamesCheckbox.Setter = (block, value) =>
            {
                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.m_hideFlames = value;

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };

            hideFlamesCheckbox.SupportsMultipleBlocks = true;

            m_customControls.Add(hideFlamesCheckbox);

            var propertyHF = MyAPIGateway.TerminalControls.CreateProperty <bool, IMyThrust>("HideThrustFlames");

            propertyHF.SupportsMultipleBlocks = false;
            propertyHF.Getter = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return(false);
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();
                return(logic != null ? logic.HideThrustFlames : false);
            };

            propertyHF.Setter = (block, value) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    logic.HideThrustFlames = value;
                }
            };

            MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyHF);

            var resetButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyThrust>("ResetDefaultColors");

            resetButton.Title = MyStringId.GetOrCompute("Reset Default Colors");

            resetButton.Action = (block) =>
            {
                if (block == null || block.GameLogic == null)
                {
                    return;
                }

                var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>();

                if (logic != null)
                {
                    var blockDefinition = block.SlimBlock.BlockDefinition as MyThrustDefinition;

                    logic.m_flameIdleColor = blockDefinition.FlameIdleColor;
                    logic.m_flameFullColor = blockDefinition.FlameFullColor;

                    if (logic.m_flameFullColor != logic.m_flameIdleColor)
                    {
                        logic.m_renderMode = RenderMode.Blended;
                    }

                    foreach (var control in m_customControls)
                    {
                        control.UpdateVisual();
                    }

                    logic.UpdateFlames();
                    logic.UpdateCustomData();
                }
            };

            resetButton.SupportsMultipleBlocks = true;

            m_customControls.Add(resetButton);
        }