Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Initial version of the server status page is completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirdoombox committed Mar 17, 2022
1 parent dba8825 commit a5b2316
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 77 deletions.
1 change: 1 addition & 0 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<converters:StringToAccentBrushConverter x:Key="StringToAccentBrush" />
<converters:BooleanToStatusImageConverter x:Key="BooleanToStatusImage" />
<converters:ServerStatusToPackIconImageConverter x:Key="ServerStatusToPackIconImage"/>
<converters:IsLastItemInContainerConverter x:Key="IsLastItemInContainer"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
116 changes: 116 additions & 0 deletions Controls/AlignableWrapPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
namespace LostArkTools.Controls;

using System;
using System.Windows;
using System.Windows.Controls;

public class AlignableWrapPanel : Panel
{
public HorizontalAlignment HorizontalContentAlignment
{
get => (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty);
set => SetValue(HorizontalContentAlignmentProperty, value);
}

public static readonly DependencyProperty HorizontalContentAlignmentProperty =
DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignableWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsArrange));

protected override Size MeasureOverride(Size constraint)
{
var curLineSize = new Size();
var panelSize = new Size();

var children = InternalChildren;

for (var i = 0; i < children.Count; i++)
{
var child = children[i] as UIElement;

// Flow passes its own constraint to children
child.Measure(constraint);
var sz = child.DesiredSize;

if (curLineSize.Width + sz.Width > constraint.Width) //need to switch to another line
{
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
panelSize.Height += curLineSize.Height;
curLineSize = sz;

if (sz.Width > constraint.Width) // if the element is wider then the constraint - give it a separate line
{
panelSize.Width = Math.Max(sz.Width, panelSize.Width);
panelSize.Height += sz.Height;
curLineSize = new Size();
}
}
else //continue to accumulate a line
{
curLineSize.Width += sz.Width;
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
}
}

// the last line size, if any need to be added
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
panelSize.Height += curLineSize.Height;

return panelSize;
}

protected override Size ArrangeOverride(Size arrangeBounds)
{
var firstInLine = 0;
var curLineSize = new Size();
double accumulatedHeight = 0;
var children = InternalChildren;

for (var i = 0; i < children.Count; i++)
{
var sz = children[i].DesiredSize;

if (curLineSize.Width + sz.Width > arrangeBounds.Width) //need to switch to another line
{
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, i);

accumulatedHeight += curLineSize.Height;
curLineSize = sz;

if (sz.Width > arrangeBounds.Width) //the element is wider then the constraint - give it a separate line
{
ArrangeLine(accumulatedHeight, sz, arrangeBounds.Width, i, ++i);
accumulatedHeight += sz.Height;
curLineSize = new Size();
}
firstInLine = i;
}
else //continue to accumulate a line
{
curLineSize.Width += sz.Width;
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
}
}

if (firstInLine < children.Count)
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, children.Count);

return arrangeBounds;
}

private void ArrangeLine(double y, Size lineSize, double boundsWidth, int start, int end)
{
var x = HorizontalContentAlignment switch
{
HorizontalAlignment.Center => (boundsWidth - lineSize.Width) / 2,
HorizontalAlignment.Right => (boundsWidth - lineSize.Width),
_ => 0
};

var children = InternalChildren;
for (var i = start; i < end; i++)
{
var child = children[i];
child.Arrange(new Rect(x, y, child.DesiredSize.Width, lineSize.Height));
x += child.DesiredSize.Width;
}
}
}
25 changes: 25 additions & 0 deletions Converters/IsLastItemInContainerConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace LostArkTools.Converters;

public class IsLastItemInContainerConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
var item = (DependencyObject)value;
var ic = ItemsControl.ItemsControlFromItemContainer(item);
var index = ic.ItemContainerGenerator.IndexFromContainer(item);
return index == ic.Items.Count - 1;
}

public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
1 change: 1 addition & 0 deletions Features/Checklist/CharacterChecklist/CharacterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
KeyUp="{s:Action CharacterNameKeyPressed}"
Margin="5" />
<Button Grid.Column="1"
ToolTip="Delete Character"
Command="{s:Action DeleteCharacter}">
<iconPacks:BoxIcons Kind="SolidTrash" />
</Button>
Expand Down
76 changes: 36 additions & 40 deletions Features/ServerStatus/RegionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,50 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LostArkTools.Features.ServerStatus"
xmlns:controls="clr-namespace:LostArkTools.Controls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:RegionViewModel}"
d:DesignHeight="300" d:DesignWidth="300">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Name}"
HorizontalContentAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
FontWeight="Bold"
Foreground="{DynamicResource MahApps.Brushes.Accent}" />
<ItemsControl ItemsSource="{Binding Servers}"
AlternationCount="2"
Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="Border">
<Grid Margin="0 5 0 5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Width="15"
Height="15"
Margin="15 0 15 0"
Source="{Binding Value, Converter={StaticResource ServerStatusToPackIconImage}}" />
<TextBlock Grid.Column="1"
Text="{Binding Name}"
FontSize="13" />
</Grid>
</Border>
<DataTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Gray10}"
TargetName="Border" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Gray9}"
TargetName="Border" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Grid.Column="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="{DynamicResource MahApps.Brushes.Gray10}"
Margin="10 5 10 5"
BorderBrush="{DynamicResource MahApps.Brushes.Gray.SemiTransparent}"
BorderThickness="1">
<Grid Margin="0 5 0 5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Width="15"
Height="15"
Margin="15 0 15 0"
Source="{Binding Value, Converter={StaticResource ServerStatusToPackIconImage}}" />
<TextBlock Grid.Column="1"
Text="{Binding Name}"
FontSize="13"
Margin="0 0 15 0"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:AlignableWrapPanel HorizontalContentAlignment="Center"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
75 changes: 38 additions & 37 deletions Features/ServerStatus/ServerStatusView.xaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
<Grid x:Class="LostArkTools.Features.ServerStatus.ServerStatusView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LostArkTools.Features.ServerStatus"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:ServerStatusViewModel}"
d:DesignHeight="300" d:DesignWidth="300">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>


<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding Regions}"
Grid.Column="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LostArkTools.Features.ServerStatus"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:ServerStatusViewModel}"
d:DesignHeight="300" d:DesignWidth="300">
<ItemsControl ItemsSource="{Binding Regions}"
Margin="0 10 0 0"
Grid.Column="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ContentControl s:View.Model="{Binding}"
Margin="25 0 25 0"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Grid>
Margin="5 10 5 10" />
<Separator Grid.Row="1"
x:Name="Separator"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsLastItemInContainer}}"
Value="True">
<Setter TargetName="Separator" Property="Visibility" Value="Hidden"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>

0 comments on commit a5b2316

Please sign in to comment.