Initial commit
This commit is contained in:
136
C#/FiveM/CardealerClient/Menus/OwnerMenu.cs
Normal file
136
C#/FiveM/CardealerClient/Menus/OwnerMenu.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Nexd.ESX.Client;
|
||||
using static CitizenFX.Core.Native.API;
|
||||
|
||||
namespace CardealerClient.Menus {
|
||||
public class OwnerMenu {
|
||||
|
||||
public static async void Open() {
|
||||
List<VehicleData> vehicles = (await CarDealer.ServerCallback("cardealer:getOwnVehicles") as List<object>).Select(x => new VehicleData(x)).ToList();
|
||||
if (vehicles.Count == 0) {
|
||||
CarDealer.Notify("Du hast keine Fahrzeuge!", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
dynamic menuData = new ExpandoObject();
|
||||
|
||||
menuData.title = Config.MenuTitle;
|
||||
menuData.align = "top-left";
|
||||
menuData.elements = await GenerateMenuElements(vehicles);
|
||||
|
||||
ESX.UI.Menu.CloseAll();
|
||||
ESX.UI.Menu.Raw.Open("default", GetCurrentResourceName(), "cardealer_owner_menu", menuData,
|
||||
new Action<dynamic, dynamic>((data, menu) => {
|
||||
VehicleData vehicle = vehicles[Convert.ToInt32(data.current.name)];
|
||||
|
||||
OpenSubMenu(vehicle, data.current.vehicle);
|
||||
}), new Action<dynamic, dynamic>((o, o1) => {
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(o1));
|
||||
}));
|
||||
}
|
||||
|
||||
private static void OpenSubMenu(VehicleData vehicle, string name) {
|
||||
dynamic menuData = new ExpandoObject();
|
||||
|
||||
menuData.title = Config.MenuTitle + " - " + name;
|
||||
menuData.align = "top-left";
|
||||
menuData.elements = GenerateSubMenuElements(vehicle);
|
||||
|
||||
ESX.UI.Menu.Raw.Open("default", GetCurrentResourceName(), "cardealer_owner_vehicle_menu", menuData,
|
||||
new Action<dynamic, dynamic>(async (data, menu) => {
|
||||
|
||||
if (data.current.name == "DELETE") {
|
||||
if (await CarDealer.DisplayConfirmationDialog("Möchtest du dieses Auto wirklich löschen?")) {
|
||||
vehicle.Delete();
|
||||
ESX.UI.Menu.CloseAll();
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.current.name == "CHANGE_PRICE") {
|
||||
vehicle.Price = Convert.ToInt32(await CarDealer.DisplayTextDialog(vehicle.Price.ToString(), 7));
|
||||
if (vehicle.Price < Config.MinSellPrice)
|
||||
CarDealer.SendNotification("~r~Dein Auto muss mindestens ~s~$" + Config.MinSellPrice + " ~r~kosten!");
|
||||
else vehicle.UpdateSlot();
|
||||
}
|
||||
|
||||
if (data.current.name == "DESCRIPTION") {
|
||||
vehicle.Description = await CarDealer.DisplayTextDialog(vehicle.Description, 60);
|
||||
vehicle.UpdateSlot();
|
||||
}
|
||||
|
||||
if (data.current.name == "PUSH_TO_EXHIBIT") {
|
||||
if (await CarDealer.DisplayConfirmationDialog("Möchtest du dieses Auto wirklich ausstellen?")) {
|
||||
ESX.UI.Menu.CloseAll();
|
||||
|
||||
bool money = await CarDealer.ServerCallback("cardealer:checkMoney", Config.ExhibitPrice);
|
||||
if (!money) {
|
||||
CarDealer.Notify("Du hast nicht genug Geld!", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = await vehicle.PushToExhibit();
|
||||
|
||||
if (!success)
|
||||
CarDealer.Notify("Alle Stellplätze sind belegt, Dein Auto bleibt im Katalog, bis ein Stellplatz frei wird", "error");
|
||||
else
|
||||
CarDealer.Notify("Das Auto wurde ausgestellt!", "success");
|
||||
}
|
||||
}
|
||||
|
||||
}), new Action<dynamic, dynamic>((o, o1) => {
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(o1));
|
||||
}));
|
||||
}
|
||||
|
||||
private static async Task<dynamic[]> GenerateMenuElements(List<VehicleData> infos) {
|
||||
dynamic[] elements = new dynamic[infos.Count];
|
||||
List<string> names = await CarDealer.GetVehicleNames(infos.Select(info => info.Properties.Raw.model).ToArray());
|
||||
|
||||
for (var i = 0; i < infos.Count; i++) {
|
||||
dynamic data = new ExpandoObject();
|
||||
|
||||
data.name = i;
|
||||
data.label = names[i] + " - $" + infos[i].Price;
|
||||
data.vehicle = names[i];
|
||||
|
||||
elements[i] = data;
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static dynamic[] GenerateSubMenuElements(VehicleData data) {
|
||||
List<dynamic> elements = new List<dynamic>();
|
||||
|
||||
if (data.ParkingSpace == 1) {
|
||||
dynamic exhibit = new ExpandoObject();
|
||||
exhibit.name = "PUSH_TO_EXHIBIT";
|
||||
exhibit.label = $"Ausstellen (${Config.ExhibitPrice})";
|
||||
elements.Add(exhibit);
|
||||
}
|
||||
|
||||
dynamic price = new ExpandoObject();
|
||||
price.name = "CHANGE_PRICE";
|
||||
price.label = "Preis ändern";
|
||||
elements.Add(price);
|
||||
|
||||
dynamic desc = new ExpandoObject();
|
||||
desc.name = "DESCRIPTION";
|
||||
desc.label = "Beschreibung ändern";
|
||||
elements.Add(desc);
|
||||
|
||||
dynamic delete = new ExpandoObject();
|
||||
delete.name = "DELETE";
|
||||
delete.label = "Löschen";
|
||||
elements.Add(delete);
|
||||
|
||||
return elements.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
102
C#/FiveM/CardealerClient/Menus/SellMenu.cs
Normal file
102
C#/FiveM/CardealerClient/Menus/SellMenu.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using static CitizenFX.Core.Native.API;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace CardealerClient.Menus {
|
||||
public class SellMenu {
|
||||
|
||||
public static async void Open() {
|
||||
string plate = ESX.Game.GetVehicleProperties(new Vehicle(GetVehiclePedIsIn(GetPlayerPed(-1), false))).plate;
|
||||
bool owned = await CarDealer.ServerCallback("cardealer:checkOwner", plate);
|
||||
|
||||
if (owned) {
|
||||
int vehicle = GetVehiclePedIsIn(GetPlayerPed(-1), true);
|
||||
|
||||
int vehicleClass = GetVehicleClass(vehicle);
|
||||
if (Config.ForbittenVehicleClasses.Contains(vehicleClass)) {
|
||||
CarDealer.Notify("Du kannst dieses Fahrzeug nicht verkaufen.", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
FreezeEntityPosition(vehicle, true);
|
||||
CarDealer.MenuOpen = true;
|
||||
ESX.UI.Menu.CloseAll();
|
||||
dynamic menuData = new ExpandoObject();
|
||||
SellData sellData = new SellData();
|
||||
|
||||
menuData.title = Config.MenuTitle;
|
||||
menuData.align = "top-left";
|
||||
menuData.elements = new dynamic[4];
|
||||
menuData.elements[0] = MenuElements.GetElement_Parkingspace();
|
||||
menuData.elements[1] = MenuElements.GetElement_Description();
|
||||
menuData.elements[2] = MenuElements.GetElement_Price();
|
||||
menuData.elements[3] = MenuElements.GetElement_Finish();
|
||||
|
||||
ESX.UI.Menu.Raw.Open("default", GetCurrentResourceName(), "cardealer_menu", menuData,
|
||||
new Action<dynamic, dynamic>(async (data, menu) => {
|
||||
|
||||
if (data.current.name == "choose_description") {
|
||||
sellData.Description = await CarDealer.DisplayTextDialog("Beschreibung hinzufügen", 60);
|
||||
}
|
||||
|
||||
if (data.current.name == "choose_price") {
|
||||
sellData.Price = Convert.ToInt32(await CarDealer.DisplayTextDialog("Preis", 7));
|
||||
}
|
||||
|
||||
if (data.current.name == "finish") {
|
||||
sellData.ParkingSpace = data.elements[0].value;
|
||||
if (sellData.Price == 0)
|
||||
CarDealer.SendNotification("~r~Lege zuerst einen Preis fest!");
|
||||
else if (sellData.Price < Config.MinSellPrice)
|
||||
CarDealer.SendNotification("~r~Dein Auto muss mindestens ~s~$" + Config.MinSellPrice + " ~r~kosten!");
|
||||
else {
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(menu));
|
||||
|
||||
if (sellData.ParkingSpace == 0) {
|
||||
bool money = await CarDealer.ServerCallback("cardealer:checkMoney", Config.ExhibitPrice);
|
||||
if (!money) {
|
||||
CarDealer.Notify("Du hast nicht genug Geld!", "error");
|
||||
CarDealer.MenuOpen = false;
|
||||
FreezeEntityPosition(vehicle, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetVehicleEngineHealth(vehicle, 1000);
|
||||
SetVehicleEngineOn(vehicle, false, false, true);
|
||||
SetVehicleFixed(vehicle);
|
||||
SetVehicleDirtLevel(vehicle, 0);
|
||||
VehicleProperties props = ESX.Game.GetVehicleProperties(vehicle);
|
||||
props.plate = GetVehicleNumberPlateText(vehicle);
|
||||
if (sellData.ParkingSpace == 0)
|
||||
sellData.Slot = 1;
|
||||
|
||||
BaseScript.TriggerServerEvent("esx_vehicleshop:deleteVehicle", props.plate);
|
||||
bool success = await CarDealer.ServerCallback("cardealer:saveVehicle", sellData.CreateDynamic(props.Raw)) || sellData.ParkingSpace == 1;
|
||||
ESX.Game.DeleteVehicle(GetVehiclePedIsIn(GetPlayerPed(-1), true).ToString());
|
||||
CarDealer.MenuOpen = false;
|
||||
|
||||
if (success)
|
||||
CarDealer.Notify("Auto ausgestellt!", "success");
|
||||
else
|
||||
CarDealer.Notify("Alle Stellplätze sind belegt, Dein Auto kommt in den Katalog, bis ein Stellplatz frei wird", "error");
|
||||
}
|
||||
}
|
||||
}), new Action<dynamic, dynamic>((o, o1) => {
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(o1));
|
||||
CarDealer.MenuOpen = false;
|
||||
FreezeEntityPosition(vehicle, false);
|
||||
})
|
||||
);
|
||||
}
|
||||
else {
|
||||
CarDealer.Notify("Dieses Auto gehört dir nicht!", "error");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user