Skip to content

Commit

Permalink
Show what hub server was fetched from
Browse files Browse the repository at this point in the history
  • Loading branch information
Visne committed Aug 18, 2023
1 parent 7a475fd commit 7601746
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
13 changes: 13 additions & 0 deletions SS14.Launcher/Utility/HubUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace SS14.Launcher.Utility;

public static class HubUtility
{
public static string GetHubShortName(string hubAddress)
{
return Uri.TryCreate(hubAddress, UriKind.Absolute, out var uri)
? uri.Host
: hubAddress;
}
}
2 changes: 1 addition & 1 deletion SS14.Launcher/ViewModels/HubSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HubSettingsViewModel : ViewModelBase
{
public ObservableCollection<HubViewModel> HubList { get; set; } = new();

private readonly DataManager _dataManager = Locator.Current.GetRequiredService<DataManager>();
private readonly DataManager _dataManager = Locator.Current.GetRequiredService<DataManager>();

public void Save()
{
Expand Down
15 changes: 15 additions & 0 deletions SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Toolkit.Mvvm.Messaging;
using SS14.Launcher.Models.Data;
using SS14.Launcher.Models.ServerStatus;
using static SS14.Launcher.Utility.HubUtility;

namespace SS14.Launcher.ViewModels.MainWindowTabs;

Expand Down Expand Up @@ -132,6 +133,20 @@ public string FallbackName

public ServerStatusData CacheData => _cacheData;

public string? FetchedFrom
{
get
{
if (_cfg.Hubs.Count > 1)
{
return _cacheData.HubAddress == null ? null : $"Fetched from {GetHubShortName(_cacheData.HubAddress)}";
}

return null;
}
}
public bool ShowFetchedFrom => _cfg.Hubs.Count > 1 && !ViewedInFavoritesPane;

public void FavoriteButtonPressed()
{
if (IsFavorite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SS14.Launcher.Models.ServerStatus;
using SS14.Launcher.Utility;
using static SS14.Launcher.Api.ServerApi;
using static SS14.Launcher.Utility.HubUtility;

namespace SS14.Launcher.ViewModels.MainWindowTabs;

Expand Down Expand Up @@ -159,11 +160,7 @@ public void UpdatePresentFilters(IEnumerable<ServerStatusData> servers)
if (!alreadyAdded.Add(filter))
continue;

var shortName = Uri.TryCreate(hub, UriKind.Absolute, out var uri)
? uri.Host
: hub;

var vm = new ServerFilterViewModel(hub, shortName, filter, this);
var vm = new ServerFilterViewModel(hub, GetHubShortName(hub), filter, this);
filtersHub.Add(vm);
}
}
Expand Down
15 changes: 13 additions & 2 deletions SS14.Launcher/Views/MainWindowTabs/ServerEntryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@
</DockPanel>
</Expander.Header>
<DockPanel Margin="4">
<TextBlock DockPanel.Dock="Top" Name="Description" Margin="4,0,4,16"
Text="{Binding Description}" TextWrapping="Wrap" />
<TextBlock DockPanel.Dock="Top"
Name="Description" Margin="4,0,4,4"
Text="{Binding Description}"
TextWrapping="Wrap" />

<TextBlock DockPanel.Dock="Top"
Margin="4,0,4,4"
TextWrapping="Wrap"
Foreground="{DynamicResource ThemeSubTextBrush}"
Text="{Binding FetchedFrom}"
IsVisible="{Binding ShowFetchedFrom}" />

<Control DockPanel.Dock="Top" Height="8" />

<Grid DockPanel.Dock="Right" VerticalAlignment="Bottom" RowDefinitions="Auto,Auto">
<!-- Favorite add/remove button -->
Expand Down

0 comments on commit 7601746

Please sign in to comment.