Add support for Wiimotes, Pro Controller and Classic Controller to the menu

This commit is contained in:
Maschell 2022-09-19 17:26:00 +02:00
parent d5850e6b8d
commit e167a2c4d3
3 changed files with 168 additions and 54 deletions

View File

@ -1,5 +1,6 @@
#include "modpackSelector.h"
#include "main.h"
#include "utils/input.h"
#include "version.h"
#include <content_redirection/redirection.h>
#include <coreinit/screen.h>
@ -13,7 +14,6 @@
#include <memory/mappedmemory.h>
#include <string>
#include <utils/logger.h>
#include <vpad/input.h>
#include <wups/storage.h>
#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2))
@ -78,8 +78,12 @@ void HandleMultiModPacks(uint64_t titleID) {
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
VPADStatus vpad_data;
VPADReadError error;
uint32_t buttonsTriggered;
VPADStatus vpad_data{};
VPADReadError vpad_error;
KPADStatus kpad_data{};
KPADError kpad_error;
bool displayAutoSkipOption = modTitlePath.size() == 1;
@ -95,24 +99,42 @@ void HandleMultiModPacks(uint64_t titleID) {
int durationInFrames = 60;
int frameCounter = 0;
KPADInit();
WPADEnableURCC(true);
while (true) {
error = VPAD_READ_NO_SAMPLES;
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &error);
buttonsTriggered = 0;
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error);
if (vpad_error == VPAD_READ_SUCCESS) {
buttonsTriggered = vpad_data.trigger;
}
for (int i = 0; i < 4; i++) {
memset(&kpad_data, 0, sizeof(kpad_data));
if (KPADReadEx((KPADChan) i, &kpad_data, 1, &kpad_error) > 0) {
if (kpad_error == KPAD_ERROR_OK && kpad_data.extensionType != 0xFF) {
if (kpad_data.extensionType == WPAD_EXT_CORE || kpad_data.extensionType == WPAD_EXT_NUNCHUK) {
buttonsTriggered |= remapWiiMoteButtons(kpad_data.trigger);
} else {
buttonsTriggered |= remapClassicButtons(kpad_data.classic.trigger);
}
}
}
}
if (curState == 1) {
if (error == VPAD_READ_SUCCESS) {
if (vpad_data.trigger & VPAD_BUTTON_X) {
if (buttonsTriggered & VPAD_BUTTON_MINUS) {
curState = 0;
continue;
}
}
if (initScreen) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION VERSION_EXTRA);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION_FULL);
console_print_pos(x_offset, 1, "Preparing modpack \"%s\"...", modTitlePath.begin()->first.c_str());
console_print_pos(x_offset, 3, "Press X to open menu");
console_print_pos(x_offset, 3, "Press MINUS to open menu");
// Flip buffers
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
@ -125,15 +147,14 @@ void HandleMultiModPacks(uint64_t titleID) {
frameCounter++;
} else {
if (error == VPAD_READ_SUCCESS) {
if (vpad_data.trigger & VPAD_BUTTON_A) {
if (buttonsTriggered & VPAD_BUTTON_A) {
wantToExit = 1;
initScreen = 1;
} else if (modTitlePath.size() == 1 && (vpad_data.trigger & VPAD_BUTTON_X)) {
} else if (modTitlePath.size() == 1 && (buttonsTriggered & VPAD_BUTTON_MINUS)) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION VERSION_EXTRA);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION_FULL);
console_print_pos(x_offset, 1, "Save settings...");
// Flip buffers
@ -151,37 +172,36 @@ void HandleMultiModPacks(uint64_t titleID) {
}
}
initScreen = 1;
} else if (vpad_data.trigger & VPAD_BUTTON_B) {
} else if (buttonsTriggered & VPAD_BUTTON_B) {
break;
} else if (vpad_data.trigger & VPAD_BUTTON_DOWN) {
} else if (buttonsTriggered & VPAD_BUTTON_DOWN) {
selected++;
initScreen = 1;
} else if (vpad_data.trigger & VPAD_BUTTON_UP) {
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
selected--;
initScreen = 1;
} else if (vpad_data.trigger & VPAD_BUTTON_L) {
} else if (buttonsTriggered & VPAD_BUTTON_L) {
selected -= per_page;
initScreen = 1;
} else if (vpad_data.trigger & VPAD_BUTTON_R) {
} else if (buttonsTriggered & VPAD_BUTTON_R) {
selected += per_page;
initScreen = 1;
}
if (selected < 0) { selected = 0; }
if (selected >= modTitlePath.size()) { selected = modTitlePath.size() - 1; }
page = selected / per_page;
}
if (initScreen) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION VERSION_EXTRA);
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION_FULL);
console_print_pos(x_offset, 1, "Press A to launch a modpack");
console_print_pos(x_offset, 2, "Press B to launch without a modpack");
if (modTitlePath.size() == 1) {
if (gAutoApplySingleModpack) {
console_print_pos(x_offset, 4, "Press X to disable autostart for a single modpack");
console_print_pos(x_offset, 4, "Press MINUS to disable autostart for a single modpack");
} else {
console_print_pos(x_offset, 4, "Press X to enable autostart for a single modpack");
console_print_pos(x_offset, 4, "Press MINUS to enable autostart for a single modpack");
}
}
int y_offset = displayAutoSkipOption ? 6 : 4;
@ -219,6 +239,7 @@ void HandleMultiModPacks(uint64_t titleID) {
}
}
KPADShutdown();
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);

85
src/utils/input.cpp Normal file
View File

@ -0,0 +1,85 @@
#include "input.h"
uint32_t remapWiiMoteButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & WPAD_BUTTON_LEFT)
conv_buttons |= VPAD_BUTTON_LEFT;
if (buttons & WPAD_BUTTON_RIGHT)
conv_buttons |= VPAD_BUTTON_RIGHT;
if (buttons & WPAD_BUTTON_DOWN)
conv_buttons |= VPAD_BUTTON_DOWN;
if (buttons & WPAD_BUTTON_UP)
conv_buttons |= VPAD_BUTTON_UP;
if (buttons & WPAD_BUTTON_PLUS)
conv_buttons |= VPAD_BUTTON_PLUS;
if (buttons & WPAD_BUTTON_B)
conv_buttons |= VPAD_BUTTON_B;
if (buttons & WPAD_BUTTON_A)
conv_buttons |= VPAD_BUTTON_A;
if (buttons & WPAD_BUTTON_MINUS)
conv_buttons |= VPAD_BUTTON_MINUS;
if (buttons & WPAD_BUTTON_HOME)
conv_buttons |= VPAD_BUTTON_HOME;
return conv_buttons;
}
uint32_t remapClassicButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
conv_buttons |= VPAD_BUTTON_LEFT;
if (buttons & WPAD_CLASSIC_BUTTON_RIGHT)
conv_buttons |= VPAD_BUTTON_RIGHT;
if (buttons & WPAD_CLASSIC_BUTTON_DOWN)
conv_buttons |= VPAD_BUTTON_DOWN;
if (buttons & WPAD_CLASSIC_BUTTON_UP)
conv_buttons |= VPAD_BUTTON_UP;
if (buttons & WPAD_CLASSIC_BUTTON_PLUS)
conv_buttons |= VPAD_BUTTON_PLUS;
if (buttons & WPAD_CLASSIC_BUTTON_X)
conv_buttons |= VPAD_BUTTON_X;
if (buttons & WPAD_CLASSIC_BUTTON_Y)
conv_buttons |= VPAD_BUTTON_Y;
if (buttons & WPAD_CLASSIC_BUTTON_B)
conv_buttons |= VPAD_BUTTON_B;
if (buttons & WPAD_CLASSIC_BUTTON_A)
conv_buttons |= VPAD_BUTTON_A;
if (buttons & WPAD_CLASSIC_BUTTON_MINUS)
conv_buttons |= VPAD_BUTTON_MINUS;
if (buttons & WPAD_CLASSIC_BUTTON_HOME)
conv_buttons |= VPAD_BUTTON_HOME;
if (buttons & WPAD_CLASSIC_BUTTON_ZR)
conv_buttons |= VPAD_BUTTON_ZR;
if (buttons & WPAD_CLASSIC_BUTTON_ZL)
conv_buttons |= VPAD_BUTTON_ZL;
if (buttons & WPAD_CLASSIC_BUTTON_R)
conv_buttons |= VPAD_BUTTON_R;
if (buttons & WPAD_CLASSIC_BUTTON_L)
conv_buttons |= VPAD_BUTTON_L;
return conv_buttons;
}

8
src/utils/input.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <cstdint>
#include <padscore/kpad.h>
#include <vpad/input.h>
uint32_t remapWiiMoteButtons(uint32_t buttons);
uint32_t remapClassicButtons(uint32_t buttons);