89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import * as alt from 'alt-client';
|
|
import * as native from 'natives';
|
|
import * as AthenaClient from '@AthenaClient/api/index.js';
|
|
import { SEAT_SELECTOR_EVENTS } from '@AthenaPlugins/odyssey-seat-selector/shared/events.js';
|
|
import { IPage } from '@AthenaClient/webview/page.js';
|
|
import { WebViewEventNames } from '@AthenaShared/enums/webViewEvents.js';
|
|
|
|
const PAGE_NAME = 'SeatSelectorMenu';
|
|
|
|
export function handleOpen() {
|
|
let tick;
|
|
if (alt.LocalPlayer.local.vehicle !== null) {
|
|
return;
|
|
}
|
|
|
|
const vehicle = alt.Utils.getClosestVehicle({ pos: alt.LocalPlayer.local.pos, range: 5 });
|
|
if (vehicle === null || vehicle.seatCount < 2) {
|
|
return;
|
|
}
|
|
|
|
if (vehicle.seatCount === 2) {
|
|
if (!native.isVehicleSeatFree(vehicle, 0, true)) {
|
|
return;
|
|
}
|
|
|
|
native.setPedConfigFlag(alt.Player.local.scriptID, 184, true);
|
|
native.taskEnterVehicle(alt.Player.local.scriptID, vehicle, 5000, 0, 2.0, 1, null, 0);
|
|
return;
|
|
}
|
|
|
|
new AthenaClient.webview.Page({
|
|
name: PAGE_NAME,
|
|
callbacks: {
|
|
onReady: () => {
|
|
AthenaClient.webview.emit(SEAT_SELECTOR_EVENTS.SET_VEHICLE, vehicle.scriptID);
|
|
|
|
updateData(vehicle.scriptID);
|
|
|
|
tick = alt.everyTick(() => {
|
|
if (!AthenaClient.webview.isPageOpen(PAGE_NAME)) {
|
|
return;
|
|
}
|
|
|
|
updateData(vehicle.scriptID);
|
|
});
|
|
},
|
|
onClose: () => {
|
|
alt.clearEveryTick(tick);
|
|
},
|
|
},
|
|
options: {
|
|
onOpen: {
|
|
focus: true,
|
|
showCursor: true,
|
|
setIsMenuOpenToTrue: true,
|
|
disablePauseMenu: true,
|
|
disableControls: 'all',
|
|
},
|
|
onClose: {
|
|
hideCursor: true,
|
|
unfocus: true,
|
|
setIsMenuOpenToFalse: true,
|
|
enablePauseMenu: true,
|
|
enableControls: true,
|
|
},
|
|
},
|
|
} as IPage).open();
|
|
}
|
|
|
|
function updateData(vehicleScriptId: number) {
|
|
const vehicle = alt.Vehicle.getByScriptID(vehicleScriptId);
|
|
if (vehicle === null || AthenaClient.utility.vector.distance(vehicle.pos, alt.LocalPlayer.local.pos) > 5) {
|
|
AthenaClient.webview.emit(WebViewEventNames.CLOSE_PAGE);
|
|
}
|
|
|
|
try {
|
|
let data: object[] = [];
|
|
for (let seat = 0; seat < vehicle.seatCount; seat++) {
|
|
data.push({
|
|
isFree: native.isVehicleSeatFree(vehicle, seat - 1, true),
|
|
index: seat - 1,
|
|
});
|
|
}
|
|
AthenaClient.webview.emit(SEAT_SELECTOR_EVENTS.UPDATE_DATA, data);
|
|
} catch (error) {
|
|
alt.logWarning(`Error while updating SeatSelectorMenu: ${error}!`);
|
|
}
|
|
}
|