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

Sanity port attempt numero duo #3

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@

<Import Project="..\RobustToolbox\MSBuild\XamlIL.targets" />
<Import Project="..\RobustToolbox\MSBuild\Robust.Analyzers.targets" />
<ItemGroup>
<EmbeddedResource Remove="Sanity\SanityWindow.xaml" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Update="Sanity\UI\SanityWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</AdditionalFiles>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Content.Client/Entry/IgnoredComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static class IgnoredComponents
"PressureSiphon",
"PipeHeater",
"AtmosDevice",
"Sanity",
"SignalReceiver",
"SignalSwitch",
"SignalTransmitter",
Expand Down
13 changes: 13 additions & 0 deletions Content.Client/Sanity/ClientMobSanityComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Content.Shared.Sanity;
using Content.Client.Sanity.UI;

namespace Content.Client.Sanity
{
public class ClientMobSanityComponent : SharedMobSanityComponent
{
}
}
34 changes: 34 additions & 0 deletions Content.Client/Sanity/ClientSanitySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Content.Shared.Sanity;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using System;
using System.Collections.Generic;
using Content.Client.Sanity.UI;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Client.Player;
using Robust.Shared.IoC;

namespace Content.Client.Sanity
{
public sealed class ClientSanitySystem : SharedSanitySystem
{
[Dependency] IPlayerManager _playerManager = default!;

public override void Initialize()
{
base.Initialize();
}


public void NotifyUI()
{
EntityUid? playerUID = _playerManager?.LocalPlayer?.ControlledEntity?.Uid;
if (playerUID is not null)
{
RaiseNetworkEvent(new SanityCloseUI((EntityUid)playerUID));
}
}

}
}
59 changes: 59 additions & 0 deletions Content.Client/Sanity/UI/SanityInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Content.Client.Sanity;
using Content.Shared.Sanity;
using System;

namespace Content.Client.Sanity.UI
{
/// <summary>
/// </summary>
///
public class SanityBoundUserInterface : BoundUserInterface
{
private SanityWindow? _window;

public SanityBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_window = new SanityWindow();
if (State != null)
UpdateState(State);

_window.OpenCentered();

_window.OnClose += Close;
_window.OnClose += NotifySystem;

}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not SanityBoundUserInterfaceState cast)
return;

_window.UpdateData(cast.Sanity);
}

protected void NotifySystem()
{
EntitySystem.Get<ClientSanitySystem>().NotifyUI();
}



protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
}

}
8 changes: 8 additions & 0 deletions Content.Client/Sanity/UI/SanityWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Sanity">
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
<Label Name="Insight" Text="{Loc 'sanity-current-amount'}" />
<LineEdit Name="SanityLineEdit" />
</BoxContainer>
</SS14Window>
27 changes: 27 additions & 0 deletions Content.Client/Sanity/UI/SanityWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.GameObjects;
using Robust.Client.GameStates;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Client.Utility;



namespace Content.Client.Sanity.UI
{
[GenerateTypedNameReferences]
public partial class SanityWindow : SS14Window
{
public SanityWindow()
{
RobustXamlLoader.Load(this);
}

public void UpdateData(int sanity)
{
SanityLineEdit.Text = sanity.ToString();
}
}
}
25 changes: 25 additions & 0 deletions Content.Server/Alert/Click/SanityMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Shared.Alert;
using JetBrains.Annotations;
using Robust.Shared.Serialization.Manager.Attributes;
using Content.Server.Sanity;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
using Robust.Server.Player;
using Robust.Server.GameObjects;

namespace Content.Server.Alert.Click
{
[UsedImplicitly]
[DataDefinition]
public class SanityMenu : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
{

if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent) && args.Player.TryGetComponent(out ActorComponent? actorComponent))
{
EntitySystem.Get<SanitySystem>().OpenUI(sanityComponent, actorComponent.PlayerSession);
}
}
}
}
Empty file.
152 changes: 152 additions & 0 deletions Content.Server/Sanity/MobSanityComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using Content.Server.Alert;
using Content.Shared.Alert;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Robust.Shared.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
using Content.Shared.Sanity;
using Robust.Shared.Players;

namespace Content.Server.Sanity
{
[RegisterComponent]
public class MobSanityComponent : SharedMobSanityComponent
{

/// <summary>
/// Sanity variables
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool Updating = false;

public int Sanity
{
get => _sanity;
set
{
if(_sanity + value > MaxSanity)
{
_sanity = MaxSanity;
return;
}
if(_sanity + value < 1)
{
_sanity = 0;
return;
}
_sanity = value;
}
}

private int _sanity = 0;
/// <summary>
/// How much sanity points are given per second, this rounds itself , but losses are aceptable.
/// </summary>

[ViewVariables(VVAccess.ReadWrite)]
public float SanityGainPerSecond = 0.1f;
/// <summary>
/// Maximum sanity to lose per cycle. Can be influenced
/// </summary>

[ViewVariables(VVAccess.ReadWrite)]
public int MaxSanityDecayPerCycle = 20;
/// <summary>
/// This divides max sanity to show the sanity hud element sprite, automatically updated when max sanity changes , do not touch.
/// </summary>

[ViewVariables(VVAccess.ReadOnly)]
public int SanitySteps = 20;

/// <summary>
/// This is the maximum sanity , the more a player has the bigger the buffer between the stages becomes
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int MaxSanity
{
get => _maxSanity;
set
{
_maxSanity = value;
// 6 Sprites so far.
SanitySteps = _maxSanity / 6;
}
}

private int _maxSanity = 100;

///
/// Insight variables
///
[ViewVariables(VVAccess.ReadWrite)]
public int Insight
{
get => _insight;
set
{
if(_insight + value > RequiredInsight)
{
InsightPoints += (_insight + value) / RequiredInsight;
_insight = (_insight + value) % RequiredInsight;
return;
}
_insight = value;
}

}


private int _insight = 0;

[ViewVariables(VVAccess.ReadWrite)]
public int RequiredInsight = 100;

[ViewVariables(VVAccess.ReadWrite)]
public int InsightPoints = 0;

[ViewVariables(VVAccess.ReadWrite)]
public float PassiveInsightGainPerSecond = 0.75f;

///
/// Rest variables
///
[ViewVariables(VVAccess.ReadWrite)]
public int Rest
{
get => _rest;
set
{
if(_rest + value > RestRequired)
{
RestPoints += (_rest + value) / RestRequired;
_rest = (_rest + value) % RestRequired;
return;
}
_rest = value;
}
}


private int _rest = 0;

[ViewVariables(VVAccess.ReadWrite)]
public int RestPoints = 0;

[ViewVariables(VVAccess.ReadWrite)]
public int RestRequired = 100;

[ViewVariables(VVAccess.ReadWrite)]
public float RestGainPerSecond = 0.75f;


}
}
Loading