diff --git a/Assets/Scripts/UI/SC_ChangeSceneButton.cs b/Assets/Scripts/UI/SC_ChangeSceneButton.cs index 6caba2b1..b41a421a 100644 --- a/Assets/Scripts/UI/SC_ChangeSceneButton.cs +++ b/Assets/Scripts/UI/SC_ChangeSceneButton.cs @@ -11,8 +11,9 @@ public class ChangeSceneButton : Script UIElement ui = GetComponent(); if (ui != null) { - ui.OnClick.RegisterAction(() => + ui.OnRelease.RegisterAction(() => { + if (sceneID != 0) { Audio.PlaySFXOnce2D("event:/UI/success"); diff --git a/Assets/Shaders/UI_FS.glsl b/Assets/Shaders/UI_FS.glsl index 26abfece..ea0bf7e9 100644 --- a/Assets/Shaders/UI_FS.glsl +++ b/Assets/Shaders/UI_FS.glsl @@ -37,11 +37,12 @@ layout(location = 1) out uint outEntityID; void main() { fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); - fragColor.a = MatProp.data[In2.materialIndex].alpha; if (fragColor.a < 0.01f) { - discard; + fragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); + // discard; } + fragColor.a = MatProp.data[In2.materialIndex].alpha; // fragColor.a = 1.0f; outEntityID = In2.eid; diff --git a/Assets/Shaders/UI_FS.shshaderb b/Assets/Shaders/UI_FS.shshaderb index 236eeaf5..f67223b9 100644 Binary files a/Assets/Shaders/UI_FS.shshaderb and b/Assets/Shaders/UI_FS.shshaderb differ 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 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 2f0ab6d6..dd3cfe80 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 { @@ -21,6 +24,7 @@ namespace SHADE /* Static defines */ /*------------------------------------------------------------------------*/ + bool SHInputManager::mouseCentering = false; bool SHInputManager::controllerInUse = false; std::map SHInputManager::bindings; @@ -751,6 +755,7 @@ namespace SHADE { ++keyCount; keys[i] = true; + controllerInUse = false; } else keys[i] = false; @@ -801,6 +806,25 @@ namespace SHADE mouseVelocityX = static_cast(mouseScreenX - mouseScreenXLast) / dt; mouseVelocityY = static_cast(mouseScreenY - mouseScreenYLast) / dt; + + //Mouse Centering + if (mouseCentering) + { + uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); + uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); + SetMouseWindowPosition(width / 2, height / 2); + + //These four lines help a lot + POINT p; + GetCursorPos(&p); + 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 mouseWheelVerticalDelta = 0; mouseWheelVerticalDelta = mouseWheelVerticalDeltaPoll; 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 diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 22c7c12e..bd2cfea5 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()); + csUIElementOnReleased(eventData->data->EID); + return eventData->handle; + } + + SHEventHandle SHScriptEngine::onUIElementOnHoverEntered(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csUIElementOnHoverEntered(eventData->data->EID); + return eventData->handle; + } + + SHEventHandle SHScriptEngine::onUIElementOnHoverExited(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csUIElementOnHoverExited(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_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 641743b8..7c5c1a0a 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)->TextureArrayIndex); + 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 d76d6d42..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)) @@ -48,6 +60,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 onReleasedEventMap[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 +123,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 +147,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.OnReleased") + } + 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.OnHoverEntered") + } + 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.OnHoverExited") + } } diff --git a/SHADE_Managed/src/Components/UIElement.hxx b/SHADE_Managed/src/Components/UIElement.hxx index a969e4b5..c93e1e55 100644 --- a/SHADE_Managed/src/Components/UIElement.hxx +++ b/SHADE_Managed/src/Components/UIElement.hxx @@ -50,6 +50,37 @@ 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(); + } + + internal: + /*-----------------------------------------------------------------------------*/ + /* Static Clear Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Disposes static event data which may contains data from SHADE_Scripting. + /// + static void ClearStaticEventData(); private: /*-----------------------------------------------------------------------------*/ @@ -65,11 +96,32 @@ 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 */ /*-----------------------------------------------------------------------------*/ + // 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; + static System::Collections::Generic::Dictionary^ onHoverExitEventMap; }; } 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; 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 875054cc..f62e0cab 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,35 @@ 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) + }; + + 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 */ @@ -376,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. @@ -427,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 */ @@ -440,6 +498,11 @@ namespace SHADE /// static void SetMousePosition(Vector2 pos); + static Vector2 GetMousePosition(); + + static void SetMouseCentering(bool state); + static bool GetMouseCentering(); + /*-----------------------------------------------------------------------------*/ /* Timing Functions */ /*-----------------------------------------------------------------------------*/ @@ -472,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