示例#1
0
        public static int GetLineCount(string text, PointF position, CitizenFX.Core.UI.Font font, float scale, float wrap)
        {
            // Tell the game that we are going to request the number of lines
            SetTextGxtEntry("CELL_EMAIL_BCON");             // _BEGIN_TEXT_COMMAND_LINE_COUNT
            // Add the text that has been sent to us
            UIResText.AddLongStringForUtf8(text);           // ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME

            // Get the resolution with the correct aspect ratio
            SizeF res = ResolutionMaintainRatio;
            // Calculate the x and y positions
            float x = position.X / res.Width;
            float y = position.Y / res.Height;

            // Set the properties for the text
            SetTextFont((int)font);
            SetTextScale(1f, scale);

            // If there is some text wrap to add
            if (wrap > 0)
            {
                // Calculate the wrap size
                float start = position.X / res.Width;
                float end   = start + (wrap / res.Width);
                // And apply it
                SetTextWrap(x, end);
            }
            // Finally, return the number of lines being made by the string
            return(GetTextScreenLineCount(x, y));            // _GET_TEXT_SCREEN_LINE_COUNT
        }
        public static float GetTextWidth(string Text, CitizenFX.Core.UI.Font Font, float Scale)
        {
            Function.Call(Hash._SET_TEXT_ENTRY_FOR_WIDTH, "jamyfafi");
            Function.Call(Hash.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME, Text);
            Function.Call(Hash.SET_TEXT_FONT, Font);
            Function.Call(Hash.SET_TEXT_SCALE, Scale, Scale);
            float result = Function.Call <float>(Hash._GET_TEXT_SCREEN_WIDTH, 1);

            return(result);
        }
示例#3
0
        public static float MeasureStringWidth(string str, Font font, float scale)
        {
            int         screenw = 2560; // Game.ScreenResolution.Width;
            int         screenh = 1440; // Game.ScreenResolution.Height;
            const float height  = 1080f;
            float       ratio   = (float)screenw / screenh;
            float       width   = height * ratio;

            return(MeasureStringWidthNoConvert(str, font, scale) * width);
        }
示例#4
0
        /// <summary>
        /// Calculates the width of a string.
        /// </summary>
        /// <param name="text">The text to measure.</param>
        /// <param name="font">Game font used for measurements.</param>
        /// <param name="scale">The scale of the characters.</param>
        /// <returns>The width of the string based on the font and scale.</returns>
        public static float GetTextWidth(string text, CitizenFX.Core.UI.Font font, float scale)
        {
            // Start by requesting the game to start processing a width measurement
            SetTextEntryForWidth("CELL_EMAIL_BCON");             // _BEGIN_TEXT_COMMAND_WIDTH
            // Add the text string
            UIResText.AddLongString(text);
            // Set the properties for the text
            SetTextFont((int)font);
            SetTextScale(1f, scale);

            // Ask the game for the relative string width
            float width = GetTextScreenWidth(true);

            // And return the literal result
            return(ResolutionMaintainRatio.Width * width);
        }
示例#5
0
        private static void RandomFont_Activated(object sender, EventArgs e)
        {
            // Here, we get a random item from the Font enum
            Font[] values     = (Font[])Enum.GetValues(typeof(Font));
            Random random     = new Random();
            Font   randomFont = values[random.Next(values.Length)];

            // And then, we apply it to every menu
            pool.ForEach <NativeMenu>(menu =>
            {
                menu.TitleFont       = randomFont;
                menu.SubtitleFont    = randomFont;
                menu.DescriptionFont = randomFont;
                menu.ItemCountFont   = randomFont;

                // Even the items!
                foreach (NativeItem item in menu.Items)
                {
                    item.TitleFont    = randomFont;
                    item.AltTitleFont = randomFont;
                }
            });
        }
示例#6
0
 public UIResText(string caption, PointF position, float scale, Color color, Font font, Alignment justify)
     : base(caption, position, scale, color, font, CitizenFX.Core.UI.Alignment.Left)
 {
     TextAlignment = justify;
 }
示例#7
0
 public static float MeasureStringWidthNoConvert(string str, Font font, float scale)
 {
     Function.Call((Hash)0x54CE8AC98E120CAB, "STRING");
     AddLongString(str);
     return(Function.Call <float>((Hash)0x85F061DA64ED2F67, (int)font) * scale);
 }
        static public async Task OnTick()
        {
            if (CinematicMode.DoHideHud)
            {
                return;
            }

            string currentStreetName   = World.GetStreetName(Game.PlayerPed.Position);
            string currentCrossingName = GetCrossingName(Game.PlayerPed.Position);
            string localizedZone       = World.GetZoneLocalizedName(Game.PlayerPed.Position);

            // Used for AI alerting
            CompactLocation = $"{currentStreetName} | {currentCrossingName} | {localizedZone}";

            if (version == 1)
            {
                CitizenFX.Core.UI.Font font = CitizenFX.Core.UI.Font.ChaletLondon;
                float scale = 0.25f;
                float x     = 0.18f;
                float y     = 0.95f;
                System.Drawing.Color colorLowImportance = System.Drawing.Color.FromArgb(255, 200, 200, 200);
                System.Drawing.Color colorFocus         = System.Drawing.Color.FromArgb(255, 255, 255, 255);

                string textAddition;

                textAddition = "In";
                FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                x += GetTextWidth(textAddition, font, scale);

                textAddition = $"{localizedZone}";
                FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                x += GetTextWidth(textAddition, font, scale);

                if (String.IsNullOrWhiteSpace(currentCrossingName))
                {
                    textAddition = "on";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);

                    textAddition = $"{currentStreetName}";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);
                }
                else
                {
                    textAddition = "at crossing of";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);

                    textAddition = $"{currentStreetName}";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);

                    textAddition = "and";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);

                    textAddition = $"{currentCrossingName}";
                    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                    x += GetTextWidth(textAddition, font, scale);
                }

                textAddition = "looking";
                FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                x += GetTextWidth(textAddition, font, scale);

                textAddition = $"{Compass.GetCardinalDirection()}";
                FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                x += GetTextWidth(textAddition, font, scale);
            }
            else if (version == 2)
            {
                CitizenFX.Core.UI.Font font = CitizenFX.Core.UI.Font.ChaletLondon;
                float scale = 0.25f;
                System.Drawing.Color colorLowImportance = System.Drawing.Color.FromArgb(255, 200, 200, 200);
                System.Drawing.Color colorFocus         = System.Drawing.Color.FromArgb(255, 255, 255, 255);

                string textAddition;

                Vector2 topRightCardinal = new Vector2(1.01f, 0.94f);
                Vector2 topLeftCardinal  = new Vector2(topRightCardinal.X - 0.04f, topRightCardinal.Y);
                FamilyRP.Roleplay.Client.UI.DrawText($"{Compass.GetCardinalDirection()}", topLeftCardinal, colorFocus, 1f, 0, Alignment.Left);
                FamilyRP.Roleplay.Client.UI.DrawText($"{localizedZone}", new Vector2(topLeftCardinal.X - GetTextWidth($"{localizedZone}", 0, 0.35f), topLeftCardinal.Y + 0.012f), colorFocus, 0.35f, 0, Alignment.Left);

                float StreetNameWidth = GetTextWidth($"{currentStreetName}", 0, 0.35f);

                if (String.IsNullOrWhiteSpace(currentCrossingName))
                {
                    FamilyRP.Roleplay.Client.UI.DrawText($"{currentStreetName}", new Vector2(topLeftCardinal.X - StreetNameWidth, topLeftCardinal.Y + 0.032f), colorFocus, 0.35f, 0, Alignment.Left);
                }
                else
                {
                    float AmpersandWidth    = GetTextWidth($"&", 0, 0.3f);
                    float CrossingNameWidth = GetTextWidth($"{currentCrossingName}", 0, 0.35f);

                    FamilyRP.Roleplay.Client.UI.DrawText($"{currentStreetName}", new Vector2(topLeftCardinal.X - StreetNameWidth, topLeftCardinal.Y + 0.032f), colorFocus, 0.35f, 0, Alignment.Left);
                    FamilyRP.Roleplay.Client.UI.DrawText($"&", new Vector2(topLeftCardinal.X - StreetNameWidth - AmpersandWidth, topLeftCardinal.Y + 0.034f), colorLowImportance, 0.3f, 0, Alignment.Left);
                    FamilyRP.Roleplay.Client.UI.DrawText($"{currentCrossingName}", new Vector2(topLeftCardinal.X - StreetNameWidth - AmpersandWidth - CrossingNameWidth, topLeftCardinal.Y + 0.032f), colorFocus, 0.35f, 0, Alignment.Left);
                }

                //Function.Call();
                //new CitizenFX.Core.UI.Text(textAddition, new PointF(x, y), colorFocus, 1f, 0, true);
                //x += GetTextWidth(textAddition, font, scale);

                //textAddition = $"{localizedZone}";
                //FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                //x += GetTextWidth(textAddition, font, scale);

                //if (String.IsNullOrWhiteSpace(currentCrossingName))
                //{
                //    textAddition = "on";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);

                //    textAddition = $"{currentStreetName}";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);
                //}
                //else
                //{
                //    textAddition = "at crossing of";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);

                //    textAddition = $"{currentStreetName}";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);

                //    textAddition = "and";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);

                //    textAddition = $"{currentCrossingName}";
                //    FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                //    x += GetTextWidth(textAddition, font, scale);
                //}

                //textAddition = "looking";
                //FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorLowImportance, 0.25f, 0, false);
                //x += GetTextWidth(textAddition, font, scale);

                //textAddition = $"{Compass.GetCardinalDirection()}";
                //FamilyRP.Roleplay.Client.UI.DrawText(textAddition, new Vector2(x, y), colorFocus, 0.25f, 0, false);
                //x += GetTextWidth(textAddition, font, scale);
            }

            await Task.FromResult(0);
        }
 public ScreenText(string text, int x, int y, float scale, Func <Task> drawTick, Color textColour, Font textFont, Alignment textAlignment, bool useShadow, bool haveOutline)
     : base(text, new PointF(x * 0.6666666667f, y * 0.6666666667f), scale, textColour, textFont, textAlignment, useShadow, haveOutline)
 {
     this.drawTick = drawTick;
 }
 public ScreenText(string text, int x, int y, float scale, Func <Task> drawTick, Color textColour, Font textFont, Alignment textAlignment, bool useShadow)
     : this(text, x, y, scale, drawTick, textColour, textFont, textAlignment, useShadow, true)
 {
 }
 public ScreenText(string text, int x, int y, float scale, Func <Task> drawTick, Color textColour, Font textFont)
     : this(text, x, y, scale, drawTick, textColour, textFont, Alignment.Center, true, true)
 {
 }
示例#12
0
 public static float MeasureStringWidthNoConvert(string str, Font font, float scale) => ScreenTools.GetTextWidth(str, font, scale);
示例#13
0
 public static float MeasureStringWidthNoConvert(string str, Font font, float scale)
 {
     BeginTextCommandWidth("STRING");
     AddLongString(str);
     return(EndTextCommandGetWidth(true) * scale);
 }