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