mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-30 22:44:22 +01:00
add ability to change the player mapped to a connected controller
This commit is contained in:
parent
5df5747c54
commit
0e03e6c96a
@ -44,6 +44,7 @@
|
|||||||
#define ANALOG_SENSITIVITY 30
|
#define ANALOG_SENSITIVITY 30
|
||||||
|
|
||||||
int rumbleRequest[4] = {0,0,0,0};
|
int rumbleRequest[4] = {0,0,0,0};
|
||||||
|
int playerMapping[4] = {0,1,2,3};
|
||||||
GuiTrigger userInput[4];
|
GuiTrigger userInput[4];
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
@ -517,7 +518,7 @@ static void UpdateCursorPosition (int chan, int &pos_x, int &pos_y)
|
|||||||
* Reads the changes (buttons pressed, etc) from a controller and reports
|
* Reads the changes (buttons pressed, etc) from a controller and reports
|
||||||
* these changes to Snes9x
|
* these changes to Snes9x
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void decodepad (int chan)
|
static void decodepad (int chan, int emuChan)
|
||||||
{
|
{
|
||||||
int i, offset;
|
int i, offset;
|
||||||
|
|
||||||
@ -587,7 +588,7 @@ static void decodepad (int chan)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** Fix offset to pad ***/
|
/*** Fix offset to pad ***/
|
||||||
offset = ((chan + 1) << 4);
|
offset = ((emuChan + 1) << 4);
|
||||||
|
|
||||||
/*** Report pressed buttons (gamepads) ***/
|
/*** Report pressed buttons (gamepads) ***/
|
||||||
for (i = 0; i < MAXJP; i++)
|
for (i = 0; i < MAXJP; i++)
|
||||||
@ -607,7 +608,7 @@ static void decodepad (int chan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*** Superscope ***/
|
/*** Superscope ***/
|
||||||
if (Settings.SuperScopeMaster && chan == 0) // report only once
|
if (Settings.SuperScopeMaster && emuChan == 0) // report only once
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
offset = 0x50;
|
offset = 0x50;
|
||||||
@ -643,14 +644,14 @@ static void decodepad (int chan)
|
|||||||
}
|
}
|
||||||
// pointer
|
// pointer
|
||||||
offset = 0x80;
|
offset = 0x80;
|
||||||
UpdateCursorPosition(chan, cursor_x[0], cursor_y[0]);
|
UpdateCursorPosition(emuChan, cursor_x[0], cursor_y[0]);
|
||||||
S9xReportPointer(offset, (u16) cursor_x[0], (u16) cursor_y[0]);
|
S9xReportPointer(offset, (u16) cursor_x[0], (u16) cursor_y[0]);
|
||||||
}
|
}
|
||||||
/*** Mouse ***/
|
/*** Mouse ***/
|
||||||
else if (Settings.MouseMaster && chan == 0)
|
else if (Settings.MouseMaster && emuChan == 0)
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
offset = 0x60 + (2 * chan);
|
offset = 0x60 + (2 * emuChan);
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
if (jp & btnmap[CTRL_MOUSE][CTRLR_GCPAD][i]
|
if (jp & btnmap[CTRL_MOUSE][CTRLR_GCPAD][i]
|
||||||
@ -667,15 +668,15 @@ static void decodepad (int chan)
|
|||||||
}
|
}
|
||||||
// pointer
|
// pointer
|
||||||
offset = 0x81;
|
offset = 0x81;
|
||||||
UpdateCursorPosition(chan, cursor_x[1 + chan], cursor_y[1 + chan]);
|
UpdateCursorPosition(emuChan, cursor_x[1 + emuChan], cursor_y[1 + emuChan]);
|
||||||
S9xReportPointer(offset + chan, (u16) cursor_x[1 + chan],
|
S9xReportPointer(offset + emuChan, (u16) cursor_x[1 + emuChan],
|
||||||
(u16) cursor_y[1 + chan]);
|
(u16) cursor_y[1 + emuChan]);
|
||||||
}
|
}
|
||||||
/*** Justifier ***/
|
/*** Justifier ***/
|
||||||
else if (Settings.JustifierMaster && chan < 2)
|
else if (Settings.JustifierMaster && emuChan < 2)
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
offset = 0x70 + (3 * chan);
|
offset = 0x70 + (3 * emuChan);
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
if (jp & btnmap[CTRL_JUST][CTRLR_GCPAD][i]
|
if (jp & btnmap[CTRL_JUST][CTRLR_GCPAD][i]
|
||||||
@ -692,9 +693,9 @@ static void decodepad (int chan)
|
|||||||
}
|
}
|
||||||
// pointer
|
// pointer
|
||||||
offset = 0x83;
|
offset = 0x83;
|
||||||
UpdateCursorPosition(chan, cursor_x[3 + chan], cursor_y[3 + chan]);
|
UpdateCursorPosition(emuChan, cursor_x[3 + emuChan], cursor_y[3 + emuChan]);
|
||||||
S9xReportPointer(offset + chan, (u16) cursor_x[3 + chan],
|
S9xReportPointer(offset + emuChan, (u16) cursor_x[3 + emuChan],
|
||||||
(u16) cursor_y[3 + chan]);
|
(u16) cursor_y[3 + emuChan]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
@ -736,7 +737,7 @@ bool MenuRequested()
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void ReportButtons ()
|
void ReportButtons ()
|
||||||
{
|
{
|
||||||
int i, j;
|
int i;
|
||||||
|
|
||||||
UpdatePads();
|
UpdatePads();
|
||||||
|
|
||||||
@ -762,10 +763,13 @@ void ReportButtons ()
|
|||||||
if(MenuRequested())
|
if(MenuRequested())
|
||||||
ScreenshotRequested = 1; // go to the menu
|
ScreenshotRequested = 1; // go to the menu
|
||||||
|
|
||||||
j = (Settings.MultiPlayer5Master == true ? 4 : 2);
|
int numControllers = (Settings.MultiPlayer5Master == true ? 4 : 2);
|
||||||
|
|
||||||
for (i = 0; i < j; i++)
|
for (i = 0; i < 4; i++) {
|
||||||
decodepad (i);
|
if(playerMapping[i] < numControllers) {
|
||||||
|
decodepad (i, playerMapping[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetControllers()
|
void SetControllers()
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
extern u32 btnmap[4][6][12];
|
extern u32 btnmap[4][6][12];
|
||||||
extern int rumbleRequest[4];
|
extern int rumbleRequest[4];
|
||||||
|
extern int playerMapping[4];
|
||||||
|
|
||||||
void ResetControls(int cc = -1, int wc = -1);
|
void ResetControls(int cc = -1, int wc = -1);
|
||||||
void ShutoffRumble();
|
void ShutoffRumble();
|
||||||
|
120
source/menu.cpp
120
source/menu.cpp
@ -68,6 +68,9 @@ static GuiTrigger * trigA = NULL;
|
|||||||
static GuiTrigger * trig2 = NULL;
|
static GuiTrigger * trig2 = NULL;
|
||||||
|
|
||||||
static GuiButton * btnLogo = NULL;
|
static GuiButton * btnLogo = NULL;
|
||||||
|
#ifdef HW_RVL
|
||||||
|
static GuiButton * batteryBtn[4];
|
||||||
|
#endif
|
||||||
static GuiImageData * gameScreen = NULL;
|
static GuiImageData * gameScreen = NULL;
|
||||||
static GuiImage * gameScreenImg = NULL;
|
static GuiImage * gameScreenImg = NULL;
|
||||||
static GuiImage * bgTopImg = NULL;
|
static GuiImage * bgTopImg = NULL;
|
||||||
@ -1256,6 +1259,97 @@ static void ControllerWindow()
|
|||||||
delete(settingText);
|
delete(settingText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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});
|
||||||
|
|
||||||
|
int currentController = GCSettings.Controller;
|
||||||
|
|
||||||
|
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
|
* MenuGame
|
||||||
*
|
*
|
||||||
@ -1420,7 +1514,6 @@ static int MenuGame()
|
|||||||
GuiText * batteryTxt[4];
|
GuiText * batteryTxt[4];
|
||||||
GuiImage * batteryImg[4];
|
GuiImage * batteryImg[4];
|
||||||
GuiImage * batteryBarImg[4];
|
GuiImage * batteryBarImg[4];
|
||||||
GuiButton * batteryBtn[4];
|
|
||||||
|
|
||||||
for(i=0; i < 4; i++)
|
for(i=0; i < 4; i++)
|
||||||
{
|
{
|
||||||
@ -1441,8 +1534,11 @@ static int MenuGame()
|
|||||||
batteryBtn[i]->SetImage(batteryImg[i]);
|
batteryBtn[i]->SetImage(batteryImg[i]);
|
||||||
batteryBtn[i]->SetIcon(batteryBarImg[i]);
|
batteryBtn[i]->SetIcon(batteryBarImg[i]);
|
||||||
batteryBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
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]->SetSelectable(false);
|
||||||
|
batteryBtn[i]->SetState(STATE_DISABLED);
|
||||||
batteryBtn[i]->SetAlpha(150);
|
batteryBtn[i]->SetAlpha(150);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1523,6 +1619,7 @@ static int MenuGame()
|
|||||||
if(newStatus == true) // controller connected
|
if(newStatus == true) // controller connected
|
||||||
{
|
{
|
||||||
batteryBtn[i]->SetAlpha(255);
|
batteryBtn[i]->SetAlpha(255);
|
||||||
|
batteryBtn[i]->SetState(STATE_DEFAULT);
|
||||||
batteryBarImg[i]->SetTile(newLevel);
|
batteryBarImg[i]->SetTile(newLevel);
|
||||||
|
|
||||||
if(newLevel == 0)
|
if(newLevel == 0)
|
||||||
@ -1533,6 +1630,7 @@ static int MenuGame()
|
|||||||
else // controller not connected
|
else // controller not connected
|
||||||
{
|
{
|
||||||
batteryBtn[i]->SetAlpha(150);
|
batteryBtn[i]->SetAlpha(150);
|
||||||
|
batteryBtn[i]->SetState(STATE_DISABLED);
|
||||||
batteryBarImg[i]->SetTile(0);
|
batteryBarImg[i]->SetTile(0);
|
||||||
batteryImg[i]->SetImage(&battery);
|
batteryImg[i]->SetImage(&battery);
|
||||||
}
|
}
|
||||||
@ -1566,6 +1664,24 @@ static int MenuGame()
|
|||||||
{
|
{
|
||||||
menu = MENU_GAMESETTINGS;
|
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)
|
else if(mainmenuBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))
|
if (WindowPrompt("Quit Game", "Quit this game? Any unsaved progress will be lost.", "OK", "Cancel"))
|
||||||
|
Loading…
Reference in New Issue
Block a user