Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mouse control on menu and title screen feature #406

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions src/goddard/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
#include "config.h"
#include "gfx_dimensions.h"

#ifdef BETTERCAMERA

#include "pc/controller/controller_mouse.h"
#include "pc/configfile.h"

static bool mouseControl = FALSE;
static int oldMouse_x;
static int oldMouse_y;
#endif

#define MAX_GD_DLS 1000
#define OS_MESG_SI_COMPLETE 0x33333333

Expand Down Expand Up @@ -2442,20 +2452,43 @@ void parse_p1_controller(void) {
// deadzone checks?
if (ABS(gdctrl->stickX) >= 6) {
gdctrl->csrX += gdctrl->stickX * 0.1; //? 0.1f
#ifdef BETTERCAMERA
mouseControl = FALSE;
#endif
}

if (ABS(gdctrl->stickY) >= 6) {
gdctrl->csrY -= gdctrl->stickY * 0.1; //? 0.1f
#ifdef BETTERCAMERA
mouseControl = FALSE;
#endif
}
#ifdef BETTERCAMERA


if (mouse_x - oldMouse_x != 0 || mouse_y - oldMouse_y != 0)
mouseControl = true;
if (mouseControl) {
float screenScale = (float) gfx_current_dimensions.height / (float)SCREEN_HEIGHT;
if (configCameraMouse) {
gdctrl->csrX = (mouse_x - (gfx_current_dimensions.width - (screenScale * (float)SCREEN_WIDTH))/ 2)/ screenScale;
gdctrl->csrY = mouse_y / screenScale;
}
}
oldMouse_x = mouse_x;
oldMouse_y = mouse_y;

if (!mouseControl) {
#endif
// border checks? is this for the cursor finger movement?
if ((f32) gdctrl->csrX < (sScreenView2->parent->upperLeft.x + (16.0f/aspect))) {
gdctrl->csrX = (s32)(sScreenView2->parent->upperLeft.x + (16.0f/aspect));
if ((f32) gdctrl->csrX < (sScreenView2->parent->upperLeft.x + (16.0f / aspect))) {
gdctrl->csrX = (s32)(sScreenView2->parent->upperLeft.x + (16.0f / aspect));
}

if ((f32) gdctrl->csrX
> (sScreenView2->parent->upperLeft.x + sScreenView2->parent->lowerRight.x - (48.0/aspect))) {
gdctrl->csrX =
(s32)(sScreenView2->parent->upperLeft.x + sScreenView2->parent->lowerRight.x - (48.0/aspect));
> (sScreenView2->parent->upperLeft.x + sScreenView2->parent->lowerRight.x - (48.0 / aspect))) {
gdctrl->csrX = (s32)(sScreenView2->parent->upperLeft.x + sScreenView2->parent->lowerRight.x
- (48.0 / aspect));
}

if ((f32) gdctrl->csrY < (sScreenView2->parent->upperLeft.y + 16.0f)) {
Expand All @@ -2471,8 +2504,11 @@ void parse_p1_controller(void) {
for (i = 0; i < sizeof(OSContPad); i++) {
((u8 *) p1contPrev)[i] = ((u8 *) p1cont)[i];
}
}

#ifdef BETTERCAMERA
}
#endif
}
/* 251A1C -> 251AC4 */
void Unknown801A324C(f32 arg0) {
return;
Expand Down
75 changes: 60 additions & 15 deletions src/menu/file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#include "sm64.h"
#include "text_strings.h"

#ifdef BETTERCAMERA

#include "pc/controller/controller_mouse.h"
#include "pc/configfile.h"
static bool mouseControl = FALSE;
static int oldMouse_x;
static int oldMouse_y;

#endif

#include "eu_translation.h"
#ifdef VERSION_EU
#undef LANGUAGE_FUNCTION
Expand Down Expand Up @@ -75,7 +85,12 @@ static u8 sYesNoColor[2];
#ifdef VERSION_EU
static s16 sCenteredX;
#endif
struct GfxDimensions {
uint32_t width, height;
float aspect_ratio;
};

extern struct GfxDimensions gfx_current_dimensions;
// The button that is selected when it is clicked.
static s8 sSelectedButtonID = MENU_BUTTON_NONE;

Expand Down Expand Up @@ -133,7 +148,7 @@ static s8 sAllFilesExist = FALSE;

// Defines the value of the save slot selected in the menu.
// Mario A: 1 | Mario B: 2 | Mario C: 3 | Mario D: 4
static s8 sSelectedFileNum = 0;
s8 sSelectedFileNum = 0;

// Which coin score mode to use when scoring files. 0 for local
// coin high score, 1 for high score across all files.
Expand Down Expand Up @@ -1607,34 +1622,64 @@ void handle_controller_cursor_input(void) {
if (rawStickY > -2 && rawStickY < 2) {
rawStickY = 0;
}
#ifdef BETTERCAMERA
else
{
mouseControl = 0;
}
#endif
if (rawStickX > -2 && rawStickX < 2) {
rawStickX = 0;
}
#ifdef BETTERCAMERA
else
{
mouseControl = 0;
}
#endif

// Move cursor
sCursorPos[0] += rawStickX / 8;
sCursorPos[1] += rawStickY / 8;

// Stop cursor from going offscreen
if (sCursorPos[0] > 132.0f) {
sCursorPos[0] = 132.0f;
}
if (sCursorPos[0] < -132.0f) {
sCursorPos[0] = -132.0f;
}
#ifdef BETTERCAMERA
static float screenScale;
screenScale = (float) gfx_current_dimensions.height / SCREEN_HEIGHT;
if (mouse_x - oldMouse_x != 0 || mouse_y - oldMouse_y != 0)
mouseControl = 1;
if (mouseControl && configCameraMouse) {
sCursorPos[0] =
((mouse_x - (gfx_current_dimensions.width - (screenScale * 320)) / 2) / screenScale)
- 160.0f;
sCursorPos[1] = (mouse_y / screenScale - 120.0f) * -1;
}
oldMouse_x = mouse_x;
oldMouse_y = mouse_y;

if (sCursorPos[1] > 90.0f) {
sCursorPos[1] = 90.0f;
}
if (sCursorPos[1] < -90.0f) {
sCursorPos[1] = -90.0f;
}
if (!mouseControl) {
#endif

// Stop cursor from going offscreen
if (sCursorPos[0] > 132.0f) {
sCursorPos[0] = 132.0f;
}
if (sCursorPos[0] < -132.0f) {
sCursorPos[0] = -132.0f;
}

if (sCursorPos[1] > 90.0f) {
sCursorPos[1] = 90.0f;
}
if (sCursorPos[1] < -90.0f) {
sCursorPos[1] = -90.0f;
}
# ifdef BETTERCAMERA
}
#endif
if (sCursorClickingTimer == 0) {
handle_cursor_button_input();
}
}

/**
* Prints the cursor (Mario Hand, different to the one in the Mario screen)
* and loads it's controller inputs in handle_controller_cursor_input
Expand Down
15 changes: 10 additions & 5 deletions src/pc/controller/controller_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "game/level_update.h"


// mouse buttons are also in the controller namespace (why), just offset 0x100
#define VK_OFS_SDL_MOUSE 0x0100
#define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE)
Expand All @@ -33,6 +34,7 @@ int mouse_y;

#ifdef BETTERCAMERA
extern u8 newcam_mouse;
extern s8 sSelectedFileNum;
#endif

static bool init_ok;
Expand Down Expand Up @@ -152,13 +154,16 @@ static void controller_sdl_read(OSContPad *pad) {
}

#ifdef BETTERCAMERA
if (newcam_mouse == 1 && sCurrPlayMode != 2)
u32 mouse;
if (newcam_mouse == 1 && sCurrPlayMode != 2 && sSelectedFileNum !=0){
SDL_SetRelativeMouseMode(SDL_TRUE);
else
mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
}
else{
SDL_SetRelativeMouseMode(SDL_FALSE);

u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);

mouse = SDL_GetMouseState(&mouse_x, &mouse_y);
}
for (u32 i = 0; i < num_mouse_binds; ++i)
if (mouse & SDL_BUTTON(mouse_binds[i][0]))
pad->button |= mouse_binds[i][1];
Expand Down