From bac5c87455d179b46f49436ae1f4fe6c15bdd579 Mon Sep 17 00:00:00 2001 From: vgmoose Date: Fri, 15 Mar 2024 23:57:11 -0400 Subject: [PATCH] add other controller types, bump wii to sdl2 --- Makefile | 2 +- helpers/Makefile.wii | 6 ++--- src/InputEvents.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++-- src/RootDisplay.cpp | 9 ++++--- src/Texture.cpp | 4 +++ 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1cc062e..f65ea48 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ INCLUDES += libs/chesto/libs/resinfs/include endif # for sdl2 platforms (wiiu or pc or switch targets) use sdl font cache -ifeq ($(filter-out wiiu pc switch,$(MAKECMDGOALS)),) +ifeq ($(filter-out wiiu pc wii switch,$(MAKECMDGOALS)),) SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache VPATH += $(CHESTO_DIR)/libs/SDL_FontCache endif diff --git a/helpers/Makefile.wii b/helpers/Makefile.wii index bdca7a4..a7040e2 100644 --- a/helpers/Makefile.wii +++ b/helpers/Makefile.wii @@ -1,10 +1,10 @@ -include $(HELPERS)/Makefile.sdl1 +include $(HELPERS)/Makefile.sdl2 include $(DEVKITPPC)/wii_rules -CFLAGS += -g -O2 -Wall $(MACHDEP) -DUSE_RAMFS -DUSE_FILE32API -DWII -DNETWORK_MOCK +CFLAGS += -g -O2 -Wall $(MACHDEP) -DUSE_RAMFS -DUSE_FILE32API -DWII LDFLAGS += -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -LIBS += -lfat -lwiiuse -lbte -laesnd -logc -lwiikeyboard +LIBS += -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lwiisocket -lmodplug -lopusfile -lopus -lmpg123 -lvorbisidec -logg -lfat -lwiiuse -lbte -laesnd -logc -lwiikeyboard -lharfbuzz -lfreetype -DNETWORK_MOCK BUILD := build_wii LIBDIRS := $(DEVKITPRO)/portlibs/wii $(DEVKITPRO)/portlibs/ppc diff --git a/src/InputEvents.cpp b/src/InputEvents.cpp index 6c61579..6897356 100644 --- a/src/InputEvents.cpp +++ b/src/InputEvents.cpp @@ -1,5 +1,7 @@ #include "InputEvents.hpp" #include "RootDisplay.hpp" +#include +#include int TOTAL_BUTTONS = 18; @@ -7,7 +9,7 @@ int TOTAL_BUTTONS = 18; CST_Keycode key_buttons[] = { SDLK_a, SDLK_b, SDLK_x, SDLK_y, SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, SDLK_RETURN, SDLK_l, SDLK_r, SDLK_z, SDLK_BACKSPACE, SDLK_UP, SDLK_DOWN, SDLK_q }; #ifndef SDL1 -SDL_GameControllerButton pad_buttons[] = { SDL_A, SDL_B, SDL_X, SDL_Y, SDL_UP, SDL_DOWN, SDL_LEFT, SDL_RIGHT, SDL_PLUS, SDL_L, SDL_R, SDL_ZL, SDL_MINUS, SDL_UP_STICK, SDL_DOWN_STICK, SDL_LEFT_STICK, SDL_RIGHT_STICK, SDL_ZR }; +SDL_GameControllerButton pad_buttons[] = { SDL_A, SDL_B, SDL_X, SDL_Y, SDL_UP, SDL_DOWN, SDL_LEFT, SDL_RIGHT, SDL_PLUS, SDL_L, SDL_R, SDL_ZL, SDL_MINUS, SDL_UP_STICK, SDL_DOWN_STICK, SDL_LEFT_STICK, SDL_RIGHT_STICK, SDL_ZR, }; #else int pad_buttons[] = { 1, 2, 3, 4, 0, 0, 0, 0, 8, 5, 6, 5, 7 }; #define SDL_FINGERDOWN SDL_MOUSEBUTTONDOWN @@ -20,11 +22,66 @@ int pad_buttons[] = { 1, 2, 3, 4, 0, 0, 0, 0, 8, 5, 6, 5, 7 }; #endif // our own "buttons" that correspond to the above SDL ones -unsigned int ie_buttons[] = { A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, L_BUTTON, R_BUTTON, ZL_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, ZR_BUTTON }; +unsigned int nintendo_buttons[] = { A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, L_BUTTON, R_BUTTON, ZL_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, ZR_BUTTON }; + +unsigned int* ie_buttons = nintendo_buttons; + +// human readable lowercase names for the buttons (used by the UI) +std::string nintendoButtonNames[] = { "a", "b", "x", "y", "up", "down", "left", "right", "plus", "l", "r", "zl", "minus", "up", "down", "left", "right", "zr" }; + +// human readable lowercase keyboard buttons +std::string keyButtonNames[] = { "a", "b", "x", "y", "up", "down", "left", "right", "return", "l", "r", "z", "backspace", "up", "down", "left", "right", "q" }; + +// wii remote (alone) buttons, a smaller set of actions +// (buttons that aren't available will need to be pressed using IR sensor) +unsigned int wii_buttons[] = { A_BUTTON, B_BUTTON, L_BUTTON, R_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, 0, 0, 0, SELECT_BUTTON, 0, 0, 0, 0, 0 }; + +std::string wiiButtonNames[] = { "a", "b", "1", "2", "up", "down", "left", "right", "plus", "", "", "", "minus", "", "", "", "", "" }; + +// wii remote and nunchuk, separate and more actions (but still not all) available +unsigned int nunchuk_buttons[] = { A_BUTTON, B_BUTTON, L_BUTTON, R_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, START_BUTTON, 0, 0, X_BUTTON, SELECT_BUTTON, UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON, Y_BUTTON }; + +std::string nunchukButtonNames[] = { "a", "b", "1", "2", "up", "down", "left", "right", "plus", "", "", "z", "minus", "up", "down", "left", "right", "c" }; // if true, don't count key inputs (PC/usb keyboard) as button events for us bool InputEvents::bypassKeyEvents = false; +struct GamepadInfo { + unsigned int* buttons; + std::string* names; + std::string prefix; + std::string controller_type; + +public: + GamepadInfo(unsigned int* buttons, std::string* names, std::string prefix, std::string controller_type) + : buttons(buttons), names(names), prefix(prefix), controller_type(controller_type) {} +}; + +// map of controller name to buttons, names, prefix, and controller type +std::map gamepadMap = { + /* Non-controller types, like keyboard */ + { "Keyboard", GamepadInfo(nullptr, keyButtonNames, "keyboard", "key") }, + /* These 5 names are returned by the wiiu SDL2 port */ + { "WiiU Gamepad", GamepadInfo(nintendo_buttons, nintendoButtonNames, "wiiu", "gamepad") }, + { "WiiU Pro Controller", { nintendo_buttons, nintendoButtonNames, "wiiu", "pro" } }, + { "Wii Remote", { wii_buttons, wiiButtonNames, "wii", "remote" } }, + { "Wii Remote and Nunchuk", { nunchuk_buttons, nunchukButtonNames, "wii", "nunchuk" } }, + { "Wii Classic Controller", { nintendo_buttons, nintendoButtonNames, "wii", "classic"} }, + /* The switch SDL2 port only returns this string for all controller types*/ + { "Switch Controller", { nintendo_buttons, nintendoButtonNames, "switch", "pro" } }, + /* For PC platforms, more specific Switch controller types can be recognized */ + // { "Pro Controller", { nintendo_buttons, nintendoButtonNames, "switch" } }, + // { "Joy-Con (L)", { nintendo_buttons, nintendoButtonNames, "switch" } }, + // { "Joy-Con (R)", { nintendo_buttons, nintendoButtonNames, "switch" } }, + // { "Switch Pro Controller", { nintendo_buttons, nintendoButtonNames, "switch" } }, + /* Other controller types */ + // { "Xbox 360 Controller", { xbox_buttons, xboxButtonNames, "xbox" } }, + // { "Xbox One Controller", { xbox_buttons, xboxButtonNames, "xbox" } }, + // { "Xbox Series X Controller", { xbox_buttons, xboxButtonNames, "xbox" } }, + // { "PS4 Controller", { ps_buttons, psButtonNames, "playstation" } }, + // { "PS5 Controller", { ps_buttons, psButtonNames, "playstation" } } +}; + InputEvents::InputEvents() { #if defined(__WIIU__) && defined(USE_KEYBOARD) diff --git a/src/RootDisplay.cpp b/src/RootDisplay.cpp index a010af4..da3319b 100644 --- a/src/RootDisplay.cpp +++ b/src/RootDisplay.cpp @@ -58,6 +58,9 @@ RootDisplay::RootDisplay() // set platform-specific default background colors, (which can be overridden) #if defined(__WIIU__) this->backgroundColor = fromRGB(0x20 - 0x10, 154 - 0x10, 199 - 0x10); +#elif defined(WII) + // the system wii gray + this->backgroundColor = fromRGB(0x8b, 0x8b, 0x8b); #elif defined(_3DS) || defined(_3DS_MOCK) this->backgroundColor = fromRGB(30, 30, 30); #elif defined(SWITCH) @@ -67,12 +70,12 @@ RootDisplay::RootDisplay() #endif // set starting resolution based on SDL version -#ifndef SDL1 - setScreenResolution(1280, 720); +#if defined(WII) + setScreenResolution(640, 480); #elif defined(_3DS) || defined(_3DS_MOCK) setScreenResolution(400, 480); // 3ds has a special resolution! #else - setScreenResolution(840, 640); + setScreenResolution(1280, 720); #endif // the main input handler diff --git a/src/Texture.cpp b/src/Texture.cpp index aad561f..e6045db 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -170,10 +170,14 @@ void Texture::render(Element* parent) CST_RenderCopyRotate(renderer, mTexture, NULL, &rect, this->angle); } else if (useColorMask) { +#ifndef SDL1 // render the texture with a mask color (only can darken the texture) SDL_SetTextureColorMod(mTexture, maskColor.r, maskColor.g, maskColor.b); +#endif CST_RenderCopy(renderer, mTexture, NULL, &rect); +#ifndef SDL1 SDL_SetTextureColorMod(mTexture, 0xFF, 0xFF, 0xFF); +#endif } else { // render the texture normally CST_RenderCopy(renderer, mTexture, NULL, &rect);