Update 29.10.2022
This commit is contained in:
204
C#/Mosleys/Mosleys.Client/ExhibitHandler.cs
Normal file
204
C#/Mosleys/Mosleys.Client/ExhibitHandler.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using CitizenFX.Core.UI;
|
||||
using Mosleys.Client.Extensions;
|
||||
using Mosleys.Client.Models;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public static class ExhibitHandler {
|
||||
public static bool ExhibitsSpawned = false;
|
||||
public static bool CatalogOpen = false;
|
||||
|
||||
private static Exhibit[] _realExhibits;
|
||||
|
||||
public static void OnTick() {
|
||||
// Digital Exhibit
|
||||
var dist = World.GetDistance(Game.Player.Character.Position, Mosleys.Config.DigitalShowPoint);
|
||||
if (dist <= 2.0f && !CatalogOpen) {
|
||||
Screen.DisplayHelpTextThisFrame("Drücke ~INPUT_CONTEXT~ um den Katalog zu öffnen");
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.Context))
|
||||
OpenCatalog();
|
||||
}
|
||||
|
||||
// Real Exhibits
|
||||
if (!ExhibitsSpawned) return;
|
||||
|
||||
Exhibit closestExhibit = new Exhibit();
|
||||
float closestDist = float.MaxValue;
|
||||
bool foundClosest = false;
|
||||
foreach (var exhibit in _realExhibits) {
|
||||
if (exhibit?.Ready != true) continue;
|
||||
exhibit.Vehicle?.Repair();
|
||||
dist = World.GetDistance(Game.Player.Character.Position, exhibit.Location.ToVector3());
|
||||
if (dist <= 5.0f && dist < closestDist) {
|
||||
closestDist = dist;
|
||||
closestExhibit = exhibit;
|
||||
foundClosest = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundClosest) return;
|
||||
closestExhibit.ShowText();
|
||||
|
||||
if (closestExhibit.TestDrive) return;
|
||||
if (Game.IsControlJustReleased(0, Control.Enter))
|
||||
closestExhibit.StartTestDrive();
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.Context))
|
||||
closestExhibit.Buy();
|
||||
}
|
||||
|
||||
public static async void SpawnExhibits() {
|
||||
var exhibits = await Utils.GetAllExhibits();
|
||||
_realExhibits = new Exhibit[Mosleys.Config.CarSlots.Length];
|
||||
|
||||
for (int i = 0; i < exhibits.Length; i++) {
|
||||
var exhibit = exhibits[i];
|
||||
if (exhibit.Slot == 0) continue;
|
||||
|
||||
var realExhibit = new Exhibit {
|
||||
Uuid = exhibit.Uuid,
|
||||
Owner = exhibit.Owner,
|
||||
Description = exhibit.Description,
|
||||
Price = exhibit.Price,
|
||||
Slot = exhibit.Slot,
|
||||
Location = Mosleys.Config.CarSlots[exhibit.Slot],
|
||||
Properties = new VehicleProperties(exhibit.Vehicle),
|
||||
TestDrive = exhibit.TestDrive
|
||||
};
|
||||
|
||||
if (!exhibit.TestDrive)
|
||||
realExhibit.Spawn();
|
||||
else realExhibit.Ready = true;
|
||||
_realExhibits[exhibit.Slot] = realExhibit;
|
||||
}
|
||||
|
||||
ExhibitsSpawned = true;
|
||||
}
|
||||
|
||||
public static void Cleanup() {
|
||||
ExhibitsSpawned = false;
|
||||
foreach (var exhibit in _realExhibits) {
|
||||
exhibit?.Despawn();
|
||||
}
|
||||
|
||||
_realExhibits = null;
|
||||
}
|
||||
|
||||
public static void UpdateSlot(int slot) {
|
||||
if (!ExhibitsSpawned) return;
|
||||
if (_realExhibits[slot] == null)
|
||||
_realExhibits[slot] = new Exhibit { Slot = slot };
|
||||
|
||||
_realExhibits[slot].Update();
|
||||
}
|
||||
|
||||
public static void OnRemove(int slot) {
|
||||
if (!ExhibitsSpawned || _realExhibits[slot] == null) return;
|
||||
_realExhibits[slot].Despawn();
|
||||
_realExhibits[slot] = null;
|
||||
}
|
||||
|
||||
private static async void OpenCatalog(string vehicleUuid = null) {
|
||||
if (CatalogOpen) return;
|
||||
CatalogOpen = true;
|
||||
Screen.ShowNotification("Lade Katalog...");
|
||||
var exhibits = (await Utils.GetAllExhibits()).Where(exhibit => exhibit.Slot == 0).ToArray();
|
||||
|
||||
if (exhibits.Length == 0) {
|
||||
Notify.Error("Es gibt zur Zeit keine Autos im Katalog!");
|
||||
CatalogOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ESX.UI.Menu.CloseAll();
|
||||
Game.Player.Character.Freeze(true);
|
||||
var camera = World.CreateCamera(Mosleys.Config.DigitalCamera.ToVector3(),
|
||||
new Vector3(0, 0, Mosleys.Config.DigitalCamera.W), API.GetGameplayCamFov());
|
||||
camera.PointAt(Mosleys.Config.CarSlots[0].ToVector3() + new Vector3(0, 0, 1.0f));
|
||||
camera.IsActive = true;
|
||||
API.RenderScriptCams(true, false, 0, true, true);
|
||||
|
||||
var index = 0;
|
||||
if (vehicleUuid != null) {
|
||||
if (exhibits.Any(exhibit => exhibit.Uuid == vehicleUuid))
|
||||
index = exhibits.ToList().FindIndex(exhibit => exhibit.Uuid == vehicleUuid);
|
||||
}
|
||||
|
||||
var currentCar = new Exhibit { Slot = 0 };
|
||||
currentCar.FromExhibit(exhibits[index]);
|
||||
|
||||
var carNames = exhibits.Select(exhibit => exhibit.DisplayName()).ToArray();
|
||||
var menuData = new ESX.UI.MenuData() {
|
||||
title = Mosleys.Config.MenuTitle,
|
||||
align = "top-left",
|
||||
elements = new List<ESX.UI.MenuElement> {
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Auto",
|
||||
name = "car",
|
||||
value = index,
|
||||
options = carNames,
|
||||
type = "slider"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Probefahrt",
|
||||
name = "testdrive",
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Kaufen",
|
||||
name = "buy"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "digital_exhibits", menuData, async (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
|
||||
if (data.current.name == "testdrive") {
|
||||
menu.Close();
|
||||
CatalogOpen = false;
|
||||
await currentCar.StartTestDrive(false);
|
||||
OpenCatalog(currentCar.Uuid);
|
||||
}
|
||||
|
||||
if (data.current.name == "buy") {
|
||||
menu.Close();
|
||||
CatalogOpen = false;
|
||||
currentCar.Buy();
|
||||
}
|
||||
}, (dData, dMenu) => {
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
menu.Close();
|
||||
CatalogOpen = false;
|
||||
}, (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
|
||||
if (data.current.name == "car") {
|
||||
var newCar = exhibits[data.elements[0].value];
|
||||
if (currentCar.Uuid == newCar.Uuid) return;
|
||||
|
||||
currentCar.Despawn();
|
||||
currentCar.FromExhibit(newCar);
|
||||
}
|
||||
});
|
||||
|
||||
while (CatalogOpen) {
|
||||
currentCar.ShowText(false, 2.5f, 0.15f);
|
||||
await BaseScript.Delay(0);
|
||||
}
|
||||
|
||||
API.RenderScriptCams(false, false, 0, true, true);
|
||||
camera.IsActive = false;
|
||||
camera.Delete();
|
||||
Game.Player.Character.Freeze(false);
|
||||
currentCar.Despawn();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using CitizenFX.Core.Native;
|
||||
using Mosleys.Shared.Models;
|
||||
|
||||
namespace Mosleys.Client.Extensions {
|
||||
public static class ExhibitVehicleExtensions {
|
||||
|
||||
public static string DisplayName(this ExhibitVehicle exhibit) =>
|
||||
API.GetDisplayNameFromVehicleModel(Convert.ToUInt32((exhibit.Vehicle as dynamic).model));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using CitizenFX.Core;
|
||||
|
||||
namespace Mosleys.Client.Extensions {
|
||||
public static class Vector4Extensions {
|
||||
|
||||
public static Vector3 ToVector3(this Vector4 vector) => new Vector3(vector.X, vector.Y, vector.Z);
|
||||
|
||||
}
|
||||
}
|
||||
23
C#/Mosleys/Mosleys.Client/Extensions/VehicleExtensions.cs
Normal file
23
C#/Mosleys/Mosleys.Client/Extensions/VehicleExtensions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
|
||||
namespace Mosleys.Client.Extensions {
|
||||
public static class VehicleExtensions {
|
||||
|
||||
public static void Freeze(this Entity vehicle, bool toggle) => API.FreezeEntityPosition(vehicle.Handle, toggle);
|
||||
|
||||
public static void SetDoorLockStatus(this Vehicle vehicle, LockStatus status) => API.SetVehicleDoorsLocked(vehicle.Handle, (int)status);
|
||||
|
||||
}
|
||||
|
||||
public enum LockStatus {
|
||||
None,
|
||||
Unlocked,
|
||||
Locked,
|
||||
LockForPlayers,
|
||||
LockForInVehicle,
|
||||
LockedInitially,
|
||||
ForceShutDoors,
|
||||
LockedButCanBeDamaged
|
||||
}
|
||||
}
|
||||
202
C#/Mosleys/Mosleys.Client/Models/Exhibit.cs
Normal file
202
C#/Mosleys/Mosleys.Client/Models/Exhibit.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System.Threading.Tasks;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using Mosleys.Client.Extensions;
|
||||
using Mosleys.Shared.Models;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace Mosleys.Client.Models {
|
||||
public class Exhibit {
|
||||
private static void DrawText3D(in Vector3 pos, in string text, float scale = 1, in bool rotate = true) {
|
||||
OutputArgument screenX = new OutputArgument(), screenY = new OutputArgument();
|
||||
bool onScreen = Function.Call<bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD , pos.X, pos.Y, pos.Z, screenX, screenY);
|
||||
if (onScreen) {
|
||||
Vector3 cam = API.GetGameplayCamCoord();
|
||||
float dist = API.GetDistanceBetweenCoords(cam.X, cam.Y, cam.Z, pos.X, pos.Y, pos.Z, true);
|
||||
|
||||
if (rotate)
|
||||
scale = (((1 / dist) * 2) * (1 / API.GetGameplayCamFov()) * 100) * scale;
|
||||
|
||||
API.SetTextColour(220, 220, 220, 255);
|
||||
API.SetTextScale(0.0f * scale, 0.40f * scale);
|
||||
API.SetTextFont(4);
|
||||
API.SetTextProportional(true);
|
||||
API.SetTextCentre(true);
|
||||
|
||||
API.SetTextEntry("STRING");
|
||||
API.AddTextComponentString(text);
|
||||
API.EndTextCommandDisplayText(screenX.GetResult<float>(), screenY.GetResult<float>());
|
||||
}
|
||||
}
|
||||
private static string HandleIntColor(int number) {
|
||||
if (number <= 0) return "Nein";
|
||||
return "~g~" + number;
|
||||
}
|
||||
|
||||
public bool Ready { get; set; }
|
||||
public bool Spawned { get; private set; }
|
||||
public string Uuid { get; set; }
|
||||
public string Owner { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int Price { get; set; }
|
||||
public int Slot { get; set; }
|
||||
public bool TestDrive { get; set; }
|
||||
public VehicleProperties Properties { get; set; }
|
||||
public Vehicle Vehicle { get; set; }
|
||||
public Vector4 Location { get; set; }
|
||||
|
||||
public async void Spawn() {
|
||||
if (Spawned) Despawn();
|
||||
Vehicle = await Mosleys.SpawnVehicle(Properties.model, Location, true);
|
||||
ESX.Game.SetVehicleProperties(Vehicle, Properties);
|
||||
|
||||
Vehicle.IsInvincible = true;
|
||||
Vehicle.SetDoorLockStatus(LockStatus.Locked);
|
||||
Vehicle.Freeze(true);
|
||||
Vehicle.PlaceOnGround();
|
||||
BaseScript.TriggerServerEvent("ls:mainCheck", Properties.plate, Vehicle.Handle, true);
|
||||
Spawned = true;
|
||||
Ready = true;
|
||||
}
|
||||
|
||||
public void Despawn() {
|
||||
Spawned = false;
|
||||
Vehicle?.Delete();
|
||||
}
|
||||
|
||||
public async void Update() {
|
||||
Ready = false;
|
||||
var exhibit = await Utils.GetExhibitBySlot(Slot);
|
||||
FromExhibit(exhibit);
|
||||
}
|
||||
|
||||
public void FromExhibit(ExhibitVehicle exhibit) {
|
||||
Ready = false;
|
||||
Uuid = exhibit.Uuid;
|
||||
Owner = exhibit.Owner;
|
||||
Description = exhibit.Description;
|
||||
Price = exhibit.Price;
|
||||
Slot = exhibit.Slot;
|
||||
Properties = new VehicleProperties(exhibit.Vehicle);
|
||||
Location = Mosleys.Config.CarSlots[Slot];
|
||||
TestDrive = exhibit.TestDrive;
|
||||
|
||||
if (Spawned || TestDrive) Despawn();
|
||||
if (!TestDrive) Spawn();
|
||||
else Ready = true;
|
||||
}
|
||||
|
||||
public void FromExhibit(ExhibitVehicle exhibit, int slot) {
|
||||
Ready = false;
|
||||
Uuid = exhibit.Uuid;
|
||||
Owner = exhibit.Owner;
|
||||
Description = exhibit.Description;
|
||||
Price = exhibit.Price;
|
||||
Slot = slot;
|
||||
Properties = new VehicleProperties(exhibit.Vehicle);
|
||||
Location = Mosleys.Config.CarSlots[Slot];
|
||||
TestDrive = exhibit.TestDrive;
|
||||
|
||||
if (Spawned || TestDrive) Despawn();
|
||||
if (!TestDrive) Spawn();
|
||||
else Ready = true;
|
||||
}
|
||||
|
||||
public void ShowText(bool keyText = true, float scale = 1.0f, float spacing = 0.1f) {
|
||||
if (!Ready) return;
|
||||
float x = Location.X;
|
||||
float y = Location.Y;
|
||||
float z = Location.Z;
|
||||
|
||||
if (TestDrive)
|
||||
DrawText3D(new Vector3(x, y, z + 1.1f), "[~r~Dieses Auto ist gerade bei einer Probefahrt~s~]");
|
||||
else {
|
||||
string turbo = "~r~Nein";
|
||||
if (Properties.modTurbo >= 1) turbo = "~g~Ja";
|
||||
|
||||
string line1 = "[~b~" + Vehicle.DisplayName + "~s~]";
|
||||
string line2 = "[Turbo : " + turbo + "~s~] [Motor : ~r~" + HandleIntColor(Properties.modEngine) + "~s~] [Getriebe : ~r~" + HandleIntColor(Properties.modTransmission) + "~s~]";
|
||||
string line3 = "[Federung : ~r~" + HandleIntColor(Properties.modSuspension) + "~s~] [Panzerung : ~r~" + HandleIntColor(Properties.modArmor) + "~s~] [Bremsen : ~r~" + HandleIntColor(Properties.modBrakes) + "~s~]";
|
||||
string line4 = "[Beschreibung : ~r~" + Description + "~s~]";
|
||||
|
||||
if (keyText) {
|
||||
string line5 = "Drücke [~r~E~s~] zum kaufen [$~r~" + Price + "~s~]";
|
||||
const string line6 = "Drücke [~r~F~s~] zum probefahren [~r~90 sek~s~]";
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 1)), line6, scale);
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 2)), line5, scale);
|
||||
}
|
||||
else {
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 2)), "[Preis : ~r~" + Price + "~s~]", scale);
|
||||
}
|
||||
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 3)), line4, scale);
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 4)), line3, scale);
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 5)), line2, scale);
|
||||
DrawText3D(new Vector3(x, y, z + 1.0f + (spacing * 6)), line1, scale);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartTestDrive(bool notifyServer = true) {
|
||||
var lastPos = Game.Player.Character.Position;
|
||||
|
||||
if (notifyServer) BaseScript.TriggerServerEvent("mosleys:server:testDrive", Slot, true);
|
||||
var vehicle = await Mosleys.SpawnVehicle(Properties.model, Mosleys.Config.TestDriveLocation);
|
||||
ESX.Game.SetVehicleProperties(vehicle, Properties);
|
||||
BaseScript.TriggerEvent("craftix:refuelVehicle", vehicle.Handle);
|
||||
Game.Player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver);
|
||||
|
||||
var startTime = Game.GameTime;
|
||||
var lastSecond = 0;
|
||||
while (Game.GameTime - startTime <= Mosleys.Config.TestDriveTime) {
|
||||
int elapsedTime = (int)((Game.GameTime - startTime) / 1000.0f);
|
||||
|
||||
if (elapsedTime > lastSecond) {
|
||||
lastSecond++;
|
||||
Mosleys.DoCustomHudText($"Probefahrt endet in {Mosleys.Config.TestDriveTime / 1000 - elapsedTime} Sekunden!", 1100);
|
||||
}
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.VehicleExit)) break;
|
||||
|
||||
await BaseScript.Delay(0);
|
||||
}
|
||||
|
||||
vehicle.Delete();
|
||||
Game.Player.Character.Position = lastPos;
|
||||
if (notifyServer) BaseScript.TriggerServerEvent("mosleys:server:testDrive", Slot, false);
|
||||
}
|
||||
|
||||
public async void Buy() {
|
||||
if (!await Mosleys.DisplayConfirmationDialog("Möchtest du dieses Auto wirklich kaufen?")) return;
|
||||
|
||||
var taken = await Mosleys.IsPlateTaken(Properties.plate);
|
||||
if (taken) {
|
||||
Properties.plate = await Mosleys.GeneratePlate();
|
||||
Notify.Warning("Das Kennzeichen des Fahrzeugs ist bereits angemeldet. Es wurde ein neues Kennzeichen generiert.");
|
||||
}
|
||||
|
||||
var hasMoney = await Mosleys.ServerCallback<bool>("mosleys:server:checkMoney", Price);
|
||||
if (!hasMoney) {
|
||||
Notify.Error("Du hast nicht genügend Geld!");
|
||||
return;
|
||||
}
|
||||
|
||||
var success = await Mosleys.ServerCallback<bool>("mosleys:server:buyVehicle", new BuyData {
|
||||
Uuid = Uuid,
|
||||
Plate = Properties.plate
|
||||
});
|
||||
if (!success) {
|
||||
Notify.Error("Dieses Auto steht nicht mehr zum verkauf!");
|
||||
return;
|
||||
}
|
||||
|
||||
var vehicle = await Mosleys.SpawnVehicle(Properties.model, Mosleys.Config.SpawnLocation);
|
||||
ESX.Game.SetVehicleProperties(vehicle, Properties);
|
||||
vehicle.EngineHealth = 1000;
|
||||
vehicle.Repair();
|
||||
vehicle.DirtLevel = 0;
|
||||
BaseScript.TriggerEvent("craftix:refuelVehicle", vehicle.Handle);
|
||||
|
||||
Game.Player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver);
|
||||
}
|
||||
}
|
||||
}
|
||||
83
C#/Mosleys/Mosleys.Client/Mosleys.Client.csproj
Normal file
83
C#/Mosleys/Mosleys.Client/Mosleys.Client.csproj
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{48D35232-689B-457F-A46E-C770F1EF4218}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Mosleys.Client</RootNamespace>
|
||||
<AssemblyName>Mosleys.Client.net</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>../Output</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>del Newtonsoft.Json.xml</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CitizenFX.Core">
|
||||
<HintPath>..\Librarys\CitizenFX.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="CitizenFX.Core.Client">
|
||||
<HintPath>..\Librarys\CitizenFX.Core.Client.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp">
|
||||
<HintPath>..\Librarys\Microsoft.CSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ExhibitHandler.cs" />
|
||||
<Compile Include="Extensions\ExhibitVehicleExtensions.cs" />
|
||||
<Compile Include="Extensions\Vector4Extensions.cs" />
|
||||
<Compile Include="Extensions\VehicleExtensions.cs" />
|
||||
<Compile Include="Models\Exhibit.cs" />
|
||||
<Compile Include="Mosleys.cs" />
|
||||
<Compile Include="Notify.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SellHandler.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
<Compile Include="VehicleManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Mosleys.Shared\Mosleys.Shared.csproj">
|
||||
<Project>{95000252-da88-4a79-8958-ca70b42ce0f9}</Project>
|
||||
<Name>Mosleys.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
132
C#/Mosleys/Mosleys.Client/Mosleys.cs
Normal file
132
C#/Mosleys/Mosleys.Client/Mosleys.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using Mosleys.Client.Extensions;
|
||||
using Mosleys.Shared;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public sealed class Mosleys : BaseScript {
|
||||
public static Config Config;
|
||||
public static bool InArea = false;
|
||||
|
||||
private static TaskCompletionSource<bool> _dialogTask;
|
||||
private static Mosleys _instance;
|
||||
|
||||
public Mosleys() {
|
||||
_instance = this;
|
||||
Config = Config.LoadConfig();
|
||||
CreateBlip();
|
||||
|
||||
EventHandlers["mosleys:dialog_accept"] += new Action(() => _dialogTask?.TrySetResult(true));
|
||||
EventHandlers["mosleys:dialog_deny"] += new Action(() => _dialogTask?.TrySetResult(false));
|
||||
|
||||
EventHandlers["onClientResourceStart"] += new Action<string>(OnStart);
|
||||
EventHandlers["onResourceStop"] += new Action<string>(OnStop);
|
||||
EventHandlers["mosleys:client:updateSlot"] += new Action<int>(ExhibitHandler.UpdateSlot);
|
||||
EventHandlers["mosleys:client:onRemove"] += new Action<int>(ExhibitHandler.OnRemove);
|
||||
EventHandlers["mosleys:client:openManageMenu"] += new Action(VehicleManager.OpenMenu);
|
||||
}
|
||||
|
||||
public static Task<T> ServerCallback<T>(string name, [Optional] dynamic args) {
|
||||
var source = new TaskCompletionSource<T>();
|
||||
ESX.TriggerServerCallback(name, new Action<dynamic>(o => {
|
||||
source.TrySetResult((T)o);
|
||||
}), args);
|
||||
return source.Task;
|
||||
}
|
||||
public static Task<Vehicle> SpawnVehicle(int model, Vector4 coords, bool local = false) {
|
||||
var source = new TaskCompletionSource<Vehicle>();
|
||||
|
||||
if (local) {
|
||||
ESX.Game.Raw.SpawnLocalVehicle(model, coords.ToVector3(), coords.W, new Action<int>(handle => {
|
||||
source.TrySetResult(new Vehicle(handle));
|
||||
}));
|
||||
}
|
||||
else {
|
||||
ESX.Game.Raw.SpawnVehicle(model, coords.ToVector3(), coords.W, new Action<int>(handle => {
|
||||
source.TrySetResult(new Vehicle(handle));
|
||||
}));
|
||||
}
|
||||
|
||||
return source.Task;
|
||||
}
|
||||
public static Task<bool> DisplayConfirmationDialog(string title) {
|
||||
_dialogTask = new TaskCompletionSource<bool>();
|
||||
|
||||
TriggerEvent("okokRequests:RequestMenuData", -1, Config.MenuTitle, title, "mosleys:dialog_accept", "client", "", 0, "mosleys:dialog_deny");
|
||||
|
||||
return _dialogTask.Task;
|
||||
}
|
||||
public static Task<string> DisplayTextDialog(string placeholder) {
|
||||
var source = new TaskCompletionSource<string>();
|
||||
|
||||
ESX.UI.Menu.Open("dialog", API.GetCurrentResourceName(), "test_dialog", new ESX.UI.MenuData() {
|
||||
title = placeholder,
|
||||
type = "default",
|
||||
align = "center"
|
||||
}, (dData, dMenu) => {
|
||||
source.TrySetResult(dData.value as string);
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(dMenu));
|
||||
}, (dData, dMenu) => {
|
||||
source.TrySetResult(null);
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(dMenu));
|
||||
});
|
||||
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public static void DoCustomHudText(string message, int duration) {
|
||||
_instance.Exports["mythic_notify"].DoCustomHudText("branco", message, duration, true);
|
||||
}
|
||||
|
||||
public static async Task<bool> IsPlateTaken(string plate) {
|
||||
var taken = await _instance.Exports["esx_vehicleshop"].IsPlateTaken(plate);
|
||||
return Convert.ToBoolean(taken);
|
||||
}
|
||||
public static async Task<string> GeneratePlate() {
|
||||
var plate = await _instance.Exports["esx_vehicleshop"].GeneratePlate();
|
||||
return Convert.ToString(plate);
|
||||
}
|
||||
|
||||
private void CreateBlip() {
|
||||
var blip = new Blip(API.AddBlipForCoord(Config.Blip.Position.X, Config.Blip.Position.Y, Config.Blip.Position.Z));
|
||||
blip.Sprite = Config.Blip.Sprite;
|
||||
blip.Color = Config.Blip.Color;
|
||||
blip.Scale = Config.Blip.Scale;
|
||||
blip.Name = Config.MenuTitle;
|
||||
blip.IsShortRange = true;
|
||||
API.SetBlipDisplay(blip.Handle, 4);
|
||||
}
|
||||
|
||||
private void OnStart(string resourceName) {
|
||||
if (resourceName != API.GetCurrentResourceName()) return;
|
||||
Tick += async () => {
|
||||
var dist = World.GetDistance(Game.Player.Character.Position, Config.Blip.Position);
|
||||
|
||||
if (dist <= Config.SpawnRadius) {
|
||||
if (!InArea) {
|
||||
ExhibitHandler.SpawnExhibits();
|
||||
InArea = true;
|
||||
}
|
||||
|
||||
SellHandler.OnTick();
|
||||
ExhibitHandler.OnTick();
|
||||
}else if (InArea) {
|
||||
ExhibitHandler.Cleanup();
|
||||
InArea = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void OnStop(string resourceName) {
|
||||
if (resourceName != API.GetCurrentResourceName()) return;
|
||||
if (ExhibitHandler.ExhibitsSpawned)
|
||||
ExhibitHandler.Cleanup();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
16
C#/Mosleys/Mosleys.Client/Notify.cs
Normal file
16
C#/Mosleys/Mosleys.Client/Notify.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using CitizenFX.Core;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public class Notify {
|
||||
|
||||
public static void SendMessage(string title, string message, int duration, string type, bool noSound = false) {
|
||||
BaseScript.TriggerEvent("okokNotify:Alert", title, message, duration, type, noSound);
|
||||
}
|
||||
|
||||
public static void Info(string message) => SendMessage(Mosleys.Config.MenuTitle, message, 5000, "info");
|
||||
public static void Success(string message) => SendMessage(Mosleys.Config.MenuTitle, message, 5000, "success");
|
||||
public static void Warning(string message) => SendMessage(Mosleys.Config.MenuTitle, message, 5000, "warning");
|
||||
public static void Error(string message) => SendMessage(Mosleys.Config.MenuTitle, message, 5000, "error");
|
||||
|
||||
}
|
||||
}
|
||||
35
C#/Mosleys/Mosleys.Client/Properties/AssemblyInfo.cs
Normal file
35
C#/Mosleys/Mosleys.Client/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Mosleys.Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Mosleys.Client")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("48D35232-689B-457F-A46E-C770F1EF4218")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
175
C#/Mosleys/Mosleys.Client/SellHandler.cs
Normal file
175
C#/Mosleys/Mosleys.Client/SellHandler.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using CitizenFX.Core.UI;
|
||||
using Mosleys.Client.Extensions;
|
||||
using Mosleys.Shared.Models;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public static class SellHandler {
|
||||
|
||||
private static bool _menuOpen = false;
|
||||
private static SellData _data;
|
||||
|
||||
public static void OnTick() {
|
||||
if (Game.Player.Character.IsInVehicle()) {
|
||||
World.DrawMarker(MarkerType.HorizontalCircleSkinny, Mosleys.Config.SellLocation, Vector3.Zero, Vector3.Zero,
|
||||
new Vector3(3.7f, 3.7f, 0.2f), Color.FromArgb(155, 229, 255));
|
||||
|
||||
float distance = World.GetDistance(Game.Player.Character.Position, Mosleys.Config.SellLocation);
|
||||
if (distance <= 4.0f && !_menuOpen) {
|
||||
Screen.DisplayHelpTextThisFrame("Drücke ~INPUT_CONTEXT~ um das Menü zu öffnen");
|
||||
|
||||
if (Game.IsControlJustReleased(0, Control.Context))
|
||||
HandleSell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async void HandleSell() {
|
||||
var vehicle = Game.Player.LastVehicle;
|
||||
var props = ESX.Game.GetVehicleProperties(vehicle);
|
||||
|
||||
// Check Vehice Class
|
||||
if (Mosleys.Config.ForbiddenVehicleClasses.Contains((int)vehicle.ClassType)) {
|
||||
Notify.Error("Du kannst dieses Fahrzeug hier nicht verkaufen!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check Ownership
|
||||
var owner = await Mosleys.ServerCallback<bool>("mosleys:server:checkVehicleOwnership", props.plate);
|
||||
if (!owner) {
|
||||
Notify.Error("Dieses Fahrzeug gehört dir nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
vehicle.Freeze(true);
|
||||
ESX.UI.Menu.CloseAll();
|
||||
|
||||
_data = new SellData();
|
||||
|
||||
// Create Menu
|
||||
var menuData = new ESX.UI.MenuData {
|
||||
title = Mosleys.Config.MenuTitle,
|
||||
align = "top-left",
|
||||
elements = new List<ESX.UI.MenuElement>(new [] {
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Stellplatztyp wählen",
|
||||
name = "choose_parkingspace",
|
||||
value = 0,
|
||||
options = new [] { "Ausgestellt", "Katalog" },
|
||||
type = "slider"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Beschreibung hinzufügen",
|
||||
name = "choose_description"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Preis wählen",
|
||||
name = "choose_price"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
label = "Fertig",
|
||||
name = "done"
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "sell_menu", menuData, (dData, dMenu) => {
|
||||
HandleMenuInteraction(new ESX.UI.Menu(dMenu), new ESX.UI.MenuData(dData));
|
||||
}, (dData, dMenu) => {
|
||||
ESX.UI.Menu.Close(new ESX.UI.Menu(dMenu));
|
||||
vehicle.Freeze(false);
|
||||
_menuOpen = false;
|
||||
});
|
||||
|
||||
_menuOpen = true;
|
||||
}
|
||||
|
||||
private static async void HandleMenuInteraction(ESX.UI.Menu menu, ESX.UI.MenuData data) {
|
||||
if (data.current.name == "choose_description") {
|
||||
var description = await Mosleys.DisplayTextDialog("Beschreibung");
|
||||
if (description == "Beschreibung") return;
|
||||
if (description.Length > 60) {
|
||||
Notify.Error("Die Beschreibung darf maximal 60 Zeichen lang sein!");
|
||||
return;
|
||||
}
|
||||
|
||||
_data.Description = description;
|
||||
}
|
||||
|
||||
if (data.current.name == "choose_price") {
|
||||
var sPrice = await Mosleys.DisplayTextDialog("Preis");
|
||||
|
||||
if (!int.TryParse(sPrice, out int price)) {
|
||||
Notify.Error("Der eingegebene Wert ist keine Zahl!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sPrice.Length > 7) {
|
||||
Notify.Error("Dein Auto darf maximal $9.999.999 kosten!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (price < Mosleys.Config.MinSellPrice) {
|
||||
Notify.Error($"Der Preis muss mindestens ${Mosleys.Config.MinSellPrice} betragen!");
|
||||
return;
|
||||
}
|
||||
|
||||
_data.Price = price;
|
||||
}
|
||||
|
||||
if (data.current.name == "done") {
|
||||
if (_data.Price == 0) {
|
||||
Notify.Error("Lege zuerst einen Preis fest!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await Mosleys.DisplayConfirmationDialog("Möchtest du das Auto wirklich verkaufen?")) {
|
||||
Game.Player.LastVehicle.Freeze(false);
|
||||
menu.Close();
|
||||
_menuOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
menu.Close();
|
||||
_menuOpen = false;
|
||||
|
||||
_data.ParkingSpace = data.elements[0].value;
|
||||
if (_data.ParkingSpace == 0) {
|
||||
var hasMoney = await Mosleys.ServerCallback<bool>("mosleys:server:checkMoney", Mosleys.Config.ExhibitPrice);
|
||||
|
||||
if (!hasMoney) {
|
||||
Notify.Error($"Du hast nicht genügend Geld! Ein Ausstellungsplatz kostet ${Mosleys.Config.ExhibitPrice}.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare Vehicle
|
||||
var vehicle = Game.Player.LastVehicle;
|
||||
vehicle.EngineHealth = 1000;
|
||||
vehicle.IsEngineRunning = false;
|
||||
vehicle.Repair();
|
||||
vehicle.DirtLevel = 0;
|
||||
|
||||
var props = ESX.Game.GetVehicleProperties(vehicle);
|
||||
_data.VehicleProperties = props.GetRaw();
|
||||
BaseScript.TriggerServerEvent("esx_vehicleshop:deleteVehicle", props.plate);
|
||||
|
||||
var success = await Mosleys.ServerCallback<bool>("mosleys:server:sellVehicle", _data) || _data.ParkingSpace == 1;
|
||||
|
||||
vehicle.Delete();
|
||||
if (success)
|
||||
Notify.Success("Auto ausgestellt!");
|
||||
else
|
||||
Notify.Warning("Alle Stellplätze sind belegt, Dein Auto kommt in den Katalog, bis ein Stellplatz frei wird.");
|
||||
|
||||
Notify.Info($"Beim Verkauf werden {Mosleys.Config.SellBill * 100}% Provision abgezogen.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
69
C#/Mosleys/Mosleys.Client/Utils.cs
Normal file
69
C#/Mosleys/Mosleys.Client/Utils.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
using CitizenFX.Core;
|
||||
using Mosleys.Shared.Models;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public static class Utils {
|
||||
|
||||
public static async Task<ExhibitVehicle[]> GetAllExhibits() {
|
||||
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getExhibits");
|
||||
|
||||
try {
|
||||
List<ExhibitVehicle> vehicles = new List<ExhibitVehicle>();
|
||||
|
||||
foreach (var exhibit in data.vehicles) {
|
||||
vehicles.Add(ExhibitVehicle.FromDynamic(exhibit));
|
||||
}
|
||||
|
||||
return vehicles.ToArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
return Array.Empty<ExhibitVehicle>();
|
||||
}
|
||||
|
||||
public static async Task<ExhibitVehicle[]> GetPlayerExhibits() {
|
||||
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getPlayerExhibits");
|
||||
|
||||
try {
|
||||
List<ExhibitVehicle> vehicles = new List<ExhibitVehicle>();
|
||||
|
||||
foreach (var exhibit in data.vehicles) {
|
||||
vehicles.Add(ExhibitVehicle.FromDynamic(exhibit));
|
||||
}
|
||||
|
||||
return vehicles.ToArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
return Array.Empty<ExhibitVehicle>();
|
||||
}
|
||||
|
||||
public static async Task<ExhibitVehicle> GetExhibitBySlot(int slot) {
|
||||
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getExhibitBySlot", slot);
|
||||
return ExhibitVehicle.FromDynamic(data);
|
||||
}
|
||||
|
||||
public static void PrintDynamic(dynamic data, string prefix = "") {
|
||||
foreach (var element in (data as IDictionary<string, object>)) {
|
||||
Debug.WriteLine($"{prefix}{element.Key}: {element.Value}");
|
||||
|
||||
if (element.Value.GetType() == typeof(ExpandoObject)) {
|
||||
PrintDynamic(element.Value, prefix + "\t");
|
||||
}
|
||||
|
||||
if (element.Value.GetType() == typeof(List<object>)) {
|
||||
Debug.WriteLine(prefix + "\t", string.Join(", ", element.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
199
C#/Mosleys/Mosleys.Client/VehicleManager.cs
Normal file
199
C#/Mosleys/Mosleys.Client/VehicleManager.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CitizenFX.Core;
|
||||
using CitizenFX.Core.Native;
|
||||
using Mosleys.Client.Extensions;
|
||||
using Mosleys.Client.Models;
|
||||
using Mosleys.Shared.Models;
|
||||
using Nexd.ESX.Client;
|
||||
|
||||
namespace Mosleys.Client {
|
||||
public static class VehicleManager {
|
||||
|
||||
private static bool _menuOpen = false;
|
||||
private static Exhibit _currentCar;
|
||||
|
||||
public static async void OpenMenu() {
|
||||
if (_menuOpen) _currentCar?.Despawn();
|
||||
var exhibits = await Utils.GetPlayerExhibits();
|
||||
|
||||
if (exhibits.Length == 0) {
|
||||
Notify.Error("Du hast keine Autos ausgestellt!");
|
||||
_menuOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Camera camera = null;
|
||||
if (!_menuOpen) {
|
||||
Game.Player.Character.Freeze(true);
|
||||
camera = World.CreateCamera(Mosleys.Config.DigitalCamera.ToVector3(),
|
||||
new Vector3(0, 0, Mosleys.Config.DigitalCamera.W), API.GetGameplayCamFov());
|
||||
camera.PointAt(Mosleys.Config.CarSlots[0].ToVector3() + new Vector3(0, 0, 1.0f));
|
||||
camera.IsActive = true;
|
||||
API.RenderScriptCams(true, false, 0, true, true);
|
||||
}
|
||||
|
||||
_menuOpen = true;
|
||||
_currentCar = new Exhibit { Slot = 0 };
|
||||
_currentCar.FromExhibit(exhibits[0], 0);
|
||||
|
||||
var menuData = new ESX.UI.MenuData {
|
||||
title = Mosleys.Config.MenuTitle,
|
||||
align = "top-left",
|
||||
elements = exhibits.Select(exhibit => new ESX.UI.MenuElement {
|
||||
name = exhibit.Uuid,
|
||||
label = exhibit.DisplayName() + " - $" + exhibit.Price
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
ESX.UI.Menu.CloseAll();
|
||||
ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "owner_menu", menuData, (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
OpenSubMenu(exhibits.Single(exhibit => exhibit.Uuid == data.current.name));
|
||||
}, (dData, dMenu) => {
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
menu.Close();
|
||||
_menuOpen = false;
|
||||
}, (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
var index = data.elements.FindIndex(element => element.name == data.current.name);
|
||||
|
||||
_currentCar.Despawn();
|
||||
_currentCar.FromExhibit(exhibits[index], 0);
|
||||
});
|
||||
|
||||
while (_menuOpen) {
|
||||
_currentCar.ShowText(false, 5.0f, 0.15f);
|
||||
await BaseScript.Delay(0);
|
||||
}
|
||||
|
||||
if (camera != null) {
|
||||
API.RenderScriptCams(false, false, 0, true, true);
|
||||
camera.IsActive = false;
|
||||
camera.Delete();
|
||||
Game.Player.Character.Freeze(false);
|
||||
_currentCar.Despawn();
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenSubMenu(ExhibitVehicle exhibit) {
|
||||
var menuData = new ESX.UI.MenuData {
|
||||
title = Mosleys.Config.MenuTitle + " - " + exhibit.DisplayName(),
|
||||
align = "top-left",
|
||||
elements = new List<ESX.UI.MenuElement> {
|
||||
new ESX.UI.MenuElement {
|
||||
name = "change_price",
|
||||
label = "Preis ändern"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
name = "change_description",
|
||||
label = "Beschreibung ändern"
|
||||
},
|
||||
new ESX.UI.MenuElement {
|
||||
name = "delete",
|
||||
label = "Zurückziehen"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (exhibit.Slot == 0) {
|
||||
var elements = menuData.elements;
|
||||
elements.Insert(0, new ESX.UI.MenuElement {
|
||||
name = "push",
|
||||
label = $"Ausstellen (${Mosleys.Config.ExhibitPrice})"
|
||||
});
|
||||
menuData.elements = elements;
|
||||
}
|
||||
|
||||
ESX.UI.Menu.Open("default", API.GetCurrentResourceName(), "owner_vehicle_menu", menuData, async (dData, dMenu) => {
|
||||
var data = new ESX.UI.MenuData(dData);
|
||||
var menu = new ESX.UI.Menu(dMenu);
|
||||
|
||||
if (data.current.name == "change_price") {
|
||||
var sPrice = await Mosleys.DisplayTextDialog("Neuer Preis");
|
||||
if (!int.TryParse(sPrice, out int price)) {
|
||||
Notify.Error("Der eingegebene Wert ist keine Zahl!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sPrice.Length > 7) {
|
||||
Notify.Error("Dein Auto darf maximal $9.999.999 kosten!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (price < Mosleys.Config.MinSellPrice) {
|
||||
Notify.Error($"Der Preis muss mindestens ${Mosleys.Config.MinSellPrice} betragen!");
|
||||
return;
|
||||
}
|
||||
|
||||
exhibit.Price = price;
|
||||
var success = await Mosleys.ServerCallback<bool>("mosleys:server:updateExhibit", new ExhibitUpdate {
|
||||
Action = UpdateAction.Update,
|
||||
Exhibit = exhibit
|
||||
});
|
||||
|
||||
if (success) Notify.Success("Der Preis wurde geändert!");
|
||||
else Notify.Error("Der Preis konnte nicht geändert werden!");
|
||||
}
|
||||
|
||||
if (data.current.name == "change_description") {
|
||||
var description = await Mosleys.DisplayTextDialog("Beschreibung");
|
||||
if (description == "Beschreibung") return;
|
||||
if (description.Length > 60) {
|
||||
Notify.Error("Die Beschreibung darf maximal 60 Zeichen lang sein!");
|
||||
return;
|
||||
}
|
||||
|
||||
exhibit.Description = description;
|
||||
var success = await Mosleys.ServerCallback<bool>("mosleys:server:updateExhibit", new ExhibitUpdate {
|
||||
Action = UpdateAction.Update,
|
||||
Exhibit = exhibit
|
||||
});
|
||||
|
||||
if (success) Notify.Success("Die Beschreibung wurde geändert!");
|
||||
else Notify.Error("Die Beschreibung konnte nicht geändert werden!");
|
||||
}
|
||||
|
||||
if (data.current.name == "delete") {
|
||||
var confirmation = await Mosleys.DisplayConfirmationDialog("Möchtest du dieses Auto wirklich aus dem Sortiment nehmen?");
|
||||
if (!confirmation) return;
|
||||
|
||||
var success = await Mosleys.ServerCallback<bool>("mosleys:server:updateExhibit", new ExhibitUpdate {
|
||||
Action = UpdateAction.Delete,
|
||||
Exhibit = exhibit
|
||||
});
|
||||
|
||||
if (success) Notify.Success("Dein Auto wird wieder in die Garage geliefert!");
|
||||
else Notify.Error("Das Auto konnte nicht zurückgezogen werden!");
|
||||
|
||||
if (success) {
|
||||
ESX.UI.Menu.CloseAll();
|
||||
OpenMenu();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.current.name == "push") {
|
||||
var hasMoney = await Mosleys.ServerCallback<bool>("mosleys:server:checkMoney", Mosleys.Config.ExhibitPrice);
|
||||
if (!hasMoney) {
|
||||
Notify.Error("Du hast nicht genügend Geld!");
|
||||
return;
|
||||
}
|
||||
|
||||
var newSlot = await Mosleys.ServerCallback<int>("mosleys:server:push", exhibit.Uuid);
|
||||
|
||||
if (newSlot != 0) Notify.Success("Auto ausgestellt");
|
||||
else Notify.Error("Das Auto konnte nicht ausgestellt werden!");
|
||||
|
||||
if (newSlot != 0) {
|
||||
menu.Close();
|
||||
exhibit.Slot = newSlot;
|
||||
OpenSubMenu(exhibit);
|
||||
}
|
||||
}
|
||||
}, (dData, dMenu) => {
|
||||
OpenMenu();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.dll
Normal file
BIN
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.dll
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.pdb
Normal file
BIN
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.pdb
Normal file
Binary file not shown.
90990
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.xml
Normal file
90990
C#/Mosleys/Mosleys.Client/bin/Release/CitizenFX.Core.xml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
C#/Mosleys/Mosleys.Client/bin/Release/Mosleys.Client.net.dll
Normal file
BIN
C#/Mosleys/Mosleys.Client/bin/Release/Mosleys.Client.net.dll
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Client/bin/Release/Mosleys.Client.net.pdb
Normal file
BIN
C#/Mosleys/Mosleys.Client/bin/Release/Mosleys.Client.net.pdb
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Client/bin/Release/MsgPack.dll
Normal file
BIN
C#/Mosleys/Mosleys.Client/bin/Release/MsgPack.dll
Normal file
Binary file not shown.
10473
C#/Mosleys/Mosleys.Client/bin/Release/MsgPack.xml
Normal file
10473
C#/Mosleys/Mosleys.Client/bin/Release/MsgPack.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
1772fe7811bac0b83ee8d664ce41b0555ef86dfc
|
||||
@@ -0,0 +1,16 @@
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\CitizenFX.Core.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\System.Reflection.Metadata.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\System.Collections.Immutable.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\MsgPack.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\CitizenFX.Core.pdb
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\CitizenFX.Core.xml
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\MsgPack.xml
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\obj\Release\Mosleys.Client.csproj.AssemblyReference.cache
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\obj\Release\Mosleys.Client.csproj.CoreCompileInputs.cache
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\Mosleys.Client.net.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\bin\Release\Mosleys.Client.net.pdb
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\obj\Release\Mosleys.Client.net.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Output\Mosleys.Client.net.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Client\obj\Release\Mosleys.Client.csproj.CopyComplete
|
||||
D:\Programmierstuff\C#\Mosleys\Output\fxmanifest.lua
|
||||
D:\Programmierstuff\C#\Mosleys\Output\settings.ini
|
||||
BIN
C#/Mosleys/Mosleys.Client/obj/Release/Mosleys.Client.net.dll
Normal file
BIN
C#/Mosleys/Mosleys.Client/obj/Release/Mosleys.Client.net.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user