mirror of https://github.com/mgba-emu/mgba.git
Qt: Ability to prevent opposing directional input
This commit is contained in:
parent
302b041507
commit
8fad1d136c
1
CHANGES
1
CHANGES
|
@ -31,6 +31,7 @@ Features:
|
|||
- Ability to lock aspect ratio
|
||||
- Local link cable support
|
||||
- Ability to switch which game controller is in use per instance
|
||||
- Ability to prevent opposing directional input
|
||||
Bugfixes:
|
||||
- ARM7: Extend prefetch by one stage
|
||||
- GBA Audio: Support 16-bit writes to FIFO audio
|
||||
|
|
|
@ -33,6 +33,7 @@ GameController::GameController(QObject* parent)
|
|||
, m_drawContext(new uint32_t[256 * 256])
|
||||
, m_threadContext()
|
||||
, m_activeKeys(0)
|
||||
, m_inactiveKeys(0)
|
||||
, m_logLevels(0)
|
||||
, m_gameOpen(false)
|
||||
, m_audioThread(new QThread(this))
|
||||
|
@ -390,17 +391,38 @@ void GameController::rewind(int states) {
|
|||
void GameController::keyPressed(int key) {
|
||||
int mappedKey = 1 << key;
|
||||
m_activeKeys |= mappedKey;
|
||||
if (!m_inputController->allowOpposing()) {
|
||||
if ((m_activeKeys & 0x30) == 0x30) {
|
||||
m_inactiveKeys |= mappedKey ^ 0x30;
|
||||
m_activeKeys ^= mappedKey ^ 0x30;
|
||||
}
|
||||
if ((m_activeKeys & 0xC0) == 0xC0) {
|
||||
m_inactiveKeys |= mappedKey ^ 0xC0;
|
||||
m_activeKeys ^= mappedKey ^ 0xC0;
|
||||
}
|
||||
}
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
void GameController::keyReleased(int key) {
|
||||
int mappedKey = 1 << key;
|
||||
m_activeKeys &= ~mappedKey;
|
||||
if (!m_inputController->allowOpposing()) {
|
||||
if (mappedKey & 0x30) {
|
||||
m_activeKeys |= m_inactiveKeys & (0x30 ^ mappedKey);
|
||||
m_inactiveKeys &= ~0x30;
|
||||
}
|
||||
if (mappedKey & 0xC0) {
|
||||
m_activeKeys |= m_inactiveKeys & (0xC0 ^ mappedKey);
|
||||
m_inactiveKeys &= ~0xC0;
|
||||
}
|
||||
}
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
void GameController::clearKeys() {
|
||||
m_activeKeys = 0;
|
||||
m_inactiveKeys = 0;
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
|
@ -549,6 +571,7 @@ void GameController::updateKeys() {
|
|||
#ifdef BUILD_SDL
|
||||
activeKeys |= m_activeButtons;
|
||||
#endif
|
||||
activeKeys &= ~m_inactiveKeys;
|
||||
m_threadContext.activeKeys = activeKeys;
|
||||
}
|
||||
|
||||
|
|
|
@ -152,6 +152,7 @@ private:
|
|||
GBAVideoSoftwareRenderer* m_renderer;
|
||||
GBACheatDevice m_cheatDevice;
|
||||
int m_activeKeys;
|
||||
int m_inactiveKeys;
|
||||
int m_logLevels;
|
||||
|
||||
bool m_gameOpen;
|
||||
|
|
|
@ -28,6 +28,7 @@ InputController::InputController(int playerId, QObject* parent)
|
|||
, m_config(nullptr)
|
||||
, m_gamepadTimer(nullptr)
|
||||
, m_playerAttached(false)
|
||||
, m_allowOpposing(false)
|
||||
{
|
||||
GBAInputMapInit(&m_inputMap);
|
||||
|
||||
|
@ -70,6 +71,7 @@ InputController::~InputController() {
|
|||
|
||||
void InputController::setConfiguration(ConfigController* config) {
|
||||
m_config = config;
|
||||
setAllowOpposing(config->getOption("allowOpposingDirections").toInt());
|
||||
loadConfiguration(KEYBOARD);
|
||||
#ifdef BUILD_SDL
|
||||
GBASDLEventsLoadConfig(&s_sdlEvents, config->input());
|
||||
|
|
|
@ -41,6 +41,9 @@ public:
|
|||
void saveProfile(uint32_t type, const QString& profile);
|
||||
const char* profileForType(uint32_t type);
|
||||
|
||||
bool allowOpposing() const { return m_allowOpposing; }
|
||||
void setAllowOpposing(bool allowOpposing) { m_allowOpposing = allowOpposing; }
|
||||
|
||||
GBAKey mapKeyboard(int key) const;
|
||||
|
||||
void bindKey(uint32_t type, int key, GBAKey);
|
||||
|
@ -73,6 +76,7 @@ private:
|
|||
GBAInputMap m_inputMap;
|
||||
ConfigController* m_config;
|
||||
int m_playerId;
|
||||
bool m_allowOpposing;
|
||||
|
||||
#ifdef BUILD_SDL
|
||||
static int s_sdlInited;
|
||||
|
|
|
@ -31,6 +31,7 @@ SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
|
|||
loadSetting("rewindBufferInterval", m_ui.rewindInterval);
|
||||
loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
|
||||
loadSetting("resampleVideo", m_ui.resampleVideo);
|
||||
loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
|
||||
|
||||
QString idleOptimization = loadSetting("idleOptimization");
|
||||
if (idleOptimization == "ignore") {
|
||||
|
@ -81,6 +82,7 @@ void SettingsView::updateConfig() {
|
|||
saveSetting("rewindBufferInterval", m_ui.rewindInterval);
|
||||
saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
|
||||
saveSetting("resampleVideo", m_ui.resampleVideo);
|
||||
saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
|
||||
|
||||
switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
|
||||
case IDLE_LOOP_IGNORE:
|
||||
|
@ -130,7 +132,7 @@ void SettingsView::saveSetting(const char* key, const QString& field) {
|
|||
|
||||
void SettingsView::loadSetting(const char* key, QAbstractButton* field) {
|
||||
QString option = loadSetting(key);
|
||||
field->setChecked(option != "0");
|
||||
field->setChecked(!option.isNull() && option != "0");
|
||||
}
|
||||
|
||||
void SettingsView::loadSetting(const char* key, QComboBox* field) {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>355</width>
|
||||
<height>501</height>
|
||||
<width>360</width>
|
||||
<height>569</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -198,6 +198,34 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>FPS target:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="fpsTarget">
|
||||
<property name="maximum">
|
||||
<number>240</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>60</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>frames per second</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="9" column="0" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
|
@ -282,35 +310,21 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>FPS target:</string>
|
||||
<item row="17" column="0" colspan="2">
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="fpsTarget">
|
||||
<property name="maximum">
|
||||
<number>240</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>60</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>frames per second</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<item row="18" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Idle loops</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="1">
|
||||
<item row="18" column="1">
|
||||
<widget class="QComboBox" name="idleOptimization">
|
||||
<item>
|
||||
<property name="text">
|
||||
|
@ -329,17 +343,10 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="0" colspan="2">
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<item row="16" column="1">
|
||||
<widget class="QCheckBox" name="allowOpposingDirections">
|
||||
<property name="text">
|
||||
<string>Idle loops</string>
|
||||
<string>Allow opposing input directions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -789,6 +789,11 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), m_config->getOption("rewindBufferCapacity").toInt(), value.toInt());
|
||||
}, this);
|
||||
|
||||
ConfigOption* allowOpposingDirections = m_config->addOption("allowOpposingDirections");
|
||||
allowOpposingDirections->connect([this](const QVariant& value) {
|
||||
m_inputController.setAllowOpposing(value.toBool());
|
||||
}, this);
|
||||
|
||||
QMenu* other = new QMenu(tr("Other"), this);
|
||||
m_shortcutController->addMenu(other);
|
||||
m_shortcutController->addFunctions(other, [this]() {
|
||||
|
|
Loading…
Reference in New Issue