diff options
author | Jeff Kent <jeff@jkent.net> | 2017-04-13 11:30:00 +0000 |
---|---|---|
committer | /dev/humancontroller <devhc@example.com> | 2017-04-15 17:24:15 +0200 |
commit | 9edb8f8a9eb94ca6150a13900716750a710a74bc (patch) | |
tree | 132bcf00fa387c12c260099c81fba7bda9dbbeb8 /src/ui | |
parent | 6d4cacd5ad49d654e99c458f5002c70732c9e0a6 (diff) |
multi-protocol: implement messagemode[2] in the ui module, for use in non-1.1 clients
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/menudef.h | 19 | ||||
-rw-r--r-- | src/ui/ui_atoms.c | 37 | ||||
-rw-r--r-- | src/ui/ui_local.h | 3 | ||||
-rw-r--r-- | src/ui/ui_main.c | 22 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 64 | ||||
-rw-r--r-- | src/ui/ui_shared.h | 1 |
6 files changed, 124 insertions, 22 deletions
diff --git a/src/ui/menudef.h b/src/ui/menudef.h index d4ed0b2..dbd0996 100644 --- a/src/ui/menudef.h +++ b/src/ui/menudef.h @@ -4,15 +4,16 @@ #define ITEM_TYPE_RADIOBUTTON 2 // toggle button, may be grouped #define ITEM_TYPE_CHECKBOX 3 // check box #define ITEM_TYPE_EDITFIELD 4 // editable text, associated with a cvar -#define ITEM_TYPE_COMBO 5 // drop down list -#define ITEM_TYPE_LISTBOX 6 // scrollable list -#define ITEM_TYPE_MODEL 7 // model -#define ITEM_TYPE_OWNERDRAW 8 // owner draw, name specs what it is -#define ITEM_TYPE_NUMERICFIELD 9 // editable text, associated with a cvar -#define ITEM_TYPE_SLIDER 10 // mouse speed, volume, etc. -#define ITEM_TYPE_YESNO 11 // yes no cvar setting -#define ITEM_TYPE_MULTI 12 // multiple list setting, enumerated -#define ITEM_TYPE_BIND 13 // multiple list setting, enumerated +#define ITEM_TYPE_SAYFIELD 5 // the chat field +#define ITEM_TYPE_COMBO 6 // drop down list +#define ITEM_TYPE_LISTBOX 7 // scrollable list +#define ITEM_TYPE_MODEL 8 // model +#define ITEM_TYPE_OWNERDRAW 9 // owner draw, name specs what it is +#define ITEM_TYPE_NUMERICFIELD 10 // editable text, associated with a cvar +#define ITEM_TYPE_SLIDER 11 // mouse speed, volume, etc. +#define ITEM_TYPE_YESNO 12 // yes no cvar setting +#define ITEM_TYPE_MULTI 13 // multiple list setting, enumerated +#define ITEM_TYPE_BIND 14 // multiple list setting, enumerated #define ITEM_ALIGN_LEFT 0 // left alignment #define ITEM_ALIGN_CENTER 1 // center alignment diff --git a/src/ui/ui_atoms.c b/src/ui/ui_atoms.c index 64efa91..a3033c4 100644 --- a/src/ui/ui_atoms.c +++ b/src/ui/ui_atoms.c @@ -294,6 +294,36 @@ static void UI_CalcPostGameStats( void ) { } +static void UI_MessageMode_f( void ) +{ + char *arg = UI_Argv( 0 ); + + trap_Cvar_Set( "ui_sayBuffer", "" ); + + switch( arg[ 11 ] ) + { + default: + case '\0': + // Global + uiInfo.chatTeam = qfalse; + break; + + case '2': + // Team + uiInfo.chatTeam = qtrue; + break; + } + + trap_Key_SetCatcher( KEYCATCH_UI ); + Menus_CloseByName( "say" ); + Menus_CloseByName( "say_team" ); + + if( uiInfo.chatTeam ) + Menus_ActivateByName( "say_team" ); + else + Menus_ActivateByName( "say" ); +} + /* ================= @@ -377,6 +407,13 @@ qboolean UI_ConsoleCommand( int realTime ) } } + if( Q_stricmp ( cmd, "messagemode" ) == 0 || + Q_stricmp ( cmd, "messagemode2" ) == 0 ) + { + UI_MessageMode_f(); + return qtrue; + } + return qfalse; } diff --git a/src/ui/ui_local.h b/src/ui/ui_local.h index 7afdf65..0066593 100644 --- a/src/ui/ui_local.h +++ b/src/ui/ui_local.h @@ -132,6 +132,7 @@ extern vmCvar_t ui_serverStatusTimeOut; //TA: bank values extern vmCvar_t ui_bank; +extern vmCvar_t ui_chatCommands; // // ui_qmenu.c @@ -917,6 +918,8 @@ typedef struct { int effectsColor; qboolean inGameLoad; + + qboolean chatTeam; } uiInfo_t; extern uiInfo_t uiInfo; diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 33f0012..8eaa77c 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -761,7 +761,7 @@ void _UI_Refresh( int realtime ) UI_SetColor( NULL ); //TA: don't draw the cursor whilst loading - if( Menu_Count( ) > 0 && !trap_Cvar_VariableValue( "ui_loading" ) ) + if( Menu_Count( ) > 0 && !trap_Cvar_VariableValue( "ui_loading" ) && !trap_Cvar_VariableValue( "ui_hideCursor" ) ) UI_DrawHandlePic( uiInfo.uiDC.cursorx-16, uiInfo.uiDC.cursory-16, 32, 32, uiInfo.uiDC.Assets.cursor); #ifndef NDEBUG @@ -4094,6 +4094,23 @@ static void UI_RunMenuScript(char **args) { if( ( cmd = uiInfo.tremHumanBuildList[ uiInfo.tremHumanBuildIndex ].cmd ) ) trap_Cmd_ExecuteText( EXEC_APPEND, cmd ); } + else if( Q_stricmp( name, "Say" ) == 0 ) + { + char buffer[ MAX_CVAR_VALUE_STRING ]; + trap_Cvar_VariableStringBuffer( "ui_sayBuffer", buffer, sizeof( buffer ) ); + + if( !buffer[ 0 ] ) + ; + else if( ui_chatCommands.integer && ( buffer[ 0 ] == '/' || + buffer[ 0 ] == '\\' ) ) + { + trap_Cmd_ExecuteText( EXEC_APPEND, va( "%s\n", buffer + 1 ) ); + } + else if( uiInfo.chatTeam ) + trap_Cmd_ExecuteText( EXEC_APPEND, va( "say_team \"%s\"\n", buffer ) ); + else + trap_Cmd_ExecuteText( EXEC_APPEND, va( "say \"%s\"\n", buffer ) ); + } else if( Q_stricmp( name, "PTRCRestore" ) == 0 ) { int len; @@ -6257,6 +6274,8 @@ vmCvar_t ui_serverStatusTimeOut; vmCvar_t ui_bank; vmCvar_t ui_winner; +vmCvar_t ui_chatCommands; + // bk001129 - made static to avoid aliasing static cvarTable_t cvarTable[] = { @@ -6385,6 +6404,7 @@ static cvarTable_t cvarTable[] = { { &ui_bank, "ui_bank", "0", 0 }, + { &ui_chatCommands, "ui_chatCommands", "1", CVAR_ARCHIVE}, }; // bk001129 - made static to avoid aliasing diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index 2ca88cb..6774742 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -1048,6 +1048,9 @@ void Menus_CloseAll( void ) { Menu_RunCloseScript(&Menus[i]); Menus[i].window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE); } + + g_editingField = qfalse; + g_waitingForKey = qfalse; } @@ -1185,12 +1188,20 @@ void Script_SetFocus(itemDef_t *item, char **args) { if (String_Parse(args, &name)) { focusItem = Menu_FindItemByName(item->parent, name); - if (focusItem && !(focusItem->window.flags & WINDOW_DECORATION) && !(focusItem->window.flags & WINDOW_HASFOCUS)) { + if (focusItem && !(focusItem->window.flags & WINDOW_DECORATION)) { Menu_ClearFocus(item->parent); focusItem->window.flags |= WINDOW_HASFOCUS; if (focusItem->onFocus) { Item_RunScript(focusItem, focusItem->onFocus); } + if (focusItem->type == ITEM_TYPE_EDITFIELD || focusItem->type == ITEM_TYPE_SAYFIELD || focusItem->type == ITEM_TYPE_NUMERICFIELD) { + focusItem->cursorPos = 0; + g_editingField = qtrue; + g_editItem = focusItem; + if (focusItem->type == ITEM_TYPE_SAYFIELD) { + DC->setOverstrikeMode(qfalse); + } + } if (DC->Assets.itemFocusSound) { DC->startLocalSound( DC->Assets.itemFocusSound, CHAN_LOCAL_SOUND ); } @@ -2183,19 +2194,34 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) { } if (key == K_TAB || key == K_DOWNARROW || key == K_KP_DOWNARROW) { + if (item->type == ITEM_TYPE_SAYFIELD) { + return qtrue; + } + newItem = Menu_SetNextCursorItem(item->parent); - if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { + if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_SAYFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { g_editItem = newItem; } } if (key == K_UPARROW || key == K_KP_UPARROW) { + if (item->type == ITEM_TYPE_SAYFIELD) { + return qtrue; + } + newItem = Menu_SetPrevCursorItem(item->parent); - if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { + if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_SAYFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { g_editItem = newItem; } } + if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 || key == K_MOUSE4) { + if (item->type == ITEM_TYPE_SAYFIELD) { + return qtrue; + } + return qfalse; + } + if ( key == K_ENTER || key == K_KP_ENTER || key == K_ESCAPE) { return qfalse; } @@ -2314,6 +2340,7 @@ void Item_StartCapture(itemDef_t *item, int key) { int flags; switch (item->type) { case ITEM_TYPE_EDITFIELD: + case ITEM_TYPE_SAYFIELD: case ITEM_TYPE_NUMERICFIELD: case ITEM_TYPE_LISTBOX: @@ -2427,6 +2454,7 @@ qboolean Item_HandleKey(itemDef_t *item, int key, qboolean down) { return qfalse; break; case ITEM_TYPE_EDITFIELD: + case ITEM_TYPE_SAYFIELD: case ITEM_TYPE_NUMERICFIELD: //return Item_TextField_HandleKey(item, key); return qfalse; @@ -2641,15 +2669,10 @@ void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { if (g_editingField && down) { if (!Item_TextField_HandleKey(g_editItem, key)) { g_editingField = qfalse; + Item_RunScript(g_editItem, g_editItem->onTextEntry); g_editItem = NULL; inHandler = qfalse; return; - } else if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) { - g_editingField = qfalse; - g_editItem = NULL; - Display_MouseMove(NULL, DC->cursorx, DC->cursory); - } else if (key == K_TAB || key == K_UPARROW || key == K_DOWNARROW) { - return; } } @@ -2737,6 +2760,8 @@ void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { g_editItem = item; DC->setOverstrikeMode(qtrue); } + } else if (item->type == ITEM_TYPE_SAYFIELD) { + // do nothing } else { if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { Item_Action(item); @@ -2769,7 +2794,7 @@ void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { case K_KP_ENTER: case K_ENTER: if (item) { - if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { + if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_SAYFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { item->cursorPos = 0; g_editingField = qtrue; g_editItem = item; @@ -4295,6 +4320,7 @@ void Item_Paint(itemDef_t *item) { case ITEM_TYPE_CHECKBOX: break; case ITEM_TYPE_EDITFIELD: + case ITEM_TYPE_SAYFIELD: case ITEM_TYPE_NUMERICFIELD: Item_TextField_Paint(item); break; @@ -4578,10 +4604,10 @@ void Item_ValidateTypeData(itemDef_t *item) { if (item->type == ITEM_TYPE_LISTBOX) { item->typeData = UI_Alloc(sizeof(listBoxDef_t)); memset(item->typeData, 0, sizeof(listBoxDef_t)); - } else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD || item->type == ITEM_TYPE_YESNO || item->type == ITEM_TYPE_BIND || item->type == ITEM_TYPE_SLIDER || item->type == ITEM_TYPE_TEXT) { + } else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_SAYFIELD || item->type == ITEM_TYPE_NUMERICFIELD || item->type == ITEM_TYPE_YESNO || item->type == ITEM_TYPE_BIND || item->type == ITEM_TYPE_SLIDER || item->type == ITEM_TYPE_TEXT) { item->typeData = UI_Alloc(sizeof(editFieldDef_t)); memset(item->typeData, 0, sizeof(editFieldDef_t)); - if (item->type == ITEM_TYPE_EDITFIELD) { + if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_SAYFIELD) { if (!((editFieldDef_t *) item->typeData)->maxPaintChars) { ((editFieldDef_t *) item->typeData)->maxPaintChars = MAX_EDITFIELD; } @@ -5123,6 +5149,13 @@ qboolean ItemParse_mouseExitText( itemDef_t *item, int handle ) { return qtrue; } +qboolean ItemParse_onTextEntry( itemDef_t *item, int handle ) { + if (!PC_Script_Parse(handle, &item->onTextEntry)) { + return qfalse; + } + return qtrue; +} + qboolean ItemParse_action( itemDef_t *item, int handle ) { if (!PC_Script_Parse(handle, &item->action)) { return qfalse; @@ -5408,6 +5441,7 @@ keywordHash_t itemParseKeywords[] = { {"mouseExit", ItemParse_mouseExit, NULL}, {"mouseEnterText", ItemParse_mouseEnterText, NULL}, {"mouseExitText", ItemParse_mouseExitText, NULL}, + {"onTextEntry", ItemParse_onTextEntry, NULL}, {"action", ItemParse_action, NULL}, {"special", ItemParse_special, NULL}, {"cvar", ItemParse_cvar, NULL}, @@ -5911,6 +5945,12 @@ int Menu_Count( void ) { void Menu_PaintAll( void ) { int i; + + if( g_editingField || g_waitingForKey ) + DC->setCVar( "ui_hideCursor", "1" ); + else + DC->setCVar( "ui_hideCursor", "0" ); + if (captureFunc) { captureFunc(captureData); } diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index e55cc7f..210899e 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -241,6 +241,7 @@ typedef struct itemDef_s { const char *action; // select script const char *onFocus; // select script const char *leaveFocus; // select script + const char *onTextEntry; // called when text entered const char *cvar; // associated cvar const char *cvarTest; // associated cvar for enable actions const char *enableCvar; // enable, disable, show, or hide based on value, this can contain a list |