2020-08-13 14:40:27 +02:00
|
|
|
using System;
|
2020-10-16 11:22:58 +02:00
|
|
|
using System.Collections.Generic;
|
2020-08-13 14:40:27 +02:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.GameTicking.Managers;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.Roles;
|
2020-07-10 08:27:55 -05:00
|
|
|
using Robust.Client.Console;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
2020-12-20 04:33:10 +01:00
|
|
|
using Robust.Client.UserInterface;
|
2020-07-10 08:27:55 -05:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2020-07-10 08:27:55 -05:00
|
|
|
using Robust.Client.Utility;
|
2021-06-20 10:09:24 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-07-10 08:27:55 -05:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Utility;
|
2021-07-18 18:39:31 +02:00
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.LateJoin
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
|
|
|
|
public sealed class LateJoinGui : SS14Window
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2021-02-01 16:49:43 -08:00
|
|
|
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public event Action<string>? SelectedId;
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly Dictionary<string, JobButton> _jobButtons = new();
|
2021-07-18 18:39:31 +02:00
|
|
|
private readonly Dictionary<string, BoxContainer> _jobCategories = new();
|
2020-10-16 11:22:58 +02:00
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
public LateJoinGui()
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
MinSize = SetSize = (360, 560);
|
2020-07-10 08:27:55 -05:00
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
2021-06-21 02:13:54 +02:00
|
|
|
Title = Loc.GetString("late-join-gui-title");
|
2021-06-20 10:09:24 +02:00
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var jobList = new BoxContainer
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Vertical
|
|
|
|
|
};
|
|
|
|
|
var vBox = new BoxContainer
|
|
|
|
|
{
|
|
|
|
|
Orientation = LayoutOrientation.Vertical,
|
2020-12-20 04:33:10 +01:00
|
|
|
Children =
|
|
|
|
|
{
|
|
|
|
|
new ScrollContainer
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
VerticalExpand = true,
|
2020-12-20 04:33:10 +01:00
|
|
|
Children =
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
2020-12-20 04:33:10 +01:00
|
|
|
jobList
|
2020-07-10 08:27:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-20 04:33:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
Contents.AddChild(vBox);
|
|
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
var firstCategory = true;
|
|
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
foreach (var job in _prototypeManager.EnumeratePrototypes<JobPrototype>().OrderBy(j => j.Name))
|
|
|
|
|
{
|
2020-12-20 04:33:10 +01:00
|
|
|
foreach (var department in job.Departments)
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
2020-12-20 04:33:10 +01:00
|
|
|
if (!_jobCategories.TryGetValue(department, out var category))
|
|
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
category = new BoxContainer
|
2020-12-20 04:33:10 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Vertical,
|
2020-12-20 04:33:10 +01:00
|
|
|
Name = department,
|
2021-06-21 02:13:54 +02:00
|
|
|
ToolTip = Loc.GetString("late-join-gui-jobs-amount-in-department-tooltip",
|
|
|
|
|
("departmentName", department))
|
2020-12-20 04:33:10 +01:00
|
|
|
};
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
if (firstCategory)
|
|
|
|
|
{
|
|
|
|
|
firstCategory = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
category.AddChild(new Control
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
MinSize = new Vector2(0, 23),
|
2020-12-20 04:33:10 +01:00
|
|
|
});
|
|
|
|
|
}
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
category.AddChild(new PanelContainer
|
|
|
|
|
{
|
|
|
|
|
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#464966")},
|
|
|
|
|
Children =
|
|
|
|
|
{
|
|
|
|
|
new Label
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Text = Loc.GetString("late-join-gui-department-jobs-label", ("departmentName", department))
|
2020-12-20 04:33:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
_jobCategories[department] = category;
|
|
|
|
|
jobList.AddChild(category);
|
|
|
|
|
}
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
var jobButton = new JobButton(job.ID);
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var jobSelector = new BoxContainer
|
2020-12-20 04:33:10 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true
|
2020-12-20 04:33:10 +01:00
|
|
|
};
|
2020-07-10 08:27:55 -05:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
var icon = new TextureRect
|
|
|
|
|
{
|
|
|
|
|
TextureScale = (2, 2),
|
|
|
|
|
Stretch = TextureRect.StretchMode.KeepCentered
|
|
|
|
|
};
|
2020-10-16 11:22:58 +02:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
if (job.Icon != null)
|
|
|
|
|
{
|
|
|
|
|
var specifier = new SpriteSpecifier.Rsi(new ResourcePath("/Textures/Interface/Misc/job_icons.rsi"), job.Icon);
|
|
|
|
|
icon.Texture = specifier.Frame0();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobSelector.AddChild(icon);
|
2020-10-16 11:22:58 +02:00
|
|
|
|
2020-12-20 04:33:10 +01:00
|
|
|
var jobLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = job.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
jobSelector.AddChild(jobLabel);
|
|
|
|
|
jobButton.AddChild(jobSelector);
|
|
|
|
|
category.AddChild(jobButton);
|
|
|
|
|
|
|
|
|
|
jobButton.OnPressed += _ =>
|
|
|
|
|
{
|
|
|
|
|
SelectedId?.Invoke(jobButton.JobId);
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
if (!gameTicker.JobsAvailable.Contains(job.ID))
|
2020-12-20 04:33:10 +01:00
|
|
|
{
|
|
|
|
|
jobButton.Disabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_jobButtons[job.ID] = jobButton;
|
|
|
|
|
}
|
2020-07-10 08:27:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectedId += jobId =>
|
|
|
|
|
{
|
|
|
|
|
Logger.InfoS("latejoin", $"Late joining as ID: {jobId}");
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand($"joingame {CommandParsing.Escape(jobId)}");
|
2020-07-10 08:27:55 -05:00
|
|
|
Close();
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
gameTicker.LobbyJobsAvailableUpdated += JobsAvailableUpdated;
|
2020-07-10 08:27:55 -05:00
|
|
|
}
|
|
|
|
|
|
2020-10-16 11:22:58 +02:00
|
|
|
private void JobsAvailableUpdated(IReadOnlyList<string> jobs)
|
|
|
|
|
{
|
2020-11-21 14:02:00 +01:00
|
|
|
foreach (var (id, button) in _jobButtons)
|
2020-10-16 11:22:58 +02:00
|
|
|
{
|
|
|
|
|
button.Disabled = !jobs.Contains(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
EntitySystem.Get<ClientGameTicker>().LobbyJobsAvailableUpdated -= JobsAvailableUpdated;
|
2020-11-21 14:02:00 +01:00
|
|
|
_jobButtons.Clear();
|
2020-12-20 04:33:10 +01:00
|
|
|
_jobCategories.Clear();
|
2020-10-16 11:22:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-10 08:27:55 -05:00
|
|
|
}
|
2020-10-16 11:22:58 +02:00
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
class JobButton : ContainerButton
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
public string JobId { get; }
|
|
|
|
|
|
|
|
|
|
public JobButton(string jobId)
|
2020-07-10 08:27:55 -05:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
JobId = jobId;
|
2020-07-10 08:27:55 -05:00
|
|
|
AddStyleClass(StyleClassButton);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|