Skip to content

Commit

Permalink
Fix button id conflicts on input editor (#985)
Browse files Browse the repository at this point in the history
* Fix button id conflicts on input editor

* remove id in favor of stick enum
  • Loading branch information
Archez authored Feb 4, 2025
1 parent d60627e commit a36b4aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
57 changes: 30 additions & 27 deletions mm/2s2h/BenGui/BenInputEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,7 @@ void BenInputEditorWindow::DrawStickDirectionLine(const char* axisDirectionName,
DrawStickDirectionLineAddMappingButton(port, stick, direction);
}

void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t id,
ImVec4 color = CHIP_COLOR_N64_GREY) {
void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, ImVec4 color = CHIP_COLOR_N64_GREY) {
static int8_t sX, sY;
std::shared_ptr<Ship::ControllerStick> controllerStick = nullptr;
if (stick == Ship::LEFT) {
Expand All @@ -626,25 +625,29 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
controllerStick = Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetRightStick();
}
controllerStick->Process(sX, sY);
DrawAnalogPreview(StringHelper::Sprintf("##AnalogPreview%d", id).c_str(), ImVec2(sX, sY));
DrawAnalogPreview(StringHelper::Sprintf("##AnalogPreview%d", stick).c_str(), ImVec2(sX, sY));

ImGui::SameLine();
ImGui::BeginGroup();
DrawStickDirectionLine(ICON_FA_ARROW_UP, port, stick, Ship::UP, color);
DrawStickDirectionLine(ICON_FA_ARROW_DOWN, port, stick, Ship::DOWN, color);
DrawStickDirectionLine(ICON_FA_ARROW_LEFT, port, stick, Ship::LEFT, color);
DrawStickDirectionLine(ICON_FA_ARROW_RIGHT, port, stick, Ship::RIGHT, color);
DrawStickDirectionLine(StringHelper::Sprintf("%s##%d", ICON_FA_ARROW_UP, stick).c_str(), port, stick, Ship::UP,
color);
DrawStickDirectionLine(StringHelper::Sprintf("%s##%d", ICON_FA_ARROW_DOWN, stick).c_str(), port, stick, Ship::DOWN,
color);
DrawStickDirectionLine(StringHelper::Sprintf("%s##%d", ICON_FA_ARROW_LEFT, stick).c_str(), port, stick, Ship::LEFT,
color);
DrawStickDirectionLine(StringHelper::Sprintf("%s##%d", ICON_FA_ARROW_RIGHT, stick).c_str(), port, stick,
Ship::RIGHT, color);
ImGui::EndGroup();
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (ImGui::TreeNode(StringHelper::Sprintf("Analog Stick Options##%d", id).c_str())) {
if (ImGui::TreeNode(StringHelper::Sprintf("Analog Stick Options##%d", stick).c_str())) {
ImGui::Text("Sensitivity:");

int32_t sensitivityPercentage = controllerStick->GetSensitivityPercentage();
if (sensitivityPercentage == 0) {
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("-##Sensitivity%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("-##Sensitivity%d", stick).c_str())) {
controllerStick->SetSensitivity(sensitivityPercentage - 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -653,7 +656,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
ImGui::SameLine(0.0f, 0.0f);
ImGui::SetNextItemWidth(SCALE_IMGUI_SIZE(160.0f));
if (ImGui::SliderInt(StringHelper::Sprintf("##Sensitivity%d", id).c_str(), &sensitivityPercentage, 0, 200,
if (ImGui::SliderInt(StringHelper::Sprintf("##Sensitivity%d", stick).c_str(), &sensitivityPercentage, 0, 200,
"%d%%", ImGuiSliderFlags_AlwaysClamp)) {
controllerStick->SetSensitivity(sensitivityPercentage);
}
Expand All @@ -662,7 +665,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("+##Sensitivity%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("+##Sensitivity%d", stick).c_str())) {
controllerStick->SetSensitivity(sensitivityPercentage + 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -671,7 +674,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
if (!controllerStick->SensitivityIsDefault()) {
ImGui::SameLine();
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickSensitivity%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickSensitivity%d", stick).c_str())) {
controllerStick->ResetSensitivityToDefault();
}
}
Expand All @@ -683,7 +686,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("-##Deadzone%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("-##Deadzone%d", stick).c_str())) {
controllerStick->SetDeadzone(deadzonePercentage - 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -692,7 +695,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
ImGui::SameLine(0.0f, 0.0f);
ImGui::SetNextItemWidth(SCALE_IMGUI_SIZE(160.0f));
if (ImGui::SliderInt(StringHelper::Sprintf("##Deadzone%d", id).c_str(), &deadzonePercentage, 0, 100, "%d%%",
if (ImGui::SliderInt(StringHelper::Sprintf("##Deadzone%d", stick).c_str(), &deadzonePercentage, 0, 100, "%d%%",
ImGuiSliderFlags_AlwaysClamp)) {
controllerStick->SetDeadzone(deadzonePercentage);
}
Expand All @@ -701,7 +704,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("+##Deadzone%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("+##Deadzone%d", stick).c_str())) {
controllerStick->SetDeadzone(deadzonePercentage + 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -710,7 +713,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
if (!controllerStick->DeadzoneIsDefault()) {
ImGui::SameLine();
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickDeadzone%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickDeadzone%d", stick).c_str())) {
controllerStick->ResetDeadzoneToDefault();
}
}
Expand All @@ -721,7 +724,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("-##NotchProximityThreshold%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("-##NotchProximityThreshold%d", stick).c_str())) {
controllerStick->SetNotchSnapAngle(notchSnapAngle - 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -730,16 +733,16 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
ImGui::SameLine(0.0f, 0.0f);
ImGui::SetNextItemWidth(SCALE_IMGUI_SIZE(160.0f));
if (ImGui::SliderInt(StringHelper::Sprintf("##NotchProximityThreshold%d", id).c_str(), &notchSnapAngle, 0, 45,
"%d°", ImGuiSliderFlags_AlwaysClamp)) {
if (ImGui::SliderInt(StringHelper::Sprintf("##NotchProximityThreshold%d", stick).c_str(), &notchSnapAngle, 0,
45, "%d°", ImGuiSliderFlags_AlwaysClamp)) {
controllerStick->SetNotchSnapAngle(notchSnapAngle);
}
ImGui::SameLine(0.0f, 0.0f);
if (notchSnapAngle == 45) {
ImGui::BeginDisabled();
}
ImGui::PushButtonRepeat(true);
if (ImGui::Button(StringHelper::Sprintf("+##NotchProximityThreshold%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("+##NotchProximityThreshold%d", stick).c_str())) {
controllerStick->SetNotchSnapAngle(notchSnapAngle + 1);
}
ImGui::PopButtonRepeat();
Expand All @@ -748,7 +751,7 @@ void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t
}
if (!controllerStick->NotchSnapAngleIsDefault()) {
ImGui::SameLine();
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickSnap%d", id).c_str())) {
if (ImGui::Button(StringHelper::Sprintf("Reset to Default###resetStickSnap%d", stick).c_str())) {
controllerStick->ResetNotchSnapAngleToDefault();
}
}
Expand Down Expand Up @@ -1355,18 +1358,18 @@ void BenInputEditorWindow::DrawPortTabContents(uint8_t portIndex) {
}

if (ImGui::CollapsingHeader("D-Pad", NULL, ImGuiTreeNodeFlags_DefaultOpen)) {
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_UP).c_str(), portIndex, BTN_DUP);
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_DOWN).c_str(), portIndex, BTN_DDOWN);
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_LEFT).c_str(), portIndex, BTN_DLEFT);
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_RIGHT).c_str(), portIndex, BTN_DRIGHT);
DrawButtonLine(StringHelper::Sprintf("%s##DPad", ICON_FA_ARROW_UP).c_str(), portIndex, BTN_DUP);
DrawButtonLine(StringHelper::Sprintf("%s##DPad", ICON_FA_ARROW_DOWN).c_str(), portIndex, BTN_DDOWN);
DrawButtonLine(StringHelper::Sprintf("%s##DPad", ICON_FA_ARROW_LEFT).c_str(), portIndex, BTN_DLEFT);
DrawButtonLine(StringHelper::Sprintf("%s##DPad", ICON_FA_ARROW_RIGHT).c_str(), portIndex, BTN_DRIGHT);
}

if (ImGui::CollapsingHeader("Analog Stick", NULL, ImGuiTreeNodeFlags_DefaultOpen)) {
DrawStickSection(portIndex, Ship::LEFT, 0);
DrawStickSection(portIndex, Ship::LEFT);
}

if (ImGui::CollapsingHeader("Additional (\"Right\") Stick")) {
DrawStickSection(portIndex, Ship::RIGHT, 1, CHIP_COLOR_N64_YELLOW);
DrawStickSection(portIndex, Ship::RIGHT, CHIP_COLOR_N64_YELLOW);
}

if (ImGui::CollapsingHeader("Rumble")) {
Expand Down
2 changes: 1 addition & 1 deletion mm/2s2h/BenGui/BenInputEditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BenInputEditorWindow : public Ship::GuiWindow {
void DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction,
std::string id);
void DrawStickDirectionLineAddMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction);
void DrawStickSection(uint8_t port, uint8_t stick, int32_t id, ImVec4 color);
void DrawStickSection(uint8_t port, uint8_t stick, ImVec4 color);

void DrawRumbleSection(uint8_t port);
void DrawRemoveRumbleMappingButton(uint8_t port, std::string id);
Expand Down

0 comments on commit a36b4aa

Please sign in to comment.