コード例 #1
0
        /// <summary>
        ///     Set a threshold on an air alarm.
        /// </summary>
        /// <param name="threshold">New threshold data.</param>
        public void SetThreshold(EntityUid uid, AtmosAlarmThreshold threshold, AtmosMonitorThresholdType type, Gas?gas = null, AirAlarmComponent?controller = null)
        {
            if (!Resolve(uid, ref controller))
            {
                return;
            }

            _atmosMonitorSystem.SetThreshold(uid, type, threshold, gas);

            _uiSystem.TrySendUiMessage(uid, SharedAirAlarmInterfaceKey.Key, new AirAlarmUpdateAlarmThresholdMessage(type, threshold, gas));
        }
コード例 #2
0
        // i have played myself by making threshold values nullable to
        // indicate validity/disabled status, with several layers of side effect
        // dependent on the other three values when you change one :HECK:
        public ThresholdControl(string name, AtmosAlarmThreshold threshold, AtmosMonitorThresholdType type, Gas?gas = null, float modifier = 1)
        {
            RobustXamlLoader.Load(this);

            _threshold = threshold;
            _type      = type;
            _gas       = gas;

            _name.Title = name;

            // i miss rust macros

            _upperBoundControl = new ThresholdBoundControl("upper-bound", _threshold.UpperBound, modifier);
            _upperBoundControl.OnBoundChanged += value =>
            {
                // a lot of threshold logic is baked into the properties,
                // so setting this just returns if a change occurred or not
                _threshold.TrySetPrimaryBound(AtmosMonitorThresholdBound.Upper, value);
                return(_threshold.UpperBound);
            };
            _upperBoundControl.OnBoundEnabled += () =>
            {
                var value = 0f;

                if (_threshold.LowerWarningBound != null)
                {
                    value = (float)_threshold.LowerWarningBound + 0.1f;
                }
                else if (_threshold.LowerBound != null)
                {
                    value = (float)_threshold.LowerBound + 0.1f;
                }

                return(value);
            };
            _upperBoundControl.OnValidBoundChanged += () =>
            {
                ThresholdDataChanged !.Invoke(_type, _threshold, _gas);
            };
            _dangerBounds.AddChild(_upperBoundControl);

            _lowerBoundControl = new ThresholdBoundControl("lower-bound", _threshold.LowerBound, modifier);
            _lowerBoundControl.OnBoundChanged += value =>
            {
                _threshold.TrySetPrimaryBound(AtmosMonitorThresholdBound.Lower, value);
                return(_threshold.LowerBound);
            };
            _lowerBoundControl.OnBoundEnabled += () =>
            {
                var value = 0f;

                if (_threshold.UpperWarningBound != null)
                {
                    value = (float)_threshold.UpperWarningBound - 0.1f;
                }
                else if (_threshold.UpperBound != null)
                {
                    value = (float)_threshold.UpperBound - 0.1f;
                }

                return(value);
            };
            _lowerBoundControl.OnValidBoundChanged += () =>
                                                      ThresholdDataChanged !.Invoke(_type, _threshold, _gas);
            _dangerBounds.AddChild(_lowerBoundControl);

            _upperWarningBoundControl = new ThresholdBoundControl("upper-warning-bound", _threshold.UpperWarningBound, modifier);
            _upperWarningBoundControl.OnBoundChanged += value =>
            {
                _threshold.TrySetWarningBound(AtmosMonitorThresholdBound.Upper, value);
                return(_threshold.UpperWarningBound);
            };
            _upperWarningBoundControl.OnBoundEnabled += () =>
            {
                var value = 0f;

                if (_threshold.LowerWarningBound != null)
                {
                    value = (float)_threshold.LowerWarningBound + 0.1f;
                }
                else if (_threshold.LowerBound != null)
                {
                    value = (float)_threshold.LowerBound + 0.1f;
                }

                return(value);
            };
            _upperWarningBoundControl.OnValidBoundChanged += () =>
                                                             ThresholdDataChanged !.Invoke(_type, _threshold, _gas);
            _warningBounds.AddChild(_upperWarningBoundControl);

            _lowerWarningBoundControl = new ThresholdBoundControl("lower-warning-bound", _threshold.LowerWarningBound, modifier);
            _lowerWarningBoundControl.OnBoundChanged += value =>
            {
                _threshold.TrySetWarningBound(AtmosMonitorThresholdBound.Lower, value);
                return(_threshold.LowerWarningBound);
            };
            _lowerWarningBoundControl.OnBoundEnabled += () =>
            {
                var value = 0f;

                if (_threshold.UpperWarningBound != null)
                {
                    value = (float)_threshold.UpperWarningBound - 0.1f;
                }
                else if (_threshold.UpperBound != null)
                {
                    value = (float)_threshold.UpperBound - 0.1f;
                }

                return(value);
            };
            _lowerWarningBoundControl.OnValidBoundChanged += () =>
                                                             ThresholdDataChanged !.Invoke(_type, _threshold, _gas);

            _warningBounds.AddChild(_lowerWarningBoundControl);

            _ignore.OnToggled += args =>
            {
                _threshold.Ignore = args.Pressed;
                ThresholdDataChanged !.Invoke(_type, _threshold, _gas);
            };
            _ignore.Pressed = _threshold.Ignore;
        }
コード例 #3
0
 private void OnThresholdChanged(AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas?gas = null)
 {
     SendMessage(new AirAlarmUpdateAlarmThresholdMessage(type, threshold, gas));
 }