From c49ee670d39f11f5eea3bd621c7e918e41c20876 Mon Sep 17 00:00:00 2001 From: Christopher Schwarz Date: Mon, 2 Nov 2009 20:00:38 +0000 Subject: * When ui_chatCommands is enabled, change the "Say:" or "Say to Team:" text in the prompt to "Command:" when appropriate, so the user can tell that their text will not be sent as chat but executed instead. (tjw) --- assets/ui/say.menu | 50 ++++++++++++++++++++++++++++++++ src/ui/ui_main.c | 20 +++++++++++++ src/ui/ui_shared.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/ui_shared.h | 3 ++ 4 files changed, 156 insertions(+) diff --git a/assets/ui/say.menu b/assets/ui/say.menu index 77204a1b..a52f2eda 100644 --- a/assets/ui/say.menu +++ b/assets/ui/say.menu @@ -39,6 +39,10 @@ textscale .4 forecolor 0.93 0.93 0.92 1 visible MENU_TRUE + onCharEntry + { + uiScript SayKeyDown; + } onTextEntry { uiScript Say; @@ -77,6 +81,10 @@ textscale .4 forecolor 0.93 0.93 0.92 1 visible MENU_TRUE + onCharEntry + { + uiScript SayKeyDown; + } onTextEntry { uiScript Say; @@ -84,4 +92,46 @@ } } } + + // Command + menuDef + { + name say_command + fullScreen MENU_FALSE + visible MENU_FALSE + rect X Y W H + aspectBias ALIGN_LEFT + focusColor 1 1 1 1 + style WINDOW_STYLE_EMPTY + onOpen + { + setfocus say_field + } + + itemDef + { + name say_field + type ITEM_TYPE_SAYFIELD + style WINDOW_STYLE_EMPTY + text "Command:" + cvar "ui_sayBuffer" + maxchars 128 + rect 0 0 W H + textalign ALIGN_LEFT + textvalign VALIGN_CENTER + textstyle ITEM_TEXTSTYLE_SHADOWED + textscale .4 + forecolor 0.93 0.93 0.92 1 + visible MENU_TRUE + onCharEntry + { + uiScript SayKeyDown; + } + onTextEntry + { + uiScript Say; + close say_command; + } + } + } } diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index a1423e86..46961723 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -3058,6 +3058,26 @@ static void UI_RunMenuScript( char **args ) else trap_Cmd_ExecuteText( EXEC_APPEND, va( "say \"%s\"\n", buffer ) ); } + else if( Q_stricmp( name, "SayKeydown" ) == 0 ) + { + if( ui_chatCommands.integer ) + { + char buffer[ MAX_CVAR_VALUE_STRING ]; + trap_Cvar_VariableStringBuffer( "ui_sayBuffer", buffer, sizeof( buffer ) ); + + if( buffer[ 0 ] == '/' || buffer[ 0 ] == '\\' ) + { + Menus_ReplaceActiveByName( "say_command" ); + } + else + { + if( !uiInfo.chatTeam ) + Menus_ReplaceActiveByName( "say" ); + else + Menus_ReplaceActiveByName( "say_team" ); + } + } + } else if( Q_stricmp( name, "playMovie" ) == 0 ) { if( uiInfo.previewMovie >= 0 ) diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index 0a416282..fcf359f1 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -3927,6 +3927,55 @@ void Menus_Activate( menuDef_t *menu ) } } +qboolean Menus_ReplaceActive( menuDef_t *menu ) +{ + int i; + menuDef_t *active; + + if( openMenuCount < 1 ) + return qfalse; + + active = menuStack[ openMenuCount - 1]; + + if( !( active->window.flags & WINDOW_HASFOCUS ) || + !( active->window.flags & WINDOW_VISIBLE ) ) + { + return qfalse; + } + + if( menu == active ) + return qfalse; + + if( menu->itemCount != active->itemCount ) + return qfalse; + + for( i = 0; i < menu->itemCount; i++ ) + { + if( menu->items[ i ]->type != active->items[ i ]->type ) + return qfalse; + } + + active->window.flags &= ~( WINDOW_FADINGOUT | WINDOW_VISIBLE ); + menu->window.flags |= ( WINDOW_HASFOCUS | WINDOW_VISIBLE ); + + menuStack[ openMenuCount - 1 ] = menu; + if( menu->onOpen ) + { + itemDef_t item; + item.parent = menu; + Item_RunScript( &item, menu->onOpen ); + } + + for( i = 0; i < menu->itemCount; i++ ) + { + menu->items[ i ]->cursorPos = active->items[ i ]->cursorPos; + menu->items[ i ]->typeData.list->startPos = active->items[ i ]->typeData.list->startPos; + menu->items[ i ]->feederID = active->items[ i ]->feederID; + menu->items[ i ]->typeData.combo->cursorPos = active->items[ i ]->typeData.combo->cursorPos; + } + return qtrue; +} + int Display_VisibleMenuCount( void ) { int i, count; @@ -4015,6 +4064,10 @@ void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) inHandler = qfalse; return; } + else + { + Item_RunScript( g_editItem, g_editItem->onCharEntry ); + } } if( menu == NULL ) @@ -6159,6 +6212,26 @@ menuDef_t *Menus_ActivateByName( const char *p ) return m; } +menuDef_t *Menus_ReplaceActiveByName( const char *p ) +{ + int i; + menuDef_t *m = NULL; + + // Activate one menu + + for( i = 0; i < menuCount; i++ ) + { + if( Q_stricmp( Menus[i].window.name, p ) == 0 ) + { + m = &Menus[i]; + if(! Menus_ReplaceActive( m ) ) + return NULL; + break; + } + } + return m; +} + void Item_Init( itemDef_t *item ) { @@ -6944,6 +7017,15 @@ qboolean ItemParse_onTextEntry( itemDef_t *item, int handle ) return qtrue; } + +qboolean ItemParse_onCharEntry( itemDef_t *item, int handle ) +{ + if( !PC_Script_Parse( handle, &item->onCharEntry ) ) + return qfalse; + + return qtrue; +} + qboolean ItemParse_action( itemDef_t *item, int handle ) { if( !PC_Script_Parse( handle, &item->action ) ) @@ -7245,6 +7327,7 @@ keywordHash_t itemParseKeywords[] = { {"mouseEnterText", ItemParse_mouseEnterText, TYPE_ANY}, {"mouseExitText", ItemParse_mouseExitText, TYPE_ANY}, {"onTextEntry", ItemParse_onTextEntry, TYPE_ANY}, + {"onCharEntry", ItemParse_onCharEntry, TYPE_ANY}, {"action", ItemParse_action, TYPE_ANY}, {"cvar", ItemParse_cvar, TYPE_ANY}, {"maxChars", ItemParse_maxChars, TYPE_EDIT}, diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index d96eabf1..462a4bb4 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -284,6 +284,7 @@ typedef struct itemDef_s const char *onFocus; // select script const char *leaveFocus; // select script const char *onTextEntry; // called when text entered + const char *onCharEntry; // 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 @@ -476,9 +477,11 @@ int Menu_Count( void ); void Menu_New( int handle ); void Menu_PaintAll( void ); menuDef_t *Menus_ActivateByName( const char *p ); +menuDef_t *Menus_ReplaceActiveByName( const char *p ); void Menu_Reset( void ); qboolean Menus_AnyFullScreenVisible( void ); void Menus_Activate( menuDef_t *menu ); +qboolean Menus_ReplaceActive( menuDef_t *menu ); displayContextDef_t *Display_GetContext( void ); void *Display_CaptureItem( int x, int y ); -- cgit