Update the ColourChoice to be better UI & UX
This commit is contained in:
parent
19a4d909f8
commit
72db6ae4d0
1 changed files with 108 additions and 44 deletions
|
|
@ -1,27 +1,41 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import SpaceShuttle from "../icons/spaceship.svelte";
|
||||||
import SciFiButton from "../SciFi-Button.svelte";
|
import SciFiButton from "../SciFi-Button.svelte";
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
|
import { myName, players } from "../../stores";
|
||||||
import BaseModal from "./BaseModal.svelte";
|
import BaseModal from "./BaseModal.svelte";
|
||||||
|
import Hexagon from "../Hexagon.svelte";
|
||||||
|
|
||||||
const emit = createEventDispatcher();
|
const emit = createEventDispatcher();
|
||||||
|
|
||||||
export let open: boolean = false;
|
export let open: boolean = false;
|
||||||
|
|
||||||
let colours = [
|
/** This will be fetched from the server when opening the modal */
|
||||||
{ name: "Green", hex: "#00aa00", taken: false },
|
const colours = [
|
||||||
{ name: "Blue", hex: "#0077b6", taken: false },
|
{ name: "Green", hex: "#00aa00" },
|
||||||
{ name: "Red", hex: "#cb0b0a", taken: false },
|
{ name: "Blue", hex: "#0077b6" },
|
||||||
{ name: "Purple", hex: "#7400b8", taken: false },
|
{ name: "Red", hex: "#cb0b0a" },
|
||||||
{ name: "Orange", hex: "#faa307", taken: false },
|
{ name: "Purple", hex: "#7400b8" },
|
||||||
{ name: "Light Green", hex: "#9ef01a", taken: true },
|
{ name: "Orange", hex: "#faa307" },
|
||||||
{ name: "Magenta", hex: "#b7094c", taken: false },
|
{ name: "Light Green", hex: "#9ef01a" },
|
||||||
{ name: "Pink", hex: "#f72585", taken: false },
|
{ name: "Magenta", hex: "#b7094c" },
|
||||||
{ name: "Yellow", hex: "#f9c80e", taken: false },
|
{ name: "Pink", hex: "#f72585" },
|
||||||
|
{ name: "Yellow", hex: "#f9c80e" },
|
||||||
];
|
];
|
||||||
|
const spaceships = [
|
||||||
|
{ name: "Space Shuttle", code: "space-shuttle" },
|
||||||
|
{ name: "Rocket", code: "rocket" },
|
||||||
|
]
|
||||||
|
|
||||||
function selectColour(colour: any) {
|
let player = $players.find(p => p.name == $myName);
|
||||||
emit("selectColour", colour);
|
|
||||||
};
|
$: myColour = player.colour;
|
||||||
|
$: takenColours = $players.map(p => p.colour);
|
||||||
|
|
||||||
|
var selectedColour = player.colour;
|
||||||
|
var selectedShip = player.ship;
|
||||||
|
|
||||||
|
function saveShipDesign() {};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -30,28 +44,70 @@ function selectColour(colour: any) {
|
||||||
<h2>Choose a Colour</h2>
|
<h2>Choose a Colour</h2>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
{#each colours as colour}
|
<div class="options">
|
||||||
<div
|
<div class="colour">
|
||||||
style="--colour: {colour.hex};"
|
<h3>Colour:</h3>
|
||||||
disabled="{colour.taken}"
|
|
||||||
>
|
|
||||||
<div class="colour"></div>
|
|
||||||
|
|
||||||
<!-- Allow the colour to be chosen if it isn't already taken -->
|
<!--
|
||||||
{#if !colour.taken}
|
Create the dropdown that allows the user to see all of
|
||||||
<span class="name">
|
the colours but not choose ones that other users
|
||||||
<SciFiButton
|
currently have selected.
|
||||||
title="Select {colour.name} to be your spaceship colour"
|
-->
|
||||||
on:click="{_ => selectColour(colour)}"
|
<select
|
||||||
|
name="colour"
|
||||||
|
id="spaceship-colour"
|
||||||
|
bind:value="{selectedColour}"
|
||||||
>
|
>
|
||||||
Select {colour.name}
|
<!-- Display each colour as given by the server -->
|
||||||
</SciFiButton>
|
{#each colours as c}
|
||||||
</span>
|
<option
|
||||||
{:else}
|
value="{c.hex}"
|
||||||
<span class="name">{colour.name}</span>
|
disabled="{
|
||||||
{/if}
|
c.hex != myColour
|
||||||
</div>
|
&& takenColours.includes(c.hex)
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{c.name}
|
||||||
|
</option>
|
||||||
{/each}
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="spaceship">
|
||||||
|
<h3>Spaceship</h3>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Create the dropdown that allows users to select which
|
||||||
|
spaceship icon they want for their player.
|
||||||
|
-->
|
||||||
|
<select
|
||||||
|
name="spaceship"
|
||||||
|
id="spaceship-icon"
|
||||||
|
bind:value="{selectedShip}"
|
||||||
|
>
|
||||||
|
{#each spaceships as ship}
|
||||||
|
<option value="{ship.code}">{ship.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="preview">
|
||||||
|
<h3>Preview:</h3>
|
||||||
|
<Hexagon>
|
||||||
|
<div
|
||||||
|
class="spaceship-icon"
|
||||||
|
style="--colour: {selectedColour};"
|
||||||
|
>
|
||||||
|
<SpaceShuttle
|
||||||
|
spaceship="{selectedShip}"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Hexagon>
|
||||||
|
<SciFiButton
|
||||||
|
on:click="{saveShipDesign}"
|
||||||
|
>
|
||||||
|
Save Design
|
||||||
|
</SciFiButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
|
|
@ -71,22 +127,30 @@ function selectColour(colour: any) {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
|
flex-direction: column;
|
||||||
.colour {
|
|
||||||
background: var(--colour);
|
|
||||||
width: 50px;
|
|
||||||
height: 50px;
|
|
||||||
margin-right: 5px;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name {
|
|
||||||
flex-grow: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include medium {
|
@include medium {
|
||||||
width: 30%;
|
width: 30%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spaceship-icon {
|
||||||
|
/*
|
||||||
|
Smaller version: 55px
|
||||||
|
Larger version: 75px
|
||||||
|
*/
|
||||||
|
--size: 80px;
|
||||||
|
width: var(--size);
|
||||||
|
height: var(--size);
|
||||||
|
display: flex;
|
||||||
|
color: var(--colour);
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue