Skip to content

Commit

Permalink
many PropertyChanged -> ValueChanged (fixes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymonf committed Oct 24, 2023
1 parent 9e76b14 commit e6551fa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions BAKKA_Editor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
Expand Down Expand Up @@ -31,6 +30,7 @@ public partial class MainViewModel : ViewModelBase

// Note UI State
public ObservableCollection<NoteOnBeatItem> NotesOnBeatList { get; } = new();
[ObservableProperty] private bool endHoldChecked = false;

// Music UI State
// TODO: move this stuff out of here
Expand Down
44 changes: 24 additions & 20 deletions BAKKA_Editor/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@
Click="endChartButton_Click">
End of Chart
</Button>
<CheckBox Name="endHoldCheck" IsChecked="False" Margin="0,0"
PropertyChanged="EndHoldCheck_OnPropertyChanged">
<CheckBox Name="_endHoldCheck"
IsChecked="{Binding EndHoldChecked}" Margin="0,0"
IsCheckedChanged="EndHoldCheck_IsCheckedChanged">
End Hold
</CheckBox>

Expand Down Expand Up @@ -318,7 +319,7 @@
Maximum="{Binding PositionTrackBarMaximum}"
SmallChange="1" LargeChange="5"
Padding="8,0,0,0"
PropertyChanged="PositionTrackBar_OnPropertyChanged"
ValueChanged="PositionTrackBar_OnValueChanged"
PointerWheelChanged="PositionTrackBar_OnPointerWheelChanged" />
</Grid>
<TextBlock Margin="0,4">Size:</TextBlock>
Expand All @@ -335,7 +336,7 @@
Maximum="{Binding SizeTrackBarMaximum}"
SmallChange="1" LargeChange="5"
Padding="8,0,0,0"
PropertyChanged="SizeTrackBar_OnPropertyChanged"
ValueChanged="SizeTrackBar_OnValueChanged"
PointerWheelChanged="SizeTrackBar_OnPointerWheelChanged" />
</Grid>
<TextBlock Margin="0,4">Measure:</TextBlock>
Expand Down Expand Up @@ -373,15 +374,16 @@
</StackPanel>

<!-- Canvas Stack Panel -->

<!-- Width="611" Height="524" -->
<StackPanel Grid.Column="1" Name="CanvasStackPanel">
<controls:SkiaCanvas Name="CircleControl" Background="Transparent" RenderSkia="RenderCanvas"
HorizontalAlignment="Center" VerticalAlignment="Center"
PointerPressed="CircleControl_OnPointerPressed"
PointerReleased="CircleControl_OnPointerReleased"
PointerMoved="CircleControl_OnPointerMoved"
PointerWheelChanged="CircleControl_OnWheel" />
<controls:SkiaCanvas
Name="CircleControl"
Background="Transparent"
RenderSkia="RenderCanvas"
HorizontalAlignment="Center" VerticalAlignment="Center"
PointerPressed="CircleControl_OnPointerPressed"
PointerReleased="CircleControl_OnPointerReleased"
PointerMoved="CircleControl_OnPointerMoved"
PointerWheelChanged="CircleControl_OnWheel" />
</StackPanel>
</Grid>

Expand Down Expand Up @@ -410,7 +412,7 @@
<StackPanel Grid.Column="1">
<Slider Value="{Binding SongTrackBar}" Minimum="0"
Maximum="{Binding SongTrackBarMaximum}" SmallChange="1"
LargeChange="5" PropertyChanged="SongTrackBar_OnPropertyChanged"
LargeChange="5" ValueChanged="SongTrackBar_OnValueChanged"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

<!-- Speed and Volume -->
Expand All @@ -426,7 +428,7 @@
Maximum="{Binding SpeedTrackBarMaximum}"
SmallChange="1" LargeChange="5" Width="100"
HorizontalAlignment="Center"
PropertyChanged="TrackBarSpeed_OnPropertyChanged" />
ValueChanged="TrackBarSpeed_OnValueChanged" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
Expand All @@ -437,7 +439,7 @@
Maximum="{Binding VolumeTrackBarMaximum}"
SmallChange="1" LargeChange="5" Width="100"
HorizontalAlignment="Center"
PropertyChanged="TrackBarVolume_OnPropertyChanged" />
ValueChanged="TrackBarVolume_OnValueChanged" />
</StackPanel>
<StackPanel Orientation="Horizontal" Name="HitsoundPanel">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
Expand All @@ -448,7 +450,7 @@
Maximum="{Binding HitsoundVolumeMaximum}"
SmallChange="1" LargeChange="5" Width="50"
HorizontalAlignment="Center"
PropertyChanged="TrackBarHitsounds_OnPropertyChanged" />
ValueChanged="TrackBarHitsounds_OnValueChanged" />
</StackPanel>
</StackPanel>
</StackPanel>
Expand Down Expand Up @@ -483,7 +485,7 @@
<TextBlock Grid.Column="1">Position</TextBlock>
<TextBlock Grid.Column="2">Size</TextBlock>
</Grid>

<ListBox Grid.Row="1" Name="NotesOnBeatListBox"
ItemsSource="{Binding NotesOnBeatList}"
SelectionChanged="NotesOnBeatListBox_OnSelectionChanged"
Expand All @@ -493,15 +495,17 @@
<DataTemplate>
<Grid ColumnDefinitions="10*,5*,5*">
<TextBlock VerticalAlignment="Center" Text="{Binding Type}" TextWrapping="Wrap" />
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding Position}" TextWrapping="Wrap" />
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Size}" TextWrapping="Wrap" />
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding Position}"
TextWrapping="Wrap" />
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Size}"
TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</HeaderedContentControl>

<HeaderedContentControl Header="Note View" Margin="0,0,0,8">
<StackPanel Margin="8">
<Grid RowDefinitions="*,Auto,*" ColumnDefinitions="*,*">
Expand Down
50 changes: 23 additions & 27 deletions BAKKA_Editor/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Styling;
using Avalonia.Threading;
Expand Down Expand Up @@ -978,7 +978,7 @@ private void SetSelectedObject(NoteType type)
minSize = 2;
break;
case NoteType.HoldJoint:
if (endHoldCheck.IsChecked!.Value)
if (_vm.EndHoldChecked)
{
updateLabel("Hold End");
currentNoteType = NoteType.HoldEnd;
Expand Down Expand Up @@ -1413,6 +1413,8 @@ private void UpdateSelectedNote()

private void MeasureNumeric_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
if (_vm.MeasureNumeric != e.NewValue)
_vm.MeasureNumeric = Convert.ToDecimal(e.NewValue ?? _vm.MeasureNumeric);
updateTime();
}

Expand All @@ -1425,10 +1427,8 @@ private void PositionNumeric_OnValueChanged(object? sender, NumericUpDownValueCh
_vm.PositionTrackBar = newValue;
}

private void PositionTrackBar_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void PositionTrackBar_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
if (!e.Property.Name.Equals("Value", StringComparison.InvariantCultureIgnoreCase) || e.NewValue == null)
return;
var newValue = Convert.ToInt32(e.NewValue);
if ((int) _vm.PositionNumeric != newValue)
_vm.PositionNumeric = newValue;
Expand All @@ -1443,10 +1443,8 @@ private void SizeNumeric_OnValueChanged(object? sender, NumericUpDownValueChange
_vm.SizeTrackBar = newValue;
}

private void SizeTrackBar_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void SizeTrackBar_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
if (!e.Property.Name.Equals("Value", StringComparison.InvariantCultureIgnoreCase) || e.NewValue == null)
return;
var newValue = Convert.ToInt32(e.NewValue);
if ((int) _vm.SizeNumeric != newValue)
_vm.SizeNumeric = newValue;
Expand Down Expand Up @@ -1488,11 +1486,11 @@ private void InsertObject()
tempNote.PrevNote = lastNote;
if (lastNote != null)
tempNote.PrevNote.NextNote = tempNote;
if (endHoldCheck.IsChecked!.Value)
if (_vm.EndHoldChecked)
{
tempNote.NoteType = NoteType.HoldEnd;
SetNonHoldButtonState(true);
endHoldCheck.IsChecked = false;
_vm.EndHoldChecked = false;
holdButtonClicked();
}
else
Expand Down Expand Up @@ -1579,14 +1577,13 @@ private void SetNonHoldButtonState(bool state)
reverseButton.IsEnabled = state;
}

private void EndHoldCheck_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void EndHoldCheck_IsCheckedChanged(object? sender, RoutedEventArgs routedEventArgs)
{
if (endHoldCheck == null || e.Property.Name != "IsChecked")
return;
if (_vm.EndHoldChecked && currentNoteType == NoteType.HoldJoint)
SetSelectedObject(NoteType.HoldEnd);

if (endHoldCheck.IsChecked.Value && currentNoteType == NoteType.HoldJoint) SetSelectedObject(NoteType.HoldEnd);

if (!endHoldCheck.IsChecked.Value && currentNoteType == NoteType.HoldEnd) SetSelectedObject(NoteType.HoldJoint);
if (!_vm.EndHoldChecked && currentNoteType == NoteType.HoldEnd)
SetSelectedObject(NoteType.HoldJoint);
}

private void OnResize()
Expand Down Expand Up @@ -2581,15 +2578,15 @@ private void SelectSongButton_OnClick(object? sender, RoutedEventArgs e)
Dispatcher.UIThread.Post(async () => await ShowOpenSongDialog(), DispatcherPriority.Background);
}

private void SongTrackBar_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void SongTrackBar_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
// TODO: tighten property check
if (currentSong == null)
return;
if (IsSongPlaying())
return;

currentSong.PlayPosition = (uint) _vm.SongTrackBar;
currentSong.PlayPosition = (uint) e.NewValue;
var info = chart.GetBeat(currentSong.PlayPosition);
if (info.Measure != -1 && valueTriggerEvent != EventSource.MouseWheel)
{
Expand All @@ -2603,27 +2600,26 @@ private void SongTrackBar_OnPropertyChanged(object? sender, AvaloniaPropertyChan
valueTriggerEvent = EventSource.None;
}

private void TrackBarVolume_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void TrackBarVolume_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
if (trackBarVolume == null)
return;
userSettings.ViewSettings.Volume = (int) _vm.VolumeTrackBar;
if (currentSong != null && e.Property.Name == "Value")
UpdateSongVolume();
userSettings.ViewSettings.Volume = (int) e.NewValue;
UpdateSongVolume();
}

private void TrackBarSpeed_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void TrackBarSpeed_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
/* No song, nothing to do. */
if (currentSong == null)
return;
currentSong.PlaybackSpeed = (float) (_vm.SpeedTrackBar / (float) _vm.SpeedTrackBarMaximum);
currentSong.PlaybackSpeed = (float) e.NewValue / _vm.SpeedTrackBarMaximum;
LabelSpeed.Text = $"Speed (x{currentSong.PlaybackSpeed:0.00})";
}

private void VisualHispeedNumeric_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
var value = (float) _vm.VisualHiSpeedNumeric;
var value = (float) (e.NewValue ?? _vm.VisualHiSpeedNumeric);
if (value >= (float) _vm.VisualHiSpeedNumericMinimum && value <= (float) _vm.VisualHiSpeedNumericMaximum)
// update
skCircleView.Hispeed = value;
Expand Down Expand Up @@ -2789,9 +2785,9 @@ private void GimmickJumpToCurrTimeButton_OnClick(object? sender, RoutedEventArgs
UpdateGimmickLabels();
}

private void TrackBarHitsounds_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
private void TrackBarHitsounds_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
userSettings.SoundSettings.HitsoundVolume = (int) _vm.HitsoundVolumeTrackBar;
userSettings.SoundSettings.HitsoundVolume = (int) e.NewValue;
var volume = (float) _vm.HitsoundVolumeTrackBar / (float) _vm.HitsoundVolumeMaximum;
hitsoundChannel?.SetVolume(Math.Clamp(volume, 0.0f, 1.0f));
}
Expand Down

0 comments on commit e6551fa

Please sign in to comment.