diff --git a/WheelWizard/Views/App.axaml b/WheelWizard/Views/App.axaml index c8b10f02..65f76ef6 100644 --- a/WheelWizard/Views/App.axaml +++ b/WheelWizard/Views/App.axaml @@ -61,6 +61,7 @@ + diff --git a/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml b/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml new file mode 100644 index 00000000..4e6c7ec3 --- /dev/null +++ b/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml.cs b/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml.cs new file mode 100644 index 00000000..4dc62a87 --- /dev/null +++ b/WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml.cs @@ -0,0 +1,121 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Media; + +namespace WheelWizard.Views.Components; + +public class MemeNumberState : TemplatedControl +{ + private StateBox? _stateBox; + private StateBox? _specialBadge; + private FormFieldLabel? _niceLabel; + + public static readonly StyledProperty TextProperty = AvaloniaProperty.Register(nameof(Text), "0"); + + public string Text + { + get => GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public static readonly StyledProperty IconDataProperty = AvaloniaProperty.Register( + nameof(IconData) + ); + + public Geometry IconData + { + get => GetValue(IconDataProperty); + set => SetValue(IconDataProperty, value); + } + + public static readonly StyledProperty IconSizeProperty = AvaloniaProperty.Register( + nameof(IconSize), + 20 + ); + + public double IconSize + { + get => GetValue(IconSizeProperty); + set => SetValue(IconSizeProperty, value); + } + + public static readonly StyledProperty TipTextProperty = AvaloniaProperty.Register(nameof(TipText)); + + public string TipText + { + get => GetValue(TipTextProperty); + set => SetValue(TipTextProperty, value); + } + + public static readonly StyledProperty VariantProperty = AvaloniaProperty.Register< + MemeNumberState, + StateBox.StateBoxVariantType + >(nameof(Variant), StateBox.StateBoxVariantType.Default); + + public StateBox.StateBoxVariantType Variant + { + get => GetValue(VariantProperty); + set => SetValue(VariantProperty, value); + } + + public static readonly StyledProperty Enable67Property = AvaloniaProperty.Register(nameof(Enable67), true); + + public bool Enable67 + { + get => GetValue(Enable67Property); + set => SetValue(Enable67Property, value); + } + + public static readonly StyledProperty Enable69Property = AvaloniaProperty.Register(nameof(Enable69), true); + + public bool Enable69 + { + get => GetValue(Enable69Property); + set => SetValue(Enable69Property, value); + } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + _stateBox = e.NameScope.Find("PART_StateBox"); + _specialBadge = e.NameScope.Find("PART_SpecialBadge"); + _niceLabel = e.NameScope.Find("PART_NiceLabel"); + + UpdateState(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == TextProperty) + { + UpdateState(); + } + } + + private void UpdateState() + { + if (_stateBox == null || _niceLabel == null || _specialBadge == null) + return; + + var val = Text; + + // Reset defaults + _niceLabel.IsVisible = false; + _stateBox.IsVisible = true; + _specialBadge.IsVisible = false; + + _stateBox.Text = val; // Always ensure text is set for normal cases + + if (val == "69" && Enable69) + { + _niceLabel.IsVisible = true; + } + else if (val == "67" && Enable67) + { + _stateBox.IsVisible = false; + _specialBadge.IsVisible = true; + } + } +} diff --git a/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml b/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml index 2e1b3e67..89a43018 100644 --- a/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml +++ b/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml @@ -30,7 +30,8 @@ ToolTip.Tip="{TemplateBinding TipText}" ToolTip.Placement="{TemplateBinding TipPlacement}" ToolTip.ShowDelay="20"> - + + @@ -38,15 +39,24 @@ Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/> + - + + FontWeight="Medium" VerticalAlignment="Center" + IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNull}}"/> + + + diff --git a/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml.cs b/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml.cs index 8c3c2039..632ef21b 100644 --- a/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml.cs +++ b/WheelWizard/Views/Components/StandardLibrary/StateBox.axaml.cs @@ -41,6 +41,14 @@ public Geometry IconData set => SetValue(IconDataProperty, value); } + public static readonly StyledProperty ContentProperty = AvaloniaProperty.Register(nameof(Content)); + + public object? Content + { + get => GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + public static readonly StyledProperty IconSizeProperty = AvaloniaProperty.Register(nameof(IconSize), 20); public double IconSize diff --git a/WheelWizard/Views/Pages/RoomsPage.axaml b/WheelWizard/Views/Pages/RoomsPage.axaml index 401423d0..2b0029b8 100644 --- a/WheelWizard/Views/Pages/RoomsPage.axaml +++ b/WheelWizard/Views/Pages/RoomsPage.axaml @@ -50,9 +50,8 @@ - - + @@ -126,9 +125,7 @@ - - + diff --git a/WheelWizard/Views/Pages/RoomsPage.axaml.cs b/WheelWizard/Views/Pages/RoomsPage.axaml.cs index 23b6ff2c..ea311f1d 100644 --- a/WheelWizard/Views/Pages/RoomsPage.axaml.cs +++ b/WheelWizard/Views/Pages/RoomsPage.axaml.cs @@ -61,7 +61,6 @@ public void OnUpdate(RepeatedTaskManager sender) foreach (var room in liveRooms.CurrentRooms) Rooms.Add(room); - RoomsNiceLabel.IsVisible = liveRooms.CurrentRooms.Count == 69; RoomsListItemCount.Text = liveRooms.CurrentRooms.Count.ToString(); PerformSearch(_searchQuery); } @@ -88,7 +87,6 @@ private void PerformSearch(string? query) foreach (var player in matchingPlayers) Players.Add(player); - PlayerNiceLabel.IsVisible = matchingPlayers.Count == 69; PlayerListItemCount.Text = matchingPlayers.Count.ToString(); } diff --git a/WheelWizard/WheelWizard.csproj b/WheelWizard/WheelWizard.csproj index 513ab804..4fbdcc10 100644 --- a/WheelWizard/WheelWizard.csproj +++ b/WheelWizard/WheelWizard.csproj @@ -115,6 +115,9 @@ EditorEmpty.axaml Code + + MemeNumberState.axaml +