Sp campaign map shows which locations have been visited (+ some minor visual improvements to the map)

This commit is contained in:
Regalis
2016-09-28 16:53:08 +03:00
parent 2bdc7441fc
commit c5ce3a75a2
2 changed files with 113 additions and 46 deletions
@@ -81,17 +81,27 @@ namespace Barotrauma
public SinglePlayerMode(XElement element) public SinglePlayerMode(XElement element)
: this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null) : this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null)
{ {
string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");
GenerateMap(mapSeed);
Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
if (subElement.Name.ToString().ToLowerInvariant() != "crew") continue; switch (subElement.Name.ToString().ToLowerInvariant())
{
case "crew":
GameMain.GameSession.CrewManager = new CrewManager(subElement);
break;
case "map":
Map = Map.Load(subElement);
break;
}
}
GameMain.GameSession.CrewManager = new CrewManager(subElement); //backwards compatibility with older save files
if (Map==null)
{
string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");
GenerateMap(mapSeed);
Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
} }
savedOnStart = true; savedOnStart = true;
@@ -378,13 +388,14 @@ namespace Barotrauma
//element.Add(new XAttribute("day", day)); //element.Add(new XAttribute("day", day));
XElement modeElement = new XElement("gamemode"); XElement modeElement = new XElement("gamemode");
modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex)); //modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex));
modeElement.Add(new XAttribute("mapseed", Map.Seed)); //modeElement.Add(new XAttribute("mapseed", Map.Seed));
CrewManager.Save(modeElement); CrewManager.Save(modeElement);
Map.Save(modeElement);
element.Add(modeElement); element.Add(modeElement);
} }
} }
} }
+86 -30
View File
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq;
using Voronoi2; using Voronoi2;
namespace Barotrauma namespace Barotrauma
@@ -28,6 +29,8 @@ namespace Barotrauma
private Location currentLocation; private Location currentLocation;
private Location selectedLocation; private Location selectedLocation;
private Location highlightedLocation;
private LocationConnection selectedConnection; private LocationConnection selectedConnection;
public Location CurrentLocation public Location CurrentLocation
@@ -55,6 +58,26 @@ namespace Barotrauma
get { return seed; } get { return seed; }
} }
public static Map Load(XElement element)
{
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
int size = ToolBox.GetAttributeInt(element, "size", 500);
Map map = new Map(mapSeed, size);
map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
string discoveredStr = ToolBox.GetAttributeString(element, "discovered", "");
string[] discoveredStrs = discoveredStr.Split(',');
for (int i = 0; i < discoveredStrs.Length; i++ )
{
map.locations[i].Discovered = discoveredStrs[i].ToLowerInvariant() == "true";
}
return map;
}
public Map(string seed, int size) public Map(string seed, int size)
{ {
this.seed = seed; this.seed = seed;
@@ -67,15 +90,16 @@ namespace Barotrauma
connections = new List<LocationConnection>(); connections = new List<LocationConnection>();
if (iceTexture==null) iceTexture = new Sprite("Content/Map/iceSurface.png", Vector2.Zero); if (iceTexture == null) iceTexture = new Sprite("Content/Map/iceSurface.png", Vector2.Zero);
if (iceCraters == null) iceCraters = TextureLoader.FromFile("Content/Map/iceCraters.png"); if (iceCraters == null) iceCraters = TextureLoader.FromFile("Content/Map/iceCraters.png");
if (iceCrack == null) iceCrack = TextureLoader.FromFile("Content/Map/iceCrack.png"); if (iceCrack == null) iceCrack = TextureLoader.FromFile("Content/Map/iceCrack.png");
Rand.SetSyncedSeed(ToolBox.StringToInt(this.seed)); Rand.SetSyncedSeed(ToolBox.StringToInt(this.seed));
GenerateLocations(); GenerateLocations();
currentLocation = locations[locations.Count / 2]; currentLocation = locations[locations.Count / 2];
currentLocation.Discovered = true;
GenerateDifficulties(currentLocation, new List<LocationConnection> (connections), 10.0f); GenerateDifficulties(currentLocation, new List<LocationConnection> (connections), 10.0f);
foreach (LocationConnection connection in connections) foreach (LocationConnection connection in connections)
@@ -203,6 +227,7 @@ namespace Barotrauma
public void MoveToNextLocation() public void MoveToNextLocation()
{ {
currentLocation = selectedLocation; currentLocation = selectedLocation;
currentLocation.Discovered = true;
selectedLocation = null; selectedLocation = null;
} }
@@ -213,22 +238,17 @@ namespace Barotrauma
DebugConsole.ThrowError("Location index out of bounds"); DebugConsole.ThrowError("Location index out of bounds");
return; return;
} }
currentLocation = locations[index]; currentLocation = locations[index];
currentLocation.Discovered = true;
} }
private Location highlightedLocation;
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f) public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
{ {
//GUI.DrawRectangle(spriteBatch, rect, Color.DarkBlue, true);
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition; Vector2 offset = -currentLocation.MapPosition;
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f); iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f);
GUI.DrawRectangle(spriteBatch, rect, Color.White);
//spriteBatch.Draw(iceTexture, offset, rect, null, null, 0f, null, Color.White, SpriteEffects.None, 0.0f);
//Vector2 scale = new Vector2((float)rect.Width/ size, (float)rect.Height/size);
float maxDist = 20.0f; float maxDist = 20.0f;
float closestDist = 0.0f; float closestDist = 0.0f;
@@ -248,10 +268,9 @@ namespace Barotrauma
} }
} }
foreach (LocationConnection connection in connections) foreach (LocationConnection connection in connections)
{ {
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 0.5f); Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
if (highlightedLocation != currentLocation && if (highlightedLocation != currentLocation &&
connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation)) connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
@@ -267,38 +286,63 @@ namespace Barotrauma
} }
} }
if (selectedLocation != currentLocation && if (selectedLocation != currentLocation &&
(connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation))) (connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation)))
{ {
crackColor = Color.Red; crackColor = Color.Red;
} }
else if (!connection.Locations[0].Discovered || !connection.Locations[1].Discovered)
foreach (Vector2[] segment in connection.CrackSegments)
{ {
Vector2 start = rectCenter + (segment[0] + offset) * scale; crackColor *= 0.2f;
Vector2 end = rectCenter + (segment[1] + offset) * scale; }
if (!rect.Contains(start) || !rect.Contains(end)) continue; for (int i = 0; i < connection.CrackSegments.Count; i++ )
{
var segment = connection.CrackSegments[i];
Vector2 start = rectCenter + (segment[0] + offset) * scale;
Vector2 end = rectCenter + (segment[1] + offset) * scale;
if (!rect.Contains(start) && !rect.Contains(end))
{
continue;
}
else
{
Vector2? intersection = MathUtils.GetLineRectangleIntersection(start, end, new Rectangle(rect.X, rect.Y + rect.Height, rect.Width, rect.Height));
if (intersection != null)
{
if (!rect.Contains(start))
{
start = (Vector2)intersection;
}
else
{
end = (Vector2)intersection;
}
}
}
float dist = Vector2.Distance(start, end); float dist = Vector2.Distance(start, end);
int width = (int)(MathHelper.Clamp(connection.Difficulty, 2.0f, 20.0f) * scale);
spriteBatch.Draw(iceCrack, spriteBatch.Draw(iceCrack,
new Rectangle((int)start.X, (int)start.Y, (int)dist+2, 30), new Rectangle((int)start.X, (int)start.Y, (int)dist + 2, width),
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end -start), new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end - start),
new Vector2(0, 30), SpriteEffects.None, 0.01f); new Vector2(0, 30), SpriteEffects.None, 0.01f);
} }
} }
rect.Inflate(8, 8);
GUI.DrawRectangle(spriteBatch, rect, Color.Black, 8);
GUI.DrawRectangle(spriteBatch, rect, Color.LightGray);
for (int i = 0; i < locations.Count; i++) for (int i = 0; i < locations.Count; i++)
{ {
Location location = locations[i]; Location location = locations[i];
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale; Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
Rectangle drawRect = location.Type.Sprite.SourceRect; Rectangle drawRect = location.Type.Sprite.SourceRect;
Rectangle sourceRect = drawRect; Rectangle sourceRect = drawRect;
drawRect.X = (int)pos.X - drawRect.Width/2; drawRect.X = (int)pos.X - drawRect.Width/2;
@@ -308,7 +352,7 @@ namespace Barotrauma
Color color = location.Connections.Find(c => c.Locations.Contains(currentLocation))==null ? Color.White : Color.Green; Color color = location.Connections.Find(c => c.Locations.Contains(currentLocation))==null ? Color.White : Color.Green;
color *= (location.Discovered) ? 0.8f : 0.4f; color *= (location.Discovered) ? 0.8f : 0.2f;
if (location == currentLocation) color = Color.Orange; if (location == currentLocation) color = Color.Orange;
@@ -348,15 +392,27 @@ namespace Barotrauma
if (location == null) continue; if (location == null) continue;
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale; Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
pos.X = (int)pos.X; pos.X = (int)(pos.X + location.Type.Sprite.SourceRect.Width*0.6f);
pos.Y = (int)pos.Y; pos.Y = (int)(pos.Y - 10);
if (highlightedLocation == location) GUI.DrawString(spriteBatch, pos, location.Name, Color.White, Color.Black * 0.8f, 3);
{
spriteBatch.DrawString(GUI.Font, location.Name, pos + new Vector2(0, 50), Color.DarkRed, 0.0f, GUI.Font.MeasureString(location.Name)/2.0f, 1.0f, SpriteEffects.None, 0.0f);
}
} }
} }
public void Save(XElement element)
{
XElement mapElement = new XElement("map");
mapElement.Add(new XAttribute("currentlocation", CurrentLocationIndex));
mapElement.Add(new XAttribute("seed", Seed));
mapElement.Add(new XAttribute("size", size));
List<bool> discovered = locations.Select(l => l.Discovered).ToList();
mapElement.Add(new XAttribute("discovered", string.Join(",", discovered)));
element.Add(mapElement);
}
} }