/// <summary> /// Draws the in-game console, debug overlay, and any text queued by the DrawText() method. /// Also manages keyboard handling for enabling or disabling the Debug interface and interacting with the in-game console. /// </summary> public static void Draw() { if (instance == null) { instance = new Debug(); } if (IsKeyPressed(KeyboardKey.KEY_F1)) { if (Enabled) { Enabled = false; ConsoleIsOpen = false; } else { Enabled = true; } } if (IsKeyPressed(KeyboardKey.KEY_GRAVE) && Enabled) { ConsoleIsOpen = !ConsoleIsOpen; } if (instance == null) { return; } if (!Enabled) { if (instance.consoleLines.Count > instance.consoleMaxLines * 2) { for (int i = 0; i < instance.consoleMaxLines; i++) { instance.consoleLinesBuffer.Push(instance.consoleLines.Pop()); } instance.consoleLines.Clear(); while (instance.consoleLinesBuffer.Count > 0) { instance.consoleLines.Push(instance.consoleLinesBuffer.Pop()); } Debug.WriteLine("Trimmed debug console"); } } if (!instance.initialized) { instance.font = ResourceManager.Get <FontResource>(@"fonts\Perfect_DOS_VGA_437_Win").Font; instance.initialized = true; } // ------------------------------------------------------------------------------------ framerate += Math.Max(GetFPS() + 0.5, 0); framerate = Math.Round(framerate / 2); Debug.WriteOverlay("FPS: " + Convert.ToString((int)framerate, null)); Vector2 p = new Vector2(); lock (instance.shapeJobs) { while (instance.shapeJobs.Count > 0) { DrawShapeJob j = instance.shapeJobs.Dequeue(); if (j.ShapeType == Shapes.Line) { Raylib.DrawLine(j.A, j.B, j.C, j.D, j.Color); } else if (j.ShapeType == Shapes.Rectangle) { Raylib.DrawRectangle(j.A, j.B, j.C, j.D, j.Color); } } } if (instance.consoleSize > 0) { UpdateTerminal(); DrawRectangle(0, 0, GetScreenWidth(), instance.consoleSize, instance.backgroundColor); DrawLineEx(new Vector2(0, instance.consoleSize + 1), new Vector2(GetScreenWidth(), instance.consoleSize + 1), 2, Color.WHITE); DrawLineEx(new Vector2(0, instance.consoleSize - instance.consoleFontSize - 1), new Vector2(GetScreenWidth(), instance.consoleSize - instance.consoleFontSize - 1), 1, Color.GRAY); DrawTextEx(instance.font, terminalBuffer.Insert(terminalCursor, showCursor ? "_" : " "), new Vector2(4, instance.consoleSize - instance.consoleFontSize - 1), instance.consoleFontSize, 1.0f, instance.foregroundColor); lock (instance.consoleLines) { p.X = 4; p.Y = instance.consoleSize - (instance.consoleFontSize * 2) - 2; int count = instance.consoleLines.Count; for (int i = 0; i < Math.Min(instance.consoleMaxLines, count); i++) { string line = instance.consoleLines.Pop(); string originalLine = line; if (i >= consoleLinesOffset) { string tag = ""; if (line.StartsWith("%", StringComparison.Ordinal)) { string[] tokens = line.Split('%'); if (tokens.Length > 2) { line = ""; for (int j = 2; j < tokens.Length; j++) { line += ((j > 2) ? "%" : "") + tokens[j]; } tag = tokens[1].ToUpper(System.Globalization.CultureInfo.InvariantCulture); } } if (p.Y > -instance.consoleFontSize) { if (!string.IsNullOrEmpty(tag)) { Color c = instance.backgroundColorAlt; if (tag == "SUCCESS") { c = new Color(0, 255, 0, 64); } else if (tag == "WARNING") { c = new Color(255, 255, 0, 64); } else if (tag == "ERROR") { c = new Color(255, 0, 0, 64); } DrawRectangle((int)p.X - 2, (int)p.Y + 1, GetScreenWidth() - 2, instance.consoleFontSize - 1, c); } DrawTextEx(instance.font, line, p, instance.consoleFontSize, 1.0f, instance.foregroundColor); } p.Y -= instance.consoleFontSize; } instance.consoleLinesBuffer.Push(originalLine); } instance.consoleLines.Clear(); while (instance.consoleLinesBuffer.Count > 0) { instance.consoleLines.Push(instance.consoleLinesBuffer.Pop()); } } } if (ConsoleIsOpen && instance.consoleSize < instance.consoleMaxSize) { instance.consoleSize += 8; } if (!ConsoleIsOpen && instance.consoleSize > 0) { instance.consoleSize -= 8; } lock (instance.textJobs) { while (instance.textJobs.Count > 0) { DrawTextJob j = instance.textJobs.Dequeue(); if (j.Y > instance.consoleSize) { p.X = j.X - 1; p.Y = j.Y - 1; DrawTextEx(instance.font, j.Text, p, j.Size, 1.0f, instance.outlineColor); p.X = j.X + 1; p.Y = j.Y + 1; DrawTextEx(instance.font, j.Text, p, j.Size, 1.0f, instance.outlineColor); p.X = j.X - 1; p.Y = j.Y + 1; DrawTextEx(instance.font, j.Text, p, j.Size, 1.0f, instance.outlineColor); p.X = j.X + 1; p.Y = j.Y - 1; DrawTextEx(instance.font, j.Text, p, j.Size, 1.0f, instance.outlineColor); p.X = j.X; p.Y = j.Y; DrawTextEx(instance.font, j.Text, p, j.Size, 1.0f, Color.BLACK); } } } lock (instance.overlayLines) { p.Y = instance.consoleSize + (instance.consoleFontSize * 0.25f); p.X = 4; while (instance.overlayLines.Count > 0) { string line = instance.overlayLines.Dequeue(); DrawRectangle((int)p.X - 2, (int)p.Y - 1, (int)((line.Length * instance.consoleFontSize * 0.66f) - 2), instance.consoleFontSize - 1, instance.outlineColor); DrawTextEx(instance.font, line, p, instance.consoleFontSize, 1.0f, Color.BLACK); p.Y += instance.consoleFontSize; } } if (instance.logLines.Count > 0) { using StreamWriter stream = new FileInfo(logfileName.Replace("#", "0")).AppendText(); while (instance.logLines.Count > 0) { stream.WriteLine(instance.logLines.Dequeue()); } } }
public static SpaceShip FromXml(XmlResource Xml, SpaceShip DstObject) { if (Xml == null) { throw new ArgumentNullException("Xml"); } SpaceShip Result = DstObject; if (DstObject == null) { Result = new SpaceShip(); } Result = SpaceObject.FromXml(Xml, Result) as SpaceShip; XmlNode obj = Xml.Xml.LastChild; string baseName = GetXmlText(obj, "Base", string.Empty); SpaceShip baseObject = Result; if (!string.IsNullOrEmpty(baseName)) { try { baseObject = SpaceShip.FromXml(ResourceManager.Get <XmlResource>(baseName), null); } catch (KeyNotFoundException e) { baseObject = Result; Console.WriteLine("XML Error: Failed to locate XML base " + baseName); } } Result.Hull = GetXmlValue(obj, "Hull", baseObject.Hull); Result.Shield = GetXmlValue(obj, "Shield", baseObject.Shield); Result.MaxHull = GetXmlValue(obj, "MaxHull", baseObject.MaxHull); Result.MaxShield = GetXmlValue(obj, "MaxShield", baseObject.MaxShield); Result.ShieldRegen = GetXmlValue(obj, "ShieldRegen", baseObject.ShieldRegen); Result.MaxThrust = GetXmlValue(obj, "MaxThrust", baseObject.MaxThrust); Result.TurnSpeed = GetXmlValue(obj, "TurnSpeed", baseObject.TurnSpeed); Result.RateOfFire = GetXmlValue(obj, "RateOfFire", baseObject.RateOfFire); Result.ShieldRebootProbability = (int)GetXmlValue(obj, "ShieldRebootProbability", baseObject.ShieldRebootProbability); Result.Texture = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", baseObject.Texture.Name)); //Result.Hitbox = Hitbox.Automatic(Result.Texture, (int)Math.Max(2, Result.Scale * Result.Texture.Texture.height / 8)); List <SpaceObject> hardpoints = GetXmlNested(obj, "Hardpoints", null); if (hardpoints != null && hardpoints.Count > 0) { Result.Hardpoints = new List <SpaceShipHardpoint>(); foreach (SpaceObject o in hardpoints) { SpaceShipHardpoint hp = o as SpaceShipHardpoint; if (hp != null) { hp.Parent = Result; hp.Depth += Result.Depth; hp.Scale *= Result.Scale; Result.Hardpoints.Add(hp); } } Debug.WriteLine("Loaded hardpoints"); } return(Result); }