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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user