diff --git a/src/CraftSharp/Components/ShopOffer.razor b/src/CraftSharp/Components/ShopOffer.razor new file mode 100644 index 0000000..9c927e5 --- /dev/null +++ b/src/CraftSharp/Components/ShopOffer.razor @@ -0,0 +1,9 @@ +
+
+ @inputAmount +
+ @centerText +
+ @outputAmount +
+
\ No newline at end of file diff --git a/src/CraftSharp/Components/ShopOffer.razor.cs b/src/CraftSharp/Components/ShopOffer.razor.cs new file mode 100644 index 0000000..60473b1 --- /dev/null +++ b/src/CraftSharp/Components/ShopOffer.razor.cs @@ -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; } + } +} diff --git a/src/CraftSharp/Components/ShopOffer.razor.css b/src/CraftSharp/Components/ShopOffer.razor.css new file mode 100644 index 0000000..8e521dc --- /dev/null +++ b/src/CraftSharp/Components/ShopOffer.razor.css @@ -0,0 +1,36 @@ +.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; + user-select:none; +} + +.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; + +} + diff --git a/src/CraftSharp/Models/AppUser.cs b/src/CraftSharp/Models/AppUser.cs index c73e3e3..b125722 100644 --- a/src/CraftSharp/Models/AppUser.cs +++ b/src/CraftSharp/Models/AppUser.cs @@ -4,6 +4,7 @@ { public int Id { get; set; } public int numberOfKeys { get; set; } = 10; + public int numberOfEmeralds { get; set; } = 250; public string Password { get; set; } public List Roles { get; set; } = new List() { UserRoles.User }; diff --git a/src/CraftSharp/Models/CurrentUser.cs b/src/CraftSharp/Models/CurrentUser.cs index 13d2f82..360c27a 100644 --- a/src/CraftSharp/Models/CurrentUser.cs +++ b/src/CraftSharp/Models/CurrentUser.cs @@ -6,6 +6,7 @@ public bool IsAuthenticated { get; set; } public string UserName { get; set; } public int NumberOfKeys { get; set; } = 0; + public int numberOfEmeralds { get; set; } = 250; public List Inventory { get; set; } = new List(); public List Roles { get; set; } = new List() { UserRoles.User }; diff --git a/src/CraftSharp/Models/ShopOfferModel.cs b/src/CraftSharp/Models/ShopOfferModel.cs new file mode 100644 index 0000000..e5b81bc --- /dev/null +++ b/src/CraftSharp/Models/ShopOfferModel.cs @@ -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; } + } +} diff --git a/src/CraftSharp/Pages/Opening.razor.cs b/src/CraftSharp/Pages/Opening.razor.cs index a7ca7cd..5347b86 100644 --- a/src/CraftSharp/Pages/Opening.razor.cs +++ b/src/CraftSharp/Pages/Opening.razor.cs @@ -44,7 +44,6 @@ namespace CraftSharp.Pages items = await DataService.List(0, totalItem); - var authState = await Context; NumberOfKeys = AuthService.GetCurrentUser().NumberOfKeys; } diff --git a/src/CraftSharp/Pages/Opening.razor.css b/src/CraftSharp/Pages/Opening.razor.css index 9dd2a89..dad262b 100644 --- a/src/CraftSharp/Pages/Opening.razor.css +++ b/src/CraftSharp/Pages/Opening.razor.css @@ -137,6 +137,7 @@ z-index: 10; width: 400px; padding-bottom: 7px; + user-select: none; } .item { diff --git a/src/CraftSharp/Pages/Shop.razor b/src/CraftSharp/Pages/Shop.razor new file mode 100644 index 0000000..d8cd0f7 --- /dev/null +++ b/src/CraftSharp/Pages/Shop.razor @@ -0,0 +1,32 @@ +@using CraftSharp.Components + +@page "/shop" + + + +
+ + +
+
+
+ +
+ + + +
+ @foreach(var offer in offers){ +
+ + +
+ } +
+
\ No newline at end of file diff --git a/src/CraftSharp/Pages/Shop.razor.cs b/src/CraftSharp/Pages/Shop.razor.cs new file mode 100644 index 0000000..0986aa6 --- /dev/null +++ b/src/CraftSharp/Pages/Shop.razor.cs @@ -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 Localizer { get; set; } + + [Inject] + public IJSRuntime JsRuntime { get; set; } + int NumberOfEmeralds { get; set; } = 0; + + List offers = new List() + { + 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 animation = new Dictionary(); + + 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(); + } + } + } +} diff --git a/src/CraftSharp/Pages/Shop.razor.css b/src/CraftSharp/Pages/Shop.razor.css new file mode 100644 index 0000000..902378d --- /dev/null +++ b/src/CraftSharp/Pages/Shop.razor.css @@ -0,0 +1,47 @@ +@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; + justify-content: center; +} + +.offers { + width: 50%; + display: flex; + flex-direction: column; + justify-content: space-evenly; +} + +.villager{ + width: 66% +} diff --git a/src/CraftSharp/Resources/Pages.Shop.fr-FR.resx b/src/CraftSharp/Resources/Pages.Shop.fr-FR.resx new file mode 100644 index 0000000..e539808 --- /dev/null +++ b/src/CraftSharp/Resources/Pages.Shop.fr-FR.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Acheter + + \ No newline at end of file diff --git a/src/CraftSharp/Resources/Pages.Shop.resx b/src/CraftSharp/Resources/Pages.Shop.resx new file mode 100644 index 0000000..dde836a --- /dev/null +++ b/src/CraftSharp/Resources/Pages.Shop.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Buy + + \ No newline at end of file diff --git a/src/CraftSharp/Resources/Pages.Shop.tr-TR.resx b/src/CraftSharp/Resources/Pages.Shop.tr-TR.resx new file mode 100644 index 0000000..a8a58fe --- /dev/null +++ b/src/CraftSharp/Resources/Pages.Shop.tr-TR.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Satın almak + + \ No newline at end of file diff --git a/src/CraftSharp/Resources/Shared.HeaderLayout.fr-FR.resx b/src/CraftSharp/Resources/Shared.HeaderLayout.fr-FR.resx index 238a0f5..18b1403 100644 --- a/src/CraftSharp/Resources/Shared.HeaderLayout.fr-FR.resx +++ b/src/CraftSharp/Resources/Shared.HeaderLayout.fr-FR.resx @@ -123,6 +123,9 @@ Se connecter + + Déconnexion + Ouverture @@ -132,6 +135,9 @@ Magasin + + + subtext_fr-FR diff --git a/src/CraftSharp/Resources/Shared.HeaderLayout.resx b/src/CraftSharp/Resources/Shared.HeaderLayout.resx index d975e18..1ed72cb 100644 --- a/src/CraftSharp/Resources/Shared.HeaderLayout.resx +++ b/src/CraftSharp/Resources/Shared.HeaderLayout.resx @@ -123,6 +123,9 @@ Login + + Logout + Opening diff --git a/src/CraftSharp/Resources/Shared.HeaderLayout.tr-TR.resx b/src/CraftSharp/Resources/Shared.HeaderLayout.tr-TR.resx index 9468275..f984165 100644 --- a/src/CraftSharp/Resources/Shared.HeaderLayout.tr-TR.resx +++ b/src/CraftSharp/Resources/Shared.HeaderLayout.tr-TR.resx @@ -123,6 +123,9 @@ Giriş yapmak + + Çıkış Yap + Açılış diff --git a/src/CraftSharp/Services/AuthService.cs b/src/CraftSharp/Services/AuthService.cs index 50c2c55..5652c56 100644 --- a/src/CraftSharp/Services/AuthService.cs +++ b/src/CraftSharp/Services/AuthService.cs @@ -11,23 +11,10 @@ namespace CraftSharp.Services static AuthService() { CurrentUser = new List - { - new AppUser { UserName = "Admin", Password = "123456", Roles = new List { 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 !"); - } - - return user; - }*/ - - + new AppUser { UserName = "Admin", Password = "123456", Roles = new List { UserRoles.Admin }, numberOfKeys=999 } + }; + } public CurrentUser GetUser(string userName) { var user = CurrentUser.FirstOrDefault(w => w.UserName == userName); @@ -45,6 +32,7 @@ namespace CraftSharp.Services IsAuthenticated = true, UserName = user.UserName, NumberOfKeys = user.numberOfKeys, + numberOfEmeralds = user.numberOfEmeralds, Inventory = user.inventory, Roles = user.Roles, Claims = claims.ToDictionary(c => c.Type, c => c.Value) diff --git a/src/CraftSharp/Services/CustomStateProvider.cs b/src/CraftSharp/Services/CustomStateProvider.cs index bedf535..059cab0 100644 --- a/src/CraftSharp/Services/CustomStateProvider.cs +++ b/src/CraftSharp/Services/CustomStateProvider.cs @@ -14,8 +14,7 @@ namespace CraftSharp.Services { private readonly IAuthService _authService; - [CascadingParameter] - public CurrentUser UserObject { get; set; } + private CurrentUser _currentUser { get; set; } public CustomStateProvider(IAuthService authService) { @@ -30,7 +29,7 @@ namespace CraftSharp.Services var userInfo = GetCurrentUser(); if (userInfo.IsAuthenticated) { - var claims = new[] { new Claim(ClaimTypes.Name, UserObject.UserName) }.Concat(UserObject.Claims.Select(c => new Claim(c.Key, c.Value))); + var claims = new[] { new Claim(ClaimTypes.Name, _currentUser.UserName) }.Concat(_currentUser.Claims.Select(c => new Claim(c.Key, c.Value))); identity = new ClaimsIdentity(claims, "Server authentication"); } } @@ -48,15 +47,14 @@ namespace CraftSharp.Services // No error - Login the user CurrentUser user; user = _authService.GetUser(loginParameters.UserName); - UserObject = user; - Console.WriteLine("\t\tLOGIN: " + UserObject.UserName); + _currentUser = user; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } public async Task Logout() { - UserObject = new CurrentUser(); + _currentUser = new CurrentUser(); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } @@ -66,7 +64,7 @@ namespace CraftSharp.Services // No error - Login the user var user = _authService.GetUser(registerParameters.UserName); - UserObject = user; + _currentUser = user; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } @@ -74,10 +72,9 @@ namespace CraftSharp.Services { CurrentUser cacheUser; - if (UserObject != null && UserObject.IsAuthenticated) + if (_currentUser != null && _currentUser.IsAuthenticated) { - Console.WriteLine("Return user"); - return UserObject; + return _currentUser; } return new CurrentUser(); } diff --git a/src/CraftSharp/Services/IAuthService.cs b/src/CraftSharp/Services/IAuthService.cs index 255eb81..605a089 100644 --- a/src/CraftSharp/Services/IAuthService.cs +++ b/src/CraftSharp/Services/IAuthService.cs @@ -5,9 +5,7 @@ namespace CraftSharp.Services public interface IAuthService { CurrentUser GetUser(string userName); - void Login(ConnexionModel loginRequest); - void Register(InscriptionModel registerRequest); } } diff --git a/src/CraftSharp/Shared/CultureSelector.razor.cs b/src/CraftSharp/Shared/CultureSelector.razor.cs index b343a6c..3437287 100644 --- a/src/CraftSharp/Shared/CultureSelector.razor.cs +++ b/src/CraftSharp/Shared/CultureSelector.razor.cs @@ -30,6 +30,7 @@ namespace CraftSharp.Shared // Redirect the user to the culture controller to set the cookie this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); + } } } diff --git a/src/CraftSharp/Shared/HeaderLayout.razor b/src/CraftSharp/Shared/HeaderLayout.razor index b6bd972..478361c 100644 --- a/src/CraftSharp/Shared/HeaderLayout.razor +++ b/src/CraftSharp/Shared/HeaderLayout.razor @@ -53,7 +53,7 @@ } - + diff --git a/src/CraftSharp/Shared/HeaderLayout.razor.css b/src/CraftSharp/Shared/HeaderLayout.razor.css index 8b8413b..606c267 100644 --- a/src/CraftSharp/Shared/HeaderLayout.razor.css +++ b/src/CraftSharp/Shared/HeaderLayout.razor.css @@ -98,7 +98,7 @@ button:hover { .nav-item { font-size: 1.1rem; padding-bottom: 0.5rem; - font-family: SuperDario; + font-family: Minecraft; } .nav-item:first-of-type { diff --git a/src/CraftSharp/wwwroot/Images/villager.png b/src/CraftSharp/wwwroot/Images/villager.png new file mode 100644 index 0000000..238a501 Binary files /dev/null and b/src/CraftSharp/wwwroot/Images/villager.png differ