enable using mouse on the radial menu

This commit is contained in:
Raf committed 2023-08-28 04:50:26 +08:00
1 parent 66443dd2c2
commit ab17a995a4
4 files changed
+59 -3

No files matched your search

+7
View File
@@ -14,6 +14,9 @@
#define CONT_NUM_BUTTONS 16 // not including the stick axes
#define CURDEV_MNK 0x01
#define CURDEV_CONTR 0x02
enum virtkey {
/* same order as SDL scancodes */
VK_KEYBOARD_BEGIN = 0,
@@ -128,4 +131,8 @@ void inputUpdate(void);
// call this before configSave()
void inputSaveConfig(void);
// returns the current used device (mouse+kb/controller) for the specified player
// TODO: in the future when the input system can differentiate inputs from different players, will need to update this
u8 inputGetCurrentUsedDevice(u8 playerNum);
#endif
+17 -1
View File
@@ -8,6 +8,7 @@
#include "input.h"
#include "video.h"
#include "config.h"
#include "constants.h"
#define MAX_BINDS 4
#define TRIG_THRESHOLD (30 * 256)
@@ -130,6 +131,8 @@ static const char *vkJoyNames[] = {
static char vkNames[VK_TOTAL_COUNT][64];
static u8 currentUsedDevice[MAX_PLAYERS];
void inputSetDefaultKeyBinds(void)
{
// TODO: make VK constants for all these
@@ -479,7 +482,8 @@ static inline s32 inputAxisScale(s32 x, const s32 deadzone, const f32 scale)
if (abs(x) < deadzone) {
return 0;
} else {
// rescale to fit the non-deadzone range
// rescale to fit the non-deadzone range
currentUsedDevice[0] = CURDEV_CONTR;
if (x < 0) {
x += deadzone;
} else {
@@ -503,6 +507,7 @@ s32 inputReadController(s32 idx, OSContPad *npad)
for (u32 i = 0; i < CONT_NUM_BUTTONS; ++i) {
if (inputBindPressed(idx, i)) {
npad->button |= 1U << i;
currentUsedDevice[0] = CURDEV_CONTR;
}
}
@@ -555,14 +560,18 @@ static inline void inputUpdateMouse(void)
if (mouseWheel > 0) {
mouseButtons |= WHEEL_UP_MASK;
currentUsedDevice[0] = CURDEV_MNK;
} else if (mouseWheel < 0) {
mouseButtons |= WHEEL_DN_MASK;
currentUsedDevice[0] = CURDEV_MNK;
}
mouseWheel = 0;
if (mouseLocked) {
SDL_GetRelativeMouseState(&mouseDX, &mouseDY);
if (mouseDX || mouseDY)
currentUsedDevice[0] = CURDEV_MNK;
} else {
mouseDX = mx - mouseX;
mouseDY = my - mouseY;
@@ -651,8 +660,10 @@ s32 inputKeyPressed(u32 vk)
{
if (vk >= VK_KEYBOARD_BEGIN && vk < VK_MOUSE_BEGIN) {
const u8 *state = SDL_GetKeyboardState(NULL);
currentUsedDevice[0] = CURDEV_MNK;
return state[vk - VK_KEYBOARD_BEGIN];
} else if (vk >= VK_MOUSE_BEGIN && vk < VK_JOY_BEGIN) {
currentUsedDevice[0] = CURDEV_MNK;
return mouseButtons & SDL_BUTTON(vk - VK_MOUSE_BEGIN + 1);
} else if (vk >= VK_JOY_BEGIN && vk < VK_TOTAL_COUNT) {
vk -= VK_JOY_BEGIN;
@@ -789,3 +800,8 @@ s32 inputGetKeyByName(const char *name)
return -1;
}
u8 inputGetCurrentUsedDevice(u8 playerNum)
{
return currentUsedDevice[playerNum];
}
+7
View File
@@ -56,6 +56,9 @@ const u8 g_AmMapping[] = {
2, // unused
};
extern f32 menuMX;
extern f32 menuMY;
struct chrdata *currentPlayerGetCommandingAibot(void)
{
return g_Vars.currentplayer->commandingaibot;
@@ -754,6 +757,10 @@ void amOpen(void)
g_AmMenus[g_AmIndex].origscreennum = 0;
g_AmMenus[g_AmIndex].prevallbots = 0;
g_AmMenus[g_AmIndex].allbots = false;
#ifndef PLATFORM_N64
menuMX = menuMY = 0;
#endif
}
}
+28 -2
View File
@@ -12,6 +12,10 @@
#include "lib/str.h"
#include "data.h"
#include "types.h"
#include "input.h"
f32 menuMX;
f32 menuMY;
void amTick(void)
{
@@ -43,8 +47,30 @@ void amTick(void)
for (j = 0; j < numsamples; j++) {
s8 gotonextscreen = false;
s8 cstickx = joyGetStickXOnSample(j, contpadnum);
s8 csticky = joyGetStickYOnSample(j, contpadnum);
s8 cstickx = joyGetStickXOnSample(j, contpadnum);
s8 csticky = joyGetStickYOnSample(j, contpadnum);
#ifndef PLATFORM_N64
if (inputGetCurrentUsedDevice(i) == CURDEV_MNK) {
f32 dx, dy;
inputMouseGetScaledDelta(&dx, &dy);
menuMX += dx;
menuMY += dy;
f32 sc = 8.f;
s8 signx = (menuMX >= 0) ? 1 : -1;
s8 signy = (menuMY >= 0) ? 1 : -1;
s32 lim = 100;
menuMX = fabsf(menuMX * sc) >= lim ? (menuMX - dx) : menuMX;
menuMY = fabsf(menuMY * sc) >= lim ? (menuMY - dy) : menuMY;
cstickx = (s8) (menuMX * sc);
csticky = (s8) -(menuMY * sc);
}
#endif
s8 absstickx;
s8 abssticky;
u16 buttonsstate = joyGetButtonsOnSample(j, contpadnum, 0xffff);