From c776bbf9a553dc69fc101b8a64305e66098298f3 Mon Sep 17 00:00:00 2001 From: Marine Date: Sat, 27 Jan 2024 16:25:53 +0100 Subject: [PATCH] connect UI --- Assets/Scenes/PhoneView.unity | 329 +++++++++++++++++++++++++++++++++- Assets/Scripts/GameManager.cs | 122 ++++++++++++- Assets/Scripts/PhoneLoop.cs | 85 ++++++++- 3 files changed, 521 insertions(+), 15 deletions(-) diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 8fa58c3..f7f6492 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -1049,7 +1049,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &638947074 RectTransform: m_ObjectHideFlags: 0 @@ -1113,7 +1113,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 638947076} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 1202782732} + m_TargetAssemblyTypeName: GameManager, Assembly-CSharp + m_MethodName: StartGame + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &638947076 MonoBehaviour: m_ObjectHideFlags: 0 @@ -2105,6 +2117,140 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &991600091 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 991600092} + - component: {fileID: 991600094} + - component: {fileID: 991600093} + m_Layer: 5 + m_Name: ErrorCodeLabel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &991600092 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 991600091} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2023851069} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 2.9758, y: 20.4609} + m_SizeDelta: {x: 154.05, y: 13.5401} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &991600093 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 991600091} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 'Error: the room code is invalide' + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2} + m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4278190335 + m_fontColor: {r: 1, g: 0, b: 0, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 11.43 + m_fontSizeBase: 11.43 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: -0.000000025251643, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &991600094 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 991600091} + m_CullTransparentMesh: 1 --- !u!1 &1034781733 GameObject: m_ObjectHideFlags: 0 @@ -2596,7 +2742,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1158329300} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 1202782732} + m_TargetAssemblyTypeName: GameManager, Assembly-CSharp + m_MethodName: PlayerValidateNameAndServerRoom + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &1158329300 MonoBehaviour: m_ObjectHideFlags: 0 @@ -2668,6 +2826,7 @@ RectTransform: m_Children: - {fileID: 1288753599} - {fileID: 1770783105} + - {fileID: 1224049645} m_Father: {fileID: 2027556832} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} @@ -2958,7 +3117,7 @@ GameObject: - component: {fileID: 1202782729} - component: {fileID: 1202782728} - component: {fileID: 1202782727} - - component: {fileID: 1202782731} + - component: {fileID: 1202782732} m_Layer: 5 m_Name: Canvas m_TagString: Untagged @@ -3049,7 +3208,7 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} ---- !u!114 &1202782731 +--- !u!114 &1202782732 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -3058,9 +3217,160 @@ MonoBehaviour: m_GameObject: {fileID: 1202782726} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 77ca3ece4774c244e96dcee6ab926fbb, type: 3} + m_Script: {fileID: 11500000, guid: 27a435387a7644784a6fc6ae538b68e5, type: 3} m_Name: m_EditorClassIdentifier: + isRoomExist: 1 + isPlayerExist: 1 + explanationTime: 4 + roomCodeField: {fileID: 2023851070} + roomError: {fileID: 991600093} + playerNameField: {fileID: 1163479463} + nameError: {fileID: 1224049646} + submitNewPlayer: {fileID: 1158329299} + listPlayersUI: {fileID: 1891690322} + submitStartGame: {fileID: 638947073} + HomeConnection: {fileID: 2027556831} + WaitingRoom: {fileID: 1590939977} + BeforeStart: {fileID: 563000513} + TakePicture: {fileID: 1181392805} + VotePicture: {fileID: 531335861} + WaitingOtherPlayers: {fileID: 2095389711} + EndGame: {fileID: 1850164816} +--- !u!1 &1224049644 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1224049645} + - component: {fileID: 1224049647} + - component: {fileID: 1224049646} + m_Layer: 5 + m_Name: ErrorNameLabel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &1224049645 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1224049644} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.0029413, y: 1.0029413, z: 0.8627451} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1163479462} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 2.9845557, y: 18.5} + m_SizeDelta: {x: 154.05, y: 13.5401} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1224049646 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1224049644} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 'Error: only numbers and letters' + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2} + m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4278190335 + m_fontColor: {r: 1, g: 0, b: 0, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 11.43 + m_fontSizeBase: 11.43 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: -0.000000025251643, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1224049647 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1224049644} + m_CullTransparentMesh: 1 --- !u!1 &1266773203 GameObject: m_ObjectHideFlags: 0 @@ -4703,8 +5013,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: -38.8} - m_SizeDelta: {x: 200, y: 50} + m_AnchoredPosition: {x: 2.8591, y: -36.5711} + m_SizeDelta: {x: 194.2818, y: 45.5423} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1770783106 MonoBehaviour: @@ -5610,6 +5920,7 @@ RectTransform: m_ConstrainProportionsScale: 1 m_Children: - {fileID: 2008743696} + - {fileID: 991600092} m_Father: {fileID: 2027556832} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} @@ -5768,7 +6079,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &2027556832 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 8f9ba43..0e50569 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,8 +1,10 @@ +using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; +using UnityEngine.UIElements; /// /// This is the game state manager on the phone side @@ -12,17 +14,50 @@ public class GameManager : MonoBehaviour private GameState currentState; private List players = new List(); + [Header("Temp variables")] + public bool isRoomExist = true; + public bool isPlayerExist = true; + + + [Header("Other component")] public float explanationTime = 4f; private float currentExplanationTime = 0; - public InputField roomCodeField; + [Header("Home Component")] + public TMP_InputField roomCodeField; public TextMeshProUGUI roomError; - public InputField playerNameField; + public TMP_InputField playerNameField; public TextMeshProUGUI nameError; + public UnityEngine.UI.Button submitNewPlayer; + + + [Header("WaitingRoom Component")] + public TextMeshProUGUI listPlayersUI; + public GameObject submitStartGame; + + + [Header("Pages")] + [SerializeField] + public GameObject HomeConnection; + [SerializeField] + public GameObject WaitingRoom; + [SerializeField] + public GameObject BeforeStart; + [SerializeField] + public GameObject TakePicture; + [SerializeField] + public GameObject VotePicture; + [SerializeField] + public GameObject WaitingOtherPlayers; + [SerializeField] + public GameObject EndGame; + + private void Start() { currentExplanationTime = explanationTime; + HomeConnection.SetActive(true); } public GameState GetCurrentState() @@ -35,12 +70,63 @@ public GameState GetCurrentState() /// public void PlayerValidateNameAndServerRoom() { - //check if the room exists, if not display an error message + String playerName = playerNameField.text; + String roomCode = roomCodeField.text; + + // send to the server the room code and the player name + + // MORGANE ENVOIE AU SERV + + // answer isPlayerExist and isRoomExist //if succeed, then the player to the server + if (isPlayerExist && isRoomExist) + { + currentState = GameState.WaitingForOtherPlayersToJoin; + WaitingRoom.SetActive(true); + HomeConnection.SetActive(false); + + + //TEMP + Player player = new Player(); + player.SetName(playerName); + player.id = "1"; + + players.Add(player); + if (players.Count == 1) + { + submitStartGame.SetActive(true); + } + + Player player2 = new Player(); + player2.SetName("3J"); + player2.id = "2"; + Player player3 = new Player(); + player3.SetName("3J"); + player3.id = "3"; + Player player4 = new Player(); + player4.SetName("3J"); + player4.id = "4"; + Player player5 = new Player(); + player5.SetName("3J"); + player5.id = "5"; + Player player6 = new Player(); + player6.SetName("3J"); + player6.id = "6"; + + + players.Add(player2); + players.Add(player3); + players.Add(player4); + players.Add(player5); + players.Add(player6); + UpdateDisplayedListUser(); + } + // else we show the errors + roomError.gameObject.SetActive(!isRoomExist); + nameError.gameObject.SetActive(!isPlayerExist); + - //if succeed, change the state and change page - currentState = GameState.WaitingForOtherPlayersToJoin; } /// @@ -48,6 +134,12 @@ public void PlayerValidateNameAndServerRoom() /// public void StartGame() { + // send Start Game + + currentState = GameState.Explanation; + WaitingRoom.SetActive(false); + BeforeStart.SetActive(true); + } @@ -58,7 +150,9 @@ public void StartGame() /// The prompt to display public void MakeAProposition(Prompt _prompt) { + currentState = GameState.MakeProposition; + } /// @@ -101,7 +195,25 @@ public void DisplayEndScreen() /// private void OnRoomUpdate() { + switch (currentState) + { + case GameState.WaitingForOtherPlayersToJoin: + { + // players = new list en fonction de ce qu'envoie fangh + UpdateDisplayedListUser(); + break; + } + } + } + + private void UpdateDisplayedListUser() + { + listPlayersUI.text = string.Empty; + for (int i = 0; i < players.Count; i++) + { + listPlayersUI.text += "\n" + players[i].name; + } } } diff --git a/Assets/Scripts/PhoneLoop.cs b/Assets/Scripts/PhoneLoop.cs index e29bcbd..0580aec 100644 --- a/Assets/Scripts/PhoneLoop.cs +++ b/Assets/Scripts/PhoneLoop.cs @@ -1,13 +1,31 @@ using System.Collections; using System.Collections.Generic; +using Unity.VisualScripting; using UnityEngine; public class PhoneLoop : MonoBehaviour { + + + [SerializeField] + public GameObject homeConnection; + [SerializeField] + public GameObject WaitingRoom; + [SerializeField] + public GameObject BeforeStart; + [SerializeField] + public GameObject TakePicture; + [SerializeField] + public GameObject VotePicture; + [SerializeField] + public GameObject WaitingOtherPlayers; + [SerializeField] + public GameObject EndGame; + // Start is called before the first frame update void Start() { - + homeConnection.SetActive(true); } // Update is called once per frame @@ -15,4 +33,69 @@ void Update() { } + + void ShowWaititngRoom() + { + homeConnection.SetActive(false); + WaitingRoom.SetActive(true); + } + + void ShowBeforeStart() + { + WaitingRoom.SetActive(false); + BeforeStart.SetActive(true); + } + + void ShowTakePicture() + { + BeforeStart.SetActive(false); + TakePicture.SetActive(true); + } + + void showWaitingOtherPlayers() + { + if (TakePicture.activeInHierarchy) + { + TakePicture.SetActive(false); + } + if (VotePicture.activeInHierarchy) + { + VotePicture.SetActive(false); + } + WaitingOtherPlayers.SetActive(true); + } + + void ShowVotePicture() + { + + if (TakePicture.activeInHierarchy) + { + TakePicture.SetActive(false); + } + if (WaitingOtherPlayers.activeInHierarchy) + { + WaitingOtherPlayers.SetActive(false); + } + VotePicture.SetActive(true); + + } + + void ShowEndGame() + { + WaitingOtherPlayers.SetActive(false) ; + EndGame.SetActive(true); + + } + + + + [ContextMenu("Fake Player Connection")] + private void FakePlayerConnection() + { + + } + + + + }