Implemented Input Binding Panel via Editor #318

Merged
mushgunAX merged 8 commits from SP3-10-input-management into main 2023-01-30 15:00:58 +08:00
3 changed files with 216 additions and 28 deletions
Showing only changes of commit dddb556553 - Show all commits

View File

@ -5,6 +5,9 @@
namespace SHADE
{
static std::vector<std::string> bindingRenames;
static std::vector<bool> positiveKeyListening;
//Internal Helper function
std::string labelConcat(char const* label, size_t entryNumber)
{
@ -30,6 +33,9 @@ namespace SHADE
{
std::string newBindingName = "Binding" + std::to_string(SHInputManager::CountBindings());
SHInputManager::AddBinding(newBindingName);
bindingRenames.resize(SHInputManager::CountBindings());
for (auto& s : bindingRenames)
s.clear();
}
if (ImGui::IsItemHovered())
{
@ -45,29 +51,28 @@ namespace SHADE
for (auto& binding : SHInputManager::GetBindings())
{
ImGui::Separator();
std::string bindingName = binding.first; //Binding name to use as argument when modifying binding values
ImGui::Text("Entry Number %d", entryNumber);
//Non-modifiable binding name
ImGui::Text("Binding Name: %s", binding.first);
std::string bindingModifiedName;
//MAKE THE INPUTTEXT WORK
ImGui::InputText(labelConcat("##bindingModifyName", entryNumber).c_str(), &bindingModifiedName);
ImGui::InputText(labelConcat("##bindingModifyName", entryNumber).c_str(), &bindingRenames[entryNumber]);
ImGui::SameLine();
if (ImGui::Button(labelConcat("Rename##bindingRename", entryNumber).c_str()))
{
SHLOGV_CRITICAL("\"{0}\" > \"{1}\"", bindingName, bindingModifiedName);
SHInputManager::RenameBinding(bindingName, bindingModifiedName);
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(bindingName.begin(),
bindingName.length() >= maxLen ?
bindingName.begin() + maxLen :
bindingName.end(), //Does not take into account null terminator
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[bindingName.length()] = '\0'; //Null terminator
bindingNameCStr[binding.first.length()] = '\0'; //Null terminator
//First character
char firstChar = bindingNameCStr[0];
@ -78,8 +83,8 @@ namespace SHADE
if (std::strlen(bindingNameCStr) < 1)
bindingNameCStr[0] = firstChar;
//Rename binding in the input manager
SHInputManager::RenameBinding(bindingName, std::string{ bindingNameCStr });
bindingName = std::string{ bindingNameCStr };
SHInputManager::RenameBinding(binding.first, std::string{ bindingNameCStr });
binding.first = std::string{ bindingNameCStr };
}
if (ImGui::IsItemHovered())
{
@ -92,11 +97,10 @@ namespace SHADE
//TODO
ImGui::Text("Value");
//Binding Type Combo Box
int bindingType = static_cast<int>(SHInputManager::GetBindingType(bindingName));
int bindingType = static_cast<int>(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(bindingName, static_cast<SHInputManager::SH_BINDINGTYPE>(bindingType));
SHInputManager::SetBindingType(binding.first, static_cast<SHInputManager::SH_BINDINGTYPE>(bindingType));
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@ -109,9 +113,9 @@ namespace SHADE
}
//Inversion
bool bindingInvert = SHInputManager::GetBindingInverted(bindingName);
bool bindingInvert = SHInputManager::GetBindingInverted(binding.first);
if (ImGui::Checkbox(labelConcat("Inverted##", entryNumber).c_str(), &bindingInvert))
SHInputManager::SetBindingInverted(bindingName, bindingInvert);
SHInputManager::SetBindingInverted(binding.first, bindingInvert);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@ -124,9 +128,9 @@ namespace SHADE
}
//Sensitivity
double bindingSensitivity = SHInputManager::GetBindingSensitivity(bindingName);
double bindingSensitivity = SHInputManager::GetBindingSensitivity(binding.first);
if (ImGui::InputDouble(labelConcat("Sensitivity##", entryNumber).c_str(), &bindingSensitivity))
SHInputManager::SetBindingSensitivity(bindingName, bindingSensitivity);
SHInputManager::SetBindingSensitivity(binding.first, bindingSensitivity);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@ -138,12 +142,12 @@ namespace SHADE
//Below this section is only for KB/M type bindings
//Not relevant for mouse movement and scrolling
if (SHInputManager::GetBindingType(bindingName) == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER)
if (SHInputManager::GetBindingType(binding.first) == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER)
{
//Dead
float bindingDead = static_cast<float>(SHInputManager::GetBindingDead(bindingName));
float bindingDead = static_cast<float>(SHInputManager::GetBindingDead(binding.first));
if (ImGui::SliderFloat(labelConcat("Deadzone##", entryNumber).c_str(), &bindingDead, 0.0f, 1.0f))
SHInputManager::SetBindingDead(bindingName, static_cast<double>(bindingDead));
SHInputManager::SetBindingDead(binding.first, static_cast<double>(bindingDead));
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@ -152,9 +156,9 @@ namespace SHADE
}
//Gravity
double bindingGravity = SHInputManager::GetBindingGravity(bindingName);
double bindingGravity = SHInputManager::GetBindingGravity(binding.first);
if (ImGui::InputDouble(labelConcat("Gravity##", entryNumber).c_str(), &bindingGravity))
SHInputManager::SetBindingGravity(bindingName, static_cast<double>(bindingGravity));
SHInputManager::SetBindingGravity(binding.first, static_cast<double>(bindingGravity));
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@ -164,9 +168,9 @@ namespace SHADE
}
//Snap
bool bindingSnap = SHInputManager::GetBindingSnap(bindingName);
bool bindingSnap = SHInputManager::GetBindingSnap(binding.first);
if (ImGui::Checkbox(labelConcat("Snap##", entryNumber).c_str(), &bindingSnap))
SHInputManager::SetBindingSnap(bindingName, bindingSnap);
SHInputManager::SetBindingSnap(binding.first, bindingSnap);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();

View File

@ -100,6 +100,187 @@ namespace SHADE
}
}
std::string SHInputManager::getKeycodeName(SH_KEYCODE k) noexcept
{
int kInt = static_cast<int>(k);
//Numbers
if (kInt >= static_cast<int>(SH_KEYCODE::NUMBER_0) && kInt <= static_cast<int>(SH_KEYCODE::NUMBER_9))
{
return std::to_string(kInt - 48);
}
//Letters
if (kInt >= static_cast<int>(SH_KEYCODE::A) && kInt <= static_cast<int>(SH_KEYCODE::Z))
{
return std::string(1, static_cast<char>(kInt));
}
//Numpads
if (kInt >= static_cast<int>(SH_KEYCODE::NUMPAD_0) && kInt <= static_cast<int>(SH_KEYCODE::NUMPAD_9))
{
return "Keypad " + std::to_string(kInt - 96);
}
//Other keys
switch (k)
{
case SH_KEYCODE::LMB:
return "Left Mouse Button";
break;
case SH_KEYCODE::RMB:
return "Right Mouse Button";
break;
case SH_KEYCODE::CANCEL:
return "Cancel";
break;
case SH_KEYCODE::MMB:
return "Middle Mouse Button";
break;
case SH_KEYCODE::XMB1:
return "X1 Mouse Button";
break;
case SH_KEYCODE::XMB2:
return "X2 Mouse Button";
break;
case SH_KEYCODE::BACKSPACE:
return "Backspace";
break;
case SH_KEYCODE::TAB:
return "Tab";
break;
case SH_KEYCODE::CLEAR:
return "Clear";
break;
case SH_KEYCODE::ENTER:
return "Enter";
break;
case SH_KEYCODE::SHIFT:
return "Shift";
break;
case SH_KEYCODE::CTRL:
return "Ctrl";
break;
case SH_KEYCODE::ALT:
return "Alt";
break;
case SH_KEYCODE::PAUSE:
return "Pause";
break;
case SH_KEYCODE::CAPS_LOCK:
return "Caps Lock";
break;
case SH_KEYCODE::IME_KANA:
return "IME Kana / Hangul Mode";
break;
case SH_KEYCODE::IME_ON:
return "IME On";
break;
case SH_KEYCODE::IME_JUNJA:
return "IME Junja Mode";
break;
case SH_KEYCODE::IME_FINAL:
return "IME Final Mode";
break;
case SH_KEYCODE::IME_HANJA:
return "IME Kanji / Hanja Mode";
break;
case SH_KEYCODE::IME_OFF:
return "IME Off";
break;
case SH_KEYCODE::ESCAPE:
return "Esc";
break;
case SH_KEYCODE::IME_CONVERT:
return "IME Convert";
break;
case SH_KEYCODE::IME_NONCONVERT:
return "IME Nonconvert";
break;
case SH_KEYCODE::IME_ACCEPT:
return "IME Accept";
break;
case SH_KEYCODE::IME_MODECHANGE:
return "IME Mode Change Request";
break;
case SH_KEYCODE::SPACE:
return "Spacebar";
break;
case SH_KEYCODE::PAGE_UP:
return "Page Up";
break;
case SH_KEYCODE::PAGE_DOWN:
return "Page Down";
break;
case SH_KEYCODE::END:
return "End";
break;
case SH_KEYCODE::HOME:
return "Home";
break;
case SH_KEYCODE::LEFT_ARROW:
return "Left Arrow";
break;
case SH_KEYCODE::UP_ARROW:
return "Up Arrow";
break;
case SH_KEYCODE::RIGHT_ARROW:
return "Right Arrow";
break;
case SH_KEYCODE::DOWN_ARROW:
return "Down Arrow";
break;
case SH_KEYCODE::SELECT:
return "Select";
break;
case SH_KEYCODE::PRINT:
return "Print";
break;
case SH_KEYCODE::EXECUTE:
return "Execute";
break;
case SH_KEYCODE::PRINT_SCREEN:
return "Print Screen";
break;
case SH_KEYCODE::INSERT:
return "Insert";
break;
case SH_KEYCODE::DEL:
return "Delete";
break;
case SH_KEYCODE::HELP:
return "Help";
break;
case SH_KEYCODE::NUMBER_0:
return "0";
break;
case SH_KEYCODE::NUMBER_1:
return "1";
break;
case SH_KEYCODE::NUMBER_2:
return "2";
break;
case SH_KEYCODE::NUMBER_3:
return "3";
break;
case SH_KEYCODE::NUMBER_4:
return "4";
break;
case SH_KEYCODE::NUMBER_5:
return "5";
break;
case SH_KEYCODE::NUMBER_6:
return "6";
break;
case SH_KEYCODE::NUMBER_7:
return "7";
break;
case SH_KEYCODE::NUMBER_8:
return "8";
break;
case SH_KEYCODE::NUMBER_9:
return "9";
break;
}
}
//The Binding File format presently goes as such:
/*
* Binding count

View File

@ -415,6 +415,9 @@ namespace SHADE
return controllerInUse;
}
//Get the name of keycode
static std::string getKeycodeName(SH_KEYCODE const keycode) noexcept;
//For testing purposes
//static void PrintCurrentState() noexcept;