Skip to content

Commit

Permalink
Cleaned up print buttons; added global scale button; added bulk impor…
Browse files Browse the repository at this point in the history
…ter; added playing card mode
  • Loading branch information
qkmaxware committed Aug 29, 2022
1 parent 56b68fc commit 5948c8f
Show file tree
Hide file tree
Showing 16 changed files with 729 additions and 26 deletions.
74 changes: 74 additions & 0 deletions Pages/CardIndex.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@page "/card"

<div class="w3-center no-print">
<nav class="w3-small" style="display: inline-block; border-radius: 0 0 8px 8px; margin-left: auto; margin-right: auto;">
<button class="w3-button w3-round-large">
<img src="assets/printer.svg" style="width: 32px; height: 32px;" onclick="window.print()">
<p>
print <select @bind="size" onclick="false" @onclick:stopPropagation>@foreach(var size in Enum.GetValues<cardSizes>()){ <option>@size</option> }</select>
</p>
</button>
</nav>
</div>

<div class="w3-row no-print">
@foreach (var card in cards) {
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-border w3-round-xlarge">
<div class="w3-center" style="height: 240px;">
<img src="@card.FrontUrl" class="pixelart"/>
</div>
<div class="w3-right-align">
<button class="w3-button" @onclick=@(() => editCard(card))>Edit</button>
<button class="w3-button w3-text-red" @onclick=@(() => deleteCard(card))>Delete</button>
</div>
</div>
</div>
}
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-button w3-round-xlarge w3-display-container" @onclick=createCard style="border: 1px dashed white; width:100%; height: 320.8px">
<div class="w3-display-middle w3-center w3-xlarge">
New<br>
+
</div>
</div>
</div>
</div>

<div class="w3-row print">
@foreach (var card in cards) {
for (var i = 0; i < card.Replicas; i++) {
<img src="@card.FrontUrl" class="card fold-right @size">
<img src="@card.BackUrl" class="card fold-left @size">
}
}
<Instructions></Instructions>
</div>

<CardEditor @ref=editor OnChange=StateHasChanged></CardEditor>
<DeleteConfirmation @ref=delete></DeleteConfirmation>

@code {
static List<PlayingCard> cards = new List<PlayingCard>();

enum cardSizes {
poker, bridge, tarot, square, game, business
}
private static cardSizes size;

private DeleteConfirmation delete;
private CardEditor editor;
private void createCard() {
var card = new PlayingCard ();
cards.Add(card);
editor?.Edit(card);
}

private void editCard(PlayingCard card) {
editor?.Edit(card);
}

private void deleteCard(PlayingCard card) {
this.delete.AskForConfirmation(() => { cards.Remove(card); StateHasChanged(); });
}
}
16 changes: 6 additions & 10 deletions Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
<br>
Create Terrain
</a>
<a href="card" class="w3-button w3-round-xlarge w3-center w3-padding" style="border: 1px dashed white;">
<img src="assets/card.svg" width=128>
<br>
Create Playing Card
</a>
</div>
</div>

@code {

private void gotoMini() {

}
private void gotoTerrain() {}

}
</div>
68 changes: 56 additions & 12 deletions Pages/MiniIndex.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
@page "/mini"

<div class="w3-center w3-padding no-print">
<a href="#" onclick="window.print()">print</a> this page to get your minis <select @bind="baseSelection"><option value="Y">with a base</option><option value="N">without base</option></select>.
<div class="w3-center no-print">
<nav class="w3-small" style="display: inline-block; border-radius: 0 0 8px 8px; margin-left: auto; margin-right: auto;">
<button class="w3-button w3-round-large" @onclick=@(() => scaleModal?.Show(true))>
<img src="assets/scale.svg" style="width: 32px; height: 32px;">
<p>scale</p>
</button>
<button class="w3-button w3-round-large">
<img src="assets/printer.svg" style="width: 32px; height: 32px;" onclick="window.print()">
<p>
print <select @bind="baseSelection" onclick="false" @onclick:stopPropagation><option value="Y">with base</option><option value="N">without base</option></select>
</p>
</button>
</nav>
</div>

<PopupModal @ref=scaleModal Title="Apply Scale" OnSave=applyScale>
<label>Scale Multiplier</label>
<input class="w3-input w3-margin-bottom" @bind=scaleMultiplier style="background-color:inherit; color:inherit;">
<label>Reset Scale</label>
<p><button class="w3-button" @onclick=resetScale>Reset</button> all mini's scale to 1</p>
</PopupModal>
@code {
private PopupModal scaleModal;
private float scaleMultiplier = 1;
private void applyScale() {
foreach (var mini in minis) {
mini.Scale *= scaleMultiplier;
}
}
private void resetScale() {
foreach (var mini in minis) {
mini.Scale = 1;
}
}
}

<div class="w3-row no-print">
@foreach (var mini in minis) {
<div class="w3-col l2 m3 s12 w3-padding">
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-border w3-round-xlarge">
<div class="w3-center w3-padding w3-large">
@mini.Name @if(mini.Replicas > 1) { <small> (x@(mini.Replicas))</small> }
Expand All @@ -22,11 +54,17 @@
</div>
</div>
}
<div class="w3-col l2 m3 s12 w3-padding">
<div class="w3-button w3-round-xlarge w3-display-container" @onclick=createMini style="border: 1px dashed white; width:100%; height: 320.8px">
<div class="w3-display-middle w3-center w3-xlarge">
New<br>
+
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-display-container w3-round-xlarge" style="border: 1px dashed white; width:100%; height: 320.8px">
<div class="w3-button w3-round-xlarge" style="display: flex; justify-content: center; align-content: center; flex-direction: column; height: 100%; width: 100%;">
<p>
New<br>+
</p>
</div>
<div class="w3-display-bottommiddle">
<p class="w3-small">
or <button @onclick=@(() => bulk?.Show(true)) @onclick:stopPropagation style="cursor: pointer">bulk add</button> multiple minis
</p>
</div>
</div>
</div>
Expand All @@ -40,20 +78,22 @@
<Instructions></Instructions>
</div>

<div class="w3-center w3-padding no-print" style="position: fixed; bottom: 0; left: 0; right: 0;">
Confused? Read the complete instructions <a href="mini/help" target="_blank">here</a>.
<div class="w3-center w3-padding no-print" style="position: fixed; bottom: 0; left: 0; right: 0; pointer-events: none;">
Confused? Read the complete instructions <a href="mini/help" target="_blank" style="pointer-events: auto">here</a>.
</div>

<MiniEditor @ref=editor OnChange=StateHasChanged></MiniEditor>
<DeleteConfirmation @ref=delete></DeleteConfirmation>
<BulkLoader @ref=bulk OnChange=bulkAdd></BulkLoader>

@code {

private MiniEditor editor;
private DeleteConfirmation delete;
private BulkLoader bulk;

private string baseSelection = "Y";
private bool printWithBase => baseSelection == "Y";
private static string baseSelection = "Y";
private static bool printWithBase => baseSelection == "Y";

public static List<Mini> minis = new List<Mini> {};

Expand All @@ -70,6 +110,10 @@
editor?.Edit(mini);
}

private void bulkAdd(IEnumerable<Mini> toAdd) {
minis.AddRange(toAdd);
StateHasChanged();
}

private void editMini(Mini mini) {
editor?.Edit(mini);
Expand Down
15 changes: 11 additions & 4 deletions Pages/TerrainIndex.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
@page "/terrain"

<div class="w3-center w3-padding no-print">
<a href="#" onclick="window.print()">print</a> this page to get your terrain.
<div class="w3-center no-print">
<nav class="w3-small" style="display: inline-block; border-radius: 0 0 8px 8px; margin-left: auto; margin-right: auto;">
<button class="w3-button w3-round-large" onclick="window.print()">
<img src="assets/printer.svg" style="width: 32px; height: 32px;">
<p>
print
</p>
</button>
</nav>
</div>

<div class="w3-row no-print">
@foreach (var mini in minis) {
<div class="w3-col l2 m3 s12 w3-padding">
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-border w3-round-xlarge">
<div class="w3-center w3-padding w3-large">
@mini.Name @if(mini.Replicas > 1) { <small> (x@(mini.Replicas))</small> }
Expand All @@ -21,7 +28,7 @@
</div>
</div>
}
<div class="w3-col l2 m3 s12 w3-padding">
<div class="w3-col l2 m4 s12 w3-padding">
<div class="w3-button w3-round-xlarge w3-display-container" @onclick=createMini style="border: 1px dashed white; width:100%; height: 320.8px">
<div class="w3-display-middle w3-center w3-xlarge">
New<br>
Expand Down
12 changes: 12 additions & 0 deletions PlayingCard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;

namespace PaperMiniMaker {

public class PlayingCard {
public int Replicas {get; set;} = 1;
public string FrontUrl {get; set;}
public string BackUrl {get; set;}
}

}
75 changes: 75 additions & 0 deletions Shared/BulkLoader.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@inject IJSRuntime js;

<div class="w3-modal @showModalCss">
<div class="w3-modal-content w3-round-xlarge">
<header class="w3-container w3-center w3-xlarge">
Bulk Add Minis
</header>
<div class="w3-padding bg">
<p>Select any number of image files below to create miniatures for.</p>
<input @ref=files type="file" accept="image/*" class="w3-input" @onchange=readFileStrings multiple>
</div>
<footer class="w3-container w3-row w3-padding">
<div class="w3-col s6">
<button class="w3-button w3-red" @onclick=@(() => Show(false))>Cancel</button>
</div>
<div class="w3-col s6" style="text-align: right;">
@if (dataUrls != null && dataUrls.dataUrls != null && dataUrls.dataUrls.Length > 0) {
<button class="w3-button w3-green" @onclick=save>Add @(dataUrls.dataUrls.Length) Minis</button>
}
</div>

</footer>
</div>
</div>

@code {

private bool isOpen = false;
private string showModalCss => isOpen ? "w3-show" : "w3-hide";

private ElementReference files;

private BulkResults dataUrls;

[Parameter] public Action<IEnumerable<Mini>> OnChange {get; set;}

private class BulkResults {
public string[] dataUrls {get; set;}
public string[] names {get; set;}
}

private async Task readFileStrings() {
dataUrls = await js.InvokeAsync<BulkResults>("BlazorHandleFileSelectMultipleDataUrl", files);
}

public void Show(bool isOpen) {
this.isOpen = isOpen;
StateHasChanged();
}

private void save() {
if (OnChange == null)
return;

if (dataUrls == null || dataUrls.dataUrls == null) {
OnChange(new Mini[0]);
Show(false);
return;
}

var minis = new Mini[this.dataUrls.dataUrls.Length];
for (var i = 0; i < minis.Length; i++) {
minis[i] = new Mini {
Name = i >= 0 && dataUrls.names != null && i < dataUrls.names.Length ? dataUrls.names[i] : "Bulk Mini",
Size = MiniSize.Medium,
FrontArt = new MiniArt {
Url = dataUrls.dataUrls[i]
},
Replicas = 1,
};
}
OnChange(minis);
Show(false);
}
}
55 changes: 55 additions & 0 deletions Shared/CardEditor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<div class="w3-modal @showModalCss">
<div class="w3-modal-content w3-round-xlarge">
<header class="w3-container w3-center w3-xlarge">
Edit Playing Card
</header>
@if (card != null) {
<div class="w3-container bg">
<label>Replicas</label>
<input type="number" class="w3-input w3-margin-bottom" @bind=@card.Replicas style="background-color:inherit; color:inherit;">

<div class="w3-margin-top w3-margin-bottom">
<div class="w3-padding" style="background-color: #2D232E;">
<label>Front Art Url</label>
<input class="w3-input" @bind=@card.FrontUrl style="background-color:inherit; color:inherit;">
<div class="w3-center w3-padding">
OR
</div>
<FilePicker Accept="image/*" AsDataUrl=true OnFileLoad=@((url) => { card.FrontUrl = url; StateHasChanged(); })></FilePicker>

<div class="w3-margin-top">&nbsp;</div>

<label>Back Art Url</label>
<input class="w3-input" @bind=@card.BackUrl style="background-color:inherit; color:inherit;">
<div class="w3-center w3-padding">
OR
</div>
<FilePicker Accept="image/*" AsDataUrl=true OnFileLoad=@((url) => { card.BackUrl = url; StateHasChanged(); })></FilePicker>
</div>
</div>
</div>
<footer class="w3-container w3-center">
<button class="w3-button" @onclick=save>Done</button>
</footer>
}
</div>
</div>

@code {
[Parameter] public Action OnChange {get; set;}
private PlayingCard card;

private bool isOpen = false;
private string showModalCss => isOpen ? "w3-show" : "w3-hide";

public void Edit(PlayingCard card) {
this.card = card;
this.isOpen = true;
StateHasChanged();
}

public void save() {
OnChange?.Invoke();
this.isOpen = false;
}
}
3 changes: 3 additions & 0 deletions Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<NavLink class="w3-bar-item w3-button" href="terrain" Match="NavLinkMatch.Prefix" ActiveClass="bg">
Terrain
</NavLink>
<NavLink class="w3-bar-item w3-button" href="card" Match="NavLinkMatch.Prefix" ActiveClass="bg">
Card
</NavLink>
</div>
</header>
@Body
Expand Down
Loading

0 comments on commit 5948c8f

Please sign in to comment.