mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
feat(phone): Added a game time indicator to top bar (#176)
This commit is contained in:
5 files changed
+44
No files matched your search
@@ -16,6 +16,7 @@ import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
|
|||||||
import Default from '../../../config/default.json';
|
import Default from '../../../config/default.json';
|
||||||
import { useNotifications } from '../hooks/useNotifications';
|
import { useNotifications } from '../hooks/useNotifications';
|
||||||
import { NotificationItem } from './NotificationItem';
|
import { NotificationItem } from './NotificationItem';
|
||||||
|
import usePhoneTime from '../../phone/hooks/usePhoneTime';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -74,6 +75,8 @@ export const NotificationBar = () => {
|
|||||||
setBarUncollapsed,
|
setBarUncollapsed,
|
||||||
} = useNotifications();
|
} = useNotifications();
|
||||||
|
|
||||||
|
const time = usePhoneTime();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid
|
<Grid
|
||||||
@@ -92,6 +95,13 @@ export const NotificationBar = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{time && (
|
||||||
|
<Grid item className={classes.item}>
|
||||||
|
<Typography className={classes.text} variant="button">
|
||||||
|
{time}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
)}
|
||||||
<Grid container item wrap="nowrap" justify="flex-end" alignItems="center">
|
<Grid container item wrap="nowrap" justify="flex-end" alignItems="center">
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<SignalIcon fontSize="small" />
|
<SignalIcon fontSize="small" />
|
||||||
|
|||||||
@@ -13,4 +13,8 @@ export const phoneState = {
|
|||||||
key: 'phoneReady',
|
key: 'phoneReady',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
|
phoneTime: atom({
|
||||||
|
key: 'phoneTime',
|
||||||
|
default: null,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
@@ -6,7 +6,9 @@ export const usePhoneService = () => {
|
|||||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||||
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
|
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
|
||||||
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
|
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
|
||||||
|
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
|
||||||
useNuiEvent('PHONE', 'setVisibility', setVisibility);
|
useNuiEvent('PHONE', 'setVisibility', setVisibility);
|
||||||
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
|
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
|
||||||
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
|
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
|
||||||
|
useNuiEvent('PHONE', 'setTime', setPhoneTime);
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
import { phoneState } from './state';
|
||||||
|
|
||||||
|
const usePhoneTime = () => {
|
||||||
|
return useRecoilValue<null | string>(phoneState.phoneTime);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default usePhoneTime;
|
||||||
@@ -31,6 +31,18 @@ function fetchOnInitialize() {
|
|||||||
|
|
||||||
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
|
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
|
||||||
|
|
||||||
|
const getCurrentGameTime = () => {
|
||||||
|
let hour: string | number = GetClockHours();
|
||||||
|
|
||||||
|
let minute: string | number = GetClockMinutes();
|
||||||
|
|
||||||
|
// Format time if need be
|
||||||
|
if (hour < 10) hour = `0${hour}`;
|
||||||
|
if (minute < 10) minute = `0${minute}`;
|
||||||
|
|
||||||
|
return `${hour}:${minute}`;
|
||||||
|
};
|
||||||
|
|
||||||
/* * * * * * * * * * * * *
|
/* * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Phone Visibility Handling
|
* Phone Visibility Handling
|
||||||
@@ -39,10 +51,12 @@ RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
|
|||||||
|
|
||||||
const showPhone = async (): Promise<void> => {
|
const showPhone = async (): Promise<void> => {
|
||||||
isPhoneOpen = true;
|
isPhoneOpen = true;
|
||||||
|
const time = getCurrentGameTime();
|
||||||
await phoneOpenAnim(); // Animation starts before the phone is open
|
await phoneOpenAnim(); // Animation starts before the phone is open
|
||||||
emitNet('phone:getCredentials');
|
emitNet('phone:getCredentials');
|
||||||
SetCursorLocation(0.9, 0.922); //Experimental
|
SetCursorLocation(0.9, 0.922); //Experimental
|
||||||
sendMessage('PHONE', 'setVisibility', true);
|
sendMessage('PHONE', 'setVisibility', true);
|
||||||
|
sendMessage('PHONE', 'setTime', time);
|
||||||
SetNuiFocus(true, true);
|
SetNuiFocus(true, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -176,3 +190,9 @@ on(`__cfx_nui:${PhoneEvents.CLOSE_PHONE}`, async (data: any, cb: Function) => {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
// Will update the phone's time even while its open
|
||||||
|
// setInterval(() => {
|
||||||
|
// const time = getCurrentGameTime()
|
||||||
|
// sendMessage('PHONE', 'setTime', time)
|
||||||
|
// }, 2000);
|
||||||
Reference in new issue
Block a user