diff --git a/Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml b/Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml new file mode 100644 index 0000000000..a8ef2dc427 --- /dev/null +++ b/Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Content.Client/Research/UI/ResearchClientServerSelectionMenu.cs b/Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml.cs similarity index 60% rename from Content.Client/Research/UI/ResearchClientServerSelectionMenu.cs rename to Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml.cs index 791e378a86..2ffad40961 100644 --- a/Content.Client/Research/UI/ResearchClientServerSelectionMenu.cs +++ b/Content.Client/Research/UI/ResearchClientServerSelectionMenu.xaml.cs @@ -1,34 +1,31 @@ +using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; +using Robust.Client.UserInterface.XAML; using Robust.Shared.IoC; using Robust.Shared.Localization; namespace Content.Client.Research.UI { - public class ResearchClientServerSelectionMenu : SS14Window + [GenerateTypedNameReferences] + public partial class ResearchClientServerSelectionMenu : SS14Window { - private readonly ItemList _servers; private int _serverCount; private string[] _serverNames = System.Array.Empty(); private int[] _serverIds = System.Array.Empty(); private int _selectedServerId = -1; - public ResearchClientBoundUserInterface Owner { get; } + private ResearchClientBoundUserInterface Owner { get; } public ResearchClientServerSelectionMenu(ResearchClientBoundUserInterface owner) { - MinSize = SetSize = (300, 300); + RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); Owner = owner; - Title = Loc.GetString("research-client-server-selection-menu-title"); - _servers = new ItemList() {SelectMode = ItemList.ItemListSelectMode.Single}; - - _servers.OnItemSelected += OnItemSelected; - _servers.OnItemDeselected += OnItemDeselected; - - Contents.AddChild(_servers); + Servers.OnItemSelected += OnItemSelected; + Servers.OnItemDeselected += OnItemDeselected; } public void OnItemSelected(ItemList.ItemListSelectedEventArgs itemListSelectedEventArgs) @@ -49,22 +46,22 @@ namespace Content.Client.Research.UI _selectedServerId = selectedServerId; // Disable so we can select the new selected server without triggering a new sync request. - _servers.OnItemSelected -= OnItemSelected; - _servers.OnItemDeselected -= OnItemDeselected; + Servers.OnItemSelected -= OnItemSelected; + Servers.OnItemDeselected -= OnItemDeselected; - _servers.Clear(); + Servers.Clear(); for (var i = 0; i < _serverCount; i++) { var id = _serverIds[i]; - _servers.AddItem(Loc.GetString("research-client-server-selection-menu-server-entry-text", ("id", id), ("serverName", _serverNames[i]))); + Servers.AddItem(Loc.GetString("research-client-server-selection-menu-server-entry-text", ("id", id), ("serverName", _serverNames[i]))); if (id == _selectedServerId) { - _servers[id].Selected = true; + Servers[id].Selected = true; } } - _servers.OnItemSelected += OnItemSelected; - _servers.OnItemDeselected += OnItemDeselected; + Servers.OnItemSelected += OnItemSelected; + Servers.OnItemDeselected += OnItemDeselected; } } } diff --git a/Content.Client/Research/UI/ResearchConsoleMenu.cs b/Content.Client/Research/UI/ResearchConsoleMenu.cs deleted file mode 100644 index 608aee28be..0000000000 --- a/Content.Client/Research/UI/ResearchConsoleMenu.cs +++ /dev/null @@ -1,309 +0,0 @@ -using System.Collections.Generic; -using Content.Shared.Research.Prototypes; -using Robust.Client.Graphics; -using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.CustomControls; -using Robust.Client.Utility; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Prototypes; -using static Robust.Client.UserInterface.Controls.BoxContainer; - -namespace Content.Client.Research.UI -{ - public class ResearchConsoleMenu : SS14Window - { - public ResearchConsoleBoundUserInterface Owner { get; } - - private readonly List _unlockedTechnologyPrototypes = new(); - private readonly List _unlockableTechnologyPrototypes = new(); - private readonly List _futureTechnologyPrototypes = new(); - - private readonly Label _pointLabel; - private readonly Label _pointsPerSecondLabel; - private readonly Label _technologyName; - private readonly Label _technologyDescription; - private readonly Label _technologyRequirements; - private readonly TextureRect _technologyIcon; - private readonly ItemList _unlockedTechnologies; - private readonly ItemList _unlockableTechnologies; - private readonly ItemList _futureTechnologies; - - public Button UnlockButton { get; private set; } - public Button ServerSelectionButton { get; private set; } - public Button ServerSyncButton { get; private set; } - - public TechnologyPrototype? TechnologySelected; - - public ResearchConsoleMenu(ResearchConsoleBoundUserInterface owner) - { - SetSize = MinSize = (800, 400); - - IoCManager.InjectDependencies(this); - - Title = Loc.GetString("research-console-menu-title"); - - Owner = owner; - - _unlockedTechnologies = new ItemList() - { - SelectMode = ItemList.ItemListSelectMode.Button, - HorizontalExpand = true, - VerticalExpand = true, - }; - - _unlockedTechnologies.OnItemSelected += UnlockedTechnologySelected; - - _unlockableTechnologies = new ItemList() - { - SelectMode = ItemList.ItemListSelectMode.Button, - HorizontalExpand = true, - VerticalExpand = true, - }; - - _unlockableTechnologies.OnItemSelected += UnlockableTechnologySelected; - - _futureTechnologies = new ItemList() - { - SelectMode = ItemList.ItemListSelectMode.Button, - HorizontalExpand = true, - VerticalExpand = true, - }; - - _futureTechnologies.OnItemSelected += FutureTechnologySelected; - - var vbox = new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - HorizontalExpand = true, - VerticalExpand = true, - }; - - var hboxTechnologies = new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - HorizontalExpand = true, - VerticalExpand = true, - SizeFlagsStretchRatio = 2, - SeparationOverride = 10, - }; - - var hboxSelected = new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - HorizontalExpand = true, - VerticalExpand = true, - SizeFlagsStretchRatio = 1 - }; - - var vboxPoints = new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - HorizontalExpand = true, - VerticalExpand = true, - SizeFlagsStretchRatio = 1, - }; - - var vboxTechInfo = new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - HorizontalExpand = true, - VerticalExpand = true, - SizeFlagsStretchRatio = 3, - }; - - _pointLabel = new Label() { Text = Loc.GetString("research-console-menu-research-points-text", ("points", 0)) }; - _pointsPerSecondLabel = new Label() { Text = Loc.GetString("research-console-menu-points-per-second-text", ("pointsPerSecond", 0)) }; - - var vboxPointsButtons = new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - Align = AlignMode.End, - HorizontalExpand = true, - VerticalExpand = true, - }; - - ServerSelectionButton = new Button() { Text = Loc.GetString("research-console-menu-server-selection-button") }; - ServerSyncButton = new Button() { Text = Loc.GetString("research-console-menu-server-sync-button") }; - UnlockButton = new Button() { Text = Loc.GetString("research-console-menu-server-unlock-button"), Disabled = true }; - - - vboxPointsButtons.AddChild(ServerSelectionButton); - vboxPointsButtons.AddChild(ServerSyncButton); - vboxPointsButtons.AddChild(UnlockButton); - - vboxPoints.AddChild(_pointLabel); - vboxPoints.AddChild(_pointsPerSecondLabel); - vboxPoints.AddChild(vboxPointsButtons); - - _technologyIcon = new TextureRect() - { - HorizontalExpand = true, - VerticalExpand = true, - SizeFlagsStretchRatio = 1, - Stretch = TextureRect.StretchMode.KeepAspectCentered, - }; - _technologyName = new Label(); - _technologyDescription = new Label(); - _technologyRequirements = new Label(); - - vboxTechInfo.AddChild(_technologyName); - vboxTechInfo.AddChild(_technologyDescription); - vboxTechInfo.AddChild(_technologyRequirements); - - hboxSelected.AddChild(_technologyIcon); - hboxSelected.AddChild(vboxTechInfo); - hboxSelected.AddChild(vboxPoints); - - hboxTechnologies.AddChild(_unlockedTechnologies); - hboxTechnologies.AddChild(_unlockableTechnologies); - hboxTechnologies.AddChild(_futureTechnologies); - - vbox.AddChild(hboxTechnologies); - vbox.AddChild(hboxSelected); - - Contents.AddChild(vbox); - - UnlockButton.OnPressed += (args) => - { - CleanSelectedTechnology(); - }; - - Populate(); - } - - /// - /// Cleans the selected technology controls to blank. - /// - private void CleanSelectedTechnology() - { - UnlockButton.Disabled = true; - _technologyIcon.Texture = Texture.Transparent; - _technologyName.Text = string.Empty; - _technologyDescription.Text = string.Empty; - _technologyRequirements.Text = string.Empty; - } - - /// - /// Called when an unlocked technology is selected. - /// - private void UnlockedTechnologySelected(ItemList.ItemListSelectedEventArgs obj) - { - TechnologySelected = _unlockedTechnologyPrototypes[obj.ItemIndex]; - - UnlockButton.Disabled = true; - - PopulateSelectedTechnology(); - } - - /// - /// Called when an unlockable technology is selected. - /// - private void UnlockableTechnologySelected(ItemList.ItemListSelectedEventArgs obj) - { - TechnologySelected = _unlockableTechnologyPrototypes[obj.ItemIndex]; - - UnlockButton.Disabled = Owner.Points < TechnologySelected.RequiredPoints; - - PopulateSelectedTechnology(); - } - - /// - /// Called when a future technology is selected - /// - private void FutureTechnologySelected(ItemList.ItemListSelectedEventArgs obj) - { - TechnologySelected = _futureTechnologyPrototypes[obj.ItemIndex]; - - UnlockButton.Disabled = true; - - PopulateSelectedTechnology(); - } - - /// - /// Populate all technologies in the ItemLists. - /// - public void PopulateItemLists() - { - _unlockedTechnologies.Clear(); - _unlockableTechnologies.Clear(); - _futureTechnologies.Clear(); - - _unlockedTechnologyPrototypes.Clear(); - _unlockableTechnologyPrototypes.Clear(); - _futureTechnologyPrototypes.Clear(); - - var prototypeMan = IoCManager.Resolve(); - - // For now, we retrieve all technologies. In the future, this should be changed. - foreach (var tech in prototypeMan.EnumeratePrototypes()) - { - if (Owner.IsTechnologyUnlocked(tech)) - { - _unlockedTechnologies.AddItem(tech.Name, tech.Icon.Frame0()); - _unlockedTechnologyPrototypes.Add(tech); - } - else if (Owner.CanUnlockTechnology(tech)) - { - _unlockableTechnologies.AddItem(tech.Name, tech.Icon.Frame0()); - _unlockableTechnologyPrototypes.Add(tech); - } - else - { - _futureTechnologies.AddItem(tech.Name, tech.Icon.Frame0()); - _futureTechnologyPrototypes.Add(tech); - } - } - } - - /// - /// Fills the selected technology controls with details. - /// - public void PopulateSelectedTechnology() - { - if (TechnologySelected == null) - { - _technologyName.Text = string.Empty; - _technologyDescription.Text = string.Empty; - _technologyRequirements.Text = string.Empty; - return; - } - - _technologyIcon.Texture = TechnologySelected.Icon.Frame0(); - _technologyName.Text = TechnologySelected.Name; - _technologyDescription.Text = TechnologySelected.Description + $"\n{TechnologySelected.RequiredPoints} " + Loc.GetString("research-console-menu-research-points-text" ,("points", Owner.Points)).ToLowerInvariant(); - _technologyRequirements.Text = Loc.GetString("research-console-tech-requirements-none"); - - var prototypeMan = IoCManager.Resolve(); - - for (var i = 0; i < TechnologySelected.RequiredTechnologies.Count; i++) - { - var requiredId = TechnologySelected.RequiredTechnologies[i]; - if (!prototypeMan.TryIndex(requiredId, out TechnologyPrototype? prototype)) continue; - if (i == 0) - _technologyRequirements.Text = Loc.GetString("research-console-tech-requirements-prototype-name", ("prototypeName", prototype.Name)); - else - _technologyRequirements.Text += $", {prototype.Name}"; - } - } - - /// - /// Updates the research point labels. - /// - public void PopulatePoints() - { - _pointLabel.Text = Loc.GetString("research-console-menu-research-points-text", ("points", Owner.Points)); - _pointsPerSecondLabel.Text = Loc.GetString("research-console-menu-points-per-second-text", ("pointsPerSecond", Owner.PointsPerSecond)); - } - - /// - /// Updates the whole user interface. - /// - public void Populate() - { - PopulatePoints(); - PopulateSelectedTechnology(); - PopulateItemLists(); - } - } -} diff --git a/Content.Client/Research/UI/ResearchConsoleMenu.xaml b/Content.Client/Research/UI/ResearchConsoleMenu.xaml new file mode 100644 index 0000000000..636f5dbb92 --- /dev/null +++ b/Content.Client/Research/UI/ResearchConsoleMenu.xaml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + +