From 90763ded715a72496d02bc25d9c5ab651dca696f Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 27 Feb 2023 08:08:04 +0800 Subject: [PATCH] Change Canvas Button Script --- Assets/Scenes/MainMenu.shade | 36 +++++++++++++- Assets/Scripts/UI/SC_ChangeCanvasButton.cs | 41 ++++++++++++++++ .../UI/SC_ChangeCanvasButton.cs.shmeta | 3 ++ SHADE_Engine/src/UI/SHUISystem.cpp | 11 +++++ SHADE_Engine/src/UI/SHUISystem.h | 2 + SHADE_Managed/Canvas.cxx | 27 ++++++++++ SHADE_Managed/Canvas.hxx | 49 +++++++++++++++++++ SHADE_Managed/src/Components/UIElement.hxx | 2 + 8 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/UI/SC_ChangeCanvasButton.cs create mode 100644 Assets/Scripts/UI/SC_ChangeCanvasButton.cs.shmeta create mode 100644 SHADE_Managed/Canvas.cxx create mode 100644 SHADE_Managed/Canvas.hxx diff --git a/Assets/Scenes/MainMenu.shade b/Assets/Scenes/MainMenu.shade index b3859b4b..7b6e653b 100644 --- a/Assets/Scenes/MainMenu.shade +++ b/Assets/Scenes/MainMenu.shade @@ -166,6 +166,9 @@ onReleaseSound: event:/Music/player_undetected hoverScale: 1.10000002 clickScale: 0.899999976 + - Type: SHADE_Scripting.UI.ChangeCanvasButton + Enabled: true + canvasToActivate: 13 - EID: 10 Name: Credits Button IsActive: true @@ -310,4 +313,35 @@ Components: ~ Scripts: - Type: SHADE_Scripting.UI.TweenManager - Enabled: true \ No newline at end of file + Enabled: true +- EID: 13 + Name: How To Play Canvas + IsActive: false + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 1920 + Canvas Height: 1080 + Scale by canvas width: false + IsActive: false + Scripts: ~ +- EID: 14 + Name: BackGround + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0.5} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1920, y: 1080, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 121834459 + IsActive: true + UI Component: + Canvas ID: 13 + Hovered: false + Clicked: false + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/UI/SC_ChangeCanvasButton.cs b/Assets/Scripts/UI/SC_ChangeCanvasButton.cs new file mode 100644 index 00000000..98ee3a73 --- /dev/null +++ b/Assets/Scripts/UI/SC_ChangeCanvasButton.cs @@ -0,0 +1,41 @@ +using SHADE; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SHADE_Scripting.UI +{ + public class ChangeCanvasButton:Script + { + + public GameObject canvasToActivate; + + protected override void awake() + { + + } + + protected override void start() + { + //if (canvasToActivate.GetComponent() == null) + // return; + UIElement ui = GetComponent(); + ui.OnRelease.RegisterAction(() => + { + Canvas.DeactivateAllCanvas(); + + canvasToActivate.SetActive(true); + Debug.Log("CANVAS CHANGED "); + }); + } + + protected override void update() + { + + } + + + } +} diff --git a/Assets/Scripts/UI/SC_ChangeCanvasButton.cs.shmeta b/Assets/Scripts/UI/SC_ChangeCanvasButton.cs.shmeta new file mode 100644 index 00000000..e817ba9d --- /dev/null +++ b/Assets/Scripts/UI/SC_ChangeCanvasButton.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_ChangeCanvasButton +ID: 154633292 +Type: 9 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index a8d69377..05bd9ab5 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -493,6 +493,17 @@ namespace SHADE return result; } + void SHUISystem::HideActiveCanvas() noexcept + { + auto& dense = SHComponentManager::GetDense(); + for (auto& canvas : dense) + { + if (SHSceneManager::CheckNodeAndComponentsActive(canvas.GetEID())) + { + SHSceneManager::GetCurrentSceneGraph().SetActive(canvas.GetEID(), false); + } + } + } diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index a1fde5db..70308f3d 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -66,6 +66,8 @@ namespace SHADE void Init(); void Exit(); + void HideActiveCanvas() noexcept; + private: bool loadTexture{false}; diff --git a/SHADE_Managed/Canvas.cxx b/SHADE_Managed/Canvas.cxx new file mode 100644 index 00000000..146b58f7 --- /dev/null +++ b/SHADE_Managed/Canvas.cxx @@ -0,0 +1,27 @@ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Canvas.hxx" +#include "Assets/NativeAsset.hxx" +#include "Utility/Convert.hxx" +#include "Utility/Debug.hxx" + + +#include "ECS_Base/Managers/SHSystemManager.h" +#include "UI/SHUISystem.h" + + +namespace SHADE +{ + Canvas::Canvas(Entity entity) + : Component(entity) + {} + + void Canvas::DeactivateAllCanvas() + { + auto system = SHSystemManager::GetSystem(); + system->HideActiveCanvas(); + } + + +} diff --git a/SHADE_Managed/Canvas.hxx b/SHADE_Managed/Canvas.hxx new file mode 100644 index 00000000..d9e1ca79 --- /dev/null +++ b/SHADE_Managed/Canvas.hxx @@ -0,0 +1,49 @@ +/************************************************************************************//*! +\file UIElement.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Jan 30, 2023 +\brief Contains the definition of the managed UIElement class with the + declaration of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2023 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +#include "Math/Quaternion.hxx" +// External Dependencies +#include "UI/SHCanvasComponent.h" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHUIComponent. + /// + public ref class Canvas : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a Canvas Component that represents a native SHCanvasComponent + /// tied to the specified Entity. + /// + /// Entity that this Component will be tied to. + Canvas(Entity entity); + + public: + + static void DeactivateAllCanvas(); + + + }; +} + diff --git a/SHADE_Managed/src/Components/UIElement.hxx b/SHADE_Managed/src/Components/UIElement.hxx index c93e1e55..d8f741d2 100644 --- a/SHADE_Managed/src/Components/UIElement.hxx +++ b/SHADE_Managed/src/Components/UIElement.hxx @@ -73,6 +73,8 @@ namespace SHADE CallbackEvent^ get(); } + + internal: /*-----------------------------------------------------------------------------*/ /* Static Clear Functions */