private void SetSubmarineVotingText(Client starter, SubmarineInfo info, VoteType type)
        {
            string    name                = starter.Name;
            JobPrefab prefab              = starter?.Character?.Info?.Job?.Prefab;
            Color     nameColor           = prefab != null ? prefab.UIColor : Color.White;
            string    characterRichString = $"‖color:{nameColor.R},{nameColor.G},{nameColor.B}‖{name}‖color:end‖";
            string    submarineRichString = $"‖color:{submarineColor.R},{submarineColor.G},{submarineColor.B}‖{info.DisplayName}‖color:end‖";

            switch (type)
            {
            case VoteType.PurchaseAndSwitchSub:
                votingOnText = TextManager.GetWithVariables("submarinepurchaseandswitchvote", new string[] { "[playername]", "[submarinename]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, info.Price.ToString(), TextManager.Get("credit").ToLower() });
                break;

            case VoteType.PurchaseSub:
                votingOnText = TextManager.GetWithVariables("submarinepurchasevote", new string[] { "[playername]", "[submarinename]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, info.Price.ToString(), TextManager.Get("credit").ToLower() });
                break;

            case VoteType.SwitchSub:
                int deliveryFee = SubmarineSelection.DeliveryFeePerDistanceTravelled * GameMain.GameSession.Map.DistanceToClosestLocationWithOutpost(GameMain.GameSession.Map.CurrentLocation, out Location endLocation);

                if (deliveryFee > 0)
                {
                    votingOnText = TextManager.GetWithVariables("submarineswitchfeevote", new string[] { "[playername]", "[submarinename]", "[locationname]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, endLocation.Name, deliveryFee.ToString(), TextManager.Get("credit").ToLower() });
                }
                else
                {
                    votingOnText = TextManager.GetWithVariables("submarineswitchnofeevote", new string[] { "[playername]", "[submarinename]" }, new string[] { characterRichString, submarineRichString });
                }
                break;
            }

            votingOnTextData = RichTextData.GetRichTextData(votingOnText, out votingOnText);
        }
        private static void DrawEventTargetTags(SpriteBatch spriteBatch, ScriptedEvent scriptedEvent)
        {
            if (Screen.Selected is GameScreen screen)
            {
                Camera cam = screen.Cam;
                Dictionary <Entity, List <string> > tagsDictionary = new Dictionary <Entity, List <string> >();
                foreach ((string key, List <Entity> value) in scriptedEvent.Targets)
                {
                    foreach (Entity entity in value)
                    {
                        if (tagsDictionary.ContainsKey(entity))
                        {
                            tagsDictionary[entity].Add(key);
                        }
                        else
                        {
                            tagsDictionary.Add(entity, new List <string> {
                                key
                            });
                        }
                    }
                }

                string identifier = scriptedEvent.Prefab.Identifier;

                foreach ((Entity entity, List <string> tags) in tagsDictionary)
                {
                    if (entity.Removed)
                    {
                        continue;
                    }

                    string text = tags.Aggregate("Tags:\n", (current, tag) => current + $"    {tag.ColorizeObject()}\n").TrimEnd('\r', '\n');
                    if (!string.IsNullOrWhiteSpace(identifier))
                    {
                        text = $"Event: {identifier.ColorizeObject()}\n{text}";
                    }

                    List <RichTextData> richTextData = RichTextData.GetRichTextData(text, out text);

                    Vector2 entityPos = cam.WorldToScreen(entity.WorldPosition);
                    Vector2 infoSize  = GUI.SmallFont.MeasureString(text);

                    Vector2 infoPos = entityPos + new Vector2(128 * cam.Zoom, -(128 * cam.Zoom));
                    infoPos.Y -= infoSize.Y / 2;

                    Rectangle infoRect = new Rectangle(infoPos.ToPoint(), infoSize.ToPoint());
                    infoRect.Inflate(4, 4);

                    GUI.DrawRectangle(spriteBatch, infoRect, Color.Black * 0.8f, isFilled: true);
                    GUI.DrawRectangle(spriteBatch, infoRect, Color.White, isFilled: false);

                    GUI.DrawStringWithColors(spriteBatch, infoPos, text, Color.White, richTextData, font: GUI.SmallFont);

                    GUI.DrawLine(spriteBatch, entityPos, new Vector2(infoRect.Location.X, infoRect.Location.Y + infoRect.Height / 2), Color.White);
                }
            }
        }
Beispiel #3
0
        public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, float deltaTime)
        {
            if (GameMain.Config.EnableSplashScreen)
            {
                try
                {
                    DrawSplashScreen(spriteBatch, graphics);
                    if (currSplashScreen != null || PendingSplashScreens.Count > 0)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    DebugConsole.ThrowError("Playing splash screen video failed", e);
                    GameMain.Config.EnableSplashScreen = false;
                }
            }

            var    titleStyle  = GUI.Style?.GetComponentStyle("TitleText");
            Sprite titleSprite = null;

            if (!WaitForLanguageSelection && titleStyle != null && titleStyle.Sprites.ContainsKey(GUIComponent.ComponentState.None))
            {
                titleSprite = titleStyle.Sprites[GUIComponent.ComponentState.None].First()?.Sprite;
            }

            drawn = true;

            currentBackgroundTexture ??= defaultBackgroundTexture;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, samplerState: GUI.SamplerState);

            float scale    = (GameMain.GraphicsWidth / (float)currentBackgroundTexture.Width) * 1.2f;
            float paddingX = currentBackgroundTexture.Width * scale - GameMain.GraphicsWidth;
            float paddingY = currentBackgroundTexture.Height * scale - GameMain.GraphicsHeight;

            double  noiseT = (Timing.TotalTime * 0.02f);
            Vector2 pos    = new Vector2((float)PerlinNoise.CalculatePerlin(noiseT, noiseT, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(noiseT, noiseT, 0.5f) - 0.5f);

            pos = new Vector2(pos.X * paddingX, pos.Y * paddingY);

            spriteBatch.Draw(currentBackgroundTexture,
                             new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight) / 2 + pos,
                             null, Color.White, 0.0f, new Vector2(currentBackgroundTexture.Width / 2, currentBackgroundTexture.Height / 2),
                             scale, SpriteEffects.None, 0.0f);

            spriteBatch.Draw(overlay, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f);

            float noiseStrength = (float)PerlinNoise.CalculatePerlin(noiseT, noiseT, 0);
            float noiseScale    = (float)PerlinNoise.CalculatePerlin(noiseT * 5.0f, noiseT * 2.0f, 0) * 4.0f;

            noiseSprite.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight),
                                  startOffset: new Vector2(Rand.Range(0.0f, noiseSprite.SourceRect.Width), Rand.Range(0.0f, noiseSprite.SourceRect.Height)),
                                  color: Color.White * noiseStrength * 0.1f,
                                  textureScale: Vector2.One * noiseScale);

            titleSprite?.Draw(spriteBatch, new Vector2(GameMain.GraphicsWidth * 0.05f, GameMain.GraphicsHeight * 0.125f),
                              Color.White, origin: new Vector2(0.0f, titleSprite.SourceRect.Height / 2.0f),
                              scale: GameMain.GraphicsHeight / 2000.0f);

            if (WaitForLanguageSelection)
            {
                DrawLanguageSelectionPrompt(spriteBatch, graphics);
            }
            else if (DrawLoadingText)
            {
                if (TextManager.Initialized)
                {
                    string loadText;
                    if (LoadState == 100.0f)
                    {
#if DEBUG
                        if (GameMain.Config.AutomaticQuickStartEnabled || GameMain.Config.AutomaticCampaignLoadEnabled || GameMain.Config.TestScreenEnabled && GameMain.FirstLoad)
                        {
                            loadText = "QUICKSTARTING ...";
                        }
                        else
                        {
#endif
                        loadText = TextManager.Get("PressAnyKey");
#if DEBUG
                    }
#endif
                    }
                    else
                    {
                        loadText = TextManager.Get("Loading");
                        if (LoadState != null)
                        {
                            loadText += " " + (int)LoadState + " %";

#if DEBUG
                            if (GameMain.FirstLoad && GameMain.CancelQuickStart)
                            {
                                loadText += " (Quickstart aborted)";
                            }
#endif
                        }
                    }
                    if (GUI.LargeFont != null)
                    {
                        GUI.LargeFont.DrawString(spriteBatch, loadText.ToUpper(),
                                                 new Vector2(GameMain.GraphicsWidth / 2.0f - GUI.LargeFont.MeasureString(loadText.ToUpper()).X / 2.0f, GameMain.GraphicsHeight * 0.75f),
                                                 Color.White);
                    }
                }

                if (GUI.Font != null && selectedTip != null)
                {
                    if (selectedTipRichTextUnparsed)
                    {
                        selectedTipRichTextData     = RichTextData.GetRichTextData(selectedTip, out selectedTip);
                        selectedTipRichTextUnparsed = false;
                    }

                    string   wrappedTip = ToolBox.WrapText(selectedTip, GameMain.GraphicsWidth * 0.5f, GUI.Font);
                    string[] lines      = wrappedTip.Split('\n');
                    float    lineHeight = GUI.Font.MeasureString(selectedTip).Y;

                    if (selectedTipRichTextData != null)
                    {
                        int rtdOffset = 0;
                        for (int i = 0; i < lines.Length; i++)
                        {
                            GUI.Font.DrawStringWithColors(spriteBatch, lines[i],
                                                          new Vector2((int)(GameMain.GraphicsWidth / 2.0f - GUI.Font.MeasureString(lines[i]).X / 2.0f), (int)(GameMain.GraphicsHeight * 0.8f + i * lineHeight)), Color.White,
                                                          0f, Vector2.Zero, 1f, SpriteEffects.None, 0f, selectedTipRichTextData, rtdOffset);
                            rtdOffset += lines[i].Length;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < lines.Length; i++)
                        {
                            GUI.Font.DrawString(spriteBatch, lines[i],
                                                new Vector2((int)(GameMain.GraphicsWidth / 2.0f - GUI.Font.MeasureString(lines[i]).X / 2.0f), (int)(GameMain.GraphicsHeight * 0.8f + i * lineHeight)), Color.White);
                        }
                    }
                }
            }
            spriteBatch.End();

            spriteBatch.Begin(blendState: BlendState.Additive);

            Vector2 decorativeScale = new Vector2(GameMain.GraphicsHeight / 1080.0f);

            float noiseVal = (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.25f, Timing.TotalTime * 0.5f, 0);
            decorativeGraph.Draw(spriteBatch, (int)(decorativeGraph.FrameCount * noiseVal),
                                 new Vector2(GameMain.GraphicsWidth * 0.001f, GameMain.GraphicsHeight * 0.24f),
                                 Color.White, Vector2.Zero, 0.0f, decorativeScale, SpriteEffects.FlipVertically);

            decorativeMap.Draw(spriteBatch, (int)(decorativeMap.FrameCount * noiseVal),
                               new Vector2(GameMain.GraphicsWidth * 0.99f, GameMain.GraphicsHeight * 0.66f),
                               Color.White, decorativeMap.FrameSize.ToVector2(), 0.0f, decorativeScale);

            if (noiseVal < 0.2f)
            {
                //SCP-CB reference
                randText = (new string[] { "NIL", "black white gray", "Sometimes we would have had time to scream", "e8m106]af", "NO" }).GetRandom();
            }
            else if (noiseVal < 0.3f)
            {
                randText = ToolBox.RandomSeed(9);
            }
            else if (noiseVal < 0.5f)
            {
                randText =
                    Rand.Int(100).ToString().PadLeft(2, '0') + " " +
                    Rand.Int(100).ToString().PadLeft(2, '0') + " " +
                    Rand.Int(100).ToString().PadLeft(2, '0') + " " +
                    Rand.Int(100).ToString().PadLeft(2, '0');
            }

            GUI.LargeFont?.DrawString(spriteBatch, randText,
                                      new Vector2(GameMain.GraphicsWidth - decorativeMap.FrameSize.X * decorativeScale.X * 0.8f, GameMain.GraphicsHeight * 0.57f),
                                      Color.White * (1.0f - noiseVal));

            spriteBatch.End();
        }
        private void CreateReputationElement(GUIComponent parent,
                                             string name, float reputation, float normalizedReputation, float initialReputation,
                                             string shortDescription, string fullDescription, Sprite icon, Sprite backgroundPortrait, Color iconColor)
        {
            var factionFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.3f), parent.RectTransform), style: null);

            if (backgroundPortrait != null)
            {
                new GUICustomComponent(new RectTransform(Vector2.One, factionFrame.RectTransform), onDraw: (sb, customComponent) =>
                {
                    backgroundPortrait.Draw(sb, customComponent.Rect.Center.ToVector2(), customComponent.Color, backgroundPortrait.size / 2, scale: customComponent.Rect.Width / backgroundPortrait.size.X);
                })
                {
                    HideElementsOutsideFrame = true,
                    IgnoreLayoutGroups       = true,
                    Color = iconColor * 0.2f
                };
            }

            var factionInfoHorizontal = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), factionFrame.RectTransform, Anchor.Center), childAnchor: Anchor.CenterLeft, isHorizontal: true)
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };

            var factionTextContent = new GUILayoutGroup(new RectTransform(Vector2.One, factionInfoHorizontal.RectTransform))
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };
            var factionIcon = new GUIImage(new RectTransform(new Point((int)(factionInfoHorizontal.Rect.Height * 0.7f)), factionInfoHorizontal.RectTransform, scaleBasis: ScaleBasis.Smallest), icon, scaleToFit: true)
            {
                Color = iconColor
            };

            factionInfoHorizontal.Recalculate();

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), factionTextContent.RectTransform),
                             name, font: GUI.SubHeadingFont)
            {
                Padding = Vector4.Zero
            };
            var factionDescription = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.6f), factionTextContent.RectTransform),
                                                      shortDescription, font: GUI.SmallFont, wrap: true)
            {
                UserData = "description",
                Padding  = Vector4.Zero
            };

            if (shortDescription != fullDescription && !string.IsNullOrEmpty(fullDescription))
            {
                factionDescription.ToolTip = fullDescription;
            }

            var sliderHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), factionTextContent.RectTransform),
                                                  childAnchor: Anchor.CenterLeft, isHorizontal: true)
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            sliderHolder.RectTransform.MaxSize = new Point(int.MaxValue, GUI.IntScale(25.0f));
            factionTextContent.Recalculate();

            new GUICustomComponent(new RectTransform(new Vector2(0.8f, 1.0f), sliderHolder.RectTransform),
                                   onDraw: (sb, customComponent) => DrawReputationBar(sb, customComponent.Rect, normalizedReputation));

            string reputationText   = ((int)Math.Round(reputation)).ToString();
            int    reputationChange = (int)Math.Round(reputation - initialReputation);

            if (Math.Abs(reputationChange) > 0)
            {
                string changeText = $"{(reputationChange > 0 ? "+" : "") + reputationChange}";
                string colorStr   = XMLExtensions.ColorToString(reputationChange > 0 ? GUI.Style.Green : GUI.Style.Red);
                var    rtData     = RichTextData.GetRichTextData($"{reputationText} (‖color:{colorStr}‖{changeText}‖color:end‖)", out string sanitizedText);
                new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), sliderHolder.RectTransform),
                                 rtData, sanitizedText,
                                 textAlignment: Alignment.CenterLeft, font: GUI.SubHeadingFont);
            }
            else
            {
                new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), sliderHolder.RectTransform),
                                 reputationText,
                                 textAlignment: Alignment.CenterLeft, font: GUI.SubHeadingFont);
            }
        }
Beispiel #5
0
        public void DrawStringWithColors(SpriteBatch sb, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects se, float layerDepth, List <RichTextData> richTextData)
        {
            if (textures.Count == 0 && !DynamicLoading)
            {
                return;
            }

            int     lineNum     = 0;
            Vector2 currentPos  = position;
            Vector2 advanceUnit = rotation == 0.0f ? Vector2.UnitX : new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));

            int          richTextDataIndex   = 0;
            RichTextData currentRichTextData = richTextData[richTextDataIndex];

            for (int i = 0; i < text.Length; i++)
            {
                if (text[i] == '\n')
                {
                    lineNum++;
                    currentPos    = position;
                    currentPos.X -= baseHeight * 1.8f * lineNum * advanceUnit.Y * scale.Y;
                    currentPos.Y += baseHeight * 1.8f * lineNum * advanceUnit.X * scale.Y;
                    continue;
                }

                uint charIndex = text[i];
                if (DynamicLoading && !texCoords.ContainsKey(charIndex))
                {
                    DynamicRenderAtlas(graphicsDevice, charIndex);
                }

                Color currentTextColor;

                if (currentRichTextData != null && i > currentRichTextData.EndIndex + lineNum)
                {
                    richTextDataIndex++;
                    currentRichTextData = richTextDataIndex < richTextData.Count ? richTextData[richTextDataIndex] : null;
                }

                if (currentRichTextData != null && currentRichTextData.StartIndex + lineNum <= i && i <= currentRichTextData.EndIndex + lineNum)
                {
                    currentTextColor = currentRichTextData.Color ?? color;
                    if (!string.IsNullOrEmpty(currentRichTextData.Metadata))
                    {
                        currentTextColor = Color.Lerp(currentTextColor, Color.White, 0.5f);
                    }
                }
                else
                {
                    currentTextColor = color;
                }

                if (texCoords.TryGetValue(charIndex, out GlyphData gd) || texCoords.TryGetValue(9633, out gd)) //9633 = white square
                {
                    if (gd.texIndex >= 0)
                    {
                        Texture2D tex = textures[gd.texIndex];
                        Vector2   drawOffset;
                        drawOffset.X = gd.drawOffset.X * advanceUnit.X * scale.X - gd.drawOffset.Y * advanceUnit.Y * scale.Y;
                        drawOffset.Y = gd.drawOffset.X * advanceUnit.Y * scale.Y + gd.drawOffset.Y * advanceUnit.X * scale.X;

                        sb.Draw(tex, currentPos + drawOffset, gd.texCoords, currentTextColor, rotation, origin, scale, se, layerDepth);
                    }
                    currentPos += gd.advance * advanceUnit * scale.X;
                }
            }
        }
Beispiel #6
0
        public void DebugDraw(SpriteBatch spriteBatch, Vector2 pos, int debugDrawMetadataOffset, string[] ignoredMetadataInfo)
        {
            var campaignData = data;

            foreach (string ignored in ignoredMetadataInfo)
            {
                if (!string.IsNullOrWhiteSpace(ignored))
                {
                    campaignData = campaignData.Where(pair => !pair.Key.StartsWith(ignored)).ToDictionary(i => i.Key, i => i.Value);
                }
            }

            int offset = 0;;

            if (campaignData.Count > 0)
            {
                offset = debugDrawMetadataOffset % campaignData.Count;
                if (offset < 0)
                {
                    offset += campaignData.Count;
                }
            }

            var text = "Campaign metadata:\n";

            int max = 0;

            for (int i = offset; i < campaignData.Count + offset; i++)
            {
                int index = i;
                if (index >= campaignData.Count)
                {
                    index -= campaignData.Count;
                }

                var(key, value) = campaignData.ElementAt(index);

                if (max < MaxDrawnElements)
                {
                    text += $"{key.ColorizeObject()}: {value.ColorizeObject()}\n";
                    max++;
                }
                else
                {
                    text += "Use arrow keys to scroll";
                    break;
                }
            }

            text = text.TrimEnd('\n');

            List <RichTextData> richTextDatas = RichTextData.GetRichTextData(text, out text) ?? new List <RichTextData>();

            Vector2   size     = GUI.SmallFont.MeasureString(text);
            Vector2   infoPos  = new Vector2(GameMain.GraphicsWidth - size.X - 16, pos.Y + 8);
            Rectangle infoRect = new Rectangle(infoPos.ToPoint(), size.ToPoint());

            infoRect.Inflate(8, 8);
            GUI.DrawRectangle(spriteBatch, infoRect, Color.Black * 0.8f, isFilled: true);
            GUI.DrawRectangle(spriteBatch, infoRect, Color.White * 0.8f);

            if (richTextDatas.Any())
            {
                GUI.DrawStringWithColors(spriteBatch, infoPos, text, Color.White, richTextDatas, font: GUI.SmallFont);
            }
            else
            {
                GUI.DrawString(spriteBatch, infoPos, text, Color.White, font: GUI.SmallFont);
            }

            float y = infoRect.Bottom + 16;

            if (Campaign.Factions != null)
            {
                const string factionHeader     = "Reputations";
                Vector2      factionHeaderSize = GUI.SubHeadingFont.MeasureString(factionHeader);
                Vector2      factionPos        = new Vector2(GameMain.GraphicsWidth - (264 / 2) - factionHeaderSize.X / 2, y);

                GUI.DrawString(spriteBatch, factionPos, factionHeader, Color.White, font: GUI.SubHeadingFont);
                y += factionHeaderSize.Y + 8;

                foreach (Faction faction in Campaign.Factions)
                {
                    string  name     = faction.Prefab.Name;
                    Vector2 nameSize = GUI.SmallFont.MeasureString(name);
                    GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 264, y), name, Color.White, font: GUI.SmallFont);
                    y += nameSize.Y + 5;

                    Color color = ToolBox.GradientLerp(faction.Reputation.NormalizedValue, Color.Red, Color.Yellow, Color.LightGreen);
                    GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int)y, (int)(faction.Reputation.NormalizedValue * 255), 10), color, isFilled: true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int)y, 256, 10), Color.White);
                    y += 15;
                }
            }

            Location location = Campaign.Map?.CurrentLocation;

            if (location?.Reputation != null)
            {
                string  name     = Campaign.Map?.CurrentLocation.Name;
                Vector2 nameSize = GUI.SmallFont.MeasureString(name);
                GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 264, y), name, Color.White, font: GUI.SmallFont);
                y += nameSize.Y + 5;

                float normalizedReputation = MathUtils.InverseLerp(location.Reputation.MinReputation, location.Reputation.MaxReputation, location.Reputation.Value);
                Color color = ToolBox.GradientLerp(normalizedReputation, Color.Red, Color.Yellow, Color.LightGreen);
                GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int)y, (int)(normalizedReputation * 255), 10), color, isFilled: true);
                GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int)y, 256, 10), Color.White);
            }

            richTextDatas.Clear();
        }
Beispiel #7
0
        protected override void Draw(SpriteBatch spriteBatch)
        {
            if (!Visible)
            {
                return;
            }

            Color currColor = GetColor(State);

            var rect = Rect;

            base.Draw(spriteBatch);

            if (TextGetter != null)
            {
                Text = TextGetter();
            }

            Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;

            if (overflowClipActive)
            {
                Rectangle scissorRect = new Rectangle(rect.X + (int)padding.X, rect.Y, rect.Width - (int)padding.X - (int)padding.Z, rect.Height);
                if (!scissorRect.Intersects(prevScissorRect))
                {
                    return;
                }
                spriteBatch.End();
                spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, scissorRect);
                spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
            }

            if (!string.IsNullOrEmpty(text))
            {
                Vector2 pos = rect.Location.ToVector2() + textPos + TextOffset;
                if (RoundToNearestPixel)
                {
                    pos.X = (int)pos.X;
                    pos.Y = (int)pos.Y;
                }

                Color currentTextColor = State == ComponentState.Hover || State == ComponentState.HoverSelected ? HoverTextColor : TextColor;
                if (!enabled)
                {
                    currentTextColor = disabledTextColor;
                }
                else if (State == ComponentState.Selected)
                {
                    currentTextColor = selectedTextColor;
                }

                if (!HasColorHighlight)
                {
                    string textToShow  = Censor ? censoredText : (Wrap ? wrappedText : text);
                    Color  colorToShow = currentTextColor * (currentTextColor.A / 255.0f);

                    if (Shadow)
                    {
                        Vector2 shadowOffset = new Vector2(GUI.IntScale(2));
                        Font.DrawString(spriteBatch, textToShow, pos + shadowOffset, Color.Black, 0.0f, origin, TextScale, SpriteEffects.None, textDepth);
                    }

                    Font.DrawString(spriteBatch, textToShow, pos, colorToShow, 0.0f, origin, TextScale, SpriteEffects.None, textDepth);
                }
                else
                {
                    if (OverrideRichTextDataAlpha)
                    {
                        RichTextData.ForEach(rt => rt.Alpha = currentTextColor.A / 255.0f);
                    }
                    Font.DrawStringWithColors(spriteBatch, Censor ? censoredText : (Wrap ? wrappedText : text), pos,
                                              currentTextColor * (currentTextColor.A / 255.0f), 0.0f, origin, TextScale, SpriteEffects.None, textDepth, RichTextData);
                }

                Strikethrough?.Draw(spriteBatch, (int)Math.Ceiling(TextSize.X / 2f), pos.X, ForceUpperCase ? pos.Y : pos.Y + GUI.Scale * 2f);
            }

            if (overflowClipActive)
            {
                spriteBatch.End();
                spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
                spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
            }

            if (OutlineColor.A * currColor.A > 0.0f)
            {
                GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
            }
        }
Beispiel #8
0
        public static List <RichTextData> GetRichTextData(string text, out string sanitizedText)
        {
            List <RichTextData> textColors = null;

            sanitizedText = text;
            if (!string.IsNullOrEmpty(text) && text.Contains(definitionIndicator))
            {
                text = text.Replace("\r", "");
                string[] segments = text.Split(definitionIndicator);

                sanitizedText = string.Empty;

                textColors = new List <RichTextData>();
                RichTextData tempData = null;

                int prevIndex = 0;
                int currIndex = 0;
                for (int i = 0; i < segments.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        sanitizedText += segments[i];
                        prevIndex      = currIndex;
                        currIndex     += segments[i].Replace("\n", "").Replace("\r", "").Length;
                    }
                    else
                    {
                        string[] attributes = segments[i].Split(attributeSeparator);
                        for (int j = 0; j < attributes.Length; j++)
                        {
                            if (attributes[j].Contains(endDefinition))
                            {
                                if (tempData != null)
                                {
                                    tempData.StartIndex = prevIndex;
                                    tempData.EndIndex   = currIndex - 1;
                                    textColors.Add(tempData);
                                }
                                tempData = null;
                            }
                            else if (attributes[j].StartsWith(colorDefinition))
                            {
                                if (tempData == null)
                                {
                                    tempData = new RichTextData();
                                }
                                string valueStr = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
                                if (valueStr.Equals("null", System.StringComparison.InvariantCultureIgnoreCase))
                                {
                                    tempData.Color = null;
                                }
                                else
                                {
                                    tempData.Color = XMLExtensions.ParseColor(valueStr);
                                }
                            }
                            else if (attributes[j].StartsWith(metadataDefinition))
                            {
                                if (tempData == null)
                                {
                                    tempData = new RichTextData();
                                }
                                tempData.Metadata = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
                            }
                        }
                    }
                }
            }

            return(textColors);
        }