Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

сделал ползунок для бумбокса #290

Closed
wants to merge 1 commit into from
Closed
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: 7 additions & 1 deletion Content.Client/BoomBox/UI/BoomBoxBoundUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ protected override void Open()
_window.PlusVolButtonPressed += OnPlusVolButtonPressed;
_window.StartButtonPressed += OnStartButtonPressed;
_window.StopButtonPressed += OnStopButtonPressed;
_window.PlaybackSliderChanged += OnPlaybackSliderChanged;
}

private void OnPlaybackSliderChanged(float newPosition)
{
SendMessage(new BoomBoxSetTimeMessage(newPosition)); // Отправка сообщения при изменении ползунка
}

private void OnMinusVolButtonPressed()
Expand Down Expand Up @@ -64,4 +70,4 @@ protected override void Dispose(bool disposing)
if (disposing)
_window?.Dispose();
}
}
}
9 changes: 6 additions & 3 deletions Content.Client/BoomBox/UI/BoomBoxWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'boombox-ui-window'}"
MinSize="256 80"
SetSize="256 80">
MinSize="256 130"
SetSize="256 130">чё
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Button Name="MinusVolButton"
Expand All @@ -22,4 +22,7 @@
Disabled="True" />
</BoxContainer>
</BoxContainer>
</DefaultWindow>
<BoxContainer Orientation="Vertical">
<Slider Name="PlaybackSlider" HorizontalExpand="True" Margin="60"/>
</BoxContainer>
</DefaultWindow>
7 changes: 6 additions & 1 deletion Content.Client/BoomBox/UI/BoomBoxWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public sealed partial class BoomBoxWindow : DefaultWindow
public event Action? PlusVolButtonPressed;
public event Action? StartButtonPressed;
public event Action? StopButtonPressed;
public event Action<float>? PlaybackSliderChanged;

private bool _isSliderDragging = false;

public BoomBoxWindow()
{
Expand All @@ -22,6 +25,7 @@ public BoomBoxWindow()
PlusVolButton.OnPressed += _ => PlusVolButtonPressed?.Invoke();
StartButton.OnPressed += _ => StartButtonPressed?.Invoke();
StopButton.OnPressed += _ => StopButtonPressed?.Invoke();
PlaybackSlider.OnValueChanged += args => PlaybackSliderChanged?.Invoke(args.Value);
}

public void UpdateState(BoomBoxUiState state)
Expand All @@ -30,5 +34,6 @@ public void UpdateState(BoomBoxUiState state)
PlusVolButton.Disabled = !state.CanPlusVol;
StartButton.Disabled = !state.CanStart;
StopButton.Disabled = !state.CanStop;
PlaybackSlider.SetValueWithoutEvent(state.PlaybackPosition);
}
}
}
3 changes: 2 additions & 1 deletion Content.Server/BoomBox/BoomBoxComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ public sealed partial class BoomBoxComponent : Component
[DataField("slots")]
public Dictionary<string, ItemSlot> Slots = new();

}
public float PlaybackPosition = 0f;
}
16 changes: 12 additions & 4 deletions Content.Server/BoomBox/BoomBoxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@ public override void Initialize()
SubscribeLocalEvent<BoomBoxComponent, BoomBoxMinusVolMessage>(OnMinusVolButtonPressed);
SubscribeLocalEvent<BoomBoxComponent, BoomBoxStartMessage>(OnStartButtonPressed);
SubscribeLocalEvent<BoomBoxComponent, BoomBoxStopMessage>(OnStopButtonPressed);
SubscribeLocalEvent<BoomBoxComponent, BoomBoxSetTimeMessage>(OnSetTimeMessage);
}

private void OnSetTimeMessage(EntityUid uid, BoomBoxComponent component, BoomBoxSetTimeMessage args)
{
if (component.Stream != null)
{
_audioSystem.SetPlaybackPosition(component.Stream, args.PlaybackPosition);
component.PlaybackPosition = args.PlaybackPosition; // Обновление позиции воспроизведения
}

UpdateUserInterface(uid, component); // Обновление интерфейса
}

// This method makes it possible to insert cassettes into the boombox
private void OnComponentInit(EntityUid uid, BoomBoxComponent component, ComponentInit args)
Expand Down Expand Up @@ -141,8 +152,6 @@ private void OnToggleInterface(EntityUid uid, BoomBoxComponent component, AfterA
UpdateUserInterface(uid, component);
}

// ----------------------------------------------------------------------------------------------------------------

private void UpdateUserInterface(EntityUid uid, BoomBoxComponent? component = null)
{
if (!Resolve(uid, ref component))
Expand Down Expand Up @@ -178,8 +187,7 @@ private void UpdateUserInterface(EntityUid uid, BoomBoxComponent? component = nu
canStop = false;
}


var state = new BoomBoxUiState(canPlusVol, canMinusVol, canStop, canStart);
var state = new BoomBoxUiState(canPlusVol, canMinusVol, canStop, canStart, component.PlaybackPosition);
_userInterface.SetUiState(uid, BoomBoxUiKey.Key, state);
}

Expand Down
18 changes: 16 additions & 2 deletions Content.Shared/BoomBox/SharedBoomBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ public sealed class BoomBoxUiState : BoundUserInterfaceState
public bool CanMinusVol { get; }
public bool CanStop { get; }
public bool CanStart { get; }
public float PlaybackPosition { get; }

public BoomBoxUiState(
bool canPlusVol,
bool canMinusVol,
bool canStop,
bool canStart)
bool canStart,
float playbackPosition)
{
CanPlusVol = canPlusVol;
CanMinusVol = canMinusVol;
CanStop = canStop;
CanStart = canStart;
PlaybackPosition = playbackPosition;
}
}

[Serializable, NetSerializable]
public sealed class BoomBoxSetTimeMessage : BoundUserInterfaceMessage
{
public float PlaybackPosition { get; }

public BoomBoxSetTimeMessage(float playbackPosition)
{
PlaybackPosition = playbackPosition;
}
}

Expand All @@ -47,4 +61,4 @@ public sealed class BoomBoxStartMessage : BoundUserInterfaceMessage
[Serializable, NetSerializable]
public sealed class BoomBoxStopMessage : BoundUserInterfaceMessage
{
}
}
Loading