feat(Toasts) Adding toasts

This commit is contained in:
2022-04-10 17:32:22 -04:00
parent 8c06fdd120
commit 4322be0053
29 changed files with 478 additions and 100 deletions
+10 -1
View File
@@ -14,6 +14,7 @@
</Router>
<EntityDialogPortal/>
<ToastPortal/>
<style>
a {
@@ -30,7 +31,15 @@
:root {
/* Duplicate Code, to deal with cache issues. See wwwroot/css/app.css for proper :root */
--severity-warning-color: #2a2000;
--severity-warning-border-color: #755c13;
--severity-error-color: #290102;
--severity-error-border-color: #4C2C33;
--severity-information-color: #030129;
--severity-information-border-color: #2c3a4c;
--severity-success-color: #042901;
--severity-success-border-color: #2E4C2C;
--accent: #432462;
--primary: #4308a3;
--primary-border: #2c0b62;
BIN
View File
Binary file not shown.
+29 -9
View File
@@ -15,10 +15,15 @@
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Markdig" Version="0.28.1"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-preview.2.22153.2"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-preview.2.22153.2" PrivateAssets="all"/>
<PackageReference Include="Markdig" Version="0.28.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-preview.2.22153.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-preview.2.22153.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0-preview.2.22153.2" />
<!--
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.2.22153.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0-preview.2.22153.1" />
@@ -27,18 +32,33 @@
</ItemGroup>
<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js"/>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Components\Components.csproj"/>
<ProjectReference Include="..\Contexts\Contexts.csproj"/>
<ProjectReference Include="..\Model\Model.csproj"/>
<ProjectReference Include="..\Services\Services.csproj"/>
<ProjectReference Include="..\Components\Components.csproj" />
<ProjectReference Include="..\Contexts\Contexts.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\generated"/>
<Folder Include="wwwroot\generated" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Localizations.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localizations.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Localizations.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Example.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+11
View File
@@ -1,9 +1,20 @@
@page "/"
@using Microsoft.Extensions.Localization
@layout PageLayout
@inject IStringLocalizer<Localizations> Loc
<DevOnlyComponent>
<DocumentationIndexPage></DocumentationIndexPage>
@Loc["Greeting"].Value
@Loc["Greeting"]
@Loc["Greeting"].Name
@Loc["Greeting"].ResourceNotFound
</DevOnlyComponent>
<HomePage></HomePage>
+54
View File
@@ -0,0 +1,54 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace IGP {
using System;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Localizations {
private static System.Resources.ResourceManager resourceMan;
private static System.Globalization.CultureInfo resourceCulture;
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Localizations() {
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Resources.ResourceManager ResourceManager {
get {
if (object.Equals(null, resourceMan)) {
System.Resources.ResourceManager temp = new System.Resources.ResourceManager("IGP.Localizations", typeof(Localizations).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal static System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
internal static string Greeting {
get {
return ResourceManager.GetString("Greeting", resourceCulture);
}
}
}
}
View File
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Greeting" xml:space="preserve">
<value>Hello</value>
</data>
</root>
-1
View File
@@ -1,6 +1,5 @@
@layout PageLayout
@page "/about"
<LayoutMediumContentComponent>
+7 -5
View File
@@ -5,7 +5,13 @@
@page "/agile"
@if (AgileService.IsLoaded())
@if (!AgileService.IsLoaded())
{
<LoadingComponent/>
}
else
{
<LayoutMediumContentComponent>
@@ -69,10 +75,6 @@
</PaperComponent>
</LayoutMediumContentComponent>
}
else
{
<LoadingComponent/>
}
@code {
@@ -13,7 +13,7 @@
<LayoutLargeContentComponent>
<WebsiteTitleComponent>Build Calculator</WebsiteTitleComponent>
<AlertComponent Type="SeverityType.Warning">
<AlertComponent Type="@SeverityType.Warning">
<Title>Work In Progress and Not Fully Tested</Title>
<Message>
Currently not considering training queue times. Lacking error toasts for invalid actions. Performance needs to be optimized. Calculations haven't been thoroughly compared against real gameplay. Added a 2 second delay to actions to account for casual micro (will probably tweak later).
+5 -51
View File
@@ -38,13 +38,13 @@
<FormNumberComponent Min="0"
Value="@((int)NumberOfTownHallsExisting)"
OnChange="@(e => { NumberOfTownHallsExisting = int.Parse(e.Value!.ToString()!); Calculate();})">
<FormLabelComponent>Number of townhalls existing</FormLabelComponent>
<FormLabelComponent>Number of townhalls you have</FormLabelComponent>
</FormNumberComponent>
<FormNumberComponent Min="0"
Value="@((int)TravelTime)"
OnChange="@(e => { TravelTime = int.Parse(e.Value!.ToString()!); Calculate();})">
<FormLabelComponent>Travel time</FormLabelComponent>
<FormLabelComponent>Worker travel time to alloy</FormLabelComponent>
</FormNumberComponent>
<FormDisplayComponent Label="Total alloy lost">
@@ -93,9 +93,9 @@
<InfoAnswerComponent>
Well, let's assume you lost a full alloy line of workers, and have to take that 741 alloy cost (300 to rebuy the workers, and 441 in lost mining time.)
<br/><br/>
If you were to set the <b>Number of townhalls existing</b> to 2, the calculator will consider worker transfer micro. Allowing you to cut the total cost by roughly 315 alloy. However, that number isn't entirely accurate, you are also going to have to bump up the <b>Travel time</b> to account for the time it takes the transferred workers to arrive at the decimated alloy line.
If you were to set the <b>Number of townhalls you have</b> to 2, the calculator will consider worker transfer micro. Allowing you to cut the total cost by roughly 315 alloy. However, that number isn't entirely accurate, you are also going to have to bump up the <b>Worker travel time to alloy</b> to account for the time it takes the transferred workers to arrive at the decimated alloy line.
<br/><br/>
Let's say it takes 10 seconds for workers to transfer from your second base. We can divide that number by 2, to represent our bases, and add those 5 additional seconds to <b>Travel time</b>, for the more accurate loss of 456 alloy (saving you 285 alloy.) <i>Which is much better than not transferring workers!</i>
Let's say it takes 10 seconds for workers to transfer from your second base. We can divide that number by 2, to represent our bases, and add those 5 additional seconds to <b>Worker travel time to alloy</b>, for the more accurate loss of 456 alloy (saving you 285 alloy.) <i>Which is much better than not transferring workers!</i>
</InfoAnswerComponent>
</InfoBodyComponent>
@@ -146,53 +146,7 @@
Can I see the code for the calculation?
</InfoQuestionComponent>
<InfoAnswerComponent>
<CodeComponent>
<div style="color: green;">//TotalAlloyHarassment is set after Calculate() function is called</div>
<div>
float TotalAlloyHarassment;
float CostOfWorker = 50;
float AlloyMinedPerSecondByWorker = 1;
float TimeToProduceWorker = 20;
float TravelTime = 1;
float NumberOfWorkersLostToHarass = 1;
float NumberOfTownHallsExisting = 1;
float SimultaneousProductionFloor() {
if (NumberOfTownHallsExisting &lt;= 0 || NumberOfWorkersLostToHarass &lt;= 0) {
return 0;
}
return (float)Math.Floor(NumberOfWorkersLostToHarass / Math.Min(NumberOfTownHallsExisting, NumberOfWorkersLostToHarass));
}
float LeftOverWorkersToProduceCount() {
return NumberOfWorkersLostToHarass % (Math.Min(NumberOfTownHallsExisting, NumberOfWorkersLostToHarass));
}
float WorkerReplacementCost() {
return CostOfWorker * NumberOfWorkersLostToHarass;
}
float DelayedMiningCost() {
return TotalAlloyHarassment - WorkerReplacementCost();
}
void Calculate() {
TotalAlloyHarassment = WorkerReplacementCost();
for (var workerProductionIndex = 0; workerProductionIndex &lt; SimultaneousProductionFloor(); workerProductionIndex++) {
TotalAlloyHarassment += AlloyMinedPerSecondByWorker * (TimeToProduceWorker + TravelTime) * (workerProductionIndex + 1);
}
TotalAlloyHarassment += LeftOverWorkersToProduceCount() * (TimeToProduceWorker + TravelTime) * AlloyMinedPerSecondByWorker;
}
</div>
</CodeComponent>
<CodeLinkComponent Href="https://github.com/JonathanMcCaffrey/IGP-Fan-Reference/blob/main/IGP/Pages/HarassCalculatorPage.razor#L223-L281"/>
</InfoAnswerComponent>
</InfoBodyComponent>
+1 -1
View File
@@ -5,7 +5,7 @@
<LayoutLargeContentComponent>
<WebsiteTitleComponent>Making Of</WebsiteTitleComponent>
<AlertComponent Type="SeverityType.Warning">
<AlertComponent Type="@SeverityType.Warning">
<Title>Under Construction</Title>
<Message>This page is still being worked on. It will list the tech and design choices made for this website. It's is strictly for educational and reference purposes, and it has nothing to do with IMMORTAL: Gates of Pyre.</Message>
</AlertComponent>
@@ -28,19 +28,19 @@
<Title>Alert Message</Title>
<Description>Used to convey important information to the viewer. Comes in Yellow (Warning), Blue (Information), Red (Error), and Green (Success). Mostly used to warn viewers of pre-alpha or incomplete content being viewed.</Description>
<Example>
<AlertComponent Type="SeverityType.Warning">
<AlertComponent Type="@SeverityType.Warning">
<Title>Warning Alert Title</Title>
<Message>Warning Alert Message</Message>
</AlertComponent>
<AlertComponent Type="SeverityType.Information">
<AlertComponent Type="@SeverityType.Information">
<Title>Information Alert Title</Title>
<Message>Information Alert Message</Message>
</AlertComponent>
<AlertComponent Type="SeverityType.Error">
<AlertComponent Type="@SeverityType.Error">
<Title>Error Alert Title</Title>
<Message>Error Alert Message</Message>
</AlertComponent>
<AlertComponent Type="SeverityType.Success">
<AlertComponent Type="@SeverityType.Success">
<Title>Succsess Alert Title</Title>
<Message>Succsess Alert Message</Message>
</AlertComponent>
+42
View File
@@ -0,0 +1,42 @@
@implements IDisposable;
@inject IToastService toastService
@if (toastService.HasToasts())
{
<div class="toastsContainer">
@foreach (var toast in toastService.GetToasts())
{
<ToastComponent Toast="toast"/>
}
</div>
}
<style>
.toastsContainer {
position: fixed;
top: 64px;
right: 64px;
}
</style>
@code {
protected override void OnInitialized()
{
toastService.Subscribe(OnUpdate);
}
public void Dispose()
{
toastService.Unsubscribe(OnUpdate);
}
void OnUpdate()
{
StateHasChanged();
}
}
+9
View File
@@ -4,6 +4,7 @@ using Services;
using Services.Development;
using Services.Immortal;
using Services.Website;
using System.Globalization;
#if NO_SQL
#else
@@ -11,6 +12,11 @@ using Contexts;
using Microsoft.EntityFrameworkCore;
#endif
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Logging.SetMinimumLevel(LogLevel.Warning);
@@ -19,6 +25,8 @@ builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddLocalization();
builder.Services.AddSingleton<INavigationService, NavigationService>();
builder.Services.AddSingleton<IKeyService, KeyService>();
@@ -40,6 +48,7 @@ builder.Services.AddSingleton(new HttpClient
builder.Services.AddSingleton<IEntityDialogService, EntityDialogService>();
builder.Services.AddSingleton<IToastService, ToastService>();
#if NO_SQL
+2
View File
@@ -7,6 +7,7 @@
@using Components.Navigation
@using Components.Shared
@using Components.Utils
@using System.Globalization
@using IGP.Dialog
@using IGP.Pages
@using IGP.Pages.Agile.Parts
@@ -27,6 +28,7 @@
@using IGP.Pages.Notes.Parts
@using IGP.Portals
@using Markdig
@using Model.Feedback
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
+12 -1
View File
@@ -4,6 +4,15 @@
@import "components/table.css";
:root {
--severity-warning-color: #2a2000;
--severity-warning-border-color: #755c13;
--severity-error-color: #290102;
--severity-error-border-color: #4C2C33;
--severity-information-color: #030129;
--severity-information-border-color: #2c3a4c;
--severity-success-color: #042901;
--severity-success-border-color: #2E4C2C;
--accent: #432462;
--primary: #4308a3;
--primary-border: #2c0b62;
@@ -22,12 +31,14 @@
--info: #451376;
--info-border: #210b36;
--info-hover: #451376;
--info-border-hover: #210b36;
--dialog-border-color: black;
--dialog-border-width: 2px;
--dialog-radius: 6px;
}
html {
box-sizing: border-box;
}
File diff suppressed because one or more lines are too long
+7 -2
View File
@@ -13,11 +13,11 @@
<link href="IGP.styles.css" rel="stylesheet"/>
</head>
<body style="background-color: var(--background); color: white;">
<body style="background-color: #161618; color: white;">
<div id="app">
<div style="width: 100vw; height: 100vh; background-color: black;"></div>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script crossorigin="anonymous"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
@@ -28,6 +28,11 @@
integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2"
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js"></script>
<script src="javascript/download.js"></script>
<script>
Blazor.start({
applicationCulture: 'en-US'
});
</script>
</body>
</html>