Skip to content

Commit

Permalink
closes octgn#2019 - group unique cards together when sorting by name …
Browse files Browse the repository at this point in the history
…in view pile window
  • Loading branch information
brine authored and kellyelton committed Nov 25, 2020
1 parent 64d0a5e commit d889a6d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 48 deletions.
10 changes: 10 additions & 0 deletions octgnFX/Octgn.JodsEngine/Play/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ public string RealName
{
get { return _type.Model != null ? _type.Model.GetName() : "Card"; }
}

public string Model
{
get { return FaceUp && _type.Model != null ? _type.Model.Id.ToString() : null; }
}
public string RealModel
{
get { return _type.Model != null ? _type.Model.Id.ToString() : null; }
}

public bool CardMoved
{
get { return _cardMoved; }
Expand Down
46 changes: 28 additions & 18 deletions octgnFX/Octgn.JodsEngine/Play/Gui/CardListControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

namespace Octgn.Play.Gui
{
public enum SortTypes
{
None,
Alpha,
Id
}
public partial class CardListControl
{
public static readonly DependencyProperty IsAlwaysUpProperty =
Expand All @@ -21,7 +27,6 @@ public partial class CardListControl
private ObservableCollection<Card> _cards;

private Predicate<Card> _filterCards;
private bool _sort;
private ListCollectionView _view;
private WrapPanel _wrapPanel;

Expand Down Expand Up @@ -59,32 +64,37 @@ public Predicate<Card> FilterCards

public bool RestrictDrop { get; set; }

public bool SortByName
public SortTypes SortMethod { get; private set; }

public void SortCards(SortTypes sort)
{
get { return _sort; }
set
if (SortMethod == sort) return;
SortMethod = sort;
using (_view.DeferRefresh())
{
if (_sort == value) return;
_sort = value;
using (_view.DeferRefresh())
if (_view.GroupDescriptions != null) _view.GroupDescriptions.Clear();
switch (sort)
{
if (value)
{
case SortTypes.Alpha:
_view.CustomSort = IsAlwaysUp
? (IComparer)new Card.RealNameComparer()
: new Card.NameComparer();
if (_view.GroupDescriptions != null)
_view.GroupDescriptions.Add(new PropertyGroupDescription(IsAlwaysUp ? "RealName" : "Name"));
}
else
{
_view.GroupDescriptions.Add(new PropertyGroupDescription(IsAlwaysUp ? "RealName" : "Name"));
break;
case SortTypes.Id:
_view.CustomSort = IsAlwaysUp
? (IComparer)new Card.RealNameComparer()
: new Card.NameComparer();
_view.GroupDescriptions.Add(new PropertyGroupDescription(IsAlwaysUp ? "RealModel" : "Model"));
break;
case SortTypes.None:
_view.CustomSort = null;
if (_view.GroupDescriptions != null) _view.GroupDescriptions.Clear();
}
break;
}
}
}


private void SaveWrapPanel(object sender, RoutedEventArgs e)
{
_wrapPanel = (WrapPanel)sender;
Expand Down Expand Up @@ -124,7 +134,7 @@ protected override void OnCardOver(object sender, CardsEventArgs e)
if (IsAlwaysUp) e.FaceUp = true;

// Drop is forbidden when not ordered by position
if (SortByName)
if (SortMethod != SortTypes.None)
{
e.CanDrop = false;
return;
Expand Down Expand Up @@ -161,7 +171,7 @@ protected override void OnCardOver(object sender, CardsEventArgs e)
protected override void OnCardDropped(object sender, CardsEventArgs e)
{
// Drop is forbidden when not ordered by position
if (SortByName)
if (SortMethod != SortTypes.None)
{
e.Handled = true;
e.CanDrop = false;
Expand Down
59 changes: 33 additions & 26 deletions octgnFX/Octgn.JodsEngine/Play/Gui/GroupWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:gui="clr-namespace:Octgn.Play.Gui"
xmlns:ctrl="clr-namespace:Octgn.Controls" Height="400" Width="510" MinHeight="350" MinWidth="390">

<ctrl:ChildWindow.Resources>
<gui:ControllerConverter x:Key="IsControlledConverter" />
</ctrl:ChildWindow.Resources>

<DockPanel LastChildFill="True">
<Border Style="{StaticResource Panel}" Margin="8,8,8,0" Padding="6,4,6,4" DockPanel.Dock="Top" CornerRadius="4">
<Grid>
<TextBox x:Name="filterBox" Width="150" HorizontalAlignment="Left" VerticalAlignment="Center"
TextChanged="FilterChanged" PreviewKeyDown="FilterBoxPreviewKeyDown" />
<TextBlock x:Name="watermark" Width="142" IsHitTestVisible="False" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="8,0,0,0" Style="{x:Null}" FontStyle="Italic" Foreground="#619AEF"
Text="Search cards" />

<ToggleButton x:Name="positionOrderBtn" Checked="PositionOrderChecked" Content="#" IsChecked="True" Width="32"
Margin="165,0,0,0" HorizontalAlignment="Left" FontWeight="Bold" Foreground="{StaticResource GlyphBrush}"
<ctrl:ChildWindow.Resources>
<gui:ControllerConverter x:Key="IsControlledConverter" />
</ctrl:ChildWindow.Resources>

<DockPanel LastChildFill="True">
<Border Style="{StaticResource Panel}" Margin="8,8,8,0" Padding="6,4,6,4" DockPanel.Dock="Top" CornerRadius="4">
<DockPanel>
<Grid>
<TextBox x:Name="filterBox" Width="150" HorizontalAlignment="Left" VerticalAlignment="Center"
TextChanged="FilterChanged" PreviewKeyDown="FilterBoxPreviewKeyDown" />
<TextBlock x:Name="watermark" Width="142" IsHitTestVisible="False" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="8,0,0,0" Style="{x:Null}" FontStyle="Italic" Foreground="#619AEF"
Text="Search cards" />
</Grid>

<ToggleButton x:Name="positionOrderBtn" Checked="PositionOrderChecked" Content="#" IsChecked="True" Width="32"
Margin="5,0,0,0" HorizontalAlignment="Left" FontWeight="Bold" Foreground="{StaticResource GlyphBrush}"
ToolTip="Sort by position" Style="{StaticResource GroupStartToggleButton}" />
<ToggleButton x:Name="alphaOrderBtn" Checked="AlphaOrderChecked" Content="A-Z" Width="32" Margin="196,0,0,0"

<ToggleButton x:Name="alphaOrderBtn" Checked="AlphaOrderChecked" Content="A-Z" Width="32"
HorizontalAlignment="Left" Foreground="{StaticResource GlyphBrush}" FontWeight="Bold" ToolTip="Sort by name"
Style="{StaticResource GroupToggleButton}" />

<ToggleButton x:Name="IdOrderBtn" Checked="IdOrderChecked" Content="ID" Width="32"
HorizontalAlignment="Left" Foreground="{StaticResource GlyphBrush}" FontWeight="Bold" ToolTip="Sort by Unique ID"
Style="{StaticResource GroupEndToggleButton}" />

<TextBlock x:Name="shuffleLink" VerticalAlignment="Center" HorizontalAlignment="Right"
<TextBlock x:Name="shuffleLink" VerticalAlignment="Center" HorizontalAlignment="Right"
Visibility="{Binding Controller, Converter={StaticResource IsControlledConverter}}">
<Hyperlink Click="CloseAndShuffleClicked">Close and shuffle</Hyperlink>
</TextBlock>
</Grid>
</Border>

<Border Style="{StaticResource Panel}" Margin="8,4,8,8">
<gui:CardListControl x:Name="cardsList" Margin="5" IsAlwaysUp="True" />
</Border>
</DockPanel>
<Hyperlink Click="CloseAndShuffleClicked">Close and shuffle</Hyperlink>
</TextBlock>
</DockPanel>
</Border>

<Border Style="{StaticResource Panel}" Margin="8,4,8,8">
<gui:CardListControl x:Name="cardsList" Margin="5" IsAlwaysUp="True" />
</Border>
</DockPanel>

</ctrl:ChildWindow>
26 changes: 23 additions & 3 deletions octgnFX/Octgn.JodsEngine/Play/Gui/GroupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ private void FilterChanged(object sender, TextChangedEventArgs e)
StringComparison.
CurrentCultureIgnoreCase) >= 0);
};
alphaOrderBtn.IsChecked = true;
if (cardsList.SortMethod == SortTypes.None)
{
IdOrderBtn.IsChecked = true;
}
}
}

Expand All @@ -164,17 +167,34 @@ private void PositionOrderChecked(object sender, RoutedEventArgs e)
{
if (alphaOrderBtn == null)
return; // Happens during the control initialization, when the event is first called
if (cardsList.SortMethod == SortTypes.None) return;

positionOrderBtn.IsChecked = true;
alphaOrderBtn.IsChecked = false;
cardsList.SortByName = false;
IdOrderBtn.IsChecked = false;
filterBox.Text = "";
cardsList.SortCards(SortTypes.None);
}

private void AlphaOrderChecked(object sender, RoutedEventArgs e)
{
if (cardsList.SortMethod == SortTypes.Alpha) return;
CardControl.SetAnimateLoad(this, false);

alphaOrderBtn.IsChecked = true;
positionOrderBtn.IsChecked = false;
cardsList.SortByName = true;
IdOrderBtn.IsChecked = false;
cardsList.SortCards(SortTypes.Alpha);
}
private void IdOrderChecked(object sender, RoutedEventArgs e)
{
if (cardsList.SortMethod == SortTypes.Id) return;
CardControl.SetAnimateLoad(this, false);

IdOrderBtn.IsChecked = true;
positionOrderBtn.IsChecked = false;
alphaOrderBtn.IsChecked = false;
cardsList.SortCards(SortTypes.Id);
}

public void CardsChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion recentchanges.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

Can now sort by unique cards in the 'view pile' window

0 comments on commit d889a6d

Please sign in to comment.