/// <summary> /// Draws the string on the console at the specified location, wrapping if needed. /// </summary> /// <param name="x">X location of the text.</param> /// <param name="y">Y location of the text.</param> /// <param name="text">The string to display.</param> public void Print(int x, int y, string text) { if (String.IsNullOrEmpty(text)) { return; } if (x >= textSurface.Width || x < 0 || y >= textSurface.Height || y < 0) { throw new Exception("X,Y is out of range for Print"); } int index = y * textSurface.Width + x; if (!UsePrintProcessor) { int total = index + text.Length > textSurface.Cells.Length ? textSurface.Cells.Length - index : index + text.Length; int charIndex = 0; for (; index < total; index++) { textSurface.Cells[index].Glyph = text[charIndex]; charIndex++; } } else { PrintNoCheck(index, ColoredString.Parse(text, index, textSurface, this)); } textSurface.IsDirty = true; }
/// <summary> /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground and background, setting the ignore properties if needed. /// </summary> /// <param name="value">The current string.</param> /// <param name="foreground">The foreground color. If null, <see cref="ColoredString.IgnoreForeground"/> will be set.</param> /// <param name="background">The background color. If null, <see cref="ColoredString.IgnoreBackground"/> will be set.</param> /// <param name="spriteEffect">The background color. If null, <see cref="ColoredString.IgnoreEffect"/> will be set.</param> /// <returns>A <see cref="ColoredString"/> object instace.</returns> public static ColoredString CreateColored(this string value, Color?foreground = null, Color?background = null) { var stacks = new ParseCommandStacks(); if (foreground.HasValue) { stacks.AddSafe(new ParseCommandRecolor() { R = foreground.Value.R, G = foreground.Value.G, B = foreground.Value.B, A = foreground.Value.A, CommandType = CommandTypes.Foreground }); } if (background.HasValue) { stacks.AddSafe(new ParseCommandRecolor() { R = background.Value.R, G = background.Value.G, B = background.Value.B, A = background.Value.A, CommandType = CommandTypes.Background }); } ColoredString newString = ColoredString.Parse(value, initialBehaviors: stacks); if (!foreground.HasValue) { newString.IgnoreForeground = true; } if (!background.HasValue) { newString.IgnoreBackground = true; } return(newString); }
/// <summary> /// Draws the string on the console at the specified location with the specified settings. /// </summary> /// <param name="x">X location of the text.</param> /// <param name="y">Y location of the text.</param> /// <param name="text">The string to display.</param> /// <param name="foreground">Sets the foreground of all characters in the text.</param> /// <param name="background">Sets the background of all characters in the text.</param> /// <param name="spriteEffect">The sprite effect to set on the cell.</param> public void Print(int x, int y, string text, Color?foreground = null, Color?background = null) { if (String.IsNullOrEmpty(text)) { return; } if (x >= textSurface.Width || x < 0 || y >= textSurface.Height || y < 0) { throw new Exception("X,Y is out of range for Print"); } int index = y * textSurface.Width + x; if (!UsePrintProcessor) { int total = index + text.Length > textSurface.Cells.Length ? textSurface.Cells.Length - index : index + text.Length; int charIndex = 0; for (; index < total; index++) { textSurface.Cells[index].GlyphIndex = text[charIndex]; if (background.HasValue) { textSurface.Cells[index].Background = background.Value; } if (foreground.HasValue) { textSurface.Cells[index].Foreground = foreground.Value; } charIndex++; } } else { var stacks = new ParseCommandStacks(); if (foreground.HasValue) { stacks.AddSafe(new ParseCommandRecolor() { R = foreground.Value.R, G = foreground.Value.G, B = foreground.Value.B, A = foreground.Value.A, CommandType = CommandTypes.Foreground }); } if (background.HasValue) { stacks.AddSafe(new ParseCommandRecolor() { R = background.Value.R, G = background.Value.G, B = background.Value.B, A = background.Value.A, CommandType = CommandTypes.Background }); } PrintNoCheck(index, ColoredString.Parse(text, index, textSurface, this, stacks)); } }
/// <summary> /// Prints text on the console. /// </summary> /// <param name="text">The text to print.</param> /// <param name="template">The way the text will look when it is printed.</param> /// <param name="templateEffect">Effect to apply to the text as its printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template) { ColoredString coloredString; if (UseStringParser) { var console = (SurfaceEditor)_console.Target; coloredString = ColoredString.Parse(text, _position.Y * console.TextSurface.Width + _position.X, console.TextSurface, console, new StringParser.ParseCommandStacks()); } else { coloredString = text.CreateColored(template.Foreground, template.Background); } return(Print(coloredString)); }
/// <summary> /// Draws the string on the console at the specified location with the specified foreground and background color, wrapping if needed. /// </summary> /// <param name="x">X location of the text.</param> /// <param name="y">Y location of the text.</param> /// <param name="text">The string to display.</param> /// <param name="foreground">Sets the foreground of all characters in the text.</param> /// <param name="background">Sets the background of all characters in the text.</param> public void Print(int x, int y, string text, Color foreground, Color background) { if (String.IsNullOrEmpty(text)) { return; } if (x >= textSurface.Width || x < 0 || y >= textSurface.Height || y < 0) { throw new Exception("X,Y is out of range for Print"); } int index = y * textSurface.Width + x; if (!UsePrintProcessor) { int total = index + text.Length > textSurface.Cells.Length ? textSurface.Cells.Length - index : index + text.Length; int charIndex = 0; for (; index < total; index++) { textSurface.Cells[index].Glyph = text[charIndex]; textSurface.Cells[index].Background = background; textSurface.Cells[index].Foreground = foreground; charIndex++; } } else { var behaviorFore = new ParseCommandRecolor() { R = foreground.R, G = foreground.G, B = foreground.B, A = foreground.A, CommandType = CommandTypes.Foreground }; var behaviorBack = new ParseCommandRecolor() { R = background.R, G = background.G, B = background.B, A = background.A, CommandType = CommandTypes.Background }; var stacks = new ParseCommandStacks(); stacks.AddSafe(behaviorFore); stacks.AddSafe(behaviorBack); PrintNoCheck(index, ColoredString.Parse(text, index, textSurface, this, stacks)); } textSurface.IsDirty = true; }
public (ColoredString title, ColoredString attributes) GetColoredString() { StringBuilder modifierString = new StringBuilder(20); if (AttackModifier > 0) { modifierString.Append($" [c:r f:InvGreen]A+{AttackModifier}"); } else if (AttackModifier < 0) { modifierString.Append($" [c:r f:InvRed]A{AttackModifier}"); } if (DefenseModifier > 0) { modifierString.Append($" [c:r f:InvGreen]D+{DefenseModifier}"); } else if (DefenseModifier < 0) { modifierString.Append($" [c:r f:InvRed]D{DefenseModifier}"); } if (HealthModifier > 0) { modifierString.Append($" [c:r f:InvGreen]H+{HealthModifier}"); } else if (HealthModifier < 0) { modifierString.Append($" [c:r f:InvRed]H{HealthModifier}"); } if (LightingModifier > 0) { modifierString.Append($" [c:r f:InvGreen]L+{LightingModifier}"); } else if (LightingModifier < 0) { modifierString.Append($" [c:r f:InvRed]L{LightingModifier}"); } return(Title.CreateColored(), ColoredString.Parse(modifierString.ToString())); }
private void DrawThemeParts() { SadConsole.UI.Colors colors = Controls.GetThemeColors(); Surface.Clear(_themePartsArea); int y = _themePartsArea.Y; int themeY = 0; UpdateColors(); AdjustableColor selectedSetting = _themeParts[_themePartSelectedIndex]; for (int i = 0; i < _themeParts.Length; i++) { int row = y + i; if (i == _themePartSelectedIndex) { themeY = row; Surface.Print(3, row, ColoredString.Parse(GetThemePartString(selectedSetting.ComputedColor, selectedSetting.Name.Replace("Control ", "")))); Surface.SetGlyph(2, row, ICellSurface.ConnectedLineThin[0], colors.Lines); Surface.DrawLine(new Point(2, row + 1), (_themePartsArea.MaxExtentX, row + 1), ICellSurface.ConnectedLineThin[0], colors.Lines); Surface.DrawLine(new Point(_themePartsArea.MaxExtentX, row + 1), new Point(_themePartsArea.MaxExtentX, row + _themePartSelectedAreaSize), ICellSurface.ConnectedLineThin[0], colors.Lines); Surface.DrawLine(new Point(_themePartsArea.MaxExtentX, row + _themePartSelectedAreaSize + 1), new Point(2, row + _themePartSelectedAreaSize + 1), ICellSurface.ConnectedLineThin[0], colors.Lines); y += _themePartSelectedAreaSize + 1; } else { Surface.Print(3, row, ColoredString.Parse(GetThemePartString(_themeParts[i].ComputedColor, _themeParts[i].Name.Replace("Control ", "")))); Surface.SetGlyph(2, row, ICellSurface.ConnectedLineThin[0], colors.Lines); } } // Connect all the lines for the selected theme area Surface.ConnectLines(ICellSurface.ConnectedLineThin, _themePartsArea); // Draw the shade selection area _themePartsShadeBoxes = new TextField(new Point(_themePartsArea.MaxExtentX - 10, themeY + 3), 10, Surface); var colorPreviewText = new TextField(_themePartsShadeBoxes.Position.WithY(themeY + 2), 5, Surface); var colorPreviewBarsText = new TextField(new Point(colorPreviewText.Position.X + colorPreviewText.Width, themeY + 2), 5, Surface); var shadePreviewBarsText = new TextField(_themePartsShadeBoxes.Position.WithY(themeY + 4), 5, Surface); var shadePreviewText = new TextField(new Point(shadePreviewBarsText.Position.X + shadePreviewBarsText.Width, themeY + 4), 5, Surface); var intoColorPreviewText = new TextField(new Point(colorPreviewText.Position.X - 3, colorPreviewText.Position.Y), 3, Surface); var intoColorPreviewString = new ColoredString(3); intoColorPreviewString.SetForeground(colors.Lines); intoColorPreviewString.SetGlyph(ICellSurface.ConnectedLineThin[(int)ICellSurface.ConnectedLineIndex.Top]); var colorPreviewString = new ColoredString(5); colorPreviewString.SetForeground(selectedSetting.BaseColor); colorPreviewString[0].Glyph = 301; colorPreviewString[1].Glyph = 303; colorPreviewString[2].Glyph = 303; colorPreviewString[3].Glyph = 303; colorPreviewString[4].Glyph = 302; var colorPreviewBarsString = new ColoredString(5); colorPreviewBarsString.SetForeground(colors.Lines); colorPreviewBarsString.SetGlyph(ICellSurface.ConnectedLineThin[(int)ICellSurface.ConnectedLineIndex.Top]); colorPreviewBarsString[4].Glyph = ICellSurface.ConnectedLineThin[(int)ICellSurface.ConnectedLineIndex.TopRight]; var shadeBarsString = new ColoredString(10); shadeBarsString[0].Glyph = 299; shadeBarsString[0].Foreground = selectedSetting.BaseColor.GetBrightest(); shadeBarsString[1].Glyph = 300; shadeBarsString[1].Foreground = selectedSetting.BaseColor.GetBrightest(); shadeBarsString[2].Glyph = 299; shadeBarsString[2].Foreground = selectedSetting.BaseColor.GetBright(); shadeBarsString[3].Glyph = 300; shadeBarsString[3].Foreground = selectedSetting.BaseColor.GetBright(); shadeBarsString[4].Glyph = 299; shadeBarsString[4].Foreground = selectedSetting.BaseColor; shadeBarsString[5].Glyph = 300; shadeBarsString[5].Foreground = selectedSetting.BaseColor; shadeBarsString[6].Glyph = 299; shadeBarsString[6].Foreground = selectedSetting.BaseColor.GetDark(); shadeBarsString[7].Glyph = 300; shadeBarsString[7].Foreground = selectedSetting.BaseColor.GetDark(); shadeBarsString[8].Glyph = 299; shadeBarsString[8].Foreground = selectedSetting.BaseColor.GetDarkest(); shadeBarsString[9].Glyph = 300; shadeBarsString[9].Foreground = selectedSetting.BaseColor.GetDarkest(); var shadePreviewBarsString = new ColoredString(5); shadePreviewBarsString.SetForeground(colors.Lines); shadePreviewBarsString.SetGlyph(ICellSurface.ConnectedLineThin[(int)ICellSurface.ConnectedLineIndex.Top]); shadePreviewBarsString[0].Glyph = ICellSurface.ConnectedLineThin[(int)ICellSurface.ConnectedLineIndex.BottomLeft]; var shadePreviewString = new ColoredString(5); shadePreviewString.SetForeground(selectedSetting.ComputedColor); shadePreviewString[0].Glyph = 301; shadePreviewString[1].Glyph = 303; shadePreviewString[2].Glyph = 303; shadePreviewString[3].Glyph = 303; shadePreviewString[4].Glyph = 302; intoColorPreviewText.Print(intoColorPreviewString); colorPreviewText.Print(colorPreviewString); colorPreviewBarsText.Print(colorPreviewBarsString); shadePreviewBarsText.Print(shadePreviewBarsString); shadePreviewText.Print(shadePreviewString); // Position the controls _themePartSettingColorSet.Position = (3, themeY + 2); _themePartSettingIsPredefinedColor.Position = (3, themeY + 3); _themePartSettingIsCustomColor.Position = (3, themeY + 4); _themePartSettingColorSet.IsVisible = true; _themePartSettingIsCustomColor.IsVisible = true; _themePartSettingIsPredefinedColor.IsVisible = true; // Configure controls/shade _themePartSettingIsCustomColor.IsSelected = selectedSetting.IsCustomColor; _themePartSettingIsPredefinedColor.IsSelected = !selectedSetting.IsCustomColor; switch (selectedSetting.Brightness) { case Colors.Brightness.Brightest: shadeBarsString[0].Glyph = 301; shadeBarsString[1].Glyph = 302; break; case Colors.Brightness.Bright: shadeBarsString[2].Glyph = 301; shadeBarsString[3].Glyph = 302; break; case Colors.Brightness.Normal: shadeBarsString[4].Glyph = 301; shadeBarsString[5].Glyph = 302; break; case Colors.Brightness.Dark: shadeBarsString[6].Glyph = 301; shadeBarsString[7].Glyph = 302; break; case Colors.Brightness.Darkest: shadeBarsString[8].Glyph = 301; shadeBarsString[9].Glyph = 302; break; default: break; } _themePartsShadeBoxes.Print(shadeBarsString); Controls.IsDirty = true; }