Migrated FCEUD_CommandMapping to ButtConfig, finally.

This commit is contained in:
Alexey 'Cluster' Avdyukhin 2021-06-08 10:43:36 +03:00 committed by zeromus
parent 91756a9593
commit ab1264064c
7 changed files with 77 additions and 85 deletions

View File

@ -929,9 +929,15 @@ void InitInputStuff(void)
for (x = 0; x < 2; x++)
for (y = 0; y < 2; y++)
JoyClearBC(&lcdcompzappersc[x][y]);
JoyClearBC(&autoHoldKeys);
JoyClearBC(&autoHoldClearKeys);
for (x = 0; x<EMUCMD_MAX; x++)
JoyClearBC(&FCEUD_CommandMapping[x]);
}
static char *MakeButtString(ButtConfig *bc, int appendKB = 1)
char *MakeButtString(ButtConfig *bc, int appendKB)
{
uint32 x; //mbg merge 7/17/06 changed to uint
char tmpstr[512];
@ -1143,7 +1149,7 @@ static void ClearExtraMeta(int* key)
static int DWBStarted;
static ButtConfig *DWBButtons;
static const uint8 *DWBText;
static const char *DWBText;
static uint8 DWBFirstPress;
static HWND die;
@ -1296,7 +1302,7 @@ gornk:
return 0;
}
int DWaitButton(HWND hParent, const uint8 *text, ButtConfig *bc)
int DWaitButton(HWND hParent, const char *text, ButtConfig *bc)
{
DWBText=text;
DWBButtons = bc;
@ -1345,7 +1351,7 @@ static INT_PTR CALLBACK DoTBCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
char btext[128];
btext[0]=0;
GetDlgItemText(hwndDlg, b, btext, 128);
DWaitButton(hwndDlg, (uint8*)btext,&DoTBButtons[b - 300]); //mbg merge 7/17/06 added cast
DWaitButton(hwndDlg, btext,&DoTBButtons[b - 300]); //mbg merge 7/17/06 added cast
}
else switch(wParam&0xFFFF)
{
@ -1737,7 +1743,7 @@ INT_PTR CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP
{
char btext[128] = { 0 };
GetDlgItemText(hwndDlg, BTN_AUTO_HOLD, btext, sizeof(btext) );
DWaitButton(hwndDlg, (uint8*)btext, &autoHoldKeys);
DWaitButton(hwndDlg, btext, &autoHoldKeys);
if (autoHoldKeys.NumC)
{
char *nstr = MakeButtString(&autoHoldKeys);
@ -1755,7 +1761,7 @@ INT_PTR CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP
{
char btext[128] = { 0 };
GetDlgItemText(hwndDlg, BTN_CLEAR_AH, btext, 128);
DWaitButton(hwndDlg, (uint8*)btext, &autoHoldClearKeys);
DWaitButton(hwndDlg, btext, &autoHoldClearKeys);
if (autoHoldClearKeys.NumC)
{
char *nstr = MakeButtString(&autoHoldClearKeys);
@ -1801,62 +1807,26 @@ void DestroyInput(void)
}
}
int FCEUD_CommandMapping[EMUCMD_MAX];
//int FCEUD_CommandMapping[EMUCMD_MAX];
ButtConfig FCEUD_CommandMapping[EMUCMD_MAX];
CFGSTRUCT HotkeyConfig[]={
AC(FCEUD_CommandMapping),
VAC(FCEUD_CommandMapping, 2),
ENDCFGSTRUCT
};
int FCEUD_TestCommandState(int c)
{
int cmd=FCEUD_CommandMapping[c];
int cmdmask=cmd&CMD_KEY_MASK;
// allow certain commands be affected by key repeat
if(c == EMUCMD_FRAME_ADVANCE || c == EMUCMD_SPEED_TURBO || c == EMUCMD_TASEDITOR_REWIND) // TODO: this should be made more general by detecting if the command has an "off" function
switch (c)
{
keys = GetKeyboard_nr();
keys_nr = GetKeyboard_nr();
case EMUCMD_FRAME_ADVANCE:
case EMUCMD_SPEED_TURBO:
case EMUCMD_TASEDITOR_REWIND:
return DTestButton(&FCEUD_CommandMapping[c], 0);
default:
return DTestButton(&FCEUD_CommandMapping[c], 1);
}
else
{
keys = GetKeyboard_jd();
keys_nr = GetKeyboard_nr();
}
/* test CTRL, SHIFT, ALT */
if (cmd & CMD_KEY_ALT)
{
int ctlstate = (cmd & CMD_KEY_LALT) ? keys_nr[SCAN_LEFTALT] : 0;
ctlstate |= (cmd & CMD_KEY_RALT) ? keys_nr[SCAN_RIGHTALT] : 0;
if (!ctlstate)
return 0;
}
else if((cmdmask != SCAN_LEFTALT && keys_nr[SCAN_LEFTALT]) || (cmdmask != SCAN_RIGHTALT && keys_nr[SCAN_RIGHTALT]))
return 0;
if (cmd & CMD_KEY_CTRL)
{
int ctlstate = (cmd & CMD_KEY_LCTRL) ? keys_nr[SCAN_LEFTCONTROL] : 0;
ctlstate |= (cmd & CMD_KEY_RCTRL) ? keys_nr[SCAN_RIGHTCONTROL] : 0;
if (!ctlstate)
return 0;
}
else if((cmdmask != SCAN_LEFTCONTROL && keys_nr[SCAN_LEFTCONTROL]) || (cmdmask != SCAN_RIGHTCONTROL && keys_nr[SCAN_RIGHTCONTROL]))
return 0;
if (cmd & CMD_KEY_SHIFT)
{
int ctlstate = (cmd & CMD_KEY_LSHIFT) ? keys_nr[SCAN_LEFTSHIFT] : 0;
ctlstate |= (cmd & CMD_KEY_RSHIFT) ? keys_nr[SCAN_RIGHTSHIFT] : 0;
if (!ctlstate)
return 0;
}
else if((cmdmask != SCAN_LEFTSHIFT && keys_nr[SCAN_LEFTSHIFT]) || (cmdmask != SCAN_RIGHTSHIFT && keys_nr[SCAN_RIGHTSHIFT]))
return 0;
return keys[cmdmask] ? 1 : 0;
}
void FCEUD_TurboOn (void)

View File

@ -68,11 +68,13 @@ void ParseGIInput(FCEUGI *GameInfo);
void SetEmulationSpeed(int type);
int FCEUD_TestCommandState(int c);
void FCEUD_UpdateInput();
int DWaitButton(HWND hParent, const char *text, ButtConfig *bc);
int DTestButton(ButtConfig *bc, uint8_t just_down = 0);
char *MakeButtString(ButtConfig *bc, int appendKB = 1);
extern CFGSTRUCT HotkeyConfig[];
extern int FCEUD_CommandMapping[EMUCMD_MAX];
extern ButtConfig FCEUD_CommandMapping[EMUCMD_MAX];
#endif

View File

@ -443,11 +443,11 @@ bool ShouldDisplayMapping(int mapn, int filter, const int* conflictTable)
}
else if(filter == EMUCMDTYPE_MAX + 1) /* Assigned */
{
return FCEUD_CommandMapping[FCEUI_CommandTable[mapn].cmd] != 0;
return FCEUD_CommandMapping[FCEUI_CommandTable[mapn].cmd].NumC != 0;
}
else if(filter == EMUCMDTYPE_MAX + 2) /* Unassigned */
{
return FCEUD_CommandMapping[FCEUI_CommandTable[mapn].cmd] == 0;
return FCEUD_CommandMapping[FCEUI_CommandTable[mapn].cmd].NumC == 0;
}
else if(filter == EMUCMDTYPE_MAX + 3) /* Conflicts */
{
@ -472,10 +472,23 @@ void PopulateConflictTable(int* conflictTable)
{
for(unsigned int j = i + 1; j < EMUCMD_MAX; ++j)
{
if(FCEUD_CommandMapping[i] &&
FCEUD_CommandMapping[i] == FCEUD_CommandMapping[j] &&
// AnS: added the condition that both commands must have the same EMUCMDFLAG_TASEDITOR, or else they are not considered conflicting
(FCEUI_CommandTable[i].flags & EMUCMDFLAG_TASEDITOR) == (FCEUI_CommandTable[j].flags & EMUCMDFLAG_TASEDITOR))
bool hasConflicsts = false;
for (unsigned int x = 0; x < FCEUD_CommandMapping[i].NumC; ++x)
{
for (unsigned int y = 0; y < FCEUD_CommandMapping[j].NumC; ++y)
{
if ((FCEUI_CommandTable[i].flags & EMUCMDFLAG_TASEDITOR) == (FCEUI_CommandTable[j].flags & EMUCMDFLAG_TASEDITOR)
&& FCEUD_CommandMapping[i].ButtType[x] == FCEUD_CommandMapping[j].ButtType[y]
&& FCEUD_CommandMapping[i].DeviceNum[x] == FCEUD_CommandMapping[j].DeviceNum[y]
&& FCEUD_CommandMapping[i].ButtonNum[x] == FCEUD_CommandMapping[j].ButtonNum[y])
{
hasConflicsts = true;
break;
}
}
if (hasConflicsts) break;
}
if (hasConflicsts)
{
conflictTable[i] = 1;
conflictTable[j] = 1;
@ -551,9 +564,9 @@ void PopulateMappingDisplay(HWND hwndDlg)
lvi.mask = LVIF_TEXT;
lvi.iItem = idx;
lvi.iSubItem = 2;
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[FCEUI_CommandTable[i].cmd]);
lvi.pszText = MakeButtString(&FCEUD_CommandMapping[FCEUI_CommandTable[i].cmd], 0);
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
free(lvi.pszText);
idx++;
}
@ -651,7 +664,7 @@ void InitFilterComboBox(HWND hwndDlg)
* Checks what ListView line was selected and shows the dialog
* that prompts the user to enter a hotkey.
**/
void AskForHotkey(HWND hwndListView)
void AskForHotkey(HWND hwndDlg, HWND hwndListView)
{
int nSel = SendMessage(hwndListView, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED);
@ -669,20 +682,16 @@ void AskForHotkey(HWND hwndListView)
int nCmd = lvi.lParam;
int nRet = DialogBox(fceu_hInstance, "NEWINPUT", hwndListView, ChangeInputDialogProc);
//int nRet = DialogBox(fceu_hInstance, "NEWINPUT", hwndListView, ChangeInputDialogProc);
DWaitButton(hwndDlg, FCEUI_CommandTable[nCmd].name, &FCEUD_CommandMapping[nCmd]);
if (nRet)
{
// nRet will be -1 when the user selects "clear".
FCEUD_CommandMapping[nCmd] = ( nRet < 0) ? 0 : nRet;
memset(&lvi, 0, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iItem = nSel;
lvi.iSubItem = 2;
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[nCmd]);
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
}
memset(&lvi, 0, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iItem = nSel;
lvi.iSubItem = 2;
lvi.pszText = MakeButtString(&FCEUD_CommandMapping[nCmd], 0);
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
free(lvi.pszText);
}
}
@ -695,7 +704,10 @@ void ApplyDefaultCommandMapping()
for(unsigned i = 0; i < NUM_DEFAULT_MAPPINGS; ++i)
{
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd] = DefaultCommandMapping[i].key;
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd].ButtType[0] = BUTTC_KEYBOARD;
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd].DeviceNum[0] = 0;
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd].ButtonNum[0] = DefaultCommandMapping[i].key;
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd].NumC = 1;
}
}
@ -781,7 +793,7 @@ INT_PTR CALLBACK MapInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR
switch (code)
{
case LVN_ITEMACTIVATE:
AskForHotkey(hwndListView);
AskForHotkey(hwndDlg, hwndListView);
// TODO: Only redraw if Conflicts filter
// is active.

View File

@ -213,12 +213,14 @@ void TASEDITOR_WINDOW::updateTooltips()
// for other controls we provide hwnd
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
char tooltipText[TOOLTIP_TEXT_MAX_LEN];
if (windowItems[i].hotkeyEmuCmd && FCEUD_CommandMapping[windowItems[i].hotkeyEmuCmd])
if (windowItems[i].hotkeyEmuCmd && FCEUD_CommandMapping[windowItems[i].hotkeyEmuCmd].NumC)
{
// add hotkey mapping if needed
strcpy(tooltipText, windowItems[i].tooltipText);
strcat(tooltipText, " (hotkey: ");
strcat(tooltipText, GetKeyComboName(FCEUD_CommandMapping[windowItems[i].hotkeyEmuCmd]));
char *buttName = MakeButtString(&FCEUD_CommandMapping[windowItems[i].hotkeyEmuCmd], 0);
strcat(tooltipText, buttName);
free(buttName);
strcat(tooltipText, ")");
toolInfo.lpszText = tooltipText;
} else

View File

@ -604,7 +604,9 @@ INT_PTR CALLBACK TracerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
{
// Assemble the message to pause the game. Uses the current hotkey mapping dynamically
strcpy(trace_str, "Pause the game (press ");
strcat(trace_str, GetKeyComboName(FCEUD_CommandMapping[EMUCMD_PAUSE]));
char *buttName = MakeButtString(&FCEUD_CommandMapping[EMUCMD_PAUSE], 0);
strcat(trace_str, buttName);
free(buttName);
strcat(trace_str, " key or snap the Debugger) to update this window.\r\n");
SetDlgItemText(hTracer, IDC_TRACER_LOG, trace_str);
}
@ -714,7 +716,9 @@ void BeginLoggingSequence(void)
tracelogbufAddressesLog.resize(tracelogbufsize);
// Assemble the message to pause the game. Uses the current hotkey mapping dynamically
strcat(trace_str, "Pause the game (press ");
strcat(trace_str, GetKeyComboName(FCEUD_CommandMapping[EMUCMD_PAUSE]));
char *buttName = MakeButtString(&FCEUD_CommandMapping[EMUCMD_PAUSE], 0);
strcat(trace_str, buttName);
free(buttName);
strcat(trace_str, " key or snap the Debugger) to update this window.\r\n");
SetDlgItemText(hTracer, IDC_TRACER_LOG, trace_str);
tracelogbufpos = tracelogbufusedsize = 0;

View File

@ -1269,11 +1269,12 @@ INT_PTR CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP
CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_NO8LIM,BST_CHECKED);
char buf[1024] = "Full Screen";
int c = FCEUD_CommandMapping[EMUCMD_MISC_TOGGLEFULLSCREEN];
if (c)
if (FCEUD_CommandMapping[EMUCMD_MISC_TOGGLEFULLSCREEN].NumC)
{
strcat(buf, " (");
strcat(buf, GetKeyComboName(c));
char *buttName = MakeButtString(&FCEUD_CommandMapping[EMUCMD_MISC_TOGGLEFULLSCREEN], 0);
strcat(buf, buttName);
free(buttName);
if (fullscreenByDoubleclick)
strcat(buf, " or double-click)");
else

View File

@ -2918,7 +2918,7 @@ string HOTKEYMENUINDEX::getQualifiedMenuText(FCEUMENU_INDEX menu_index) {
}
string HOTKEYMENUINDEX::getQualifiedMenuText(char* text, int emu_cmd_id) {
char* combo = GetKeyComboName(FCEUD_CommandMapping[emu_cmd_id]);
char* combo = MakeButtString(&FCEUD_CommandMapping[emu_cmd_id], 0);
char* str = new char[strlen(text) + strlen(combo) + strlen("\t") + 1];
strcpy(str, text);
if (strcmp("", combo))
@ -2926,6 +2926,7 @@ string HOTKEYMENUINDEX::getQualifiedMenuText(char* text, int emu_cmd_id) {
strcat(str, "\t");
strcat(str, combo);
}
free(combo);
string menustr = str;
delete[] str;
return menustr;