Skip to content

Commit

Permalink
添加加载器
Browse files Browse the repository at this point in the history
  • Loading branch information
d3ara1n committed Aug 4, 2024
1 parent eeb8cb9 commit e1bc5ad
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 24 deletions.
3 changes: 2 additions & 1 deletion changelogs/v0.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
- **修复**实例元数据中附件就地修改版本后立刻更新列表中同一个附件的版本
- **修复**账号能验证并刷新(#29)
- **修复**账号在保存和恢复中不再丢失部分信息
- **优化**在界面中引入部分亚克力元素来提升美感
- **优化**在界面中引入部分亚克力元素来提升美感
- **新增**元数据能在界面中检索并添加加载器
31 changes: 30 additions & 1 deletion src/Polymerium.App/Dialogs/AddLoaderDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:lab="using:CommunityToolkit.WinUI.Controls"
xmlns:local="using:Polymerium.App.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:Polymerium.App.Models"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
Title="Add loader dialog"
CloseButtonText="Cancel"
Expand All @@ -16,6 +17,34 @@
mc:Ignorable="d">

<StackPanel>
<AutoSuggestBox QueryIcon="Library" />
<AutoSuggestBox
x:Name="VersionBox"
ItemsSource="{x:Bind Versions}"
PlaceholderText="Loader version..."
QueryIcon="Library"
Text="{x:Bind SelectedVersion, Mode=TwoWay}"
TextChanged="VersionBox_TextChanged"
TextMemberPath="Version">
<AutoSuggestBox.ItemTemplate>
<DataTemplate x:DataType="models:LoaderVersionModel">
<toolkit:DockPanel>
<Border
toolkit:DockPanel.Dock="Right"
Background="{ThemeResource ControlAltFillColorSecondaryBrush}"
CornerRadius="3">
<TextBlock
Margin="6,4,6,4"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind Type}" />
</Border>
<TextBlock
FontWeight="{x:Bind Highlighted, Converter={StaticResource BoolToFontBoldConverter}}"
Foreground="{x:Bind Highlighted, Converter={StaticResource BoolToAccentTextBrushConverter}}"
Text="{x:Bind Version}" />
</toolkit:DockPanel>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
</StackPanel>
</ContentDialog>
41 changes: 41 additions & 0 deletions src/Polymerium.App/Dialogs/AddLoaderDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

using CommunityToolkit.WinUI.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Polymerium.App.Models;
using System.Collections.Generic;
using System.Linq;

namespace Polymerium.App.Dialogs
{
public sealed partial class AddLoaderDialog
{
private AdvancedCollectionView Versions { get; }

private string filter = string.Empty;



public string SelectedVersion
{
get { return (string)GetValue(SelectedVersionProperty); }
set { SetValue(SelectedVersionProperty, value); }
}

// Using a DependencyProperty as the backing store for SelectedVersion. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedVersionProperty =
DependencyProperty.Register(nameof(SelectedVersion), typeof(string), typeof(AddLoaderDialog), new PropertyMetadata(string.Empty));



public AddLoaderDialog(XamlRoot root, string identity, IEnumerable<LoaderVersionModel> versions)
{
XamlRoot = root;
InitializeComponent();

Versions = new AdvancedCollectionView(versions.OrderByDescending(x => x.ReleasedAt).ToList()) { Filter = Filter };
}

private bool Filter(object obj)
{
if (obj is LoaderVersionModel model)
{
return model.Version.Contains(filter);
}
return false;
}

private void VersionBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
filter = VersionBox.Text;
Versions.Refresh();
}
}
}
}
9 changes: 3 additions & 6 deletions src/Polymerium.App/Models/LoaderVersionModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Trident.Abstractions.Resources;

namespace Polymerium.App.Models
{
public record LoaderVersionModel(string Identity, string Version, DateTimeOffset ReleasedAt,bool Highlighted = false)
public record LoaderVersionModel(string Identity, string Version, DateTimeOffset ReleasedAt, ReleaseType Type, bool Highlighted = false)
{
}
}
}
9 changes: 2 additions & 7 deletions src/Polymerium.App/Tasks/UpdateTask.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Trident.Abstractions;
using Trident.Abstractions;

namespace Polymerium.App.Tasks;
public class UpdateTask : TaskBase
{
public UpdateTask(string key, Metadata metadata) : base(key, $"Updating {key}...", "Preparing")
{
}
}
}
2 changes: 1 addition & 1 deletion src/Polymerium.App/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void QuerySubmitted(string query)

private async Task UpdateInternal(Metadata metadata)
{
foreach(var layer in metadata.Layers)
foreach (var layer in metadata.Layers)
{
// TODO
}
Expand Down
19 changes: 14 additions & 5 deletions src/Polymerium.App/ViewModels/MetadataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ABI.System.Collections.Generic;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Dispatching;
using Polymerium.App.Modals;
Expand All @@ -9,9 +8,9 @@
using Polymerium.Trident.Engines;
using Polymerium.Trident.Extensions;
using Polymerium.Trident.Helpers;
using Polymerium.Trident.Models.PrismLauncher;
using Polymerium.Trident.Services;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -359,6 +358,7 @@ private async void DeleteLayer(LayerModel? layer)

public async Task<IEnumerable<LoaderVersionModel>> GetLoaderVersionsAsync(string identity)
{

var uid = identity switch
{
Loader.COMPONENT_FORGE => PrismLauncherHelper.UID_FORGE,
Expand All @@ -367,8 +367,17 @@ public async Task<IEnumerable<LoaderVersionModel>> GetLoaderVersionsAsync(string
Loader.COMPONENT_QUILT => PrismLauncherHelper.UID_QUILT,
_ => throw new ResourceIdentityUnrecognizedException(identity, nameof(Loader))
};
var manifest = await PrismLauncherHelper.GetManifestAsync(uid, _httpClientFactory);
return manifest.Versions.Select(x => new LoaderVersionModel(identity, x.Version, x.ReleaseTime, x.Recommended));
var manifesta = await PrismLauncherHelper.GetManifestAsync(uid, _httpClientFactory);
return manifesta.Versions.Where(x => x.Requires.Any(y => y.Uid == PrismLauncherHelper.UID_INTERMEDIARY || (y.Uid == PrismLauncherHelper.UID_MINECRAFT && (y.Equal == model.Inner.Metadata.Version || y.Suggest == model.Inner.Metadata.Version)))).Select(x => new LoaderVersionModel(identity, x.Version, x.ReleaseTime, x.Type switch
{
PrismReleaseType.Release => ReleaseType.Release,
PrismReleaseType.Snapshot => ReleaseType.Snapshot,
PrismReleaseType.Old_Snapshot => ReleaseType.Snapshot,
PrismReleaseType.Experiment => ReleaseType.Experiment,
PrismReleaseType.Old_Alpha => ReleaseType.Alpha,
PrismReleaseType.Old_Beta => ReleaseType.Beta,
_ => throw new NotImplementedException()
}, x.Recommended));
}
}
}
7 changes: 5 additions & 2 deletions src/Polymerium.App/Views/MetadataView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,18 @@
<SplitButton
Grid.Column="4"
Command="{x:Bind ViewModel.GotoWorkbenchViewCommand}"
CommandParameter="{x:Bind ViewModel.SelectedLayer.IsLocked.Value, Mode=OneWay}"
Content="Get More">
CommandParameter="{x:Bind ViewModel.SelectedLayer.IsLocked.Value, Mode=OneWay}">
<SplitButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Bulk Update" />
<MenuFlyoutItem Text="View Changelog" />
<MenuFlyoutItem Text="Export List" />
</MenuFlyout>
</SplitButton.Flyout>
<StackPanel Orientation="Horizontal" Spacing="5">
<FontIcon FontSize="{StaticResource ButtonFontIconFontSize}" Glyph="&#xF133;" />
<TextBlock Text="Get" />
</StackPanel>
</SplitButton>
</Grid>
<toolkit:SwitchPresenter TargetType="models:DataLoadingState" Value="{x:Bind ViewModel.AttachmentLoadingState, Mode=OneWay}">
Expand Down
5 changes: 4 additions & 1 deletion src/Polymerium.App/Views/MetadataView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ private void AddLoader(string identity)
{
VersionLoadingState = DataLoadingState.Idle;
var dialog = new AddLoaderDialog(XamlRoot, identity, versions);
await dialog.ShowAsync();
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
{
ViewModel.SelectedLayer?.Loaders.Add(new LoaderModel(new Loader(identity, dialog.SelectedVersion), ViewModel.SelectedLayer.RemoveLoaderCommand));
}
});
});

Expand Down

0 comments on commit e1bc5ad

Please sign in to comment.