public override string ToString() { TextCanvas canvas = new TextCanvas(this.Width, this.Height, TextCanvas.NumOfColorsEnum.XTERM256); canvas.DrawRawData(0, 0, buffer); return(canvas.ToString()); }
public string GetInfo() { string baseDir = "./Messages/Citys/"; string spfile = "p1.png.MII"; TextCanvas canvas = new TextCanvas(screenWidth, 18, TextCanvas.NumOfColorsEnum.XTERM256); StringBuilder sBuilder = new StringBuilder(); canvas.FillRectangle(0, 0, 44, 18, 234); string tileFilename = Path.Combine(baseDir, spfile); var img = Messages.Message.ReadMII2File(tileFilename); img.Write(2, 2, canvas); canvas.DrawString(45, 1, string.Format("Port: {0}", SpacePort.Name), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(45, 2, string.Format("Planet: {0}", SpacePort.Body.PlanetName), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(45, 3, string.Format("Planet Sector: {0}", SpacePort.PlanetSector), (byte)ANSI.ANSIColor_16.Cyan, 0); sBuilder.AppendLine(canvas.ToString()); return(sBuilder.ToString()); }
public string GetInfo() { string baseDir = "./Messages/Planets"; string filename = string.Empty; switch (Planet.BodyType) { case SystemBodyType.Asteroid: filename = "AS.MII"; break; case SystemBodyType.RockyWorld: filename = "R.MII"; break; case SystemBodyType.RockyPlanetoid: filename = "R2.MII"; break; case SystemBodyType.Inferno: filename = "I.MII"; break; case SystemBodyType.Venuzian: filename = "V.MII"; break; case SystemBodyType.Terrestrial: filename = "T.MII"; break; case SystemBodyType.WaterWorld: filename = "W.MII"; break; case SystemBodyType.IceWorld: filename = "W2.MII"; break; case SystemBodyType.GasGiant: filename = "GS.MII"; break; case SystemBodyType.RingedGasGiant: filename = "GS2.MII"; break; case SystemBodyType.SubGasGiant: filename = "GS3.MII"; break; default: filename = "R.MII"; break; } //get the star ansi image; filename = Path.Combine(baseDir, filename); var starFile = Messages.Message.ReadMII2File(filename); TextCanvas canvas = new TextCanvas(screenWidth, starFile.Height, TextCanvas.NumOfColorsEnum.XTERM256); starFile.Write(0, 0, canvas); canvas.DrawString(40, canvas.Height - 5, string.Format("Planet: {0}", Planet.Name), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(40, canvas.Height - 4, string.Format("Planet class: {0}", Planet.GetClass_Ext()), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(40, canvas.Height - 3, string.Format("Orbital period: {0} Earth years", Planet.OrbitalPeriod), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(40, canvas.Height - 2, string.Format("Orbital radius: {0:0.000} AU", Planet.OrbitalRadius), (byte)ANSI.ANSIColor_16.Cyan, 0); canvas.DrawString(40, canvas.Height - 1, string.Format("Surface Temperature: {0:0.0}°", Planet.Temperature), (byte)ANSI.ANSIColor_16.Cyan, 0); StringBuilder sBuilder = new StringBuilder(); sBuilder.AppendLine(canvas.ToString()); //sBuilder.AppendLine(WrapString(Planet.Description)); sBuilder.AppendFormat("\r\n"); sBuilder.AppendFormat(ANSI.SetColorANSI16("Surface sectors:\r\n", ANSI.ANSIColor_16.BrightCyan)); char lineChar = 'A'; for (int y = 0; y < Planet.PlanetSector.GetLength(1); y++) { if (y == 0) { sBuilder.Append(" "); sBuilder.Append(ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan)); for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++) { sBuilder.AppendFormat(" {0,-2} ", x + 1); } sBuilder.Append(ANSI.ClearFormat()); sBuilder.AppendFormat("\r\n"); } sBuilder.Append(ANSI.SetColorANSI16(string.Format("{0,-2}", lineChar), ANSI.ANSIColor_16.BrightCyan)); lineChar++; for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++) { GetPlanetSectorString(Planet.PlanetSector[x, y], sBuilder); } sBuilder.AppendFormat("\r\n"); } sBuilder.AppendFormat(ANSI.SetColorANSI16("\r\nSpace Ports / Stations: ", ANSI.ANSIColor_16.BrightCyan)); sBuilder.AppendFormat("{0}\r\n", (Planet.SpacePort.Count > 0) ? "" : ANSI.SetColorANSI16("None", ANSI.ANSIColor_16.Cyan)); foreach (var s in Planet.SpacePort) { sBuilder.AppendFormat("{3}[{4}{0}{3}] {4}{1,-30}{3} Sector: {4}{2}{5}\r\n", s.Id, s.Name, s.PlanetSector, ANSI.ColorANSI16(ANSI.ANSIColor_16.Cyan), ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan), ANSI.ClearFormat() ); } return(sBuilder.ToString()); }
public string GetHud() { List <SectorObject> secObjects = new List <SectorObject>(); List <ObjInfo> objects = new List <ObjInfo>(); GameManager manager = GameManager.Instance; //int smallHudWidth = 30, smallHudHeight = 15; int smallHudWidth = 20, smallHudHeight = 12; TextCanvas closeDistHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas closeDistHUDCanvas_Target = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas_Target.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas_Target.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyEShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyEShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyEShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas canvas = new TextCanvas(Width - 5, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); //canvas.DrawRectangle(0, 0, Width -5, Height -5, (byte)ANSI.ANSIColor_8.Cyan); //canvas.DrawString(Width / 2, Height / 2, "▲", (byte)ANSI.ANSIColor_16.Green, (byte)ANSI.ANSIColor_16.Black); StarSystem system = this.Player.Player.Location.StarSystem; SpaceShip ship = this.Player.Player.SpaceShip; if (system == null) { return(string.Empty); } var sysM = manager.StarSystemManager.GetStarSystemArea(system.Coords); secObjects.AddRange(system.SystemBodies); secObjects.AddRange(sysM.GetShipsInSystem().Cast <SectorObject>()); secObjects.Add(system); if (ship.Target != null) { secObjects.Add(ship.Target); } secObjects.Add(ship); double minDist = Double.MaxValue; double minDistShips = Double.MaxValue; double minDist_Target = Double.MaxValue; double minDistEShips = Double.MaxValue; foreach (SectorObject secObject in secObjects) { double dist = secObject.SystemLocation.GetInSystemDistance(ship.SystemLocation); double dist_Target = (ship.Target != null) ? secObject.SystemLocation.GetInSystemDistance(ship.Target.SystemLocation) : 0; if (dist < minDist && dist > 0) { minDist = dist; } if (dist_Target < minDist_Target && dist_Target > 0) { minDist_Target = dist_Target; } SpaceShip shipObj = secObject as SpaceShip; SystemBody bodyObj = secObject as SystemBody; StarSystem sysObj = secObject as StarSystem; ObjInfo info = new ObjInfo(); info.X = secObject.SystemLocation.X; info.Y = secObject.SystemLocation.Y; info.Distance = dist; if (secObject == ship) { info.IsPlayer = true; } if (secObject == ship.Target) { info.IsTarget = true; } if (shipObj != null) { info.Display = "▪"; if (dist < minDistShips && dist > 0) { minDistShips = dist; } if (info.IsEnemy) { if (dist < minDistEShips && dist > 0) { minDistEShips = dist; } } } else if (bodyObj != null) { info.Display = "●"; } else if (sysObj != null) { info.Display = "☼"; } objects.Add(info); } if (minDist_Target == Double.MaxValue) { minDist_Target = 0; } if (minDistShips == Double.MaxValue) { minDistShips = 0; } if (minDistEShips == Double.MaxValue) { minDistEShips = 0; } //write close distance HUD double hudRange = minDist * (smallHudHeight / 2); // 149598000 / 2; double zX = ship.SystemLocation.X; double zY = ship.SystemLocation.Y; #region Close Distance HUD foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Ships HUD hudRange = minDistShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Enemy Ships HUD hudRange = minDistEShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange) && obj.IsEnemy) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyEShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyEShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Target Close Distance HUD hudRange = minDist_Target * (smallHudHeight / 2); // 149598000 / 2; if (ship.Target != null) { zX = ship.Target.SystemLocation.X; zY = ship.Target.SystemLocation.Y; } foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas_Target.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas_Target.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion canvas.DrawRawData(0, 0, closeDistHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth, 0, nearbyShipsHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth * 2, 0, closeDistHUDCanvas_Target.GetRawData()); canvas.DrawRawData(smallHudWidth * 3, 0, nearbyEShipsHUDCanvas.GetRawData()); long baseX, baseY; baseX = (long)(ship.SystemLocation.X / minDist); baseY = (long)(ship.SystemLocation.Y / minDist); return(canvas.ToString()); }