Пример #1
0
        private void Zooming()
        {
            var zoomingStrength = GetZoomingStrength();

            if (FloatUtil.NearlyEqual(zoomingStrength, 0f))
            {
                return;
            }

            _viewModel.OnZooming(zoomingStrength, Time.deltaTime);
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            // assume this is only ever compared against another CameraTransformValue
            var other = (CameraTransformValue)obj;

            return(FloatUtil.NearlyEqual(Position.x, other.Position.x) &&
                   FloatUtil.NearlyEqual(Position.y, other.Position.y) &&
                   FloatUtil.NearlyEqual(Position.z, other.Position.z) &&
                   FloatUtil.NearlyEqual(Rot.x, other.Rot.x) &&
                   FloatUtil.NearlyEqual(Rot.y, other.Rot.y) &&
                   FloatUtil.NearlyEqual(Rot.z, other.Rot.z) &&
                   FloatUtil.NearlyEqual(Rot.w, other.Rot.w));
        }
Пример #3
0
        private void Panning() //consider adding panning with middle mouse button
        {
            var panningStrength = GetPanningStrength();

            if (FloatUtil.NearlyEqual(panningStrength, 0f))
            {
                return;
            }

            var mousePosition = Input.mousePosition;

            var panningDirection = (mousePosition - new Vector3(Screen.width / 2f, Screen.height / 2f, 0)).normalized;

            panningDirection.z = panningDirection.y;
            panningDirection.y = 0;

            _viewModel.OnPanning(panningDirection, GetPanningStrength(), Time.deltaTime);
        }
Пример #4
0
            private void CreatePaletteButtonHintLabel(UBuilder builder,
                                                      bool showMph,
                                                      SpeedValue speedValue,
                                                      SpeedLimitPaletteButton button,
                                                      UPanel buttonPanel)
            {
                // Other speed unit info label
                string otherUnit = showMph
                                       ? ToKmphPreciseString(speedValue)
                                       : ToMphPreciseString(speedValue);

                // Choose label text under the button
                string GetSpeedButtonHintText()
                {
                    if (FloatUtil.NearlyEqual(speedValue.GameUnits, 0.0f))
                    {
                        return(Translation.SpeedLimits.Get("Palette.Text:Default"));
                    }

                    if (speedValue.GameUnits >= SpeedValue.UNLIMITED)
                    {
                        return(Translation.SpeedLimits.Get("Palette.Text:Unlimited"));
                    }

                    return(otherUnit);
                }

                ULabel label = button.AltUnitsLabel =
                    builder.Label_(
                        parent: buttonPanel,
                        t: GetSpeedButtonHintText(),
                        stack: UStackMode.Below);

                label.width         = SpeedLimitPaletteButton.SELECTED_WIDTH;
                label.textAlignment = UIHorizontalAlignment.Center;
                label.ContributeToBoundingBox(false); // parent ignore our width
            }
Пример #5
0
        private float GetZoomingStrength()
        {
            var zoomInput     = Input.GetAxis("Mouse ScrollWheel");
            var inputStrength = Mathf.Abs(zoomInput);

            if (!FloatUtil.NearlyEqual(zoomInput, 0f))
            {
                _currentZoomingDirection = Mathf.Sign(zoomInput) * (config.IsInvertedWheel ? -1f : 1f);
            }

            if (!FloatUtil.NearlyEqual(zoomInput, 0f))
            {
                //accelerating
                _accumulatedZoomingDecelerationValue = 0;
                _accumulatedZoomingValue            += inputStrength;
                _accumulatedZoomingValue             = Mathf.Clamp01(_accumulatedZoomingValue);
            }
            else if (!FloatUtil.NearlyEqual(_accumulatedZoomingValue, 0f))
            {
                //decelerating

                _accumulatedZoomingDecelerationValue += config.DecelerationSpeed * Time.deltaTime;
                _accumulatedZoomingDecelerationValue  = Mathf.Clamp01(_accumulatedZoomingDecelerationValue);

                _accumulatedZoomingValue -= Easing.ExponentialEaseInOut(_accumulatedZoomingDecelerationValue, config.SmoothFactor);
                _accumulatedZoomingValue  = Mathf.Clamp01(_accumulatedZoomingValue);
            }
            else
            {
                //all is set, do nothing
                _currentZoomingDirection = 0f;
                return(0);
            }

            return(_currentZoomingDirection * Easing.ExponentialEaseInOut(_accumulatedZoomingValue, config.SmoothFactor));
        }
        /// <summary>
        /// The window for selecting and applying a speed limit
        /// </summary>
        /// <param name="num"></param>
        private void GuiSpeedLimitsWindow(int num)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            Color             oldColor       = GUI.color;
            List <SpeedValue> allSpeedLimits = EnumerateSpeedLimits(SpeedUnit.CurrentlyConfigured);

            allSpeedLimits.Add(new SpeedValue(0)); // add last item: no limit

            bool showMph     = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;
            var  column      = 0u; // break palette to a new line at breakColumn
            int  breakColumn = showMph ? BREAK_PALETTE_COLUMN_MPH : BREAK_PALETTE_COLUMN_KMPH;

            foreach (SpeedValue speedLimit in allSpeedLimits)
            {
                // Highlight palette item if it is very close to its float speed
                if (FloatUtil.NearlyEqual(currentPaletteSpeedLimit.GameUnits, speedLimit.GameUnits))
                {
                    GUI.color = Color.gray;
                }

                GuiSpeedLimitsWindow_AddButton(showMph, speedLimit);
                GUI.color = oldColor;

                // TODO: This can be calculated from SpeedLimit MPH or KMPH limit constants
                column++;
                if (column % breakColumn == 0)
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                }
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //---------------------
            // UI buttons row
            //---------------------
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(Translation.GetString("Default_speed_limits"),
                                 GUILayout.Width(200)))
            {
                TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_Defaults");
                defaultsWindowVisible = true;
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //---------------------
            // Checkboxes row
            //---------------------
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            showLimitsPerLane = GUILayout.Toggle(
                showLimitsPerLane,
                Translation.GetString("Show_lane-wise_speed_limits"));

            GUILayout.FlexibleSpace();

            // Display MPH checkbox, if ticked will save global config
            bool displayMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;

            displayMph = GUILayout.Toggle(displayMph, Translation.GetString("Display_speed_limits_mph"));

            if (GlobalConfig.Instance.Main.DisplaySpeedLimitsMph != displayMph)
            {
                OptionsGeneralTab.SetDisplayInMph(displayMph);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            DragWindow(ref paletteWindowRect);
        }