This commit is contained in:
hydrant
2021-04-02 21:48:59 +02:00
parent b032934f0e
commit 8cbab7ef15
3 changed files with 84 additions and 45 deletions

View File

@@ -12,6 +12,7 @@ const Point = NativeUI.Point;
const Color = NativeUI.Color;
let screenRes = mp.game.graphics.getScreenResolution(0, 0);
import vehicleColors from './colors';
import moneyformat from '../moneyformat';
export default function tuning(globalData: IGlobalData) {
var keyBound = false;
@@ -53,6 +54,10 @@ export default function tuning(globalData: IGlobalData) {
{ Slot: 38, Name: "Hydraulik", Price: 2000 },
{ Slot: 39, Name: "Motorabdeckung", Price: 2000 },
{ Slot: 40, Name: "Luftfilter", Price: 2000 },
{ Slot: 41, Name: "Domstrebe", Price: 2000 },
{ Slot: 42, Name: "Scheinwerferabdeckung", Price: 2000 },
{ Slot: 43, Name: "Nebelscheinwerfer", Price: 2000 },
{ Slot: 44, Name: "Dach-Extra", Price: 2000 },
{ Slot: 46, Name: "Fenster", Price: 2000 },
{ Slot: 48, Name: "Design", Price: 2000 }
];
@@ -156,6 +161,10 @@ export default function tuning(globalData: IGlobalData) {
}
});
var currentMod = new Array<number>();
var currentActiveModItem = new Array<NativeUI.UIMenuItem>();
var currentSelectedItem: VehicleModMenuItem = null;
mp.events.add("showTuningMenu", () => {
mp.events.call("hideTuningInfo", false);
mp.gui.chat.show(false);
@@ -178,12 +187,8 @@ export default function tuning(globalData: IGlobalData) {
repairItem.BackColor = new Color(94, 94, 94);
repairItem.HighlightedBackColor = new Color(105, 105, 105);
var currentMod = new Array<number>();
var currentActiveModItem = new Array<NativeUI.UIMenuItem>();
carModTypes.forEach((modType) => {
var mod = null;
var mod: number = null;
if (modType === 22) { // Lichter
var hlColor = localVehicle.getVariable("headlightColor");
@@ -221,6 +226,10 @@ export default function tuning(globalData: IGlobalData) {
}
}
mp.gui.chat.push("getting price for modtype = " + modType.toString() + ", modtypename = " + modName);
var price = getModSlotPrice(modType);
if (mod === null) {
mod = localVehicle.getMod(modType);
}
@@ -247,7 +256,8 @@ export default function tuning(globalData: IGlobalData) {
modText = mp.game.ui.getLabelText(localVehicle.getModTextLabel(modType, x));
if (modText === "NULL") modText = getModName(localVehicle, modType, x);
}
var item = new UIMenuItem(modText);
var item = new VehicleModMenuItem(modText);
item.price = price;
modMenu.AddItem(item);
if (x === mod) {
@@ -255,6 +265,9 @@ export default function tuning(globalData: IGlobalData) {
currentActiveModItem[modType] = item;
modMenu.CurrentSelection = x;
}
else {
item.SetRightLabel("$"+ moneyformat(price));
}
}
modMenu.IndexChange.on((index: number) => {
@@ -272,13 +285,13 @@ export default function tuning(globalData: IGlobalData) {
}
});
modMenu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => {
currentMod[modType] = index - 1;
currentActiveModItem[modType].SetRightBadge(BadgeStyle.None);
item.SetRightBadge(BadgeStyle.Car);
currentActiveModItem[modType] = item;
modMenu.ItemSelect.on((item: VehicleModMenuItem, index: number) => {
if (currentMod[modType] == index - 1) {
return;
}
mp.events.callRemote("setVehicleMod", modType, index);
currentSelectedItem = item;
mp.events.callRemote("setVehicleMod", modType, index, price);
});
modMenu.MenuClose.on(() => {
@@ -311,6 +324,13 @@ export default function tuning(globalData: IGlobalData) {
});
mp.events.add("SERVER:Tuning_ModSucessfull", (modType: number, index: number) => {
currentMod[modType] = index - 1;
currentActiveModItem[modType].SetRightLabel("$" + moneyformat(currentSelectedItem.price));
currentSelectedItem.SetRightBadge(BadgeStyle.Car);
currentActiveModItem[modType] = currentSelectedItem;
});
mp.events.add("playerLeaveVehicle", () => {
if (keyBound) {
mp.events.call("hideTuningInfo", true);
@@ -435,6 +455,10 @@ export default function tuning(globalData: IGlobalData) {
return realModName;
}
function getModSlotPrice(modType: number): number {
return carModSlotName.filter(x => x.Slot == modType)[0].Price;
}
function setHeadlightsColor(vehicle, index) {
if (!vehicle) {
@@ -552,4 +576,8 @@ export default function tuning(globalData: IGlobalData) {
mp.events.callRemote("CLIENT:TuningManager_SetVehicleColor", false, color);
}
class VehicleModMenuItem extends UIMenuItem {
public price: number;
}
}