Parcourir la source

Adds looking in the distance (#238)

* alt tab black screen bugfix

* First working version

Detects a key for lookzoom now

* Moves LookZoom to client instead

I moved it to shared before because stoopid

* Some next form of this stupid code

I hate it

* More code for the system

still not really functional

* more commit

* Kinda works now but still bad

* REAL WORKING VERSION

still scuffed but i want to commit it anyways

* Mostly fixes the offset not getting reset when toggled on and off

i should add a check when switching hands or dropping the item though

* Gives these components to humans and some related cleanup

* More yml tweaks

* Changes the delay to press the button

* Key change

* Small namespace correction

* Adds some comments to the code
dallaszzz il y a 5 mois
Parent
commit
02fb77f0a5

+ 9 - 0
Content.Client/Civ14/LookZoom/LookZoomComponent.cs

@@ -0,0 +1,9 @@
+namespace Content.Client.Civ14.LookZoom;
+
+[RegisterComponent]
+public sealed partial class LookZoomComponent : Component
+{
+    public bool State = false;
+
+    public TimeSpan DelayedTime;
+}

+ 97 - 0
Content.Client/Civ14/LookZoom/LookZoomSystem.cs

@@ -0,0 +1,97 @@
+#nullable enable
+using Content.Shared.Camera;
+using Content.Shared.Input;
+using Robust.Shared.Input.Binding;
+using Content.Client.Movement.Components;
+using Content.Client.Movement.Systems;
+using Robust.Shared.Player;
+using Content.Shared.Hands.EntitySystems;
+using Robust.Shared.Timing;
+using Robust.Client.Player;
+using Robust.Shared.GameObjects;
+using System.Numerics;
+using Robust.Client.Timing;
+
+
+namespace Content.Client.Civ14.LookZoom;
+public sealed class LookZoomSystem : EntitySystem
+{
+    [Dependency] private readonly EyeCursorOffsetSystem _eyeOffset = default!;
+    [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly IPlayerManager _player = default!;
+    [Dependency] private readonly IClientGameTiming _gameTiming = default!;
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<LookZoomComponent, GetEyeOffsetRelayedEvent>(UpdateLookZoom);
+
+        CommandBinds.Builder
+        .Bind(ContentKeyFunctions.LookZoom, InputCmdHandler.FromDelegate(OnLookZoomHandler, handle: false, outsidePrediction: false))
+        .Register<LookZoomSystem>();
+    }
+
+    public void OnLookZoomHandler(ICommonSession? session)
+    {
+        // Gets the player character uid
+        var uid = session?.AttachedEntity;
+
+        if (!TryComp<LookZoomComponent>(uid, out var comp))
+            return;
+
+        // Checks if the cooldown is over by comparing to the current time
+        if (_timing.CurTime < comp.DelayedTime)
+            return;
+
+        // Sets the cooldown to the current time + 0.1 seconds
+        comp.DelayedTime = _timing.CurTime + TimeSpan.FromSeconds(0.1);
+
+        if (comp.State == false)
+        {
+            _handsSystem.TryGetActiveItem(uid.Value, out var item);
+            ResetOffset(uid);
+            ResetOffset(item);
+            comp.State = true;
+            return;
+        }
+        comp.State = false;
+    }
+    public void UpdateLookZoom(EntityUid uid, LookZoomComponent comp, ref GetEyeOffsetRelayedEvent args)
+    {
+        if (comp.State == false)
+        {
+            return;
+        }
+
+        _handsSystem.TryGetActiveItem(comp.Owner, out var item);
+
+        // Sets the offset if there is an item in the active hand with the EyeCurserOffset component
+        if (item != null && TryComp<EyeCursorOffsetComponent>(item, out var itemComp))
+        {
+            SetOffset(item.Value, args);
+            return;
+        }
+
+        //Sets the offset using the EyeCurserOffset on the player entity instead
+        SetOffset(comp.Owner, args);
+    }
+
+    private void SetOffset(EntityUid uid, GetEyeOffsetRelayedEvent args)
+    {
+        var offset = _eyeOffset.OffsetAfterMouse(uid, null);
+        if (offset == null)
+            return;
+
+        args.Offset += offset.Value;
+    }
+
+    private void ResetOffset(EntityUid? uid)
+    {
+        if (TryComp(uid, out EyeCursorOffsetComponent? cursorOffsetComp))
+        {
+            if (_gameTiming.IsFirstTimePredicted)
+                cursorOffsetComp.CurrentPosition = Vector2.Zero;
+        }
+    }
+}

+ 3 - 0
Content.Client/Content.Client.csproj

@@ -23,6 +23,9 @@
     <ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
     <ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Civ14\" />
+  </ItemGroup>
   <Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
   <Import Project="..\RobustToolbox\MSBuild\XamlIL.targets" />
 </Project>

+ 3 - 0
Content.Client/Input/ContentContexts.cs

@@ -99,6 +99,9 @@ public static void SetupContexts(IInputContextContainer contexts)
             human.AddFunction(ContentKeyFunctions.Lay); // Stalker-Changes-UI
             // actions should be common (for ghosts, mobs, etc)
             common.AddFunction(ContentKeyFunctions.OpenActionsMenu);
+            // Civ14 change start
+            human.AddFunction(ContentKeyFunctions.LookZoom);
+            // Civ14 change end
 
             foreach (var boundKey in ContentKeyFunctions.GetHotbarBoundKeys())
             {

+ 4 - 0
Content.Client/Movement/Systems/EyeCursorOffsetSystem.cs

@@ -83,6 +83,10 @@ private void OnGetEyeOffsetEvent(EntityUid uid, EyeCursorOffsetComponent compone
                 {
                     vectorOffset = vectorOffset.Normalized() * component.OffsetSpeed;
                 }
+                // Check to make sure vectorOffset is not NaN
+                if (float.IsNaN(vectorOffset.X) || float.IsNaN(vectorOffset.Y))
+                    return null;
+
                 component.CurrentPosition += vectorOffset;
             }
         }

+ 3 - 0
Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs

@@ -154,6 +154,9 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
             AddHeader("ui-options-header-general");
             AddCheckBox("ui-options-hotkey-keymap", _cfg.GetCVar(CVars.DisplayUSQWERTYHotkeys), HandleToggleUSQWERTYCheckbox);
 
+            AddHeader("ui-options-header-civ"); // Section for civ14 controls
+            AddButton(ContentKeyFunctions.LookZoom);
+
             AddHeader("ui-options-header-movement");
             AddButton(EngineKeyFunctions.MoveUp);
             AddButton(EngineKeyFunctions.MoveLeft);

+ 6 - 0
Content.Server/Civ14/LookZoom/LookZoomComponent.cs

@@ -0,0 +1,6 @@
+namespace Content.Server.Civ14.LookZoom;
+
+[RegisterComponent]
+public sealed partial class LookZoomComponent : Component
+{
+}

+ 3 - 1
Content.Shared/Input/ContentKeyFunctions.cs

@@ -101,7 +101,9 @@ public static class ContentKeyFunctions
         public static readonly BoundKeyFunction Hotbar7 = "Hotbar7";
         public static readonly BoundKeyFunction Hotbar8 = "Hotbar8";
         public static readonly BoundKeyFunction Hotbar9 = "Hotbar9";
-
+        // Civ14 Change Start
+        public static readonly BoundKeyFunction LookZoom = "LookZoom";
+        // Civ14 Change End
         public static BoundKeyFunction[] GetHotbarBoundKeys() =>
             new[]
             {

+ 1 - 1
Content.Shared/Movement/Systems/SharedContentEyeSystem.cs

@@ -143,7 +143,7 @@ public void SetMaxZoom(EntityUid uid, Vector2 value, ContentEyeComponent? compon
     public void UpdateEyeOffset(Entity<EyeComponent> eye)
     {
         var ev = new GetEyeOffsetEvent();
-        RaiseLocalEvent(eye, ref ev);
+        //RaiseLocalEvent(eye, ref ev);
 
         var evRelayed = new GetEyeOffsetRelayedEvent();
         RaiseLocalEvent(eye, ref evRelayed);

+ 3 - 0
Resources/Prototypes/Civ14/Entities/Objects/Guns/base.yml

@@ -24,3 +24,6 @@
         - state: mag-0
           map: ["enum.GunVisualLayers.Mag"]
     - type: Appearance
+    - type: EyeCursorOffset
+      maxOffset: 6
+      pvsIncrease: 0.6

+ 4 - 0
Resources/Prototypes/Entities/Mobs/Species/human.yml

@@ -32,6 +32,10 @@
     - type: ShowAntagIcons
     - type: ShowSyndicateIcons
     - type: SleepZone
+    - type: LookZoom #civ14
+    - type: EyeCursorOffset #civ14
+      maxOffset: 4
+      pvsIncrease: 0.4
     - type: Inventory
       femaleDisplacements:
         jumpsuit:

+ 7 - 2
Resources/keybinds.yml

@@ -1,4 +1,4 @@
-version: 1 # Not used right now, whatever.
+version: 1 # Not used right now, whatever.
 binds:
   - function: UIClick
     type: State
@@ -182,7 +182,8 @@ binds:
     key: Z
   - function: AltActivateItemInHand
     type: State
-    key: Space
+    key: E
+    mod1: Control
   - function: OpenCharacterMenu
     type: State
     key: C
@@ -590,3 +591,7 @@ binds:
     type: State
     key: MouseRight
     canFocus: true
+  - function: LookZoom
+    type: State
+    key: Space
+    canFocus: true