From bde191aeca68eae05e6bae9e6374a8facab30b51 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 25 Jan 2023 23:22:15 +0800 Subject: [PATCH] Input Bindings Panel Done --- Assets/Bindings.SHConfig | 95 +++ .../InputBindings/SHInputBindingsPanel.cpp | 541 ++++++++++++++---- SHADE_Engine/src/Input/SHInputManager.cpp | 50 +- SHADE_Engine/src/Input/SHInputManager.h | 11 +- 4 files changed, 550 insertions(+), 147 deletions(-) diff --git a/Assets/Bindings.SHConfig b/Assets/Bindings.SHConfig index 573541ac..bdc254b5 100644 --- a/Assets/Bindings.SHConfig +++ b/Assets/Bindings.SHConfig @@ -1 +1,96 @@ +7 +Controller Look Horizontal 0 +0 +5 +0.2 +5 +0 +0 +0 +1 +18 +0 +Controller Look Vertical +0 +0 +5 +0.2 +5 +0 +0 +0 +1 +19 +0 +Horizontal +0 +0 +5 +0.2 +5 +1 +2 +39 +68 +2 +37 +65 +2 +3 +16 +1 +2 +Jump +0 +0 +1000 +0.2 +1000 +0 +1 +32 +0 +1 +10 +0 +Mouse Look Horizontal +1 +0 +1 +0.2 +1 +0 +0 +0 +0 +0 +Mouse Look Vertical +2 +0 +1 +0.2 +1 +0 +0 +0 +0 +0 +Vertical +0 +0 +5 +0.2 +5 +1 +2 +38 +87 +2 +40 +83 +2 +0 +17 +1 +1 diff --git a/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp index ca9e263f..c304c1b0 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/InputBindings/SHInputBindingsPanel.cpp @@ -5,8 +5,29 @@ namespace SHADE { + //Vectors containing data for elements for different bindings static std::vector bindingRenames; - static std::vector positiveKeyListening; + + //Flags to prevent unwanted editing of bindings + static size_t positiveKeyListeningFor; + static bool positiveKeyListening; + + static size_t negativeKeyListeningFor; + static bool negativeKeyListening; + + static size_t positiveControllerListeningFor; + static bool positiveControllerListening; + + static size_t negativeControllerListeningFor; + static bool negativeControllerListening; + + //Internal Helper function + void resizeVectors(size_t newSize) + { + bindingRenames.resize(newSize); + for (auto& s : bindingRenames) + s.clear(); + } //Internal Helper function std::string labelConcat(char const* label, size_t entryNumber) @@ -25,17 +46,63 @@ namespace SHADE { if (SHEditorWindow::Begin()) { + //ImGui::ShowDemoWindow(); + //Binding count ImGui::Text("Binding Count: %d", SHInputManager::CountBindings()); + //Binding file name + static std::string bindingFileName; + ImGui::InputText("Binding File Path", &bindingFileName); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text(".SHConfig will be appeneded to file name"); + ImGui::Text("If no name is provided, saves to \"Assets/Bindings.SHConfig\""); + ImGui::EndTooltip(); + } + + //Save bindings to... + if (ImGui::Button("Save Bindings")) + { + if (bindingFileName.empty()) + { + SHInputManager::SaveBindings(); + } + else + { + std::string filePath = std::string(ASSET_ROOT); + filePath += "/"; + filePath += bindingFileName; + filePath += ".SHConfig"; + SHInputManager::SaveBindings(filePath); + } + } + + //Load bindings from... + if (ImGui::Button("Load Bindings")) + { + if (bindingFileName.empty()) + { + SHInputManager::LoadBindings(); + } + else + { + std::string filePath = std::string(ASSET_ROOT); + filePath += "/"; + filePath += bindingFileName; + filePath += ".SHConfig"; + SHInputManager::LoadBindings(filePath); + } + resizeVectors(SHInputManager::CountBindings()); + } + //Button to add new binding if (ImGui::Button("Add New Binding")) { std::string newBindingName = "Binding" + std::to_string(SHInputManager::CountBindings()); SHInputManager::AddBinding(newBindingName); - bindingRenames.resize(SHInputManager::CountBindings()); - for (auto& s : bindingRenames) - s.clear(); + resizeVectors(SHInputManager::CountBindings()); } if (ImGui::IsItemHovered()) { @@ -50,144 +117,378 @@ namespace SHADE //Listing for each binding for (auto& binding : SHInputManager::GetBindings()) { - ImGui::Separator(); - - ImGui::Text("Entry Number %d", entryNumber); - - //Non-modifiable binding name - ImGui::Text("Binding Name: %s", binding.first); - ImGui::InputText(labelConcat("##bindingModifyName", entryNumber).c_str(), &bindingRenames[entryNumber]); - ImGui::SameLine(); - if (ImGui::Button(labelConcat("Rename##bindingRename", entryNumber).c_str())) + if (ImGui::CollapsingHeader(binding.first.c_str())) { - SHInputManager::RenameBinding(binding.first, bindingRenames[entryNumber]); - bindingRenames[entryNumber].clear(); - } + //Modifiable binding name + ImGui::Text("Binding Name: %s", binding.first.c_str()); + ImGui::InputText(labelConcat("##bindingModifyName", entryNumber).c_str(), &bindingRenames[entryNumber]); + ImGui::SameLine(); + if (ImGui::Button(labelConcat("Rename##bindingRename", entryNumber).c_str())) + { + SHInputManager::RenameBinding(binding.first, bindingRenames[entryNumber]); + bindingRenames[entryNumber].clear(); + } - //Modifiable binding name - /*size_t constexpr maxLen = 256; //Maximum binding name length - static char bindingNameCStr[maxLen]; - std::copy(binding.first.begin(), - binding.first.length() >= maxLen ? - binding.first.begin() + maxLen : - binding.first.end(), //Does not take into account null terminator - bindingNameCStr); - bindingNameCStr[binding.first.length()] = '\0'; //Null terminator - - //First character - char firstChar = bindingNameCStr[0]; - //If the input text is modified, modify the binding's name - if (ImGui::InputText("Binding Name", bindingNameCStr, maxLen)) - { - //Ensure name does not get shorter than 1 character long - if (std::strlen(bindingNameCStr) < 1) - bindingNameCStr[0] = firstChar; - //Rename binding in the input manager - SHInputManager::RenameBinding(binding.first, std::string{ bindingNameCStr }); - binding.first = std::string{ bindingNameCStr }; - } - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("The name of this binding"); - ImGui::EndTooltip(); - }*/ - - //Binding value test - //TODO - ImGui::Text("Value"); - - //Binding Type Combo Box - int bindingType = static_cast(SHInputManager::GetBindingType(binding.first)); - if (ImGui::Combo(labelConcat("Input Type##", entryNumber).c_str(), &bindingType, "Keyboard / Mouse Buttons / Controller\0Mouse Horizontal\0Mouse Vertical\0Mouse Scroll Wheel")) - SHInputManager::SetBindingType(binding.first, static_cast(bindingType)); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Which of the four types the binding uses"); - ImGui::Text("Keyboard / Mouse Buttons / Controller = Keys, mouse buttons and ALL controller inputs"); - ImGui::Text("Mouse Horizontal = Horizontal movement of the mouse"); - ImGui::Text("Mouse Vertical = Vertical movement of the mouse"); - ImGui::Text("Mouse Scroll Wheel = The scroll wheel found at the middle of most mouses"); - ImGui::EndTooltip(); - } - - //Inversion - bool bindingInvert = SHInputManager::GetBindingInverted(binding.first); - if (ImGui::Checkbox(labelConcat("Inverted##", entryNumber).c_str(), &bindingInvert)) - SHInputManager::SetBindingInverted(binding.first, bindingInvert); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("If inverted:"); - ImGui::Text("Positive inputs mean negative value of the binding"); - ImGui::Text("Negative inputs mean positive value of the binding"); - ImGui::Text("Mouse moving up / right means negative value of the binding"); - ImGui::Text("Scrolling the mouse wheel up means negative value of the binding"); - ImGui::EndTooltip(); - } - - //Sensitivity - double bindingSensitivity = SHInputManager::GetBindingSensitivity(binding.first); - if (ImGui::InputDouble(labelConcat("Sensitivity##", entryNumber).c_str(), &bindingSensitivity)) - SHInputManager::SetBindingSensitivity(binding.first, bindingSensitivity); - if (ImGui::IsItemHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("Value multiplier for mouse movement and scrolling"); - ImGui::Text("For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative"); - ImGui::Text("For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1"); - ImGui::EndTooltip(); - } - - //Below this section is only for KB/M type bindings - //Not relevant for mouse movement and scrolling - if (SHInputManager::GetBindingType(binding.first) == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER) - { - //Dead - float bindingDead = static_cast(SHInputManager::GetBindingDead(binding.first)); - if (ImGui::SliderFloat(labelConcat("Deadzone##", entryNumber).c_str(), &bindingDead, 0.0f, 1.0f)) - SHInputManager::SetBindingDead(binding.first, static_cast(bindingDead)); + if (ImGui::Button(labelConcat("Delete Binding##", entryNumber).c_str())) + { + SHInputManager::RemoveBinding(binding.first); + resizeVectors(SHInputManager::CountBindings()); + ImGui::End(); + return; + } if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("Any positive or negative analog input with magnitude less than this will be registered as neutral"); + ImGui::Text("Delete this binding from the list"); ImGui::EndTooltip(); } - //Gravity - double bindingGravity = SHInputManager::GetBindingGravity(binding.first); - if (ImGui::InputDouble(labelConcat("Gravity##", entryNumber).c_str(), &bindingGravity)) - SHInputManager::SetBindingGravity(binding.first, static_cast(bindingGravity)); + //Binding value test + ImGui::BeginDisabled(); + float val = SHInputManager::GetBindingAxis(binding.first); + ImGui::SliderFloat(labelConcat("Value##", entryNumber).c_str(), &val, -1.0f, 1.0f); + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("The rate at which the value moves to neutral if no input in the direction is read"); - ImGui::TextColored(ImVec4{ 1.0f, 0.5f, 0.5f, 1.0f }, "Should be non-negative"); + ImGui::Text("Test the current value of the binding"); + ImGui::Text("For mouse movement/wheel inputs, will be multiplied by Sensitivity, with 0 being neutral (no input detected)"); + ImGui::Text("Between -1 and 1 for other inputs, with 0 still being neutral (no input detected)"); ImGui::EndTooltip(); } - - //Snap - bool bindingSnap = SHInputManager::GetBindingSnap(binding.first); - if (ImGui::Checkbox(labelConcat("Snap##", entryNumber).c_str(), &bindingSnap)) - SHInputManager::SetBindingSnap(binding.first, bindingSnap); + ImGui::BeginDisabled(); + float rawVal = SHInputManager::GetBindingAxisRaw(binding.first); + ImGui::SliderFloat(labelConcat("Raw Value##", entryNumber).c_str(), &rawVal, -1.0f, 1.0f); + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("If no other input on the axis is present and a input is made in the opposite direction of the current value,"); - ImGui::Text("the binding's value will jump to neutral 0 before resuming in the input direction"); + ImGui::Text("Test the current value of the binding"); + ImGui::Text("Raw value means it will be fixed among -1, 0 and 1 for non-mouse movement/wheel inputs"); + ImGui::Text("No difference between this and Value for mouse movement/wheel inputs"); + ImGui::Text("But for other inputs, does not consider smoothing options such as gravity and sensitivity"); + ImGui::Text("If both positive and negative input is detected, returns neutral 0"); ImGui::EndTooltip(); } - - //Positive key codes - //Negative key codes + //Binding Type Combo Box + int bindingType = static_cast(SHInputManager::GetBindingType(binding.first)); + if (ImGui::Combo(labelConcat("Input Type##", entryNumber).c_str(), &bindingType, "Keyboard / Mouse Buttons / Controller\0Mouse Horizontal\0Mouse Vertical\0Mouse Scroll Wheel")) + SHInputManager::SetBindingType(binding.first, static_cast(bindingType)); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Which of the four types the binding uses"); + ImGui::Text("Keyboard / Mouse Buttons / Controller = Keys, mouse buttons and ALL controller inputs"); + ImGui::Text("Mouse Horizontal = Horizontal movement of the mouse"); + ImGui::Text("Mouse Vertical = Vertical movement of the mouse"); + ImGui::Text("Mouse Scroll Wheel = The scroll wheel found at the middle of most mouses"); + ImGui::EndTooltip(); + } - //Positive controller codes + //Inversion + bool bindingInvert = SHInputManager::GetBindingInverted(binding.first); + if (ImGui::Checkbox(labelConcat("Inverted##", entryNumber).c_str(), &bindingInvert)) + SHInputManager::SetBindingInverted(binding.first, bindingInvert); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("If inverted:"); + ImGui::Text("Positive inputs mean negative value of the binding"); + ImGui::Text("Negative inputs mean positive value of the binding"); + ImGui::Text("Mouse moving up / right means negative value of the binding"); + ImGui::Text("Scrolling the mouse wheel up means negative value of the binding"); + ImGui::EndTooltip(); + } - //Negative controller codes + //Sensitivity + double bindingSensitivity = SHInputManager::GetBindingSensitivity(binding.first); + if (ImGui::InputDouble(labelConcat("Sensitivity##", entryNumber).c_str(), &bindingSensitivity)) + SHInputManager::SetBindingSensitivity(binding.first, bindingSensitivity); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Value multiplier for mouse movement and scrolling"); + ImGui::Text("For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative"); + //ImGui::Text("For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1"); + ImGui::Text("Irrelevant for other analog inputs"); + ImGui::EndTooltip(); + } + + //Below this section is only for KB/M type bindings + //Not relevant for mouse movement and scrolling + if (SHInputManager::GetBindingType(binding.first) == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER) + { + //Dead + float bindingDead = static_cast(SHInputManager::GetBindingDead(binding.first)); + if (ImGui::SliderFloat(labelConcat("Deadzone##", entryNumber).c_str(), &bindingDead, 0.0f, 1.0f)) + SHInputManager::SetBindingDead(binding.first, static_cast(bindingDead)); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Any positive or negative analog input with magnitude less than this will be registered as neutral"); + ImGui::EndTooltip(); + } + + //Gravity + double bindingGravity = SHInputManager::GetBindingGravity(binding.first); + if (ImGui::InputDouble(labelConcat("Gravity##", entryNumber).c_str(), &bindingGravity)) + SHInputManager::SetBindingGravity(binding.first, static_cast(bindingGravity)); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("The rate at which the value moves to neutral if no input in the direction is read"); + ImGui::TextColored(ImVec4{ 1.0f, 0.5f, 0.5f, 1.0f }, "Should be non-negative"); + ImGui::EndTooltip(); + } + + //Snap + bool bindingSnap = SHInputManager::GetBindingSnap(binding.first); + if (ImGui::Checkbox(labelConcat("Snap##", entryNumber).c_str(), &bindingSnap)) + SHInputManager::SetBindingSnap(binding.first, bindingSnap); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("If no other input on the axis is present and a input is made in the opposite direction of the current value,"); + ImGui::Text("the binding's value will jump to neutral 0 before resuming in the input direction"); + ImGui::EndTooltip(); + } + + size_t keycodeIndex = 0; + //Positive key codes + ImGui::Separator(); + ImGui::Text("Positive Key Codes:"); + + ImGui::SameLine(); + //Button to ask for inputs + if (!positiveKeyListening) + { + if (ImGui::Button(labelConcat("New##positiveKeyCode", entryNumber).c_str())) + { + positiveKeyListening = true; + positiveKeyListeningFor = entryNumber; + } + } + else + { + if (positiveKeyListeningFor == entryNumber) + { + //Listening for inputs + ImGui::Button(labelConcat("Press##positiveKeyCode", entryNumber).c_str()); + + SHInputManager::SH_KEYCODE k; + if (SHInputManager::AnyKey(&k)) + { + positiveKeyListening = false; + SHInputManager::AddBindingPositiveKeyCode(binding.first, k); + } + } + else + { + //Not listening + ImGui::BeginDisabled(); + ImGui::Button(labelConcat("New##positiveKeyCode", entryNumber).c_str()); + ImGui::EndDisabled(); + } + } + + //List and remove bindings + ImGui::Indent(); + keycodeIndex = 0; + for (auto& k : binding.second.positiveKeyCodes) + { + //ImGui::Text("%d", static_cast(k)); + ImGui::Text(SHInputManager::GetKeyCodeName(k).c_str()); + ImGui::SameLine(); + std::string labelString = "X##KeyPositive"; + labelString += binding.first; + + //Delete button + if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str())) + { + SHInputManager::RemoveBindingPositiveKeyCode(binding.first, k); + break; + } + ++keycodeIndex; + } + ImGui::Unindent(); + + + //Negative key codes + ImGui::Separator(); + ImGui::Text("Negative Key Codes:"); + + ImGui::SameLine(); + //Button to ask for inputs + if (!negativeKeyListening) + { + if (ImGui::Button(labelConcat("New##negativeKeyCode", entryNumber).c_str())) + { + negativeKeyListening = true; + negativeKeyListeningFor = entryNumber; + } + } + else + { + if (negativeKeyListeningFor == entryNumber) + { + //Listening for inputs + ImGui::Button(labelConcat("Press##negativeKeyCode", entryNumber).c_str()); + + SHInputManager::SH_KEYCODE k; + if (SHInputManager::AnyKey(&k)) + { + negativeKeyListening = false; + SHInputManager::AddBindingNegativeKeyCode(binding.first, k); + } + } + else + { + //Not listening + ImGui::BeginDisabled(); + ImGui::Button(labelConcat("New##negativeKeyCode", entryNumber).c_str()); + ImGui::EndDisabled(); + } + } + + //List and remove bindings + ImGui::Indent(); + keycodeIndex = 0; + for (auto& k : binding.second.negativeKeyCodes) + { + //ImGui::Text("%d", static_cast(k)); + ImGui::Text(SHInputManager::GetKeyCodeName(k).c_str()); + ImGui::SameLine(); + std::string labelString = "X##KeyNegative"; + labelString += binding.first; + + //Delete button + if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str())) + { + SHInputManager::RemoveBindingNegativeKeyCode(binding.first, k); + break; + } + ++keycodeIndex; + } + ImGui::Unindent(); + + //Positive controller codes + ImGui::Separator(); + ImGui::Text("Positive Controller Codes:"); + + ImGui::SameLine(); + //Button to ask for inputs + if (!positiveControllerListening) + { + if (ImGui::Button(labelConcat("New##positiveControllerCode", entryNumber).c_str())) + { + positiveControllerListening = true; + positiveControllerListeningFor = entryNumber; + } + } + else + { + if (positiveControllerListeningFor == entryNumber) + { + //Listening for inputs + ImGui::Button(labelConcat("Press##positiveControllerCode", entryNumber).c_str()); + + SHInputManager::SH_CONTROLLERCODE c; + if (SHInputManager::AnyControllerInput(&c)) + { + positiveControllerListening = false; + SHInputManager::AddBindingPositiveControllerCode(binding.first, c); + } + } + else + { + //Not listening + ImGui::BeginDisabled(); + ImGui::Button(labelConcat("New##positiveControllerCode", entryNumber).c_str()); + ImGui::EndDisabled(); + } + } + + //List and remove bindings + ImGui::Indent(); + keycodeIndex = 0; + for (auto& c : binding.second.positiveControllerCodes) + { + //ImGui::Text("%d", static_cast(k)); + ImGui::Text(SHInputManager::GetControllerCodeName(c).c_str()); + ImGui::SameLine(); + std::string labelString = "X##ControllerPositive"; + labelString += binding.first; + + //Delete button + if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str())) + { + SHInputManager::RemoveBindingPositiveControllerCode(binding.first, c); + break; + } + ++keycodeIndex; + } + ImGui::Unindent(); + + //Negative controller codes + ImGui::Separator(); + ImGui::Text("Negative Controller Codes:"); + + ImGui::SameLine(); + //Button to ask for inputs + if (!negativeControllerListening) + { + if (ImGui::Button(labelConcat("New##negativeControllerCode", entryNumber).c_str())) + { + negativeControllerListening = true; + negativeControllerListeningFor = entryNumber; + } + } + else + { + if (negativeControllerListeningFor == entryNumber) + { + //Listening for inputs + ImGui::Button(labelConcat("Press##negativeControllerCode", entryNumber).c_str()); + + SHInputManager::SH_CONTROLLERCODE c; + if (SHInputManager::AnyControllerInput(&c)) + { + negativeControllerListening = false; + SHInputManager::AddBindingNegativeControllerCode(binding.first, c); + } + } + else + { + //Not listening + ImGui::BeginDisabled(); + ImGui::Button(labelConcat("New##negativeControllerCode", entryNumber).c_str()); + ImGui::EndDisabled(); + } + } + + //List and remove bindings + ImGui::Indent(); + keycodeIndex = 0; + for (auto& c : binding.second.negativeControllerCodes) + { + //ImGui::Text("%d", static_cast(k)); + ImGui::Text(SHInputManager::GetControllerCodeName(c).c_str()); + ImGui::SameLine(); + std::string labelString = "X##ControllerNegative"; + labelString += binding.first; + + //Delete button + if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str())) + { + SHInputManager::RemoveBindingNegativeControllerCode(binding.first, c); + break; + } + ++keycodeIndex; + } + ImGui::Unindent(); + } } - ++entryNumber; //Next entry } } diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 87ea3aa5..2f0ab6d6 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -100,7 +100,7 @@ namespace SHADE } } - std::string SHInputManager::getKeyCodeName(SH_KEYCODE k) noexcept + std::string SHInputManager::GetKeyCodeName(SH_KEYCODE k) noexcept { int kInt = static_cast(k); //Numbers @@ -116,7 +116,7 @@ namespace SHADE //Numpads if (kInt >= static_cast(SH_KEYCODE::NUMPAD_0) && kInt <= static_cast(SH_KEYCODE::NUMPAD_9)) { - return "Keypad " + std::to_string(kInt - 96); + return "Numpad " + std::to_string(kInt - 96); } //Function keys if (kInt >= static_cast(SH_KEYCODE::F1) && kInt <= static_cast(SH_KEYCODE::F24)) @@ -266,22 +266,22 @@ namespace SHADE return "Sleep"; break; case SH_KEYCODE::MULTIPLY: - return "Multiply"; + return "Numpad *"; break; case SH_KEYCODE::ADD: - return "Add"; + return "Numpad +"; break; case SH_KEYCODE::SEPARATOR: return "Separator"; break; case SH_KEYCODE::SUBTRACT: - return "Subtract"; + return "Numpad -"; break; case SH_KEYCODE::DECIMAL: - return "Decimal"; + return "Numpad ."; break; case SH_KEYCODE::DIVIDE: - return "Divide"; + return "Numpad /"; break; case SH_KEYCODE::NUM_LOCK: return "Num Lock"; @@ -380,10 +380,16 @@ namespace SHADE return "; or :"; break; case SH_KEYCODE::OEM_PLUS: - return "+"; + return "= or +"; break; case SH_KEYCODE::OEM_COMMA: - return ","; + return ", or <"; + break; + case SH_KEYCODE::OEM_MINUS: + return "- or _"; + break; + case SH_KEYCODE::OEM_PERIOD: + return ". or >"; break; case SH_KEYCODE::OEM_2: return "/ or ?"; @@ -496,7 +502,7 @@ namespace SHADE } } - std::string SHInputManager::getControllerCodeName(SH_CONTROLLERCODE c) noexcept + std::string SHInputManager::GetControllerCodeName(SH_CONTROLLERCODE c) noexcept { switch (c) { @@ -1143,7 +1149,7 @@ namespace SHADE digitalInput = true; } if (std::abs(newValue) > std::abs(largestMagnitude)) - largestMagnitude = newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0); + largestMagnitude = newValue * (data.inverted ? -1.0 : 1.0); } } @@ -1159,7 +1165,7 @@ namespace SHADE digitalInput = true; } if (std::abs(newValue) > std::abs(largestMagnitude)) - largestMagnitude = -newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0); + largestMagnitude = -newValue * (data.inverted ? -1.0 : 1.0); } } @@ -1203,21 +1209,23 @@ namespace SHADE if (data.value > 1.0) data.value = 1.0; else if (data.value < -1.0) data.value = -1.0; } - //If analog input was in, - //sensitivity is instead used as a multiplier + //If analog input was in, raw value taken else { - data.value = largestMagnitude * data.sensitivity; + data.value = largestMagnitude; if (data.value > 1.0) data.value = 1.0; else if (data.value < -1.0) data.value = -1.0; } if (data.snap) //Snapping { - if (data.value > 0.0 && data.negativeInputHeld) - data.value = 0.0; - if (data.value < 0.0 && data.positiveInputHeld) - data.value = 0.0; + if (digitalInput) //Only for digital inputs + { + if (data.value > 0.0 && data.negativeInputHeld) + data.value = 0.0; + if (data.value < 0.0 && data.positiveInputHeld) + data.value = 0.0; + } } } } @@ -1399,11 +1407,11 @@ namespace SHADE { return 0.0; } - else if (bindings[bindingName].positiveInputHeld) + else if (GetBindingAxis(bindingName, cNum) > 0.0) { return 1.0; } - else if (bindings[bindingName].negativeInputHeld) + else if (GetBindingAxis(bindingName, cNum) < 0.0) { return -1.0; } diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 52322f0c..1bcafa7d 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -363,6 +363,7 @@ namespace SHADE //Speed in units per second that the axis will move toward target value for digital //For mouse movement / scrolling, serves as multiplier + //Irrelevant for other analog inputs double sensitivity = 1.0; //If enabled, axis value will reset to zero when pressing a button @@ -416,10 +417,10 @@ namespace SHADE } //Get the name of key code - static std::string getKeyCodeName(SH_KEYCODE const keyCode) noexcept; + static std::string GetKeyCodeName(SH_KEYCODE const keyCode) noexcept; //Get the name of controller code - static std::string getControllerCodeName(SH_CONTROLLERCODE const controllerCode) noexcept; + static std::string GetControllerCodeName(SH_CONTROLLERCODE const controllerCode) noexcept; //For testing purposes //static void PrintCurrentState() noexcept; @@ -825,7 +826,7 @@ namespace SHADE //Get the sensitivity of the binding //Serves as a multiplier for mouse movement/scrolling //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative - //For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1 + //Irrelevant for other analog inputs static inline double GetBindingSensitivity(std::string const& bindingName) { return bindings[bindingName].sensitivity; @@ -834,7 +835,7 @@ namespace SHADE //Set the sensitivity of the binding //Serves as a multiplier for mouse movement/scrolling //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative - //For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1 + //Irrelevant for other analog inputs static inline void SetBindingSensitivity(std::string const& bindingName, double const newValue) { bindings[bindingName].sensitivity = newValue; @@ -1000,8 +1001,6 @@ namespace SHADE //Get the axis value of binding, between -1 and 1 for non-mouse movement/wheel //For mouse movement/wheel, it won't be between -1 and 1. It will also be multiplied by sensitivity - //To avoid interference between mouse movement/wheel and keyboard/mouse/controller input, - //Set mouseXBound, mouseYBound and mouseScrollBound to false //controllerNumber is not used static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept;