Implemented mouse centering and hiding in game #384

Merged
mushgunAX merged 9 commits from SP3-10-input-management into main 2023-03-03 18:29:54 +08:00
8 changed files with 59 additions and 19 deletions

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 50110174
SubPass: UI
SubPass: UI Translucent
Properties:
data.color: {x: 0, y: 0, z: 0, w: 1}
data.textureIndex: 0

View File

@ -95,18 +95,24 @@ public class GameManager : Script
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeOut();
Application.IsCursorVisible = false;
}
protected override void update()
{
if (GamePause || !stealFoodPopUpDone)
{
Input.SetMouseCentering(false);
//Application.IsCursorVisible = true;
return;
}
if (currGameState == GameState.START)
{
Input.SetMouseCentering(true);
timer -= Time.DeltaTimeF;
if(scoreText)
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
@ -138,6 +144,7 @@ public class GameManager : Script
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMWin"].Play();
goingToWin = true;
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeIn();
}
else if(!goingToWin && (timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)))
@ -146,11 +153,14 @@ public class GameManager : Script
AudioHandler.StopAllSounds(false);
AudioHandler.audioClipHandlers["BGMLose"].Play();
goingToLose = true;
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeIn();
}
}
//Handling transitions
if (SceneFadeInOut.Instance != null)
{
if (SceneFadeInOut.Instance.FadeInFinished())
{
if (goingToWin)
@ -163,6 +173,18 @@ public class GameManager : Script
}
}
}
else
{
if (goingToWin)
{
SceneManager.ChangeScene(winScene);
}
if (goingToLose)
{
SceneManager.ChangeScene(loseScene);
}
}
}
protected override void onDestroy()
{

View File

@ -22,13 +22,11 @@ public class ChangeSceneButton : Script
{
ui.OnRelease.RegisterAction(() =>
{
if (sceneID != 0)
{
Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds();
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeIn();
clickedFlag = true;
}
@ -37,7 +35,6 @@ public class ChangeSceneButton : Script
else
{
Debug.LogError("Failed to register button action for ChangeSceneButton.");
}
}
protected override void update()

View File

@ -1,6 +1,7 @@
using System;
using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.UI;
public class EndScene : Script
{
@ -12,6 +13,15 @@ public class EndScene : Script
AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");
}
protected override void start()
{
Input.SetMouseCentering(false);
Debug.Log("EndScene::Start():");
Application.IsCursorVisible = true;
SceneFadeInOut.Instance.CallFadeOut();
}
protected override void update()
{
if (Input.GetKeyDown(Input.KeyCode.R))

View File

@ -1,6 +1,7 @@
using System;
using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.UI;
public class MainMenu : Script
{
@ -23,6 +24,9 @@ public class MainMenu : Script
protected override void start()
{
Input.SetMouseCentering(false);
Application.IsCursorVisible = true;
SceneFadeInOut.Instance.CallFadeOut();
}
protected override void update()
{

View File

@ -13,6 +13,7 @@ public class PauseMenu : Script
protected override void awake()
{
if (GameManager.Instance != null)
GameManager.Instance.GamePause = false;
if (canvas)
@ -41,6 +42,8 @@ public class PauseMenu : Script
if (GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = false;
Input.SetMouseCentering(true);
Application.IsCursorVisible = false;
AudioHandler.PauseAllSounds(false);
if (gamePauseText)
gamePauseText.Enabled = false;
@ -91,6 +94,8 @@ public class PauseMenu : Script
if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause && GameManager.Instance.stealFoodPopUpDone)
{
GameManager.Instance.GamePause = true;
Input.SetMouseCentering(false);
Application.IsCursorVisible = true;
AudioHandler.PauseAllSounds(true);
if (gamePauseText)
gamePauseText.Enabled = true;

View File

@ -43,7 +43,6 @@ namespace SHADE_Scripting.UI
protected override void start()
{
}
protected override void update()
@ -56,7 +55,6 @@ namespace SHADE_Scripting.UI
if (fadeInTime == 0.0f)
{
alphaValue = 1.0f;
}
else
{
@ -65,6 +63,7 @@ namespace SHADE_Scripting.UI
if (alphaValue >= 1.0f)
{
alphaValue = 1.0f;
//GameObject.Parent.SetActive(false);
}
}
@ -83,6 +82,8 @@ namespace SHADE_Scripting.UI
if (alphaValue <= 0.0f)
{
alphaValue = 0.0f;
//This line is to be added so that (because the fade in and out item is usually the front-most UI element)
//the fade in and out UI element does not block functionality of other UI elements
GameObject.Parent.SetActive(false);
}
}

View File

@ -198,6 +198,7 @@ namespace SHADE
void SHWindow::SetMouseVisible(bool show)
{
while(GetMouseVisible() != show)
ShowCursor(show);
}