diff --git a/source/input.cpp b/source/input.cpp index 5aa93d4..f168717 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -34,6 +34,7 @@ #define ANALOG_SENSITIVITY 30 int rumbleRequest[4] = {0,0,0,0}; +int playerMapping[4] = {0,1,2,3}; GuiTrigger userInput[4]; #ifdef HW_RVL @@ -965,6 +966,16 @@ bool MenuRequested() return false; } +static int GetPlayerChan(int pad) +{ + for(int i=3; i >= 0; i--) { + if(playerMapping[i] == pad) { + return i; + } + } + return pad; +} + u32 GetJoy(int pad) { // request to go back to menu @@ -975,7 +986,9 @@ u32 GetJoy(int pad) return 0; } - u32 J = DecodeJoy(pad); + int chan = GetPlayerChan(pad); + + u32 J = DecodeJoy(chan); // don't allow up+down or left+right if ((J & 48) == 48) J &= ~16; diff --git a/source/input.h b/source/input.h index b2c1c1b..902bf26 100644 --- a/source/input.h +++ b/source/input.h @@ -33,6 +33,7 @@ #define VBA_CAPTURE 2048 extern int rumbleRequest[4]; +extern int playerMapping[4]; extern u32 btnmap[6][10]; void ResetControls(int wc = -1); diff --git a/source/menu.cpp b/source/menu.cpp index 4794448..1e0da75 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -57,6 +57,9 @@ static GuiTrigger * trigA = NULL; static GuiTrigger * trig2 = NULL; static GuiButton * btnLogo = NULL; +#ifdef HW_RVL +static GuiButton * batteryBtn[4]; +#endif static GuiImageData * gameScreen = NULL; static GuiImage * gameScreenImg = NULL; static GuiImage * bgTopImg = NULL; @@ -1145,6 +1148,95 @@ static int MenuGameSelection() return menu; } +#ifdef HW_RVL +static int playerMappingChan = 0; + +static void PlayerMappingWindowUpdate(void * ptr, int dir) +{ + GuiButton * b = (GuiButton *)ptr; + if(b->GetState() == STATE_CLICKED) + { + playerMapping[playerMappingChan] += dir; + + if(playerMapping[playerMappingChan] > 3) + playerMapping[playerMappingChan] = 0; + if(playerMapping[playerMappingChan] < 0) + playerMapping[playerMappingChan] = 3; + + char playerNumber[20]; + sprintf(playerNumber, "Player %d", playerMapping[playerMappingChan]+1); + + settingText->SetText(playerNumber); + b->ResetState(); + } +} + +static void PlayerMappingWindowLeftClick(void * ptr) { PlayerMappingWindowUpdate(ptr, -1); } +static void PlayerMappingWindowRightClick(void * ptr) { PlayerMappingWindowUpdate(ptr, +1); } + +static void PlayerMappingWindow(int chan) +{ + playerMappingChan = chan; + + GuiWindow * w = new GuiWindow(300,250); + w->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + + GuiTrigger trigLeft; + trigLeft.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT, WIIDRC_BUTTON_LEFT); + + GuiTrigger trigRight; + trigRight.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT, WIIDRC_BUTTON_RIGHT); + + GuiImageData arrowLeft(button_arrow_left_png); + GuiImage arrowLeftImg(&arrowLeft); + GuiImageData arrowLeftOver(button_arrow_left_over_png); + GuiImage arrowLeftOverImg(&arrowLeftOver); + GuiButton arrowLeftBtn(arrowLeft.GetWidth(), arrowLeft.GetHeight()); + arrowLeftBtn.SetImage(&arrowLeftImg); + arrowLeftBtn.SetImageOver(&arrowLeftOverImg); + arrowLeftBtn.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); + arrowLeftBtn.SetTrigger(trigA); + arrowLeftBtn.SetTrigger(trig2); + arrowLeftBtn.SetTrigger(&trigLeft); + arrowLeftBtn.SetSelectable(false); + arrowLeftBtn.SetUpdateCallback(PlayerMappingWindowLeftClick); + + GuiImageData arrowRight(button_arrow_right_png); + GuiImage arrowRightImg(&arrowRight); + GuiImageData arrowRightOver(button_arrow_right_over_png); + GuiImage arrowRightOverImg(&arrowRightOver); + GuiButton arrowRightBtn(arrowRight.GetWidth(), arrowRight.GetHeight()); + arrowRightBtn.SetImage(&arrowRightImg); + arrowRightBtn.SetImageOver(&arrowRightOverImg); + arrowRightBtn.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); + arrowRightBtn.SetTrigger(trigA); + arrowRightBtn.SetTrigger(trig2); + arrowRightBtn.SetTrigger(&trigRight); + arrowRightBtn.SetSelectable(false); + arrowRightBtn.SetUpdateCallback(PlayerMappingWindowRightClick); + + char playerNumber[20]; + sprintf(playerNumber, "Player %d", playerMapping[playerMappingChan]+1); + + settingText = new GuiText(playerNumber, 22, (GXColor){0, 0, 0, 255}); + + w->Append(&arrowLeftBtn); + w->Append(&arrowRightBtn); + w->Append(settingText); + + char title[50]; + sprintf(title, "Player Mapping - Controller %d", chan+1); + + int previousPlayerMapping = playerMapping[playerMappingChan]; + + if(!SettingWindow(title,w)) + playerMapping[playerMappingChan] = previousPlayerMapping; // undo changes + + delete(w); + delete(settingText); +} +#endif + /**************************************************************************** * MenuGame * @@ -1375,8 +1467,11 @@ static int MenuGame() batteryBtn[i]->SetImage(batteryImg[i]); batteryBtn[i]->SetIcon(batteryBarImg[i]); batteryBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - batteryBtn[i]->SetRumble(false); + batteryBtn[i]->SetTrigger(trigA); + batteryBtn[i]->SetSoundOver(&btnSoundOver); + batteryBtn[i]->SetSoundClick(&btnSoundClick); batteryBtn[i]->SetSelectable(false); + batteryBtn[i]->SetState(STATE_DISABLED); batteryBtn[i]->SetAlpha(150); } @@ -1477,6 +1572,7 @@ static int MenuGame() if(newStatus == true) // controller connected { batteryBtn[i]->SetAlpha(255); + batteryBtn[i]->SetState(STATE_DEFAULT); batteryBarImg[i]->SetTile(newLevel); if(newLevel == 0) @@ -1487,6 +1583,7 @@ static int MenuGame() else // controller not connected { batteryBtn[i]->SetAlpha(150); + batteryBtn[i]->SetState(STATE_DISABLED); batteryBarImg[i]->SetTile(0); batteryImg[i]->SetImage(&battery); } @@ -1530,6 +1627,24 @@ static int MenuGame() { menu = MENU_GAMESETTINGS; } +#ifdef HW_RVL + else if(batteryBtn[0]->GetState() == STATE_CLICKED) + { + PlayerMappingWindow(0); + } + else if(batteryBtn[1]->GetState() == STATE_CLICKED) + { + PlayerMappingWindow(1); + } + else if(batteryBtn[2]->GetState() == STATE_CLICKED) + { + PlayerMappingWindow(2); + } + else if(batteryBtn[3]->GetState() == STATE_CLICKED) + { + PlayerMappingWindow(3); + } +#endif else if(mainmenuBtn.GetState() == STATE_CLICKED) { if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))