Skip to content
Merged
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
1 change: 1 addition & 0 deletions WheelWizard/Views/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<StyleInclude Source="Components/StandardLibrary/LoadingIcon.axaml" />
<StyleInclude Source="Components/StandardLibrary/SidebarRadioButton.axaml" />
<StyleInclude Source="Components/StandardLibrary/PopupListButton.axaml" />
<StyleInclude Source="Components/StandardLibrary/MemeNumberState.axaml" />

<!-- PAGE/WHWZ SPECIFIC COMPONENTS -->
<StyleInclude Source="Components/WhWzLibrary/ModBrowserListItem.axaml" />
Expand Down
103 changes: 103 additions & 0 deletions WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:components="clr-namespace:WheelWizard.Views.Components">

<Design.PreviewWith>
<Border Padding="20" Background="{StaticResource Neutral950}">
<StackPanel Spacing="40" Orientation="Horizontal">
<StackPanel Spacing="10">
<components:MemeNumberState Text="10" IconSize="0" Enable67="False" Enable69="False"/>
<components:MemeNumberState Text="69" IconSize="0" Enable67="False" Enable69="False"/>
<components:MemeNumberState Text="67" IconSize="0" Enable67="False" Enable69="False"/>
</StackPanel>

<StackPanel Spacing="10">
<components:MemeNumberState Text="10" IconSize="0" />
<components:MemeNumberState Text="69" IconSize="0" />
<components:MemeNumberState Text="67" IconSize="0" />
</StackPanel>

<StackPanel Spacing="10">
<components:MemeNumberState IconData="{StaticResource Award}" Text="10" />
<components:MemeNumberState IconData="{StaticResource Award}" Text="69" />
<components:MemeNumberState IconData="{StaticResource Award}" Text="67" />
</StackPanel>
</StackPanel>

</Border>
</Design.PreviewWith>

<Style Selector="components|MemeNumberState">
<Setter Property="Template">
<ControlTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" VerticalAlignment="Center">

<Panel>
<!-- Normal State -->
<components:StateBox x:Name="PART_StateBox"
IconData="{TemplateBinding IconData}"
IconSize="{TemplateBinding IconSize}"
Text="{TemplateBinding Text}"
FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType=components:MemeNumberState}}"
Variant="{TemplateBinding Variant}"
TipText="{TemplateBinding TipText}" />

<!-- 67 Special State -->
<components:StateBox x:Name="PART_SpecialBadge"
IconData="{TemplateBinding IconData}"
IconSize="{TemplateBinding IconSize}"
Variant="{TemplateBinding Variant}"
FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType=components:MemeNumberState}}"
TipText="{TemplateBinding TipText}"
IsVisible="False">
<components:StateBox.Content>
<Grid ColumnDefinitions="Auto, Auto">
<TextBlock Text="6" Classes="BobUp"
Foreground="{StaticResource Warning100}"
FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType=components:MemeNumberState}}"
VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="7" Classes="BobDown" Margin="1,0,0,0"
Foreground="{StaticResource Warning100}"
FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType=components:MemeNumberState}}"
VerticalAlignment="Center" />
</Grid>
</components:StateBox.Content>
</components:StateBox>
</Panel>

<components:FormFieldLabel Foreground="{StaticResource Primary400}"
Text="Nice!"
x:Name="PART_NiceLabel"
IsVisible="False"
VerticalAlignment="Center" />
</StackPanel>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="TextBlock.BobUp">
<Style.Animations>
<Animation Duration="0:0:0.25" IterationCount="Infinite" PlaybackDirection="Alternate">
<KeyFrame Cue="0%">
<Setter Property="TranslateTransform.Y" Value="2" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="TranslateTransform.Y" Value="-2" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>

<Style Selector="TextBlock.BobDown">
<Style.Animations>
<Animation Duration="0:0:0.25" Delay="0:0:0.25" IterationCount="Infinite" PlaybackDirection="Alternate">
<KeyFrame Cue="0%">
<Setter Property="TranslateTransform.Y" Value="2" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="TranslateTransform.Y" Value="-2" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</Styles>
121 changes: 121 additions & 0 deletions WheelWizard/Views/Components/StandardLibrary/MemeNumberState.axaml.cs
Original file line number Diff line number Diff line change
@@ -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<string> TextProperty = AvaloniaProperty.Register<MemeNumberState, string>(nameof(Text), "0");

public string Text
{
get => GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

public static readonly StyledProperty<Geometry> IconDataProperty = AvaloniaProperty.Register<MemeNumberState, Geometry>(
nameof(IconData)
);

public Geometry IconData
{
get => GetValue(IconDataProperty);
set => SetValue(IconDataProperty, value);
}

public static readonly StyledProperty<double> IconSizeProperty = AvaloniaProperty.Register<MemeNumberState, double>(
nameof(IconSize),
20
);

public double IconSize
{
get => GetValue(IconSizeProperty);
set => SetValue(IconSizeProperty, value);
}

public static readonly StyledProperty<string> TipTextProperty = AvaloniaProperty.Register<MemeNumberState, string>(nameof(TipText));

public string TipText
{
get => GetValue(TipTextProperty);
set => SetValue(TipTextProperty, value);
}

public static readonly StyledProperty<StateBox.StateBoxVariantType> 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<bool> Enable67Property = AvaloniaProperty.Register<MemeNumberState, bool>(nameof(Enable67), true);

public bool Enable67
{
get => GetValue(Enable67Property);
set => SetValue(Enable67Property, value);
}

public static readonly StyledProperty<bool> Enable69Property = AvaloniaProperty.Register<MemeNumberState, bool>(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<StateBox>("PART_StateBox");
_specialBadge = e.NameScope.Find<StateBox>("PART_SpecialBadge");
_niceLabel = e.NameScope.Find<FormFieldLabel>("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;
}
}
}
16 changes: 13 additions & 3 deletions WheelWizard/Views/Components/StandardLibrary/StateBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,33 @@
ToolTip.Tip="{TemplateBinding TipText}"
ToolTip.Placement="{TemplateBinding TipPlacement}"
ToolTip.ShowDelay="20">
<Grid ColumnDefinitions="Auto,Auto, *">
<Grid ColumnDefinitions="Auto,Auto,*">
<!-- Icon (always visible if IconData is set) -->
<Border Background="Transparent"
IsVisible="{TemplateBinding IconData, Converter={x:Static ObjectConverters.IsNotNull}}"
Width="{TemplateBinding IconSize}" Height="{TemplateBinding IconSize}">
<Path Data="{TemplateBinding IconData}" x:Name="PART_StateBox_IconPath"
Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>

<!-- Spacer between icon and text/content -->
<Rectangle Grid.Column="1" Width="4"
IsVisible="{TemplateBinding IconSize,
Converter={x:Static conv:NumberConverters.GreaterThan0 }}"/>

<TextBlock Grid.Column="2" x:Name="PART_StateBox_Text"
<!-- Text (visible when Content is null) -->
<TextBlock Grid.Column="2" x:Name="PART_StateBox_Text"
Margin="0,0,0,0"
Text="{TemplateBinding Text}"
FontSize="{TemplateBinding FontSize}"
FontWeight="Medium" VerticalAlignment="Center"/>
FontWeight="Medium" VerticalAlignment="Center"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNull}}"/>

<!-- Content (visible when Content is not null) -->
<ContentPresenter Grid.Column="2" x:Name="PART_ContentPresenter"
Content="{TemplateBinding Content}"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}"
VerticalAlignment="Center"/>
</Grid>
</Border>
</ControlTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public Geometry IconData
set => SetValue(IconDataProperty, value);
}

public static readonly StyledProperty<object?> ContentProperty = AvaloniaProperty.Register<StateBox, object?>(nameof(Content));

public object? Content
{
get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

public static readonly StyledProperty<double> IconSizeProperty = AvaloniaProperty.Register<StateBox, double>(nameof(IconSize), 20);

public double IconSize
Expand Down
9 changes: 3 additions & 6 deletions WheelWizard/Views/Pages/RoomsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,6">
<components:FormFieldLabel Text="{x:Static lang:Common.ListTitle_Rooms}" />
<components:StateBox Text="0" IconSize="0" x:Name="RoomsListItemCount" />
<components:FormFieldLabel Foreground="{StaticResource Primary400}" Margin="4,0,0,0"
Text="Nice!" x:Name="RoomsNiceLabel" IsVisible="False" />
<components:MemeNumberState Text="0" IconSize="0" x:Name="RoomsListItemCount"
IconData="{StaticResource Dice}" />
</StackPanel>
<Border Background="{StaticResource BackgroundLineColor}" Height="1" HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" />
Expand Down Expand Up @@ -126,9 +125,7 @@
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,6">
<components:FormFieldLabel Text="{x:Static lang:Common.ListTitle_Players}" />
<components:StateBox Text="0" IconSize="0" x:Name="PlayerListItemCount" />
<components:FormFieldLabel Foreground="{StaticResource Primary400}" Margin="4,0,0,0"
Text="Nice!" x:Name="PlayerNiceLabel" IsVisible="False" />
<components:MemeNumberState Text="0" IconSize="0" x:Name="PlayerListItemCount" />
</StackPanel>
<Border Background="{StaticResource BackgroundLineColor}" Height="1" HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" />
Expand Down
2 changes: 0 additions & 2 deletions WheelWizard/Views/Pages/RoomsPage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
foreach (var room in liveRooms.CurrentRooms)
Rooms.Add(room);

RoomsNiceLabel.IsVisible = liveRooms.CurrentRooms.Count == 69;
RoomsListItemCount.Text = liveRooms.CurrentRooms.Count.ToString();
PerformSearch(_searchQuery);
}
Expand All @@ -88,7 +87,6 @@
foreach (var player in matchingPlayers)
Players.Add(player);

PlayerNiceLabel.IsVisible = matchingPlayers.Count == 69;
PlayerListItemCount.Text = matchingPlayers.Count.ToString();
}

Expand Down Expand Up @@ -137,7 +135,7 @@

#region PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged;

Check warning on line 138 in WheelWizard/Views/Pages/RoomsPage.axaml.cs

View workflow job for this annotation

GitHub Actions / Build and Test

'RoomsPage.PropertyChanged' hides inherited member 'AvaloniaObject.PropertyChanged'. Use the new keyword if hiding was intended.

protected virtual void OnPropertyChanged(string propertyName)
{
Expand Down
3 changes: 3 additions & 0 deletions WheelWizard/WheelWizard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<DependentUpon>EditorEmpty.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\Components\StandardLibrary\MemeNumberState.axaml.cs">
<DependentUpon>MemeNumberState.axaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup Label="Additional Files">
Expand Down
Loading