-
Notifications
You must be signed in to change notification settings - Fork 0
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
jannie qol #6
Merged
Merged
jannie qol #6
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
51 changes: 51 additions & 0 deletions
51
Content.Client/_White/ItemSlotPicker/ItemSlotPickerSystem.cs
This file contains 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,51 @@ | ||
using Content.Shared._White.ItemSlotPicker; | ||
using Content.Shared.Interaction; | ||
using Content.Shared._White.ItemSlotPicker.UI; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Player; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Containers; | ||
using Robust.Shared.Timing; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Client._White.ItemSlotPicker; | ||
|
||
public sealed class ItemSlotPickerSystem : SharedItemSlotPickerSystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<ItemSlotPickerComponent, EntInsertedIntoContainerMessage>(EntInserted); | ||
SubscribeLocalEvent<ItemSlotPickerComponent, EntRemovedFromContainerMessage>(EntRemoved); | ||
} | ||
|
||
private void EntInserted(EntityUid uid, ItemSlotPickerComponent comp, EntInsertedIntoContainerMessage args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted || | ||
_player.LocalEntity is not EntityUid player || | ||
!_ui.IsUiOpen(uid, ItemSlotPickerKey.Key, player)) | ||
return; | ||
var msg = new ItemSlotPickerContentsChangedMessage(); | ||
msg.Actor = player; | ||
_ui.RaiseUiMessage(uid, ItemSlotPickerKey.Key, msg); | ||
} | ||
|
||
private void EntRemoved(EntityUid uid, ItemSlotPickerComponent comp, EntRemovedFromContainerMessage args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted || | ||
_player.LocalEntity is not EntityUid player || | ||
!_ui.IsUiOpen(uid, ItemSlotPickerKey.Key, player)) | ||
return; | ||
var msg = new ItemSlotPickerContentsChangedMessage(); | ||
msg.Actor = player; | ||
_ui.RaiseUiMessage(uid, ItemSlotPickerKey.Key, msg); | ||
} | ||
|
||
} |
141 changes: 141 additions & 0 deletions
141
Content.Client/_White/ItemSlotPicker/UI/ItemSlotPickerBoundUserInterface.cs
This file contains 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,141 @@ | ||
using Content.Client.Chat.UI; | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.Containers.ItemSlots; | ||
using JetBrains.Annotations; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Shared.Timing; | ||
using static Robust.Client.UserInterface.Control; | ||
using System.Numerics; | ||
using Content.Shared._White.ItemSlotPicker; | ||
using Content.Shared._White.ItemSlotPicker.UI; | ||
|
||
namespace Content.Client._White.ItemSlotPicker.UI; | ||
|
||
// a UFO came by and left this message here | ||
[UsedImplicitly] | ||
public sealed class ItemSlotPickerBoundUserInterface : BoundUserInterface | ||
{ | ||
[Dependency] private readonly IClyde _clyde = default!; | ||
[Dependency] private readonly IEyeManager _eye = default!; | ||
|
||
private readonly ItemSlotsSystem _itemSlots; | ||
private readonly SharedTransformSystem _transform; | ||
|
||
private RadialMenu? _menu; | ||
private RadialContainer? _layer; | ||
|
||
public ItemSlotPickerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_itemSlots = EntMan.System<ItemSlotsSystem>(); | ||
_transform = EntMan.System<SharedTransformSystem>(); | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
_menu = new EntityCenteredRadialMenu(Owner); | ||
_menu.OnClose += Close; | ||
_menu.CloseButtonStyleClass = "RadialMenuCloseButton"; | ||
_menu.BackButtonStyleClass = "RadialMenuBackButton"; | ||
|
||
UpdateLayer(); | ||
_menu.OpenCenteredAt(_eye.WorldToScreen(_transform.GetWorldPosition(Owner)) / _clyde.ScreenSize); | ||
} | ||
|
||
private void UpdateLayer() | ||
{ | ||
var picker = EntMan.GetComponent<ItemSlotPickerComponent>(Owner); | ||
if (_layer is not null) | ||
_menu!.RemoveChild(_layer); | ||
|
||
_layer = new RadialContainer(); | ||
foreach (var slotID in picker.ItemSlots) | ||
{ | ||
if (!_itemSlots.TryGetSlot(Owner, slotID, out var slot) || | ||
!slot.HasItem) | ||
continue; | ||
|
||
// i see no value in having 99 different radial button types with the only difference being what data they hold | ||
// hence i'm just setting all relevant parameters after constructing the button. | ||
var button = new RadialMenuTextureButton | ||
{ | ||
StyleClasses = { "RadialMenuButton" }, | ||
SetSize = new Vector2(64f, 64f), | ||
ToolTip = Loc.GetString(slot.Name), | ||
}; | ||
|
||
var tex = new TextureRect | ||
{ | ||
VerticalAlignment = VAlignment.Center, | ||
HorizontalAlignment = HAlignment.Center, | ||
Texture = EntMan.GetComponent<SpriteComponent>(slot.Item!.Value).Icon?.Default, | ||
TextureScale = new Vector2(2f, 2f), | ||
}; | ||
|
||
button.AddChild(tex); | ||
button.OnButtonUp += _ => { SendPredictedMessage(new ItemSlotPickerSlotPickedMessage(slotID)); }; | ||
_layer.AddChild(button); | ||
} | ||
_menu!.AddChild(_layer); | ||
} | ||
|
||
protected override void ReceiveMessage(BoundUserInterfaceMessage message) | ||
{ | ||
if (message is not ItemSlotPickerContentsChangedMessage) | ||
return; | ||
UpdateLayer(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) return; | ||
|
||
_menu?.Dispose(); | ||
} | ||
} | ||
|
||
[Virtual] | ||
public class EntityCenteredRadialMenu : RadialMenu | ||
{ | ||
public EntityUid Entity; | ||
[Dependency] private readonly IClyde _clyde = default!; | ||
[Dependency] private readonly IEyeManager _eye = default!; | ||
[Dependency] private readonly IEntityManager _entMan = default!; | ||
private readonly SharedTransformSystem _transform; | ||
|
||
private Vector2 _cachedPos; | ||
|
||
public EntityCenteredRadialMenu(EntityUid entity) : base() | ||
{ | ||
Entity = entity; | ||
IoCManager.InjectDependencies(this); | ||
_transform = _entMan.System<SharedTransformSystem>(); | ||
} | ||
|
||
public EntityCenteredRadialMenu(EntityUid entity, IEntityManager man, IEyeManager eye, IClyde clyde) : base() | ||
{ | ||
Entity = entity; | ||
_clyde = clyde; | ||
_entMan = man; | ||
_eye = eye; | ||
_transform = _entMan.System<SharedTransformSystem>(); | ||
} | ||
|
||
|
||
protected override void FrameUpdate(FrameEventArgs args) | ||
{ | ||
base.FrameUpdate(args); | ||
if (_entMan.Deleted(Entity) || | ||
!_entMan.TryGetComponent<TransformComponent>(Entity, out var transform)) | ||
return; | ||
var pos = _eye.WorldToScreen(_transform.GetWorldPosition(Entity)) / _clyde.ScreenSize; | ||
if (pos == _cachedPos) | ||
return; | ||
_cachedPos = pos; | ||
RecenterWindow(pos); | ||
} | ||
} |
This file contains 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,5 @@ | ||
using Content.Shared._White.ItemSlotPicker; | ||
|
||
namespace Content.Server._White.ItemSlotPicker; | ||
|
||
public sealed class ItemSlotPickerSystem : SharedItemSlotPickerSystem; |
This file contains 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
This file contains 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
This file contains 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
17 changes: 17 additions & 0 deletions
17
Content.Shared/_White/ItemSlotPicker/ItemSlotPickerComponent.cs
This file contains 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,17 @@ | ||
using Robust.Shared.GameStates; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Shared._White.ItemSlotPicker; | ||
|
||
[RegisterComponent] | ||
[NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class ItemSlotPickerComponent : Component | ||
{ | ||
[DataField] | ||
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] | ||
public List<string> ItemSlots = new(); | ||
} |
66 changes: 66 additions & 0 deletions
66
Content.Shared/_White/ItemSlotPicker/SharedItemSlotPickerSystem.cs
This file contains 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,66 @@ | ||
using Content.Shared._White.ItemSlotPicker.UI; | ||
using Content.Shared.ActionBlocker; | ||
using Content.Shared.Containers.ItemSlots; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Interaction; | ||
using Robust.Shared.Containers; | ||
using Robust.Shared.Serialization; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Shared._White.ItemSlotPicker; | ||
|
||
public abstract class SharedItemSlotPickerSystem : EntitySystem | ||
{ | ||
[Dependency] protected readonly SharedUserInterfaceSystem _ui = default!; | ||
[Dependency] protected readonly ItemSlotsSystem _itemSlots = default!; | ||
[Dependency] protected readonly ActionBlockerSystem _blocker = default!; | ||
[Dependency] protected readonly SharedInteractionSystem _interact = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<ItemSlotPickerComponent, ComponentInit>(CompInit); | ||
SubscribeLocalEvent<ItemSlotPickerComponent, AlternativeInteractionEvent>(AltInteract); | ||
SubscribeLocalEvent<ItemSlotPickerComponent, ItemSlotPickerSlotPickedMessage>(OnMessage); | ||
} | ||
|
||
protected virtual void CompInit(EntityUid uid, ItemSlotPickerComponent comp, ComponentInit args) | ||
{ | ||
_ui.SetUi(uid, ItemSlotPickerKey.Key, new InterfaceData("ItemSlotPickerBoundUserInterface", 1.5f)); | ||
} | ||
|
||
protected virtual void AltInteract(EntityUid uid, ItemSlotPickerComponent comp, AlternativeInteractionEvent args) | ||
{ | ||
var user = args.User; | ||
if (!TryComp<ItemSlotsComponent>(uid, out var slots) || | ||
!TryComp<HandsComponent>(user, out var hands) || | ||
!_blocker.CanComplexInteract(user) || | ||
!_blocker.CanInteract(user, uid) || | ||
!_interact.InRangeAndAccessible(user, uid, 1.5f)) | ||
return; | ||
|
||
args.Handled = true; | ||
|
||
if (hands.ActiveHandEntity is EntityUid item) | ||
foreach (var slot in comp.ItemSlots) | ||
if (_itemSlots.TryInsert(uid, slot, item, user, slots, true)) | ||
return; // I wish this altverb bullshit wasn't a thing. | ||
|
||
_ui.TryToggleUi(uid, ItemSlotPickerKey.Key, user); | ||
} | ||
|
||
protected virtual void OnMessage(EntityUid uid, ItemSlotPickerComponent comp, ItemSlotPickerSlotPickedMessage args) | ||
{ | ||
if (!comp.ItemSlots.Contains(args.SlotId) || | ||
!_itemSlots.TryGetSlot(uid, args.SlotId, out var slot)) | ||
return; | ||
|
||
_itemSlots.TryEjectToHands(uid, slot, args.Actor, true); | ||
_ui.CloseUi(uid, ItemSlotPickerKey.Key, args.Actor); | ||
} | ||
} | ||
[Serializable, NetSerializable] | ||
public enum ItemSlotPickerKey { Key }; |
20 changes: 20 additions & 0 deletions
20
Content.Shared/_White/ItemSlotPicker/UI/ItemSlotPickerSlotPickedMessage.cs
This file contains 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,20 @@ | ||
using Robust.Shared.Serialization; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Shared._White.ItemSlotPicker.UI; | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class ItemSlotPickerSlotPickedMessage(string id) : BoundUserInterfaceMessage | ||
{ | ||
public string SlotId = id; | ||
} | ||
|
||
|
||
//[Serializable, NetSerializable] | ||
public sealed class ItemSlotPickerContentsChangedMessage() : BoundUserInterfaceMessage | ||
{ | ||
} |
This file contains 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
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.
Тебе тут нужен ref
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.
не нужен, ивент не struct