Files
wwdpublic/Content.Client/PDA/PdaBoundUserInterface.cs
RadsammyT 2067191104 Cherry-Pick Storage V2 Fixes From wizden#34845 (#1868)
# Description

~~finally figured out how to cherry-pick across repos jfc~~
Cherry-picks
https://github.com/space-wizards/space-station-14/pull/34845.
Essentially fixes most of the issues with Storage V2 when it initially
got merged into EE, finally.

Or, TL;DR, fixes:
 - storage stars always being golden
- windows always resetting to its default position on reopening- now
saves its position instead
 - hotkeys not being ergonomic enough (which was really disrupting)
 - and some other things regarding 1-tick delays between containers
 -  and the back button being illegaly visible

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- **PDA Menu Improvement:** Streamlined the PDA menu display for more
consistent and intuitive access.
- **Enhanced Storage UI:** Storage windows now open at dynamic positions
for smoother transitions and easier navigation.
- **Nested Storage Management:** Improved handling of nested storage
interfaces reduces clutter and simplifies user interactions.
- **Improved Item Interaction:** Updated item selection displays and
automatic parent window adjustments for a more cohesive experience.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
(cherry picked from commit 3021de3ee6fd88d82b3f090ea4d17398a0c01f64)
2025-03-08 14:31:33 +03:00

124 lines
3.8 KiB
C#

using Content.Client.CartridgeLoader;
using Content.Shared.CartridgeLoader;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.PDA;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
namespace Content.Client.PDA
{
[UsedImplicitly]
public sealed class PdaBoundUserInterface : CartridgeLoaderBoundUserInterface
{
[ViewVariables]
private PdaMenu? _menu;
public PdaBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
if (_menu == null)
CreateMenu();
}
private void CreateMenu()
{
_menu = this.CreateWindowCenteredLeft<PdaMenu>();
_menu.FlashLightToggleButton.OnToggled += _ =>
{
SendMessage(new PdaToggleFlashlightMessage());
};
_menu.EjectIdButton.OnPressed += _ =>
{
SendPredictedMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaIdSlotId));
};
_menu.EjectPenButton.OnPressed += _ =>
{
SendPredictedMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaPenSlotId));
};
_menu.EjectPaiButton.OnPressed += _ =>
{
SendPredictedMessage(new ItemSlotButtonPressedEvent(PdaComponent.PdaPaiSlotId));
};
_menu.ActivateMusicButton.OnPressed += _ =>
{
SendMessage(new PdaShowMusicMessage());
};
_menu.AccessRingtoneButton.OnPressed += _ =>
{
SendMessage(new PdaShowRingtoneMessage());
};
_menu.ShowUplinkButton.OnPressed += _ =>
{
SendMessage(new PdaShowUplinkMessage());
};
_menu.LockUplinkButton.OnPressed += _ =>
{
SendMessage(new PdaLockUplinkMessage());
};
_menu.OnProgramItemPressed += ActivateCartridge;
_menu.OnInstallButtonPressed += InstallCartridge;
_menu.OnUninstallButtonPressed += UninstallCartridge;
_menu.ProgramCloseButton.OnPressed += _ => DeactivateActiveCartridge();
var borderColorComponent = GetBorderColorComponent();
if (borderColorComponent == null)
return;
_menu.BorderColor = borderColorComponent.BorderColor;
_menu.AccentHColor = borderColorComponent.AccentHColor;
_menu.AccentVColor = borderColorComponent.AccentVColor;
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not PdaUpdateState updateState)
return;
_menu?.UpdateState(updateState);
}
protected override void AttachCartridgeUI(Control cartridgeUIFragment, string? title)
{
_menu?.ProgramView.AddChild(cartridgeUIFragment);
_menu?.ToProgramView(title ?? Loc.GetString("comp-pda-io-program-fallback-title"));
}
protected override void DetachCartridgeUI(Control cartridgeUIFragment)
{
if (_menu is null)
return;
_menu.ToHomeScreen();
_menu.HideProgramHeader();
_menu.ProgramView.RemoveChild(cartridgeUIFragment);
}
protected override void UpdateAvailablePrograms(List<(EntityUid, CartridgeComponent)> programs)
{
_menu?.UpdateAvailablePrograms(programs);
}
private PdaBorderColorComponent? GetBorderColorComponent()
{
return EntMan.GetComponentOrNull<PdaBorderColorComponent>(Owner);
}
}
}