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); }
/// <summary> /// Synchronize and save a value associated with a terminal control. The value will be synchronized everytime it changes. /// </summary> /// <param name="control">GUI control for getting/setting the value.</param> /// <param name="fieldName">The name of a field in the script to get/set the value from/to. If the field has a default value, the DefaultValueAttribute should be used.</param> /// <param name="save">Iff true, save the value to disk.</param> public ValueSync(IMyTerminalValueControl <TValue> control, string fieldName, bool save = true) : base(control.Id, fieldName, save) { control.Getter = GetValue; control.Setter = SetValue; _control = (IMyTerminalControl)control; }
/// <summary> /// Synchronize and save a value associated with a terminal control. The value will be synchronized everytime it changes. /// </summary> /// <param name="control">GUI control for getting/setting the value.</param> /// <param name="getter">Function to get the value from a script.</param> /// <param name="setter">Function to set a value in a script.</param> /// <param name="save">Iff true, save the value to disk.</param> /// <param name="defaultValue">The default value to use. The value in the script will be set to defaultValue by ValueSync.</param> public ValueSync(IMyTerminalValueControl <TValue> control, GetterDelegate getter, SetterDelegate setter, bool save = true, TValue defaultValue = default(TValue)) : base(control.Id, getter, setter, save, defaultValue) { control.Getter = GetValue; control.Setter = SetValue; _control = (IMyTerminalControl)control; }
/// <summary> /// Returns true if it can retrieve the current value without throwing an exception. /// </summary> public static bool CanAccessValue <TValue>(this IMyTerminalValueControl <TValue> terminalValue, IMyTerminalBlock tBlock) { if (terminalValue.Getter != null && terminalValue.Setter != null) { try { terminalValue.Getter(tBlock); return(true); } catch { } } return(false); }
public override void AddControls(List <IMyTerminalControl> controls) { MyTerminalControlSlider <MyShipController> hours = new MyTerminalControlSlider <MyShipController>("WaitForHours", MyStringId.GetOrCompute("Hours"), MyStringId.GetOrCompute("Hours to wait for")), minutes = new MyTerminalControlSlider <MyShipController>("WaitForMinutes", MyStringId.GetOrCompute("Minutes"), MyStringId.GetOrCompute("Minutes to wait for")), seconds = new MyTerminalControlSlider <MyShipController>("WaitForSeconds", MyStringId.GetOrCompute("Seconds"), MyStringId.GetOrCompute("Seconds to wait for")); hours.DefaultValue = 0f; hours.Normalizer = Normalizer; hours.Denormalizer = Denormalizer; hours.Writer = Writer; IMyTerminalValueControl <float> valueControl = hours; valueControl.Getter = block => duration.Hours; valueControl.Setter = (block, value) => { duration = TimeSpan.FromHours((int)value); minutes.UpdateVisual(); seconds.UpdateVisual(); }; controls.Add(hours); minutes.DefaultValue = 0f; minutes.Normalizer = Normalizer; minutes.Denormalizer = Denormalizer; minutes.Writer = Writer; valueControl = minutes; valueControl.Getter = block => duration.Minutes; valueControl.Setter = (block, value) => { duration = TimeSpan.FromMinutes((int)value); hours.UpdateVisual(); seconds.UpdateVisual(); }; controls.Add(minutes); seconds.DefaultValue = 0f; seconds.Normalizer = Normalizer; seconds.Denormalizer = Denormalizer; seconds.Writer = Writer; valueControl = seconds; valueControl.Getter = block => duration.Seconds; valueControl.Setter = (block, value) => { duration = TimeSpan.FromSeconds((int)value); hours.UpdateVisual(); minutes.UpdateVisual(); }; controls.Add(seconds); }
public override void AddControls(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls) { MyTerminalControlSlider <MyShipController> speed = new MyTerminalControlSlider <MyShipController>("Speed", MyStringId.GetOrCompute("Speed"), MyStringId.GetOrCompute(AddDescription)); speed.DefaultValue = ServerSettings.GetSetting <float>(ServerSettings.SettingName.fDefaultSpeed); speed.Normalizer = Normalizer; speed.Denormalizer = Denormalizer; speed.Writer = (block, sb) => { sb.Append(PrettySI.makePretty(m_speed)); sb.Append("m/s"); }; IMyTerminalValueControl <float> valueControler = speed; valueControler.Getter = block => m_speed; valueControler.Setter = (block, value) => m_speed = value; controls.Add(speed); }
public override void AddControls(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls) { MyTerminalControlSlider <MyShipController> radius = new MyTerminalControlSlider <MyShipController>("Radius", MyStringId.GetOrCompute("Radius"), MyStringId.GetOrCompute(AddDescription)); radius.DefaultValue = 100f; radius.Normalizer = Normalizer; radius.Denormalizer = Denormalizer; radius.Writer = (block, sb) => { sb.Append(PrettySI.makePretty(m_radius)); sb.Append('m'); }; IMyTerminalValueControl <float> valueControler = radius; valueControler.Getter = block => m_radius; valueControler.Setter = (block, value) => m_radius = value; controls.Add(radius); }
public override void AddControls(List <Sandbox.ModAPI.Interfaces.Terminal.IMyTerminalControl> controls) { if (!m_addingResponse) { MyTerminalControlSlider <MyShipController> range = new MyTerminalControlSlider <MyShipController>("RangeSlider", MyStringId.GetOrCompute("Range"), MyStringId.GetOrCompute("How close enemy needs to be for autopilot to respond to it. Zero indicates infinite range.")); range.Normalizer = Normalizer; range.Denormalizer = Denormalizer; range.Writer = (block, sb) => { sb.Append(PrettySI.makePretty(m_range)); sb.Append('m'); }; IMyTerminalValueControl <float> valueControler = range; valueControler.Getter = block => m_range; valueControler.Setter = (block, value) => m_range = value; controls.Add(range); MyTerminalControlTextbox <MyShipController> enemyId = new MyTerminalControlTextbox <MyShipController>("EnemyId", MyStringId.GetOrCompute("Enemy Entity ID"), MyStringId.GetOrCompute("If set, only target an enemy with this entity ID")); enemyId.Getter = block => new StringBuilder(m_enemyId.ToString()); enemyId.Setter = (block, value) => { if (!long.TryParse(value.ToString(), out m_enemyId)) { m_enemyId = -1L; } }; controls.Add(enemyId); } if (m_responseListbox == null) { m_responseListbox = new MyTerminalControlListbox <MyShipController>("Responses", MyStringId.GetOrCompute("Responses"), MyStringId.NullOrEmpty); m_responseListbox.ListContent = ListContent; m_responseListbox.ItemSelected = ItemSelected; } controls.Add(m_responseListbox); if (!m_addingResponse) { controls.Add(new MyTerminalControlButton <MyShipController>("AddResponse", MyStringId.GetOrCompute("Add Response"), MyStringId.NullOrEmpty, AddResponse)); controls.Add(new MyTerminalControlButton <MyShipController>("RemoveResponse", MyStringId.GetOrCompute("Remove Response"), MyStringId.NullOrEmpty, RemoveResponse)); controls.Add(new MyTerminalControlButton <MyShipController>("MoveResponseUp", MyStringId.GetOrCompute("Move Response Up"), MyStringId.NullOrEmpty, MoveResponseUp)); controls.Add(new MyTerminalControlButton <MyShipController>("MoveResponseDown", MyStringId.GetOrCompute("Move Response Down"), MyStringId.NullOrEmpty, MoveResponseDown)); } }
public void AddInverseControl(IMyTerminalValueControl <bool> control, TValue flag) { int flagValue = flag.ToInt32(CultureInfo.InvariantCulture); _controls.Add((IMyTerminalControl)control); control.Getter = (block) => { int currentValue = GetValue(block).ToInt32(CultureInfo.InvariantCulture); return((currentValue & flagValue) == 0); }; control.Setter = (block, value) => { int currentValue = GetValue(block).ToInt32(CultureInfo.InvariantCulture); if (value) { currentValue &= ~flagValue; } else { currentValue |= flagValue; } SetValue(block, (TValue)Convert.ChangeType(currentValue, Enum.GetUnderlyingType(typeof(TValue)))); }; }
public override void AddControls(List <IMyTerminalControl> controls) { MyTerminalControlSlider <MyShipController> distance = new MyTerminalControlSlider <MyShipController>("Distance", MyStringId.GetOrCompute("Distance"), MyStringId.GetOrCompute(AddDescription)); distance.DefaultValue = 0; distance.Normalizer = Normalizer; distance.Denormalizer = Denormalizer; distance.Writer = (block, sb) => { if (m_distSetting >= minJumpDistance) { sb.Append(PrettySI.makePretty(m_distSetting)); sb.Append("m"); } else { sb.AppendLine("Disable"); } }; IMyTerminalValueControl <float> valueControler = distance; valueControler.Getter = block => m_distSetting; valueControler.Setter = (block, value) => m_distSetting = value; controls.Add(distance); }
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 static IMyTerminalControlProperty <TValue> CreateProperty <TBlock, TValue>(this IMyTerminalValueControl <TValue> control) where TBlock : IMyTerminalBlock { var property = MyAPIGateway.TerminalControls.CreateProperty <TValue, TBlock>(((IMyTerminalControl)control).Id); property.Getter = control.Getter; property.Setter = control.Setter; property.SupportsMultipleBlocks = false; property.Enabled = ((IMyTerminalControl)control).Enabled; return(property); }