/// <summary>
        /// React on inner textbox value changed.
        /// </summary>
        private void _TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            // If value changed from UI - set new value of Text property.
            if (_pauseTextChangeEventHandler)
            {
                return;
            }

            object obj = null;

            try
            {
                if (_typeConverter == null)
                {
                    obj = double.Parse(_TextBox.Text);
                }
                else
                {
                    obj = _typeConverter.ConvertFromString(_TextBox.Text);
                }

                if (_valueUnits != _displayUnits)
                {
                    obj = UnitConvertor.Convert((double)obj, _displayUnits, _valueUnits);
                }

                if ((double)this.Value != (double)obj)
                {
                    this.Value = (double)obj;
                }
            }
            catch
            { }
        }
        /// <summary>
        /// Set Text property to textbox using correct region format.
        /// </summary>
        private void _SetTextToInnerTextBox()
        {
            if (!_inited || this.Value == null)
            {
                if (_inited)
                {
                    // Clear value.
                    _TextBox.Text = "";
                }

                return;
            }

            object obj = this.Value;

            if (_valueUnits != _displayUnits)
            {
                obj = UnitConvertor.Convert((double)obj, _valueUnits, _displayUnits);
            }

            _TextBox.Text = obj.ToString();

            if (!_needAfterInit)
            {
                _needAfterInit = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add bindable property value
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="tipProperty">Property</param>
        /// <param name="source">Source object</param>
        private static void _AddBindableProperty(InlineCollection inlines, TipProperty tipProperty, object source)
        {
            try
            {
                PropertyPath propertyPath = new PropertyPath(tipProperty.PrefixPath + tipProperty.Name);

                Binding binding = new Binding();
                binding.Path   = propertyPath;
                binding.Source = source;

                FrameworkElement fe = new FrameworkElement();
                BindingOperations.SetBinding(fe, FrameworkElement.DataContextProperty, binding);

                object value = fe.DataContext;
                if (value != null)
                {
                    string valueStr;

                    if (value is double && tipProperty.ValueUnits.HasValue && tipProperty.DisplayUnits.HasValue)
                    {
                        Unit valueUnits   = tipProperty.ValueUnits.Value;
                        Unit displayUnits = tipProperty.DisplayUnits.Value;
                        if (valueUnits != displayUnits)
                        {
                            value = UnitConvertor.Convert((double)value, valueUnits, displayUnits);
                        }

                        valueStr = UnitFormatter.Format((double)value, displayUnits);
                    }
                    else
                    {
                        // Special case for planned date
                        if (tipProperty.Name.Equals(Order.PropertyNamePlannedDate))
                        {
                            DateTime dateTime = (DateTime)value;
                            valueStr = dateTime.ToShortDateString();
                        }
                        else if (tipProperty.Name.Equals(Stop.PropertyNameStopType))
                        {
                            valueStr = _GetStopTypeStr((StopType)value, (Stop)source);
                        }
                        else
                        {
                            valueStr = value.ToString();
                        }
                    }

                    if (valueStr.Length > 0)
                    {
                        _AddLine(tipProperty.Title, valueStr, inlines, false);
                    }
                }

                BindingOperations.ClearBinding(fe, FrameworkElement.DataContextProperty);
            }
            catch (Exception ex)
            {
                Logger.Info(ex);
            }
        }
Ejemplo n.º 4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        protected override void DoValidate(double objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            Type         type     = currentTarget.GetType();
            PropertyInfo property = type.GetProperty(key);

            UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

            Unit displayUnits = (RegionInfo.CurrentRegion.IsMetric)? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
            Unit valueUnits   = unitAttribute.ValueUnits;

            if ((objectToValidate < _minValue) || (_maxValue < objectToValidate))
            {
                string format = this.MessageTemplate;

                double maxValue = _maxValue;
                if (valueUnits != displayUnits)
                {
                    maxValue = UnitConvertor.Convert(maxValue, valueUnits, displayUnits);
                }

                string valueToDisplay = UnitFormatter.Format(maxValue, displayUnits);

                string message = string.Format(format, valueToDisplay);
                this.LogValidationResult(validationResults, message, currentTarget, key);
            }
        }
Ejemplo n.º 5
0
    public void SetData(Boat b, BoatShopSceneController bssc)
    {
        LocalizationManager lz = MainGameController.instance.localizationManager;

        _boatNameText.text  = b.Name;
        _boatStatsText.text = lz.GetLocalizedValue("speed_text") + ": \t" + UnitConvertor.Convert(b.GetSpeed()) + "\n" +
                              "NGZ: \t" + b.NGZLimit + "\n" +
                              lz.GetLocalizedValue("max_damage_text") + ": \t" + b.MaxDamage + "\n" +
                              lz.GetLocalizedValue("offline_speed_text") + ": \t" + UnitConvertor.Convert(b.OfflineSpeed);
        if (!b.Bought)
        {
            _boatBuyText.text = lz.GetLocalizedValue("buy_text") + "\n" + b.Price + " " + lz.GetLocalizedValue("gold_text")[0];
            _boatBuyButton.onClick.RemoveAllListeners();
            _boatBuyButton.onClick.AddListener(delegate { bssc.BuyBoat(b); });
        }
        else if (!b.Active)
        {
            _boatBuyText.text = lz.GetLocalizedValue("use_text");
            _boatBuyButton.onClick.RemoveAllListeners();
            _boatBuyButton.onClick.AddListener(delegate { bssc.UseBoat(b); });
            _boatBuyButton.enabled = true;
        }
        else
        {
            _boatBuyText.text      = lz.GetLocalizedValue("using_text");
            _boatBuyButton.enabled = false;
        }
    }
        /// <summary>
        /// Gets Max Work Time value from GUI.
        /// </summary>
        /// <returns>Max Work Time value.</returns>
        private int _GetInputedMaxWorkTime()
        {
            double inputedValue = 0;

            if (null != maxWorkTimeTextBox.Value)
            {
                inputedValue = (double)((UInt32)maxWorkTimeTextBox.Value);
            }
            return((int)UnitConvertor.Convert(inputedValue, Unit.Hour, Unit.Minute));
        }
        /// <summary>
        /// Inits page controls.
        /// </summary>
        private void _InitControls()
        {
            Debug.Assert(!_isInited); // only once

            // init page controls
            var defaults = Defaults.Instance;

            // init Max Order from Defaults
            if (null == maxOrderTextBox.Value)
            {
                maxOrderTextBox.Value = (UInt32)defaults.RoutesDefaults.MaxOrder;
            }

            // init Max Work Time from Defaults
            if (null == maxWorkTimeTextBox.Value)
            {
                maxWorkTimeTextBox.Value = (UInt32)UnitConvertor.Convert(defaults.RoutesDefaults.MaxTotalDuration, Unit.Minute, Unit.Hour);
            }

            // init Start Time Window from Defaults
            var startTimeWindow = defaults.RoutesDefaults.StartTimeWindow;

            textBoxStart.Time      = startTimeWindow.From;
            textBoxEnd.Time        = startTimeWindow.To;
            textBoxStart.IsEnabled = textBoxEnd.IsEnabled = !startTimeWindow.IsWideopen;

            // init table
            _InitDataGridLayout();

            // init vehicle number from project
            int routesCount = DataKeeper.Routes.Count;

            if (0 == (UInt32)vehicleNumberTextBox.Value)
            {
                vehicleNumberTextBox.Value = (UInt32)((0 == routesCount) ? DEFAULT_ROUTE_COUNT : routesCount);
                if (0 == routesCount) // defaults records is shown immediately in table
                {
                    _DoGrowList(DEFAULT_ROUTE_COUNT);
                }
            }

            _isInited = true;
        }
Ejemplo n.º 8
0
    public void SetData(string from, string to, float distance, TimeSpan time)
    {
        _fromText.text     = from;
        _toText.text       = to;
        _distanceText.text = UnitConvertor.Convert(distance) + UnitConvertor.UnitString();
        string hourzero   = "";
        string minutezero = "";
        string secondzero = "";

        if (time.Hours < 10)
        {
            hourzero = "0";
        }
        if (time.Minutes < 10)
        {
            minutezero = "0";
        }
        if (time.Seconds < 10)
        {
            secondzero = "0";
        }
        _timeText.text = time.Days + " " + MainGameController.instance.localizationManager.GetLocalizedValue("days_text") + " " + hourzero + time.Hours + ":" + minutezero + time.Minutes + ":" + secondzero + time.Seconds;
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Set Text property to textbox using correct region format.
        /// </summary>
        private void _SetTextToInnerTextBox()
        {
            if (!_inited || this.Value == null)
            {
                if (_inited)
                {
                    // Clear value.
                    _TextBox.Text = string.Empty;
                }

                return;
            }

            double value = (double)this.Value;

            if (_valueUnits != _displayUnits)
            {
                value = UnitConvertor.Convert(value, _valueUnits, _displayUnits);
            }

            string valueToDisplay = UnitFormatter.Format(value, _displayUnits);

            _TextBox.Text = valueToDisplay;
        }
Ejemplo n.º 10
0
    public void UpdateInfoPanels()
    {
        LocalizationManager lz = MainGameController.instance.localizationManager;

        _distanceLeftText.text = lz.GetLocalizedValue("distance_left_text") + ":\n " + UnitConvertor.Convert(_route.GetDistanceLeft()) + UnitConvertor.UnitString();
        _arrivelTimeText.text  = lz.GetLocalizedValue("excpected_arrival_time_text") + ":\n " + _arrivalTime.ToString("dd-MM-yyyy HH:mm:ss");
        _currentSpeedText.text = lz.GetLocalizedValue("current_speed_text") + ":\n " + Mathf.Round(UnitConvertor.Convert(_currentSpeed * 10)) / 10 + UnitConvertor.UnitString() + "/h";
        _maxSpeedText.text     = lz.GetLocalizedValue("maximum_speed_text") + ":\n " + Mathf.Round(UnitConvertor.Convert(MainGameController.instance.player.GetActiveBoat().GetSpeedModified() * 10)) / 10 + UnitConvertor.UnitString() + "/h";
    }
Ejemplo n.º 11
0
 public override double CalculateArea()
 {
     return(UnitConvertor.Convert(RadiusCm) * UnitConvertor.Convert(RadiusCm) * Math.PI);
 }
Ejemplo n.º 12
0
 public override double CalculateArea()
 {
     return(0.5 * UnitConvertor.Convert(BaseCm) * UnitConvertor.Convert(HeightCm));
 }
Ejemplo n.º 13
0
 public override double CalculateArea()
 {
     return(UnitConvertor.Convert(SideCm) * UnitConvertor.Convert(SideCm));
 }