From 933760d7732a9f0a21cccb69e37f6e3b54388aba Mon Sep 17 00:00:00 2001 From: hydrant Date: Tue, 30 Jul 2019 19:05:49 +0200 Subject: [PATCH] Add Paycheck to interaction menu --- .../Interaction/interactionmenu.ts | 40 +++++++++++++++++-- ReallifeGamemode.Client/global.d.ts | 11 +++++ ReallifeGamemode.Client/inputhelper/index.ts | 8 ++-- .../Commands/UserCommands.cs | 2 +- ReallifeGamemode.Server/Events/Key.cs | 7 +++- ReallifeGamemode.Server/Finance/Paycheck.cs | 14 +++++++ 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/ReallifeGamemode.Client/Interaction/interactionmenu.ts b/ReallifeGamemode.Client/Interaction/interactionmenu.ts index df262fb9..68ef8de9 100644 --- a/ReallifeGamemode.Client/Interaction/interactionmenu.ts +++ b/ReallifeGamemode.Client/Interaction/interactionmenu.ts @@ -1,5 +1,6 @@ import * as NativeUI from 'NativeUI'; import InputHelper from '../inputhelper'; +import moneyFormat from '../moneyformat'; const Menu = NativeUI.Menu; const UIMenuItem = NativeUI.UIMenuItem; @@ -23,6 +24,8 @@ export default function (globalData: GlobalData) { var factionItem = new UIMenuItem("Fraktion", "Verwalte deine Fraktion"); var groupItem = new UIMenuItem("Gruppe", "Verwalte deine Gruppe"); + var paycheckItem = new UIMenuItem("Gehaltsscheck", "Schaue dir deinen Verdienst der letzten Stunde an"); + mp.events.add("SERVER:InteractionMenu_OpenMenu", (accountDataJson: string, faction: string, group: string, factionInvite: boolean, groupInvite: boolean) => { var accountData: AccountData = JSON.parse(accountDataJson); @@ -48,6 +51,39 @@ export default function (globalData: GlobalData) { menu.BindMenuToItem(getGroupMenu(group, menu), groupItem); } + if (accountData.paycheck) { + var p = accountData.paycheck; + var paycheckMenu = new Menu("Gehaltsscheck", "Dein Verdienst der letzten Stunde", new Point(50, 50), null, null); + paycheckMenu.Visible = false; + + var item: NativeUI.UIMenuItem = new UIMenuItem("Lohn"); + item.SetRightLabel("~g~+ $" + moneyFormat(p.wage)); + paycheckMenu.AddItem(item); + + item = new UIMenuItem("Finanzhilfe"); + item.SetRightLabel("~g~+ $" + moneyFormat(p.financialHelp)); + paycheckMenu.AddItem(item); + + item = new UIMenuItem("Fahrzeugsteuer"); + item.SetRightLabel("~r~- $" + moneyFormat(p.vehicleTaxation)); + paycheckMenu.AddItem(item); + + item = new UIMenuItem("Grundsteuer"); + item.SetRightLabel("~r~- $" + moneyFormat(p.propertyTaxation)); + paycheckMenu.AddItem(item); + + item = new UIMenuItem("Mietkosten"); + item.SetRightLabel("~r~- $" + moneyFormat(p.rentalFees)); + paycheckMenu.AddItem(item); + + item = new UIMenuItem("Einkommenssteuer"); + item.SetRightLabel((p.financialInterest * 100).toString() + "%"); + paycheckMenu.AddItem(item); + + menu.AddItem(paycheckItem); + menu.BindMenuToItem(paycheckMenu, paycheckItem); + } + var items: Array = new Array(); if (factionInvite) items.push("Fraktion"); if (groupInvite) items.push("Gruppe"); @@ -58,8 +94,7 @@ export default function (globalData: GlobalData) { menu.AddItem(acceptItem); } - menu.Visible = true; - mp.gui.chat.show(false); + menu.Open(); globalData.InMenu = true; menu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => { @@ -71,7 +106,6 @@ export default function (globalData: GlobalData) { menu.MenuClose.on(() => { globalData.InMenu = false; - mp.gui.chat.show(true); }) }); diff --git a/ReallifeGamemode.Client/global.d.ts b/ReallifeGamemode.Client/global.d.ts index 9c3e391d..fe4c05c1 100644 --- a/ReallifeGamemode.Client/global.d.ts +++ b/ReallifeGamemode.Client/global.d.ts @@ -15,6 +15,17 @@ declare interface AccountData { group: string; groupRank: string; job: string; + paycheck: Paycheck; +} + +declare interface Paycheck { + financialHelp: number; + financialInterest: number; + vehicleTaxation: number; + propertyTaxation: number; + wage: number; + amount: number; + rentalFees: number; } declare interface FactionRanks { diff --git a/ReallifeGamemode.Client/inputhelper/index.ts b/ReallifeGamemode.Client/inputhelper/index.ts index 78296256..9e717d0a 100644 --- a/ReallifeGamemode.Client/inputhelper/index.ts +++ b/ReallifeGamemode.Client/inputhelper/index.ts @@ -46,6 +46,7 @@ this.browser.destroy(); this.data.InInput = false; this.created = false; + this.browser = null; } } @@ -60,9 +61,10 @@ private valueGetter(): Promise { return new Promise(resolve => { - setInterval(() => { - if (this.value !== undefined) resolve(this.value); - }, 50); + while (this.value !== undefined) { + mp.game.wait(1); + } + resolve(this.value); }); } diff --git a/ReallifeGamemode.Server/Commands/UserCommands.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs index 35109697..d339cd29 100644 --- a/ReallifeGamemode.Server/Commands/UserCommands.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -45,7 +45,7 @@ namespace ReallifeGamemode.Server.Commands ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Grundsteuer (Haus) : ~r~-$" + Economy.Paychecks[user.Id].PropertyTaxation); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Mietkosten : ~r~-$" + Economy.Paychecks[user.Id].RentalFees); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Einkommen Steuer : ~r~" + (int)(Economy.Paychecks[user.Id].FinancialInterest * 100) + " %"); - ChatService.SendMessage(client, ""); + ChatService.SendMessage(client, " "); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Ausgaben : ~r~-$" + (Economy.Paychecks[user.Id].Wage - Economy.Paychecks[user.Id].Amount)); ChatService.SendMessage(client, "~g~[PAYCHECK] -------------------------------------------------------"); } diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 833040ad..e9e70dca 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -6,6 +6,7 @@ using ReallifeGamemode.Server.Classes; using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Factions.Medic; +using ReallifeGamemode.Server.Finance; using ReallifeGamemode.Server.Inventory; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Models; @@ -105,6 +106,9 @@ namespace ReallifeGamemode.Server.Events User u = player.GetUser(); if (u == null) return; + Paycheck paycheck = null; + if (Economy.Paychecks.ContainsKey(u.Id)) paycheck = Economy.Paychecks[u.Id]; + var accountData = new { regDate = u.RegistrationDate.ToShortDateString(), @@ -113,7 +117,8 @@ namespace ReallifeGamemode.Server.Events factionRank = u.GetFactionRank().RankName, group = u.Group?.Name ?? "Keine", groupRank = u.GroupRank.GetName(), - job = JobManager.GetJob(u.JobId ?? 0)?.Name ?? "Keiner" + job = JobManager.GetJob(u.JobId ?? 0)?.Name ?? "Keiner", + paycheck }; string faction = u.FactionLeader ? u.Faction.Name : null; diff --git a/ReallifeGamemode.Server/Finance/Paycheck.cs b/ReallifeGamemode.Server/Finance/Paycheck.cs index 58619e0c..678cb0ae 100644 --- a/ReallifeGamemode.Server/Finance/Paycheck.cs +++ b/ReallifeGamemode.Server/Finance/Paycheck.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using GTANetworkAPI; +using Newtonsoft.Json; using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Models; @@ -12,12 +13,25 @@ namespace ReallifeGamemode.Server.Finance { public class Paycheck { + [JsonProperty("financialHelp")] public float FinancialHelp { get; set; } = 0; + + [JsonProperty("financialInterest")] public float FinancialInterest { get; set; } = 0; + + [JsonProperty("vehicleTaxation")] public int VehicleTaxation { get; set; } = 0; + + [JsonProperty("propertyTaxation")] public float PropertyTaxation { get; set; } = 0; + + [JsonProperty("wage")] public int Wage { get; set; } = 0; + + [JsonProperty("amount")] public int Amount { get; set; } = 0; + + [JsonProperty("rentalFees")] public int RentalFees { get; set; } = 0; public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees)