Skip to content

Commit

Permalink
Use icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Visne committed Jan 3, 2024
1 parent 42c6586 commit 76c2680
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public bool IsExpanded
}

public string Name => Favorite?.Name ?? _cacheData.Name ?? _fallbackName;
public string FavoriteButtonText => IsFavorite ? "Remove Favorite" : "Add Favorite";
private bool IsFavorite => _cfg.FavoriteServers.Lookup(Address).HasValue;
public string FavoriteButtonText => IsFavorite ? "Unfavorite" : "Favorite";
public bool IsFavorite => _cfg.FavoriteServers.Lookup(Address).HasValue;

public bool ViewedInFavoritesPane { get; set; }

Expand Down
15 changes: 11 additions & 4 deletions SS14.Launcher/Views/MainWindowTabs/HomePageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mainWindowTabs="clr-namespace:SS14.Launcher.ViewModels.MainWindowTabs"
xmlns:views="clr-namespace:SS14.Launcher.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SS14.Launcher.Views.MainWindowTabs.HomePageView">
<Design.DataContext>
Expand All @@ -15,14 +16,20 @@

<!-- Favorites -->
<DockPanel DockPanel.Dock="Top" LastChildFill="False" Margin="4, 0, 4, 2">
<TextBlock DockPanel.Dock="Left" Text="Favorite Servers:" Classes="NanoHeadingMedium" />
<Button DockPanel.Dock="Right" Content="Add Favorite..." Classes="OpenLeft" Command="{Binding AddFavoritePressed}" />
<Button DockPanel.Dock="Right" Content="Refresh" Classes="OpenRight" Command="{Binding RefreshPressed}" />
<TextBlock DockPanel.Dock="Left" Text="Favorite Servers" Classes="NanoHeadingMedium" />
<Button DockPanel.Dock="Right" Classes="OpenLeft" Command="{Binding AddFavoritePressed}">
<views:IconLabel Icon="{DynamicResource ButtonIcon-plus}" Height="20" Width="20" />
<ToolTip.Tip>Add favorite server</ToolTip.Tip>
</Button>
<Button DockPanel.Dock="Right" Classes="OpenRight" Command="{Binding RefreshPressed}">
<views:IconLabel Icon="{DynamicResource ButtonIcon-refresh}" Height="20" Width="20" />
<ToolTip.Tip>Refresh</ToolTip.Tip>
</Button>
</DockPanel>

<DockPanel DockPanel.Dock="Bottom" LastChildFill="False" Margin="0, 5, 5, 1">
<Button DockPanel.Dock="Right" HorizontalAlignment="Right" Classes="OpenLeft"
Content="Direct Connect To Server..."
Content="Direct connect to server"
Command="{Binding DirectConnectPressed}" />
<Button DockPanel.Dock="Right" HorizontalAlignment="Right" Classes="OpenRight"
Content="Run content bundle/replay"
Expand Down
11 changes: 8 additions & 3 deletions SS14.Launcher/Views/MainWindowTabs/ServerEntryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@

<DockPanel Dock="Right">
<!-- Favorite add/remove button -->
<Button Classes="OpenRight"
Content="{Binding FavoriteButtonText}"
Command="{Binding FavoriteButtonPressed}" />
<Button Name="FavoriteButton"
Classes="OpenRight"
Command="{Binding FavoriteButtonPressed}">
<views:IconLabel Name="FavoriteButtonIconLabel"
Icon="{DynamicResource ButtonIcon-star}"
Content="{Binding FavoriteButtonText}"
Height="20" />
</Button>

<!-- Raise to top button. -->
<Button IsVisible="{Binding ViewedInFavoritesPane}"
Expand Down
35 changes: 33 additions & 2 deletions SS14.Launcher/Views/MainWindowTabs/ServerEntryView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,53 @@
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Serilog;
using SS14.Launcher.ViewModels.MainWindowTabs;

namespace SS14.Launcher.Views.MainWindowTabs;

public partial class ServerEntryView : UserControl
{
private readonly IImage _starIcon;
private readonly IImage _starOutlineIcon;

public ServerEntryView()
{
InitializeComponent();

Links.LayoutUpdated += ApplyStyle;
Links.LayoutUpdated += UpdateLinkButtons;
FavoriteButtonIconLabel.LayoutUpdated += UpdateFavoriteButton;

if (Application.Current?.FindResource("ButtonIcon-star") as IImage is not { } starIcon ||
Application.Current.FindResource("ButtonIcon-star-outline") as IImage is not { } starOutlineIcon)
{
throw new Exception("Failed to load favorite icons");
}

_starIcon = starIcon;
_starOutlineIcon = starOutlineIcon;
}

private void UpdateFavoriteButton(object? _1, EventArgs _2)
{
if (DataContext as ServerEntryViewModel is not { } context)
{
Log.Error($"Failed to get DataContext in {nameof(UpdateFavoriteButton)}");
return;
}

if (context.ViewedInFavoritesPane)
FavoriteButton.Classes.Add("OpenRight");
else
FavoriteButton.Classes.Remove("OpenRight");

FavoriteButtonIconLabel.Icon = context.IsFavorite ? _starIcon : _starOutlineIcon;
}

// Sets the style for the link buttons correctly so that they look correct
private void ApplyStyle(object? _1, EventArgs _2)
private void UpdateLinkButtons(object? _1, EventArgs _2)
{
for (var i = 0; i < Links.ItemCount; i++)
{
Expand Down
5 changes: 4 additions & 1 deletion SS14.Launcher/Views/MainWindowTabs/ServerListTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<DockPanel LastChildFill="True">

<DockPanel DockPanel.Dock="Bottom" Margin="4 4 4 0">
<Button DockPanel.Dock="Right" Content="Refresh" Command="{Binding RefreshPressed}" Classes="OpenLeft" />
<Button DockPanel.Dock="Right" Command="{Binding RefreshPressed}" Classes="OpenLeft">
<views:IconLabel Icon="{DynamicResource ButtonIcon-refresh}" Height="20" Width="20" />
<ToolTip.Tip>Refresh</ToolTip.Tip>
</Button>
<ToggleButton DockPanel.Dock="Right" IsChecked="{Binding FiltersVisible}" Classes="OpenRight">
<ToggleButton.Content>
<MultiBinding StringFormat="{}Filters ({0} / {1})">
Expand Down

0 comments on commit 76c2680

Please sign in to comment.