-
Notifications
You must be signed in to change notification settings - Fork 194
port vehicle system #1477
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
Merged
Merged
port vehicle system #1477
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ea167af
port vehicle system
Rxup bd06b20
fix
Rxup 4871770
fix
Rxup d110c88
Merge branch 'master' into feature/vehicle-system
Rxup 7b4ab69
Update migration.yml
Rxup fb2fc21
fix
Rxup 8a45e33
fix
Rxup 7a93ae8
fix
Rxup 38c0c6d
fix
Rxup 4e69887
fix
Rxup 678e77d
fix
Rxup c4bf66c
fix
Rxup 2e5eb47
fix
Rxup ec93840
Update SharedGunSystem.cs
Rxup 94753b3
fix
Rxup 1d1215e
fix
Rxup 84fa3a2
Update BkmVovaMechSystem.cs
Rxup c94a326
Update BkmVovaMechHandsUIController.cs
Rxup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
262 changes: 262 additions & 0 deletions
262
Content.Client/Backmen/VovaMech/BkmVovaMechHandsUIController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| using Content.Client.Gameplay; | ||
| using Content.Client.Hands.Systems; | ||
| using Content.Client.UserInterface.Controls; | ||
| using Content.Client.UserInterface.Systems.Hands.Controls; | ||
| using Content.Client.UserInterface.Systems.Hotbar.Widgets; | ||
| using Content.Client.Verbs.UI; | ||
| using Content.Shared.Hands; | ||
| using Content.Shared.Hands.Components; | ||
| using Content.Shared.Input; | ||
| using Content.Shared.Inventory.VirtualItem; | ||
| using Content.Shared.Timing; | ||
| using Robust.Client.UserInterface; | ||
| using Robust.Client.UserInterface.Controllers; | ||
| using Robust.Shared.Input; | ||
| using Robust.Shared.Timing; | ||
|
|
||
| namespace Content.Client.Backmen.VovaMech; | ||
|
|
||
| /// <summary> | ||
| /// Separate hand bar for OneStar mech innate tools, shown above the player hotbar while piloting. | ||
| /// </summary> | ||
| public sealed partial class BkmVovaMechHandsUIController : UIController, IOnStateEntered<GameplayState>, IOnSystemChanged<BkmVovaMechSystem>, IOnSystemChanged<HandsSystem> | ||
| { | ||
| [Dependency] private IEntityManager _entities = default!; | ||
|
|
||
| [UISystemDependency] private readonly BkmVovaMechSystem _mechSystem = default!; | ||
| [UISystemDependency] private readonly HandsSystem _handsSystem = default!; | ||
| [UISystemDependency] private readonly UseDelaySystem _useDelay = default!; | ||
|
|
||
| private EntityUid? _mechUid; | ||
| private HandsComponent? _mechHands; | ||
| private HandButton? _activeHand; | ||
|
|
||
| private HotbarGui? Hotbar => UIManager.GetActiveUIWidgetOrNull<HotbarGui>(); | ||
|
|
||
| public void OnSystemLoaded(BkmVovaMechSystem system) | ||
| { | ||
| system.LocalPilotedMechChanged += OnLocalPilotedMechChanged; | ||
| } | ||
|
|
||
| public void OnSystemUnloaded(BkmVovaMechSystem system) | ||
| { | ||
| system.LocalPilotedMechChanged -= OnLocalPilotedMechChanged; | ||
| } | ||
|
|
||
| public void OnSystemLoaded(HandsSystem system) | ||
| { | ||
| system.OnPlayerAddHand += OnMechHandAdded; | ||
| system.OnPlayerRemoveHand += OnMechHandRemoved; | ||
| } | ||
|
|
||
| public void OnSystemUnloaded(HandsSystem system) | ||
| { | ||
| system.OnPlayerAddHand -= OnMechHandAdded; | ||
| system.OnPlayerRemoveHand -= OnMechHandRemoved; | ||
| } | ||
|
|
||
| public void OnStateEntered(GameplayState state) | ||
| { | ||
| if (_mechUid is { } mech && _mechHands is { } hands) | ||
| LoadMechHands(mech, hands); | ||
| } | ||
|
|
||
| public override void FrameUpdate(FrameEventArgs args) | ||
| { | ||
| base.FrameUpdate(args); | ||
|
|
||
| if (_mechUid is not { } mech || _mechHands == null || Hotbar?.MechHandContainer is not { } container) | ||
| return; | ||
|
|
||
| SetActiveHand(_mechHands.ActiveHandId); | ||
|
|
||
| foreach (var hand in container.GetButtons()) | ||
| RefreshHandButton(mech, hand.SlotName, hand); | ||
|
|
||
| foreach (var hand in container.GetButtons()) | ||
| { | ||
| if (!_entities.TryGetComponent(hand.Entity, out UseDelayComponent? useDelay)) | ||
| { | ||
| hand.CooldownDisplay.Visible = false; | ||
| continue; | ||
| } | ||
|
|
||
| var delay = _useDelay.GetLastEndingDelay((hand.Entity.Value, useDelay)); | ||
| hand.CooldownDisplay.Visible = true; | ||
| hand.CooldownDisplay.FromTime(delay.StartTime, delay.EndTime); | ||
| } | ||
| } | ||
|
|
||
| private void OnLocalPilotedMechChanged(EntityUid? mech) | ||
| { | ||
| if (mech == null) | ||
| { | ||
| UnloadMechHands(); | ||
| return; | ||
| } | ||
|
|
||
| if (!_entities.TryGetComponent(mech, out HandsComponent? hands)) | ||
| { | ||
| _mechUid = mech; | ||
| _mechHands = null; | ||
| return; | ||
| } | ||
|
|
||
| LoadMechHands(mech.Value, hands); | ||
| } | ||
|
|
||
| private void OnMechHandAdded(Entity<HandsComponent> entity, string name, HandLocation location) | ||
| { | ||
| if (entity.Owner != _mechUid || _mechHands == null) | ||
| return; | ||
|
|
||
| if (!_handsSystem.TryGetHand((entity.Owner, entity.Comp), name, out var hand)) | ||
| return; | ||
|
|
||
| AddHandButton(name, hand.Value); | ||
| SetActiveHand(_mechHands.ActiveHandId); | ||
| } | ||
|
|
||
| private void OnMechHandRemoved(Entity<HandsComponent> entity, string name) | ||
| { | ||
| if (entity.Owner != _mechUid || Hotbar?.MechHandContainer is not { } container) | ||
| return; | ||
|
|
||
| container.TryRemoveButton(name, out _); | ||
| SetActiveHand(_mechHands?.ActiveHandId); | ||
| } | ||
|
|
||
| private void LoadMechHands(EntityUid mech, HandsComponent hands) | ||
| { | ||
| UnloadMechHands(); | ||
|
|
||
| _mechUid = mech; | ||
| _mechHands = hands; | ||
|
|
||
| if (Hotbar == null) | ||
| return; | ||
|
|
||
| Hotbar.MechHandsRow.Visible = true; | ||
| Hotbar.MechHandContainer.PlayerHandsComponent = hands; | ||
| Hotbar.MechHandContainer.ClearButtons(); | ||
|
|
||
| foreach (var handId in hands.SortedHands) | ||
| { | ||
| if (!_handsSystem.TryGetHand((mech, hands), handId, out var hand)) | ||
| continue; | ||
|
|
||
| AddHandButton(handId, hand.Value); | ||
| } | ||
|
|
||
| SetActiveHand(hands.ActiveHandId); | ||
|
|
||
| if (hands.ActiveHandId == null && hands.SortedHands.Count > 0) | ||
| _mechSystem.RequestSetMechHand(hands.SortedHands[0]); | ||
| } | ||
|
|
||
| private void UnloadMechHands() | ||
| { | ||
| _mechUid = null; | ||
| _mechHands = null; | ||
| _activeHand = null; | ||
|
|
||
| if (Hotbar == null) | ||
| return; | ||
|
|
||
| Hotbar.MechHandsRow.Visible = false; | ||
| Hotbar.MechHandContainer.ClearButtons(); | ||
| Hotbar.MechHandContainer.PlayerHandsComponent = null; | ||
| } | ||
|
|
||
| private void AddHandButton(string handId, Hand hand) | ||
| { | ||
| if (Hotbar?.MechHandContainer is not { } || _mechUid is not { } mech) | ||
| return; | ||
|
|
||
| var button = new HandButton(handId, hand.Location); | ||
| button.Pressed += HandPressed; | ||
|
|
||
| Hotbar.MechHandContainer.TryAddButton(button); | ||
| RefreshHandButton(mech, handId, button); | ||
| } | ||
|
|
||
| private void RefreshHandButton(EntityUid mech, string handId, HandButton button) | ||
| { | ||
| if (_mechHands == null) | ||
| return; | ||
|
|
||
| if (_handsSystem.TryGetHeldItem((mech, _mechHands), handId, out var held) && | ||
| _entities.TryGetComponent(held, out VirtualItemComponent? virt)) | ||
| { | ||
| button.SetEntity(virt.BlockingEntity); | ||
| button.Blocked = true; | ||
| return; | ||
| } | ||
|
|
||
| button.SetEntity(held); | ||
| button.Blocked = false; | ||
| } | ||
|
|
||
| private void HandPressed(GUIBoundKeyEventArgs args, SlotControl hand) | ||
| { | ||
| if (_mechUid is not { } mech || _mechHands == null) | ||
| return; | ||
|
|
||
| var handsEnt = (mech, _mechHands); | ||
|
|
||
| if (args.Function == EngineKeyFunctions.UIClick) | ||
| { | ||
| MechHandClick(handsEnt, hand.SlotName); | ||
| SetActiveHand(_mechHands.ActiveHandId); | ||
| args.Handle(); | ||
| } | ||
| else if (args.Function == EngineKeyFunctions.UseSecondary) | ||
| { | ||
| if (_handsSystem.TryGetHeldItem(handsEnt, hand.SlotName, out var held)) | ||
| UIManager.GetUIController<VerbMenuUIController>().OpenVerbMenu(held.Value); | ||
|
|
||
| args.Handle(); | ||
| } | ||
| else if (args.Function == ContentKeyFunctions.ActivateItemInWorld) | ||
| { | ||
| _handsSystem.TryActivateItemInHand(mech, _mechHands, hand.SlotName); | ||
| args.Handle(); | ||
| } | ||
| else if (args.Function == ContentKeyFunctions.AltActivateItemInWorld) | ||
| { | ||
| _handsSystem.TryUseItemInHand(mech, altInteract: true, _mechHands, hand.SlotName); | ||
| args.Handle(); | ||
| } | ||
| } | ||
|
|
||
| private void MechHandClick(Entity<HandsComponent> ent, string handName) | ||
| { | ||
| var hands = ent.Comp; | ||
|
|
||
| if (handName != hands.ActiveHandId) | ||
| { | ||
| _mechSystem.RequestSetMechHand(handName); | ||
| return; | ||
| } | ||
|
|
||
| if (_handsSystem.GetActiveItem(ent.AsNullable()) != null) | ||
| _handsSystem.TryUseItemInHand(ent.Owner); | ||
| } | ||
|
|
||
| private void SetActiveHand(string? handName) | ||
| { | ||
| if (handName == null) | ||
| { | ||
| _activeHand?.Highlight = false; | ||
| _activeHand = null; | ||
| return; | ||
| } | ||
|
|
||
| if (Hotbar?.MechHandContainer.TryGetButton(handName, out var handControl) != true || handControl == _activeHand) | ||
| return; | ||
|
|
||
| _activeHand?.Highlight = false; | ||
| handControl!.Highlight = true; | ||
| _activeHand = handControl; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Rxup/space-station-14
Length of output: 2542
🏁 Script executed:
Repository: Rxup/space-station-14
Length of output: 50378
🏁 Script executed:
Repository: Rxup/space-station-14
Length of output: 11926
_mechHandsне подхватывается при поздней инициализации рук мехаЕсли
HandsComponentпоявляется послеLocalPilotedMechChanged,_mechHandsостаётсяnullдо пересадки:OnMechHandAddedсразу выходит по этому флагу, а других путей повторно вызватьLoadMechHandsнет. Добавь восстановление вOnMechHandAdded(или отдельный хук на стартHandsComponent), иначе UI рук меха может так и не появиться в текущей сессии пилотирования.🤖 Prompt for AI Agents