Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost Bar!!!! (From Goobstation) #1675

Merged
merged 17 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Content.Client/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public void OpenGhostRoles()
_console.RemoteExecuteCommand(null, "ghostroles");
}

public void GhostBarSpawn() // Goobstation - Ghost Bar
{
RaiseNetworkEvent(new GhostBarSpawnEvent());
}

public void ToggleGhostVisibility(bool? visibility = null)
{
GhostVisibility = visibility ?? !GhostVisibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Content.Client.UserInterface.Systems.Ghost;
public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSystem>
{
[Dependency] private readonly IEntityNetworkManager _net = default!;

[UISystemDependency] private readonly GhostSystem? _system = default;

private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();


public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -125,6 +125,8 @@ public void LoadGui()
Gui.RequestWarpsPressed += RequestWarps;
Gui.ReturnToBodyPressed += ReturnToBody;
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.GhostBarPressed += GhostBarPressed; // Goobstation - Ghost Bar
Gui.GhostBarWindow.SpawnButtonPressed += GhostBarSpawnPressed; // Goobstation - Ghost Bar
Gui.TargetWindow.WarpClicked += OnWarpClicked;
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
Gui.ReturnToRoundPressed += ReturnToRound;
Expand All @@ -140,6 +142,8 @@ public void UnloadGui()
Gui.RequestWarpsPressed -= RequestWarps;
Gui.ReturnToBodyPressed -= ReturnToBody;
Gui.GhostRolesPressed -= GhostRolesPressed;
Gui.GhostBarPressed -= GhostBarPressed; // Goobstation - Ghost Bar
Gui.GhostBarWindow.SpawnButtonPressed -= GhostBarSpawnPressed; // Goobstation - Ghost Bar
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
Gui.ReturnToRoundPressed -= ReturnToRound;

Expand Down Expand Up @@ -167,4 +171,14 @@ private void GhostRolesPressed()
{
_system?.OpenGhostRoles();
}

private void GhostBarPressed() // Goobstation - Ghost Bar
{
Gui?.GhostBarWindow.OpenCentered();
}

private void GhostBarSpawnPressed() // Goobstation - Ghost Bar
{
_system?.GhostBarSpawn();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<widgets:GhostGui xmlns="https://spacestation14.io"
<widgets:GhostGui xmlns="https://spacestation14.io"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Ghost.Widgets"
HorizontalAlignment="Center">
<BoxContainer Orientation="Horizontal">
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
<Button Name="GhostRolesButton" />
<Button Name="GhostBarButton" Text="{Loc 'ghost-target-window-ghostbar'}" /> <!-- Goobstation - Ghost Bar -->
<Button Name="ReturnToRound" Text="{Loc ghost-gui-return-to-round-button}" />
</BoxContainer>
</widgets:GhostGui>
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Content.Client._Goobstation.UserInterface.Systems.Ghost.Controls;

namespace Content.Client.UserInterface.Systems.Ghost.Widgets;

[GenerateTypedNameReferences]
public sealed partial class GhostGui : UIWidget
{
public GhostTargetWindow TargetWindow { get; }
public GhostBarRulesWindow GhostBarWindow { get; }

public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public event Action? GhostBarPressed; // Goobstation - Ghost Bar
public event Action? ReturnToRoundPressed;

public GhostGui()
Expand All @@ -22,17 +25,21 @@ public GhostGui()

TargetWindow = new GhostTargetWindow();

GhostBarWindow = new GhostBarRulesWindow();

MouseFilter = MouseFilterMode.Ignore;

GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
GhostBarButton.OnPressed += _ => GhostBarPressed?.Invoke(); // Goobstation - Ghost Bar
ReturnToRound.OnPressed += _ => ReturnToRoundPressed?.Invoke();
}

public void Hide()
{
TargetWindow.Close();
GhostBarWindow.Close(); // Goobstation - Ghost Bar
Visible = false;
}

Expand Down Expand Up @@ -63,6 +70,7 @@ protected override void Dispose(bool disposing)
if (disposing)
{
TargetWindow.Dispose();
GhostBarWindow.Dispose(); // Goobstation - Ghost Bar
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ghost-target-window-ghostbar'}"
MinSize="500 300"
SetSize="500 300">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<RichTextLabel Name="TopBanner" VerticalExpand="True"/>
<Button Name="SpawnButton"
Text="{Loc 'ghost-window-spawn-ghostbar-button'}"
Disabled="True"
TextAlign="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</BoxContainer>
</DefaultWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client._Goobstation.UserInterface.Systems.Ghost.Controls
{
[GenerateTypedNameReferences]
public sealed partial class GhostBarRulesWindow : DefaultWindow
{
[Dependency] private readonly IConfigurationManager _cfg = IoCManager.Resolve<IConfigurationManager>();
private float _timer;

public event Action? SpawnButtonPressed;
public GhostBarRulesWindow()
{
RobustXamlLoader.Load(this);
var ghostBarTime = _cfg.GetCVar(CCVars.GhostRoleTime);
_timer = ghostBarTime;

if (ghostBarTime > 0f)
{
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button-timer", ("time", $"{_timer:0.0}"));
TopBanner.SetMessage(FormattedMessage.FromMarkupPermissive(Loc.GetString("ghost-bar-rules") + "\n" + Loc.GetString("ghost-roles-window-rules-footer", ("time", ghostBarTime))));
SpawnButton.Disabled = true;
}

SpawnButton.OnPressed += _ => SpawnButtonPressed?.Invoke();
}


protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!SpawnButton.Disabled) return;
if (_timer > 0.0)
{
_timer -= args.DeltaSeconds;
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button-timer", ("time", $"{_timer:0.0}"));
}
else
{
SpawnButton.Disabled = false;
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button");
}
}
}

}
28 changes: 20 additions & 8 deletions Content.Server/Traits/TraitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
using Content.Shared.Customization.Systems;
using Content.Shared.Database;
using Content.Shared.Players;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Traits;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Content.Shared.Whitelist;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
Expand Down Expand Up @@ -44,15 +46,25 @@ public override void Initialize()
}

// When the player is spawned in, add all trait components selected during character creation
private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args) =>
ApplyTraits(args.Mob, args.JobId, args.Profile,
_playTimeTracking.GetTrackerTimes(args.Player), args.Player.ContentData()?.Whitelisted ?? false);

/// <summary>
/// Adds the traits selected by a player to an entity.
/// </summary>
public void ApplyTraits(EntityUid uid, ProtoId<JobPrototype>? jobId, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted, bool punishCheater = true)
{
var pointsTotal = _configuration.GetCVar(CCVars.GameTraitsDefaultPoints);
var traitSelections = _configuration.GetCVar(CCVars.GameTraitsMax);
if (args.JobId is not null && !_prototype.TryIndex<JobPrototype>(args.JobId, out var jobPrototype)
if (jobId is not null && !_prototype.TryIndex(jobId, out var jobPrototype)
&& jobPrototype is not null && !jobPrototype.ApplyTraits)
return;

foreach (var traitId in args.Profile.TraitPreferences)
var jobPrototypeToUse = _prototype.Index(jobId ?? _prototype.EnumeratePrototypes<JobPrototype>().First().ID);

foreach (var traitId in profile.TraitPreferences)
{
if (!_prototype.TryIndex<TraitPrototype>(traitId, out var traitPrototype))
{
Expand All @@ -62,8 +74,8 @@ private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)

if (!_characterRequirements.CheckRequirementsValid(
traitPrototype.Requirements,
_prototype.Index<JobPrototype>(args.JobId ?? _prototype.EnumeratePrototypes<JobPrototype>().First().ID),
args.Profile, _playTimeTracking.GetTrackerTimes(args.Player), args.Player.ContentData()?.Whitelisted ?? false, traitPrototype,
jobPrototypeToUse,
profile, playTimes, whitelisted, traitPrototype,
EntityManager, _prototype, _configuration,
out _))
continue;
Expand All @@ -72,11 +84,11 @@ private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
pointsTotal += traitPrototype.Points;
--traitSelections;

AddTrait(args.Mob, traitPrototype);
AddTrait(uid, traitPrototype);
}

if (pointsTotal < 0 || traitSelections < 0)
PunishCheater(args.Mob);
if (punishCheater && (pointsTotal < 0 || traitSelections < 0))
PunishCheater(uid);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server._Goobstation.Ghostbar.Components;

/// <summary>
/// Tracker for ghostbar players
/// </summary>
[RegisterComponent]
public sealed partial class GhostBarPlayerComponent : Component
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server._Goobstation.Ghostbar.Components;

/// <summary>
/// Target for ghosts to spawn at
/// </summary>
[RegisterComponent]
public sealed partial class GhostBarSpawnComponent : Component
{

}
Loading
Loading