Adds Research, unlockable technologies, Protolathes... (#264)

* Work on Research so far
More work on UI...
Fix ResearchClient and Protolathe UI stuff.
Fix infinite select -> request state -> select -> ... loop
Add UI to ResearchClient, etc.
Technology Database states, and a bit of work on the research console ui
A bit of work on Research Console UI
Protolathe sync
Stuff that actually does things
Protolathe databases yay
Alright got my motivation back
Yeah, no. It's almost 3 AM already
Fix serialization bug again
More work on stuff
Stuff
Adds files for most new components/systems.

* Protolathes actually work now

* Research. Just Research.

* Adds icons from Eris.

* Address reviews

* Change LatheMenu resize behaviour

* Update Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Update Content.Client/Research/ResearchConsoleMenu.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Move IoC Resolve out of for loop

* Address review

* Localize stuff
This commit is contained in:
Víctor Aguilera Puerto
2019-09-03 22:51:19 +02:00
committed by Pieter-Jan Briers
parent b62fb4a318
commit ba8b495ec0
61 changed files with 1884 additions and 23 deletions

View File

@@ -23,7 +23,7 @@ namespace Content.Client.GameObjects.Components.Research
public MaterialStorageComponent Storage { get; private set; }
public SharedLatheComponent Lathe { get; private set; }
public LatheDatabaseComponent Database { get; private set; }
public SharedLatheDatabaseComponent Database { get; private set; }
[ViewVariables]
public Queue<LatheRecipePrototype> QueuedRecipes => _queuedRecipes;
@@ -41,13 +41,15 @@ namespace Content.Client.GameObjects.Components.Research
if (!Owner.Owner.TryGetComponent(out MaterialStorageComponent storage)
|| !Owner.Owner.TryGetComponent(out SharedLatheComponent lathe)
|| !Owner.Owner.TryGetComponent(out LatheDatabaseComponent database)) return;
|| !Owner.Owner.TryGetComponent(out SharedLatheDatabaseComponent database)) return;
Storage = storage;
Lathe = lathe;
Database = database;
menu = new LatheMenu {Owner = this};
menu = new LatheMenu(this);
queueMenu = new LatheQueueMenu { Owner = this };
menu.OnClose += Close;
@@ -57,6 +59,16 @@ namespace Content.Client.GameObjects.Components.Research
menu.QueueButton.OnPressed += (args) => { queueMenu.OpenCentered(); };
menu.ServerConnectButton.OnPressed += (args) =>
{
SendMessage(new SharedLatheComponent.LatheServerSelectionMessage());
};
menu.ServerSyncButton.OnPressed += (args) =>
{
SendMessage(new SharedLatheComponent.LatheServerSyncMessage());
};
storage.OnMaterialStorageChanged += menu.PopulateDisabled;
storage.OnMaterialStorageChanged += menu.PopulateMaterials;
@@ -74,10 +86,10 @@ namespace Content.Client.GameObjects.Components.Research
{
case SharedLatheComponent.LatheProducingRecipeMessage msg:
if (!_prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe)) break;
queueMenu.SetInfo(recipe);
queueMenu?.SetInfo(recipe);
break;
case SharedLatheComponent.LatheStoppedProducingRecipeMessage msg:
queueMenu.ClearInfo();
queueMenu?.ClearInfo();
break;
case SharedLatheComponent.LatheFullQueueMessage msg:
_queuedRecipes.Clear();
@@ -86,7 +98,7 @@ namespace Content.Client.GameObjects.Components.Research
if (!_prototypeManager.TryIndex(id, out LatheRecipePrototype recipePrototype)) break;
_queuedRecipes.Enqueue(recipePrototype);
}
queueMenu.PopulateList();
queueMenu?.PopulateList();
break;
}
}

View File

@@ -0,0 +1,38 @@
using System;
using Content.Shared.GameObjects.Components.Research;
using Content.Shared.Research;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.Components.Research
{
[RegisterComponent]
[ComponentReference(typeof(SharedLatheDatabaseComponent))]
public class ProtolatheDatabaseComponent : SharedProtolatheDatabaseComponent
{
#pragma warning disable CS0649
[Dependency]
private IPrototypeManager _prototypeManager;
#pragma warning restore
/// <summary>
/// Invoked when the database gets updated.
/// </summary>
public event Action OnDatabaseUpdated;
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
base.HandleComponentState(curState, nextState);
if (!(curState is ProtolatheDatabaseState state)) return;
Clear();
foreach (var ID in state.Recipes)
{
if(!_prototypeManager.TryIndex(ID, out LatheRecipePrototype recipe)) continue;
AddRecipe(recipe);
}
OnDatabaseUpdated?.Invoke();
}
}
}

View File

@@ -0,0 +1,46 @@
using Content.Shared.GameObjects.Components.Research;
using Robust.Client.GameObjects.Components.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects.Components.UserInterface;
namespace Content.Client.GameObjects.Components.Research
{
public class ResearchClientBoundUserInterface : BoundUserInterface
{
private ResearchClientServerSelectionMenu _menu;
public ResearchClientBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
SendMessage(new SharedResearchClientComponent.ResearchClientSyncMessage());
}
protected override void Open()
{
base.Open();
_menu = new ResearchClientServerSelectionMenu() { Owner = this };
_menu.OnClose += Close;
_menu.OpenCentered();
}
public void SelectServer(int serverId)
{
SendMessage(new SharedResearchClientComponent.ResearchClientServerSelectedMessage(serverId));
}
public void DeselectServer()
{
SendMessage(new SharedResearchClientComponent.ResearchClientServerDeselectedMessage());
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (!(state is SharedResearchClientComponent.ResearchClientBoundInterfaceState rstate)) return;
_menu.Populate(rstate.ServerCount, rstate.ServerNames, rstate.ServerIds, rstate.SelectedServerId);
}
}
}

View File

@@ -0,0 +1,86 @@
using System;
using Content.Shared.GameObjects.Components.Research;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
namespace Content.Client.GameObjects.Components.Research
{
public class ResearchClientServerSelectionMenu : SS14Window
{
private ItemList _servers;
private int _serverCount = 0;
private string[] _serverNames = new string[]{};
private int[] _serverIds = new int[]{};
private int _selectedServerId = -1;
#pragma warning disable 649
[Dependency] private readonly ILocalizationManager _localizationManager;
#pragma warning restore 649
protected override Vector2? CustomSize => (300, 300);
public ResearchClientBoundUserInterface Owner { get; set; }
public ResearchClientServerSelectionMenu()
{
IoCManager.InjectDependencies(this);
Title = _localizationManager.GetString("Research Server Selection");
_servers = new ItemList() {SelectMode = ItemList.ItemListSelectMode.Single};
_servers.OnItemSelected += OnItemSelected;
_servers.OnItemDeselected += OnItemDeselected;
var margin = new MarginContainer()
{
SizeFlagsVertical = SizeFlags.FillExpand,
SizeFlagsHorizontal = SizeFlags.FillExpand,
MarginTop = 5f,
MarginLeft = 5f,
MarginRight = -5f,
MarginBottom = -5f,
};
margin.AddChild(_servers);
Contents.AddChild(margin);
}
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.Select(i);
}
_servers.OnItemSelected += OnItemSelected;
_servers.OnItemDeselected += OnItemDeselected;
}
}
}

View File

@@ -0,0 +1,80 @@
using Content.Client.Research;
using Content.Shared.GameObjects.Components.Research;
using Content.Shared.Research;
using Robust.Client.GameObjects.Components.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Log;
namespace Content.Client.GameObjects.Components.Research
{
public class ResearchConsoleBoundUserInterface : BoundUserInterface
{
public int Points { get; private set; } = 0;
public int PointsPerSecond { get; private set; } = 0;
private ResearchConsoleMenu _consoleMenu;
private TechnologyDatabaseComponent TechnologyDatabase;
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
SendMessage(new SharedResearchConsoleComponent.ConsoleServerSyncMessage());
}
protected override void Open()
{
base.Open();
if (!Owner.Owner.TryGetComponent(out TechnologyDatabase)) return;
_consoleMenu = new ResearchConsoleMenu(this);
_consoleMenu.ServerSyncButton.OnPressed += (args) =>
{
SendMessage(new SharedResearchConsoleComponent.ConsoleServerSyncMessage());
};
_consoleMenu.ServerSelectionButton.OnPressed += (args) =>
{
SendMessage(new SharedResearchConsoleComponent.ConsoleServerSelectionMessage());
};
_consoleMenu.UnlockButton.OnPressed += (args) =>
{
SendMessage(new SharedResearchConsoleComponent.ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID));
};
_consoleMenu.OpenCentered();
TechnologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate;
}
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
{
return TechnologyDatabase.IsTechnologyUnlocked(technology);
}
public bool CanUnlockTechnology(TechnologyPrototype technology)
{
return TechnologyDatabase.CanUnlockTechnology(technology);
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var castState = (SharedResearchConsoleComponent.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();
}
}
}

View File

@@ -0,0 +1,35 @@
using System;
using Content.Shared.GameObjects.Components.Research;
using Content.Shared.Research;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using SixLabors.ImageSharp.Processing;
namespace Content.Client.GameObjects.Components.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 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();
}
}
}