Ejemplo n.º 1
0
        public void Tick()
        {
            if (!Main.IsOnServer())
            {
                return;
            }

            var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds);

            int alpha = 100;

            if (timePassed > 60000 && !_isFocused)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000);
            }
            if (timePassed < 300 && _lastFadedOut)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300);
            }


            var pos = GetInputboxPos(Main.PlayerSettings.ScaleChatWithSafezone);

            _mainScaleform.Render2DScreenSpace(new PointF(pos.X, pos.Y), new PointF(UI.WIDTH, UI.HEIGHT));

            var textAlpha = (alpha / 100f) * 126 + 126;
            var c         = 0;

            if (_messages.Any())
            {
                for (int indx = Math.Min(_messagesPerPage + _pagingIndex, _messages.Count - 1); indx >= (_messages.Count <= _messagesPerPage ? 0 : _pagingIndex); indx--)
                {
                    var msg = _messages[indx];

                    string output = msg.Item1;
                    var    limit  = UIMenu.GetScreenResolutionMantainRatio().Width - UIMenu.GetSafezoneBounds().X;
                    while (StringMeasurer.MeasureString(output) > limit)
                    {
                        output = output.Substring(0, output.Length - 5);
                    }

                    if (Main.PlayerSettings.ScaleChatWithSafezone)
                    {
                        new UIResText(output, UIMenu.GetSafezoneBounds() + new Size(0, 25 * c), 0.35f,
                                      Color.FromArgb((int)textAlpha, msg.Item2))
                        {
                            Outline = true,
                        }.Draw();
                    }
                    else
                    {
                        new UIResText(output, new Point(0, 25 * c), 0.35f,
                                      Color.FromArgb((int)textAlpha, msg.Item2))
                        {
                            Outline = true,
                        }.Draw();
                    }
                    c++;
                }
            }

            if (_pagingIndex != 0 && _messages.Count > _messagesPerPage)
            {
                Point start = UIMenu.GetSafezoneBounds();
                if (!Main.PlayerSettings.ScaleChatWithSafezone)
                {
                    start = new Point();
                }
                start = new Point(start.X - 15, start.Y);
                var chatHeight       = 25 * (_messagesPerPage + 1);
                var availableChoices = _messages.Count - _messagesPerPage;
                var barHeight        = (1f / availableChoices) * chatHeight;

                new UIResRectangle(start, new Size(10, chatHeight), Color.FromArgb(50, 0, 0, 0)).Draw();
                new UIResRectangle(start + new Size(0, (int)(chatHeight - chatHeight * ((_pagingIndex + 1) / (float)availableChoices))), new Size(10, (int)barHeight), Color.FromArgb(150, 0, 0, 0)).Draw();
            }

            if (!IsFocused)
            {
                return;
            }

            if (!Main.CanOpenChatbox)
            {
                IsFocused = false;
            }

            Game.DisableControlThisFrame(0, Control.NextCamera);
            Game.DisableAllControlsThisFrame(0);
        }
Ejemplo n.º 2
0
        public void Tick()
        {
            if (!Main.IsOnServer())
            {
                return;
            }

            var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds);

            int alpha = 100;

            if (timePassed > 60000 && !_isFocused)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000);
            }
            if (timePassed < 300 && _lastFadedOut)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300);
            }

            var textAlpha = (alpha / 100f) * 126 + 126;
            var c         = 0;

            if (_messages.Any())
            {
                for (int indx = Math.Min(_messagesPerPage + _pagingIndex, _messages.Count - 1); indx >= (_messages.Count <= _messagesPerPage ? 0 : _pagingIndex); indx--)
                {
                    var   msg      = _messages[indx];
                    Point position = Main.PlayerSettings.ScaleChatWithSafezone
                    ? UIMenu.GetSafezoneBounds() + new Size(0, 25 * c)
                    : new Point(0, 25 * c);
                    string output = msg.Item1;
                    var    res    = GTA.UI.Screen.Resolution;

                    int length = NativeUI.StringMeasurer.MeasureString(output);

                    while (length > res.Width - 10 - position.X && output.Length > 10)
                    {
                        output = output.Substring(0, Math.Max(10, output.Length - 10));
                        length = NativeUI.StringMeasurer.MeasureString(output);
                    }

                    new UIResText(output, position, 0.45f,
                                  Color.FromArgb((int)textAlpha, msg.Item2))
                    {
                        Outline = true,
                    }.Draw();

                    c++;
                }
            }

            if (_pagingIndex != 0 && _messages.Count > _messagesPerPage)
            {
                Point start = UIMenu.GetSafezoneBounds();
                if (!Main.PlayerSettings.ScaleChatWithSafezone)
                {
                    start = new Point();
                }
                start = new Point(start.X - 15, start.Y);
                var chatHeight       = 25 * (_messagesPerPage + 1);
                var availableChoices = _messages.Count - _messagesPerPage;
                var barHeight        = (1f / availableChoices) * chatHeight;

                new UIResRectangle(start, new Size(10, chatHeight), Color.FromArgb(50, 0, 0, 0)).Draw();
                new UIResRectangle(start + new Size(0, (int)(chatHeight - chatHeight * ((_pagingIndex + 1) / (float)availableChoices))), new Size(10, (int)barHeight), Color.FromArgb(150, 0, 0, 0)).Draw();
            }

            if (!Main.CanOpenChatbox)
            {
                IsFocused = false;
            }

            if (!IsFocused)
            {
                return;
            }


            DrawChatboxInput();

            Game.DisableControlThisFrame(0, Control.NextCamera);
            Game.DisableAllControlsThisFrame(0);
        }
Ejemplo n.º 3
0
        public void Tick()
        {
            if (!Main.IsOnServer())
            {
                return;
            }

            var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds);

            int alpha = 100;

            if (timePassed > 60000 && !_isFocused)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000);
            }
            if (timePassed < 300 && _lastFadedOut)
            {
                alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300);
            }


            var pos = GetInputboxPos(Main.PlayerSettings.ScaleChatWithSafezone);

            _mainScaleform.Render2DScreenSpace(new PointF(pos.X, pos.Y), new PointF(UI.WIDTH, UI.HEIGHT));

            var textAlpha = (alpha / 100f) * 126 + 126;
            var c         = 0;

            foreach (var msg in _messages)
            {
                string output = msg.Item1;
                var    limit  = UIMenu.GetScreenResolutionMaintainRatio().Width - UIMenu.GetSafezoneBounds().X;
                while (StringMeasurer.MeasureString(output) > limit)
                {
                    output = output.Substring(0, output.Length - 5);
                }

                if (Main.PlayerSettings.ScaleChatWithSafezone)
                {
                    new UIResText(output, UIMenu.GetSafezoneBounds() + new Size(0, 25 * c), 0.35f,
                                  Color.FromArgb((int)textAlpha, msg.Item2))
                    {
                        Outline = true,
                    }.Draw();
                }
                else
                {
                    new UIResText(output, new Point(0, 25 * c), 0.35f,
                                  Color.FromArgb((int)textAlpha, msg.Item2))
                    {
                        Outline = true,
                    }.Draw();
                }
                c++;
            }

            if (!IsFocused)
            {
                return;
            }
            Game.DisableControlThisFrame(0, Control.NextCamera);
            Game.DisableAllControlsThisFrame(0);
            Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
        }