Skip to content

Commit af0a729

Browse files
committed
release: Improve image loading + wait for initialization.
1 parent ffc993c commit af0a729

File tree

4 files changed

+57
-42
lines changed

4 files changed

+57
-42
lines changed

src/Flarial.Launcher/Controls/InitializationTypeBox.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ sealed class WaitForGlobalResources : ContentItem<bool?>
6161
internal override bool? Value => true;
6262
protected override string String => "Wait for global resources, safe & slow.";
6363
}
64-
6564
}
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Management.Automation;
23
using Flarial.Launcher.Xaml;
34
using Windows.UI.Core;
45
using Windows.UI.Xaml;
@@ -12,8 +13,8 @@ namespace Flarial.Launcher.Controls;
1213

1314
abstract class PromotionImageButton : XamlElement<Image>
1415
{
15-
protected abstract string? ImageUri { get; }
16-
protected abstract string? NavigateUri { get; }
16+
protected abstract string ImageUri { get; }
17+
protected abstract string NavigateUri { get; }
1718

1819
static readonly CoreCursor _hand = new(CoreCursorType.Hand, 0);
1920
static readonly CoreCursor _arrow = new(CoreCursorType.Arrow, 0);
@@ -22,21 +23,19 @@ protected PromotionImageButton() : base(new())
2223
{
2324
(~this).Width = 320 * 0.95;
2425
(~this).Height = 50 * 0.95;
25-
(~this).VerticalAlignment = VerticalAlignment.Bottom;
26+
(~this).Visibility = Visibility.Collapsed;
2627

27-
(~this).Source = new BitmapImage
28-
{
29-
DecodePixelType = DecodePixelType.Logical,
30-
UriSource = ImageUri is { } ? new(ImageUri) : null
31-
};
32-
33-
(~this).ImageOpened += OnImageOpened;
34-
(~this).PointerPressed += OnImagePointerPressed;
35-
36-
(~this).PointerEntered += OnImagePointerEntered;
28+
(~this).Tag = NavigateUri;
29+
(~this).ImageFailed += OnImageFailed;
3730
(~this).PointerExited += OnImagePointerExited;
31+
(~this).PointerEntered += OnImagePointerEntered;
32+
(~this).PointerPressed += OnImagePointerPressed;
3833

39-
(~this).Tag = NavigateUri;
34+
if (ImageUri is { })
35+
{
36+
(~this).Visibility = Visibility.Visible;
37+
(~this).Source = new BitmapImage { UriSource = new(ImageUri) };
38+
}
4039
}
4140

4241
unsafe static void OnImagePointerPressed(object sender, RoutedEventArgs args)
@@ -45,10 +44,8 @@ unsafe static void OnImagePointerPressed(object sender, RoutedEventArgs args)
4544
ShellExecute(Null, null, lpFile, null, null, SW_NORMAL);
4645
}
4746

48-
static void OnImageOpened(object sender, RoutedEventArgs args) => ((Image)sender).Visibility = Visibility.Visible;
49-
47+
static void OnImageFailed(object sender, RoutedEventArgs args) => ((Image)sender).Visibility = Visibility.Collapsed;
5048
static void OnImagePointerEntered(object sender, RoutedEventArgs args) => CoreWindow.GetForCurrentThread().PointerCursor = _hand;
51-
5249
static void OnImagePointerExited(object sender, RoutedEventArgs args) => CoreWindow.GetForCurrentThread().PointerCursor = _arrow;
5350
}
5451

@@ -64,15 +61,15 @@ sealed class LiteByteHostingImageButton : PromotionImageButton
6461
protected override string NavigateUri => "https://litebyte.co/minecraft?utm_source=flarial-client&utm_medium=app&utm_campaign=bedrock-launch";
6562
}
6663

64+
sealed class InfinityNetworkImageButton : PromotionImageButton
65+
{
66+
protected override string ImageUri => "https://assets.infinitymcpe.com/banner.png";
67+
protected override string NavigateUri => "https://discord.gg/infinitymcpe";
68+
}
69+
6770
[Obsolete("", true)]
6871
sealed class CollapseNetworkImageButton : PromotionImageButton
6972
{
7073
protected override string ImageUri => "https://collapsemc.com/assets/other/ad-banner.png";
7174
protected override string NavigateUri => "minecraft://?addExternalServer=Collapse|clps.gg:19132";
72-
}
73-
74-
sealed class InfinityNetworkImageButton : PromotionImageButton
75-
{
76-
protected override string ImageUri => "https://assets.infinitymcpe.com/banner.png";
77-
protected override string NavigateUri => "https://discord.gg/infinitymcpe";
7875
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Windows.UI.Xaml;
2+
using Windows.UI.Xaml.Controls;
3+
4+
namespace Flarial.Launcher.Controls;
5+
6+
sealed class PromotionImagesBox : Grid
7+
{
8+
readonly PromotionImageButton _left = new LiteByteHostingImageButton();
9+
readonly PromotionImageButton _middle = new StubImageButton();
10+
readonly PromotionImageButton _right = new InfinityNetworkImageButton();
11+
12+
internal PromotionImagesBox()
13+
{
14+
Margin = new(12);
15+
RowSpacing = 12;
16+
ColumnSpacing = 12;
17+
18+
ColumnDefinitions.Add(new() { Width = GridLength.Auto });
19+
ColumnDefinitions.Add(new() { Width = GridLength.Auto });
20+
ColumnDefinitions.Add(new() { Width = GridLength.Auto });
21+
22+
SetColumn(~_left, 0);
23+
SetColumn(~_middle, 1);
24+
SetColumn(~_right, 2);
25+
26+
Children.Add(~_left);
27+
Children.Add(~_right);
28+
Children.Add(~_middle);
29+
}
30+
}

src/Flarial.Launcher/Pages/HomePage.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ sealed class HomePage : Grid
2222
Width = 96,
2323
Height = 96,
2424
Margin = new(0, 0, 0, 90),
25+
Source = new BitmapImage(),
2526
VerticalAlignment = VerticalAlignment.Center,
26-
HorizontalAlignment = HorizontalAlignment.Center,
27-
Source = new BitmapImage { DecodePixelType = DecodePixelType.Logical }
27+
HorizontalAlignment = HorizontalAlignment.Center
2828
};
2929

3030
internal readonly Button _button = new()
@@ -56,10 +56,6 @@ sealed class HomePage : Grid
5656
readonly MainNavigationView _view;
5757
readonly ApplicationSettings _settings;
5858

59-
readonly PromotionImageButton _leftImageButton = new LiteByteHostingImageButton();
60-
readonly PromotionImageButton _centerImageButton = new StubImageButton();
61-
readonly PromotionImageButton _rightImageButton = new InfinityNetworkImageButton();
62-
6359
UnsupportedVersionDialog UnsupportedVersion
6460
{
6561
get
@@ -84,24 +80,17 @@ internal HomePage(MainNavigationView view, ApplicationSettings settings)
8480
logoBitmap.SetSource(stream.AsRandomAccessStream());
8581
}
8682

87-
(~_leftImageButton).Margin = new(12, 0, 0, 12);
88-
(~_leftImageButton).HorizontalAlignment = HorizontalAlignment.Left;
89-
90-
(~_centerImageButton).Margin = new(0, 0, 0, 12);
91-
(~_centerImageButton).HorizontalAlignment = HorizontalAlignment.Center;
92-
93-
(~_rightImageButton).Margin = new(0, 0, 12, 12);
94-
(~_rightImageButton).HorizontalAlignment = HorizontalAlignment.Right;
95-
9683
Children.Add(_leftText);
9784
Children.Add(_rightText);
9885

9986
Children.Add(_button);
10087
Children.Add(_logoImage);
10188

102-
Children.Add(~_leftImageButton);
103-
Children.Add(~_centerImageButton);
104-
Children.Add(~_rightImageButton);
89+
Children.Add(new PromotionImagesBox()
90+
{
91+
VerticalAlignment = VerticalAlignment.Bottom,
92+
HorizontalAlignment = HorizontalAlignment.Center
93+
});
10594

10695
_button.Click += OnButtonClick;
10796
}

0 commit comments

Comments
 (0)