Selaa lähdekoodia

HTML colors + more

Bepis 6 vuotta sitten
vanhempi
commit
a3aa3a23ba

+ 15 - 4
NTERA/Console/EraConsoleInstance.cs

@@ -1,6 +1,7 @@
 using System.Drawing;
 using System.Drawing;
 using System.Text;
 using System.Text;
 using System.Threading;
 using System.Threading;
+using MinorShift.Emuera.Content;
 using MinorShift.Emuera.GameProc;
 using MinorShift.Emuera.GameProc;
 using MinorShift.Emuera.Sub;
 using MinorShift.Emuera.Sub;
 using NTERA.Interop;
 using NTERA.Interop;
@@ -13,9 +14,16 @@ namespace NTERA.Console
 
 
 		public AutoResetEvent InputResetEvent { get; protected set; } = new AutoResetEvent(false);
 		public AutoResetEvent InputResetEvent { get; protected set; } = new AutoResetEvent(false);
 
 
+		public Color ForeColor = Color.White;
+
 		public void AddText(string text)
 		public void AddText(string text)
 		{
 		{
-			Renderer.AddItem(new TextRenderItem(text));
+			var item = new TextRenderItem(text, Alignment)
+			{
+				TextBrush = new SolidBrush(ForeColor)
+			};
+
+			Renderer.AddItem(item);
 		}
 		}
 
 
 		public void AddText(string text, Color color)
 		public void AddText(string text, Color color)
@@ -118,7 +126,7 @@ namespace NTERA.Console
 			printCustomBar("-");
 			printCustomBar("-");
 		}
 		}
 
 
-		public void PrintSingleLine(string line, bool something = false)
+		public void PrintSingleLine(string line, bool temporary = false)
 		{
 		{
 			AddText(line);
 			AddText(line);
 		}
 		}
@@ -159,7 +167,7 @@ namespace NTERA.Console
 			AddText(message);
 			AddText(message);
 		}
 		}
 
 
-		public DisplayLineAlignment Alignment { get; set; }
+		public DisplayLineAlignment Alignment { get; set; } = DisplayLineAlignment.LEFT;
 		public void deleteLine(int line)
 		public void deleteLine(int line)
 		{
 		{
 		}
 		}
@@ -234,7 +242,9 @@ namespace NTERA.Console
 
 
 		public void PrintImg(string img)
 		public void PrintImg(string img)
 		{
 		{
-			AddText(img);
+			var image = AppContents.GetContent<CroppedImage>(img);
+
+			Renderer.AddItem(new ImageRenderItem(image.BaseImage.Bitmap, image.Rectangle, alignment: Alignment));
 		}
 		}
 
 
 		public void PrintShape(string shape, int[] param)
 		public void PrintShape(string shape, int[] param)
@@ -262,6 +272,7 @@ namespace NTERA.Console
 
 
 		public void SetStringStyle(Color color)
 		public void SetStringStyle(Color color)
 		{
 		{
+			ForeColor = color;
 		}
 		}
 
 
 		public void SetStringStyle(FontStyle fontStyle)
 		public void SetStringStyle(FontStyle fontStyle)

+ 36 - 5
NTERA/Console/HTMLParser.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
 using System.Xml.Linq;
 using System.Xml.Linq;
 using MinorShift.Emuera.Content;
 using MinorShift.Emuera.Content;
@@ -11,16 +12,14 @@ namespace NTERA.Interop
 	{
 	{
 		public static IEnumerable<IRenderItem> ParseHtml(string html)
 		public static IEnumerable<IRenderItem> ParseHtml(string html)
 		{
 		{
-			var parent = new XElement("parent");
-
 			//fix broken HTML from shitty emuera format
 			//fix broken HTML from shitty emuera format
 			string fixedHtml = Regex.Replace(html, @"<img([^\/]*?)>", "<img$1 />");
 			string fixedHtml = Regex.Replace(html, @"<img([^\/]*?)>", "<img$1 />");
 			fixedHtml = fixedHtml.Replace("<br>", "<br/>");
 			fixedHtml = fixedHtml.Replace("<br>", "<br/>");
 			fixedHtml = fixedHtml.Replace("<nobr>", "<nobr/>");
 			fixedHtml = fixedHtml.Replace("<nobr>", "<nobr/>");
 
 
-			parent.Add(XElement.Parse(fixedHtml));
+			var element = XElement.Parse($"<parent>{fixedHtml}</parent>");
 
 
-			return ParseHtml_Internal(parent, HtmlStyle.Default);
+			return ParseHtml_Internal(element, HtmlStyle.Default);
 		}
 		}
 
 
 		private static IEnumerable<IRenderItem> ParseHtml_Internal(XElement xmlNode, HtmlStyle style)
 		private static IEnumerable<IRenderItem> ParseHtml_Internal(XElement xmlNode, HtmlStyle style)
@@ -56,12 +55,42 @@ namespace NTERA.Interop
 						renderItems.Add(new TextRenderItem(""));
 						renderItems.Add(new TextRenderItem(""));
 						break;
 						break;
 
 
+					case "nobr":
+						//renderItems.Add(new TextRenderItem(""));
+						break;
+
+					case "font":
+						string color = node.Attribute("color")?.Value;
+
+						if (color != null)
+						{
+							if (color.StartsWith("#"))
+							{
+								string colorHex = color.Substring(1).PadLeft(8, 'F');
+
+								localStyle.ForeColor = Color.FromArgb(Convert.ToInt32(colorHex, 16));
+							}
+							else
+								localStyle.ForeColor = Color.FromName(color);
+						}
+
+						renderItems.AddRange(ParseHtml_Internal(node, localStyle));
+						break;
+
+					case "nonbutton":
+						//renderItems.Add(new TextRenderItem(node.Value, color: localStyle.ForeColor, alignment: localStyle.Alignment));
+						renderItems.AddRange(ParseHtml_Internal(node, localStyle));
+						break;
+
 					default:
 					default:
-						renderItems.Add(new TextRenderItem(node.ToString(), alignment: localStyle.Alignment));
+						renderItems.Add(new TextRenderItem(node.ToString(), color: localStyle.ForeColor, alignment: localStyle.Alignment));
 						break;
 						break;
 				}
 				}
 			}
 			}
 
 
+			if (!xmlNode.HasElements && !string.IsNullOrWhiteSpace(xmlNode.Value))
+				renderItems.Add(new TextRenderItem(xmlNode.Value, color: localStyle.ForeColor, alignment: localStyle.Alignment));
+
 			return renderItems;
 			return renderItems;
 		}
 		}
 
 
@@ -71,6 +100,8 @@ namespace NTERA.Interop
 
 
 			public DisplayLineAlignment Alignment = DisplayLineAlignment.LEFT;
 			public DisplayLineAlignment Alignment = DisplayLineAlignment.LEFT;
 
 
+			public Color ForeColor = Color.White;
+
 			public HtmlStyle()
 			public HtmlStyle()
 			{
 			{
 
 

+ 4 - 1
NTERA/Console/RenderItem/TextRenderItem.cs

@@ -16,10 +16,13 @@ namespace NTERA.Console
 		public DisplayLineAlignment Alignment;
 		public DisplayLineAlignment Alignment;
 
 
 
 
-		public TextRenderItem(string text, DisplayLineAlignment alignment = DisplayLineAlignment.LEFT)
+		public TextRenderItem(string text, DisplayLineAlignment alignment = DisplayLineAlignment.LEFT, Color? color = null)
 		{
 		{
 			Text = text;
 			Text = text;
 			Alignment = alignment;
 			Alignment = alignment;
+			
+			if (color.HasValue)
+				TextBrush = new SolidBrush(color.Value);
 		}
 		}
 		
 		
 
 

+ 1 - 1
NTERA/Interop/IConsole.cs

@@ -25,7 +25,7 @@ namespace NTERA.Interop
 		bool noOutputLog { get; set; }
 		bool noOutputLog { get; set; }
 		void ThrowTitleError(bool something);
 		void ThrowTitleError(bool something);
 		void PrintBar();
 		void PrintBar();
-		void PrintSingleLine(string line, bool something = false);
+		void PrintSingleLine(string line, bool temporary = false);
 		void NewLine();
 		void NewLine();
 		void RefreshStrings(bool something);
 		void RefreshStrings(bool something);
 		void SetWindowTitle(string title);
 		void SetWindowTitle(string title);