From dfe4d047e91405069c7e1df3b83fdb057be8791f Mon Sep 17 00:00:00 2001 From: Glence Date: Sat, 18 Feb 2023 22:21:23 +0800 Subject: [PATCH 01/18] added a jumppad to the game --- Assets/Scenes/MainGame.shade | 37 ++++++++++++++++--- .../Gameplay/Player/SC_PlayerController.cs | 14 ++++++- Assets/Scripts/SC_JumpPad.cs | 22 +++++++++++ Assets/Scripts/SC_JumpPad.cs.shmeta | 3 ++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 Assets/Scripts/SC_JumpPad.cs create mode 100644 Assets/Scripts/SC_JumpPad.cs.shmeta diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 87343839..53b5a0a0 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -9671,6 +9671,7 @@ maxJumpHeight: 2 maxJumpTime: 0.75 fallMultipler: 3 + jumpPadMultiplayer: 1.20000005 lightMultiper: 0.75 mediumMultiper: 0.5 heavyMultiper: 0.25 @@ -9682,6 +9683,7 @@ aimingLength: 1 throwItem: false rayDistance: 0.75 + rayHeight: 0.100000001 - EID: 3 Name: HoldingPoint IsActive: true @@ -10483,11 +10485,11 @@ Translate: {x: 2.70000005, y: 0.100000001, z: -2} Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} - IsActive: true + IsActive: false Renderable Component: Mesh: 140697366 Material: 129495479 - IsActive: true + IsActive: false RigidBody Component: Type: Dynamic Drag: 0.00999999978 @@ -10501,7 +10503,7 @@ Freeze Rotation X: true Freeze Rotation Y: false Freeze Rotation Z: true - IsActive: true + IsActive: false Collider Component: Colliders: - Is Trigger: false @@ -10513,7 +10515,7 @@ Density: 1 Position Offset: {x: 0, y: 0.899999976, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - IsActive: true + IsActive: false Scripts: - Type: Homeowner1 Enabled: true @@ -10525,4 +10527,29 @@ eyeOffset: [0, 1.64999998, 0] distanceToCapture: 0.5 captureTime: 0.5 - footstepSFXIntervalMultiplier: 0.5 \ No newline at end of file + footstepSFXIntervalMultiplier: 0.5 +- EID: 16 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 3.43332767, y: 0.149463654, z: 6.84711409} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Collision Tag: 0 + Type: Box + Half Extents: {x: 1, y: 0.25, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: + - Type: JumpPad + Enabled: true \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs b/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs index d66e7e30..202e587e 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PlayerController.cs @@ -65,7 +65,7 @@ public class PlayerController : Script //Jumping vars================================================================== [Tooltip("max height of the jump")] public float maxJumpHeight = 1.0f; - [Tooltip("max amt of time it will take for the jump")] + [Tooltip("max amount of time it will take for the jump")] public float maxJumpTime = 0.5f; [Tooltip("increase gravity when falling")] public float fallMultipler = 3.0f; @@ -73,6 +73,9 @@ public class PlayerController : Script private bool isGrounded = true; private float gravity = -9.8f; private float groundGravity = -0.5f; + public bool landedOnJumpPad { get; set; } + [Tooltip("multiply height on Jump Pad ")] + public float jumpPadMultiplayer = 2.0f; //ItemMultipler================================================================== [Tooltip("How light item will affect player jump")] @@ -88,6 +91,7 @@ public class PlayerController : Script isMoveKeyPress = false; holdItem = false; isAiming = false; + landedOnJumpPad = false; //Jump setup float timeToApex = maxJumpTime / 2; @@ -287,7 +291,7 @@ public class PlayerController : Script { if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE) { - if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null) + if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad ) && isGrounded && rb != null) { currentState = RaccoonStates.JUMP; Vector3 v = rb.LinearVelocity; @@ -302,6 +306,12 @@ public class PlayerController : Script if (item != null && item.currCategory == ItemCategory.HEAVY) v.y *= heavyMultiper; } + + if (landedOnJumpPad) + { + v.y *= jumpPadMultiplayer; + landedOnJumpPad = false; + } rb.LinearVelocity = v; } } diff --git a/Assets/Scripts/SC_JumpPad.cs b/Assets/Scripts/SC_JumpPad.cs new file mode 100644 index 00000000..0e331f8c --- /dev/null +++ b/Assets/Scripts/SC_JumpPad.cs @@ -0,0 +1,22 @@ +using SHADE; +using System; + +public class JumpPad : Script +{ + protected override void awake() + { + } + + protected override void update() + { + } + + protected override void onCollisionEnter(CollisionInfo info) + { + if (info.GameObject.GetScript() && info.GameObject.GetScript().currentState == PlayerController.RaccoonStates.FALLING) + { + info.GameObject.GetScript().landedOnJumpPad = true; + } + } + +} diff --git a/Assets/Scripts/SC_JumpPad.cs.shmeta b/Assets/Scripts/SC_JumpPad.cs.shmeta new file mode 100644 index 00000000..62a99f19 --- /dev/null +++ b/Assets/Scripts/SC_JumpPad.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_JumpPad +ID: 167326885 +Type: 9 From d754a0b5c3836c7a236a7b15f57c5affc48c976d Mon Sep 17 00:00:00 2001 From: Glence Date: Sat, 18 Feb 2023 23:43:43 +0800 Subject: [PATCH 02/18] added targetOffSet to camera position --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 6ebbd078..d508fc09 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -265,7 +265,7 @@ namespace SHADE { camera.offset = arm->GetOffset(); if (arm->lookAtCameraOrigin) - CameraLookAt(camera, camera.position); + CameraLookAt(camera, camera.position + arm->GetTargetOffset()); } From 09d88b5a70d75974ae64265867daa119a20f8579 Mon Sep 17 00:00:00 2001 From: Glence Date: Mon, 20 Feb 2023 19:53:22 +0800 Subject: [PATCH 03/18] small bug fixes for text and serialization and added game pause --- Assets/Scenes/MainGame.shade | 137 +++++++++++++++--- Assets/Scripts/Audio/AudioHandler.cs | 8 + .../Gameplay/Player/SC_PickAndThrow.cs | 15 +- .../Gameplay/Player/SC_ThirdPersonCamera.cs | 16 +- Assets/Scripts/Gameplay/SC_GameManager.cs | 26 +++- .../SHTextRenderingSubSystem.cpp | 4 + .../src/Serialization/SHSerialization.cpp | 7 + 7 files changed, 183 insertions(+), 30 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index f1b16c1b..5e30379e 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -9563,6 +9563,7 @@ timer: 200 scoreText: 237 timeText: 206 + gamePauseText: 11 multiplierText: 139 maxMultiplierDuration: 5 maxMultiplierCombo: 10 @@ -9570,7 +9571,7 @@ - EID: 199 Name: =====Text==== IsActive: true - NumberOfChildren: 3 + NumberOfChildren: 4 Components: ~ Scripts: ~ - EID: 237 @@ -9618,6 +9619,21 @@ Font: 176667660 IsActive: true Scripts: ~ +- EID: 11 + Name: GamePause + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -145, y: 200, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 60, y: 60, z: 60} + IsActive: true + Text Renderer Component: + Text: Game Pause + Font: 176667660 + IsActive: true + Scripts: ~ - EID: 198 Name: ====Raccoon==== IsActive: true @@ -9677,18 +9693,20 @@ maxJumpTime: 0.75 fallMultipler: 3 jumpPadMultiplayer: 1.20000005 - lightMultiper: 0.75 - mediumMultiper: 0.5 - heavyMultiper: 0.25 + lightMultiper: 0.899999976 + mediumMultiper: 0.699999988 + heavyMultiper: 0.5 - Type: PickAndThrow Enabled: true throwForce: [10, 8, 10] - cameraArmOffSet: [0, 0.25, 0] + cameraArmOffSet: [0.25, 0.600000024, 0.200000003] delayTimer: 1 aimingLength: 1 throwItem: false rayDistance: 0.75 rayHeight: 0.100000001 + aimingFOV: 50 + defaultFOV: 45 - EID: 3 Name: HoldingPoint IsActive: true @@ -9715,30 +9733,31 @@ Pitch: 0 Yaw: 360 Roll: 1.28065994e-06 - Width: 1920 - Height: 1080 + Width: 1055 + Height: 604 Near: 0.00999999978 Far: 10000 Perspective: true + FOV: 45 IsActive: true Camera Arm Component: Arm Pitch: 0 Arm Yaw: 0 Arm Length: 3 Look At Camera Origin: true - Target Offset: {x: 0, y: 0, z: 0} + Target Offset: {x: 0, y: 0.75, z: 0} Camera Collision: true IsActive: true Scripts: - Type: SHADE_Scripting.ThirdPersonCamera Enabled: true armLength: 3 - turnSpeedPitch: 0.300000012 - turnSpeedYaw: 0.5 - pitchClamp: 45 + turnSpeedPitch: 0.200000003 + turnSpeedYaw: 0.400000006 inverseXControls: false - inverseYControls: true - lowerClamp: 5 + inverseYControls: false + pitchUpperClamp: 45 + pitchLowerClamp: 5 - EID: 9 Name: PlayerBag IsActive: true @@ -10533,28 +10552,108 @@ distanceToCapture: 0.5 captureTime: 0.5 footstepSFXIntervalMultiplier: 0.5 -- EID: 16 - Name: Default +- EID: 12 + Name: Mesh_Meat IsActive: true NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 3.43332767, y: 0.149463654, z: 6.84711409} + Translate: {x: 2.30459714, y: 0.209537908, z: 6.371418} Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} IsActive: true + Renderable Component: + Mesh: 136892700 + Material: 131956078 + IsActive: true + RigidBody Component: + Type: Dynamic + Drag: 0.00999999978 + Angular Drag: 0.100000001 + Use Gravity: true + Interpolate: false + Sleeping Enabled: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true Collider Component: Colliders: - Is Trigger: false - Collision Tag: 0 + Collision Tag: 2 Type: Box - Half Extents: {x: 1, y: 0.25, z: 1} + Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} Friction: 0.400000006 Bounciness: 0 Density: 1 Position Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} IsActive: true + Scripts: + - Type: Item + Enabled: true + Score: 50 + currCategory: 1 + density: 1 + dontReturn: false +- EID: 16 + Name: JumpPad + IsActive: false + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 3.43332767, y: 0.149463654, z: 6.84711409} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: false + Collider Component: + Colliders: + - Is Trigger: false + Collision Tag: 1 + Type: Box + Half Extents: {x: 1, y: 0.25, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: false Scripts: - Type: JumpPad - Enabled: true \ No newline at end of file + Enabled: true +- EID: 10 + Name: Canvas + IsActive: false + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 1920 + Canvas Height: 1080 + IsActive: false + Scripts: ~ +- EID: 8 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 300, y: 200, z: 500} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Button Component: + Default Texture: 52901020 + Hovered Texture: 62235279 + Clicked Texture: 64722619 + IsActive: true + UI Component: + Canvas ID: 10 + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/Audio/AudioHandler.cs b/Assets/Scripts/Audio/AudioHandler.cs index f2e552c1..c6067819 100644 --- a/Assets/Scripts/Audio/AudioHandler.cs +++ b/Assets/Scripts/Audio/AudioHandler.cs @@ -19,5 +19,13 @@ namespace SHADE_Scripting.Audio h.Value.Stop(fadeOut); } } + + public static void pauseAllSounds(bool pause) + { + foreach (KeyValuePair h in audioClipHandlers) + { + h.Value.SetPause(pause); + } + } } } diff --git a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs index a2f1ddb8..d5046db1 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs @@ -8,7 +8,7 @@ using static Item; public class PickAndThrow : Script { - public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f); + public Vector3 throwForce = new Vector3(10.0f, 8.0f, 10.0f); public Vector3 cameraArmOffSet = new Vector3(0.0f, 0.25f, 0.0f); public GameObject item { get; set; } public float delayTimer = 1.0f; @@ -33,6 +33,9 @@ public class PickAndThrow : Script [Tooltip("Height of ray")] public float rayHeight = 0.1f; + public float aimingFOV = 50; + public float defaultFOV = 45; + protected override void awake() { pc = GetScript(); @@ -74,6 +77,7 @@ public class PickAndThrow : Script pc.isAiming = true; pc.camArm.ArmLength = aimingLength; pc.camArm.TargetOffset = cameraArmOffSet; + pc.cam.FOV = aimingFOV; } if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) @@ -83,6 +87,7 @@ public class PickAndThrow : Script itemCollider.GetCollisionShape(0).IsTrigger = false; pc.isAiming = false; pc.camArm.TargetOffset = Vector3.Zero; + pc.cam.FOV = defaultFOV; if (tpc) pc.camArm.ArmLength = tpc.armLength; pc.holdItem = false; @@ -103,6 +108,7 @@ public class PickAndThrow : Script if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && pc.isAiming) { pc.isAiming = false; + pc.cam.FOV = defaultFOV; pc.camArm.TargetOffset = Vector3.Zero; if (tpc) pc.camArm.ArmLength = tpc.armLength; @@ -132,7 +138,7 @@ public class PickAndThrow : Script { if (itemScript) { - Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir); + Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y + (throwForce.y * GetPitchRatioRange()), throwForce.z * lastZDir); if (itemScript.currCategory == ItemCategory.LIGHT) itemRidigBody.AddForce(vec * 0.2f); if (itemScript.currCategory == ItemCategory.MEDIUM) @@ -254,5 +260,10 @@ public class PickAndThrow : Script return false; } + private float GetPitchRatioRange() + { + return (pc.camArm.Pitch - tpc.pitchUpperClamp) / (tpc.pitchLowerClamp - tpc.pitchUpperClamp); + } + } \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/SC_ThirdPersonCamera.cs b/Assets/Scripts/Gameplay/Player/SC_ThirdPersonCamera.cs index b03dbf2f..c3026ce6 100644 --- a/Assets/Scripts/Gameplay/Player/SC_ThirdPersonCamera.cs +++ b/Assets/Scripts/Gameplay/Player/SC_ThirdPersonCamera.cs @@ -14,10 +14,10 @@ namespace SHADE_Scripting public float armLength = 2.0f; public float turnSpeedPitch = 0.3f; public float turnSpeedYaw = 0.5f; - public float pitchClamp = 45.0f; public bool inverseXControls = false; public bool inverseYControls = false; - public float lowerClamp = 5.0f; + public float pitchUpperClamp = 45.0f; + public float pitchLowerClamp = 5.0f; protected override void awake() { @@ -51,17 +51,17 @@ namespace SHADE_Scripting arm.Pitch += vel.y * turnSpeedPitch * Time.DeltaTimeF; if (inverseXControls) - arm.Yaw -= vel.x * turnSpeedYaw * Time.DeltaTimeF; - else arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; + else + arm.Yaw -= vel.x * turnSpeedYaw * Time.DeltaTimeF; - if (arm.Pitch > pitchClamp) + if (arm.Pitch > pitchUpperClamp) { - arm.Pitch = pitchClamp; + arm.Pitch = pitchUpperClamp; } - else if (arm.Pitch < lowerClamp) + else if (arm.Pitch < pitchLowerClamp) { - arm.Pitch = lowerClamp; + arm.Pitch = pitchLowerClamp; } } } diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index 83b0747a..24a7012b 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -26,6 +26,7 @@ public class GameManager : Script public GameObject scoreText; public GameObject timeText; + public GameObject gamePauseText; //mulitpler info public GameObject multiplierText; @@ -38,6 +39,9 @@ public class GameManager : Script private Vector3 fontScalar; public static GameManager Instance { get; private set; } + //public static int highScore { get; private set; } maybe need + + public bool GamePause { get; set; } protected override void start() { @@ -76,6 +80,7 @@ public class GameManager : Script currMultiplierCombo = 1; currMultiplierDuration = 0; fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration); + GamePause = false; AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win"); AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose"); @@ -83,7 +88,26 @@ public class GameManager : Script protected override void update() { - Cheats(); + if (GamePause) + { + if (Input.GetKeyDown(Input.KeyCode.Escape) && GamePause) + { + GamePause = false; + AudioHandler.pauseAllSounds(false); + gamePauseText.GetComponent().Enabled = false; + } + return; + } + + //Cheats(); + + if (Input.GetKeyDown(Input.KeyCode.Escape) && !GamePause) + { + GamePause = true; + AudioHandler.pauseAllSounds(true); + gamePauseText.GetComponent().Enabled = true; + } + if (currGameState == GameState.START) { timer -= Time.DeltaTimeF; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index ffd5ac96..e1935634 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -13,6 +13,7 @@ #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" #include "Graphics/MiddleEnd/Interface/SHRenderer.h" +#include "Scene/SHSceneManager.h" namespace SHADE { @@ -184,6 +185,9 @@ namespace SHADE for (auto& comp : textRendererComps) { + if (!SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + continue; + auto* transform = SHComponentManager::GetComponent(comp.GetEID()); Handle fontHandle = comp.fontHandle; diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index bb0f4a43..febca024 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -70,6 +70,7 @@ namespace SHADE //Compile component IDs const auto componentIDList = SHSerialization::GetComponentIDList(node[ComponentsNode]); eid = SHEntityManager::CreateEntity(componentIDList, eid, name, parentEID); + createdEntities[oldEID] = eid; //createdEntities.push_back(eid); if (node[NumberOfChildrenNode]) @@ -90,6 +91,12 @@ namespace SHADE if (node[ScriptsNode]) SHSystemManager::GetSystem()->DeserialiseScripts(eid, node[ScriptsNode]); + auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + if (node[IsActiveNode]) + { + sceneGraph.SetActive(eid, node[IsActiveNode].as()); + } + return eid; } From d7725f4e26f1c8e03c171d2bb6834585a8b3e28b Mon Sep 17 00:00:00 2001 From: Glence Date: Tue, 21 Feb 2023 00:47:20 +0800 Subject: [PATCH 04/18] Pause is done --- Assets/Scenes/MainGame.shade | 70 ++++++++++++-- Assets/Scripts/Gameplay/SC_GameManager.cs | 26 ------ Assets/Scripts/UI/SC_PauseMenu.cs | 106 ++++++++++++++++++++++ Assets/Scripts/UI/SC_PauseMenu.cs.shmeta | 3 + 4 files changed, 170 insertions(+), 35 deletions(-) create mode 100644 Assets/Scripts/UI/SC_PauseMenu.cs create mode 100644 Assets/Scripts/UI/SC_PauseMenu.cs.shmeta diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 5e30379e..591c386f 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -9563,11 +9563,17 @@ timer: 200 scoreText: 237 timeText: 206 - gamePauseText: 11 multiplierText: 139 maxMultiplierDuration: 5 maxMultiplierCombo: 10 multiplierFont: 60 + - Type: PauseMenu + Enabled: true + resumeBtn: 8 + retryBtn: 461 + quitBtn: 0 + gamePauseText: 11 + canvas: 10 - EID: 199 Name: =====Text==== IsActive: true @@ -9625,14 +9631,14 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: -145, y: 200, z: 0} + Translate: {x: -250, y: 300, z: 0} Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 60, y: 60, z: 60} + Scale: {x: 100, y: 100, z: 100} IsActive: true Text Renderer Component: Text: Game Pause Font: 176667660 - IsActive: true + IsActive: false Scripts: ~ - EID: 198 Name: ====Raccoon==== @@ -9733,8 +9739,8 @@ Pitch: 0 Yaw: 360 Roll: 1.28065994e-06 - Width: 1055 - Height: 604 + Width: 2560 + Height: 1369 Near: 0.00999999978 Far: 10000 Perspective: true @@ -10627,7 +10633,7 @@ - EID: 10 Name: Canvas IsActive: false - NumberOfChildren: 1 + NumberOfChildren: 3 Components: Canvas Component: Canvas Width: 1920 @@ -10635,12 +10641,12 @@ IsActive: false Scripts: ~ - EID: 8 - Name: Default + Name: ResumeButton IsActive: true NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: 0, z: 0} + Translate: {x: 0, y: 100, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 300, y: 200, z: 500} IsActive: true @@ -10656,4 +10662,50 @@ UI Component: Canvas ID: 10 IsActive: true + Scripts: ~ +- EID: 0 + Name: QuitButton + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -300, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 300, y: 200, z: 500} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Button Component: + Default Texture: 66477839 + Hovered Texture: 65045286 + Clicked Texture: 58607560 + IsActive: true + UI Component: + Canvas ID: 10 + IsActive: true + Scripts: ~ +- EID: 461 + Name: RetryButton + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -100, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 300, y: 200, z: 500} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Button Component: + Default Texture: 55782622 + Hovered Texture: 58972174 + Clicked Texture: 55224464 + IsActive: true + UI Component: + Canvas ID: 10 + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index 24a7012b..6478b5ea 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -26,7 +26,6 @@ public class GameManager : Script public GameObject scoreText; public GameObject timeText; - public GameObject gamePauseText; //mulitpler info public GameObject multiplierText; @@ -80,7 +79,6 @@ public class GameManager : Script currMultiplierCombo = 1; currMultiplierDuration = 0; fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration); - GamePause = false; AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win"); AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose"); @@ -90,24 +88,9 @@ public class GameManager : Script { if (GamePause) { - if (Input.GetKeyDown(Input.KeyCode.Escape) && GamePause) - { - GamePause = false; - AudioHandler.pauseAllSounds(false); - gamePauseText.GetComponent().Enabled = false; - } return; } - //Cheats(); - - if (Input.GetKeyDown(Input.KeyCode.Escape) && !GamePause) - { - GamePause = true; - AudioHandler.pauseAllSounds(true); - gamePauseText.GetComponent().Enabled = true; - } - if (currGameState == GameState.START) { timer -= Time.DeltaTimeF; @@ -164,15 +147,6 @@ public class GameManager : Script Instance = null; } - private void Cheats() - { - if (Input.GetKeyDown(Input.KeyCode.Escape)) - { - Audio.StopAllSounds(); - SceneManager.ChangeScene(97158628); - } - } - public void ItemScored() { totalItemCount -= 1; diff --git a/Assets/Scripts/UI/SC_PauseMenu.cs b/Assets/Scripts/UI/SC_PauseMenu.cs new file mode 100644 index 00000000..eae7aa91 --- /dev/null +++ b/Assets/Scripts/UI/SC_PauseMenu.cs @@ -0,0 +1,106 @@ +using System; +using SHADE; +using SHADE_Scripting.Audio; + +public class PauseMenu : Script +{ + public GameObject resumeBtn; + public GameObject retryBtn; + public GameObject quitBtn; + + public GameObject gamePauseText; + public GameObject canvas; + + protected override void awake() + { + GameManager.Instance.GamePause = false; + if (gamePauseText) + gamePauseText.GetComponent().Enabled = false; + if (canvas) + canvas.SetActive(false); + + if (!resumeBtn) + Debug.LogError("Resume Btn missing"); + + if (!retryBtn) + Debug.LogError("Retry Btn missing"); + + if (!quitBtn) + Debug.LogError("Quit Btn missing"); + } + protected override void start() + { + //resume + UIElement resume = resumeBtn.GetComponent(); + if (resume != null) + { + resume.OnClick.RegisterAction(() => + { + if (GameManager.Instance.GamePause) + { + GameManager.Instance.GamePause = false; + AudioHandler.pauseAllSounds(false); + if (gamePauseText) + gamePauseText.GetComponent().Enabled = false; + if (canvas) + canvas.SetActive(false); + } + }); + } + else + { + Debug.LogError("Failed to register resume button."); + } + + //retry + UIElement retry = retryBtn.GetComponent(); + if (retry != null) + { + retry.OnClick.RegisterAction(() => + { + Audio.StopAllSounds(); + //get curr scene + //SceneManager.ChangeScene(); + }); + } + else + { + Debug.LogError("Failed to register retry button."); + } + + UIElement quit = quitBtn.GetComponent(); + if (quit != null) + { + quit.OnClick.RegisterAction(() => + { + Audio.StopAllSounds(); + //go to main menu + SceneManager.ChangeScene(97158628); + }); + } + else + { + Debug.LogError("Failed to register quit button."); + } + } + + protected override void update() + { + if (GameManager.Instance.GamePause) + { + return; + } + + if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause) + { + GameManager.Instance.GamePause = true; + AudioHandler.pauseAllSounds(true); + if (gamePauseText) + gamePauseText.GetComponent().Enabled = true; + if (canvas) + canvas.SetActive(true); + } + + } +} + diff --git a/Assets/Scripts/UI/SC_PauseMenu.cs.shmeta b/Assets/Scripts/UI/SC_PauseMenu.cs.shmeta new file mode 100644 index 00000000..0ddcf762 --- /dev/null +++ b/Assets/Scripts/UI/SC_PauseMenu.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_PauseMenu +ID: 151952680 +Type: 9 From febe22e4871b11012233d6ab1505f5415b9e1687 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 21 Feb 2023 09:52:23 +0800 Subject: [PATCH 05/18] Added new button events --- Assets/Editor/Editor.SHConfig | 2 +- SHADE_Engine/src/Events/SHEventDefines.h | 3 + SHADE_Engine/src/UI/SHUISystem.cpp | 233 ++++++++++------------- SHADE_Engine/src/UI/SHUISystem.h | 5 + 4 files changed, 110 insertions(+), 133 deletions(-) diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig index 9bd51ca8..37edf50c 100644 --- a/Assets/Editor/Editor.SHConfig +++ b/Assets/Editor/Editor.SHConfig @@ -1,4 +1,4 @@ Start Maximized: true -Working Scene ID: 86098106 +Working Scene ID: 97158628 Window Size: {x: 1920, y: 1013} Style: 0 \ No newline at end of file diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index fa5bcafb..fffe8b5f 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -26,4 +26,7 @@ constexpr SHEventIdentifier SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT { 17 }; constexpr SHEventIdentifier SH_BUTTON_CLICK_EVENT { 18 }; constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_DRAW_EVENT { 19 }; constexpr SHEventIdentifier SH_WINDOW_RESIZE_EVENT { 20 }; +constexpr SHEventIdentifier SH_BUTTON_RELEASE_EVENT { 21 }; +constexpr SHEventIdentifier SH_BUTTON_HOVER_ENTER_EVENT { 22 }; +constexpr SHEventIdentifier SH_BUTTON_HOVER_EXIT_EVENT { 23 }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 92a754bf..3ddff353 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -146,6 +146,105 @@ namespace SHADE } } + bool SHUISystem::CheckButtonHoveredOrClicked(EntityID eid, SHVec2 topExtent, SHVec2 btmExtent, bool& isHovered, bool& isClicked) noexcept + { + + auto cameraSystem = SHSystemManager::GetSystem(); + SHVec2 mousePos; + SHVec2 windowSize; +#ifdef SHEDITOR + windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; + mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; + //mousePos.y = windowSize.y - mousePos.y; + //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) + mousePos /= windowSize; + //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) + + + +#else + + int x, y; + SHInputManager::GetMouseScreenPosition(&x, &y); + mousePos.x = x; + mousePos.y = y; + auto ws = SHSystemManager::GetSystem()->GetWindow()->GetWindowSize(); + windowSize = { static_cast(ws.first), static_cast(ws.second) }; + mousePos /= windowSize; +#endif + + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; + //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y) + + topExtent = CanvasToScreenPoint(topExtent, true); + btmExtent = CanvasToScreenPoint(btmExtent, true); + //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) + + + //comp.isClicked = false; + if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x + && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) + { + if (isHovered == false) + { + SHButtonClickEvent clickEvent; + clickEvent.EID = eid; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT); + } + isHovered = true; + + + +#ifdef SHEDITOR + //if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) + { + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) + { + isClicked = true; + SHButtonClickEvent clickEvent; + clickEvent.EID = eid; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } + } +#else + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + SHButtonClickEvent clickEvent; + clickEvent.EID = eid; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); + } +#endif + + //SHLOG_INFO("HOVERED") + } + else + { + if (isHovered == true) + { + SHButtonClickEvent clickEvent; + clickEvent.EID = eid; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_EXIT_EVENT); + } + + isHovered = false; + //SHLOG_INFO("NOT HOVERED") + } + if (isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + isClicked = false; + SHButtonClickEvent clickEvent; + clickEvent.EID = eid; + SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_RELEASE_EVENT); + + return true; + } + + + return false; + + } + void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept { @@ -164,72 +263,7 @@ namespace SHADE SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; - - SHVec2 mousePos; - SHVec2 windowSize; -#ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; - mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; - //mousePos.y = windowSize.y - mousePos.y; - //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) - mousePos /= windowSize; - //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) - - - -#else - - int x, y; - SHInputManager::GetMouseScreenPosition(&x, &y); - mousePos.x = x; - mousePos.y = y; - auto ws = SHSystemManager::GetSystem()->GetWindow()->GetWindowSize(); - windowSize = { static_cast(ws.first), static_cast(ws.second) }; - mousePos /= windowSize; -#endif - - SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0)}; - //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y) - - topExtent = CanvasToScreenPoint(topExtent,true); - btmExtent = CanvasToScreenPoint(btmExtent,true); - //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) - - - //comp.isClicked = false; - if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x - && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) - { - comp.isHovered = true; - #ifdef SHEDITOR - //if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) - { - if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = true; - } - } - #else - if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = true; - } - #endif - - //SHLOG_INFO("HOVERED") - } - else - { - comp.isHovered = false; - //SHLOG_INFO("NOT HOVERED") - } - if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = false; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); - } + CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked); if (SHComponentManager::HasComponent(comp.GetEID())) { @@ -295,73 +329,8 @@ namespace SHADE SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; - - SHVec2 mousePos; - SHVec2 windowSize; -#ifdef SHEDITOR - windowSize = SHEditorWindowManager::GetEditorWindow()->beginContentRegionAvailable; - mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; - //mousePos.y = windowSize.y - mousePos.y; - //SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y) - mousePos /= windowSize; - //SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y) - - - -#else - - int x, y; - SHInputManager::GetMouseScreenPosition(&x, &y); - mousePos.x = x; - mousePos.y = y; - auto ws = SHSystemManager::GetSystem()->GetWindow()->GetWindowSize(); - windowSize = { static_cast(ws.first), static_cast(ws.second) }; - mousePos /= windowSize; -#endif - - SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; - //SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y) - - topExtent = CanvasToScreenPoint(topExtent, true); - btmExtent = CanvasToScreenPoint(btmExtent, true); - //SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y) - - - //comp.isClicked = false; - if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x - && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) - { - comp.isHovered = true; -#ifdef SHEDITOR - //if (SHSystemManager::GetSystem()->editorState == SHEditor::State::PLAY) - { - if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = true; - } - } -#else - if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = true; - } -#endif - - //SHLOG_INFO("HOVERED") - } - else - { - comp.isHovered = false; - //SHLOG_INFO("NOT HOVERED") - } - if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) - { - comp.isClicked = false; + if (CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked)) comp.value = !comp.value; - SHButtonClickEvent clickEvent; - clickEvent.EID = comp.GetEID(); - SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); - } if (SHComponentManager::HasComponent(comp.GetEID())) { diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index ae1091ec..1eaf883e 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -72,6 +72,11 @@ namespace SHADE void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept; void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; + + //returns true on button release. + bool CheckButtonHoveredOrClicked(EntityID eid, SHVec2 topExtent, SHVec2 btmExtent, bool& isHovered, bool& isClicked) noexcept; + + SHVec2 CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept; From fe64844c4e429194f6bd9e9071e35e726d539b55 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 21 Feb 2023 09:55:14 +0800 Subject: [PATCH 06/18] Mouse Centering --- Assets/Scenes/MainGame.shade | 1 + SHADE_Engine/src/Input/SHInputManager.cpp | 20 ++++++++++++++++++++ SHADE_Managed/src/Input/Input.hxx | 22 +++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 87343839..3e52198d 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -9682,6 +9682,7 @@ aimingLength: 1 throwItem: false rayDistance: 0.75 + rayHeight: 0.100000001 - EID: 3 Name: HoldingPoint IsActive: true diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 2f0ab6d6..d3ce59d5 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -14,6 +14,9 @@ #include #include "SHInputManager.h" #include "../Tools/SHException.h" +#include +#include +#include namespace SHADE { @@ -801,6 +804,23 @@ namespace SHADE mouseVelocityX = static_cast(mouseScreenX - mouseScreenXLast) / dt; mouseVelocityY = static_cast(mouseScreenY - mouseScreenYLast) / dt; + + //Mouse Centering + if (GetKey(SH_KEYCODE::Q)) + { + uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); + uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); + SetMouseWindowPosition(width / 2, height / 2); + + //This four lines help a lot + POINT p; + GetCursorPos(&p); + + mouseVelocityX -= static_cast(p.x - mouseScreenX) / dt; + mouseVelocityY -= static_cast(p.y - mouseScreenY) / dt; + } + + //Mouse wheel vertical delta updating mouseWheelVerticalDelta = 0; mouseWheelVerticalDelta = mouseWheelVerticalDeltaPoll; diff --git a/SHADE_Managed/src/Input/Input.hxx b/SHADE_Managed/src/Input/Input.hxx index 875054cc..2a6689aa 100644 --- a/SHADE_Managed/src/Input/Input.hxx +++ b/SHADE_Managed/src/Input/Input.hxx @@ -181,7 +181,6 @@ namespace SHADE //Break //Menu //Mouse buttons use mouse codes, which are enums declared later - //TODO Controller input #if 0 Space = static_cast(SHInputManager::SH_KEYCODE::SPACE), //Apostrophe = static_cast(SHInputManager::SH_KEYCODE::APOSTROPHE), @@ -355,6 +354,27 @@ namespace SHADE Button3 = static_cast(SHInputManager::SH_KEYCODE::XMB1), Button4 = static_cast(SHInputManager::SH_KEYCODE::XMB2) }; + enum class ControllerCode : int + { + DpadUp = static_cast(SHInputManager::SH_CONTROLLERCODE::DPAD_UP), + DpadDown = static_cast(SHInputManager::SH_CONTROLLERCODE::DPAD_DOWN), + DpadLeft = static_cast(SHInputManager::SH_CONTROLLERCODE::DPAD_LEFT), + DpadRight = static_cast(SHInputManager::SH_CONTROLLERCODE::DPAD_RIGHT), + Start = static_cast(SHInputManager::SH_CONTROLLERCODE::START), + Back = static_cast(SHInputManager::SH_CONTROLLERCODE::BACK), + LeftThumbstickButton = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_THUMBSTICK), + RightThumbstickButton = static_cast(SHInputManager::SH_CONTROLLERCODE::RIGHT_THUMBSTICK), + LeftShoulder = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_SHOULDER), + RightShoulder = static_cast(SHInputManager::SH_CONTROLLERCODE::RIGHT_SHOULDER), + AButton = static_cast(SHInputManager::SH_CONTROLLERCODE::A), + BButton = static_cast(SHInputManager::SH_CONTROLLERCODE::B), + XButton = static_cast(SHInputManager::SH_CONTROLLERCODE::X), + YButton = static_cast(SHInputManager::SH_CONTROLLERCODE::Y), + LeftTrigger = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_TRIGGER), + RightTrigger = static_cast(SHInputManager::SH_CONTROLLERCODE::RIGHT_TRIGGER), + LeftThumbStickX = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_THUMBSTICK_X), + LeftThumbStickY = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_THUMBSTICK_Y) + }; /*-----------------------------------------------------------------------------*/ /* Properites */ From 51909071e69fa1677dba73f68a5cc4ba9d75aa83 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 21 Feb 2023 10:09:58 +0800 Subject: [PATCH 07/18] Change isHovered and isClicked to be stored in UIComponent instead and made a helper function to check for clicks and hovered --- SHADE_Engine/src/UI/SHButtonComponent.cpp | 6 ++- SHADE_Engine/src/UI/SHButtonComponent.h | 8 +-- .../src/UI/SHToggleButtonComponent.cpp | 3 +- SHADE_Engine/src/UI/SHToggleButtonComponent.h | 8 +-- SHADE_Engine/src/UI/SHUIComponent.cpp | 17 +++++++ SHADE_Engine/src/UI/SHUIComponent.h | 16 ++++++ SHADE_Engine/src/UI/SHUISystem.cpp | 51 +++++++++---------- SHADE_Engine/src/UI/SHUISystem.h | 2 +- 8 files changed, 64 insertions(+), 47 deletions(-) diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp index 35b6b3bc..cbc36ce3 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -6,8 +6,7 @@ namespace SHADE { SHButtonComponent::SHButtonComponent() - :size(1.0f), isHovered(false), isClicked(false), - defaultTexture(0), hoveredTexture(0), clickedTexture(0), currentTexture(0) + : defaultTexture(0), hoveredTexture(0), clickedTexture(0), currentTexture(0) { } @@ -41,6 +40,9 @@ namespace SHADE clickedTexture = texture; } + + + } diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h index bb66d224..a89a4b9e 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.h +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -17,8 +17,6 @@ namespace SHADE SHButtonComponent(); virtual ~SHButtonComponent() = default; - SHVec2 size; - AssetID GetClickedTexture() const noexcept; AssetID GetDefaultTexture() const noexcept; AssetID GetHoveredTexture() const noexcept; @@ -32,11 +30,7 @@ namespace SHADE friend class SHUISystem; private: - //Set to true when mouse is hovering over the button. - bool isHovered; - //This is set to true when the mouse clicks down, and set back to false when mouse releases. - //The event for the button click will be broadcasted when mouse release. - bool isClicked; + AssetID defaultTexture; AssetID hoveredTexture; AssetID clickedTexture; diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp index 47df669c..1ae0e9e0 100644 --- a/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp @@ -5,8 +5,7 @@ namespace SHADE { SHToggleButtonComponent::SHToggleButtonComponent() - :size(1.0f), isHovered(false), isClicked(false), value(false), - defaultTexture(0), toggledTexture(0), currentTexture(0) + :value(false), defaultTexture(0), toggledTexture(0), currentTexture(0) { } diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.h b/SHADE_Engine/src/UI/SHToggleButtonComponent.h index dc678fe9..1903df93 100644 --- a/SHADE_Engine/src/UI/SHToggleButtonComponent.h +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.h @@ -17,8 +17,6 @@ namespace SHADE SHToggleButtonComponent(); virtual ~SHToggleButtonComponent() = default; - SHVec2 size; - AssetID GetToggledTexture() const noexcept; AssetID GetDefaultTexture() const noexcept; bool GetValue() const noexcept; @@ -33,11 +31,7 @@ namespace SHADE friend class SHUISystem; private: - //Set to true when mouse is hovering over the button. - bool isHovered; - //This is set to true when the mouse clicks down, and set back to false when mouse releases. - //The event for the button click will be broadcasted when mouse release. - bool isClicked; + bool value; AssetID defaultTexture; AssetID toggledTexture; diff --git a/SHADE_Engine/src/UI/SHUIComponent.cpp b/SHADE_Engine/src/UI/SHUIComponent.cpp index 8131d081..95b93375 100644 --- a/SHADE_Engine/src/UI/SHUIComponent.cpp +++ b/SHADE_Engine/src/UI/SHUIComponent.cpp @@ -7,6 +7,7 @@ namespace SHADE { SHUIComponent::SHUIComponent() + :size(1.0f), isHovered(false), isClicked(false) { } @@ -27,6 +28,20 @@ namespace SHADE (void)id; } + bool SHUIComponent::GetIsHovered() const noexcept + { + return isHovered; + } + + bool SHUIComponent::GetIsClicked() const noexcept + { + return isClicked; + } + + void SHUIComponent::SetEmptyHoveredClick(bool value) noexcept + { + (void)value; + } } @@ -37,6 +52,8 @@ RTTR_REGISTRATION registration::class_("UI Component") .property("Canvas ID", &SHUIComponent::GetCanvasID, &SHUIComponent::SetCanvasID) + .property("Hovered", &SHUIComponent::GetIsHovered, &SHUIComponent::SetEmptyHoveredClick) + .property("Clicked", &SHUIComponent::GetIsClicked, &SHUIComponent::SetEmptyHoveredClick) ; diff --git a/SHADE_Engine/src/UI/SHUIComponent.h b/SHADE_Engine/src/UI/SHUIComponent.h index 5a9290cc..dd5bb664 100644 --- a/SHADE_Engine/src/UI/SHUIComponent.h +++ b/SHADE_Engine/src/UI/SHUIComponent.h @@ -5,6 +5,7 @@ #include "SH_API.h" #include "ECS_Base/Components/SHComponent.h" #include "Math/SHMatrix.h" +#include "Math/Vector/SHVec2.h" namespace SHADE @@ -17,14 +18,29 @@ namespace SHADE SHUIComponent(); ~SHUIComponent() = default; + + SHVec2 size; + + SHMatrix const& GetMatrix() const noexcept; EntityID GetCanvasID() const noexcept; void SetCanvasID(EntityID id) noexcept; + bool GetIsHovered() const noexcept; + bool GetIsClicked() const noexcept; + + void SetEmptyHoveredClick(bool value)noexcept; + + private: SHMatrix localToCanvasMatrix; EntityID canvasID; + //Set to true when mouse is hovering over the button. Only set if there is a Button/Slider/ToggleButton comp. + bool isHovered; + //This is set to true when the mouse clicks down, and set back to false when mouse releases. Only set if there is a Button/Slider/ToggleButton comp. + bool isClicked; + RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 3ddff353..69481b5e 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -146,9 +146,14 @@ namespace SHADE } } - bool SHUISystem::CheckButtonHoveredOrClicked(EntityID eid, SHVec2 topExtent, SHVec2 btmExtent, bool& isHovered, bool& isClicked) noexcept + bool SHUISystem::CheckButtonHoveredOrClicked(SHUIComponent& comp) noexcept { + SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * comp.GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * comp.GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + + SHVec2 topExtent{ topExtent4.x,topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; auto cameraSystem = SHSystemManager::GetSystem(); SHVec2 mousePos; SHVec2 windowSize; @@ -185,13 +190,13 @@ namespace SHADE if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) { - if (isHovered == false) + if (comp.isHovered == false) { SHButtonClickEvent clickEvent; - clickEvent.EID = eid; + clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT); } - isHovered = true; + comp.isHovered = true; @@ -200,9 +205,9 @@ namespace SHADE { if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) { - isClicked = true; + comp.isClicked = true; SHButtonClickEvent clickEvent; - clickEvent.EID = eid; + clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } } @@ -211,7 +216,7 @@ namespace SHADE { comp.isClicked = true; SHButtonClickEvent clickEvent; - clickEvent.EID = eid; + clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); } #endif @@ -220,21 +225,21 @@ namespace SHADE } else { - if (isHovered == true) + if (comp.isHovered == true) { SHButtonClickEvent clickEvent; - clickEvent.EID = eid; + clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_EXIT_EVENT); } - isHovered = false; + comp.isHovered = false; //SHLOG_INFO("NOT HOVERED") } - if (isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { - isClicked = false; + comp.isClicked = false; SHButtonClickEvent clickEvent; - clickEvent.EID = eid; + clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_RELEASE_EVENT); return true; @@ -256,14 +261,9 @@ namespace SHADE auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); //auto canvasComp = SHComponentManager::GetComponent_s(uiComp->canvasID); - SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); - SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f,0.0f, 0.0f,1.0f); - - SHVec2 topExtent{ topExtent4.x,topExtent4.y }; - SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; - CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked); + CheckButtonHoveredOrClicked(*uiComp); if (SHComponentManager::HasComponent(comp.GetEID())) { @@ -272,7 +272,7 @@ namespace SHADE AssetID textureID = 0; - if (!comp.isHovered && !comp.isClicked) + if (!uiComp->isHovered && !uiComp->isClicked) { if (comp.GetDefaultTexture() != 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE) { @@ -281,7 +281,7 @@ namespace SHADE //SHLOG_INFO("SETTING DEFAULT TEXTURE") } } - else if (comp.isClicked) + else if (uiComp->isClicked) { if (comp.GetClickedTexture() != 0 && SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE) { @@ -322,14 +322,9 @@ namespace SHADE auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); //auto canvasComp = SHComponentManager::GetComponent_s(uiComp->canvasID); - SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); - SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); + - - SHVec2 topExtent{ topExtent4.x,topExtent4.y }; - SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; - - if (CheckButtonHoveredOrClicked(comp.GetEID(), topExtent, btmExtent, comp.isHovered, comp.isClicked)) + if (CheckButtonHoveredOrClicked(*uiComp)) comp.value = !comp.value; if (SHComponentManager::HasComponent(comp.GetEID())) diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 1eaf883e..3b2bb2cf 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -74,7 +74,7 @@ namespace SHADE void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; //returns true on button release. - bool CheckButtonHoveredOrClicked(EntityID eid, SHVec2 topExtent, SHVec2 btmExtent, bool& isHovered, bool& isClicked) noexcept; + bool CheckButtonHoveredOrClicked(SHUIComponent& comp) noexcept; From a3112f9c60d1cb8232bf9ec4ef437c219ac7a8b5 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 21 Feb 2023 10:48:07 +0800 Subject: [PATCH 08/18] Fixed Canvas Scaler to keep AR of the UI Elements --- Assets/Scenes/MainMenu.shade | 12 ++++++++++-- SHADE_Engine/src/UI/SHCanvasComponent.cpp | 7 ++++++- SHADE_Engine/src/UI/SHCanvasComponent.h | 5 ++++- SHADE_Engine/src/UI/SHUISystem.cpp | 13 +++++++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Assets/Scenes/MainMenu.shade b/Assets/Scenes/MainMenu.shade index 54208e8b..30ef368a 100644 --- a/Assets/Scenes/MainMenu.shade +++ b/Assets/Scenes/MainMenu.shade @@ -6,6 +6,7 @@ Canvas Component: Canvas Width: 1920 Canvas Height: 1080 + Scale by canvas width: false IsActive: true Scripts: ~ - EID: 1 @@ -24,6 +25,8 @@ IsActive: true UI Component: Canvas ID: 0 + Hovered: false + Clicked: false IsActive: true Scripts: ~ - EID: 5 @@ -47,6 +50,8 @@ IsActive: true UI Component: Canvas ID: 0 + Hovered: false + Clicked: false IsActive: true Scripts: - Type: ChangeSceneButton @@ -73,6 +78,8 @@ IsActive: true UI Component: Canvas ID: 0 + Hovered: false + Clicked: false IsActive: true Scripts: - Type: QuitButton @@ -106,11 +113,12 @@ Pitch: 0 Yaw: 0 Roll: 0 - Width: 1920 - Height: 1080 + Width: 1319 + Height: 622 Near: 0.00999999978 Far: 10000 Perspective: true + FOV: 90 IsActive: true Scripts: ~ - EID: 4 diff --git a/SHADE_Engine/src/UI/SHCanvasComponent.cpp b/SHADE_Engine/src/UI/SHCanvasComponent.cpp index 1ffc7a19..5ee93bc1 100644 --- a/SHADE_Engine/src/UI/SHCanvasComponent.cpp +++ b/SHADE_Engine/src/UI/SHCanvasComponent.cpp @@ -6,7 +6,7 @@ namespace SHADE { SHCanvasComponent::SHCanvasComponent() - :width(1),height(1), dirtyMatrix(false), canvasMatrix() + :width(1), height(1), dirtyMatrix(false), canvasMatrix(), scaleByCanvasWidth(false) { } @@ -27,6 +27,8 @@ namespace SHADE height = val; } + + SHCanvasComponent::CanvasSizeType SHCanvasComponent::GetCanvasWidth() const noexcept { @@ -43,6 +45,8 @@ namespace SHADE return canvasMatrix; } + + } @@ -54,6 +58,7 @@ RTTR_REGISTRATION registration::class_("Canvas Component") .property("Canvas Width", &SHCanvasComponent::GetCanvasWidth, &SHCanvasComponent::SetCanvasWidth) .property("Canvas Height", &SHCanvasComponent::GetCanvasHeight, &SHCanvasComponent::SetCanvasHeight) + .property("Scale by canvas width", &SHCanvasComponent::scaleByCanvasWidth) ; diff --git a/SHADE_Engine/src/UI/SHCanvasComponent.h b/SHADE_Engine/src/UI/SHCanvasComponent.h index 145b3cb3..5b6c1781 100644 --- a/SHADE_Engine/src/UI/SHCanvasComponent.h +++ b/SHADE_Engine/src/UI/SHCanvasComponent.h @@ -21,21 +21,24 @@ namespace SHADE SHCanvasComponent(); ~SHCanvasComponent() = default; + bool scaleByCanvasWidth; void SetCanvasSize(CanvasSizeType width, CanvasSizeType height) noexcept; void SetCanvasWidth(CanvasSizeType width) noexcept; void SetCanvasHeight(CanvasSizeType height) noexcept; + CanvasSizeType GetCanvasWidth() const noexcept; CanvasSizeType GetCanvasHeight() const noexcept; SHMatrix const& GetMatrix() const noexcept; + private: CanvasSizeType width; CanvasSizeType height; bool dirtyMatrix; SHMatrix canvasMatrix; - + RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 69481b5e..3552e47b 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -131,8 +131,17 @@ namespace SHADE auto cameraSystem = SHSystemManager::GetSystem(); SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0); comp.canvasMatrix = SHMatrix::Identity; - comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f); - comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f); + float scale = camSize.y / comp.GetCanvasHeight(); + if (comp.scaleByCanvasWidth) + { + scale = camSize.x / comp.GetCanvasWidth(); + } + + comp.canvasMatrix(0, 0) = scale; + comp.canvasMatrix(1, 1) = scale; + + //comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f); + //comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f); } void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept From 9a7c0d0bf6513dc42e0bc6b08df89f81e7e1154c Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 21 Feb 2023 17:30:43 +0800 Subject: [PATCH 09/18] Added SharedMaterial for Renderable --- SHADE_Managed/src/Components/Renderable.cxx | 7 ++++++- SHADE_Managed/src/Components/Renderable.hxx | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx index 1aa83637..929b0006 100644 --- a/SHADE_Managed/src/Components/Renderable.cxx +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -47,11 +47,16 @@ namespace SHADE } } SHADE::Material Renderable::Material::get() + { + auto mat = GetNativeComponent()->GetModifiableMaterial(); + return mat ? SHADE::Material(mat) : SHADE::Material(); + } + SHADE::Material Renderable::SharedMaterial::get() { auto mat = GetNativeComponent()->GetMaterial(); return mat ? SHADE::Material(mat) : SHADE::Material(); } - void Renderable::Material::set(SHADE::Material value) + void Renderable::SharedMaterial::set(SHADE::Material value) { if (value) { diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx index b0786035..a4417166 100644 --- a/SHADE_Managed/src/Components/Renderable.hxx +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -55,9 +55,19 @@ namespace SHADE void set(MeshAsset value); } /// - /// Material used to render this Renderable. + /// Special instance of the shared Material for this Renderable. When accessing + /// this property, a new instance of the shared Material is created and assigned + /// to this Renderable. Hence, changes will only affect this Renderable. /// property SHADE::Material Material + { + SHADE::Material get(); + } + /// + /// The shared Material used to render this Renderable and other Renderables + /// using the same base Material. + /// + property SHADE::Material SharedMaterial { SHADE::Material get(); void set(SHADE::Material value); From 06ad2a4c0c6b416941eb3c3728bc18835e5498d2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 21 Feb 2023 21:20:31 +0800 Subject: [PATCH 10/18] moved the UI routines --- SHADE_Application/src/Application/SBApplication.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index a89fb050..3ebcc904 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -132,16 +132,19 @@ namespace Sandbox SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); - SHSystemManager::RegisterRoutine(); - SHSystemManager::RegisterRoutine(); - SHSystemManager::RegisterRoutine(); - SHSystemManager::RegisterRoutine(); //SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + + SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); + + SHSystemManager::RegisterRoutine(); #ifdef SHEDITOR From 0e572d7f8957aa25ed1597244df8de22def6b825 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 22 Feb 2023 15:15:38 +0800 Subject: [PATCH 11/18] progress --- SHADE_Engine/src/Input/SHInputManager.cpp | 6 +++--- SHADE_Engine/src/Input/SHInputManager.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index d3ce59d5..c28636d3 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -24,6 +24,7 @@ namespace SHADE /* Static defines */ /*------------------------------------------------------------------------*/ + bool SHInputManager::mouseCentering = false; bool SHInputManager::controllerInUse = false; std::map SHInputManager::bindings; @@ -806,16 +807,15 @@ namespace SHADE //Mouse Centering - if (GetKey(SH_KEYCODE::Q)) + if (mouseCentering) { uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); SetMouseWindowPosition(width / 2, height / 2); - //This four lines help a lot + //These four lines help a lot POINT p; GetCursorPos(&p); - mouseVelocityX -= static_cast(p.x - mouseScreenX) / dt; mouseVelocityY -= static_cast(p.y - mouseScreenY) / dt; } diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 1bcafa7d..dcfcdf57 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -1074,6 +1074,18 @@ namespace SHADE SetCursorPos(p.x, p.y); } + //Call to set the flag to start mouse centering every frame + static inline void SetMouseCentering(bool state) noexcept + { + mouseCentering = state; + } + + //Get the flag whether mouse centering is on or not + static inline bool GetMouseCentering() noexcept + { + return mouseCentering; + } + private: /*------------------------------------------------------------------------*/ /* Constants */ @@ -1097,6 +1109,9 @@ namespace SHADE /* Data Members */ /*------------------------------------------------------------------------*/ + //Whether mouse centering will be called every frame or not + static bool mouseCentering; + //If the last input is from controller(s) or KB/M //True if from controller(s), False if from KB/M //Useful for switching control hints between controllers and KB/M From bea179fb0faa2d57c89316b4387d67f450d37ae2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 22 Feb 2023 21:49:10 +0800 Subject: [PATCH 12/18] Added script mappings for new button events --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 54 +++++++++++ SHADE_Engine/src/Scripting/SHScriptEngine.h | 6 ++ SHADE_Managed/src/Components/UIElement.cxx | 93 +++++++++++++++++++ SHADE_Managed/src/Components/UIElement.hxx | 42 +++++++++ 4 files changed, 195 insertions(+) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 22c7c12e..36d34b6c 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -369,6 +369,27 @@ namespace SHADE return eventData->handle; } + SHEventHandle SHScriptEngine::onUIElementReleased(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csUIElementOnClicked(eventData->data->EID); + return eventData->handle; + } + + SHEventHandle SHScriptEngine::onUIElementOnHoverEntered(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csUIElementOnClicked(eventData->data->EID); + return eventData->handle; + } + + SHEventHandle SHScriptEngine::onUIElementOnHoverExited(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csUIElementOnClicked(eventData->data->EID); + return eventData->handle; + } + SHEventHandle SHScriptEngine::onSceneNodeChildrenAdded(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); @@ -539,6 +560,24 @@ namespace SHADE DEFAULT_CSHARP_NAMESPACE + ".UIElement", "OnClicked" ); + csUIElementOnReleased = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".UIElement", + "OnReleased" + ); + csUIElementOnHoverEntered = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".UIElement", + "OnHoverEntered" + ); + csUIElementOnHoverExited = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".UIElement", + "OnHoverExited" + ); csEditorRenderScripts = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, @@ -608,6 +647,21 @@ namespace SHADE std::make_shared>(this, &SHScriptEngine::onUIElementClicked) }; SHEventManager::SubscribeTo(SH_BUTTON_CLICK_EVENT, std::dynamic_pointer_cast(clickedUIElementEventReceiver)); + std::shared_ptr> releasedUIElementEventReceiver + { + std::make_shared>(this, &SHScriptEngine::onUIElementReleased) + }; + SHEventManager::SubscribeTo(SH_BUTTON_RELEASE_EVENT, std::dynamic_pointer_cast(releasedUIElementEventReceiver)); + std::shared_ptr> hoverEnterUIElementEventReceiver + { + std::make_shared>(this, &SHScriptEngine::onUIElementOnHoverEntered) + }; + SHEventManager::SubscribeTo(SH_BUTTON_HOVER_ENTER_EVENT, std::dynamic_pointer_cast(hoverEnterUIElementEventReceiver)); + std::shared_ptr> hoverExitedUIElementEventReceiver + { + std::make_shared>(this, &SHScriptEngine::onUIElementOnHoverExited) + }; + SHEventManager::SubscribeTo(SH_BUTTON_HOVER_EXIT_EVENT, std::dynamic_pointer_cast(hoverExitedUIElementEventReceiver)); /* SceneGraph */ // Register for SceneNode child added event diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 9b234d04..b207ae64 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -292,6 +292,9 @@ namespace SHADE CsEventRelayFuncPtr csSceneNodeChildrenChanged = nullptr; CsEventRelayFuncPtr csUIElementOnRemoved = nullptr; CsEventRelayFuncPtr csUIElementOnClicked = nullptr; + CsEventRelayFuncPtr csUIElementOnReleased = nullptr; + CsEventRelayFuncPtr csUIElementOnHoverEntered = nullptr; + CsEventRelayFuncPtr csUIElementOnHoverExited = nullptr; // - Editor CsScriptEditorFuncPtr csEditorRenderScripts = nullptr; CsFuncPtr csEditorUndo = nullptr; @@ -306,6 +309,9 @@ namespace SHADE SHEventHandle onColliderComponentRemoved(SHEventPtr eventPtr); SHEventHandle onUIElementRemoved(SHEventPtr eventPtr); SHEventHandle onUIElementClicked(SHEventPtr eventPtr); + SHEventHandle onUIElementReleased(SHEventPtr eventPtr); + SHEventHandle onUIElementOnHoverEntered(SHEventPtr eventPtr); + SHEventHandle onUIElementOnHoverExited(SHEventPtr eventPtr); SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr); SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr); SHEventHandle onSceneDestroyed(SHEventPtr eventPtr); diff --git a/SHADE_Managed/src/Components/UIElement.cxx b/SHADE_Managed/src/Components/UIElement.cxx index d76d6d42..42b8caef 100644 --- a/SHADE_Managed/src/Components/UIElement.cxx +++ b/SHADE_Managed/src/Components/UIElement.cxx @@ -48,6 +48,57 @@ namespace SHADE // Return the event return onClickEventMap[owner.EntityId]; } + CallbackEvent^ UIElement::OnRelease::get() + { + // Create map if it wasn't before + if (onReleasedEventMap == nullptr) + { + onReleasedEventMap = gcnew System::Collections::Generic::Dictionary(); + } + + // Create event if it wasn't before + if (!onReleasedEventMap->ContainsKey(owner.EntityId)) + { + onReleasedEventMap->Add(owner.EntityId, gcnew CallbackEvent()); + } + + // Return the event + return onClickEventMap[owner.EntityId]; + } + CallbackEvent^ UIElement::OnHoverEnter::get() + { + // Create map if it wasn't before + if (onHoverEnterEventMap == nullptr) + { + onHoverEnterEventMap = gcnew System::Collections::Generic::Dictionary(); + } + + // Create event if it wasn't before + if (!onHoverEnterEventMap->ContainsKey(owner.EntityId)) + { + onHoverEnterEventMap->Add(owner.EntityId, gcnew CallbackEvent()); + } + + // Return the event + return onHoverEnterEventMap[owner.EntityId]; + } + CallbackEvent^ UIElement::OnHoverExit::get() + { + // Create map if it wasn't before + if (onHoverExitEventMap == nullptr) + { + onHoverExitEventMap = gcnew System::Collections::Generic::Dictionary(); + } + + // Create event if it wasn't before + if (!onHoverExitEventMap->ContainsKey(owner.EntityId)) + { + onHoverExitEventMap->Add(owner.EntityId, gcnew CallbackEvent()); + } + + // Return the event + return onHoverExitEventMap[owner.EntityId]; + } /*---------------------------------------------------------------------------------*/ /* Event Handling Functions */ @@ -60,6 +111,18 @@ namespace SHADE { onClickEventMap->Remove(entity); } + if (onReleasedEventMap != nullptr && onReleasedEventMap->ContainsKey(entity)) + { + onReleasedEventMap->Remove(entity); + } + if (onHoverEnterEventMap != nullptr && onHoverEnterEventMap->ContainsKey(entity)) + { + onHoverEnterEventMap->Remove(entity); + } + if (onHoverExitEventMap != nullptr && onHoverExitEventMap->ContainsKey(entity)) + { + onHoverExitEventMap->Remove(entity); + } SAFE_NATIVE_CALL_END("UIElement.OnComponentRemoved") } void UIElement::OnClicked(EntityID entity) @@ -72,4 +135,34 @@ namespace SHADE } SAFE_NATIVE_CALL_END("UIElement.OnClicked") } + void UIElement::OnReleased(EntityID entity) + { + SAFE_NATIVE_CALL_BEGIN + // Remove the event if it contained an event + if (onReleasedEventMap != nullptr && onReleasedEventMap->ContainsKey(entity)) + { + onReleasedEventMap[entity]->Invoke(); + } + SAFE_NATIVE_CALL_END("UIElement.OnClicked") + } + void UIElement::OnHoverEntered(EntityID entity) + { + SAFE_NATIVE_CALL_BEGIN + // Remove the event if it contained an event + if (onHoverEnterEventMap != nullptr && onHoverEnterEventMap->ContainsKey(entity)) + { + onHoverEnterEventMap[entity]->Invoke(); + } + SAFE_NATIVE_CALL_END("UIElement.OnClicked") + } + void UIElement::OnHoverExited(EntityID entity) + { + SAFE_NATIVE_CALL_BEGIN + // Remove the event if it contained an event + if (onHoverExitEventMap != nullptr && onHoverExitEventMap->ContainsKey(entity)) + { + onHoverExitEventMap[entity]->Invoke(); + } + SAFE_NATIVE_CALL_END("UIElement.OnClicked") + } } diff --git a/SHADE_Managed/src/Components/UIElement.hxx b/SHADE_Managed/src/Components/UIElement.hxx index a969e4b5..7b762ce3 100644 --- a/SHADE_Managed/src/Components/UIElement.hxx +++ b/SHADE_Managed/src/Components/UIElement.hxx @@ -50,6 +50,28 @@ namespace SHADE { CallbackEvent^ get(); } + /// + /// Event that is raised when this UIElement is released. + /// + property CallbackEvent^ OnRelease + { + CallbackEvent^ get(); + } + /// + /// Event that is raised on the first frame when this UIElement is hovered over. + /// + property CallbackEvent^ OnHoverEnter + { + CallbackEvent^ get(); + } + /// + /// Event that is raised on the first frame when this UIElement is no longer + /// hovered over. + /// + property CallbackEvent^ OnHoverExit + { + CallbackEvent^ get(); + } private: /*-----------------------------------------------------------------------------*/ @@ -65,11 +87,31 @@ namespace SHADE /// /// The entity which was clicked. static void OnClicked(EntityID entity); + /// + /// To be called from native code when this component is released from clicking. + /// + /// The entity which was clicked. + static void OnReleased(EntityID entity); + /// + /// To be called from native code on the first frame that this component is + /// hovered on. + /// + /// The entity which was clicked. + static void OnHoverEntered(EntityID entity); + /// + /// To be called from native code on the first frame that this component is + /// no longer hovered on. + /// + /// The entity which was clicked. + static void OnHoverExited(EntityID entity); /*-----------------------------------------------------------------------------*/ /* Static Data Members */ /*-----------------------------------------------------------------------------*/ static System::Collections::Generic::Dictionary^ onClickEventMap; + static System::Collections::Generic::Dictionary^ onReleasedEventMap; + static System::Collections::Generic::Dictionary^ onHoverEnterEventMap; + static System::Collections::Generic::Dictionary^ onHoverExitEventMap; }; } From dbe9b4d13363c4f5a6cccc22e4d2e01748c4ee9a Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 22 Feb 2023 23:50:39 +0800 Subject: [PATCH 13/18] Controller, Bindings and Mouse Centre via C# --- .../InputBindings/SHInputBindingsPanel.cpp | 4 + SHADE_Engine/src/Input/SHInputManager.cpp | 4 + SHADE_Managed/src/Input/Input.cxx | 297 ++++++++++++++++++ SHADE_Managed/src/Input/Input.hxx | 103 ++++++ 4 files changed, 408 insertions(+) diff --git a/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp index d3fa33fa..9aa5e579 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp @@ -47,6 +47,8 @@ namespace SHADE if (SHEditorWindow::Begin()) { //ImGui::ShowDemoWindow(); + if (bindingRenames.size() != SHInputManager::CountBindings()) + resizeVectors(SHInputManager::CountBindings()); //Binding count ImGui::Text("Binding Count: %d", SHInputManager::CountBindings()); @@ -127,6 +129,8 @@ namespace SHADE { SHInputManager::RenameBinding(binding.first, bindingRenames[entryNumber]); bindingRenames[entryNumber].clear(); + ImGui::End(); + return; } if (ImGui::Button(labelConcat("Delete Binding##", entryNumber).c_str())) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index c28636d3..dd3cfe80 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -755,6 +755,7 @@ namespace SHADE { ++keyCount; keys[i] = true; + controllerInUse = false; } else keys[i] = false; @@ -819,6 +820,9 @@ namespace SHADE mouseVelocityX -= static_cast(p.x - mouseScreenX) / dt; mouseVelocityY -= static_cast(p.y - mouseScreenY) / dt; } + + if (mouseVelocityX != 0.0 || mouseVelocityY != 0.0) + controllerInUse = false; //Mouse wheel vertical delta updating diff --git a/SHADE_Managed/src/Input/Input.cxx b/SHADE_Managed/src/Input/Input.cxx index f0ea0edc..ee628523 100644 --- a/SHADE_Managed/src/Input/Input.cxx +++ b/SHADE_Managed/src/Input/Input.cxx @@ -30,10 +30,29 @@ namespace SHADE { return SHInputManager::GetMouseWheelVerticalDelta(); } + bool Input::ControllerInUse::get() + { + return SHInputManager::GetControllerInUse(); + } /*---------------------------------------------------------------------------------*/ /* Usage Functions */ /*---------------------------------------------------------------------------------*/ + bool Input::AnyKey() + { + return SHInputManager::AnyKey(); + } + + bool Input::AnyKeyDown() + { + return SHInputManager::AnyKeyDown(); + } + + bool Input::AnyKeyUp() + { + return SHInputManager::AnyKeyUp(); + } + bool Input::GetKey(KeyCode key) { return SHInputManager::GetKey(static_cast(key)); @@ -64,6 +83,50 @@ namespace SHADE return SHInputManager::GetKeyUp(static_cast(mouseButton)); } + bool Input::AnyControllerInput() + { + return SHInputManager::AnyControllerInput(); + } + bool Input::AnyControllerInputDown() + { + return SHInputManager::AnyControllerInputDown(); + } + bool Input::AnyControllerInputUp() + { + return SHInputManager::AnyControllerInputUp(); + } + bool Input::AnyControllerButton() + { + return SHInputManager::AnyControllerButton(); + } + bool Input::AnyControllerButtonDown() + { + return SHInputManager::AnyControllerButtonDown(); + } + bool Input::AnyControllerButtonUp() + { + return SHInputManager::AnyControllerButtonUp(); + } + + bool Input::GetControllerInput(Input::ControllerCode code) + { + return SHInputManager::GetControllerInput(static_cast(code)); + } + double Input::GetControllerInputNormalisedValue(Input::ControllerCode code) + { + double toReturn = 0.0; + SHInputManager::GetControllerInput(static_cast(code), &toReturn); + return toReturn; + } + bool Input::GetControllerInputDown(Input::ControllerCode code) + { + return SHInputManager::GetControllerInputDown(static_cast(code)); + } + bool Input::GetControllerInputUp(Input::ControllerCode code) + { + return SHInputManager::GetControllerInputUp(static_cast(code)); + } + /*---------------------------------------------------------------------------------*/ /* Cursor Functions */ /*---------------------------------------------------------------------------------*/ @@ -76,6 +139,24 @@ namespace SHADE ); } + Vector2 Input::GetMousePosition() + { + int x = 0; + int y = 0; + SHInputManager::GetMouseWindowPosition(&x, &y); + return Convert::ToCLI(SHVec2{ (float)x,(float)y }); + } + + void Input::SetMouseCentering(bool state) + { + SHInputManager::SetMouseCentering(state); + } + + bool Input::GetMouseCentering() + { + return SHInputManager::GetMouseCentering(); + } + /*---------------------------------------------------------------------------------*/ /* Time Functions */ /*---------------------------------------------------------------------------------*/ @@ -106,4 +187,220 @@ namespace SHADE return Convert::ToCLI(SHVec2{ (float)velX,(float)velY }); } + + double Input::GetControllerInputHeldTime(Input::ControllerCode code) + { + return SHInputManager::GetControllerInputHeldTime(static_cast(code)); + } + double Input::GetControllerInputReleasedTime(Input::ControllerCode code) + { + return SHInputManager::GetControllerInputReleasedTime(static_cast(code)); + } + + /*-----------------------------------------------------------------------------*/ + /* Binding Functions */ + /*-----------------------------------------------------------------------------*/ + void Input::SaveBindings() + { + SHInputManager::SaveBindings(); + } + + void Input::SaveBindings(System::String^ targetFile) + { + SHInputManager::SaveBindings(Convert::ToNative(targetFile)); + } + + void Input::LoadBindings() + { + SHInputManager::LoadBindings(); + } + + void Input::LoadBindings(System::String^ sourceFile) + { + SHInputManager::LoadBindings(Convert::ToNative(sourceFile)); + } + + bool Input::GetBindingInverted(System::String^ bindingName) + { + return SHInputManager::GetBindingInverted(Convert::ToNative(bindingName)); + } + void Input::SetBindingInverted(System::String^ bindingName, bool newValue) + { + SHInputManager::SetBindingInverted(Convert::ToNative(bindingName), newValue); + } + double Input::GetBindingGravity(System::String^ bindingName) + { + return SHInputManager::GetBindingGravity(Convert::ToNative(bindingName)); + } + void Input::SetBindingGravity(System::String^ bindingName, double newValue) + { + SHInputManager::SetBindingGravity(Convert::ToNative(bindingName), newValue); + } + double Input::GetBindingDead(System::String^ bindingName) + { + return SHInputManager::GetBindingDead(Convert::ToNative(bindingName)); + } + void Input::SetBindingDead(System::String^ bindingName, double newValue) + { + SHInputManager::SetBindingDead(Convert::ToNative(bindingName), newValue); + } + double Input::GetBindingSensitivity(System::String^ bindingName) + { + return SHInputManager::GetBindingSensitivity(Convert::ToNative(bindingName)); + } + void Input::SetBindingSensitivity(System::String^ bindingName, double newValue) + { + SHInputManager::SetBindingSensitivity(Convert::ToNative(bindingName), newValue); + } + bool Input::GetBindingSnap(System::String^ bindingName) + { + return SHInputManager::GetBindingSnap(Convert::ToNative(bindingName)); + } + void Input::SetBindingSnap(System::String^ bindingName, bool newValue) + { + SHInputManager::SetBindingSnap(Convert::ToNative(bindingName), newValue); + } + + + System::Collections::Generic::HashSet^ Input::GetBindingPositiveKeyCodes(System::String^ bindingName) + { + System::Collections::Generic::HashSet^ toReturn = gcnew System::Collections::Generic::HashSet(); + std::set list = SHInputManager::GetBindingPositiveKeyCodes(Convert::ToNative(bindingName)); + for (auto kc : list) + { + toReturn->Add(static_cast(kc)); + } + return toReturn; + } + void Input::AddBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toAdd) + { + SHInputManager::AddBindingPositiveKeyCode(Convert::ToNative(bindingName), static_cast(toAdd)); + } + void Input::RemoveBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toRemove) + { + SHInputManager::RemoveBindingPositiveKeyCode(Convert::ToNative(bindingName), static_cast(toRemove)); + } + void Input::ClearBindingPositiveKeyCodes(System::String^ bindingName) + { + SHInputManager::ClearBindingPositiveKeyCodes(Convert::ToNative(bindingName)); + } + + System::Collections::Generic::HashSet^ Input::GetBindingNegativeKeyCodes(System::String^ bindingName) + { + System::Collections::Generic::HashSet^ toReturn = gcnew System::Collections::Generic::HashSet(); + std::set list = SHInputManager::GetBindingNegativeKeyCodes(Convert::ToNative(bindingName)); + for (auto kc : list) + { + toReturn->Add(static_cast(kc)); + } + return toReturn; + } + void Input::AddBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toAdd) + { + SHInputManager::AddBindingNegativeKeyCode(Convert::ToNative(bindingName), static_cast(toAdd)); + } + void Input::RemoveBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toRemove) + { + SHInputManager::RemoveBindingNegativeKeyCode(Convert::ToNative(bindingName), static_cast(toRemove)); + } + void Input::ClearBindingNegativeKeyCodes(System::String^ bindingName) + { + SHInputManager::ClearBindingNegativeKeyCodes(Convert::ToNative(bindingName)); + } + + System::Collections::Generic::HashSet^ Input::GetBindingPositiveControllerCodes(System::String^ bindingName) + { + System::Collections::Generic::HashSet^ toReturn = gcnew System::Collections::Generic::HashSet(); + std::set list = SHInputManager::GetBindingPositiveControllerCodes(Convert::ToNative(bindingName)); + for (auto kc : list) + { + toReturn->Add(static_cast(kc)); + } + return toReturn; + } + void Input::AddBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toAdd) + { + SHInputManager::AddBindingPositiveControllerCode(Convert::ToNative(bindingName), static_cast(toAdd)); + } + void Input::RemoveBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toRemove) + { + SHInputManager::RemoveBindingPositiveControllerCode(Convert::ToNative(bindingName), static_cast(toRemove)); + } + void Input::ClearBindingPositiveControllerCodes(System::String^ bindingName) + { + SHInputManager::ClearBindingPositiveControllerCodes(Convert::ToNative(bindingName)); + } + + System::Collections::Generic::HashSet^ Input::GetBindingNegativeControllerCodes(System::String^ bindingName) + { + System::Collections::Generic::HashSet^ toReturn = gcnew System::Collections::Generic::HashSet(); + std::set list = SHInputManager::GetBindingNegativeControllerCodes(Convert::ToNative(bindingName)); + for (auto kc : list) + { + toReturn->Add(static_cast(kc)); + } + return toReturn; + } + void Input::AddBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toAdd) + { + SHInputManager::AddBindingNegativeControllerCode(Convert::ToNative(bindingName), static_cast(toAdd)); + } + void Input::RemoveBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toRemove) + { + SHInputManager::RemoveBindingNegativeControllerCode(Convert::ToNative(bindingName), static_cast(toRemove)); + } + void Input::ClearBindingNegativeControllerCodes(System::String^ bindingName) + { + SHInputManager::ClearBindingNegativeControllerCodes(Convert::ToNative(bindingName)); + } + + double Input::GetBindingAxis(System::String^ bindingName) + { + return SHInputManager::GetBindingAxis(Convert::ToNative(bindingName)); + } + double Input::GetBindingAxisRaw(System::String^ bindingName) + { + return SHInputManager::GetBindingAxisRaw(Convert::ToNative(bindingName)); + } + bool Input::GetBindingPositiveButton(System::String^ bindingName) + { + return SHInputManager::GetBindingPositiveButton(Convert::ToNative(bindingName)); + } + bool Input::GetBindingNegativeButton(System::String^ bindingName) + { + return SHInputManager::GetBindingNegativeButton(Convert::ToNative(bindingName)); + } + bool Input::GetBindingPositiveButtonDown(System::String^ bindingName) + { + return SHInputManager::GetBindingPositiveButtonDown(Convert::ToNative(bindingName)); + } + bool Input::GetBindingNegativeButtonDown(System::String^ bindingName) + { + return SHInputManager::GetBindingNegativeButtonDown(Convert::ToNative(bindingName)); + } + bool Input::GetBindingPositiveButtonUp(System::String^ bindingName) + { + return SHInputManager::GetBindingPositiveButtonUp(Convert::ToNative(bindingName)); + } + bool Input::GetBindingNegativeButtonUp(System::String^ bindingName) + { + return SHInputManager::GetBindingNegativeButtonUp(Convert::ToNative(bindingName)); + } + + double Input::GetBindingPositiveHeldTime(System::String^ bindingName) + { + return SHInputManager::GetBindingPositiveHeldTime(Convert::ToNative(bindingName)); + } + double Input::GetBindingNegativeHeldTime(System::String^ bindingName) + { + return SHInputManager::GetBindingNegativeHeldTime(Convert::ToNative(bindingName)); + } + double Input::GetBindingPositiveReleasedTime(System::String^ bindingName) + { + return SHInputManager::GetBindingPositiveReleasedTime(Convert::ToNative(bindingName)); + } + double Input::GetBindingNegativeReleasedTime(System::String^ bindingName) + { + return SHInputManager::GetBindingNegativeReleasedTime(Convert::ToNative(bindingName)); + } } \ No newline at end of file diff --git a/SHADE_Managed/src/Input/Input.hxx b/SHADE_Managed/src/Input/Input.hxx index 2a6689aa..f62e0cab 100644 --- a/SHADE_Managed/src/Input/Input.hxx +++ b/SHADE_Managed/src/Input/Input.hxx @@ -376,6 +376,14 @@ namespace SHADE LeftThumbStickY = static_cast(SHInputManager::SH_CONTROLLERCODE::LEFT_THUMBSTICK_Y) }; + enum class BindingType : int + { + KbMbController = static_cast(SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER), + mouseX = static_cast(SHInputManager::SH_BINDINGTYPE::MOUSE_X), + mouseY = static_cast(SHInputManager::SH_BINDINGTYPE::MOUSE_Y), + mouseScroll = static_cast(SHInputManager::SH_BINDINGTYPE::MOUSE_SCROLL) + }; + /*-----------------------------------------------------------------------------*/ /* Properites */ /*-----------------------------------------------------------------------------*/ @@ -396,9 +404,25 @@ namespace SHADE int get(); } + static property bool ControllerInUse + { + bool get(); + } + /*-----------------------------------------------------------------------------*/ /* Usage Functions */ /*-----------------------------------------------------------------------------*/ + + /// + /// Checks if any key is being held down. + /// This will also be true if GetKeyDown() is true. + /// + /// KeyCode of the first key that was detected to be pressed. + /// True while the user holds down the key specified. + static bool AnyKey(); + static bool AnyKeyDown(); + static bool AnyKeyUp(); + /// /// Checks if a specified key is being held down. /// This will also be true if GetKeyDown() is true. @@ -447,6 +471,20 @@ namespace SHADE /// True during the frame the user releases the given mouse button. /// static bool GetMouseButtonUp(MouseCode mouseButton); + + //For controller + + static bool AnyControllerInput(); + static bool AnyControllerInputDown(); + static bool AnyControllerInputUp(); + static bool AnyControllerButton(); + static bool AnyControllerButtonDown(); + static bool AnyControllerButtonUp(); + + static bool GetControllerInput(ControllerCode code); + static double GetControllerInputNormalisedValue(ControllerCode code); + static bool GetControllerInputDown(ControllerCode code); + static bool GetControllerInputUp(ControllerCode code); /*-----------------------------------------------------------------------------*/ /* Cursor Functions */ @@ -460,6 +498,11 @@ namespace SHADE /// static void SetMousePosition(Vector2 pos); + static Vector2 GetMousePosition(); + + static void SetMouseCentering(bool state); + static bool GetMouseCentering(); + /*-----------------------------------------------------------------------------*/ /* Timing Functions */ /*-----------------------------------------------------------------------------*/ @@ -492,6 +535,66 @@ namespace SHADE /// Time in seconds that the key was held. static double GetMouseReleasedTime(MouseCode mouseButton); + static double GetControllerInputHeldTime(ControllerCode code); + static double GetControllerInputReleasedTime(ControllerCode code); + static Vector2 GetMouseVelocity(); + + /*-----------------------------------------------------------------------------*/ + /* Binding Functions */ + /*-----------------------------------------------------------------------------*/ + static void SaveBindings(); //To default file + static void SaveBindings(System::String^ targetFile); + static void LoadBindings(); //From default file + static void LoadBindings(System::String^ sourceFile); + + static bool GetBindingInverted(System::String^ bindingName); + static void SetBindingInverted(System::String^ bindingName, bool newValue); + static double GetBindingGravity(System::String^ bindingName); + static void SetBindingGravity(System::String^ bindingName, double newValue); + static double GetBindingDead(System::String^ bindingName); + static void SetBindingDead(System::String^ bindingName, double newValue); + static double GetBindingSensitivity(System::String^ bindingName); + static void SetBindingSensitivity(System::String^ bindingName, double newValue); + static bool GetBindingSnap(System::String^ bindingName); + static void SetBindingSnap(System::String^ bindingName, bool newValue); + + static System::Collections::Generic::HashSet^ GetBindingPositiveKeyCodes(System::String^ bindingName); + static void AddBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toAdd); + static void RemoveBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toRemove); + static void ClearBindingPositiveKeyCodes(System::String^ bindingName); + + static System::Collections::Generic::HashSet^ GetBindingNegativeKeyCodes(System::String^ bindingName); + static void AddBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toAdd); + static void RemoveBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toRemove); + static void ClearBindingNegativeKeyCodes(System::String^ bindingName); + + static System::Collections::Generic::HashSet^ GetBindingPositiveControllerCodes(System::String^ bindingName); + static void AddBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toAdd); + static void RemoveBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toRemove); + static void ClearBindingPositiveControllerCodes(System::String^ bindingName); + + static System::Collections::Generic::HashSet^ GetBindingNegativeControllerCodes(System::String^ bindingName); + static void AddBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toAdd); + static void RemoveBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toRemove); + static void ClearBindingNegativeControllerCodes(System::String^ bindingName); + + //Binding states + + static double GetBindingAxis(System::String^ bindingName); + static double GetBindingAxisRaw(System::String^ bindingName); + static bool GetBindingPositiveButton(System::String^ bindingName); + static bool GetBindingNegativeButton(System::String^ bindingName); + static bool GetBindingPositiveButtonDown(System::String^ bindingName); + static bool GetBindingNegativeButtonDown(System::String^ bindingName); + static bool GetBindingPositiveButtonUp(System::String^ bindingName); + static bool GetBindingNegativeButtonUp(System::String^ bindingName); + + //Binding times + + static double GetBindingPositiveHeldTime(System::String^ bindingName); + static double GetBindingNegativeHeldTime(System::String^ bindingName); + static double GetBindingPositiveReleasedTime(System::String^ bindingName); + static double GetBindingNegativeReleasedTime(System::String^ bindingName); }; } \ No newline at end of file From 1b865b129b7ad0b9715282d0374e4892103e601d Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 23 Feb 2023 12:50:42 +0800 Subject: [PATCH 14/18] Added finalizeChanges call and debug logs for hover enter --- Assets/Scripts/UI/SC_ChangeSceneButton.cs | 9 +++++---- SHADE_Engine/src/UI/SHUISystem.cpp | 8 ++++++++ SHADE_Engine/src/UI/SHUISystem.h | 2 ++ SHADE_Managed/src/Components/UIElement.cxx | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/UI/SC_ChangeSceneButton.cs b/Assets/Scripts/UI/SC_ChangeSceneButton.cs index 6caba2b1..4ce87cc8 100644 --- a/Assets/Scripts/UI/SC_ChangeSceneButton.cs +++ b/Assets/Scripts/UI/SC_ChangeSceneButton.cs @@ -11,13 +11,14 @@ public class ChangeSceneButton : Script UIElement ui = GetComponent(); if (ui != null) { - ui.OnClick.RegisterAction(() => + ui.OnHoverEnter.RegisterAction(() => { + Debug.Log("C# Hover Enter"); if (sceneID != 0) { - Audio.PlaySFXOnce2D("event:/UI/success"); - SceneManager.ChangeScene(sceneID); - Audio.StopAllSounds(); + //Audio.PlaySFXOnce2D("event:/UI/success"); + //SceneManager.ChangeScene(sceneID); + //Audio.StopAllSounds(); } }); } diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 3552e47b..aeb30b0b 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -204,6 +204,7 @@ namespace SHADE SHButtonClickEvent clickEvent; clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT); + SHLOG_INFO("C++ BROADCASTED HOVER ENTER EVENT EID: {}", clickEvent.EID); } comp.isHovered = true; @@ -313,6 +314,7 @@ namespace SHADE auto material = renderable->GetModifiableMaterial(); comp.currentTexture = textureID; material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet(textureID)); + loadTexture = true; } @@ -367,6 +369,7 @@ namespace SHADE auto material = renderable->GetModifiableMaterial(); comp.currentTexture = textureID; material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet(textureID)); + loadTexture = true; } @@ -390,6 +393,11 @@ namespace SHADE if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) system->UpdateToggleButtonComponent(comp); } + if (system->loadTexture == true) + { + system->loadTexture = false; + SHResourceManager::FinaliseChanges(); + } } SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 3b2bb2cf..f3f7847e 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -68,6 +68,8 @@ namespace SHADE private: + bool loadTexture{false}; + void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept; diff --git a/SHADE_Managed/src/Components/UIElement.cxx b/SHADE_Managed/src/Components/UIElement.cxx index 42b8caef..75e16a1c 100644 --- a/SHADE_Managed/src/Components/UIElement.cxx +++ b/SHADE_Managed/src/Components/UIElement.cxx @@ -63,7 +63,7 @@ namespace SHADE } // Return the event - return onClickEventMap[owner.EntityId]; + return onReleasedEventMap[owner.EntityId]; } CallbackEvent^ UIElement::OnHoverEnter::get() { From d7846082a3e509bec76f2c51a642aecd97f8b65b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 23 Feb 2023 13:32:00 +0800 Subject: [PATCH 15/18] Fixed incorrect managed functions being called for new button events --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 6 +++--- SHADE_Managed/src/Components/UIElement.cxx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 36d34b6c..d63db50d 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -372,21 +372,21 @@ namespace SHADE SHEventHandle SHScriptEngine::onUIElementReleased(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); - csUIElementOnClicked(eventData->data->EID); + csUIElementOnRemoved(eventData->data->EID); return eventData->handle; } SHEventHandle SHScriptEngine::onUIElementOnHoverEntered(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); - csUIElementOnClicked(eventData->data->EID); + csUIElementOnHoverEntered(eventData->data->EID); return eventData->handle; } SHEventHandle SHScriptEngine::onUIElementOnHoverExited(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); - csUIElementOnClicked(eventData->data->EID); + csUIElementOnHoverExited(eventData->data->EID); return eventData->handle; } diff --git a/SHADE_Managed/src/Components/UIElement.cxx b/SHADE_Managed/src/Components/UIElement.cxx index 75e16a1c..cc854bd2 100644 --- a/SHADE_Managed/src/Components/UIElement.cxx +++ b/SHADE_Managed/src/Components/UIElement.cxx @@ -143,7 +143,7 @@ namespace SHADE { onReleasedEventMap[entity]->Invoke(); } - SAFE_NATIVE_CALL_END("UIElement.OnClicked") + SAFE_NATIVE_CALL_END("UIElement.OnReleased") } void UIElement::OnHoverEntered(EntityID entity) { @@ -153,7 +153,7 @@ namespace SHADE { onHoverEnterEventMap[entity]->Invoke(); } - SAFE_NATIVE_CALL_END("UIElement.OnClicked") + SAFE_NATIVE_CALL_END("UIElement.OnHoverEntered") } void UIElement::OnHoverExited(EntityID entity) { @@ -163,6 +163,6 @@ namespace SHADE { onHoverExitEventMap[entity]->Invoke(); } - SAFE_NATIVE_CALL_END("UIElement.OnClicked") + SAFE_NATIVE_CALL_END("UIElement.OnHoverExited") } } From 7292f11cdb63f93feebfa7203a33a7661e2e7896 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 23 Feb 2023 13:32:23 +0800 Subject: [PATCH 16/18] Fixed issue where duplicate script assemblies are loaded again --- SHADE_Managed/src/Components/UIElement.cxx | 14 +++++++++++++- SHADE_Managed/src/Components/UIElement.hxx | 10 ++++++++++ SHADE_Managed/src/Engine/ECS.hxx | 2 +- SHADE_Managed/src/Engine/EngineInterface.cxx | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/SHADE_Managed/src/Components/UIElement.cxx b/SHADE_Managed/src/Components/UIElement.cxx index cc854bd2..8e6134e1 100644 --- a/SHADE_Managed/src/Components/UIElement.cxx +++ b/SHADE_Managed/src/Components/UIElement.cxx @@ -28,6 +28,18 @@ namespace SHADE : Component(entity) {} + void UIElement::ClearStaticEventData() + { + if (onClickEventMap != nullptr) + onClickEventMap->Clear(); + if (onReleasedEventMap != nullptr) + onReleasedEventMap->Clear(); + if (onHoverEnterEventMap != nullptr) + onHoverEnterEventMap->Clear(); + if (onHoverExitEventMap != nullptr) + onHoverExitEventMap->Clear(); + } + /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ @@ -37,7 +49,7 @@ namespace SHADE if (onClickEventMap == nullptr) { onClickEventMap = gcnew System::Collections::Generic::Dictionary(); - } + } // Create event if it wasn't before if (!onClickEventMap->ContainsKey(owner.EntityId)) diff --git a/SHADE_Managed/src/Components/UIElement.hxx b/SHADE_Managed/src/Components/UIElement.hxx index 7b762ce3..c93e1e55 100644 --- a/SHADE_Managed/src/Components/UIElement.hxx +++ b/SHADE_Managed/src/Components/UIElement.hxx @@ -73,6 +73,15 @@ namespace SHADE CallbackEvent^ get(); } + internal: + /*-----------------------------------------------------------------------------*/ + /* Static Clear Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Disposes static event data which may contains data from SHADE_Scripting. + /// + static void ClearStaticEventData(); + private: /*-----------------------------------------------------------------------------*/ /* Event Handling Functions */ @@ -108,6 +117,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Static Data Members */ /*-----------------------------------------------------------------------------*/ + // As these hold references to code in SHADE_Scripting, we must remember to dispose of them when changing scenes static System::Collections::Generic::Dictionary^ onClickEventMap; static System::Collections::Generic::Dictionary^ onReleasedEventMap; static System::Collections::Generic::Dictionary^ onHoverEnterEventMap; diff --git a/SHADE_Managed/src/Engine/ECS.hxx b/SHADE_Managed/src/Engine/ECS.hxx index 18acf30d..64207f72 100644 --- a/SHADE_Managed/src/Engine/ECS.hxx +++ b/SHADE_Managed/src/Engine/ECS.hxx @@ -51,7 +51,7 @@ namespace SHADE /// specified Component. /// generic where T : BaseComponent - static T GetComponent(EntityID entity); + static T GetComponent(EntityID entity); /// /// Retrieves the first Component from the specified GameObject's children that /// matches the specified type. diff --git a/SHADE_Managed/src/Engine/EngineInterface.cxx b/SHADE_Managed/src/Engine/EngineInterface.cxx index 2009b2e5..50f8fbc2 100644 --- a/SHADE_Managed/src/Engine/EngineInterface.cxx +++ b/SHADE_Managed/src/Engine/EngineInterface.cxx @@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" #include "Scripts/ScriptStore.hxx" +#include "Components/UIElement.hxx" namespace SHADE { @@ -43,6 +44,9 @@ namespace SHADE oss << "[EngineInterface] Unloading " << Convert::ToNative(ManagedLibraryName) << ".dll"; ScriptStore::Exit(); + // Unload static data of components that have access to the assembly + UIElement::ClearStaticEventData(); + // Unload the script scriptContext->Unload(); scriptContext = nullptr; From 64be53bad33d7a5d1dba69586ceafc863ed34fe5 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 23 Feb 2023 13:39:09 +0800 Subject: [PATCH 17/18] Fixed button events only working once --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index d63db50d..bd2cfea5 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -372,7 +372,7 @@ namespace SHADE SHEventHandle SHScriptEngine::onUIElementReleased(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); - csUIElementOnRemoved(eventData->data->EID); + csUIElementOnReleased(eventData->data->EID); return eventData->handle; } From 69f2e678df51ca4c0118e458ce13c910b385790d Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 23 Feb 2023 13:42:22 +0800 Subject: [PATCH 18/18] re-enabled scene change and disabled debug logs --- Assets/Scripts/UI/SC_ChangeSceneButton.cs | 10 +++++----- SHADE_Engine/src/UI/SHUISystem.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/UI/SC_ChangeSceneButton.cs b/Assets/Scripts/UI/SC_ChangeSceneButton.cs index 4ce87cc8..b41a421a 100644 --- a/Assets/Scripts/UI/SC_ChangeSceneButton.cs +++ b/Assets/Scripts/UI/SC_ChangeSceneButton.cs @@ -11,14 +11,14 @@ public class ChangeSceneButton : Script UIElement ui = GetComponent(); if (ui != null) { - ui.OnHoverEnter.RegisterAction(() => + ui.OnRelease.RegisterAction(() => { - Debug.Log("C# Hover Enter"); + if (sceneID != 0) { - //Audio.PlaySFXOnce2D("event:/UI/success"); - //SceneManager.ChangeScene(sceneID); - //Audio.StopAllSounds(); + Audio.PlaySFXOnce2D("event:/UI/success"); + SceneManager.ChangeScene(sceneID); + Audio.StopAllSounds(); } }); } diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index aeb30b0b..b42e71a6 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -204,7 +204,7 @@ namespace SHADE SHButtonClickEvent clickEvent; clickEvent.EID = comp.GetEID(); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT); - SHLOG_INFO("C++ BROADCASTED HOVER ENTER EVENT EID: {}", clickEvent.EID); + //SHLOG_INFO("C++ BROADCASTED HOVER ENTER EVENT EID: {}", clickEvent.EID); } comp.isHovered = true;