Skip to content

Commit

Permalink
block mouse mapping when mouse outside popup
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmanLP committed Dec 24, 2024
1 parent a272e1a commit 07cf287
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 194 deletions.
14 changes: 14 additions & 0 deletions src/controller/controldeck/ControlDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif
#include <imgui.h>
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
#include "window/gui/BaseInputEditor.h"

namespace Ship {

Expand Down Expand Up @@ -94,6 +95,19 @@ bool ControlDeck::MouseGameInputBlocked() {
(window->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID());
}

bool ControlDeck::MouseMappingInputBlocked() {
static std::shared_ptr<BaseInputEditor> inputEditor = nullptr;
if (inputEditor == nullptr) {
inputEditor = std::dynamic_pointer_cast<BaseInputEditor>(
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Custom Input Editor"));
}
if (inputEditor == nullptr) {
inputEditor = std::dynamic_pointer_cast<BaseInputEditor>(
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Input Editor"));
}
return ImGui::IsAnyItemHovered() || inputEditor->IsMouseMappingBlocked();
}

std::shared_ptr<Controller> ControlDeck::GetControllerByPort(uint8_t port) {
return mPorts[port]->GetConnectedController();
}
Expand Down
1 change: 1 addition & 0 deletions src/controller/controldeck/ControlDeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ControlDeck {
bool GamepadGameInputBlocked();
bool KeyboardGameInputBlocked();
bool MouseGameInputBlocked();
bool MouseMappingInputBlocked();
void SetSinglePlayerMappingMode(bool singlePlayer);
bool IsSinglePlayerMappingMode();
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi
mUseInputToCreateNewMapping = true;
if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) {
mapping = std::make_shared<KeyboardKeyToButtonMapping>(mPortIndex, bitmask, mKeyboardScancodeForNewMapping);
} else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() &&
} else if (!Context::GetInstance()->GetControlDeck()->MouseMappingInputBlocked() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
mapping = std::make_shared<MouseButtonToButtonMapping>(mPortIndex, bitmask, mMouseButtonForNewMapping);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct
if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) {
mapping = std::make_shared<KeyboardKeyToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mKeyboardScancodeForNewMapping);
} else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() &&
} else if (!Context::GetInstance()->GetControlDeck()->MouseMappingInputBlocked() &&
mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
mapping = std::make_shared<MouseButtonToAxisDirectionMapping>(mPortIndex, mStickIndex, direction,
mMouseButtonForNewMapping);
Expand Down
8 changes: 8 additions & 0 deletions src/window/gui/BaseInputEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace Ship {
class BaseInputEditor {
public:
virtual bool IsMouseMappingBlocked() = 0;
};
} // namespace Ship
Loading

0 comments on commit 07cf287

Please sign in to comment.