This commit is contained in:
MelonSpeedruns 2022-05-17 19:16:39 -04:00
commit 12a70386cc
10 changed files with 109 additions and 5 deletions

View file

@ -44,6 +44,11 @@ namespace Ship {
pad->gyro_x = wGyroX;
pad->gyro_y = wGyroY;
pad->touch_x = wTouchX;
pad->touch_y = wTouchY;
pad->touch = wTouching;
}
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {

View file

@ -38,6 +38,9 @@ namespace Ship {
int8_t wStickY;
float wGyroX;
float wGyroY;
bool wTouching;
float wTouchX;
float wTouchY;
virtual std::string GetControllerType() = 0;
virtual std::string GetConfSection() = 0;

View file

@ -114,7 +114,10 @@ typedef struct {
/* 0x04 */ u8 err_no;
/* 0x05 */ f32 gyro_x;
/* 0x09 */ f32 gyro_y;
} OSContPad; // size = 0x0D
/* 0x0A */ u8 touch;
/* 0x0B */ f32 touch_x;
/* 0x0F */ f32 touch_y;
} OSContPad; // size = 0x13
typedef struct {
/* 0x00 */ u8 rumble;

View file

@ -227,6 +227,21 @@ namespace Ship {
wGyroX *= gyro_sensitivity;
wGyroY *= gyro_sensitivity;
int x, y;
Uint32 buttons;
SDL_PumpEvents();
buttons = SDL_GetMouseState(&x, &y);
wTouchX = x;
wTouchY = y;
if ((buttons & SDL_BUTTON_LMASK) != 0) {
wTouching = 1;
}
else {
wTouching = 0;
}
}
for (int32_t i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) {

View file

@ -120,7 +120,10 @@ typedef struct {
/* 0x04 */ uint8_t err_no;
/* 0x05 */ float gyro_x;
/* 0x09 */ float gyro_y;
} OSContPad; // size = 0x0D
/* 0x0A */ uint8_t touch;
/* 0x0B */ float touch_x;
/* 0x0F */ float touch_y;
} OSContPad; // size = 0x13
typedef struct {
/* 0x00 */ uint8_t rumble;

View file

@ -247,6 +247,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
input->cur.button = 0;
input->cur.stick_x = 0;
input->cur.stick_y = 0;
input->cur.touch = 0;
input->cur.err_no = padnow1->err_no;
if (padMgr->ctrlrIsConnected[i]) {
padMgr->ctrlrIsConnected[i] = false;
@ -269,6 +270,11 @@ 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.touch != input->cur.touch;
input->press.touch = (u8)(input->cur.touch && buttonDiff2);
input->rel.touch = (u8)(!input->cur.touch && 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.touch) {
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.touch) {
if (globalCtx->sceneLoadFlag != 20) {
Audio_SetCutsceneFlag(0);

View file

@ -163,6 +163,30 @@ void FileChoose_FinishFadeIn(GameState* thisx) {
}
}
void HandleMouseInput(Input* input) {
if (input->press.touch) {
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;
float pos_x = ((input->cur.touch_x / OTRGetCurrentWidth()) * (240.0f * ratio) - newX);
float 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;
}
/**
* 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 +202,31 @@ 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)) {
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)) {
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)) {
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,

View file

@ -347,6 +347,25 @@ 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)) {
if (this->kbdButton != FS_KBD_BTN_BACKSPACE) {
this->kbdButton = FS_KBD_BTN_BACKSPACE;
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)) {
if (this->kbdY != 5 && this->kbdX != 4) {
this->kbdY = 5;
this->kbdX = 4;
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);