Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GameStartScreen.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import { Button, useTheme } from 'react-native-paper';
  21. import { StyleSheet, View } from 'react-native';
  22. import i18n from 'i18n-js';
  23. import LinearGradient from 'react-native-linear-gradient';
  24. import { MASCOT_STYLE } from '../../../components/Mascot/Mascot';
  25. import MascotPopup from '../../../components/Mascot/MascotPopup';
  26. import CollapsibleScrollView from '../../../components/Collapsible/CollapsibleScrollView';
  27. import GENERAL_STYLES from '../../../constants/Styles';
  28. import GameBackground from '../components/GameBrackground';
  29. import PostGameContent from '../components/PostGameContent';
  30. import WelcomeGameContent from '../components/WelcomeGameContent';
  31. import FullGamePodium from '../components/FullGamePodium';
  32. import { useNavigation } from '@react-navigation/core';
  33. import { usePreferences } from '../../../context/preferencesContext';
  34. import {
  35. getPreferenceObject,
  36. PreferenceKeys,
  37. } from '../../../utils/asyncStorage';
  38. import { StackNavigationProp } from '@react-navigation/stack';
  39. type GameStatsType = {
  40. score: number;
  41. level: number;
  42. time: number;
  43. isHighScore: boolean;
  44. };
  45. type Props = {
  46. route: {
  47. params?: GameStatsType;
  48. };
  49. };
  50. const styles = StyleSheet.create({
  51. playButton: {
  52. marginLeft: 'auto',
  53. marginRight: 'auto',
  54. marginTop: 10,
  55. },
  56. });
  57. export default function GameStartScreen(props: Props) {
  58. const theme = useTheme();
  59. const navigation = useNavigation<StackNavigationProp<any>>();
  60. const { preferences } = usePreferences();
  61. function getScores() {
  62. const pref = getPreferenceObject(PreferenceKeys.gameScores, preferences) as
  63. | Array<number>
  64. | undefined;
  65. if (pref) {
  66. return pref.sort((a, b) => b - a);
  67. } else {
  68. return [];
  69. }
  70. }
  71. const scores = getScores();
  72. const lastGameStats = props.route.params;
  73. const getMainContent = () => {
  74. return (
  75. <View style={GENERAL_STYLES.flex}>
  76. {lastGameStats ? (
  77. <PostGameContent
  78. stats={lastGameStats}
  79. isHighScore={lastGameStats.isHighScore}
  80. />
  81. ) : (
  82. <WelcomeGameContent />
  83. )}
  84. <Button
  85. icon={'play'}
  86. mode={'contained'}
  87. onPress={() => {
  88. navigation.replace('game-main');
  89. }}
  90. style={styles.playButton}
  91. >
  92. {i18n.t('screens.game.play')}
  93. </Button>
  94. <FullGamePodium
  95. scores={scores}
  96. isHighScore={lastGameStats?.isHighScore === true}
  97. />
  98. </View>
  99. );
  100. };
  101. return (
  102. <View style={GENERAL_STYLES.flex}>
  103. <GameBackground />
  104. <LinearGradient
  105. style={GENERAL_STYLES.flex}
  106. colors={[`${theme.colors.background}00`, theme.colors.background]}
  107. start={{ x: 0, y: 0 }}
  108. end={{ x: 0, y: 1 }}
  109. >
  110. <CollapsibleScrollView headerColors={'transparent'}>
  111. {getMainContent()}
  112. <MascotPopup
  113. title={i18n.t('screens.game.mascotDialog.title')}
  114. message={i18n.t('screens.game.mascotDialog.message')}
  115. icon="gamepad-variant"
  116. buttons={{
  117. cancel: {
  118. message: i18n.t('screens.game.mascotDialog.button'),
  119. icon: 'check',
  120. },
  121. }}
  122. emotion={MASCOT_STYLE.COOL}
  123. />
  124. </CollapsibleScrollView>
  125. </LinearGradient>
  126. </View>
  127. );
  128. }