Skip to content

Commit

Permalink
Implemented IFF search (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Jan 4, 2024
1 parent 3c404f7 commit b466e22
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
23 changes: 10 additions & 13 deletions Content.Client/Shuttles/UI/RadarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public sealed class RadarControl : MapGridControl
public bool ShowIFFShuttles { get; set; } = true;
public bool ShowDocks { get; set; } = true;

/// <summary>
/// If present, called for every IFF. Must determine if it should or should not be shown.
/// </summary>
public Func<EntityUid, MapGridComponent, IFFComponent?, bool>? IFFFilter { get; set; } = null;

/// <summary>
/// Currently hovered docked to show on the map.
/// </summary>
Expand Down Expand Up @@ -286,19 +291,11 @@ protected override void Draw(DrawingHandleScreen handle)
uiPosition = new Vector2(uiX + uiXCentre, uiY + uiYCentre);
}

if (!ShowIFFShuttles)
{
if (iff != null && (iff.Flags & IFFFlags.IsPlayerShuttle) != 0x0)
{
label.Visible = false;
}
else
label.Visible = true;
}
else
{
label.Visible = true;
}
label.Visible = ShowIFFShuttles
|| iff == null || (iff.Flags & IFFFlags.IsPlayerShuttle) == 0x0;

if (IFFFilter != null)
label.Visible &= IFFFilter(gUid, grid.Comp, iff);

label.Text = Loc.GetString("shuttle-console-iff-label", ("name", name), ("distance", $"{distance:0.0}"));
LayoutContainer.SetPosition(label, uiPosition);
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
Align="Right"/>
</GridContainer>
</BoxContainer>

<Button Name="IFFToggle"
Text="{Loc 'shuttle-console-iff-toggle'}"
TextAlign="Center"
Expand All @@ -119,6 +120,13 @@
Text="{Loc 'shuttle-console-undock'}"
TextAlign="Center"
Disabled="True"/>

<!-- Frontier - IFF search -->
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Name="IffSearchBox">
<Label Text="{Loc 'shuttle-console-iff-search'}"></Label>

<LineEdit Name="IffSearchCriteria" Access="Public" HorizontalExpand="True"></LineEdit>
</BoxContainer>
</BoxContainer>
</GridContainer>
</controls:FancyWindow>
16 changes: 16 additions & 0 deletions Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public ShuttleConsoleWindow()
DockToggle.Pressed = RadarScreen.ShowDocks;

UndockButton.OnPressed += OnUndockPressed;

// Frontier - IFF search
IffSearchCriteria.OnTextChanged += args => OnIffSearchChanged(args.Text);
}

private void WorldRangeChange(float value)
Expand Down Expand Up @@ -95,6 +98,19 @@ private void OnUndockPressed(BaseButton.ButtonEventArgs args)
UndockPressed?.Invoke(DockingScreen.ViewedDock.Value);
}

private void OnIffSearchChanged(string text)
{
text = text.Trim();

RadarScreen.IFFFilter = text.Length == 0
? null // If empty, do not filter
: (entity, grid, iff) => // Otherwise use simple search criteria
{
_entManager.TryGetComponent<MetaDataComponent>(entity, out var metadata);
return metadata != null && metadata.EntityName.Contains(text, StringComparison.OrdinalIgnoreCase);
};
}

public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
{
_shuttleEntity = coordinates?.EntityId;
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/shuttles/console.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ shuttle-console-hyperspace-none = No destinations found
shuttle-console-unknown = Unknown
shuttle-console-iff-label = {$name} ({$distance}m)
shuttle-console-iff-search = Search IFF
# Buttons
shuttle-console-strafing = Strafing mode
shuttle-console-iff-toggle = Show IFF
Expand Down

0 comments on commit b466e22

Please sign in to comment.