From fe64844c4e429194f6bd9e9071e35e726d539b55 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 21 Feb 2023 09:55:14 +0800 Subject: [PATCH 01/10] 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 06ad2a4c0c6b416941eb3c3728bc18835e5498d2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 21 Feb 2023 21:20:31 +0800 Subject: [PATCH 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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 08/10] 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 09/10] 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 10/10] 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;