Qt: Allow changing controller ports. No mouse yet.

This commit is contained in:
BearOso 2024-04-22 15:29:19 -05:00
parent 8077396d39
commit 98cac16b46
6 changed files with 107 additions and 12 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(snes9x-qt VERSION 1.61)
project(snes9x-qt VERSION 1.62)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
@ -102,8 +102,15 @@ list(APPEND INCLUDES ${SDL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
list(APPEND FLAGS ${SDL_COMPILE_FLAGS} ${ZLIB_COMPILE_FLAGS})
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
list(APPEND LIBS opengl32 libSDL2.a libz.a libc++.a)
list(APPEND LIBS gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32 dinput8)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
message("Clang compiler, using libc++.")
list(APPEND LIBS libc++.a)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
message("GNU compiler, using libstdc++.")
list(APPEND LIBS libstdc++.a)
endif()
list(APPEND LIBS libSDL2.a libz.a opengl32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32 dinput8)
list(APPEND DEFINES SDL_MAIN_HANDLED)
list(APPEND PLATFORM_SOURCES
../common/video/wgl_context.cpp

View File

@ -7,8 +7,8 @@
#include <QtEvents>
#include <QTimer>
ControllerPanel::ControllerPanel(EmuApplication *app)
: BindingPanel(app)
ControllerPanel::ControllerPanel(EmuApplication *app_)
: BindingPanel(app_)
{
setupUi(this);
QObject::connect(controllerComboBox, &QComboBox::currentIndexChanged, [&](int index) {
@ -57,6 +57,11 @@ ControllerPanel::ControllerPanel(EmuApplication *app)
recreateAutoAssignMenu();
onJoypadsChanged([&]{ recreateAutoAssignMenu(); });
connect(portComboBox, &QComboBox::currentIndexChanged, [&](int index) {
this->app->config->port_configuration = index;
app->updateBindings();
});
}
void ControllerPanel::recreateAutoAssignMenu()
@ -166,6 +171,7 @@ void ControllerPanel::showEvent(QShowEvent *event)
{
BindingPanel::showEvent(event);
recreateAutoAssignMenu();
portComboBox->setCurrentIndex(app->config->port_configuration);
}
ControllerPanel::~ControllerPanel()

View File

@ -14,6 +14,52 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Controller Ports:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="portComboBox">
<item>
<property name="text">
<string>One Controller</string>
</property>
</item>
<item>
<property name="text">
<string>Two Controllers</string>
</property>
</item>
<item>
<property name="text">
<string>Mouse + Controller</string>
</property>
</item>
<item>
<property name="text">
<string>SuperScope + Controller</string>
</property>
</item>
<item>
<property name="text">
<string>Controller + Multitap</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -58,7 +104,7 @@
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@ -86,7 +132,7 @@
<string>Edit</string>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
<enum>QToolButton::ToolButtonPopupMode::DelayedPopup</enum>
</property>
</widget>
</item>
@ -118,7 +164,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -136,10 +182,10 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This box lists keyboard keys and gamepad buttons mapped to the SNES controller. There are 4 slots, so you can assign 4 different keys or buttons to one SNES button.&lt;/p&gt;&lt;p&gt;To set a binding, click a box or highlight it with the keyboard and press Enter/Return. The box will show three dots &amp;quot;...&amp;quot;. Press the desired key or gamepad button to assign it to that box. The Escape key will clear the box.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::SelectionMode::SingleSelection</enum>
</property>
<attribute name="verticalHeaderCascadingSectionResizes">
<bool>true</bool>

View File

@ -286,6 +286,7 @@ bool EmuConfig::setDefaults(int section)
if (section == -1 || section == 4)
{
// Controllers
port_configuration = 0;
memset(binding.controller, 0, sizeof(binding.controller));
const char *button_list[] = { "Up", "Down", "Left", "Right", "d", "c", "s", "x", "z", "a", "Return", "Space" };
@ -494,6 +495,10 @@ void EmuConfig::config(std::string filename, bool write)
Enum("SoundFilter", sound_filter, { "Gaussian", "Nearest", "Linear", "Cubic", "Sinc" });
EndSection();
BeginSection("Ports");
Enum("PortConfiguration", port_configuration, { "OneController", "TwoControllers", "Mouse", "SuperScope", "Multitap" });
EndSection();
const char *names[] = { "Up", "Down", "Left", "Right", "A", "B", "X", "Y", "L", "R", "Start", "Select", "Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y", "Turbo_L", "Turbo_R" };
for (int c = 0; c < 5; c++)
{

View File

@ -157,6 +157,16 @@ struct EmuConfig
int sram_save_interval;
enum PortConfiguration
{
eOneController = 0,
eTwoControllers,
eMousePlusController,
eSuperScopePlusController,
eControllerPlusMultitap
};
int port_configuration;
static const int allowed_bindings = 4;
static const int num_controller_bindings = 18;
static const int num_shortcuts = 55;

View File

@ -1,4 +1,5 @@
#include "Snes9xController.hpp"
#include "EmuConfig.hpp"
#include "SoftwareScalers.hpp"
#include <memory>
#include <filesystem>
@ -610,8 +611,28 @@ void Snes9xController::updateBindings(const EmuConfig *const config)
S9xUnmapAllControls();
switch (config->port_configuration)
{
case EmuConfig::eTwoControllers:
S9xSetController(0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController(1, CTL_JOYPAD, 1, 1, 1, 1);
break;
case EmuConfig::eMousePlusController:
S9xSetController(0, CTL_MOUSE, 0, 0, 0, 0);
S9xSetController(1, CTL_JOYPAD, 0, 0, 0, 0);
break;
case EmuConfig::eSuperScopePlusController:
S9xSetController(0, CTL_SUPERSCOPE, 0, 0, 0, 0);
S9xSetController(1, CTL_JOYPAD, 0, 0, 0, 0);
break;
case EmuConfig::eControllerPlusMultitap:
S9xSetController(0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController(1, CTL_MP5, 1, 2, 3, 4);
break;
default:
S9xSetController(0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController(1, CTL_NONE, 0, 0, 0, 0);
}
for (int controller_number = 0; controller_number < 5; controller_number++)
{