Client LuaCsForBarotrauma
MapGenerationParams.cs
2 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
4 using System.Collections.Immutable;
5 using System.Linq;
6 using System.Xml.Linq;
7 
8 namespace Barotrauma
9 {
11  {
14  {
15  get
16  {
17  return Params.ActivePrefab;
18  }
19  }
20 
21 #if DEBUG
23  public bool ShowLocations { get; set; }
24 
25  [Serialize(true, IsPropertySaveable.Yes), Editable]
26  public bool ShowLevelTypeNames { get; set; }
27 
28  [Serialize(true, IsPropertySaveable.Yes), Editable]
29  public bool ShowOverlay { get; set; }
30 #else
31  public readonly bool ShowLocations = true;
32  public readonly bool ShowLevelTypeNames = false;
33  public readonly bool ShowOverlay = true;
34 #endif
35 
37  public int DifficultyZones { get; set; } //Number of difficulty zones
38 
40  public int Width { get; set; }
41 
43  public int Height { get; set; }
44 
45  [Serialize(20.0f, IsPropertySaveable.Yes, description: "Connections with a length smaller or equal to this generate the smallest possible levels (using the MinWidth parameter in the level generation paramaters)."), Editable(0.0f, 5000.0f)]
46  public float SmallLevelConnectionLength { get; set; }
47 
48  [Serialize(200.0f, IsPropertySaveable.Yes, description: "Connections with a length larger or equal to this generate the largest possible levels (using the MaxWidth parameter in the level generation paramaters)."), Editable(0.0f, 5000.0f)]
49  public float LargeLevelConnectionLength { get; set; }
50 
51  [Serialize("20,20", IsPropertySaveable.Yes, description: "How far from each other voronoi sites are placed. " +
52  "Sites determine shape of the voronoi graph. Locations are placed at the vertices of the voronoi cells. " +
53  "(Decreasing this value causes the number of sites, and the complexity of the map, to increase exponentially - be careful when adjusting)"), Editable]
54  public Point VoronoiSiteInterval { get; set; }
55 
57  public Point VoronoiSiteVariance { get; set; }
58 
59  [Serialize(10.0f, IsPropertySaveable.Yes, description: "Connections smaller than this are removed."), Editable(0.0f, 500.0f)]
60  public float MinConnectionDistance { get; set; }
61 
62  [Serialize(5.0f, IsPropertySaveable.Yes, description: "Locations that are closer than this to another location are removed."), Editable(0.0f, 100.0f)]
63  public float MinLocationDistance { get; set; }
64 
65  [Serialize(0.1f, IsPropertySaveable.Yes, description: "ConnectionIterationMultiplier for the UI indicator lines between locations."), Editable(0.0f, 10.0f, DecimalCount = 2)]
66  public float ConnectionIndicatorIterationMultiplier { get; set; }
67 
68  [Serialize(0.1f, IsPropertySaveable.Yes, description: "ConnectionDisplacementMultiplier for the UI indicator lines between locations."), Editable(0.0f, 10.0f, DecimalCount = 2)]
69  public float ConnectionIndicatorDisplacementMultiplier { get; set; }
70 
71  public readonly ImmutableArray<int> GateCount;
72 
73 #if CLIENT
74 
75  [Serialize(0.75f, IsPropertySaveable.Yes), Editable(DecimalCount = 2)]
76  public float MinZoom { get; set; }
77 
78  [Serialize(1.5f, IsPropertySaveable.Yes), Editable(DecimalCount = 2)]
79  public float MaxZoom { get; set; }
80 
81  [Serialize(1.0f, IsPropertySaveable.Yes), Editable(DecimalCount = 2)]
82  public float MapTileScale { get; set; }
83 
84  [Serialize(15.0f, IsPropertySaveable.Yes, description: "Size of the location icons in pixels when at 100% zoom."), Editable(1.0f, 1000.0f)]
85  public float LocationIconSize { get; set; }
86 
87  [Serialize(5.0f, IsPropertySaveable.Yes, description: "Width of the connections between locations, in pixels when at 100% zoom."), Editable(1.0f, 1000.0f)]
88  public float LocationConnectionWidth { get; set; }
89 
90  [Serialize("220,220,100,255", IsPropertySaveable.Yes, description: "The color used to display the indicators (current location, selected location, etc)."), Editable()]
91  public Color IndicatorColor { get; set; }
92 
93  [Serialize("150,150,150,255", IsPropertySaveable.Yes, description: "The color used to display the connections between locations."), Editable()]
94  public Color ConnectionColor { get; set; }
95 
96  [Serialize("150,150,150,255", IsPropertySaveable.Yes, description: "The color used to display the connections between locations when they're highlighted."), Editable()]
97  public Color HighlightedConnectionColor { get; set; }
98 
99  [Serialize("150,150,150,255", IsPropertySaveable.Yes, description: "The color used to display the connections the player hasn't travelled through."), Editable()]
100  public Color UnvisitedConnectionColor { get; set; }
101 
102  public Sprite ConnectionSprite { get; private set; }
103  public Sprite PassedConnectionSprite { get; private set; }
104 
105  public SpriteSheet DecorativeGraphSprite { get; private set; }
106 
107  public Sprite MissionIcon { get; private set; }
108  public Sprite TypeChangeIcon { get; private set; }
109 
110  public Sprite FogOfWarSprite { get; private set; }
111  public Sprite CurrentLocationIndicator { get; private set; }
112  public Sprite SelectedLocationIndicator { get; private set; }
113 
114  public readonly ImmutableDictionary<Identifier, ImmutableArray<Sprite>> MapTiles;
115 #endif
116 
117  public string Name => GetType().ToString();
118 
119  public Dictionary<Identifier, SerializableProperty> SerializableProperties
120  {
121  get; private set;
122  }
123 
125 
126  public MapGenerationParams(ContentXElement element, MapGenerationParametersFile file) : base(file, file.Path.Value.ToIdentifier())
127  {
129 
130  var gateCount = element.GetAttributeIntArray("gatecount", null) ?? element.GetAttributeIntArray("GateCount", null);
131  if (gateCount == null)
132  {
133  gateCount = new int[DifficultyZones];
134  for (int i = 0; i < DifficultyZones; i++)
135  {
136  gateCount[i] = 1;
137  }
138  }
139  GateCount = gateCount.ToImmutableArray();
140 
141  Dictionary<Identifier, List<Sprite>> mapTiles = new Dictionary<Identifier, List<Sprite>>();
142 
143  foreach (var subElement in element.Elements())
144  {
145  switch (subElement.Name.ToString().ToLowerInvariant())
146  {
147 #if CLIENT
148  case "connectionsprite":
149  ConnectionSprite = new Sprite(subElement);
150  break;
151  case "passedconnectionsprite":
152  PassedConnectionSprite = new Sprite(subElement);
153  break;
154  case "maptile":
155  Identifier biome = subElement.GetAttributeIdentifier("biome", "");
156  if (!mapTiles.ContainsKey(biome))
157  {
158  mapTiles[biome] = new List<Sprite>();
159  }
160  mapTiles[biome].Add(new Sprite(subElement));
161  break;
162  case "fogofwarsprite":
163  FogOfWarSprite = new Sprite(subElement);
164  break;
165  case "locationindicator":
166  case "currentlocationindicator":
167  CurrentLocationIndicator = new Sprite(subElement);
168  break;
169  case "selectedlocationindicator":
170  SelectedLocationIndicator = new Sprite(subElement);
171  break;
172  case "decorativegraphsprite":
173  DecorativeGraphSprite = new SpriteSheet(subElement);
174  break;
175  case "missionicon":
176  MissionIcon = new Sprite(subElement);
177  break;
178  case "typechangeicon":
179  TypeChangeIcon = new Sprite(subElement);
180  break;
181 #endif
182  case "radiationparams":
183  RadiationParams = new RadiationParams(subElement);
184  break;
185  }
186  }
187 #if CLIENT
188  MapTiles = mapTiles.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableDictionary();
189 #endif
190  }
191 
192  public override void Dispose()
193  {
194 #if CLIENT
200  MissionIcon?.Remove();
203  foreach (ImmutableArray<Sprite> spriteList in MapTiles.Values)
204  {
205  foreach (Sprite sprite in spriteList)
206  {
207  sprite.Remove();
208  }
209  }
210 #endif
211  }
212  }
213 }
int?[] GetAttributeIntArray(string key, int[]? def)
readonly ImmutableDictionary< Identifier, ImmutableArray< Sprite > > MapTiles
static readonly PrefabSelector< MapGenerationParams > Params
Dictionary< Identifier, SerializableProperty > SerializableProperties
static MapGenerationParams Instance
MapGenerationParams(ContentXElement element, MapGenerationParametersFile file)
readonly ImmutableArray< int > GateCount
readonly Identifier Identifier
Definition: Prefab.cs:34
static Dictionary< Identifier, SerializableProperty > DeserializeProperties(object obj, XElement element=null)