/*============================================================================= Name : KeyBindings.c Purpose : This file handles all of the logic for the key bindings Created 8/04/1999 by Drew Dunlop Copyright Relic Entertainment, Inc. All rights reserved. =============================================================================*/ #include "types.h" #include "KeyBindings.h" #include "uicontrols.h" #include "key.h" #include "fontreg.h" #include "FEColour.h" #include "strings.h" /*============================================================================= Defines : =============================================================================*/ /*============================================================================= Data definitions : =============================================================================*/ udword kbKeySavedKeys[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; kbBoundKeys *kbKeyTable = NULL; kbBoundKeys kbKeyTableEnglish[kbTOTAL_COMMANDS] = { // command defaultkey primary key key to reset to { kbNEXT_FORMATION , TABKEY , TABKEY , TABKEY }, { kbBUILD_MANAGER , BKEY , BKEY , BKEY }, { kbPREVIOUS_FOCUS , CKEY , CKEY , CKEY }, { kbNEXT_FOCUS , VKEY , VKEY , VKEY }, { kbDOCK , DKEY , DKEY , DKEY }, { kbSELECT_ALL_VISIBLE , EKEY , EKEY , EKEY }, { kbFOCUS , FKEY , FKEY , FKEY }, { kbRESEARCH_MANAGER , RKEY , RKEY , RKEY }, { kbHARVEST , HKEY , HKEY , HKEY }, { kbMOVE , MKEY , MKEY , MKEY }, { kbNEXT_TACTIC , RBRACK , RBRACK , RBRACK }, { kbPREVIOUS_TACTIC , LBRACK , LBRACK , LBRACK }, { kbSCUTTLE , SKEY , SKEY , SKEY }, { kbSHIP_SPECIAL , ZKEY , ZKEY , ZKEY }, { kbTACTICAL_OVERLAY , CAPSLOCKKEY , CAPSLOCKKEY , CAPSLOCKKEY }, // { kbSENSORS_MANAGER , SPACEKEY , SPACEKEY , SPACEKEY }, { kbMOTHERSHIP , HOMEKEY , HOMEKEY , HOMEKEY }, { kbKAMIKAZE , KKEY , KKEY , KKEY }, { kbCANCEL_ORDERS , TILDEKEY , TILDEKEY , TILDEKEY }, { kbLAUNCH_MANAGER , LKEY , LKEY , LKEY } }; kbBoundKeys kbKeyTableFrench[kbTOTAL_COMMANDS] = { // command defaultkey primary key key to reset to { kbNEXT_FORMATION , TABKEY , TABKEY , TABKEY }, { kbBUILD_MANAGER , BKEY , BKEY , BKEY }, { kbPREVIOUS_FOCUS , CKEY , XKEY , XKEY }, { kbNEXT_FOCUS , VKEY , VKEY , VKEY }, { kbDOCK , DKEY , AKEY , AKEY }, { kbSELECT_ALL_VISIBLE , EKEY , EKEY , EKEY }, { kbFOCUS , FKEY , FKEY , FKEY }, { kbRESEARCH_MANAGER , RKEY , RKEY , RKEY }, { kbHARVEST , HKEY , CKEY , CKEY }, { kbMOVE , MKEY , DKEY , DKEY }, { kbNEXT_TACTIC , RBRACK , RBRACK , RBRACK }, { kbPREVIOUS_TACTIC , LBRACK , LBRACK , LBRACK }, { kbSCUTTLE , SKEY , SKEY , SKEY }, { kbSHIP_SPECIAL , ZKEY , ZKEY , ZKEY }, { kbTACTICAL_OVERLAY , CAPSLOCKKEY , CAPSLOCKKEY , CAPSLOCKKEY }, // { kbSENSORS_MANAGER , SPACEKEY , SPACEKEY , SPACEKEY }, { kbMOTHERSHIP , HOMEKEY , HOMEKEY , HOMEKEY }, { kbKAMIKAZE , KKEY , KKEY , KKEY }, { kbCANCEL_ORDERS , TILDEKEY , TILDEKEY , TILDEKEY }, { kbLAUNCH_MANAGER , LKEY , LKEY , LKEY } }; kbBoundKeys kbKeyTableGerman[kbTOTAL_COMMANDS] = { // command defaultkey primary key key to reset to { kbNEXT_FORMATION , TABKEY , TABKEY , TABKEY }, { kbBUILD_MANAGER , BKEY , BKEY , BKEY }, { kbPREVIOUS_FOCUS , CKEY , CKEY , CKEY }, { kbNEXT_FOCUS , VKEY , VKEY , VKEY }, { kbDOCK , DKEY , DKEY , DKEY }, { kbSELECT_ALL_VISIBLE , EKEY , EKEY , EKEY }, { kbFOCUS , FKEY , FKEY , FKEY }, { kbRESEARCH_MANAGER , RKEY , RKEY , RKEY }, { kbHARVEST , HKEY , HKEY , HKEY }, { kbMOVE , MKEY , WKEY , WKEY }, { kbNEXT_TACTIC , RBRACK , RBRACK , RBRACK }, { kbPREVIOUS_TACTIC , LBRACK , LBRACK , LBRACK }, { kbSCUTTLE , SKEY , SKEY , SKEY }, { kbSHIP_SPECIAL , ZKEY , ZKEY , ZKEY }, { kbTACTICAL_OVERLAY , CAPSLOCKKEY , CAPSLOCKKEY , CAPSLOCKKEY }, // { kbSENSORS_MANAGER , SPACEKEY , SPACEKEY , SPACEKEY }, { kbMOTHERSHIP , HOMEKEY , HOMEKEY , HOMEKEY }, { kbKAMIKAZE , KKEY , KKEY , KKEY }, { kbCANCEL_ORDERS , TILDEKEY , TILDEKEY , TILDEKEY }, { kbLAUNCH_MANAGER , LKEY , LKEY , LKEY } }; kbBoundKeys kbKeyTableSpanish[kbTOTAL_COMMANDS] = { // command defaultkey primary key key to reset to { kbNEXT_FORMATION , TABKEY , TABKEY , TABKEY }, { kbBUILD_MANAGER , BKEY , BKEY , BKEY }, { kbPREVIOUS_FOCUS , CKEY , CKEY , CKEY }, { kbNEXT_FOCUS , VKEY , VKEY , VKEY }, { kbDOCK , DKEY , AKEY , AKEY }, { kbSELECT_ALL_VISIBLE , EKEY , EKEY , EKEY }, { kbFOCUS , FKEY , FKEY , FKEY }, { kbRESEARCH_MANAGER , RKEY , RKEY , RKEY }, { kbHARVEST , HKEY , HKEY , HKEY }, { kbMOVE , MKEY , DKEY , DKEY }, { kbNEXT_TACTIC , RBRACK , RBRACK , RBRACK }, { kbPREVIOUS_TACTIC , LBRACK , LBRACK , LBRACK }, { kbSCUTTLE , SKEY , SKEY , SKEY }, { kbSHIP_SPECIAL , ZKEY , ZKEY , ZKEY }, { kbTACTICAL_OVERLAY , CAPSLOCKKEY , CAPSLOCKKEY , CAPSLOCKKEY }, // { kbSENSORS_MANAGER , SPACEKEY , SPACEKEY , SPACEKEY }, { kbMOTHERSHIP , HOMEKEY , HOMEKEY , HOMEKEY }, { kbKAMIKAZE , KKEY , KKEY , KKEY }, { kbCANCEL_ORDERS , TILDEKEY , TILDEKEY , TILDEKEY }, { kbLAUNCH_MANAGER , LKEY , LKEY , LKEY } }; kbBoundKeys kbKeyTableItalian[kbTOTAL_COMMANDS] = { // command defaultkey primary key key to reset to { kbNEXT_FORMATION , TABKEY , TABKEY , TABKEY }, { kbBUILD_MANAGER , BKEY , BKEY , BKEY }, { kbPREVIOUS_FOCUS , CKEY , CKEY , CKEY }, { kbNEXT_FOCUS , VKEY , VKEY , VKEY }, { kbDOCK , DKEY , AKEY , AKEY }, { kbSELECT_ALL_VISIBLE , EKEY , EKEY , EKEY }, { kbFOCUS , FKEY , FKEY , FKEY }, { kbRESEARCH_MANAGER , RKEY , RKEY , RKEY }, { kbHARVEST , HKEY , HKEY , HKEY }, { kbMOVE , MKEY , MKEY , MKEY }, { kbNEXT_TACTIC , RBRACK , RBRACK , RBRACK }, { kbPREVIOUS_TACTIC , LBRACK , LBRACK , LBRACK }, { kbSCUTTLE , SKEY , SKEY , SKEY }, { kbSHIP_SPECIAL , ZKEY , ZKEY , ZKEY }, { kbTACTICAL_OVERLAY , CAPSLOCKKEY , CAPSLOCKKEY , CAPSLOCKKEY }, // { kbSENSORS_MANAGER , SPACEKEY , SPACEKEY , SPACEKEY }, { kbMOTHERSHIP , HOMEKEY , HOMEKEY , HOMEKEY }, { kbKAMIKAZE , KKEY , KKEY , KKEY }, { kbCANCEL_ORDERS , TILDEKEY , TILDEKEY , TILDEKEY }, { kbLAUNCH_MANAGER , LKEY , LKEY , LKEY } }; kbBoundKeys kbKeySaveTable[kbTOTAL_COMMANDS]; // This is a look-up table that has a value of TRUE for bool8 kbCanMapKey[KEY_TOTAL_KEYS]; // This is a look-up table for the strings sdword kbKeyToString[KEY_TOTAL_KEYS]; // fonthandle for the keyboard list window font initialized in the options init fonthandle kbKeyListFont; // pointer to the listwindow handle listwindowhandle kbListWindow=NULL; bool bkDisableKeyRemap=FALSE; /*============================================================================= Private Function Prototypes : =============================================================================*/ void kbSetNewKey(udword keypressed); bool kbKeyUsed(udword keytocheck); /*============================================================================= Function Logic : =============================================================================*/ /*----------------------------------------------------------------------------- Name : kbListTitleDraw Description : This function draws the title for the keyboard list window Inputs : Rectangle of draw area Outputs : none Parameters : rectangle *rect Return : void -----------------------------------------------------------------------------*/ void kbListTitleDraw(rectangle *rect) { fonthandle oldfont; rectangle r = *rect; oldfont = fontMakeCurrent(kbKeyListFont); fontPrintf(rect->x0+6, rect->y0, colWhite, strGetString(strCommandToBind)); fontPrintf(rect->x0 + (((rect->x1-rect->x0)*3)/5), rect->y0, colWhite, strGetString(strKeyBound)); r.x0 -= 2; r.x1++; r.y1--; primRectTranslucent2(&r, colRGBA(0,160,100,63)); // primLine2(r.x0,r.y1,r.x1,r.y1,colRGB(20,200,20)); // primRectOutline2(&r, 1, colRGB(20,200,20)); fontMakeCurrent(oldfont); } /*----------------------------------------------------------------------------- Name : kbListItemDraw Description : This function draws each item in the list window Inputs : rect, and the item pointer Outputs : none Parameters : rectangle *rect, listitemhandle data Return : void -----------------------------------------------------------------------------*/ void kbListItemDraw(rectangle *rect, listitemhandle data) { fonthandle oldfont; kbBoundKeys *bkey = (kbBoundKeys *)data->data; color c = FEC_ListItemStandard; oldfont = fontMakeCurrent(kbKeyListFont); // if selected then this color if (bitTest(data->flags, UICLI_Selected)) { c = FEC_ListItemSelected; } if (bkey->status == KB_NotBound) { // if not bound then print in red c = colRGB(255,20,20); } else if (bkey->status == KB_GetKeyPress) { // if not bound then print in yellow color c = colRGB(255,255,20); } fontPrintf(rect->x0 + 6, rect->y0, c, strGetString(bkey->command + strKeyCommandOffset)); if (bkey->status == KB_GetKeyPress) { // if getting keypress then show it with ???? fontPrintf(rect->x0 + (((rect->x1-rect->x0)*3)/5), rect->y0, c, "??????"); } else { if (bkey->primarykey == 0) { // no key assigned to this fontPrintf(rect->x0 + (((rect->x1-rect->x0)*3)/5), rect->y0, c, "%s", strGetString(strNoKeyBound)); } else { // key assigned so print the name of that key dbgAssert(bkey->primarykey < KEY_TOTAL_KEYS); fontPrintf(rect->x0 + (((rect->x1-rect->x0)*3)/5), rect->y0, c, "%s", strGetString(kbKeyToString[bkey->primarykey])); } } fontMakeCurrent(oldfont); } /*----------------------------------------------------------------------------- Name : kbListWindowCB Description : This function initializes the key bindings list window Inputs : name, and atom Outputs : none Parameters : char *string, featom *atom Return : void -----------------------------------------------------------------------------*/ void kbListWindowCB(char *string, featom *atom) { fonthandle oldfont; sdword index; kbBoundKeys *bkey; if (FEFIRSTCALL(atom)) { oldfont = fontMakeCurrent(kbKeyListFont); kbListWindow = (listwindowhandle)atom->pData; uicListWindowInit(kbListWindow, kbListTitleDraw, // title draw NULL, // title click process, no title fontHeight(" ")+(fontHeight(" ")>>1), // title height, no title kbListItemDraw, // item draw funtcion fontHeight(" ")+(fontHeight(" ")>>1), // item height UICLW_CanSelect|UICLW_CanHaveFocus); for (index = 0; index < kbTOTAL_COMMANDS; index++) { uicListAddItem(kbListWindow, (ubyte *)&kbKeyTable[index], UICLI_CanSelect, UICLW_AddToHead); } fontMakeCurrent(oldfont); return; } else if (FELASTCALL(atom)) { bitClear(kbListWindow->windowflags, UICLW_GetKeyPressed); for (index = 0; index < kbTOTAL_COMMANDS; index++) { if (kbKeyTable[index].primarykey == 0) { kbKeyTable[index].status = KB_NotBound; } else { kbKeyTable[index].status = KB_NormalBound; } } kbListWindow = NULL; return; } // General callbacks because of user input switch (kbListWindow->message) { case CM_AcceptText: case CM_DoubleClick: bkey = (kbBoundKeys *)kbListWindow->CurLineSelected->data; bitSet(kbListWindow->windowflags, UICLW_GetKeyPressed); #ifdef DEBUG_STOMP regVerify((regionhandle)&kbListWindow->reg); #endif bitSet(kbListWindow->reg.status, RSF_DrawThisFrame); bkey->status = KB_GetKeyPress; break; case CM_KeyCaptured: kbSetNewKey(kbListWindow->keypressed); break; case CM_LoseFocus: case CM_NewItemSelected: bitClear(kbListWindow->windowflags, UICLW_GetKeyPressed); for (index = 0; index < kbTOTAL_COMMANDS; index++) { if (kbKeyTable[index].primarykey == 0) { kbKeyTable[index].status = KB_NotBound; } else { kbKeyTable[index].status = KB_NormalBound; } } break; } } /*----------------------------------------------------------------------------- Name : kbPoolListItemDraw Description : This function draws each item in the key pool list window Inputs : rect, and the item pointer Outputs : none Parameters : rectangle *rect, listitemhandle data Return : void -----------------------------------------------------------------------------*/ void kbPoolListItemDraw(rectangle *rect, listitemhandle data) { fonthandle oldfont; color c = FEC_ListItemStandard; sword key1, key2; udword udata = (udword)data->data; oldfont = fontMakeCurrent(kbKeyListFont); // unpack the two key's key1 = (sword) (udata&(0x0000FFFF)); key2 = (sword) ((udata&(0xFFFF0000))>>16); // if selected then this color if (bitTest(data->flags, UICLI_Selected)) { c = FEC_ListItemSelected; } if (key1 != -1) { fontPrintf(rect->x0 + 6, rect->y0, c, strGetString(kbKeyToString[key1])); } if (key2 != -1) { fontPrintf(rect->x0 + ( (rect->x1-rect->x0)>>1 ), rect->y0, c, strGetString(kbKeyToString[key2])); } fontMakeCurrent(oldfont); } /*----------------------------------------------------------------------------- Name : kbPoolListWindowCB Description : This function Initializes the list of keys window Inputs : keypressed Outputs : none Parameters : udword keypressed Return : void -----------------------------------------------------------------------------*/ void kbPoolListWindowCB(char *string, featom *atom) { fonthandle oldfont; static sdword index; listwindowhandle keypool; sdword done; udword data; sword key1, key2; if (FEFIRSTCALL(atom)) { oldfont = fontMakeCurrent(kbKeyListFont); keypool = (listwindowhandle)atom->pData; uicListWindowInit(keypool, NULL, // title draw NULL, // title click process, no title 0, // title height, no title kbPoolListItemDraw, // item draw funtcion fontHeight(" ")+(fontHeight(" ")>>1), // item height UICLW_CanSelect|UICLW_CanHaveFocus); done = 0; for (index=0;indexCurLineSelected->data; if (kbCanMapKey[keypressed]) { for (index=0;indexprimarykey = keypressed; bkey->status = KB_NormalBound; #ifdef DEBUG_STOMP regVerify((regionhandle)&kbListWindow->reg); #endif bitSet(kbListWindow->reg.status, RSF_DrawThisFrame); } else { if (bkey->primarykey != 0) bkey->status = KB_NormalBound; else bkey->status = KB_NotBound; if (gameIsRunning) { feScreenStart(feStack[feStackIndex].baseRegion, "In_Game_Invalid_Key"); } else { feScreenStart(feStack[feStackIndex].baseRegion, "Invalid_Key"); } // this key is not a key that can be remapped. } } /*----------------------------------------------------------------------------- Name : kbKeyResetToDefault Description : This function will reset all of the keyboard bindings to default. Inputs : name, and atom Outputs : none Parameters : char *string, featom *atom Return : void -----------------------------------------------------------------------------*/ void kbKeyResetToDefault(char *string, featom *atom) { sdword index; for (index=kbTOTAL_COMMANDS-1; index >= 0; index--) { kbKeyTable[index].primarykey = kbKeyTable[index].resettokey; kbKeyTable[index].status = KB_NormalBound; } #ifdef DEBUG_STOMP regVerify(&kbListWindow->reg); #endif bitSet(kbListWindow->reg.status, RSF_DrawThisFrame); } /*----------------------------------------------------------------------------- Name : kbCheckBindings Description : This function will checks to see if this key is a remappable key and then do the conversion. Inputs : keypressed Outputs : none Parameters : sdword keypressed Return : void -----------------------------------------------------------------------------*/ sdword kbCheckBindings(sdword keypressed) { sdword index; if (kbCanMapKey[keypressed]) { for (index=0;index 1) return(TRUE); return(FALSE); } /*----------------------------------------------------------------------------- Name : kbCommandKeyIsHit Description : This function will return true if the key is hit for the command specified Inputs : command Outputs : boolean Parameters : udword command Return : bool -----------------------------------------------------------------------------*/ bool kbCommandKeyIsHit(udword command) { return(keyIsHit(kbKeyTable[command].primarykey)); } /*----------------------------------------------------------------------------- Name : kbKeyBoundToCommand Description : This function returns the key that is bound to that command Inputs : Command to get the key for Outputs : key bound Parameters : udword command Return : udword -----------------------------------------------------------------------------*/ udword kbKeyBoundToCommand(udword command) { if (kbKeyTable != NULL) return(kbKeyTable[command].primarykey); return (0); } /*----------------------------------------------------------------------------- Name : kbInitKeyBindings Description : This function Initializes the keybindings. Inputs : void Outputs : none Parameters : void Return : void -----------------------------------------------------------------------------*/ void kbInitKeyBindings(void) { sdword index; bool bInFile=FALSE; kbKeyListFont = frFontRegister("hw_eurosecond_11.hff"); for (index=0;index