Переглянути джерело

Add --fontsize option to change, er, the fontsize

StuffedAnon 6 роки тому
батько
коміт
72390ad5cc

+ 12 - 4
NTERA/Console/ConsoleRenderer.cs

@@ -14,7 +14,7 @@ namespace NTERA.Console
 		public List<List<IRenderItem>> Items { get; protected set; } = new List<List<IRenderItem>>();
 
 		public List<Rectangle> UpdateRegions = new List<Rectangle>();
-		
+
 		public int offset;
 
 		public int LastLineCount;
@@ -24,13 +24,21 @@ namespace NTERA.Console
 
 		private Brush backgroundBrush = new SolidBrush(Color.Black);
 
+		public Font Font;
+
 		private Control control;
 
 		public ConsoleRenderer(Control control)
 		{
 			this.control = control;
 			Items.Add(new List<IRenderItem>());
-			LineHeight = (int)(new Font("MS UI Gothic", 12)).GetHeight();
+			SetFontSize(12);
+		}
+
+		public void SetFontSize(int fontSize)
+		{
+			Font = new Font("MS UI Gothic", fontSize);
+			LineHeight = (int)(Font.GetHeight());
 		}
 
 		private void WriteTextItem(TextRenderItem item)
@@ -128,7 +136,7 @@ namespace NTERA.Console
 					control.Invalidate(item.Region, true);
 					lastUpdateRange = item.Region;
 				}
-							
+
 				return;
 			}
 
@@ -139,4 +147,4 @@ namespace NTERA.Console
 			}
 		}
 	}
-}
+}

+ 5 - 3
NTERA/Console/EraConsoleInstance.cs

@@ -16,11 +16,12 @@ namespace NTERA.Console
 
 		public Color DefaultForeColor = Color.White;
 		public Color ForeColor = Color.White;
+		public Font Font;
 
 		public void AddText(string text, PrintFlags? flags = null, Color? color = null)
 		{
 			var flags_ = flags ?? new PrintFlags { NewLine = true };
-			var item = new TextRenderItem(text)
+			var item = new TextRenderItem(text, Font)
 			{
 				TextBrush = new SolidBrush(color ?? (flags_.NoColor ? DefaultForeColor : ForeColor)),
 				Alignment = Alignment,
@@ -42,6 +43,7 @@ namespace NTERA.Console
 		{
 			Renderer = renderer;
 			ScriptEngine = scriptEngine;
+			Font = renderer.Font;
 		}
 
 		public InputRequest CurrentRequest { get; set; }
@@ -241,7 +243,7 @@ namespace NTERA.Console
 
 		public void PrintHtml(string html, bool newline)
 		{
-			foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage))
+			foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage, Font))
 				Renderer.WriteItem(item);
 		}
 
@@ -256,7 +258,7 @@ namespace NTERA.Console
 		{
 			AddText(shape);
 		}
-        
+
 		public void DebugPrint(string message)
 		{
 			AddText(message);

+ 11 - 11
NTERA/Console/HTMLParser.cs

@@ -12,7 +12,7 @@ namespace NTERA.Console
 {
 	public static class HtmlParser
 	{
-		public static IEnumerable<IRenderItem> ParseHtml(string html, Func<string, CroppedImage> assetFunc)
+		public static IEnumerable<IRenderItem> ParseHtml(string html, Func<string, CroppedImage> assetFunc, Font font)
 		{
 			//fix broken HTML from shitty emuera format
 			string fixedHtml = Regex.Replace(html, @"<img([^\/]*?)>", "<img$1 />");
@@ -21,10 +21,10 @@ namespace NTERA.Console
 
 			var element = XElement.Parse($"<parent>{fixedHtml}</parent>");
 
-			return ParseHtml_Internal(element, assetFunc, HtmlStyle.Default);
+			return ParseHtml_Internal(element, assetFunc, HtmlStyle.Default, font);
 		}
 
-		private static IEnumerable<IRenderItem> ParseHtml_Internal(XElement xmlNode, Func<string, CroppedImage> assetFunc, HtmlStyle style)
+		private static IEnumerable<IRenderItem> ParseHtml_Internal(XElement xmlNode, Func<string, CroppedImage> assetFunc, HtmlStyle style, Font font)
 		{
 			List<IRenderItem> renderItems = new List<IRenderItem>();
 			HtmlStyle localStyle = (HtmlStyle)style.Clone();
@@ -39,7 +39,7 @@ namespace NTERA.Console
 						if (alignment != null)
 							localStyle.Alignment = (DisplayLineAlignment)Enum.Parse(typeof(DisplayLineAlignment), alignment.ToUpper());
 
-						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle));
+						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle, font));
 						break;
 
 					case "img":
@@ -54,11 +54,11 @@ namespace NTERA.Console
 						break;
 
 					case "br":
-						renderItems.Add(new TextRenderItem(""));
+						renderItems.Add(new TextRenderItem("", font));
 						break;
 
 					case "nobr":
-						//renderItems.Add(new TextRenderItem(""));
+						//renderItems.Add(new TextRenderItem("", font));
 						break;
 
 					case "font":
@@ -76,22 +76,22 @@ namespace NTERA.Console
 								localStyle.ForeColor = Color.FromName(color);
 						}
 
-						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle));
+						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle, font));
 						break;
 
 					case "nonbutton":
-						//renderItems.Add(new TextRenderItem(node.Value, color: localStyle.ForeColor, alignment: localStyle.Alignment));
-						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle));
+						//renderItems.Add(new TextRenderItem(node.Value, font, color: localStyle.ForeColor, alignment: localStyle.Alignment));
+						renderItems.AddRange(ParseHtml_Internal(node, assetFunc, localStyle, font));
 						break;
 
 					default:
-						renderItems.Add(new TextRenderItem(node.ToString(), color: localStyle.ForeColor, alignment: localStyle.Alignment));
+						renderItems.Add(new TextRenderItem(node.ToString(), font, color: localStyle.ForeColor, alignment: localStyle.Alignment));
 						break;
 				}
 			}
 
 			if (!xmlNode.HasElements && !string.IsNullOrWhiteSpace(xmlNode.Value))
-				renderItems.Add(new TextRenderItem(xmlNode.Value, color: localStyle.ForeColor, alignment: localStyle.Alignment));
+				renderItems.Add(new TextRenderItem(xmlNode.Value, font, color: localStyle.ForeColor, alignment: localStyle.Alignment));
 
 			return renderItems;
 		}

+ 4 - 3
NTERA/Console/RenderItem/ButtonTextRenderItem.cs

@@ -5,7 +5,7 @@ namespace NTERA.Console.RenderItem
 {
 	public class ButtonTextRenderItem : BaseRenderItem
 	{
-		public static Font Font { get; set; } = new Font("MS UI Gothic", 12); //new Font("Arial", 12);
+		public static Font Font { get; set; } //new Font("Arial", 12);
 
 		public static SolidBrush TextBrush = new SolidBrush(Color.White);
 
@@ -15,8 +15,9 @@ namespace NTERA.Console.RenderItem
 
 		public override bool InvalidateOnMouseStateChange => true;
 
-		public ButtonTextRenderItem(string text)
+		public ButtonTextRenderItem(string text, Font font)
 		{
+			Font = font;
 			Text = text.Replace(" ", "  ");
 		}
 
@@ -31,4 +32,4 @@ namespace NTERA.Console.RenderItem
 			return TextRenderer.MeasureText(graphics, Text, Font).Width + renderArea.X;
 		}
 	}
-}
+}

+ 8 - 7
NTERA/Console/RenderItem/TextRenderItem.cs

@@ -10,7 +10,7 @@ namespace NTERA.Console.RenderItem
 {
 	public class TextRenderItem : BaseRenderItem
 	{
-		public Font Font { get; set; } = new Font("MS UI Gothic", 12);
+		public Font Font { get; set; }
 
 		public SolidBrush TextBrush { get; set; } = new SolidBrush(Color.White);
 
@@ -33,15 +33,16 @@ namespace NTERA.Console.RenderItem
 		}
 
 
-		public TextRenderItem(string text, DisplayLineAlignment alignment = DisplayLineAlignment.LEFT, Color? color = null)
+		public TextRenderItem(string text, Font font, DisplayLineAlignment alignment = DisplayLineAlignment.LEFT, Color? color = null)
 		{
 			Text = AlignText(text); //text.Replace(" ", "    ").Replace("6", " 6"); //" 6   ", " 6  "
 			Alignment = alignment;
-			
+			Font = font;
+
 			if (color.HasValue)
 				TextBrush = new SolidBrush(color.Value);
 		}
-		
+
 
 		public override int Render(Graphics graphics, Rectangle renderArea, Rectangle invalidatedArea, Point mousePointer)
 		{
@@ -82,16 +83,16 @@ namespace NTERA.Console.RenderItem
 			return TextRenderer.MeasureText(graphics, Text, Font).Width + renderArea.X;
 		}
 
-		public static List<TextRenderItem> CreateFromLinedText(string text)
+		public static List<TextRenderItem> CreateFromLinedText(string text, Font font)
 		{
 			List<TextRenderItem> items = new List<TextRenderItem>();
 
 			foreach (string line in text.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
 			{
-				items.Add(new TextRenderItem(line));
+				items.Add(new TextRenderItem(line, font));
 			}
 
 			return items;
 		}
 	}
-}
+}

+ 1 - 0
NTERA/Options.cs

@@ -5,5 +5,6 @@ namespace NTERA
 	{
         public bool IgnoreErrors = false;
         public string EraFolder = null;
+        public int FontSize = 12;
     }
 }

+ 16 - 5
NTERA/Program.cs

@@ -17,17 +17,28 @@ namespace NTERA
 				options.EraFolder = Environment.CurrentDirectory;
 			}
 
-			foreach(var arg in args)
-			{
+			for (var i = 0; i < args.Length; i++) {
+				var arg = args[i];
 				if (arg == "--ignoreerrors") {
 					options.IgnoreErrors = true;
 				}
+				else if (arg == "--fontsize") {
+					++i;
+					int fontsize;
+					if (i >= args.Length || !Int32.TryParse(args[i], out fontsize)) {
+						System.Console.Write($"Need to specify fontsize (currently {options.FontSize}), e.g.  --fontsize 12\n");
+						return;
+					}
+
+					options.FontSize = fontsize;
+				}
 				else if (arg == "--help" || arg == "-h" || arg == "/?") {
-					System.Console.Write(@"
+					System.Console.Write($@"
 NTERA - An ERA game engine, implemented in .net:
 	[path to era game]
-	--help           - This help message
-	--ignoreerrors   - Do not stop on missing function errors etc. (Will likely break the game!)
+	--help            - This help message
+	--ignoreerrors    - Do not stop on missing function errors etc. (Will likely break the game!)
+	--fontsize <size> - Set the font size (Currently {options.FontSize})
 					");
 					return;
 				}

+ 2 - 1
NTERA/formMain.cs

@@ -17,6 +17,7 @@ namespace NTERA
 		public formMain(Options options)
 		{
 			InitializeComponent();
+			consoleControl1.Renderer.SetFontSize(options.FontSize);
 
             //var scriptEngine = new EmuEraGameInstance();
             //var scriptEngine = new Engine();
@@ -38,4 +39,4 @@ namespace NTERA
 			}
 		}
 	}
-}
+}