From 0984eee6bb3d71b7489b264267dc97c7de3cdad2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 2 Mar 2023 17:34:11 +0800 Subject: [PATCH 1/2] Gameplay UI WIP --- Assets/Scenes/Level2.shade | 45 +++++++++++++++++-- Assets/Scripts/Gameplay/SC_GameManager.cs | 5 +++ Assets/Scripts/UI/EasingHelper.cs | 4 +- Assets/Scripts/UI/SC_MultiplierTextFx.cs | 42 +++++++++++++++-- .../src/Components/TextRenderable.cxx | 13 ++++++ .../src/Components/TextRenderable.hxx | 7 +++ SHADE_Managed/src/Components/Transform.cxx | 1 + 7 files changed, 109 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index e3de1671..cb330d56 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -4833,14 +4833,14 @@ Enabled: true - EID: 10 Name: Pause Canvas - IsActive: true + IsActive: false NumberOfChildren: 4 Components: Canvas Component: Canvas Width: 1920 Canvas Height: 1080 Scale by canvas width: false - IsActive: true + IsActive: false Scripts: ~ - EID: 8 Name: ResumeButton @@ -13435,4 +13435,43 @@ Components: ~ Scripts: - Type: SHADE_Scripting.UI.TweenManager - Enabled: true \ No newline at end of file + Enabled: true +- EID: 524 + Name: Canvas + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 1920 + Canvas Height: 1080 + Scale by canvas width: false + IsActive: true + Scripts: ~ +- EID: 525 + Name: StealFoodLogo + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 0, y: 0, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 127459277 + IsActive: true + UI Component: + Canvas ID: 524 + Hovered: false + Clicked: false + IsActive: true + Scripts: + - Type: SHADE_Scripting.UI.StealFoodPopUp + Enabled: true + popInDuration: 0.5 + popOutDuration: 0.5 + stayDuration: 1 + rotationAmt: 1800 + scaleAmtX: 538 + scaleAmtY: 377 \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index 00eeadbb..b61928ba 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -90,6 +90,11 @@ public class GameManager : Script protected override void update() { + if (Input.GetKeyDown(Input.KeyCode.G)) + ItemScored(); + + + if (GamePause) { return; diff --git a/Assets/Scripts/UI/EasingHelper.cs b/Assets/Scripts/UI/EasingHelper.cs index d0480f7a..37c54d06 100644 --- a/Assets/Scripts/UI/EasingHelper.cs +++ b/Assets/Scripts/UI/EasingHelper.cs @@ -52,12 +52,12 @@ namespace SHADE_Scripting.UI private static float EaseInSine(float value) { - return (float)(1.0f - Math.Cos((value * Math.PI) / 2.0f)); + return (float)(1.0f - Math.Cos((value * Math.PI / 2.0f) )); } private static float EaseOutSine(float value) { - return (float)(Math.Sin(value * Math.PI) / 2.0f); + return (float)(Math.Sin(value * Math.PI / 2.0f) ); } diff --git a/Assets/Scripts/UI/SC_MultiplierTextFx.cs b/Assets/Scripts/UI/SC_MultiplierTextFx.cs index 1b3129ec..ccd2a4a8 100644 --- a/Assets/Scripts/UI/SC_MultiplierTextFx.cs +++ b/Assets/Scripts/UI/SC_MultiplierTextFx.cs @@ -11,6 +11,7 @@ namespace SHADE_Scripting.UI { [NonSerialized] private TweenThread sizeThread; + private TweenThread sizeInvertThread; private TweenThread alphaThread; @@ -20,6 +21,7 @@ namespace SHADE_Scripting.UI private bool showMultiplier = false; + const float sizeUpDuration = 0.1f; [NonSerialized] private Vector3 defaultScale; @@ -27,6 +29,7 @@ namespace SHADE_Scripting.UI protected override void start() { sizeThread = TweenManager.CreateTweenThread(0.0f, maxSize, minSize, EASING_METHOD.EASE_IN_SINE); + sizeInvertThread = TweenManager.CreateTweenThread(sizeUpDuration, minSize, maxSize, EASING_METHOD.EASE_IN_SINE); alphaThread = TweenManager.CreateTweenThread(0.0f, 1.0f, minAlpha, EASING_METHOD.EASE_OUT_SINE); Transform transform = GetComponent(); if (transform != null) @@ -43,8 +46,29 @@ namespace SHADE_Scripting.UI protected override void update() { Transform transform = GetComponent(); + + if (transform != null && showMultiplier == true) { + if(!sizeInvertThread.IsCompleted()) + { + transform.LocalScale = defaultScale * sizeInvertThread.GetValue(); + + Renderable rend = GetComponentInChildren(); + if(rend) + { + rend.Material.SetProperty("data.alpha", 1.0f); + } + + TextRenderable text = GetComponent(); + if (text) + { + Color clr = text.TextColor; + text.TextColor = new Color(clr.r, clr.g, clr.b, 1.0f); + } + return; + } + if(sizeThread.IsCompleted()) { transform.LocalScale = Vector3.Zero; @@ -53,7 +77,18 @@ namespace SHADE_Scripting.UI else { transform.LocalScale = defaultScale * sizeThread.GetValue(); - GetComponentInChildren().Material.SetProperty("data.alpha",alphaThread.GetValue()); + + Renderable rend = GetComponentInChildren(); + if (rend) + { + rend.Material.SetProperty("data.alpha", alphaThread.GetValue()); + } + TextRenderable text = GetComponent(); + if(text) + { + Color clr = text.TextColor; + text.TextColor = new Color(clr.r,clr.g,clr.b,alphaThread.GetValue() * 1.3f); + } } } } @@ -62,9 +97,10 @@ namespace SHADE_Scripting.UI public void ShowMultiplier(int multiplier, float duration) { GetComponent().Text = $"X {multiplier}"; - sizeThread.duration = duration; - alphaThread.duration = duration; + sizeThread.duration = duration + sizeUpDuration; + alphaThread.duration = duration + sizeUpDuration; + sizeInvertThread.Reset(); sizeThread.Reset(); alphaThread.Reset(); showMultiplier = true; diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx index 3eb1f3b9..93d80b65 100644 --- a/SHADE_Managed/src/Components/TextRenderable.cxx +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited. #include "Assets/NativeAsset.hxx" #include "Utility/Convert.hxx" + namespace SHADE { /*---------------------------------------------------------------------------------*/ @@ -55,4 +56,16 @@ namespace SHADE GetNativeComponent()->SetFont(value.NativeObject); } } + + Color TextRenderable::TextColor::get() + { + return Convert::ToCLI(GetNativeComponent()->GetColour()); + } + + void TextRenderable::TextColor::set(Color value) + { + GetNativeComponent()->SetColour(Convert::ToNative(value)); + } + + } diff --git a/SHADE_Managed/src/Components/TextRenderable.hxx b/SHADE_Managed/src/Components/TextRenderable.hxx index b17a919c..b65f9c59 100644 --- a/SHADE_Managed/src/Components/TextRenderable.hxx +++ b/SHADE_Managed/src/Components/TextRenderable.hxx @@ -60,6 +60,13 @@ namespace SHADE FontAsset get(); void set(FontAsset value); } + + property Color TextColor + { + Color get(); + void set(Color value); + } + }; } diff --git a/SHADE_Managed/src/Components/Transform.cxx b/SHADE_Managed/src/Components/Transform.cxx index d5b38967..3216d0f0 100644 --- a/SHADE_Managed/src/Components/Transform.cxx +++ b/SHADE_Managed/src/Components/Transform.cxx @@ -22,6 +22,7 @@ namespace SHADE : Component(entity) {} + /*-----------------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------------*/ From 6d1e179baffea40e5eb0c02666d2193e28ab5306 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sat, 4 Mar 2023 02:46:56 +0800 Subject: [PATCH 2/2] UI doine --- Assets/Scenes/Level2.shade | 30 +++++++++++--- Assets/Scenes/MainMenu.shade | 14 ++++--- Assets/Scripts/Gameplay/SC_GameManager.cs | 9 ++--- Assets/Scripts/UI/SC_ScrollingCredits.cs | 49 +++++++++++++++++++++++ 4 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 Assets/Scripts/UI/SC_ScrollingCredits.cs diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index cb330d56..948964e3 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -2279,18 +2279,38 @@ IsActive: true Scripts: ~ - EID: 206 - Name: Timer + Name: Timer Text IsActive: true - NumberOfChildren: 0 + NumberOfChildren: 1 Components: Transform Component: - Translate: {x: 500, y: 400, z: 0} + Translate: {x: 700, y: 400, z: 0.100000001} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 60, y: 60, z: 60} IsActive: true Text Renderer Component: Text: My name is Brandon. - Font: 176667660 + Font: 174412429 + IsActive: true + UI Component: + Canvas ID: 199 + Hovered: false + Clicked: false + IsActive: true + Scripts: ~ +- EID: 526 + Name: Timer BG + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0.5, y: 0.300000012, z: 0.98999995} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 5, y: 2, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 126220632 IsActive: true UI Component: Canvas ID: 199 @@ -4882,7 +4902,7 @@ Components: Transform Component: Translate: {x: 0, y: -300, z: 0} - Rotate: {x: 0, y: 0, z: 0} + Rotate: {x: 724.5, y: 424.5, z: 59.9999962} Scale: {x: 400, y: 100, z: 500} IsActive: true Renderable Component: diff --git a/Assets/Scenes/MainMenu.shade b/Assets/Scenes/MainMenu.shade index 1edd67b5..6e569b46 100644 --- a/Assets/Scenes/MainMenu.shade +++ b/Assets/Scenes/MainMenu.shade @@ -1100,7 +1100,11 @@ Hovered: false Clicked: false IsActive: true - Scripts: ~ + Scripts: + - Type: SHADE_Scripting.UI.ScrollingCredits + Enabled: true + endY: 4000 + duration: 20 - EID: 48 Name: BackButton IsActive: true @@ -1131,23 +1135,23 @@ canvasToActivate: 0 - EID: 49 Name: Credits Title Text - IsActive: true + IsActive: false NumberOfChildren: 0 Components: Transform Component: Translate: {x: -150, y: 400, z: 0.100000001} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 100, y: 100, z: 1} - IsActive: true + IsActive: false Text Renderer Component: Text: Credits Font: 174412429 - IsActive: true + IsActive: false UI Component: Canvas ID: 46 Hovered: false Clicked: false - IsActive: true + IsActive: false Scripts: ~ - EID: 50 Name: Level Select Canvas diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index b61928ba..0ec3a4e5 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -106,12 +106,10 @@ public class GameManager : Script if(scoreText) scoreText.GetComponent().Text = $"{Score}"; if(timeText) - timeText.GetComponent().Text = $"Time Left: {timer.ToString("0.00")}"; + timeText.GetComponent().Text = $"{timer.ToString("0.00")}"; if (itemScored) { - //multiplierText.GetComponent().Text = $"X {currMultiplierCombo}"; - //multiplierText.GetComponent().LocalScale -= fontScalar * Time.DeltaTimeF; currMultiplierDuration += Time.DeltaTimeF; if (currMultiplierDuration >= maxMultiplierDuration) @@ -170,7 +168,6 @@ public class GameManager : Script totalItemCount -= 1; itemScored = true; currMultiplierDuration = 0; - //multiplierText.GetComponent().LocalScale = new Vector3(multiplierFont, multiplierFont, multiplierFont); if (currMultiplierCombo < maxMultiplierCombo) currMultiplierCombo += 1; @@ -178,9 +175,9 @@ public class GameManager : Script MultiplierTextFx fx = multiplierText.GetScript(); if (fx) { - fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration); + fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration); } - } + } } diff --git a/Assets/Scripts/UI/SC_ScrollingCredits.cs b/Assets/Scripts/UI/SC_ScrollingCredits.cs new file mode 100644 index 00000000..d4b362d8 --- /dev/null +++ b/Assets/Scripts/UI/SC_ScrollingCredits.cs @@ -0,0 +1,49 @@ +using System; +using SHADE; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SHADE_Scripting.UI +{ + public class ScrollingCredits: Script + { + + public float endY = 4000.0f; + public float duration = 30.0f; + + + [NonSerialized] + TweenThread thread; + + protected override void awake() + { + base.awake(); + + } + + protected override void start() + { + base.start(); + + Transform transform = GetComponent(); + if(transform != null) + { + thread = TweenManager.CreateTweenThread(duration, transform.LocalPosition.y, endY, EASING_METHOD.EASE_IN_SINE); + } + } + + protected override void update() + { + base.update(); + + Transform transform = GetComponent(); + + if(thread != null && transform != null) + { + transform.LocalPosition = new Vector3( transform.LocalPosition.x ,thread.GetValue() , transform.LocalPosition.z); + } + } + } +}