4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
6 using Microsoft.Xna.Framework.Input;
13 partial class LinkedSubmarine : MapEntity
15 public override void Draw(SpriteBatch spriteBatch,
bool editing,
bool back =
true)
17 if (!editing || wallVertices ==
null) {
return; }
25 bool isLinkAllowed = e is
Item item && item.
HasTag(Tags.DockingPort);
27 GUI.DrawLine(spriteBatch,
30 isLinkAllowed ? GUIStyle.Green * 0.5f : GUIStyle.Red * 0.5f, width: 3);
34 public void Draw(SpriteBatch spriteBatch, Vector2 drawPos,
float alpha = 1.0f)
36 Color color = (
IsHighlighted) ? GUIStyle.Orange : GUIStyle.Green;
39 Vector2 pos = drawPos;
41 for (
int i = 0; i < wallVertices.Count; i++)
43 Vector2 startPos = wallVertices[i] + pos;
44 startPos.Y = -startPos.Y;
46 Vector2 endPos = wallVertices[(i + 1) % wallVertices.Count] + pos;
49 GUI.DrawLine(spriteBatch,
52 color * alpha, 0.0f, 5);
56 GUI.DrawLine(spriteBatch, pos + Vector2.UnitY * 50.0f, pos - Vector2.UnitY * 50.0f, color * alpha, 0.0f, 5);
57 GUI.DrawLine(spriteBatch, pos + Vector2.UnitX * 50.0f, pos - Vector2.UnitX * 50.0f, color * alpha, 0.0f, 5);
75 if (entity ==
this|| entity is not
Item || !entity.
IsMouseOn(position)) {
continue; }
76 if (((
Item)entity).GetComponent<DockingPort>() ==
null) {
continue; }
90 private GUIComponent CreateEditingHUD(
bool inGame =
false)
99 AbsoluteSpacing = (int)(GUI.Scale * 5)
102 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
103 TextManager.Get(
"LinkedSub"), font: GUIStyle.LargeFont);
107 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
108 TextManager.Get(
"LinkLinkedSub"), textColor: GUIStyle.Orange, font: GUIStyle.SmallFont);
111 var pathContainer =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), isHorizontal:
true);
113 string filePath = this.filePath;
114 if (filePath.StartsWith(
"Submarines"))
117 string subName = Path.GetFileNameWithoutExtension(filePath);
118 string foundPath = ContentPackageManager.LocalPackages.Concat(ContentPackageManager.VanillaCorePackage.ToEnumerable())
119 .SelectMany(p => p.GetFiles<SubmarineFile>())
120 .FirstOrDefault(f => Path.GetFileNameWithoutExtension(f.Path.Value).Equals(subName, StringComparison.OrdinalIgnoreCase))
122 if (foundPath.IsNullOrEmpty())
125 foundPath = Path.Combine(ContentPackage.LocalModsDir, subName, $
"{subName}.sub");
128 filePath = foundPath;
131 var pathBox =
new GUITextBox(
new RectTransform(
new Vector2(0.75f, 1.0f), pathContainer.RectTransform), filePath, font: GUIStyle.SmallFont);
132 var reloadButton =
new GUIButton(
new RectTransform(
new Vector2(0.25f / pathBox.RectTransform.RelativeSize.X, 1.0f), pathBox.RectTransform,
Anchor.CenterRight,
Pivot.CenterLeft),
133 TextManager.Get(
"ReloadLinkedSub"), style:
"GUIButtonSmall")
137 ToolTip = TextManager.Get(
"ReloadLinkedSubTooltip")
142 (
int)(paddedFrame.Children.Sum(c => c.Rect.Height + paddedFrame.AbsoluteSpacing) / paddedFrame.RectTransform.RelativeSize.Y)));
149 private bool Reload(GUIButton button,
object obj)
151 var pathBox = obj as GUITextBox;
153 if (!File.Exists(pathBox.Text))
155 new GUIMessageBox(TextManager.Get(
"Error"), TextManager.GetWithVariable(
"ReloadLinkedSubError",
"[file]", pathBox.Text));
156 pathBox.Flash(GUIStyle.Red);
157 pathBox.Text = filePath;
161 XDocument doc = SubmarineInfo.OpenFile(pathBox.Text);
162 if (doc ==
null || doc.Root ==
null) {
return false; }
163 doc.Root.SetAttributeValue(
"filepath", pathBox.Text);
165 pathBox.Flash(GUIStyle.Green);
167 GenerateWallVertices(doc.Root);
168 saveElement = doc.Root;
169 saveElement.Name =
"LinkedSubmarine";
170 CargoCapacity = doc.Root.GetAttributeInt(
"cargocapacity", 0);
172 filePath = pathBox.Text;
Vector2 ScreenToWorld(Vector2 coords)
virtual Vector2 WorldPosition
void UpdateManually(float deltaTime, bool alsoChildren=false, bool recursive=true)
By default, all the gui elements are updated automatically in the same order they appear on the updat...
RectTransform RectTransform
bool HasTag(Identifier tag)
override void Draw(SpriteBatch spriteBatch, bool editing, bool back=true)
void Draw(SpriteBatch spriteBatch, Vector2 drawPos, float alpha=1.0f)
override void UpdateEditing(Camera cam, float deltaTime)
static GUIComponent editingHUD
static IEnumerable< MapEntity > HighlightedEntities
static void PositionEditingHUD()
override Vector2 Position
readonly List< MapEntity > linkedTo
virtual bool IsMouseOn(Vector2 position)