forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: Activatable UI for Pinpointer (#2664)
- Loading branch information
Showing
32 changed files
with
771 additions
and
12 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
Content.Client/SS220/Pinpointer/UI/PinpointerBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
|
||
using Content.Shared.Pinpointer; | ||
using Content.Shared.SS220.Pinpointer; | ||
using JetBrains.Annotations; | ||
using Robust.Client.UserInterface; | ||
|
||
namespace Content.Client.SS220.Pinpointer.UI; | ||
|
||
[UsedImplicitly] | ||
public sealed partial class PinpointerBoundUserInterface : BoundUserInterface | ||
{ | ||
private PinpointerMenu? _crewMenu; | ||
private PinpointerUplinkMenu? _itemMenu; | ||
|
||
public PinpointerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
switch (state) | ||
{ | ||
case PinpointerCrewUIState crewState: | ||
if (_crewMenu == null) | ||
return; | ||
|
||
_crewMenu.CrewListCoords = crewState.Sensors; | ||
_crewMenu.PopulateList(); | ||
break; | ||
|
||
case PinpointerItemUIState itemState: | ||
if (_itemMenu == null) | ||
return; | ||
|
||
_itemMenu.ItemListSet = itemState.Items; | ||
_itemMenu.PopulateList(); | ||
break; | ||
} | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
if (!EntMan.TryGetComponent<PinpointerComponent>(Owner, out var pinpointer)) | ||
return; | ||
|
||
switch (pinpointer.Mode) | ||
{ | ||
case PinpointerMode.Crew: | ||
{ | ||
_crewMenu = this.CreateWindow<PinpointerMenu>(); | ||
_crewMenu.OnTargetPicked = OnTargetPicked; | ||
_crewMenu.PopulateList(); | ||
break; | ||
} | ||
|
||
case PinpointerMode.Item: | ||
{ | ||
_itemMenu = this.CreateWindow<PinpointerUplinkMenu>(); | ||
_itemMenu.OnTargetPicked = OnTargetPicked; | ||
_itemMenu.OnDnaPicked = OnDnaPicked; | ||
_itemMenu.PopulateList(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
_crewMenu?.Close(); | ||
_itemMenu?.Close(); | ||
_itemMenu?.DnaWindow?.Close(); | ||
} | ||
|
||
private void OnTargetPicked(NetEntity target) | ||
{ | ||
SendMessage(new PinpointerTargetPick(target)); | ||
} | ||
|
||
private void OnDnaPicked(string? dna) | ||
{ | ||
SendMessage(new PinpointerDnaPick(dna)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<controls:FancyWindow xmlns="https://spacestation14.io" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc 'pinpointer-ui-title'}" | ||
MinSize="350 300" | ||
Resizable="True"> | ||
|
||
<BoxContainer Orientation="Vertical" VerticalExpand="True"> | ||
<Label Text="{Loc 'pinpointer-ui-person-to-track'}" Name="LabelTrack" Access="Public" Margin="5 0 0 0" HorizontalExpand="True"/> | ||
<PanelContainer StyleClasses="HighDivider"/> | ||
|
||
<ScrollContainer VerticalExpand="True" HScrollEnabled="False"> | ||
<BoxContainer Name="CrewList" Orientation="Vertical"/> | ||
</ScrollContainer> | ||
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'object-tab-object-search'}" HorizontalExpand="true"/> | ||
</BoxContainer> | ||
|
||
</controls:FancyWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
|
||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.SS220.Pinpointer; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
|
||
namespace Content.Client.SS220.Pinpointer.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class PinpointerMenu : FancyWindow | ||
{ | ||
public Action<NetEntity>? OnTargetPicked; | ||
|
||
public HashSet<TrackedItem> CrewListCoords = []; | ||
|
||
private string _searchText = string.Empty; | ||
|
||
public PinpointerMenu() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
SearchBar.OnTextChanged += OnSearchChanged; | ||
} | ||
|
||
private void OnSearchChanged(LineEdit.LineEditEventArgs args) | ||
{ | ||
_searchText = args.Text.Trim().ToLower(); | ||
PopulateList(); | ||
} | ||
|
||
public void PopulateList() | ||
{ | ||
CrewList.RemoveAllChildren(); | ||
|
||
foreach (var entry in CrewListCoords) | ||
{ | ||
var button = CreateTargetButton(entry.Name, () => OnTargetPicked?.Invoke(entry.Entity)); | ||
|
||
if (button == null) | ||
continue; | ||
|
||
CrewList.AddChild(button); | ||
} | ||
} | ||
|
||
private Button? CreateTargetButton(string fullName, Action onClick) | ||
{ | ||
if (!fullName.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase)) | ||
return null; | ||
|
||
var button = new Button | ||
{ | ||
ToolTip = fullName, | ||
StyleClasses = { "OpenBoth" }, | ||
SetHeight = 30, | ||
Margin = new Thickness(5, 0, 5, 5), | ||
HorizontalExpand = true, | ||
}; | ||
|
||
var label = new Label | ||
{ | ||
Text = fullName, | ||
HorizontalExpand = true, | ||
HorizontalAlignment = HAlignment.Center, | ||
}; | ||
|
||
button.OnPressed += _ => onClick(); | ||
button.AddChild(label); | ||
|
||
return button; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Content.Client/SS220/Pinpointer/UI/PinpointerUplinkMenu.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<controls:FancyWindow | ||
xmlns="https://spacestation14.io" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc 'pinpointer-ui-title'}" | ||
MinSize="350 300" | ||
Resizable="True"> | ||
|
||
<BoxContainer Orientation="Vertical" VerticalExpand="True"> | ||
<BoxContainer Orientation="Horizontal"> | ||
<Label Text="{Loc 'pinpointer-ui-item-to-track'}" | ||
Name="LabelTrack" | ||
HorizontalExpand="True" | ||
Access="Public" | ||
Margin="5 0 0 0"/> | ||
<Button Name="DNASearch" | ||
StyleClasses="OpenBoth" | ||
SetWidth="130" | ||
Text="{Loc 'pinpointer-ui-uplink-search-by-dna'}" | ||
Margin="0 0 5 0"/> | ||
</BoxContainer> | ||
<PanelContainer StyleClasses="HighDivider"/> | ||
|
||
<ScrollContainer VerticalExpand="True" HScrollEnabled="False"> | ||
<BoxContainer Name="ItemList" Orientation="Vertical"/> | ||
</ScrollContainer> | ||
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'object-tab-object-search'}" HorizontalExpand="true"/> | ||
</BoxContainer> | ||
|
||
</controls:FancyWindow> |
129 changes: 129 additions & 0 deletions
129
Content.Client/SS220/Pinpointer/UI/PinpointerUplinkMenu.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
|
||
using System.Numerics; | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.SS220.Pinpointer; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
|
||
namespace Content.Client.SS220.Pinpointer.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class PinpointerUplinkMenu : FancyWindow | ||
{ | ||
public FancyWindow? DnaWindow; | ||
|
||
public HashSet<TrackedItem> ItemListSet = []; | ||
|
||
public Action<NetEntity>? OnTargetPicked; | ||
public Action<string>? OnDnaPicked; | ||
|
||
private string _searchText = string.Empty; | ||
|
||
public PinpointerUplinkMenu() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
SearchBar.OnTextChanged += OnSearchChanged; | ||
DNASearch.OnPressed += OnDNASearch; | ||
} | ||
|
||
private void OnSearchChanged(LineEdit.LineEditEventArgs args) | ||
{ | ||
_searchText = args.Text.Trim().ToLower(); | ||
PopulateList(); | ||
} | ||
|
||
private void OnDNASearch(BaseButton.ButtonEventArgs args) | ||
{ | ||
if (DnaWindow != null) | ||
{ | ||
DnaWindow.Open(); | ||
return; | ||
} | ||
|
||
DnaWindow = new FancyWindow | ||
{ | ||
Title = Loc.GetString("pinpointer-ui-uplink-search-by-dna"), | ||
SetSize = new Vector2(200, 200), | ||
}; | ||
|
||
|
||
var boxContainer = new BoxContainer | ||
{ | ||
Orientation = BoxContainer.LayoutOrientation.Vertical, | ||
HorizontalAlignment = HAlignment.Center, | ||
VerticalAlignment = VAlignment.Center, | ||
}; | ||
|
||
var lineEdit = new LineEdit | ||
{ | ||
PlaceHolder = Loc.GetString("pinpointer-ui-uplink-enter-dna"), | ||
SetSize = new Vector2(150, 30), | ||
}; | ||
|
||
var button = new Button() | ||
{ | ||
Text = Loc.GetString("pinpointer-ui-uplink-accept"), | ||
Modulate = Color.LimeGreen, | ||
StyleClasses = { "OpenBoth" }, | ||
SetSize = new Vector2(150, 30), | ||
}; | ||
|
||
button.OnPressed += _ => | ||
{ | ||
if (string.IsNullOrEmpty(lineEdit.Text)) | ||
return; | ||
|
||
OnDnaPicked?.Invoke(lineEdit.Text); | ||
}; | ||
|
||
boxContainer.AddChild(lineEdit); | ||
boxContainer.AddChild(button); | ||
DnaWindow.AddChild(boxContainer); | ||
DnaWindow.OpenCentered(); | ||
} | ||
|
||
public void PopulateList() | ||
{ | ||
ItemList.RemoveAllChildren(); | ||
|
||
foreach (var entry in ItemListSet) | ||
{ | ||
var button = CreateTargetButton(entry.Name, () => OnTargetPicked?.Invoke(entry.Entity)); | ||
|
||
if (button == null) | ||
continue; | ||
|
||
ItemList.AddChild(button); | ||
} | ||
} | ||
|
||
private Button? CreateTargetButton(string fullName, Action onClick) | ||
{ | ||
if (!fullName.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase)) | ||
return null; | ||
|
||
var button = new Button | ||
{ | ||
ToolTip = fullName, | ||
StyleClasses = { "OpenBoth" }, | ||
SetHeight = 30, | ||
Margin = new Thickness(5, 0, 5, 5), | ||
HorizontalExpand = true, | ||
}; | ||
|
||
var label = new Label | ||
{ | ||
Text = fullName, | ||
HorizontalExpand = true, | ||
HorizontalAlignment = HAlignment.Center, | ||
}; | ||
|
||
button.OnPressed += _ => onClick(); | ||
button.AddChild(label); | ||
|
||
return button; | ||
} | ||
} | ||
|
Oops, something went wrong.