feat(phone): Added a game time indicator to top bar (#176)

This commit is contained in:
Taso authored and GitHub committed 2021-03-26 13:30:09 -04:00
1 parent 6b865f2e73
commit 853b335ef9
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 { useNotifications } from '../hooks/useNotifications';
import { NotificationItem } from './NotificationItem';
import usePhoneTime from '../../phone/hooks/usePhoneTime';
const useStyles = makeStyles((theme) => ({
root: {
@@ -74,6 +75,8 @@ export const NotificationBar = () => {
setBarUncollapsed,
} = useNotifications();
const time = usePhoneTime();
return (
<>
<Grid
@@ -92,6 +95,13 @@ export const NotificationBar = () => {
</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 item>
<SignalIcon fontSize="small" />
+4
View File
@@ -13,4 +13,8 @@ export const phoneState = {
key: 'phoneReady',
default: false,
}),
phoneTime: atom({
key: 'phoneTime',
default: null,
}),
};
@@ -6,7 +6,9 @@ export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
useNuiEvent('PHONE', 'setTime', setPhoneTime);
};
+8
View File
@@ -0,0 +1,8 @@
import { useRecoilValue } from 'recoil';
import { phoneState } from './state';
const usePhoneTime = () => {
return useRecoilValue<null | string>(phoneState.phoneTime);
};
export default usePhoneTime;
+20
View File
@@ -31,6 +31,18 @@ function fetchOnInitialize() {
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
@@ -39,10 +51,12 @@ RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
const showPhone = async (): Promise<void> => {
isPhoneOpen = true;
const time = getCurrentGameTime();
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
SetCursorLocation(0.9, 0.922); //Experimental
sendMessage('PHONE', 'setVisibility', true);
sendMessage('PHONE', 'setTime', time);
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);