@@ -49,10 +49,9 @@ console_t consoleState;
4949
5050Console::Field g_consoleField (INT_MAX );
5151
52- cvar_t *con_animationSpeed;
53- cvar_t *con_animationType;
52+ Cvar::Range<Cvar::Cvar<float >> con_animationSpeed (" con_animationSpeed" , " speed of console fade in/out and scrolling" , Cvar::NONE , 3 , 0.1 , 100 );
5453
55- cvar_t *con_autoclear ;
54+ Cvar::Cvar< bool > con_autoclear ( " con_autoclear " , " drop input upon closing console " , Cvar:: NONE , true ) ;
5655Cvar::Cvar<bool > con_persistOnMapChange ( " con_persistOnMapChange" , " Current console input will be saved when changing map" , Cvar::NONE , false );
5756
5857/* *
@@ -61,9 +60,11 @@ Cvar::Cvar<bool> con_persistOnMapChange( "con_persistOnMapChange", "Current cons
6160 * 2: lock scrolling if in scrollback, even for own output
6261 * 3: always lock scrolling
6362 */
64- cvar_t *con_scrollLock;
63+ Cvar::Range<Cvar::Cvar<int >> con_scrollLock (" con_scrollLock" ,
64+ " go to end of console buffer upon (0) any output (1) pressing enter (2) new output when already at end (3) none of the above" ,
65+ Cvar::NONE , 2 , 0 , 3 );
6566
66- cvar_t * con_prompt;
67+ Cvar::Cvar<std::string> con_prompt ( " con_prompt " , " text at start of console input line " , Cvar:: NONE , " ^3-> " ) ;
6768
6869cvar_t *con_borderWidth;
6970cvar_t *con_borderColorAlpha;
@@ -84,12 +85,16 @@ cvar_t *con_colorGreen;
8485 * allows for debugging the console without using the consoles scrollback,
8586 * which might otherwise end in loops or unnecessary verbose output
8687 */
87- cvar_t *con_debug ;
88+ Cvar::Cvar< bool > con_debug ( " con_debug " , " show stats about console drawing " , Cvar:: NONE , false ) ;
8889
8990static const int ANIMATION_TYPE_NONE = 0 ;
9091static const int ANIMATION_TYPE_SCROLL_DOWN = 1 ;
9192static const int ANIMATION_TYPE_FADE = 2 ;
9293
94+ Cvar::Range<Cvar::Cvar<int >> con_animationType (" con_animationType" ,
95+ " show console open/close with (0) nothing (1) grow/shrink (2) fade in/out (3) both" ,
96+ Cvar::NONE , ANIMATION_TYPE_FADE , 0 , ANIMATION_TYPE_SCROLL_DOWN | ANIMATION_TYPE_FADE );
97+
9398/*
9499================
95100Con_ToggleConsole_f
@@ -98,7 +103,7 @@ Con_ToggleConsole_f
98103void Con_ToggleConsole_f ()
99104{
100105 // ydnar: persistent console input is more useful
101- if ( con_autoclear-> integer && !( con_persistOnMapChange.Get () && consoleState.changedMap ) )
106+ if ( con_autoclear. Get () && !( con_persistOnMapChange.Get () && consoleState.changedMap ) )
102107 {
103108 g_consoleField.Clear ();
104109 }
@@ -372,10 +377,9 @@ bool Con_CheckResize()
372377 consoleState.scrollLineIndex = consoleState.lines .size () - 1 ;
373378 }
374379
375- if ( con_prompt )
376380 {
377381 // 8 spaces for clock, 1 for cursor
378- g_console_field_width = consoleState.textWidthInChars - 9 - Color::StrlenNocolor ( con_prompt-> string );
382+ g_console_field_width = consoleState.textWidthInChars - 9 - Color::StrlenNocolor ( con_prompt. Get (). c_str () );
379383 g_consoleField.SetWidth (g_console_field_width);
380384 }
381385
@@ -389,13 +393,6 @@ Con_Init
389393*/
390394void Con_Init ()
391395{
392- con_animationSpeed = Cvar_Get ( " con_animationSpeed" , " 3" , 0 );
393- con_animationType = Cvar_Get ( " con_animationType" , " 2" , 0 );
394-
395- con_autoclear = Cvar_Get ( " con_autoclear" , " 1" , 0 );
396- con_scrollLock = Cvar_Get ( " con_scrollLock" , " 2" , 0 );
397-
398- con_prompt = Cvar_Get ( " con_prompt" , " ^3->" , 0 );
399396
400397 con_height = Cvar_Get ( " con_height" , " 55" , 0 );
401398 con_colorRed = Cvar_Get ( " con_colorRed" , " 0" , 0 );
@@ -412,8 +409,6 @@ void Con_Init()
412409 con_borderColorGreen = Cvar_Get ( " con_borderColorGreen" , " 1" , 0 );
413410 con_borderColorAlpha = Cvar_Get ( " con_borderColorAlpha" , " 0.2" , 0 );
414411
415- con_debug = Cvar_Get ( " con_debug" , " 0" , 0 );
416-
417412 // Done defining cvars for console colors
418413
419414 if ( !con_persistOnMapChange.Get () ) {
@@ -436,7 +431,7 @@ Con_Linefeed
436431*/
437432void Con_Linefeed ()
438433{
439- const int scrollLockMode = con_scrollLock ? con_scrollLock-> integer : 0 ;
434+ const int scrollLockMode = con_scrollLock. Get () ;
440435
441436 // fall down to input line if scroll lock is configured to do so
442437 if (scrollLockMode <= 0 )
@@ -644,7 +639,7 @@ void Con_DrawInput( int linePosition, float overrideAlpha )
644639 qtime_t realtime;
645640
646641 Com_RealTime ( &realtime );
647- Com_sprintf ( prompt, sizeof ( prompt ), " ^0[^3%02d%c%02d^0]^* %s" , realtime.tm_hour , ( realtime.tm_sec & 1 ) ? ' :' : ' ' , realtime.tm_min , con_prompt-> string );
642+ Com_sprintf ( prompt, sizeof ( prompt ), " ^0[^3%02d%c%02d^0]^* %s" , realtime.tm_hour , ( realtime.tm_sec & 1 ) ? ' :' : ' ' , realtime.tm_min , con_prompt. Get (). c_str () );
648643
649644 Color::Color color = console_color;
650645 color.SetAlpha ( consoleState.currentAlphaFactor * overrideAlpha );
@@ -769,7 +764,7 @@ void Con_DrawConsoleScrollbar()
769764 SCR_FillRect ( scrollBarX, scrollBarY, scrollBarWidth, scrollHandleLength, color );
770765 }
771766
772- if (con_debug-> integer ) {
767+ if (con_debug. Get () ) {
773768 Con_DrawRightFloatingTextLine ( 6 , Color::White, va ( " Scrollbar (px): Size %d HandleSize %d Position %d" , (int ) scrollBarLength, (int ) scrollHandleLength, (int ) scrollHandlePostition ) );
774769 }
775770}
@@ -848,7 +843,7 @@ void Con_DrawConsoleContent()
848843 return ;
849844 }
850845
851- if (con_debug-> integer ) {
846+ if (con_debug. Get () ) {
852847 Con_DrawRightFloatingTextLine ( 3 , Color::White, va ( " Buffer (lines): ScrollbackLength %d" , (int ) consoleState.lines .size () ) );
853848 Con_DrawRightFloatingTextLine ( 4 , Color::White, va ( " Display (lines): From %d to %d (%d a %i px)" ,
854849 0 , consoleState.scrollLineIndex , consoleState.visibleAmountOfLines , charHeight ) );
@@ -941,7 +936,7 @@ void Con_DrawAnimatedConsole()
941936 // build info, projectname/copyrights, meta information or similar
942937 Con_DrawAboutText ();
943938
944- if (con_debug-> integer ) {
939+ if (con_debug. Get () ) {
945940 Con_DrawRightFloatingTextLine ( 8 , Color::White, va ( " Animation: target %d current fraction %f alpha %f" , (int ) consoleState.isOpened , consoleState.currentAnimationFraction , consoleState.currentAlphaFactor ) );
946941 }
947942
@@ -1014,7 +1009,7 @@ void Con_UpdateConsoleState()
10141009 * calculate global alpha factor
10151010 * apply the fade animation if the type is set, otherwise remain completely visible
10161011 */
1017- consoleState.currentAlphaFactor = ( con_animationType-> integer & ANIMATION_TYPE_FADE ) ? consoleState.currentAnimationFraction : 1 .0f ;
1012+ consoleState.currentAlphaFactor = ( con_animationType. Get () & ANIMATION_TYPE_FADE ) ? consoleState.currentAnimationFraction : 1 .0f ;
10181013
10191014 /*
10201015 * calculate current console height
@@ -1033,7 +1028,7 @@ void Con_UpdateConsoleState()
10331028
10341029
10351030 // animate via scroll animation if the type is set
1036- if ( con_animationType-> integer & ANIMATION_TYPE_SCROLL_DOWN )
1031+ if ( con_animationType. Get () & ANIMATION_TYPE_SCROLL_DOWN )
10371032 {
10381033 consoleState.height *= consoleState.currentAnimationFraction ;
10391034 }
@@ -1067,10 +1062,6 @@ void Con_RunAnimatedConsole()
10671062 {
10681063 Cvar_Reset (con_height->name );
10691064 }
1070- if (con_animationSpeed->value <= 0 .0f )
1071- {
1072- Cvar_Reset (con_animationSpeed->name );
1073- }
10741065
10751066 Con_UpdateConsoleState ( );
10761067
@@ -1136,19 +1127,19 @@ void Con_RunConsole()
11361127
11371128 if ( !consoleState.isOpened && consoleState.currentAnimationFraction >= 0 .0f )
11381129 {
1139- consoleState.currentAnimationFraction -= con_animationSpeed-> value * cls.realFrametime * 0 .001f ;
1130+ consoleState.currentAnimationFraction -= con_animationSpeed. Get () * cls.realFrametime * 0 .001f ;
11401131
1141- if ( consoleState.currentAnimationFraction <= 0 .0f || con_animationType-> integer == ANIMATION_TYPE_NONE )
1132+ if ( consoleState.currentAnimationFraction <= 0 .0f || con_animationType. Get () == ANIMATION_TYPE_NONE )
11421133 { // we are closed, do some last onClose work
11431134 consoleState.currentAnimationFraction = 0 .0f ;
11441135 consoleState.lastReadLineIndex = consoleState.lines .size ()-1 ;
11451136 }
11461137 }
11471138 else if ( consoleState.isOpened && consoleState.currentAnimationFraction <= 1 .0f )
11481139 {
1149- consoleState.currentAnimationFraction += con_animationSpeed-> value * cls.realFrametime * 0 .001f ;
1140+ consoleState.currentAnimationFraction += con_animationSpeed. Get () * cls.realFrametime * 0 .001f ;
11501141
1151- if ( consoleState.currentAnimationFraction > 1 .0f || con_animationType-> integer == ANIMATION_TYPE_NONE )
1142+ if ( consoleState.currentAnimationFraction > 1 .0f || con_animationType. Get () == ANIMATION_TYPE_NONE )
11521143 {
11531144 consoleState.currentAnimationFraction = 1 .0f ;
11541145 }
@@ -1159,16 +1150,16 @@ void Con_RunConsole()
11591150 const float scrollDifference = std::max ( 0 .5f , fabsf ( consoleState.bottomDisplayedLine - consoleState.scrollLineIndex ) );
11601151 if ( consoleState.bottomDisplayedLine < consoleState.scrollLineIndex )
11611152 {
1162- consoleState.bottomDisplayedLine += con_animationSpeed-> value * cls.realFrametime * 0 .005f * scrollDifference;
1163- if ( consoleState.bottomDisplayedLine > consoleState.scrollLineIndex || con_animationType-> integer == ANIMATION_TYPE_NONE )
1153+ consoleState.bottomDisplayedLine += con_animationSpeed. Get () * cls.realFrametime * 0 .005f * scrollDifference;
1154+ if ( consoleState.bottomDisplayedLine > consoleState.scrollLineIndex || con_animationType. Get () == ANIMATION_TYPE_NONE )
11641155 {
11651156 consoleState.bottomDisplayedLine = consoleState.scrollLineIndex ;
11661157 }
11671158 }
11681159 else if ( consoleState.bottomDisplayedLine > consoleState.scrollLineIndex )
11691160 {
1170- consoleState.bottomDisplayedLine -= con_animationSpeed-> value * cls.realFrametime * 0 .005f * scrollDifference;
1171- if ( consoleState.bottomDisplayedLine < consoleState.scrollLineIndex || con_animationType-> integer == ANIMATION_TYPE_NONE )
1161+ consoleState.bottomDisplayedLine -= con_animationSpeed. Get () * cls.realFrametime * 0 .005f * scrollDifference;
1162+ if ( consoleState.bottomDisplayedLine < consoleState.scrollLineIndex || con_animationType. Get () == ANIMATION_TYPE_NONE )
11721163 {
11731164 consoleState.bottomDisplayedLine = consoleState.scrollLineIndex ;
11741165 }
0 commit comments