Adding working shop page

arthur_shop
Arthur VALIN 2 years ago
parent dc934f727c
commit f9bd286b23

@ -0,0 +1,9 @@
<div class="offer">
<div class="input">
<img src="@inputIcon" style="width: 30px" /> @inputAmount
</div>
@centerText
<div class="output">
<img src="@outputIcon" style="width: 30px" /> @outputAmount
</div>
</div>

@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Components;
namespace CraftSharp.Components
{
public partial class ShopOffer
{
[Parameter]
public int inputAmount { get; set; }
[Parameter]
public int outputAmount{ get; set; }
[Parameter]
public string centerText { get; set; }
[Parameter]
public string inputIcon { get; set; }
[Parameter]
public string outputIcon { get; set; }
}
}

@ -0,0 +1,35 @@
.offer {
width: 100%;
text-decoration: none;
text-align: center;
color: white;
cursor: pointer;
background: url('Images/btn1.png') center center/contain no-repeat;
background-size: 100% 100%;
font-family: SilkscreenNormal;
line-height: 26px;
padding-top: 6px;
font-family: Minecraft;
position: relative;
padding-bottom: 17px;
}
.offer:hover {
background: url('Images/btn2.png')center center/contain no-repeat;
background-size: 100% 100%;
}
.input {
position: absolute;
left: 5px;
top: 5px;
}
.output {
position: absolute;
right: 5px;
top: 9px;
}

@ -4,6 +4,7 @@
{ {
public int Id { get; set; } public int Id { get; set; }
public int numberOfKeys { get; set; } = 10; public int numberOfKeys { get; set; } = 10;
public int numberOfEmeralds { get; set; } = 250;
public string Password { get; set; } public string Password { get; set; }
public List<UserRoles> Roles { get; set; } = new List<UserRoles>() { UserRoles.User }; public List<UserRoles> Roles { get; set; } = new List<UserRoles>() { UserRoles.User };

@ -6,6 +6,7 @@
public bool IsAuthenticated { get; set; } public bool IsAuthenticated { get; set; }
public string UserName { get; set; } public string UserName { get; set; }
public int NumberOfKeys { get; set; } = 0; public int NumberOfKeys { get; set; } = 0;
public int numberOfEmeralds { get; set; } = 250;
public List<Item> Inventory { get; set; } = new List<Item>(); public List<Item> Inventory { get; set; } = new List<Item>();
public List<UserRoles> Roles { get; set; } = new List<UserRoles>() { UserRoles.User }; public List<UserRoles> Roles { get; set; } = new List<UserRoles>() { UserRoles.User };

@ -0,0 +1,10 @@
namespace CraftSharp.Models
{
public class ShopOfferModel
{
public string InputIconPath { get; set; }
public string OutputIconPath { get; set; }
public int InputAmount { get; set; }
public int OutputAmount { get; set; }
}
}

@ -27,9 +27,6 @@ namespace CraftSharp.Pages
[Inject] [Inject]
public CustomStateProvider AuthService { get; set; } public CustomStateProvider AuthService { get; set; }
[CascadingParameter]
public Task<AuthenticationState> Context { get; set; }
int NumberOfKeys { get; set; } = 0; int NumberOfKeys { get; set; } = 0;
int CostInKeys { get; set; } = 1; int CostInKeys { get; set; } = 1;
@ -45,7 +42,6 @@ namespace CraftSharp.Pages
items = await DataService.List(0, totalItem); items = await DataService.List(0, totalItem);
var authState = await Context;
NumberOfKeys = AuthService.GetCurrentUser().NumberOfKeys; NumberOfKeys = AuthService.GetCurrentUser().NumberOfKeys;
} }

@ -0,0 +1,32 @@
@using CraftSharp.Components
@page "/shop"
<AuthorizeView>
<Authorized>
<div class="NumberOfEmeralds">
<ValueIndicator IconPath="/Images/shop_icon.png"
Value="@NumberOfEmeralds">
</ValueIndicator>
</div>
</Authorized>
</AuthorizeView>
<div class="shopPanel">
<img src="/Images/villager.png" id="villager"/>
<div class="offers">
@foreach(var offer in offers){
<div @onclick="@(() => buyKeys(offer))"
class="@animation[offer]">
<ShopOffer inputIcon=@offer.InputIconPath
outputIcon=@offer.OutputIconPath
inputAmount=@offer.InputAmount
outputAmount=@offer.OutputAmount
centerText=@Localizer["Buy"]>
</ShopOffer>
</div>
}
</div>
</div>

@ -0,0 +1,76 @@
using CraftSharp.Models;
using CraftSharp.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.JSInterop;
using System.Reflection.Metadata;
namespace CraftSharp.Pages
{
public partial class Shop
{
[Inject]
public CustomStateProvider AuthService { get; set; }
[Inject]
public IStringLocalizer<Shop> Localizer { get; set; }
[Inject]
public IJSRuntime JsRuntime { get; set; }
int NumberOfEmeralds { get; set; } = 0;
List<ShopOfferModel> offers = new List<ShopOfferModel>()
{
new ShopOfferModel()
{
InputAmount=5,
InputIconPath="/Images/shop_icon.png",
OutputAmount=1,
OutputIconPath="/Images/opening_icon.png",
},
new ShopOfferModel()
{
InputAmount=20,
InputIconPath="/Images/shop_icon.png",
OutputAmount=5,
OutputIconPath="/Images/opening_icon.png",
},
new ShopOfferModel()
{
InputAmount=50,
InputIconPath="/Images/shop_icon.png",
OutputAmount=15,
OutputIconPath="/Images/opening_icon.png",
},
};
Dictionary<ShopOfferModel, string> animation = new Dictionary<ShopOfferModel, string>();
protected override async Task OnInitializedAsync()
{
NumberOfEmeralds = AuthService.GetCurrentUser().numberOfEmeralds;
foreach(ShopOfferModel offer in offers)
{
animation[offer] = "";
}
}
private async void buyKeys(ShopOfferModel offer)
{
if (offer.InputAmount <= NumberOfEmeralds)
{
NumberOfEmeralds -= offer.InputAmount;
AuthService.GetCurrentUser().NumberOfKeys += offer.OutputAmount;
}
else
{
animation[offer] = "buttonShake";
StateHasChanged();
await Task.Delay(500);
animation[offer] = "";
StateHasChanged();
}
}
}
}

@ -0,0 +1,46 @@
@keyframes buttonShake {
0%, 100% {
transform: translateX(0);
}
10%, 30%, 50%, 70% {
transform: translateX(-5px);
}
20%, 40%, 60% {
transform: translateX(5px);
}
80% {
transform: translateX(3px);
}
90% {
transform: translateX(-3px);
}
}
.buttonShake {
animation: buttonShake 0.5s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
}
.NumberOfEmeralds {
float: right;
margin: 5px;
}
.shopPanel{
display:flex;
}
.offers {
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-evenly;
}
.villager{
width: 66%
}

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Buy" xml:space="preserve">
<value>Acheter</value>
</data>
</root>

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Buy" xml:space="preserve">
<value>Buy</value>
</data>
</root>

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Buy" xml:space="preserve">
<value>Satın almak</value>
</data>
</root>

@ -11,23 +11,10 @@ namespace CraftSharp.Services
static AuthService() static AuthService()
{ {
CurrentUser = new List<AppUser> CurrentUser = new List<AppUser>
{
new AppUser { UserName = "Admin", Password = "123456", Roles = new List<UserRoles> { UserRoles.Admin }, numberOfKeys=999 }
};
}
/* public AppUser GetCurrentUser(string userName)
{
var user = CurrentUser.FirstOrDefault(w => w.UserName == userName);
if (user == null)
{ {
throw new Exception("User name or password invalid !"); new AppUser { UserName = "Admin", Password = "123456", Roles = new List<UserRoles> { UserRoles.Admin }, numberOfKeys=999 }
} };
}
return user;
}*/
public CurrentUser GetUser(string userName) public CurrentUser GetUser(string userName)
{ {
var user = CurrentUser.FirstOrDefault(w => w.UserName == userName); var user = CurrentUser.FirstOrDefault(w => w.UserName == userName);
@ -45,6 +32,7 @@ namespace CraftSharp.Services
IsAuthenticated = true, IsAuthenticated = true,
UserName = user.UserName, UserName = user.UserName,
NumberOfKeys = user.numberOfKeys, NumberOfKeys = user.numberOfKeys,
numberOfEmeralds = user.numberOfEmeralds,
Inventory = user.inventory, Inventory = user.inventory,
Roles = user.Roles, Roles = user.Roles,
Claims = claims.ToDictionary(c => c.Type, c => c.Value) Claims = claims.ToDictionary(c => c.Type, c => c.Value)

@ -5,9 +5,7 @@ namespace CraftSharp.Services
public interface IAuthService public interface IAuthService
{ {
CurrentUser GetUser(string userName); CurrentUser GetUser(string userName);
void Login(ConnexionModel loginRequest); void Login(ConnexionModel loginRequest);
void Register(InscriptionModel registerRequest); void Register(InscriptionModel registerRequest);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Loading…
Cancel
Save