2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
4 using Microsoft.Xna.Framework.Input;
6 using System.Collections.Generic;
11 partial class WayPoint : MapEntity
13 private static Dictionary<string, Sprite> iconSprites;
14 private const int WaypointSize = 12, SpawnPointSize = 32;
23 get {
return ShouldDrawIcon(); }
26 public override void Draw(SpriteBatch spriteBatch,
bool editing,
bool back =
true)
29 if (!ShouldDrawIcon()) {
return; }
33 drawPos.Y = -drawPos.Y;
35 Draw(spriteBatch, drawPos);
38 public void Draw(SpriteBatch spriteBatch, Vector2 drawPos)
40 Color clr =
CurrentHull ==
null ? Color.DodgerBlue : GUIStyle.Green;
51 iconSize = (int)(iconSize * 1.5f);
56 int glowSize = (int)(iconSize * 1.5f);
57 GUIStyle.UIGlowCircular.Draw(spriteBatch,
58 new Rectangle((
int)(drawPos.X - glowSize / 2), (
int)(drawPos.Y - glowSize / 2), glowSize, glowSize),
68 sprite = iconSprites[
"Path"];
72 sprite = iconSprites[
"Door"];
75 sprite2 = iconSprites[
"Ladder"];
89 sprite = iconSprites[
"Ladder"];
94 float spriteScale = iconSize / (float)sprite.
SourceRect.Width;
95 sprite.Draw(spriteBatch, drawPos, clr, origin: sprite.size / 2, scale: spriteScale, depth: 0.001f);
96 sprite2?.
Draw(spriteBatch, drawPos + sprite.size * spriteScale * 0.5f, clr, origin: sprite2.
size / 2, scale: spriteScale, depth: 0.001f);
106 GUI.DrawLine(spriteBatch,
109 (
IsTraversable ? GUIStyle.Green : Color.Gray) * 0.7f, width: 5, depth: 0.002f);
113 GUI.DrawLine(spriteBatch,
116 GUIStyle.Green * 0.5f, width: 1);
120 GUI.DrawLine(spriteBatch,
123 GUIStyle.Green * 0.5f, width: 1);
126 var color = Color.WhiteSmoke;
139 color =
Ladders ==
null ? Color.Red : Color.Yellow;
143 color = Color.Yellow;
153 GUIStyle.SmallFont.DrawString(spriteBatch,
159 GUIStyle.SmallFont.DrawString(spriteBatch,
168 if (!ShouldDrawIcon()) {
return false; }
169 float dist = Vector2.DistanceSquared(position,
WorldPosition);
171 return dist < radius * radius;
174 private bool ShouldDrawIcon()
183 return GameMain.DebugDraw || ShowSpawnPoints;
202 if (e is not
WayPoint || e ==
this) {
continue; }
222 if (ConnectedGap == gap)
229 var ladder = i?.GetComponent<Ladder>();
236 var ladder = i?.GetComponent<
Ladder>();
262 private void UpdateLinkedEntity<T>(Vector2 worldPos, IEnumerable<T> list, Action<T> match, Action<T> noMatch,
int inflate = 0) where T : MapEntity
264 foreach (var entity
in list)
266 var rect = entity.WorldRect;
267 rect.Inflate(inflate, inflate);
268 if (
Submarine.RectContains(rect, worldPos))
279 private bool ChangeSpawnType(GUIButton button,
object obj)
281 var prevSpawnType = spawnType;
282 GUITextBlock spawnTypeText = button.Parent.GetChildByUserData(
"spawntypetext") as GUITextBlock;
283 var values = (
SpawnType[])Enum.GetValues(typeof(SpawnType));
284 int currIndex = values.IndexOf(spawnType);
285 currIndex += (int)button.UserData;
287 int lastIndex = values.Length - 1;
288 if (currIndex > lastIndex)
290 currIndex = firstIndex;
292 if (currIndex < firstIndex)
294 currIndex = lastIndex;
296 spawnType = values[currIndex];
297 spawnTypeText.Text = spawnType.ToString();
298 if (spawnType ==
SpawnType.ExitPoint || prevSpawnType ==
SpawnType.ExitPoint) { CreateEditingHUD(); }
302 private GUIComponent CreateEditingHUD()
304 editingHUD =
new GUIFrame(
new RectTransform(
new Vector2(0.3f, 0.15f), GUI.Canvas,
Anchor.CenterRight) { MinSize = new Point(400, 0) })
309 var paddedFrame =
new GUILayoutGroup(
new RectTransform(
new Vector2(0.9f, 0.85f), editingHUD.RectTransform,
Anchor.Center))
312 AbsoluteSpacing = (int)(GUI.Scale * 5)
317 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get(
"Waypoint"), font: GUIStyle.LargeFont);
318 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get(
"LinkWaypoint"));
322 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), TextManager.Get(
"Spawnpoint"), font: GUIStyle.LargeFont);
324 if (!Layer.IsNullOrEmpty())
326 var layerText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), paddedFrame.RectTransform), TextManager.AddPunctuation(
':', TextManager.Get(
"editor.layer"), Layer));
329 var spawnTypeContainer =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), isHorizontal:
true)
332 RelativeSpacing = 0.05f
334 new GUITextBlock(
new RectTransform(
new Vector2(0.5f, 1.0f), spawnTypeContainer.RectTransform), TextManager.Get(
"SpawnType"));
336 var button =
new GUIButton(
new RectTransform(Vector2.One, spawnTypeContainer.RectTransform, scaleBasis:
ScaleBasis.BothHeight), style:
"GUIMinusButton")
339 OnClicked = ChangeSpawnType
341 new GUITextBlock(
new RectTransform(
new Vector2(0.3f, 1.0f), spawnTypeContainer.RectTransform), spawnType.ToString(), textAlignment: Alignment.Center)
343 UserData =
"spawntypetext"
345 button =
new GUIButton(
new RectTransform(Vector2.One, spawnTypeContainer.RectTransform, scaleBasis:
ScaleBasis.BothHeight), style:
"GUIPlusButton")
348 OnClicked = ChangeSpawnType
351 var descText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
352 TextManager.Get(
"IDCardDescription"), font: GUIStyle.SmallFont)
354 ToolTip = TextManager.Get(
"IDCardDescriptionTooltip")
356 GUITextBox propertyBox =
new GUITextBox(
new RectTransform(
new Vector2(0.5f, 1.0f), descText.RectTransform,
Anchor.CenterRight), IdCardDesc)
359 ToolTip = TextManager.Get(
"IDCardDescriptionTooltip")
361 propertyBox.OnTextChanged += (textBox, text) =>
366 propertyBox.OnEnterPressed += (textBox, text) =>
369 textBox.Flash(GUIStyle.Green);
372 propertyBox.OnDeselected += (textBox, keys) =>
374 IdCardDesc = textBox.Text;
375 textBox.Flash(GUIStyle.Green);
378 var idCardTagsText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
379 TextManager.Get(
"IDCardTags"), font: GUIStyle.SmallFont)
381 ToolTip = TextManager.Get(
"IDCardTagsTooltip")
383 propertyBox =
new GUITextBox(
new RectTransform(
new Vector2(0.5f, 1.0f), idCardTagsText.RectTransform,
Anchor.CenterRight),
string.Join(
", ", idCardTags))
386 ToolTip = TextManager.Get(
"IDCardTagsTooltip")
388 propertyBox.OnTextChanged += (textBox, text) =>
390 IdCardTags = text.Split(
',');
393 propertyBox.OnEnterPressed += (textBox, text) =>
395 textBox.Text =
string.Join(
",", IdCardTags);
396 textBox.Flash(GUIStyle.Green);
399 propertyBox.OnDeselected += (textBox, keys) =>
401 textBox.Text =
string.Join(
",", IdCardTags);
402 textBox.Flash(GUIStyle.Green);
405 var jobsText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
406 TextManager.Get(
"SpawnpointJobs"), font: GUIStyle.SmallFont)
408 ToolTip = TextManager.Get(
"SpawnpointJobsTooltip")
410 var jobDropDown =
new GUIDropDown(
new RectTransform(
new Vector2(0.5f, 1.0f), jobsText.RectTransform,
Anchor.CenterRight))
412 ToolTip = TextManager.Get(
"SpawnpointJobsTooltip"),
413 OnSelected = (selected, userdata) =>
415 AssignedJob = userdata as JobPrefab;
419 jobDropDown.AddItem(TextManager.Get(
"Any"),
null);
420 foreach (JobPrefab jobPrefab
in JobPrefab.Prefabs)
422 jobDropDown.AddItem(jobPrefab.Name, jobPrefab);
424 jobDropDown.SelectItem(AssignedJob);
426 var tagsText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
427 TextManager.Get(
"spawnpointtags"), font: GUIStyle.SmallFont);
428 propertyBox =
new GUITextBox(
new RectTransform(
new Vector2(0.5f, 1.0f), tagsText.RectTransform,
Anchor.CenterRight),
string.Join(
", ", tags))
431 ToolTip = TextManager.Get(
"spawnpointtagstooltip")
433 propertyBox.OnTextChanged += (textBox, text) =>
435 tags = text.Split(
',').ToIdentifiers().ToHashSet();
438 propertyBox.OnEnterPressed += (textBox, text) =>
440 textBox.Text =
string.Join(
",", tags);
441 textBox.Flash(GUIStyle.Green);
444 propertyBox.OnDeselected += (textBox, keys) =>
446 textBox.Text =
string.Join(
",", tags);
447 textBox.Flash(GUIStyle.Green);
452 var sizeField = GUI.CreatePointField(ExitPointSize, GUI.IntScale(20), TextManager.Get(
"dimensions"), paddedFrame.RectTransform);
453 GUINumberInput xField =
null, yField =
null;
454 foreach (GUIComponent child
in sizeField.GetAllChildren())
458 yField = child as GUINumberInput;
462 xField = child as GUINumberInput;
463 if (xField !=
null) {
break; }
466 xField.MinValueInt = 0;
467 xField.OnValueChanged = (numberInput) => { ExitPointSize =
new Point(numberInput.IntValue, ExitPointSize.Y); };
468 yField.MinValueInt = 0;
469 yField.OnValueChanged = (numberInput) => { ExitPointSize =
new Point(ExitPointSize.X, numberInput.IntValue); };
473 editingHUD.RectTransform.Resize(
new Point(
474 editingHUD.Rect.Width,
475 (
int)(paddedFrame.Children.Sum(c => c.Rect.Height + paddedFrame.AbsoluteSpacing) / paddedFrame.RectTransform.RelativeSize.Y)));
477 PositionEditingHUD();
Vector2 ScreenToWorld(Vector2 coords)
virtual Vector2 WorldPosition
virtual Vector2 DrawPosition
readonly ushort ID
Unique, but non-persistent identifier. Stays the same if the entities are created in the exactly same...
static SubEditorScreen SubEditorScreen
static List< Gap > GapList
static readonly List< Item > ItemList
static GUIComponent editingHUD
static IEnumerable< MapEntity > HighlightedEntities
override Vector2 Position
readonly List< MapEntity > linkedTo
void Draw(ISpriteBatch spriteBatch, Vector2 pos, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None)
static bool IsLayerVisible(MapEntity entity)
static bool RectContains(Rectangle rect, Vector2 pos, bool inclusive=false)
static bool ShowWayPoints
void Draw(SpriteBatch spriteBatch, Vector2 drawPos)
override bool IsVisible(Rectangle worldView)
override bool IsMouseOn(Vector2 position)
override bool SelectableInEditor
override void UpdateEditing(Camera cam, float deltaTime)
override void Draw(SpriteBatch spriteBatch, bool editing, bool back=true)