Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

304 port UI to blazor proof of concept #308

Merged
merged 59 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
77279bd
Add a Razor class library but for some reason the Razor component can…
ekolis Feb 17, 2024
289cbfa
Add HTML boilerplate
ekolis Feb 17, 2024
521a392
Rename FrEee.WinForms to FrEee.UI.WinForms
ekolis Feb 18, 2024
c82cf84
Update namespaces
ekolis Feb 18, 2024
6649c9f
Update project/solutoin
ekolis Feb 18, 2024
2a7d4fc
Undo some accidentally committed changes
ekolis Feb 18, 2024
4d57c72
Blazorified the GameProgressBar
ekolis Feb 24, 2024
3f3c06f
Adjust styling
ekolis Feb 24, 2024
ff5d8ea
Don't allow progress bar to overflow
ekolis Feb 24, 2024
b1dd595
Set up the new font thingy, not using it yet because I haven't found …
ekolis Feb 24, 2024
4581f77
Fix right text of progress bar not getting set
ekolis Feb 24, 2024
3078993
Fix crashing when refreshing progress bar
ekolis Feb 25, 2024
5fa2033
comments for things to clean up
ekolis Feb 25, 2024
7a3d828
Wrap view model properties without having useless local fields
ekolis Feb 25, 2024
4d7bdca
Move some code from WinForms to the Blazor view model
ekolis Mar 3, 2024
403b8b2
Fix crash when calling a WinForms modal dialog from Blazor while debu…
ekolis Mar 3, 2024
3dfea0d
Remove references to nonexitent FrEee.UI project
ekolis Mar 9, 2024
318f9d3
Add comment, that's weird that it's inconsistent
ekolis Mar 9, 2024
d2e59b0
Fix progress bar not refreshing again
ekolis Mar 9, 2024
312727d
Add resource display but it's broken. Also added Blazor test form.
ekolis Mar 9, 2024
07b7e7b
Actually render the Blazor view in the resource display
ekolis Mar 10, 2024
641abbf
Try to fix the resource displays' colors and icons but not quite. Ico…
ekolis Mar 10, 2024
0f7b6b2
Fixed resource displays (hopefully the symlinks will persist in the b…
ekolis Mar 10, 2024
9d8d934
Fix Blazor image path issue by moving index.html to the root. This fe…
ekolis Mar 10, 2024
c0bbce8
Delete empty wwwroot folder
ekolis Mar 10, 2024
497ebb5
Install a couple NuGet packages to fix inability to put Blazor-based …
ekolis Mar 16, 2024
f5ac3f4
Combine multile ResourceDisplays into a ResourceQuantityDisplay
ekolis Mar 16, 2024
a1d5c26
Refactor some code into a base BlazorControl
ekolis Mar 17, 2024
f4045b6
Remove unneeded analytics packages and a using statement
ekolis Mar 17, 2024
e127e9f
Adjust a few things in the BlazorControl
ekolis Mar 17, 2024
71defb2
Get rid of a generic type parameter, somehow partially fix resource d…
ekolis Mar 17, 2024
6285af2
Get rid of the other generic type parameter for BlazorControl
ekolis Mar 17, 2024
e0fc416
Fix BlazorWebView based controls in WinForms designer by using some s…
ekolis Mar 17, 2024
97a9a24
Fix resource inventory display
ekolis Mar 17, 2024
cfe8f60
Delerte an unused method
ekolis Mar 17, 2024
9b9e6b4
Move controls that have been converted to Blazor to their own namespa…
ekolis Mar 17, 2024
61caecb
Adjust namespaces of moved controls
ekolis Mar 17, 2024
7383ef8
Moved the wrong control oops
ekolis Mar 17, 2024
042f3e8
GamePictureBox is now Blazor; for some reason there's a scvroll bar
ekolis Mar 17, 2024
7441c71
Actually show text on full size GamePictureBox forms
ekolis Mar 17, 2024
7723a07
Display name of Blazor control in WinForms designer
ekolis Mar 17, 2024
4acdbc8
Add a pie chart Blazor component, the HTML checks out in a browser bu…
ekolis Mar 30, 2024
85a8d6b
Fix pie chart rendering
ekolis Mar 30, 2024
4491642
Blazor galaxy map WIP
ekolis Mar 30, 2024
9c5a374
Somewhat fix layout of galaxy map, somewhat break that of resource di…
ekolis Mar 31, 2024
305464a
Fix image alignment/sizing
ekolis Mar 31, 2024
b953961
Implement presence map mode
ekolis Mar 31, 2024
44388df
Set up MEF and dropdown for galaxy map modes
ekolis Mar 31, 2024
722b853
Trying to draw warp lines
ekolis Mar 31, 2024
1ced0a2
Draw warp lines, but they're scaled wrong
ekolis Mar 31, 2024
9756e4e
Delete unused function
ekolis Mar 31, 2024
624d1d2
Cleaning up the map, add green grid because green grids are cool
ekolis Mar 31, 2024
f7cc423
Don't place star systems off the lower or right edges of the map
ekolis Mar 31, 2024
da131bb
Fixed map rendering
ekolis Mar 31, 2024
80e4526
Render the selected star system with a white border
ekolis Apr 7, 2024
18abc2f
Clicking a system actually selects it
ekolis Apr 7, 2024
2184af8
Get rid of background click handler for galaxy map because it's causi…
ekolis Apr 7, 2024
ca9cedd
Fix numbers being hidden on the resourve display
ekolis Apr 21, 2024
c251d5e
Fix vertical alignment of resource display text
ekolis Apr 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions FrEee.Assets/FrEee.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<None Update="Fonts\kwajong-readme.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fonts\Kwajong.otf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup>
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
Expand Down
3 changes: 3 additions & 0 deletions FrEee.UI.Blazor/Component1.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="my-component">
This component is defined in the <strong>FrEee.UI.Blazor</strong> library.
</div>
6 changes: 6 additions & 0 deletions FrEee.UI.Blazor/Component1.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.my-component {
border: 2px dashed red;
padding: 1em;
margin: 1em 0;
background-image: url('background.png');
}
37 changes: 37 additions & 0 deletions FrEee.UI.Blazor/ExampleJsInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.JSInterop;

namespace FrEee.UI.Blazor
{
// This class provides an example of how JavaScript functionality can be wrapped
// in a .NET class for easy consumption. The associated JavaScript module is
// loaded on demand when first needed.
//
// This class can be registered as scoped DI service and then injected into Blazor
// components for use.

public class ExampleJsInterop : IAsyncDisposable
{
private readonly Lazy<Task<IJSObjectReference>> moduleTask;

public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/FrEee.UI.Blazor/exampleJsInterop.js").AsTask());
}

public async ValueTask<string> Prompt(string message)
{
var module = await moduleTask.Value;
return await module.InvokeAsync<string>("showPrompt", message);
}

public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}
}
6 changes: 6 additions & 0 deletions FrEee.UI.Blazor/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Installs weavers in the Fody plugin-->
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<!-- Automatically implements INotifyPropertyChanged change notifications for properties in classes that implement the interface -->
<PropertyChanged />
</Weavers>
74 changes: 74 additions & 0 deletions FrEee.UI.Blazor/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
35 changes: 35 additions & 0 deletions FrEee.UI.Blazor/FrEee.UI.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>


<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Excubo.Blazor.Canvas" Version="3.2.46" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.3" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FrEee.Assets\FrEee.Assets.csproj" />
<ProjectReference Include="..\FrEee\FrEee.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="Views\ImageDisplay.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

<PropertyGroup>
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
</PropertyGroup>

</Project>
100 changes: 100 additions & 0 deletions FrEee.UI.Blazor/Views/GalaxyMap.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@using System.Drawing
@using System.ComponentModel
@using System.Numerics
@using FrEee.Extensions
@using Excubo.Blazor.Canvas

@code {
[Parameter]
public GalaxyMapViewModel VM { get; set; } = new();

/// <summary>
/// When the view model's properties change, update the UI.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
StateHasChanged();
}

protected override void OnInitialized()
{
VM.PropertyChanged += ViewModelPropertyChanged;
}

public void Dispose()
{
VM.PropertyChanged -= ViewModelPropertyChanged;
}

private Canvas helper_canvas;
private ElementReference normal_canvas;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var size = VM.Scale + 1;
var xoffset = VM.Width / 2d;
var yoffset = VM.Height / 2d;

await using (var ctx = await helper_canvas.GetContext2DAsync())
{
await ctx.ClearRectAsync(0, 0, VM.Width, VM.Height);
await ctx.SetTransformAsync(size, 0, 0, size, (xoffset + 0.5) * size, (yoffset + 0.5) * size);
await ctx.RestoreAsync();
await ctx.SaveAsync();
await ctx.StrokeStyleAsync("white");
await ctx.LineWidthAsync(0.1);
foreach (var connections in VM.WarpGraph.Connections)
{
var src = connections.Key;
foreach (var dest in connections.Value)
{
// TODO: display one way warps differently (arrows, incomplete lines, gradients?)
await ctx.MoveToAsync(src.Location.X, src.Location.Y);
await ctx.LineToAsync(dest.Location.X, dest.Location.Y);
await ctx.StrokeAsync();
}
}
}

await base.OnAfterRenderAsync(firstRender);
}
}

<div>
<div class="fill">
<ImageDisplay VM="@VM.BackgroundImageVM" />
</div>
<div class="zoom overlay" style="aspect-ratio: @(VM.AspectRatio)">
<Canvas @ref="helper_canvas" class="zoom" width="@VM.ScaledWidth" height="@VM.ScaledHeight"/>
</div>
<div class="zoom overlay2" style="aspect-ratio: @(VM.AspectRatio); display: grid">
@for (var x = VM.MinX; x <= VM.MaxX; x++)
{
for (var y = VM.MinY; y <= VM.MaxY; y++)
{
var sysloc = VM.StarSystemLocations.SingleOrDefault(q => q.Location.X == x && q.Location.Y == y);
var row = y - VM.MinY + 1;
var col = x - VM.MinX + 1;
if (sysloc is not null)
{
// system pie
string border = "1px solid black";
if (sysloc.Item == VM.SelectedStarSystem)
{
// making the border thicker breaks the layout for some reason
border = "1px solid white";
}
<div style="grid-row: @row; grid-column: @col; width: 1fr; height: 1fr; aspect-ratio: 1; border: @border">
<PieChart T="int" VM="@(VM.Mode.GetStarSystemViewModel(sysloc.Item, VM.StarSystemClicked))" />
</div>
}
else
{
// placeholder
<div style="grid-row: @row; grid-column: @col; width: 1fr; height: 1fr; aspect-ratio: 1; border: 1px dotted #00ff0044" />
}
}
}
</div>
</div>
36 changes: 36 additions & 0 deletions FrEee.UI.Blazor/Views/GalaxyMapModes/GalaxyMapModeLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace FrEee.UI.Blazor.Views.GalaxyMapModes;

public class GalaxyMapModeLibrary
{
private CompositionContainer container;

private static GalaxyMapModeLibrary Instance { get; set; } = new GalaxyMapModeLibrary();

private GalaxyMapModeLibrary()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IGalaxyMapMode).Assembly));
container = new CompositionContainer(catalog);
container.ComposeParts(this);
}

[ImportMany(typeof(IGalaxyMapMode))]
public IEnumerable<IGalaxyMapMode> AllOfThem { get; private set; }

public static IEnumerable<IGalaxyMapMode> All => Instance.AllOfThem;

public static IGalaxyMapMode? Find<T>(string name = "")
where T : IGalaxyMapMode
{
var results = All.OfType<T>();
if (!string.IsNullOrWhiteSpace(name))
{
results = results.Where(q => q.Name.Contains(name));
}
return results.FirstOrDefault();
}
}
27 changes: 27 additions & 0 deletions FrEee.UI.Blazor/Views/GalaxyMapModes/IGalaxyMapMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FrEee.Objects.Space;

namespace FrEee.UI.Blazor.Views.GalaxyMapModes;

/// <summary>
/// Rendering modes for the galaxy map.
/// </summary>
public interface IGalaxyMapMode
{
/// <summary>
/// The name of this mode.
/// </summary>
string Name { get; }

/// <summary>
/// Gets a <see cref="PieChartViewModel{T}"/> to represent a star system.
/// </summary>
/// <param name="starSystem">The star system to represent.</param>
/// <param name="starSystemClicked">Action to take when the star system is clicked.</param>
/// <returns>The view model.</returns>
PieChartViewModel<int> GetStarSystemViewModel(StarSystem starSystem, Action<StarSystem> starSystemClicked);
}
Loading