RetroGamingAppPage.xaml.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Threading.Tasks;
  4. using Avalonia;
  5. using Avalonia.Animation;
  6. using Avalonia.Controls;
  7. using Avalonia.Interactivity;
  8. using Avalonia.Media;
  9. namespace ControlCatalog.Pages;
  10. public partial class RetroGamingAppPage : UserControl
  11. {
  12. static readonly Color BgColor = Color.Parse("#120a1f");
  13. static readonly Color SurfaceColor = Color.Parse("#2d1b4e");
  14. static readonly Color CyanColor = Color.Parse("#00ffff");
  15. static readonly Color YellowColor = Color.Parse("#ffff00");
  16. static readonly Color MutedColor = Color.Parse("#7856a8");
  17. static readonly Color TextColor = Color.Parse("#e0d0ff");
  18. NavigationPage? _nav;
  19. ScrollViewer? _infoPanel;
  20. public RetroGamingAppPage()
  21. {
  22. InitializeComponent();
  23. _nav = this.FindControl<NavigationPage>("RetroNav");
  24. if (_nav != null)
  25. _ = _nav.PushAsync(BuildHomePage());
  26. }
  27. protected override void OnLoaded(RoutedEventArgs e)
  28. {
  29. base.OnLoaded(e);
  30. _infoPanel = this.FindControl<ScrollViewer>("InfoPanel");
  31. UpdateInfoPanelVisibility();
  32. }
  33. protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
  34. {
  35. base.OnPropertyChanged(change);
  36. if (change.Property == BoundsProperty)
  37. UpdateInfoPanelVisibility();
  38. }
  39. void UpdateInfoPanelVisibility()
  40. {
  41. if (_infoPanel != null)
  42. _infoPanel.IsVisible = Bounds.Width >= 650;
  43. }
  44. ContentPage BuildHomePage()
  45. {
  46. var page = new ContentPage { Background = new SolidColorBrush(BgColor) };
  47. page.Header = BuildPixelArcadeLogo();
  48. NavigationPage.SetTopCommandBar(page, BuildNavBarRight());
  49. var panel = new Panel();
  50. panel.Children.Add(BuildHomeTabbedPage());
  51. panel.Children.Add(BuildSearchFab());
  52. page.Content = panel;
  53. return page;
  54. }
  55. static Control BuildPixelArcadeLogo()
  56. {
  57. var row = new StackPanel
  58. {
  59. Orientation = Avalonia.Layout.Orientation.Horizontal,
  60. Spacing = 10,
  61. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
  62. };
  63. var iconPanel = new Grid { Width = 36, Height = 30 };
  64. iconPanel.Children.Add(new Border
  65. {
  66. Width = 36, Height = 20, CornerRadius = new CornerRadius(3),
  67. Background = new SolidColorBrush(Color.Parse("#cc44dd")),
  68. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Bottom,
  69. });
  70. iconPanel.Children.Add(new Border
  71. {
  72. Width = 9, Height = 9,
  73. Background = new SolidColorBrush(SurfaceColor),
  74. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left,
  75. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Bottom,
  76. Margin = new Thickness(4, 0, 0, 6),
  77. });
  78. iconPanel.Children.Add(new Border
  79. {
  80. Width = 9, Height = 9,
  81. Background = new SolidColorBrush(SurfaceColor),
  82. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
  83. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Bottom,
  84. Margin = new Thickness(0, 0, 4, 6),
  85. });
  86. row.Children.Add(iconPanel);
  87. var textStack = new StackPanel { Spacing = 1 };
  88. textStack.Children.Add(new TextBlock
  89. {
  90. Text = "PIXEL",
  91. FontFamily = new FontFamily("Courier New, monospace"),
  92. FontSize = 14, FontWeight = FontWeight.Bold,
  93. Foreground = new SolidColorBrush(YellowColor), LineHeight = 16,
  94. });
  95. textStack.Children.Add(new TextBlock
  96. {
  97. Text = "ARCADE",
  98. FontFamily = new FontFamily("Courier New, monospace"),
  99. FontSize = 14, FontWeight = FontWeight.Bold,
  100. Foreground = new SolidColorBrush(YellowColor), LineHeight = 16,
  101. });
  102. row.Children.Add(textStack);
  103. return row;
  104. }
  105. static Control BuildNavBarRight()
  106. {
  107. var row = new StackPanel
  108. {
  109. Orientation = Avalonia.Layout.Orientation.Horizontal,
  110. Spacing = 10,
  111. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
  112. Margin = new Thickness(0, 0, 8, 0),
  113. };
  114. row.Children.Add(new PathIcon
  115. {
  116. Width = 16, Height = 16,
  117. Foreground = new SolidColorBrush(TextColor),
  118. Data = Geometry.Parse("M12 22c1.1 0 2-.9 2-2h-4c0 1.1.9 2 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z"),
  119. });
  120. var avatar = new Border
  121. {
  122. Width = 26, Height = 26,
  123. CornerRadius = new CornerRadius(0),
  124. ClipToBounds = true,
  125. Background = new SolidColorBrush(SurfaceColor),
  126. BorderBrush = new SolidColorBrush(MutedColor),
  127. BorderThickness = new Thickness(1),
  128. };
  129. avatar.Child = new TextBlock
  130. {
  131. Text = "P1",
  132. FontFamily = new FontFamily("Courier New, monospace"),
  133. FontSize = 7, FontWeight = FontWeight.Bold,
  134. Foreground = new SolidColorBrush(CyanColor),
  135. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
  136. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
  137. };
  138. row.Children.Add(avatar);
  139. return row;
  140. }
  141. TabbedPage BuildHomeTabbedPage()
  142. {
  143. var tp = new TabbedPage
  144. {
  145. Background = new SolidColorBrush(BgColor),
  146. TabPlacement = TabPlacement.Bottom,
  147. PageTransition = new PageSlide(TimeSpan.FromMilliseconds(250)),
  148. };
  149. tp.Resources["TabItemHeaderFontSize"] = 12.0;
  150. tp.Resources["TabbedPageTabStripBackground"] = new SolidColorBrush(SurfaceColor);
  151. tp.Resources["TabbedPageTabItemHeaderForegroundSelected"] = new SolidColorBrush(Color.Parse("#ad2bee"));
  152. tp.Resources["TabbedPageTabItemHeaderForegroundUnselected"] = new SolidColorBrush(MutedColor);
  153. var homeView = new RetroGamingHomeView();
  154. homeView.GameSelected = PushDetailPage;
  155. var homeTab = new ContentPage
  156. {
  157. Header = "Home",
  158. Icon = new PathIcon { Data = Geometry.Parse("M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z") },
  159. Background = new SolidColorBrush(BgColor),
  160. Content = homeView,
  161. };
  162. var gamesView = new RetroGamingGamesView();
  163. gamesView.GameSelected = PushDetailPage;
  164. var gamesTab = new ContentPage
  165. {
  166. Header = "Games",
  167. Icon = new PathIcon { Data = Geometry.Parse("M7.97,16L5,19C4.67,19.3 4.23,19.5 3.75,19.5A1.75,1.75 0 0,1 2,17.75V17.5L3,10.12C3.21,7.81 5.14,6 7.5,6H16.5C18.86,6 20.79,7.81 21,10.12L22,17.5V17.75A1.75,1.75 0 0,1 20.25,19.5C19.77,19.5 19.33,19.3 19,19L16.03,16H7.97M7,9V11H5V13H7V15H9V13H11V11H9V9H7M14.5,12A1.5,1.5 0 0,0 13,13.5A1.5,1.5 0 0,0 14.5,15A1.5,1.5 0 0,0 16,13.5A1.5,1.5 0 0,0 14.5,12M17.5,9A1.5,1.5 0 0,0 16,10.5A1.5,1.5 0 0,0 17.5,12A1.5,1.5 0 0,0 19,10.5A1.5,1.5 0 0,0 17.5,9Z") },
  168. Background = new SolidColorBrush(BgColor),
  169. Content = gamesView,
  170. };
  171. var favTab = new ContentPage
  172. {
  173. Header = "Favorites",
  174. Icon = new PathIcon { Data = Geometry.Parse("M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z") },
  175. Background = new SolidColorBrush(BgColor),
  176. Content = new RetroGamingFavoritesView(),
  177. };
  178. var profileTab = new ContentPage
  179. {
  180. Header = "Profile",
  181. Icon = new PathIcon { Data = Geometry.Parse("M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z") },
  182. Background = new SolidColorBrush(BgColor),
  183. Content = new RetroGamingProfileView(),
  184. };
  185. tp.Pages = new ObservableCollection<Page> { homeTab, gamesTab, favTab, profileTab };
  186. return tp;
  187. }
  188. Control BuildSearchFab()
  189. {
  190. var fab = new Button
  191. {
  192. Width = 50, Height = 50,
  193. CornerRadius = new CornerRadius(0),
  194. Background = new SolidColorBrush(YellowColor),
  195. Padding = new Thickness(0),
  196. };
  197. fab.Classes.Add("retro-fab");
  198. fab.Content = new PathIcon
  199. {
  200. Width = 22, Height = 22,
  201. Foreground = new SolidColorBrush(BgColor),
  202. Data = Geometry.Parse("M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"),
  203. };
  204. fab.Click += (_, _) => _ = _nav?.PushModalAsync(BuildSearchModal());
  205. return new Border
  206. {
  207. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
  208. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Bottom,
  209. Margin = new Thickness(0, 0, 0, 35),
  210. BoxShadow = new BoxShadows(new BoxShadow
  211. {
  212. Blur = 10, Spread = 1,
  213. Color = Color.FromArgb(140, 255, 255, 0),
  214. }),
  215. Child = fab,
  216. };
  217. }
  218. ContentPage BuildSearchModal()
  219. {
  220. var page = new ContentPage { Background = new SolidColorBrush(BgColor) };
  221. var searchView = new RetroGamingSearchView();
  222. searchView.CloseRequested = () => _ = _nav?.PopModalAsync();
  223. searchView.GameSelected = async title =>
  224. {
  225. await (_nav?.PopModalAsync() ?? System.Threading.Tasks.Task.CompletedTask);
  226. PushDetailPage(title);
  227. };
  228. page.Content = searchView;
  229. return page;
  230. }
  231. async void PushDetailPage(string gameTitle)
  232. {
  233. if (_nav == null) return;
  234. var detailView = new RetroGamingDetailView(gameTitle);
  235. var page = new ContentPage
  236. {
  237. Background = new SolidColorBrush(BgColor),
  238. Content = detailView,
  239. };
  240. NavigationPage.SetBarLayoutBehavior(page, BarLayoutBehavior.Overlay);
  241. page.NavigatedTo += (_, _) => { if (_nav != null) _nav.Resources["NavigationBarBackground"] = Brushes.Transparent; };
  242. page.NavigatedFrom += (_, _) => { if (_nav != null) _nav.Resources["NavigationBarBackground"] = new SolidColorBrush(SurfaceColor); };
  243. var cmdBar = new StackPanel
  244. {
  245. Orientation = Avalonia.Layout.Orientation.Horizontal,
  246. Spacing = 4,
  247. VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
  248. Margin = new Thickness(0, 0, 8, 0),
  249. };
  250. var heartBtn = new Button();
  251. heartBtn.Classes.Add("retro-icon-btn");
  252. heartBtn.Content = new PathIcon
  253. {
  254. Width = 16, Height = 16,
  255. Foreground = new SolidColorBrush(Color.Parse("#ad2bee")),
  256. Data = Geometry.Parse("M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"),
  257. };
  258. var shareBtn = new Button();
  259. shareBtn.Classes.Add("retro-icon-btn");
  260. shareBtn.Content = new PathIcon
  261. {
  262. Width = 16, Height = 16,
  263. Foreground = new SolidColorBrush(TextColor),
  264. Data = Geometry.Parse("M18,16.08C17.24,16.08 16.56,16.38 16.04,16.85L8.91,12.7C8.96,12.47 9,12.24 9,12C9,11.76 8.96,11.53 8.91,11.3L15.96,7.19C16.5,7.69 17.21,8 18,8A3,3 0 0,0 21,5A3,3 0 0,0 18,2A3,3 0 0,0 15,5C15,5.24 15.04,5.47 15.09,5.7L8.04,9.81C7.5,9.31 6.79,9 6,9A3,3 0 0,0 3,12A3,3 0 0,0 6,15C6.79,15 7.5,14.69 8.04,14.19L15.16,18.35C15.11,18.56 15.08,18.78 15.08,19C15.08,20.61 16.39,21.92 18,21.92C19.61,21.92 20.92,20.61 20.92,19C20.92,17.39 19.61,16.08 18,16.08Z"),
  265. };
  266. cmdBar.Children.Add(heartBtn);
  267. cmdBar.Children.Add(shareBtn);
  268. NavigationPage.SetTopCommandBar(page, cmdBar);
  269. await _nav.PushAsync(page);
  270. }
  271. }