mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
cleanup(scripts/cl_photo): Cleaned up code
This commit is contained in:
1 parent
fdfd4133e2
commit
6b21cfddd0
1 file changed
+47
-51
@@ -4,7 +4,10 @@ const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
|
|||||||
|
|
||||||
const exp = (global as any).exports;
|
const exp = (global as any).exports;
|
||||||
|
|
||||||
|
let inCameraMode = false;
|
||||||
|
|
||||||
function closePhoneTemp() {
|
function closePhoneTemp() {
|
||||||
|
SetNuiFocus(false, false);
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
//Hides phone
|
//Hides phone
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -16,6 +19,7 @@ function closePhoneTemp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openPhoneTemp() {
|
function openPhoneTemp() {
|
||||||
|
SetNuiFocus(true, true);
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
//Opens phone
|
//Opens phone
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -26,74 +30,66 @@ function openPhoneTemp() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let takingPhoto = false;
|
function CellFrontCamActivate(activate: boolean) {
|
||||||
|
|
||||||
function CellFrontCamActivate(activate: any) {
|
|
||||||
return Citizen.invokeNative('0x2491A93618B7D838', activate);
|
return Citizen.invokeNative('0x2491A93618B7D838', activate);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
|
const displayHelperText = () => {
|
||||||
on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async () => {
|
BeginTextCommandDisplayHelp('TWOSTRINGS');
|
||||||
CreateMobilePhone(1);
|
AddTextComponentString('Exit Camera Mode: ~INPUT_CELLPHONE_CANCEL~');
|
||||||
CellCamActivate(true, true);
|
AddTextComponentString('Toggle Front/Back: ~INPUT_PHONE~');
|
||||||
|
EndTextCommandDisplayHelp(0, true, false, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
|
||||||
|
on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async (data: any, cb: Function) => {
|
||||||
|
cb();
|
||||||
|
// Create Phone Prop
|
||||||
|
CreateMobilePhone(1);
|
||||||
|
// Active Camera Change
|
||||||
|
CellCamActivate(true, true);
|
||||||
|
// Hide phone from rendering temporary
|
||||||
closePhoneTemp();
|
closePhoneTemp();
|
||||||
|
|
||||||
SetNuiFocus(false, false);
|
SetNuiFocus(false, false);
|
||||||
|
|
||||||
takingPhoto = true;
|
inCameraMode = true;
|
||||||
|
|
||||||
while (takingPhoto) {
|
while (inCameraMode) {
|
||||||
await Delay(0);
|
await Delay(0);
|
||||||
let frontCam = false;
|
let frontCam = false;
|
||||||
|
displayHelperText();
|
||||||
if (IsControlJustPressed(1, 27)) {
|
if (IsControlJustPressed(1, 27)) {
|
||||||
if (!frontCam) {
|
frontCam = !frontCam;
|
||||||
frontCam = true;
|
CellFrontCamActivate(frontCam);
|
||||||
CellFrontCamActivate(true);
|
|
||||||
} else {
|
|
||||||
frontCam = false;
|
|
||||||
CellFrontCamActivate(false);
|
|
||||||
}
|
|
||||||
} else if (IsControlJustPressed(1, 176)) {
|
} else if (IsControlJustPressed(1, 176)) {
|
||||||
takePhoto();
|
await handleTakePicture();
|
||||||
await Delay(200);
|
|
||||||
console.log('phone closing');
|
|
||||||
DestroyMobilePhone();
|
|
||||||
CellCamActivate(false, false);
|
|
||||||
|
|
||||||
openPhoneTemp();
|
|
||||||
SetNuiFocus(true, true);
|
|
||||||
|
|
||||||
takingPhoto = false;
|
|
||||||
} else if (IsControlJustPressed(1, 177)) {
|
} else if (IsControlJustPressed(1, 177)) {
|
||||||
DestroyMobilePhone();
|
handleCameraExit();
|
||||||
CellCamActivate(false, false);
|
|
||||||
|
|
||||||
openPhoneTemp();
|
|
||||||
SetNuiFocus(true, true);
|
|
||||||
|
|
||||||
takingPhoto = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ClearHelp(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
//setTick(async () => {
|
const handleTakePicture = async () => {
|
||||||
// while (takingPhoto) {
|
takePhoto();
|
||||||
// await Delay(0);
|
await Delay(200);
|
||||||
//
|
DestroyMobilePhone();
|
||||||
// if (IsControlReleased(1, 177)) {
|
CellCamActivate(false, false);
|
||||||
// DestroyMobilePhone();
|
openPhoneTemp();
|
||||||
// CellCamActivate(false, false);
|
inCameraMode = false;
|
||||||
// takingPhoto = false;
|
};
|
||||||
// SetNuiFocus(true, true);
|
|
||||||
// break;
|
const handleCameraExit = () => {
|
||||||
// }
|
DestroyMobilePhone();
|
||||||
// }
|
CellCamActivate(false, false);
|
||||||
//})
|
openPhoneTemp();
|
||||||
|
inCameraMode = false;
|
||||||
|
};
|
||||||
|
|
||||||
onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
|
onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
|
||||||
console.log(photos);
|
// console.log(photos);
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
app: 'CAMERA',
|
app: 'CAMERA',
|
||||||
@@ -104,7 +100,6 @@ onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function takePhoto() {
|
function takePhoto() {
|
||||||
const [width, height] = GetActiveScreenResolution();
|
|
||||||
// Return and log error if screenshot basic token not found
|
// Return and log error if screenshot basic token not found
|
||||||
if (SCREENSHOT_BASIC_TOKEN === 'none') {
|
if (SCREENSHOT_BASIC_TOKEN === 'none') {
|
||||||
return console.error(
|
return console.error(
|
||||||
@@ -129,13 +124,14 @@ function takePhoto() {
|
|||||||
|
|
||||||
onNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, () => {
|
onNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, () => {
|
||||||
emitNet(events.CAMERA_FETCH_PHOTOS);
|
emitNet(events.CAMERA_FETCH_PHOTOS);
|
||||||
})
|
});
|
||||||
|
|
||||||
// delete photo
|
// delete photo
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
|
RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
|
||||||
on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any) => {
|
on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any, cb: Function) => {
|
||||||
emitNet(events.CAMERA_DELETE_PHOTO, data);
|
emitNet(events.CAMERA_DELETE_PHOTO, data);
|
||||||
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => {
|
onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => {
|
||||||
|
|||||||
Reference in new issue
Block a user