Skip to content

Commit

Permalink
NewsPage UI & NotificationService PART
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Aug 4, 2023
1 parent b86e812 commit c4a4384
Show file tree
Hide file tree
Showing 17 changed files with 273 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nrk.FluentCore.Classes.Datas.Authenticate;
using Nrk.FluentCore.Classes.Datas.Launch;
using Nrk.FluentCore.Classes.Datas.Parse;
using Nrk.FluentCore.Classes.Enums;
using Nrk.FluentCore.Components.Launch;
using Nrk.FluentCore.DefaultComponets.Parse;
using Nrk.FluentCore.Utils;
Expand Down Expand Up @@ -78,7 +79,7 @@ public override IEnumerable<string> Build()
{ "${auth_access_token}" , _account.AccessToken },
{ "${auth_session}" , _account.AccessToken },
{ "${auth_uuid}" ,_account.Uuid.ToString("N") },
{ "${user_type}" , "Mojang" },
{ "${user_type}" , _account.Type.Equals(AccountType.Microsoft) ? "MSA" : "Mojang" },
{ "${user_properties}" , "{}" },
{ "${version_name}" , GameInfo.AbsoluteId },
{ "${version_type}" , GameInfo.Type },
Expand Down
2 changes: 1 addition & 1 deletion Natsurainko.FluentCore (v4)/Utils/MemoryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static (int, int) CalculateJavaMemory(int min = 512)
: GetUnixMetrics();
#pragma warning restore CA1416

var willUsed = (metrics.Free / 1024) * 0.6;
var willUsed = metrics.Free * 0.6;
var max = willUsed < min ? min : Convert.ToInt32(willUsed);

return (max, min);
Expand Down
4 changes: 2 additions & 2 deletions Natsurainko.FluentLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<SolidColorBrush x:Key="DeleteButtonBackground" Color="#BFCC0000" />
<SolidColorBrush x:Key="DeleteButtonBorder" Color="#BFCC0000" />
<x:Double x:Key="ExpanderSplitterOpacity">1</x:Double>
<SolidColorBrush x:Key="AntiTheme" Color="Black" />
<Color x:Key="AcrylicTintColor">White</Color>
<SolidColorBrush x:Key="IconBorder" Color="#25000000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="DeleteButtonBackground" Color="#3FFF0000" />
<SolidColorBrush x:Key="DeleteButtonBorder" Color="#59FF0000" />
<x:Double x:Key="ExpanderSplitterOpacity">0.1</x:Double>
<SolidColorBrush x:Key="AntiTheme" Color="White" />
<Color x:Key="AcrylicTintColor">Black</Color>
<SolidColorBrush x:Key="IconBorder" Color="#10FFFFFF" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public override void RunLaunch()

throw;
}

}

private void McProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
Expand Down
43 changes: 36 additions & 7 deletions Natsurainko.FluentLauncher/Dictionaries/NotifyStyleDictionary.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Natsurainko.FluentLauncher.Views">
xmlns:behaviors="using:Natsurainko.FluentLauncher.Utils.Xaml.Behaviors"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:Natsurainko.FluentLauncher.Views"
xmlns:media="using:CommunityToolkit.WinUI.UI.Media">
<DataTemplate x:Key="NotifyPresenterTemplate">
<Border
MinWidth="100"
MinHeight="75"
MaxWidth="500"
MaxHeight="300"
Background="{ThemeResource SystemControlAcrylicElementBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="8">
<Border.Background>
<AcrylicBrush
TintColor="{ThemeResource AcrylicTintColor}"
TintLuminosityOpacity="0.25"
TintOpacity="0.25" />
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -45,18 +52,36 @@
Command="{Binding CloseCommand}"
Style="{ThemeResource AlternateCloseButtonStyle}" />
</Grid>
<ScrollViewer Grid.Row="2" Content="{Binding NotifyContent}" />
<ContentControl
Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{Binding NotifyContent}" />
</Grid>
</Border>
</DataTemplate>

<DataTemplate x:Key="NormalMessageNotifyTemplate">
<ScrollViewer>
<StackPanel Padding="20,0" Spacing="5">
<TextBlock Text="{Binding Text}" />
<TextBlock
Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}"
Style="{ThemeResource CaptionTextBlockStyle}"
Text="{Binding Description}" />
</StackPanel>
</ScrollViewer>
</DataTemplate>

<DataTemplate x:Key="AuthenticationSuccessfulNotifyTemplate">
<StackPanel Padding="20,0" Spacing="5">
<TextBlock FontWeight="SemiBold">
<Run Text="Welcome Back," />
<Run Text="{Binding Name}" />
</TextBlock>
<ListViewItem Margin="-10,0" Padding="10,10">
<ListViewItem Margin="-10,0" Padding="20,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand All @@ -68,12 +93,16 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Image
<Border
Grid.RowSpan="2"
Grid.Column="0"
Width="32"
Height="32"
Source="/Assets/Icons/steve.png" />
CornerRadius="4">
<i:Interaction.Behaviors>
<behaviors:SkinHeadControlBehavior Account="{Binding}" />
</i:Interaction.Behaviors>
</Border>
<TextBlock
Grid.Row="0"
Grid.Column="2"
Expand Down
2 changes: 1 addition & 1 deletion Natsurainko.FluentLauncher/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="26553XcubeStudio.Natsurianko.FluentLauncher"
Publisher="CN=053EFB0E-6705-4A11-94B9-980C4C9E0047"
Version="2.1.16.0" />
Version="2.1.17.0" />

<Properties>
<DisplayName>Natsurianko.FluentLauncher</DisplayName>
Expand Down
17 changes: 0 additions & 17 deletions Natsurainko.FluentLauncher/Services/Data/CurseForgeCategoryData.cs

This file was deleted.

48 changes: 0 additions & 48 deletions Natsurainko.FluentLauncher/Services/Data/CurseForgeResourceData.cs

This file was deleted.

3 changes: 3 additions & 0 deletions Natsurainko.FluentLauncher/Services/Launch/LaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class LaunchService : DefaultLaunchService
private readonly AuthenticationService _authenticationService;
private readonly new SettingsService _settingsService;
private readonly new AccountService _accountService;
private readonly new GameService _gameService;
private readonly ObservableCollection<LaunchProcess> _launchProcesses = new();
private readonly DownloadService _downloadService;

Expand All @@ -44,6 +45,7 @@ public LaunchService(
_authenticationService = authenticationService;
_settingsService = settingsService;
_downloadService = downloadService;
_gameService = gameService;

LaunchProcesses = new(_launchProcesses);
}
Expand Down Expand Up @@ -132,6 +134,7 @@ public void LaunchNewGame(GameInfo gameInfo)
var launchTime = DateTime.Now;
specialConfig.LastLaunchTime = launchTime;
_gameService.GameInfos.Where(x => x.Equals(gameInfo)).FirstOrDefault().LastLaunchTime = launchTime;
(gameInfo as ExtendedGameInfo).LastLaunchTime = launchTime;
return new Process
Expand Down
47 changes: 36 additions & 11 deletions Natsurainko.FluentLauncher/Services/UI/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class NotificationService
private StackPanel _itemsContainer;
private Grid _shadowReceiver;
private ThemeShadow _themeShadow;
private int _nextItemZIndex = 1;

public void InitContainer(StackPanel itemsContainer, Grid shadowReceiver)
{
Expand All @@ -22,48 +23,66 @@ public void InitContainer(StackPanel itemsContainer, Grid shadowReceiver)
_themeShadow.Receivers.Add(shadowReceiver);
}

public void NotifyMessage(string title, string text, string description = "", string icon = "\uE7E7", int delay = 5000)
{
NotifyWithSpecialContent(title, "NormalMessageNotifyTemplate", new
{
Text = text,
Description = description
}, icon, delay);
}

public void NotifyWithSpecialContent(string title, string contentTemplateKey, object contentDataContext, string icon = "\uE7E7", int delay = 5000)
{
_itemsContainer.Children.Add(CreateNotifyPresenter(
_itemsContainer.Children.Insert(0, CreateNotifyPresenter(
title, contentTemplateKey, contentDataContext, icon, delay));
}

private ContentPresenter CreateNotifyPresenter(string title, string contentTemplateKey, object contentDataContext, string icon = "\uE7E7", int delay = 5000)
{
var translateTransform = new TranslateTransform() { X = 500 };
var translateTransform = new TranslateTransform() { Y = -125 };
var popupAnimation = CreatePopupAnimation(translateTransform);

var contentPresenter = new ContentPresenter
{
CornerRadius = new CornerRadius(8),
ContentTemplate = (DataTemplate)App.Current.Resources["NotifyPresenterTemplate"],
Shadow = _themeShadow,
RenderTransform = translateTransform
RenderTransform = translateTransform,
MaxWidth = 500,
};

Canvas.SetZIndex(contentPresenter, _nextItemZIndex);
_nextItemZIndex++;

contentPresenter.Translation += new System.Numerics.Vector3(0, 0, 48);

async void ContentPresenter_Loaded(object sender, RoutedEventArgs e)
{
contentPresenter.Loaded -= ContentPresenter_Loaded;
popupAnimation.Begin();

var notifyPresenterViewModel = new NotifyPresenterViewModel
{
Icon = icon,
NotifyTitile = title,
NotifyContent = CreateNotifyContent(contentTemplateKey, contentDataContext),
Remove = () => _itemsContainer.Children.Remove(contentPresenter),
RetractAnimation = CreateRetractAnimation(translateTransform)
CreateRetractAnimationAction = () => CreateRetractAnimation(translateTransform),
Remove = () =>
{
_itemsContainer.Children.Remove(contentPresenter);
OnRemovedItem();
},
};
contentPresenter.DataContext = notifyPresenterViewModel;

await Task.Delay(delay);
await notifyPresenterViewModel.Close();

contentPresenter.Loaded -= ContentPresenter_Loaded;
if (!notifyPresenterViewModel._removed)
await notifyPresenterViewModel.Close();
}
contentPresenter.Loaded += ContentPresenter_Loaded;

contentPresenter.Loaded += ContentPresenter_Loaded;
return contentPresenter;
}

Expand Down Expand Up @@ -93,7 +112,7 @@ private Storyboard CreatePopupAnimation(TranslateTransform transform)

storyboard.Children.Add(doubleAnimation);
Storyboard.SetTarget(doubleAnimation, transform);
Storyboard.SetTargetProperty(storyboard, "X");
Storyboard.SetTargetProperty(storyboard, "Y");

return storyboard;
}
Expand All @@ -102,13 +121,19 @@ private Storyboard CreateRetractAnimation(TranslateTransform transform)
{
var storyboard = new Storyboard();
var doubleAnimation = new DoubleAnimation();
doubleAnimation.To = 500;
doubleAnimation.To = -_itemsContainer.ActualHeight - 75;
doubleAnimation.EasingFunction = new CircleEase();

storyboard.Children.Add(doubleAnimation);
Storyboard.SetTarget(doubleAnimation, transform);
Storyboard.SetTargetProperty(storyboard, "X");
Storyboard.SetTargetProperty(storyboard, "Y");

return storyboard;
}

private void OnRemovedItem()
{
if (_itemsContainer.Children.Count == 0)
_nextItemZIndex = 1;
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit c4a4384

Please sign in to comment.