Add Paycheck to interaction menu

This commit is contained in:
hydrant
2019-07-30 19:05:49 +02:00
parent db005f30fc
commit 933760d773
6 changed files with 74 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import * as NativeUI from 'NativeUI'; import * as NativeUI from 'NativeUI';
import InputHelper from '../inputhelper'; import InputHelper from '../inputhelper';
import moneyFormat from '../moneyformat';
const Menu = NativeUI.Menu; const Menu = NativeUI.Menu;
const UIMenuItem = NativeUI.UIMenuItem; const UIMenuItem = NativeUI.UIMenuItem;
@@ -23,6 +24,8 @@ export default function (globalData: GlobalData) {
var factionItem = new UIMenuItem("Fraktion", "Verwalte deine Fraktion"); var factionItem = new UIMenuItem("Fraktion", "Verwalte deine Fraktion");
var groupItem = new UIMenuItem("Gruppe", "Verwalte deine Gruppe"); 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) => { mp.events.add("SERVER:InteractionMenu_OpenMenu", (accountDataJson: string, faction: string, group: string, factionInvite: boolean, groupInvite: boolean) => {
var accountData: AccountData = JSON.parse(accountDataJson); var accountData: AccountData = JSON.parse(accountDataJson);
@@ -48,6 +51,39 @@ export default function (globalData: GlobalData) {
menu.BindMenuToItem(getGroupMenu(group, menu), groupItem); 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<string> = new Array<string>(); var items: Array<string> = new Array<string>();
if (factionInvite) items.push("Fraktion"); if (factionInvite) items.push("Fraktion");
if (groupInvite) items.push("Gruppe"); if (groupInvite) items.push("Gruppe");
@@ -58,8 +94,7 @@ export default function (globalData: GlobalData) {
menu.AddItem(acceptItem); menu.AddItem(acceptItem);
} }
menu.Visible = true; menu.Open();
mp.gui.chat.show(false);
globalData.InMenu = true; globalData.InMenu = true;
menu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => { menu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => {
@@ -71,7 +106,6 @@ export default function (globalData: GlobalData) {
menu.MenuClose.on(() => { menu.MenuClose.on(() => {
globalData.InMenu = false; globalData.InMenu = false;
mp.gui.chat.show(true);
}) })
}); });

View File

@@ -15,6 +15,17 @@ declare interface AccountData {
group: string; group: string;
groupRank: string; groupRank: string;
job: 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 { declare interface FactionRanks {

View File

@@ -46,6 +46,7 @@
this.browser.destroy(); this.browser.destroy();
this.data.InInput = false; this.data.InInput = false;
this.created = false; this.created = false;
this.browser = null;
} }
} }
@@ -60,9 +61,10 @@
private valueGetter(): Promise<string> { private valueGetter(): Promise<string> {
return new Promise(resolve => { return new Promise(resolve => {
setInterval(() => { while (this.value !== undefined) {
if (this.value !== undefined) resolve(this.value); mp.game.wait(1);
}, 50); }
resolve(this.value);
}); });
} }

View File

@@ -6,6 +6,7 @@ using ReallifeGamemode.Server.Classes;
using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Inventory; using ReallifeGamemode.Server.Inventory;
using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.Models; using ReallifeGamemode.Server.Models;
@@ -105,6 +106,9 @@ namespace ReallifeGamemode.Server.Events
User u = player.GetUser(); User u = player.GetUser();
if (u == null) return; if (u == null) return;
Paycheck paycheck = null;
if (Economy.Paychecks.ContainsKey(u.Id)) paycheck = Economy.Paychecks[u.Id];
var accountData = new var accountData = new
{ {
regDate = u.RegistrationDate.ToShortDateString(), regDate = u.RegistrationDate.ToShortDateString(),
@@ -113,7 +117,8 @@ namespace ReallifeGamemode.Server.Events
factionRank = u.GetFactionRank().RankName, factionRank = u.GetFactionRank().RankName,
group = u.Group?.Name ?? "Keine", group = u.Group?.Name ?? "Keine",
groupRank = u.GroupRank.GetName(), 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; string faction = u.FactionLeader ? u.Faction.Name : null;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using GTANetworkAPI; using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Models; using ReallifeGamemode.Server.Models;
@@ -12,12 +13,25 @@ namespace ReallifeGamemode.Server.Finance
{ {
public class Paycheck public class Paycheck
{ {
[JsonProperty("financialHelp")]
public float FinancialHelp { get; set; } = 0; public float FinancialHelp { get; set; } = 0;
[JsonProperty("financialInterest")]
public float FinancialInterest { get; set; } = 0; public float FinancialInterest { get; set; } = 0;
[JsonProperty("vehicleTaxation")]
public int VehicleTaxation { get; set; } = 0; public int VehicleTaxation { get; set; } = 0;
[JsonProperty("propertyTaxation")]
public float PropertyTaxation { get; set; } = 0; public float PropertyTaxation { get; set; } = 0;
[JsonProperty("wage")]
public int Wage { get; set; } = 0; public int Wage { get; set; } = 0;
[JsonProperty("amount")]
public int Amount { get; set; } = 0; public int Amount { get; set; } = 0;
[JsonProperty("rentalFees")]
public int RentalFees { get; set; } = 0; public int RentalFees { get; set; } = 0;
public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees) public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees)