Merge pull request #13 from ThomasRubini/client_game_start_mode_selection
[Client] Add game selection view to start page
This commit is contained in:
		
						commit
						eca60f10a6
					
				| @ -53,7 +53,7 @@ body { | ||||
| 
 | ||||
| /* Utility classes */ | ||||
| .hidden { | ||||
|     display: none; | ||||
|     display: none !important; | ||||
| } | ||||
| 
 | ||||
| /* Links */ | ||||
|  | ||||
| @ -3,6 +3,32 @@ | ||||
|     --header-actions-height: 3em; | ||||
| } | ||||
| 
 | ||||
| button { | ||||
|     background-color: transparent; | ||||
|     border: none; | ||||
|     cursor: pointer; | ||||
|     padding: 0; | ||||
| } | ||||
| 
 | ||||
| input { | ||||
|     background-color: white; | ||||
|     border: none; | ||||
|     border-radius: 1em; | ||||
|     font-family: "Titan One", sans-serif; | ||||
|     font-size: 1em; | ||||
|     padding: 0.5em; | ||||
|     color: black; | ||||
| } | ||||
| 
 | ||||
| input::placeholder { | ||||
|     color: black; | ||||
|     opacity: 0.5; | ||||
| } | ||||
| 
 | ||||
| .back_btn { | ||||
|     fill: #BD1E1E; | ||||
| } | ||||
| 
 | ||||
| .game_begin { | ||||
|     align-items: center; | ||||
|     border-radius: 1.5em; | ||||
| @ -30,19 +56,12 @@ | ||||
|     font-family: "Spicy Rice", serif; | ||||
|     font-weight: bold; | ||||
|     font-size: 5em; | ||||
|     margin-block-start: 0; | ||||
|     margin-block-end: 0; | ||||
|     margin-top: 0.5em; | ||||
|     margin-bottom: 0.5em; | ||||
|     margin: 0.25em; | ||||
|     text-align: center; | ||||
| } | ||||
| 
 | ||||
| .top_button { | ||||
|     background-color: transparent; | ||||
|     border: none; | ||||
|     fill: white; | ||||
|     cursor: pointer; | ||||
|     padding: 0; | ||||
| .ingame { | ||||
|     margin: 0; | ||||
| } | ||||
| 
 | ||||
| .header_actions { | ||||
| @ -59,7 +78,6 @@ | ||||
|     border-radius: var(--button-and-dialog-border-radius); | ||||
|     cursor: pointer; | ||||
|     font-family: "Titan One", sans-serif; | ||||
|     font-size: 3em; | ||||
|     margin-left: auto; | ||||
|     margin-right: auto; | ||||
|     padding-top: 0.5em; | ||||
| @ -75,3 +93,92 @@ | ||||
|     transform: translate(0.1em, 0.1em); | ||||
|     box-shadow: 10px -10px 25px 0px black, -10px 10px 25px 0px black; | ||||
| } | ||||
| 
 | ||||
| .game_mode_selection { | ||||
|     align-items: center; | ||||
|     background-image: url("../images/start_background.png"); | ||||
|     background-position: center; | ||||
|     background-repeat: no-repeat; | ||||
|     background-size: cover; | ||||
|     display: flex; | ||||
|     flex-direction: column; | ||||
|     flex-wrap: nowrap; | ||||
|     height: 100vh; | ||||
|     justify-content: center; | ||||
| } | ||||
| 
 | ||||
| .game_mode_item { | ||||
|     margin: 0.5em; | ||||
|     display: flex; | ||||
|     flex-direction: column; | ||||
|     align-content: center; | ||||
|     justify-content: center; | ||||
|     align-items: center; | ||||
| } | ||||
| 
 | ||||
| .game_mode_item_title { | ||||
|     font-family: "Titan One", sans-serif; | ||||
|     font-size: 2em; | ||||
|     margin: 0.25em; | ||||
| } | ||||
| 
 | ||||
| .game_mode_item_input_text_single_line { | ||||
|     align-items: center; | ||||
|     display: flex; | ||||
|     flex-direction: row; | ||||
|     flex-wrap: wrap; | ||||
|     justify-content: center; | ||||
|     margin-top: 0.5em; | ||||
|     margin-bottom: 0.5em; | ||||
| } | ||||
| 
 | ||||
| .game_mode_items { | ||||
|     display: flex; | ||||
|     flex-direction: row; | ||||
|     flex-wrap: wrap; | ||||
|     justify-content: center; | ||||
|     align-items: center; | ||||
| } | ||||
| 
 | ||||
| .game_mode_choice_selector { | ||||
|     background-color: black; | ||||
|     border-color: white; | ||||
|     border-style: solid; | ||||
|     border-radius: 1.5em; | ||||
|     padding: 1em; | ||||
| } | ||||
| 
 | ||||
| .game_start_failed { | ||||
|     color: #BD1E1E; | ||||
|     font-family: "Roboto Mono", sans-serif; | ||||
|     font-size: 1em; | ||||
|     font-size: 1.5em; | ||||
|     font-weight: bold; | ||||
|     margin-bottom: 0.25em; | ||||
|     margin-left: 0.5em; | ||||
|     margin-top: 0.25em; | ||||
|     margin-right: 0.5em; | ||||
| } | ||||
| 
 | ||||
| .theme_switcher { | ||||
|     fill: white; | ||||
| } | ||||
| 
 | ||||
| #back_button { | ||||
|     position: absolute; | ||||
|     left: 0; | ||||
|     top: 0; | ||||
| } | ||||
| 
 | ||||
| #create_room_button, #join_room_button, #start_solo_game_button { | ||||
|     font-size: 1.5em; | ||||
| } | ||||
| 
 | ||||
| #game_username { | ||||
|     margin: 0.5em; | ||||
|     width: calc(100% - 1.5em); | ||||
| } | ||||
| 
 | ||||
| #play_button { | ||||
|     font-size: 3em; | ||||
| } | ||||
|  | ||||
							
								
								
									
										145
									
								
								truthseeker/static/js/game_start_page.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								truthseeker/static/js/game_start_page.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,145 @@ | ||||
| /** | ||||
|  * Show the game selection view. | ||||
|  * | ||||
|  * <p> | ||||
|  * The "hidden" class is added on the footer, the game_start elements and the game_mode_selection | ||||
|  * elements are show. The body margin is also set to 0 by adding the ingame class. | ||||
|  * </p> | ||||
|  */ | ||||
| function showGameModeSelection() { | ||||
|     document.getElementsByTagName("body")[0].classList.add("ingame"); | ||||
|     document.getElementsByTagName("footer")[0].classList.add("hidden"); | ||||
|     document.getElementsByClassName("game_start")[0].classList.add("hidden"); | ||||
|     document.getElementsByClassName("game_mode_selection")[0].classList.remove("hidden"); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Show the game selection view. | ||||
|  * | ||||
|  * <p> | ||||
|  * The "hidden" class is removed on the footer, the game_start elements and the game_mode_selection | ||||
|  * elements are hidden. The body margin is also set to its normal value by removing the ingame | ||||
|  * class. | ||||
|  * </p> | ||||
|  */ | ||||
| function hideGameModeSelection() { | ||||
|     document.getElementsByTagName("body")[0].classList.remove("ingame"); | ||||
|     document.getElementsByTagName("footer")[0].classList.remove("hidden"); | ||||
|     document.getElementsByClassName("game_start")[0].classList.remove("hidden"); | ||||
|     document.getElementsByClassName("game_mode_selection")[0].classList.add("hidden"); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Hide an error message on the first game_start_failed CSS element. | ||||
|  * | ||||
|  * <p> | ||||
|  * The element will be hidden by removing the hidden CSS class on the element. | ||||
|  * </p> | ||||
|  */ | ||||
| function hideInvalidInputErrorMessage() { | ||||
|     document.getElementsByClassName("game_start_failed")[0].classList.add("hidden"); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Show an error message on the first game_start_failed CSS element. | ||||
|  * | ||||
|  * <p> | ||||
|  * The current error message text will be replaced by the given message and the element will be | ||||
|  * shown, by removing the hidden CSS class on the element. | ||||
|  * </p> | ||||
|  * | ||||
|  * @param {boolean} errorMessage the error message to show | ||||
|  */ | ||||
| function showInvalidInputErrorMessage(errorMessage) { | ||||
|     let gameStartFailedElement = document.getElementsByClassName("game_start_failed")[0]; | ||||
|     gameStartFailedElement.textContent = errorMessage; | ||||
|     gameStartFailedElement.classList.remove("hidden"); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Determine whether a nickname is invalid. | ||||
|  * | ||||
|  * <p> | ||||
|  * A nickname is invalid when it only contains spaces characters or is empty. | ||||
|  * </p> | ||||
|  * | ||||
|  * @returns whether a nickname is invalid | ||||
|  */ | ||||
| function isNickNameInvalid() { | ||||
|     return document.getElementById("game_username").value.trim() == ""; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Determine whether a room code is invalid. | ||||
|  * | ||||
|  * <p> | ||||
|  * A room code is invalid when it only contains spaces characters or is empty. | ||||
|  * </p> | ||||
|  * | ||||
|  * @returns whether a room code is invalid | ||||
|  */ | ||||
| function isRoomCodeInvalid() { | ||||
|     return document.getElementById("game_room_code").value.trim() == ""; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Determine whether nickname and/or room code inputs are valid. | ||||
|  * | ||||
|  * <p> | ||||
|  * The nickname validity is always checked, while the room code validity is checked only when | ||||
|  * checkRoomCode is true (because when creating a room or playing on a solo match, the room code is | ||||
|  * not used so checking it would be useless and would require a valid room code). | ||||
|  * </p> | ||||
|  * | ||||
|  * @param {boolean} checkRoomCode whether the room code input should be checked | ||||
|  * @returns whether the checked inputs are valid | ||||
|  */ | ||||
| function areInputsValid(checkRoomCode) { | ||||
|     if (isNickNameInvalid()) { | ||||
|         showInvalidInputErrorMessage("Le nom saisi n'est pas valide."); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     if (checkRoomCode && isRoomCodeInvalid())  { | ||||
|         showInvalidInputErrorMessage("Le code de salon saisi n'est pas valide."); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| function startSoloGame() { | ||||
|     if (!areInputsValid(false)) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     hideInvalidInputErrorMessage(); | ||||
| 
 | ||||
|     //TODO: code to start solo game
 | ||||
| } | ||||
| 
 | ||||
| function createMultiPlayerRoom() { | ||||
|     if (!areInputsValid(false)) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     hideInvalidInputErrorMessage(); | ||||
| 
 | ||||
|     //TODO: code to create multi player game
 | ||||
| } | ||||
| 
 | ||||
| function joinMultiPlayerRoom() { | ||||
|     if (!areInputsValid(true)) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     hideInvalidInputErrorMessage(); | ||||
| 
 | ||||
|     //TODO: code to join multi player game
 | ||||
| } | ||||
| 
 | ||||
| document.getElementById("play_button").addEventListener("click", showGameModeSelection); | ||||
| document.getElementById("back_button").addEventListener("click", hideGameModeSelection); | ||||
| document.getElementById("start_solo_game_button").addEventListener("click", startSoloGame); | ||||
| document.getElementById("create_room_button").addEventListener("click", createMultiPlayerRoom); | ||||
| document.getElementById("join_room_button").addEventListener("click", joinMultiPlayerRoom); | ||||
| @ -12,7 +12,7 @@ | ||||
|         <div class="alert_dialog_background"></div> | ||||
|         <div class="game_start"> | ||||
|             <div class="header_actions"> | ||||
|                 <button class="top_button theme_switcher" aria-label="Changer de thème"> | ||||
|                 <button class="theme_switcher" aria-label="Changer de thème"> | ||||
|                     <svg class="theme_switcher_btn" xmlns="http://www.w3.org/2000/svg" height="48" width="48"> | ||||
|                         <path d="M24 34q-4.15 0-7.075-2.925T14 24q0-4.15 2.925-7.075T24 14q4.15 0 7.075 2.925T34 24q0 4.15-2.925 7.075T24 34ZM2 25.5v-3h8v3Zm36 0v-3h8v3ZM22.5 10V2h3v8Zm0 36v-8h3v8Zm-9.45-30.85L8.1 10.2l2.1-2.1 4.95 4.95ZM37.8 39.9l-4.95-4.95 2.1-2.1 4.95 4.95Zm-2.85-24.75-2.1-2.1L37.8 8.1l2.1 2.1ZM10.2 39.9l-2.1-2.1 4.95-4.95 2.1 2.1Z"/> | ||||
|                     </svg> | ||||
| @ -23,6 +23,33 @@ | ||||
|                 <button class="action_button" id="play_button">Jouer</button> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="game_mode_selection hidden"> | ||||
|             <button id="back_button" aria-label="Retourner à la page précédente"> | ||||
|                 <svg class="back_btn" xmlns="http://www.w3.org/2000/svg" height="48" width="48"> | ||||
|                     <path d="m23.15 36.95-17.3-11.1Q4.7 25.25 4.7 24t1.15-1.9L23.15 11q1.15-.7 2.35-.075 1.2.625 1.2 2.025v8.75h15.8q.95 0 1.625.675T44.8 24q0 .95-.675 1.6-.675.65-1.625.65H26.7V35q0 1.45-1.2 2.075-1.2.625-2.35-.125Z"/> | ||||
|                 </svg> | ||||
|             </button> | ||||
|             <h1 class="game_title">Thruth Inquiry</h1> | ||||
|             <div class="game_mode_choice_selector"> | ||||
|                 <p class="game_start_failed hidden">Une erreur s'est produite. Réessayez ultérieurement.</p> | ||||
|                 <input type="text" id="game_username" placeholder="Entrez un pseudo" value="" required="required" maxlength="20"> | ||||
|                 <div class="game_mode_items"> | ||||
|                     <div class="game_mode_item"> | ||||
|                         <h2 class="game_mode_item_title">Mode Solo</h2> | ||||
|                         <button class="action_button" id="start_solo_game_button">Jouer</button> | ||||
|                     </div> | ||||
|                     <div class="game_mode_item"> | ||||
|                         <h2 class="game_mode_item_title">Mode Multi</h2> | ||||
|                         <button class="action_button" id="create_room_button">Créer un salon</button> | ||||
|                         <div class="game_mode_item_input_text_single_line"> | ||||
|                             <h3 class="game_mode_item_title">Code :</h3> | ||||
|                             <input type="text" id="game_room_code" placeholder="" value="" required="required" maxlength="20"> | ||||
|                         </div> | ||||
|                         <button class="action_button" id="join_room_button">Rejoindre</button> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="unsupported_browser"> | ||||
|             <div id="unsupported_browser_dialog" class="alert_dialog"> | ||||
|                 <h3 class="alert_dialog_title">Navigateur non supporté</h3> | ||||
| @ -46,5 +73,6 @@ | ||||
|             </div> | ||||
|         </footer> | ||||
|         <script src="/static/js/game_common.js"></script> | ||||
|         <script src="/static/js/game_start_page.js"></script> | ||||
|     </body> | ||||
| </html> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user