Re-organize all projects (#4166)
This commit is contained in:
@@ -1,233 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.GameObjects.Components.Research;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Research
|
||||
{
|
||||
public class LatheMenu : SS14Window
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private readonly ItemList _items;
|
||||
private readonly ItemList _materials;
|
||||
private readonly LineEdit _amountLineEdit;
|
||||
private readonly LineEdit _searchBar;
|
||||
public Button QueueButton;
|
||||
public Button ServerConnectButton;
|
||||
public Button ServerSyncButton;
|
||||
|
||||
public LatheBoundUserInterface Owner { get; }
|
||||
|
||||
private readonly List<LatheRecipePrototype> _shownRecipes = new();
|
||||
|
||||
public LatheMenu(LatheBoundUserInterface owner)
|
||||
{
|
||||
SetSize = MinSize = (300, 450);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Owner = owner;
|
||||
|
||||
Title = "Lathe Menu";
|
||||
|
||||
var vBox = new VBoxContainer()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
SeparationOverride = 5,
|
||||
};
|
||||
|
||||
var hBoxButtons = new HBoxContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
VerticalExpand = true,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
};
|
||||
|
||||
QueueButton = new Button()
|
||||
{
|
||||
Text = "Queue",
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
};
|
||||
|
||||
ServerConnectButton = new Button()
|
||||
{
|
||||
Text = "Server list",
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
};
|
||||
|
||||
ServerSyncButton = new Button()
|
||||
{
|
||||
Text = "Sync",
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
};
|
||||
|
||||
var spacer = new Control()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 3,
|
||||
};
|
||||
|
||||
var hBoxFilter = new HBoxContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
VerticalExpand = true,
|
||||
SizeFlagsStretchRatio = 1
|
||||
};
|
||||
|
||||
_searchBar = new LineEdit()
|
||||
{
|
||||
PlaceHolder = "Search Designs",
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 3
|
||||
};
|
||||
|
||||
_searchBar.OnTextChanged += Populate;
|
||||
|
||||
var filterButton = new Button()
|
||||
{
|
||||
Text = "Filter",
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
Disabled = true,
|
||||
};
|
||||
|
||||
_items = new ItemList()
|
||||
{
|
||||
SizeFlagsStretchRatio = 8,
|
||||
VerticalExpand = true,
|
||||
SelectMode = ItemList.ItemListSelectMode.Button,
|
||||
};
|
||||
|
||||
_items.OnItemSelected += ItemSelected;
|
||||
|
||||
_amountLineEdit = new LineEdit()
|
||||
{
|
||||
PlaceHolder = "Amount",
|
||||
Text = "1",
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
|
||||
_amountLineEdit.OnTextChanged += PopulateDisabled;
|
||||
|
||||
_materials = new ItemList()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
SizeFlagsStretchRatio = 3
|
||||
};
|
||||
|
||||
hBoxButtons.AddChild(spacer);
|
||||
if (Owner.Database is ProtolatheDatabaseComponent database)
|
||||
{
|
||||
hBoxButtons.AddChild(ServerConnectButton);
|
||||
hBoxButtons.AddChild(ServerSyncButton);
|
||||
database.OnDatabaseUpdated += Populate;
|
||||
}
|
||||
hBoxButtons.AddChild(QueueButton);
|
||||
|
||||
hBoxFilter.AddChild(_searchBar);
|
||||
hBoxFilter.AddChild(filterButton);
|
||||
|
||||
vBox.AddChild(hBoxButtons);
|
||||
vBox.AddChild(hBoxFilter);
|
||||
vBox.AddChild(_items);
|
||||
vBox.AddChild(_amountLineEdit);
|
||||
vBox.AddChild(_materials);
|
||||
|
||||
Contents.AddChild(vBox);
|
||||
}
|
||||
|
||||
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
|
||||
{
|
||||
int.TryParse(_amountLineEdit.Text, out var quantity);
|
||||
if (quantity <= 0) quantity = 1;
|
||||
Owner.Queue(_shownRecipes[args.ItemIndex], quantity);
|
||||
}
|
||||
|
||||
public void PopulateMaterials()
|
||||
{
|
||||
_materials.Clear();
|
||||
|
||||
if (Owner.Storage == null) return;
|
||||
|
||||
foreach (var (id, amount) in Owner.Storage)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(id, out MaterialPrototype? materialPrototype)) continue;
|
||||
var material = materialPrototype;
|
||||
_materials.AddItem($"{material.Name} {amount} cm³", material.Icon.Frame0(), false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables or enables shown recipes depending on whether there are enough materials for it or not.
|
||||
/// </summary>
|
||||
public void PopulateDisabled()
|
||||
{
|
||||
int.TryParse(_amountLineEdit.Text, out var quantity);
|
||||
if (quantity <= 0) quantity = 1;
|
||||
for (var i = 0; i < _shownRecipes.Count; i++)
|
||||
{
|
||||
var prototype = _shownRecipes[i];
|
||||
_items[i].Disabled = !Owner.Lathe?.CanProduce(prototype, quantity) ?? true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PopulateDisabled()"/>
|
||||
public void PopulateDisabled(LineEdit.LineEditEventArgs args)
|
||||
{
|
||||
PopulateDisabled();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds shown recipes to the ItemList control.
|
||||
/// </summary>
|
||||
public void PopulateList()
|
||||
{
|
||||
_items.Clear();
|
||||
foreach (var prototype in _shownRecipes)
|
||||
{
|
||||
_items.AddItem(prototype.Name, prototype.Icon.Frame0());
|
||||
}
|
||||
|
||||
PopulateDisabled();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the list of recipes that will actually be shown, using the current filters.
|
||||
/// </summary>
|
||||
public void Populate()
|
||||
{
|
||||
_shownRecipes.Clear();
|
||||
|
||||
if (Owner.Database == null) return;
|
||||
|
||||
foreach (var prototype in Owner.Database)
|
||||
{
|
||||
if (_searchBar.Text.Trim().Length != 0)
|
||||
{
|
||||
if (prototype.Name.ToLowerInvariant().Contains(_searchBar.Text.Trim().ToLowerInvariant()))
|
||||
_shownRecipes.Add(prototype);
|
||||
continue;
|
||||
}
|
||||
|
||||
_shownRecipes.Add(prototype);
|
||||
}
|
||||
|
||||
PopulateList();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Populate"/>
|
||||
public void Populate(LineEdit.LineEditEventArgs args)
|
||||
{
|
||||
Populate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
using Content.Client.GameObjects.Components.Research;
|
||||
using Content.Shared.Research;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Research
|
||||
{
|
||||
public class LatheQueueMenu : SS14Window
|
||||
{
|
||||
public LatheBoundUserInterface Owner { get; set; }
|
||||
|
||||
[ViewVariables]
|
||||
private readonly ItemList _queueList;
|
||||
private readonly Label _nameLabel;
|
||||
private readonly Label _description;
|
||||
private readonly TextureRect _icon;
|
||||
|
||||
public LatheQueueMenu(LatheBoundUserInterface owner)
|
||||
{
|
||||
Owner = owner;
|
||||
SetSize = MinSize = (300, 450);
|
||||
Title = Loc.GetString("lathequeue-menu-title");
|
||||
|
||||
var vBox = new VBoxContainer();
|
||||
|
||||
var hBox = new HBoxContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
};
|
||||
|
||||
_icon = new TextureRect()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
};
|
||||
|
||||
var vBoxInfo = new VBoxContainer()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
SizeFlagsStretchRatio = 3,
|
||||
};
|
||||
|
||||
_nameLabel = new Label()
|
||||
{
|
||||
RectClipContent = true,
|
||||
};
|
||||
|
||||
_description = new Label()
|
||||
{
|
||||
RectClipContent = true,
|
||||
VerticalAlignment = VAlignment.Stretch,
|
||||
VerticalExpand = true
|
||||
|
||||
};
|
||||
|
||||
_queueList = new ItemList()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
SizeFlagsStretchRatio = 3,
|
||||
SelectMode = ItemList.ItemListSelectMode.None
|
||||
};
|
||||
|
||||
vBoxInfo.AddChild(_nameLabel);
|
||||
vBoxInfo.AddChild(_description);
|
||||
|
||||
hBox.AddChild(_icon);
|
||||
hBox.AddChild(vBoxInfo);
|
||||
|
||||
vBox.AddChild(hBox);
|
||||
vBox.AddChild(_queueList);
|
||||
|
||||
Contents.AddChild(vBox);
|
||||
|
||||
ClearInfo();
|
||||
}
|
||||
|
||||
public void SetInfo(LatheRecipePrototype recipe)
|
||||
{
|
||||
_icon.Texture = recipe.Icon.Frame0();
|
||||
if (recipe.Name != null)
|
||||
_nameLabel.Text = recipe.Name;
|
||||
if (recipe.Description != null)
|
||||
_description.Text = recipe.Description;
|
||||
}
|
||||
|
||||
public void ClearInfo()
|
||||
{
|
||||
_icon.Texture = Texture.Transparent;
|
||||
_nameLabel.Text = "-------";
|
||||
_description.Text = "Not producing anything.";
|
||||
}
|
||||
|
||||
public void PopulateList()
|
||||
{
|
||||
_queueList.Clear();
|
||||
var idx = 1;
|
||||
foreach (var recipe in Owner.QueuedRecipes)
|
||||
{
|
||||
_queueList.AddItem($"{idx}. {recipe.Name}", recipe.Icon.Frame0());
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Content.Client/Research/TechnologyDatabaseComponent.cs
Normal file
37
Content.Client/Research/TechnologyDatabaseComponent.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using Content.Shared.Research.Components;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Research
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class TechnologyDatabaseComponent : SharedTechnologyDatabaseComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Event called when the database is updated.
|
||||
/// </summary>
|
||||
public event Action? OnDatabaseUpdated;
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not TechnologyDatabaseState state) return;
|
||||
|
||||
_technologies.Clear();
|
||||
|
||||
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
foreach (var techID in state.Technologies)
|
||||
{
|
||||
if (!protoManager.TryIndex(techID, out TechnologyPrototype? technology)) continue;
|
||||
_technologies.Add(technology);
|
||||
}
|
||||
|
||||
OnDatabaseUpdated?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using static Content.Shared.Research.Components.SharedResearchClientComponent;
|
||||
|
||||
namespace Content.Client.Research.UI
|
||||
{
|
||||
public class ResearchClientBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private ResearchClientServerSelectionMenu? _menu;
|
||||
|
||||
public ResearchClientBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
SendMessage(new ResearchClientSyncMessage());
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new ResearchClientServerSelectionMenu(this);
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
public void SelectServer(int serverId)
|
||||
{
|
||||
SendMessage(new ResearchClientServerSelectedMessage(serverId));
|
||||
}
|
||||
|
||||
public void DeselectServer()
|
||||
{
|
||||
SendMessage(new ResearchClientServerDeselectedMessage());
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (state is not ResearchClientBoundInterfaceState rState) return;
|
||||
_menu?.Populate(rState.ServerCount, rState.ServerNames, rState.ServerIds, rState.SelectedServerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Research.UI
|
||||
{
|
||||
public class ResearchClientServerSelectionMenu : SS14Window
|
||||
{
|
||||
private readonly ItemList _servers;
|
||||
private int _serverCount;
|
||||
private string[] _serverNames = new string[]{};
|
||||
private int[] _serverIds = new int[]{};
|
||||
private int _selectedServerId = -1;
|
||||
|
||||
public ResearchClientBoundUserInterface Owner { get; }
|
||||
|
||||
public ResearchClientServerSelectionMenu(ResearchClientBoundUserInterface owner)
|
||||
{
|
||||
MinSize = SetSize = (300, 300);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Owner = owner;
|
||||
Title = Loc.GetString("Research Server Selection");
|
||||
|
||||
_servers = new ItemList() {SelectMode = ItemList.ItemListSelectMode.Single};
|
||||
|
||||
_servers.OnItemSelected += OnItemSelected;
|
||||
_servers.OnItemDeselected += OnItemDeselected;
|
||||
|
||||
Contents.AddChild(_servers);
|
||||
}
|
||||
|
||||
public void OnItemSelected(ItemList.ItemListSelectedEventArgs itemListSelectedEventArgs)
|
||||
{
|
||||
Owner.SelectServer(_serverIds[itemListSelectedEventArgs.ItemIndex]);
|
||||
}
|
||||
|
||||
public void OnItemDeselected(ItemList.ItemListDeselectedEventArgs itemListDeselectedEventArgs)
|
||||
{
|
||||
Owner.DeselectServer();
|
||||
}
|
||||
|
||||
public void Populate(int serverCount, string[] serverNames, int[] serverIds, int selectedServerId)
|
||||
{
|
||||
_serverCount = serverCount;
|
||||
_serverNames = serverNames;
|
||||
_serverIds = serverIds;
|
||||
_selectedServerId = selectedServerId;
|
||||
|
||||
// Disable so we can select the new selected server without triggering a new sync request.
|
||||
_servers.OnItemSelected -= OnItemSelected;
|
||||
_servers.OnItemDeselected -= OnItemDeselected;
|
||||
|
||||
_servers.Clear();
|
||||
for (var i = 0; i < _serverCount; i++)
|
||||
{
|
||||
var id = _serverIds[i];
|
||||
_servers.AddItem($"ID: {id} || {_serverNames[i]}");
|
||||
if (id == _selectedServerId)
|
||||
_servers[id].Selected = true;
|
||||
}
|
||||
|
||||
_servers.OnItemSelected += OnItemSelected;
|
||||
_servers.OnItemDeselected += OnItemDeselected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using static Content.Shared.Research.Components.SharedResearchConsoleComponent;
|
||||
|
||||
namespace Content.Client.Research.UI
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ResearchConsoleBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
public int Points { get; private set; }
|
||||
public int PointsPerSecond { get; private set; }
|
||||
private ResearchConsoleMenu? _consoleMenu;
|
||||
private TechnologyDatabaseComponent? _technologyDatabase;
|
||||
|
||||
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
SendMessage(new ConsoleServerSyncMessage());
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
if (!Owner.Owner.TryGetComponent(out _technologyDatabase)) return;
|
||||
|
||||
_consoleMenu = new ResearchConsoleMenu(this);
|
||||
|
||||
_consoleMenu.OnClose += Close;
|
||||
|
||||
_consoleMenu.ServerSyncButton.OnPressed += (_) =>
|
||||
{
|
||||
SendMessage(new ConsoleServerSyncMessage());
|
||||
};
|
||||
|
||||
_consoleMenu.ServerSelectionButton.OnPressed += (_) =>
|
||||
{
|
||||
SendMessage(new ConsoleServerSelectionMessage());
|
||||
};
|
||||
|
||||
_consoleMenu.UnlockButton.OnPressed += (_) =>
|
||||
{
|
||||
if (_consoleMenu.TechnologySelected != null)
|
||||
{
|
||||
SendMessage(new ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID));
|
||||
}
|
||||
};
|
||||
|
||||
_consoleMenu.OpenCentered();
|
||||
|
||||
_technologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate;
|
||||
}
|
||||
|
||||
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
||||
{
|
||||
return _technologyDatabase?.IsTechnologyUnlocked(technology) ?? false;
|
||||
}
|
||||
|
||||
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
||||
{
|
||||
return _technologyDatabase?.CanUnlockTechnology(technology) ?? false;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
var castState = (ResearchConsoleBoundInterfaceState)state;
|
||||
Points = castState.Points;
|
||||
PointsPerSecond = castState.PointsPerSecond;
|
||||
// We update the user interface here.
|
||||
_consoleMenu?.PopulatePoints();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
_consoleMenu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.GameObjects.Components.Research;
|
||||
using Content.Shared.Research;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
@@ -9,7 +8,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Research
|
||||
namespace Content.Client.Research.UI
|
||||
{
|
||||
public class ResearchConsoleMenu : SS14Window
|
||||
{
|
||||
Reference in New Issue
Block a user