Merge branch 'touch' into free-cam

# Conflicts:
#	libultraship/libultraship/Controller.cpp
#	libultraship/libultraship/Controller.h
#	libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h
#	libultraship/libultraship/UltraController.h
This commit is contained in:
MelonSpeedruns 2022-05-22 10:09:13 -04:00
commit a91bd6acaf
10 changed files with 216 additions and 16 deletions

View file

@ -2,6 +2,7 @@
#include "GlobalCtx2.h"
#include "stox.h"
#include <memory>
#include <SDL2/SDL_events.h>
namespace Ship {
Controller::Controller(int32_t dwControllerNumber) : dwControllerNumber(dwControllerNumber) {
@ -16,6 +17,29 @@ namespace Ship {
void Controller::Read(OSContPad* pad) {
ReadFromSource();
// Mouse Inputs
int x, y;
Uint32 buttons;
SDL_PumpEvents();
buttons = SDL_GetMouseState(&x, &y);
wTouchX = x;
wTouchY = y;
if ((buttons & SDL_BUTTON_LMASK) != 0) {
wLeftClick = 1;
}
else {
wLeftClick = 0;
}
if ((buttons & SDL_BUTTON_RMASK) != 0) {
wRightClick = 1;
}
else {
wRightClick = 0;
}
pad->button |= dwPressedButtons & 0xFFFF;
if (pad->stick_x == 0) {
@ -47,6 +71,11 @@ namespace Ship {
pad->cam_x = wCamX;
pad->cam_y = wCamY;
pad->touch_x = wTouchX;
pad->touch_y = wTouchY;
pad->left_click = wLeftClick;
pad->right_click = wRightClick;
}
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {
@ -96,4 +125,4 @@ namespace Ship {
std::string Controller::GetBindingConfSection() {
return GetControllerType() + " CONTROLLER BINDING " + std::to_string(GetControllerNumber() + 1);
}
}
}

View file

@ -37,8 +37,14 @@ namespace Ship {
int8_t wStickY;
float wGyroX;
float wGyroY;
float wCamX;
float wCamY;
bool wLeftClick;
bool wRightClick;
float wTouchX;
float wTouchY;
float wCamX;
float wCamY;
virtual std::string GetControllerType() = 0;
virtual std::string GetConfSection() = 0;
@ -49,4 +55,4 @@ namespace Ship {
std::shared_ptr<ControllerAttachment> Attachment;
int32_t dwControllerNumber;
};
}
}

View file

@ -114,9 +114,13 @@ typedef struct {
/* 0x04 */ u8 err_no;
/* 0x05 */ f32 gyro_x;
/* 0x09 */ f32 gyro_y;
/* 0x0D */ f32 cam_x;
/* 0x11 */ f32 cam_y;
} OSContPad; // size = 0x0D
/* 0x0A */ u8 left_click;
/* 0x0B */ u8 right_click;
/* 0x0C */ f32 touch_x;
/* 0x10 */ f32 touch_y;
/* 0x14 */ f32 cam_x;
/* 0x18 */ f32 cam_y;
} OSContPad; // size = 0x1C
typedef struct {
/* 0x00 */ u8 rumble;

View file

@ -120,9 +120,13 @@ typedef struct {
/* 0x04 */ uint8_t err_no;
/* 0x05 */ float gyro_x;
/* 0x09 */ float gyro_y;
/* 0x0D */ float cam_x;
/* 0x11 */ float cam_y;
} OSContPad; // size = 0x0D
/* 0x0A */ uint8_t left_click;
/* 0x0B */ uint8_t right_click;
/* 0x0C */ float touch_x;
/* 0x10 */ float touch_y;
/* 0x14 */ float cam_x;
/* 0x18 */ float cam_y;
} OSContPad; // size = 0x1C
typedef struct {
/* 0x00 */ uint8_t rumble;

View file

@ -247,6 +247,8 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
input->cur.button = 0;
input->cur.stick_x = 0;
input->cur.stick_y = 0;
input->cur.left_click = 0;
input->cur.right_click = 0;
input->cur.err_no = padnow1->err_no;
if (padMgr->ctrlrIsConnected[i]) {
padMgr->ctrlrIsConnected[i] = false;
@ -269,6 +271,15 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
PadUtils_UpdateRelXY(input);
input->press.stick_x += (s8)(input->cur.stick_x - input->prev.stick_x);
input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y);
u8 buttonDiff2;
buttonDiff2 = input->prev.left_click != input->cur.left_click;
input->press.left_click = (u8)(input->cur.left_click && buttonDiff2);
input->rel.left_click = (u8)(!input->cur.left_click && buttonDiff2);
buttonDiff2 = input->prev.right_click != input->cur.right_click;
input->press.right_click = (u8)(input->cur.right_click && buttonDiff2);
input->rel.right_click = (u8)(!input->cur.right_click && buttonDiff2);
}
controllerCallback.rumble = CVar_GetS32("gRumbleEnabled", 0) && (padMgr->rumbleEnable[0] > 0);

View file

@ -4,7 +4,7 @@ void TitleSetup_InitImpl(GameState* gameState) {
osSyncPrintf("ゼルダ共通データ初期化\n"); // "Zelda common data initalization"
SaveContext_Init();
gameState->running = false;
SET_NEXT_GAMESTATE(gameState, Title_Init, TitleContext);
SET_NEXT_GAMESTATE(gameState, FileChoose_Init, TitleContext);
}
void TitleSetup_Destroy(GameState* gameState) {

View file

@ -341,7 +341,7 @@ void EnMag_Update(Actor* thisx, GlobalContext* globalCtx) {
if (this->globalState < MAG_STATE_DISPLAY) {
if (CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_START) ||
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_A) ||
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) {
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B) || globalCtx->state.input[0].press.left_click) {
Audio_PlaySoundGeneral(NA_SE_SY_PIECE_OF_HEART, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
@ -367,7 +367,8 @@ void EnMag_Update(Actor* thisx, GlobalContext* globalCtx) {
if (sDelayTimer == 0) {
if (CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_START) ||
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_A) ||
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) {
CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B) ||
globalCtx->state.input[0].press.left_click) {
if (globalCtx->sceneLoadFlag != 20) {
Audio_SetCutsceneFlag(0);

View file

@ -214,6 +214,11 @@ void FileChoose_DrawOptions(GameState* thisx);
void FileChoose_DrawNameEntry(GameState* thisx);
void FileChoose_DrawCharacter(GraphicsContext* gfxCtx, void* texture, s16 vtx);
void HandleMouseInput(Input* input);
u8 HandleMouseCursor(FileChooseContext* this, Input* input, int minx, int miny, int maxx, int maxy);
Vec2f HandleMouseCursorSplit(FileChooseContext* this, Input* input, int minx, int miny, int maxx, int maxy, int countx,
int county);
extern s16 D_808123F0[];
#endif

View file

@ -163,6 +163,70 @@ void FileChoose_FinishFadeIn(GameState* thisx) {
}
}
void HandleMouseInput(Input* input) {
if (input->press.left_click) {
input->press.button = BTN_A;
}
}
u8 HandleMouseCursor(FileChooseContext* this, Input* input, int minx, int miny, int maxx, int maxy) {
float ogratio = 320.0f / 240.0f;
float ratio = (float)OTRGetCurrentWidth() / (float)OTRGetCurrentHeight();
float newX = ((240.0f * ratio) - (240.0f * ogratio)) / 2.0f;
uint32_t pos_x = ((input->cur.touch_x / OTRGetCurrentWidth()) * (240.0f * ratio) - newX);
uint32_t pos_y = (input->cur.touch_y / OTRGetCurrentHeight()) * 240.0f;
if (pos_x >= minx && pos_x <= minx + maxx) {
if (pos_y >= miny && pos_y <= miny + maxy) {
return 1;
}
}
return 0;
}
Vec2f HandleMouseCursorSplit(FileChooseContext* this, Input* input, int minx, int miny, int maxx, int maxy, int countx, int county) {
float ogratio = 320.0f / 240.0f;
float ratio = (float)OTRGetCurrentWidth() / (float)OTRGetCurrentHeight();
float newX = ((240.0f * ratio) - (240.0f * ogratio)) / 2.0f;
uint32_t pos_x = ((input->cur.touch_x / OTRGetCurrentWidth()) * (240.0f * ratio) - newX);
uint32_t pos_y = (input->cur.touch_y / OTRGetCurrentHeight()) * 240.0f;
Vec2f pos;
if (pos_x < minx || pos_x > minx + maxx || pos_y < miny || pos_y > miny + maxy) {
pos.x = -1;
pos.y = -1;
return pos;
}
int pointerx = (pos_x - minx) / 16.3f;
int pointery = (pos_y - miny) / 16.0f;
if (pointerx <= 0) {
pointerx = 0;
}
if (pointery <= 0) {
pointery = 0;
}
if (pointerx >= countx - 1) {
pointerx = countx - 1;
}
if (pointery >= county - 1) {
pointery = county - 1;
}
pos.x = pointerx;
pos.y = pointery;
return pos;
}
/**
* Update the cursor and wait for the player to select a button to change menus accordingly.
* If an empty file is selected, enter the name entry config mode.
@ -178,6 +242,29 @@ void FileChoose_UpdateMainMenu(GameState* thisx) {
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (HandleMouseCursor(this, input, 57, 74, 66, 17) == 1) {
if (this->buttonIndex != FS_BTN_MAIN_FILE_1) {
this->buttonIndex = FS_BTN_MAIN_FILE_1;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
} else if (HandleMouseCursor(this, input, 57, 91, 66, 17) == 1) {
if (this->buttonIndex != FS_BTN_MAIN_FILE_2) {
this->buttonIndex = FS_BTN_MAIN_FILE_2;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
} else if (HandleMouseCursor(this, input, 57, 107, 66, 17) == 1) {
if (this->buttonIndex != FS_BTN_MAIN_FILE_3) {
this->buttonIndex = FS_BTN_MAIN_FILE_3;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
}
if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) {
if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) {
osSyncPrintf("REGCK_ALL[%x]=%x,%x,%x,%x,%x,%x\n", this->buttonIndex,
@ -1318,6 +1405,22 @@ void FileChoose_ConfirmFile(GameState* thisx) {
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (HandleMouseCursor(this, input, 57, 156, 66, 17) == 1) {
if (this->confirmButtonIndex != FS_BTN_CONFIRM_YES) {
this->confirmButtonIndex = FS_BTN_CONFIRM_YES;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
} else if (HandleMouseCursor(this, input, 57, 173, 66, 17) == 1) {
if (this->confirmButtonIndex != FS_BTN_CONFIRM_QUIT) {
this->confirmButtonIndex = FS_BTN_CONFIRM_QUIT;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
}
if (CHECK_BTN_ALL(input->press.button, BTN_START) || (CHECK_BTN_ALL(input->press.button, BTN_A))) {
if (this->confirmButtonIndex == FS_BTN_CONFIRM_YES) {
func_800AA000(300.0f, 180, 20, 100);
@ -1328,7 +1431,7 @@ void FileChoose_ConfirmFile(GameState* thisx) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->selectMode++;
}
} else if (CHECK_BTN_ALL(input->press.button, BTN_B)) {
} else if (CHECK_BTN_ALL(input->press.button, BTN_B) || input->press.right_click) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->selectMode++;
} else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {

View file

@ -347,13 +347,49 @@ void FileChoose_DrawNameEntry(GameState* thisx) {
PRIMITIVE, 0);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255);
if (HandleMouseCursor(this, input, 193, 169, 28, 17) == 1) {
if (this->kbdButton != FS_KBD_BTN_BACKSPACE) {
this->charIndex = 0;
this->kbdX = 3;
this->kbdY = 5;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
}
if (HandleMouseCursor(this, input, 226, 169, 44, 17) == 1) {
if (this->kbdButton != FS_KBD_BTN_END) {
this->charIndex = 0;
this->kbdX = 4;
this->kbdY = 5;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
}
Vec2f namePos = HandleMouseCursorSplit(this, input, 60, 79, 211, 79, 13, 5);
if (namePos.x != -1 && namePos.y != -1) {
int index = namePos.x + (namePos.y * 13);
if (this->charIndex != index) {
this->kbdButton = 99;
this->kbdX = 0;
this->kbdY = 0;
this->charIndex = index;
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
HandleMouseInput(input);
}
if (this->configMode == CM_NAME_ENTRY) {
if (CHECK_BTN_ALL(input->press.button, BTN_START)) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
// place cursor on END button
this->kbdY = 5;
this->kbdX = 4;
} else if (CHECK_BTN_ALL(input->press.button, BTN_B)) {
} else if (CHECK_BTN_ALL(input->press.button, BTN_B) || input->press.right_click) {
if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) {
for (i = this->newFileNameCharCount; i < 7; i++) {
this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1];
@ -397,7 +433,8 @@ void FileChoose_DrawNameEntry(GameState* thisx) {
this->newFileNameCharCount = 7;
}
}
} else if (CHECK_BTN_ALL(input->press.button, BTN_A) && (this->charPage != this->kbdButton)) {
} else if (CHECK_BTN_ALL(input->press.button, BTN_A) &&
(this->charPage != this->kbdButton)) {
if (this->kbdButton == FS_KBD_BTN_BACKSPACE) {
if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) {
for (i = this->newFileNameCharCount; i < 7; i++) {