[iortcw] 64/152: All: Improve keyboard/joystick input in UI

Simon McVittie smcv at debian.org
Fri Sep 8 10:40:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.5a
in repository iortcw.

commit 75f5ae6a714adafa8079ab7c51c0b829be554f6d
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Sun Jun 5 13:18:00 2016 -0400

    All: Improve keyboard/joystick input in UI
    
    Make Yes/No, Multi, Slider, and Bind items allow enter key to change
    value without mouse over item. Add support for left and right arrow keys
    and joystick button 1-4 to Yes/No, Multi, and Slider and many item
    specific 'ownerdraw' key handlers.
---
 MP/code/ui/ui_main.c   | 357 +++++++++++++++++++++-------------------------
 MP/code/ui/ui_shared.c |  97 ++++++++++---
 MP/code/ui/ui_shared.h |   1 +
 SP/code/ui/ui_main.c   | 373 ++++++++++++++++++++++---------------------------
 SP/code/ui/ui_shared.c |  94 ++++++++++---
 SP/code/ui/ui_shared.h |   1 +
 6 files changed, 485 insertions(+), 438 deletions(-)

diff --git a/MP/code/ui/ui_main.c b/MP/code/ui/ui_main.c
index fd4c8f5..a8285ec 100644
--- a/MP/code/ui/ui_main.c
+++ b/MP/code/ui/ui_main.c
@@ -2118,11 +2118,12 @@ static void UI_DrawOpponent( rectDef_t *rect ) {
 #else
 		UI_PlayerInfo_SetModel( &info2, model );
 #endif  // #ifdef MISSIONPACK
-
 		UI_PlayerInfo_SetInfo( &info2, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MP40, qfalse );
-
+#ifdef MISSIONPACK
+		UI_RegisterClientModelname( &info2, model, headmodel, team );
+#else
 		UI_RegisterClientModelname( &info2, model );
-
+#endif  // #ifdef MISSIONPACK
 		updateOpponentModel = qfalse;
 	}
 
@@ -2936,106 +2937,105 @@ static qboolean UI_OwnerDrawVisible( int flags ) {
 	return vis;
 }
 
-static qboolean UI_Handicap_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_Handicap_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int h;
-		h = Com_Clamp( 5, 100, trap_Cvar_VariableValue( "handicap" ) );
-		if ( key == K_MOUSE2 ) {
-			h -= 5;
-		} else {
-			h += 5;
-		}
-		if ( h > 100 ) {
+
+		h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
+		h += 5 * select;
+
+		if (h > 100) {
 			h = 5;
-		} else if ( h < 5 ) {
+		} else if (h < 5) {
 			h = 100;
 		}
-		trap_Cvar_Set( "handicap", va( "%i", h ) );
+
+		trap_Cvar_SetValue( "handicap", h );
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_Effects_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_Effects_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.effectsColor += select;
 
-		if ( key == K_MOUSE2 ) {
-			uiInfo.effectsColor--;
-		} else {
-			uiInfo.effectsColor++;
-		}
-
-		if ( uiInfo.effectsColor > 6 ) {
+		if( uiInfo.effectsColor > 6 ) {
 			uiInfo.effectsColor = 0;
-		} else if ( uiInfo.effectsColor < 0 ) {
+		} else if (uiInfo.effectsColor < 0) {
 			uiInfo.effectsColor = 6;
 		}
 
-		trap_Cvar_SetValue( "color", uitogamecode[uiInfo.effectsColor] );
+		trap_Cvar_SetValue( "color1", uitogamecode[uiInfo.effectsColor] );
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_ClanName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_ClanName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i;
-		i = UI_TeamIndexFromName( UI_Cvar_VariableString( "ui_teamName" ) );
-		if ( uiInfo.teamList[i].cinematic >= 0 ) {
-			trap_CIN_StopCinematic( uiInfo.teamList[i].cinematic );
+
+		i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
+
+		if (uiInfo.teamList[i].cinematic >= 0) {
+			trap_CIN_StopCinematic(uiInfo.teamList[i].cinematic);
 			uiInfo.teamList[i].cinematic = -1;
 		}
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
-		if ( i >= uiInfo.teamCount ) {
+
+		i += select;
+
+		if (i >= uiInfo.teamCount) {
 			i = 0;
-		} else if ( i < 0 ) {
+		} else if (i < 0) {
 			i = uiInfo.teamCount - 1;
 		}
-		trap_Cvar_Set( "ui_teamName", uiInfo.teamList[i].teamName );
+
+		trap_Cvar_Set( "ui_teamName", uiInfo.teamList[i].teamName);
 		updateModel = qtrue;
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_GameType_HandleKey( int flags, float *special, int key, qboolean resetMap ) {
+static qboolean UI_GameType_HandleKey(int flags, float *special, int key, qboolean resetMap) {
 //#ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		int oldCount = UI_MapCountByGameType( qtrue );
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		int oldCount = UI_MapCountByGameType(qtrue);
 
 		// hard coded mess here
-		if ( key == K_MOUSE2 ) {
+		if (select < 0) {
 			ui_gameType.integer--;
-			if ( ui_gameType.integer == 2 ) {
+			if (ui_gameType.integer == 2) {
 				ui_gameType.integer = 1;
-			} else if ( ui_gameType.integer < 2 ) {
+			} else if (ui_gameType.integer < 2) {
 				ui_gameType.integer = uiInfo.numGameTypes - 1;
 			}
 		} else {
 			ui_gameType.integer++;
-			if ( ui_gameType.integer >= uiInfo.numGameTypes ) {
+			if (ui_gameType.integer >= uiInfo.numGameTypes) {
 				ui_gameType.integer = 1;
-			} else if ( ui_gameType.integer == 2 ) {
+			} else if (ui_gameType.integer == 2) {
 				ui_gameType.integer = 3;
 			}
 		}
-
-		if ( uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_TOURNAMENT ) {
-			trap_Cvar_Set( "ui_Q3Model", "1" );
+    
+		if (uiInfo.gameTypes[ui_gameType.integer].gtEnum < GT_TEAM) {
+			trap_Cvar_SetValue( "ui_Q3Model", 1 );
 		} else {
-			trap_Cvar_Set( "ui_Q3Model", "0" );
+			trap_Cvar_SetValue( "ui_Q3Model", 0 );
 		}
 
-		trap_Cvar_Set( "ui_gameType", va( "%d", ui_gameType.integer ) );
-		UI_SetCapFragLimits( qtrue );
-		UI_LoadBestScores( uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum );
-		if ( resetMap && oldCount != UI_MapCountByGameType( qtrue ) ) {
-			trap_Cvar_Set( "ui_currentMap", "0" );
-			Menu_SetFeederSelection( NULL, FEEDER_MAPS, 0, NULL );
+		trap_Cvar_SetValue("ui_gameType", ui_gameType.integer);
+		UI_SetCapFragLimits(qtrue);
+		UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
+		if (resetMap && oldCount != UI_MapCountByGameType(qtrue)) {
+			trap_Cvar_SetValue( "ui_currentMap", 0);
+			Menu_SetFeederSelection(NULL, FEEDER_MAPS, 0, NULL);
 		}
 		return qtrue;
 	}
@@ -3043,51 +3043,43 @@ static qboolean UI_GameType_HandleKey( int flags, float *special, int key, qbool
 	return qfalse;
 }
 
-static qboolean UI_NetGameType_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_NetGameType_HandleKey(int flags, float *special, int key) {
 //#ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-
-		if ( key == K_MOUSE2 ) {
-			ui_netGameType.integer--;
-		} else {
-			ui_netGameType.integer++;
-		}
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_netGameType.integer += select;
 
-		if ( ui_netGameType.integer < 0 ) {
+		if (ui_netGameType.integer < 0) {
 			ui_netGameType.integer = uiInfo.numGameTypes - 1;
-		} else if ( ui_netGameType.integer >= uiInfo.numGameTypes ) {
+		} else if (ui_netGameType.integer >= uiInfo.numGameTypes) {
 			ui_netGameType.integer = 0;
 		}
 
-		trap_Cvar_Set( "ui_netGameType", va( "%d", ui_netGameType.integer ) );
-		trap_Cvar_Set( "ui_actualnetGameType", va( "%d", uiInfo.gameTypes[ui_netGameType.integer].gtEnum ) );
-		trap_Cvar_Set( "ui_currentNetMap", "0" );
-		UI_MapCountByGameType( qfalse );
-		Menu_SetFeederSelection( NULL, FEEDER_ALLMAPS, 0, NULL );
+		trap_Cvar_SetValue( "ui_netGameType", ui_netGameType.integer);
+		trap_Cvar_SetValue( "ui_actualnetGameType", uiInfo.gameTypes[ui_netGameType.integer].gtEnum);
+		trap_Cvar_SetValue( "ui_currentNetMap", 0);
+		UI_MapCountByGameType(qfalse);
+		Menu_SetFeederSelection(NULL, FEEDER_ALLMAPS, 0, NULL);
 		return qtrue;
 	}
 //#endif	// #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_JoinGameType_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_JoinGameType_HandleKey(int flags, float *special, int key) {
 //#ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_joinGameType.integer += select;
 
-		if ( key == K_MOUSE2 ) {
-			ui_joinGameType.integer--;
-		} else {
-			ui_joinGameType.integer++;
-		}
-
-		if ( ui_joinGameType.integer < 0 ) {
+		if (ui_joinGameType.integer < 0) {
 			ui_joinGameType.integer = uiInfo.numJoinGameTypes - 1;
-		} else if ( ui_joinGameType.integer >= uiInfo.numJoinGameTypes ) {
+		} else if (ui_joinGameType.integer >= uiInfo.numJoinGameTypes) {
 			ui_joinGameType.integer = 0;
 		}
 
-		trap_Cvar_Set( "ui_joinGameType", va( "%d", ui_joinGameType.integer ) );
-		UI_BuildServerDisplayList( qtrue );
+		trap_Cvar_SetValue( "ui_joinGameType", ui_joinGameType.integer);
+		UI_BuildServerDisplayList(qtrue);
 		return qtrue;
 	}
 //#endif	// #ifdef MISSIONPACK
@@ -3096,81 +3088,71 @@ static qboolean UI_JoinGameType_HandleKey( int flags, float *special, int key )
 
 
 
-static qboolean UI_Skill_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_Skill_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i = trap_Cvar_VariableValue( "g_spSkill" );
 
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
+		i += select;
 
-		if ( i < 1 ) {
+		if (i < 1) {
 			i = numSkillLevels;
-		} else if ( i > numSkillLevels ) {
+		} else if (i > numSkillLevels) {
 			i = 1;
 		}
 
-		trap_Cvar_Set( "g_spSkill", va( "%i", i ) );
+		trap_Cvar_SetValue("g_spSkill", i);
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_TeamName_HandleKey( int flags, float *special, int key, qboolean blue ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_TeamName_HandleKey(int flags, float *special, int key, qboolean blue) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i;
-		i = UI_TeamIndexFromName( UI_Cvar_VariableString( ( blue ) ? "ui_blueTeam" : "ui_redTeam" ) );
 
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
+		i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam"));
+		i += select;
 
-		if ( i >= uiInfo.teamCount ) {
+		if (i >= uiInfo.teamCount) {
 			i = 0;
-		} else if ( i < 0 ) {
+		} else if (i < 0) {
 			i = uiInfo.teamCount - 1;
 		}
 
-		trap_Cvar_Set( ( blue ) ? "ui_blueTeam" : "ui_redTeam", uiInfo.teamList[i].teamName );
-
+		trap_Cvar_Set( (blue) ? "ui_blueTeam" : "ui_redTeam", uiInfo.teamList[i].teamName);
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_TeamMember_HandleKey( int flags, float *special, int key, qboolean blue, int num ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_TeamMember_HandleKey(int flags, float *special, int key, qboolean blue, int num) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		// 0 - None
 		// 1 - Human
 		// 2..NumCharacters - Bot
-		char *cvar = va( blue ? "ui_blueteam%i" : "ui_redteam%i", num );
-		int value = trap_Cvar_VariableValue( cvar );
+		char *cvar = va(blue ? "ui_blueteam%i" : "ui_redteam%i", num);
+		int value = trap_Cvar_VariableValue(cvar);
 
-		if ( key == K_MOUSE2 ) {
-			value--;
-		} else {
-			value++;
-		}
+		value += select;
 
-		if ( ui_actualNetGameType.integer >= GT_TEAM ) {
-			if ( value >= uiInfo.characterCount + 2 ) {
+		if (ui_actualNetGameType.integer >= GT_TEAM) {
+			if (value >= uiInfo.characterCount + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = uiInfo.characterCount + 2 - 1;
 			}
 		} else {
-			if ( value >= UI_GetNumBots() + 2 ) {
+			if (value >= UI_GetNumBots() + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = UI_GetNumBots() + 2 - 1;
 			}
 		}
 
-		trap_Cvar_Set( cvar, va( "%i", value ) );
+		trap_Cvar_SetValue(cvar, value);
 		return qtrue;
 	}
 	return qfalse;
@@ -3178,13 +3160,9 @@ static qboolean UI_TeamMember_HandleKey( int flags, float *special, int key, qbo
 
 static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 //#ifdef MISSIONPACK
-	if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
-		
-		if (key == K_MOUSE2) {
-			ui_netSource.integer--;
-		} else {
-			ui_netSource.integer++;
-		}
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_netSource.integer += select;
 
 		if(ui_netSource.integer >= UIAS_GLOBAL1 && ui_netSource.integer <= UIAS_GLOBAL5)
 		{
@@ -3196,12 +3174,8 @@ static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 				trap_Cvar_VariableStringBuffer(cvarname, masterstr, sizeof(masterstr));
 				if(*masterstr)
 					break;
-			
-				if (key == K_MOUSE2) {
-					ui_netSource.integer--;
-				} else {
-					ui_netSource.integer++;
-				}
+
+				ui_netSource.integer += select;
 			}
 		}
 
@@ -3215,38 +3189,35 @@ static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 		if (!(ui_netSource.integer >= UIAS_GLOBAL1 && ui_netSource.integer <= UIAS_GLOBAL5)) {
 			UI_StartServerRefresh(qtrue);
 		}
-		trap_Cvar_Set( "ui_netSource", va("%d", ui_netSource.integer));
+		trap_Cvar_SetValue( "ui_netSource", ui_netSource.integer);
 		return qtrue;
 	}
 //#endif	// #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_NetFilter_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_NetFilter_HandleKey(int flags, float *special, int key) {
 //#ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-
-		if ( key == K_MOUSE2 ) {
-			ui_serverFilterType.integer--;
-		} else {
-			ui_serverFilterType.integer++;
-		}
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_serverFilterType.integer += select;
 
-		if ( ui_serverFilterType.integer >= numServerFilters ) {
+		if (ui_serverFilterType.integer >= numServerFilters) {
 			ui_serverFilterType.integer = 0;
-		} else if ( ui_serverFilterType.integer < 0 ) {
+		} else if (ui_serverFilterType.integer < 0) {
 			ui_serverFilterType.integer = numServerFilters - 1;
 		}
-		UI_BuildServerDisplayList( qtrue );
+		UI_BuildServerDisplayList(qtrue);
 		return qtrue;
 	}
 //#endif	// #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_OpponentName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
+static qboolean UI_OpponentName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		if (select < 0) {
 			UI_PriorOpponent();
 		} else {
 			UI_NextOpponent();
@@ -3256,27 +3227,24 @@ static qboolean UI_OpponentName_HandleKey( int flags, float *special, int key )
 	return qfalse;
 }
 
-static qboolean UI_BotName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		int game = trap_Cvar_VariableValue( "g_gametype" );
+static qboolean UI_BotName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		int game = trap_Cvar_VariableValue("g_gametype");
 		int value = uiInfo.botIndex;
 
-		if ( key == K_MOUSE2 ) {
-			value--;
-		} else {
-			value++;
-		}
+		value += select;
 
-		if ( game >= GT_TEAM ) {
-			if ( value >= uiInfo.characterCount + 2 ) {
+		if (game >= GT_TEAM) {
+			if (value >= uiInfo.characterCount + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = uiInfo.characterCount + 2 - 1;
 			}
 		} else {
-			if ( value >= UI_GetNumBots() + 2 ) {
+			if (value >= UI_GetNumBots() + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = UI_GetNumBots() + 2 - 1;
 			}
 		}
@@ -3286,45 +3254,41 @@ static qboolean UI_BotName_HandleKey( int flags, float *special, int key ) {
 	return qfalse;
 }
 
-static qboolean UI_BotSkill_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
-			uiInfo.skillIndex--;
-		} else {
-			uiInfo.skillIndex++;
-		}
-		if ( uiInfo.skillIndex >= numSkillLevels ) {
+static qboolean UI_BotSkill_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.skillIndex += select;
+
+		if (uiInfo.skillIndex >= numSkillLevels) {
 			uiInfo.skillIndex = 0;
-		} else if ( uiInfo.skillIndex < 0 ) {
-			uiInfo.skillIndex = numSkillLevels - 1;
+		} else if (uiInfo.skillIndex < 0) {
+			uiInfo.skillIndex = numSkillLevels-1;
 		}
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_RedBlue_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_RedBlue_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		uiInfo.redBlue ^= 1;
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_Crosshair_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
-			uiInfo.currentCrosshair--;
-		} else {
-			uiInfo.currentCrosshair++;
-		}
+static qboolean UI_Crosshair_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.currentCrosshair += select;
 
-		if ( uiInfo.currentCrosshair >= NUM_CROSSHAIRS ) {
+		if (uiInfo.currentCrosshair >= NUM_CROSSHAIRS) {
 			uiInfo.currentCrosshair = 0;
-		} else if ( uiInfo.currentCrosshair < 0 ) {
+		} else if (uiInfo.currentCrosshair < 0) {
 			uiInfo.currentCrosshair = NUM_CROSSHAIRS - 1;
 		}
-		trap_Cvar_Set( "cg_drawCrosshair", va( "%d", uiInfo.currentCrosshair ) );
+		trap_Cvar_SetValue("cg_drawCrosshair", uiInfo.currentCrosshair);
 		return qtrue;
 	}
 	return qfalse;
@@ -3332,34 +3296,31 @@ static qboolean UI_Crosshair_HandleKey( int flags, float *special, int key ) {
 
 
 
-static qboolean UI_SelectedPlayer_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_SelectedPlayer_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int selected;
 
 		UI_BuildPlayerList();
-		if ( !uiInfo.teamLeader ) {
+		if (!uiInfo.teamLeader) {
 			return qfalse;
 		}
-		selected = trap_Cvar_VariableValue( "cg_selectedPlayer" );
+		selected = trap_Cvar_VariableValue("cg_selectedPlayer");
 
-		if ( key == K_MOUSE2 ) {
-			selected--;
-		} else {
-			selected++;
-		}
+		selected += select;
 
-		if ( selected > uiInfo.myTeamCount ) {
+		if (selected > uiInfo.myTeamCount) {
 			selected = 0;
-		} else if ( selected < 0 ) {
+		} else if (selected < 0) {
 			selected = uiInfo.myTeamCount;
 		}
 
-		if ( selected == uiInfo.myTeamCount ) {
-			trap_Cvar_Set( "cg_selectedPlayerName", "Everyone" );
+		if (selected == uiInfo.myTeamCount) {
+			trap_Cvar_Set( "cg_selectedPlayerName", "Everyone");
 		} else {
-			trap_Cvar_Set( "cg_selectedPlayerName", uiInfo.teamNames[selected] );
+			trap_Cvar_Set( "cg_selectedPlayerName", uiInfo.teamNames[selected]);
 		}
-		trap_Cvar_Set( "cg_selectedPlayer", va( "%d", selected ) );
+		trap_Cvar_SetValue( "cg_selectedPlayer", selected);
 	}
 	return qfalse;
 }
diff --git a/MP/code/ui/ui_shared.c b/MP/code/ui/ui_shared.c
index 0dae2a3..31a9a2a 100644
--- a/MP/code/ui/ui_shared.c
+++ b/MP/code/ui/ui_shared.c
@@ -2314,13 +2314,19 @@ qboolean Item_ListBox_HandleKey( itemDef_t *item, int key, qboolean down, qboole
 }
 
 qboolean Item_YesNo_HandleKey( itemDef_t *item, int key ) {
-	if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && item->window.flags & WINDOW_HASFOCUS && item->cvar ) {
-		if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
-			// ATVI Wolfenstein Misc #462
-			// added the flag to toggle via action script only
-			if ( !( item->cvarFlags & CVAR_NOTOGGLE ) ) {
-				DC->setCVar( item->cvar, va( "%i", !DC->getCVarValue( item->cvar ) ) );
+	if (item->cvar) {
+		qboolean action = qfalse;
+		if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
+			if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
+				action = qtrue;
 			}
+		} else if (UI_SelectForKey(key) != 0) {
+			action = qtrue;
+ 		}
+		// ATVI Wolfenstein Misc #462
+		// added the flag to toggle via action script only
+		if (action && !(item->cvarFlags & CVAR_NOTOGGLE)) {
+			DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar)));
 			return qtrue;
 		}
 	}
@@ -2390,11 +2396,21 @@ const char *Item_Multi_Setting( itemDef_t *item ) {
 qboolean Item_Multi_HandleKey( itemDef_t *item, int key ) {
 	multiDef_t *multiPtr = (multiDef_t*)item->typeData;
 	if ( multiPtr ) {
-		if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && item->window.flags & WINDOW_HASFOCUS && item->cvar ) {
-			if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
-				int current = Item_Multi_FindCvarByValue( item ) + 1;
+		if (item->cvar) {
+			int select = 0;
+			if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
+				if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
+					select = (key == K_MOUSE2) ? -1 : 1;
+				}
+			} else {
+				select = UI_SelectForKey(key);
+			}
+			if (select != 0) {
+				int current = Item_Multi_FindCvarByValue(item) + select;
 				int max = Item_Multi_CountSettings( item );
-				if ( current < 0 || current >= max ) {
+				if ( current < 0 ) {
+					current = max-1;
+				} else if ( current >= max ) {
 					current = 0;
 				}
 				if ( multiPtr->strDef ) {
@@ -2720,10 +2736,10 @@ qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down ) {
 	float x, value, width, work;
 
 	//DC->Print("slider handle key\n");
-	if ( item->window.flags & WINDOW_HASFOCUS && item->cvar && Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) ) {
-		if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
+	if (item->cvar) {
+		if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
 			editFieldDef_t *editDef = item->typeData;
-			if ( editDef ) {
+			if (editDef && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
 				rectDef_t testRect;
 				width = SLIDER_WIDTH;
 				if ( item->text ) {
@@ -2750,6 +2766,23 @@ qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down ) {
 					return qtrue;
 				}
 			}
+		} else {
+			int select = UI_SelectForKey(key);
+			if (select != 0) {
+				editFieldDef_t *editDef = item->typeData;
+				if (editDef) {
+					// 20 is number of steps
+					value = DC->getCVarValue(item->cvar) + (((editDef->maxVal - editDef->minVal)/20) * select);
+
+					if (value < editDef->minVal)
+						value = editDef->minVal;
+					else if (value > editDef->maxVal)
+						value = editDef->maxVal;
+
+					DC->setCVar(item->cvar, va("%f", value));
+					return qtrue;
+				}
+			}
 		}
 	}
 	DC->Print( "slider handle key exit\n" );
@@ -2992,6 +3025,32 @@ static rectDef_t *Item_CorrectedTextRect( itemDef_t *item ) {
 	return ▭
 }
 
+// menu item key horizontal action: -1 = previous value, 1 = next value, 0 = no change
+int UI_SelectForKey(int key)
+{
+	switch (key) {
+		case K_MOUSE1:
+		case K_MOUSE3:
+		case K_ENTER:
+		case K_KP_ENTER:
+		case K_RIGHTARROW:
+		case K_KP_RIGHTARROW:
+		case K_JOY1:
+		case K_JOY2:
+		case K_JOY3:
+		case K_JOY4:
+			return 1; // next
+
+		case K_MOUSE2:
+		case K_LEFTARROW:
+		case K_KP_LEFTARROW:
+			return -1; // previous
+	}
+
+	// no change
+	return 0;
+}
+
 void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) {
 	int i;
 	itemDef_t *item = NULL;
@@ -3141,7 +3200,6 @@ void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) {
 	case K_AUX14:
 	case K_AUX15:
 	case K_AUX16:
-		break;
 	case K_KP_ENTER:
 	case K_ENTER:
 	case K_MOUSE3:
@@ -3940,15 +3998,18 @@ qboolean Item_Bind_HandleKey( itemDef_t *item, int key, qboolean down ) {
 	int id;
 	int i;
 
-	if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && !g_waitingForKey ) {
-		if ( down && ( key == K_MOUSE1 || key == K_ENTER ) ) {
+	if (!g_waitingForKey)
+	{
+		if (down && ((key == K_MOUSE1 && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory))
+				|| key == K_ENTER || key == K_KP_ENTER || key == K_JOY1 || key == K_JOY2 || key == K_JOY3 || key == K_JOY4)) {
 			g_waitingForKey = qtrue;
 			g_bindItem = item;
 		}
 		return qtrue;
-	} else
+	}
+	else
 	{
-		if ( !g_waitingForKey || g_bindItem == NULL ) {
+		if (g_bindItem == NULL) {
 			return qtrue;
 		}
 
diff --git a/MP/code/ui/ui_shared.h b/MP/code/ui/ui_shared.h
index d4fb4f5..875eff4 100644
--- a/MP/code/ui/ui_shared.h
+++ b/MP/code/ui/ui_shared.h
@@ -462,6 +462,7 @@ void Menu_Reset( void );
 qboolean Menus_AnyFullScreenVisible( void );
 void  Menus_Activate( menuDef_t *menu );
 
+int UI_SelectForKey(int key);
 displayContextDef_t *Display_GetContext( void );
 void        *Display_CaptureItem( int x, int y );
 qboolean    Display_MouseMove( void *p, int x, int y );
diff --git a/SP/code/ui/ui_main.c b/SP/code/ui/ui_main.c
index 875b4dd..81e85a8 100644
--- a/SP/code/ui/ui_main.c
+++ b/SP/code/ui/ui_main.c
@@ -2083,7 +2083,11 @@ static void UI_DrawOpponent( rectDef_t *rect ) {
 		UI_PlayerInfo_SetModel( &info2, model );
 #endif  // #ifdef MISSIONPACK
 		UI_PlayerInfo_SetInfo( &info2, LEGS_IDLE, TORSO_STAND, viewangles, vec3_origin, WP_MP40, qfalse );
+#ifdef MISSIONPACK
+		UI_RegisterClientModelname( &info2, model, headmodel, team );
+#else
 		UI_RegisterClientModelname( &info2, model );
+#endif  // #ifdef MISSIONPACK
 		updateOpponentModel = qfalse;
 	}
 
@@ -2939,66 +2943,60 @@ static qboolean UI_OwnerDrawVisible( int flags ) {
 	return vis;
 }
 
-static qboolean UI_Handicap_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_Handicap_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int h;
-		h = Com_Clamp( 5, 100, trap_Cvar_VariableValue( "handicap" ) );
-		if ( key == K_MOUSE2 ) {
-			h -= 5;
-		} else {
-			h += 5;
-		}
-		if ( h > 100 ) {
+
+		h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
+		h += 5 * select;
+
+		if (h > 100) {
 			h = 5;
-		} else if ( h < 5 ) {
+		} else if (h < 5) {
 			h = 100;
 		}
-		trap_Cvar_Set( "handicap", va( "%i", h ) );
+
+		trap_Cvar_SetValue( "handicap", h );
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_Effects_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-
-		if ( key == K_MOUSE2 ) {
-			uiInfo.effectsColor--;
-		} else {
-			uiInfo.effectsColor++;
-		}
+static qboolean UI_Effects_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.effectsColor += select;
 
-		if ( uiInfo.effectsColor > 6 ) {
+		if( uiInfo.effectsColor > 6 ) {
 			uiInfo.effectsColor = 0;
-		} else if ( uiInfo.effectsColor < 0 ) {
+		} else if (uiInfo.effectsColor < 0) {
 			uiInfo.effectsColor = 6;
 		}
 
-		trap_Cvar_SetValue( "color", uitogamecode[uiInfo.effectsColor] );
+		trap_Cvar_SetValue( "color1", uitogamecode[uiInfo.effectsColor] );
 		return qtrue;
 	}
 	return qfalse;
 }
 
-
 //----(SA)	added
 static qboolean UI_SavegameName_HandleKey( int flags, float *special, int key ) {
 
 	// disable
 	return qfalse;
 #if 0
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i;
+
 		i = UI_SavegameIndexFromName( ui_savegameName.string );
 
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
-		if ( i >= uiInfo.savegameCount ) {
+		i += select;
+
+		if (i >= uiInfo.savegameCount) {
 			i = 0;
-		} else if ( i < 0 ) {
+		} else if (i < 0) {
 			i = uiInfo.savegameCount - 1;
 		}
 
@@ -3014,66 +3012,68 @@ static qboolean UI_SavegameName_HandleKey( int flags, float *special, int key )
 }
 //----(SA)	end
 
-
-static qboolean UI_ClanName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_ClanName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i;
-		i = UI_TeamIndexFromName( UI_Cvar_VariableString( "ui_teamName" ) );
-		if ( uiInfo.teamList[i].cinematic >= 0 ) {
-			trap_CIN_StopCinematic( uiInfo.teamList[i].cinematic );
+
+		i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
+
+		if (uiInfo.teamList[i].cinematic >= 0) {
+			trap_CIN_StopCinematic(uiInfo.teamList[i].cinematic);
 			uiInfo.teamList[i].cinematic = -1;
 		}
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
-		if ( i >= uiInfo.teamCount ) {
+
+		i += select;
+
+		if (i >= uiInfo.teamCount) {
 			i = 0;
-		} else if ( i < 0 ) {
+		} else if (i < 0) {
 			i = uiInfo.teamCount - 1;
 		}
-		trap_Cvar_Set( "ui_teamName", uiInfo.teamList[i].teamName );
+
+		trap_Cvar_Set( "ui_teamName", uiInfo.teamList[i].teamName);
 		updateModel = qtrue;
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_GameType_HandleKey( int flags, float *special, int key, qboolean resetMap ) {
+static qboolean UI_GameType_HandleKey(int flags, float *special, int key, qboolean resetMap) {
 #ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		int oldCount = UI_MapCountByGameType( qtrue );
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		int oldCount = UI_MapCountByGameType(qtrue);
 
 		// hard coded mess here
-		if ( key == K_MOUSE2 ) {
+		if (select < 0) {
 			ui_gameType.integer--;
-			if ( ui_gameType.integer == 2 ) {
+			if (ui_gameType.integer == 2) {
 				ui_gameType.integer = 1;
-			} else if ( ui_gameType.integer < 2 ) {
+			} else if (ui_gameType.integer < 2) {
 				ui_gameType.integer = uiInfo.numGameTypes - 1;
 			}
 		} else {
 			ui_gameType.integer++;
-			if ( ui_gameType.integer >= uiInfo.numGameTypes ) {
+			if (ui_gameType.integer >= uiInfo.numGameTypes) {
 				ui_gameType.integer = 1;
-			} else if ( ui_gameType.integer == 2 ) {
+			} else if (ui_gameType.integer == 2) {
 				ui_gameType.integer = 3;
 			}
 		}
-
-		if ( uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_TOURNAMENT ) {
-			trap_Cvar_Set( "ui_Q3Model", "1" );
+    
+		if (uiInfo.gameTypes[ui_gameType.integer].gtEnum < GT_TEAM) {
+			trap_Cvar_SetValue( "ui_Q3Model", 1 );
 		} else {
-			trap_Cvar_Set( "ui_Q3Model", "0" );
+			trap_Cvar_SetValue( "ui_Q3Model", 0 );
 		}
 
-		trap_Cvar_Set( "ui_gameType", va( "%d", ui_gameType.integer ) );
-		UI_SetCapFragLimits( qtrue );
-		UI_LoadBestScores( uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum );
-		if ( resetMap && oldCount != UI_MapCountByGameType( qtrue ) ) {
-			trap_Cvar_Set( "ui_currentMap", "0" );
-			Menu_SetFeederSelection( NULL, FEEDER_MAPS, 0, NULL );
+		trap_Cvar_SetValue("ui_gameType", ui_gameType.integer);
+		UI_SetCapFragLimits(qtrue);
+		UI_LoadBestScores(uiInfo.mapList[ui_currentMap.integer].mapLoadName, uiInfo.gameTypes[ui_gameType.integer].gtEnum);
+		if (resetMap && oldCount != UI_MapCountByGameType(qtrue)) {
+			trap_Cvar_SetValue( "ui_currentMap", 0);
+			Menu_SetFeederSelection(NULL, FEEDER_MAPS, 0, NULL);
 		}
 		return qtrue;
 	}
@@ -3081,51 +3081,43 @@ static qboolean UI_GameType_HandleKey( int flags, float *special, int key, qbool
 	return qfalse;
 }
 
-static qboolean UI_NetGameType_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_NetGameType_HandleKey(int flags, float *special, int key) {
 #ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_netGameType.integer += select;
 
-		if ( key == K_MOUSE2 ) {
-			ui_netGameType.integer--;
-		} else {
-			ui_netGameType.integer++;
-		}
-
-		if ( ui_netGameType.integer < 0 ) {
+		if (ui_netGameType.integer < 0) {
 			ui_netGameType.integer = uiInfo.numGameTypes - 1;
-		} else if ( ui_netGameType.integer >= uiInfo.numGameTypes ) {
+		} else if (ui_netGameType.integer >= uiInfo.numGameTypes) {
 			ui_netGameType.integer = 0;
 		}
 
-		trap_Cvar_Set( "ui_netGameType", va( "%d", ui_netGameType.integer ) );
-		trap_Cvar_Set( "ui_actualnetGameType", va( "%d", uiInfo.gameTypes[ui_netGameType.integer].gtEnum ) );
-		trap_Cvar_Set( "ui_currentNetMap", "0" );
-		UI_MapCountByGameType( qfalse );
-		Menu_SetFeederSelection( NULL, FEEDER_ALLMAPS, 0, NULL );
+		trap_Cvar_SetValue( "ui_netGameType", ui_netGameType.integer);
+		trap_Cvar_SetValue( "ui_actualnetGameType", uiInfo.gameTypes[ui_netGameType.integer].gtEnum);
+		trap_Cvar_SetValue( "ui_currentNetMap", 0);
+		UI_MapCountByGameType(qfalse);
+		Menu_SetFeederSelection(NULL, FEEDER_ALLMAPS, 0, NULL);
 		return qtrue;
 	}
 #endif  // #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_JoinGameType_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_JoinGameType_HandleKey(int flags, float *special, int key) {
 #ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_joinGameType.integer += select;
 
-		if ( key == K_MOUSE2 ) {
-			ui_joinGameType.integer--;
-		} else {
-			ui_joinGameType.integer++;
-		}
-
-		if ( ui_joinGameType.integer < 0 ) {
+		if (ui_joinGameType.integer < 0) {
 			ui_joinGameType.integer = uiInfo.numJoinGameTypes - 1;
-		} else if ( ui_joinGameType.integer >= uiInfo.numJoinGameTypes ) {
+		} else if (ui_joinGameType.integer >= uiInfo.numJoinGameTypes) {
 			ui_joinGameType.integer = 0;
 		}
 
-		trap_Cvar_Set( "ui_joinGameType", va( "%d", ui_joinGameType.integer ) );
-		UI_BuildServerDisplayList( qtrue );
+		trap_Cvar_SetValue( "ui_joinGameType", ui_joinGameType.integer);
+		UI_BuildServerDisplayList(qtrue);
 		return qtrue;
 	}
 #endif  // #ifdef MISSIONPACK
@@ -3134,81 +3126,71 @@ static qboolean UI_JoinGameType_HandleKey( int flags, float *special, int key )
 
 
 
-static qboolean UI_Skill_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_Skill_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i = trap_Cvar_VariableValue( "g_spSkill" );
 
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
+		i += select;
 
-		if ( i < 1 ) {
+		if (i < 1) {
 			i = numSkillLevels;
-		} else if ( i > numSkillLevels ) {
+		} else if (i > numSkillLevels) {
 			i = 1;
 		}
 
-		trap_Cvar_Set( "g_spSkill", va( "%i", i ) );
+		trap_Cvar_SetValue("g_spSkill", i);
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_TeamName_HandleKey( int flags, float *special, int key, qboolean blue ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_TeamName_HandleKey(int flags, float *special, int key, qboolean blue) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int i;
-		i = UI_TeamIndexFromName( UI_Cvar_VariableString( ( blue ) ? "ui_blueTeam" : "ui_redTeam" ) );
 
-		if ( key == K_MOUSE2 ) {
-			i--;
-		} else {
-			i++;
-		}
+		i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam"));
+		i += select;
 
-		if ( i >= uiInfo.teamCount ) {
+		if (i >= uiInfo.teamCount) {
 			i = 0;
-		} else if ( i < 0 ) {
+		} else if (i < 0) {
 			i = uiInfo.teamCount - 1;
 		}
 
-		trap_Cvar_Set( ( blue ) ? "ui_blueTeam" : "ui_redTeam", uiInfo.teamList[i].teamName );
-
+		trap_Cvar_Set( (blue) ? "ui_blueTeam" : "ui_redTeam", uiInfo.teamList[i].teamName);
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_TeamMember_HandleKey( int flags, float *special, int key, qboolean blue, int num ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_TeamMember_HandleKey(int flags, float *special, int key, qboolean blue, int num) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		// 0 - None
 		// 1 - Human
 		// 2..NumCharacters - Bot
-		char *cvar = va( blue ? "ui_blueteam%i" : "ui_redteam%i", num );
-		int value = trap_Cvar_VariableValue( cvar );
+		char *cvar = va(blue ? "ui_blueteam%i" : "ui_redteam%i", num);
+		int value = trap_Cvar_VariableValue(cvar);
 
-		if ( key == K_MOUSE2 ) {
-			value--;
-		} else {
-			value++;
-		}
+		value += select;
 
-		if ( ui_actualNetGameType.integer >= GT_TEAM ) {
-			if ( value >= uiInfo.characterCount + 2 ) {
+		if (ui_actualNetGameType.integer >= GT_TEAM) {
+			if (value >= uiInfo.characterCount + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = uiInfo.characterCount + 2 - 1;
 			}
 		} else {
-			if ( value >= UI_GetNumBots() + 2 ) {
+			if (value >= UI_GetNumBots() + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = UI_GetNumBots() + 2 - 1;
 			}
 		}
 
-		trap_Cvar_Set( cvar, va( "%i", value ) );
+		trap_Cvar_SetValue(cvar, value);
 		return qtrue;
 	}
 	return qfalse;
@@ -3216,13 +3198,9 @@ static qboolean UI_TeamMember_HandleKey( int flags, float *special, int key, qbo
 
 static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 #ifdef MISSIONPACK
-	if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER) {
-		
-		if (key == K_MOUSE2) {
-			ui_netSource.integer--;
-		} else {
-			ui_netSource.integer++;
-		}
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_netSource.integer += select;
 
 		if(ui_netSource.integer >= UIAS_GLOBAL1 && ui_netSource.integer <= UIAS_GLOBAL5)
 		{
@@ -3234,18 +3212,14 @@ static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 				trap_Cvar_VariableStringBuffer(cvarname, masterstr, sizeof(masterstr));
 				if(*masterstr)
 					break;
-			
-				if (key == K_MOUSE2) {
-					ui_netSource.integer--;
-				} else {
-					ui_netSource.integer++;
-				}
+
+				ui_netSource.integer += select;
 			}
 		}
 
 		if (ui_netSource.integer >= numNetSources) {
 			ui_netSource.integer = 0;
-		} else if ( ui_netSource.integer < 0 ) {
+		} else if (ui_netSource.integer < 0) {
 			ui_netSource.integer = numNetSources - 1;
 		}
 
@@ -3253,38 +3227,35 @@ static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
 		if (!(ui_netSource.integer >= UIAS_GLOBAL1 && ui_netSource.integer <= UIAS_GLOBAL5)) {
 			UI_StartServerRefresh(qtrue);
 		}
-		trap_Cvar_Set( "ui_netSource", va( "%d", ui_netSource.integer ) );
+		trap_Cvar_SetValue( "ui_netSource", ui_netSource.integer);
 		return qtrue;
 	}
 #endif  // #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_NetFilter_HandleKey( int flags, float *special, int key ) {
+static qboolean UI_NetFilter_HandleKey(int flags, float *special, int key) {
 #ifdef MISSIONPACK
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-
-		if ( key == K_MOUSE2 ) {
-			ui_serverFilterType.integer--;
-		} else {
-			ui_serverFilterType.integer++;
-		}
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		ui_serverFilterType.integer += select;
 
-		if ( ui_serverFilterType.integer >= numServerFilters ) {
+		if (ui_serverFilterType.integer >= numServerFilters) {
 			ui_serverFilterType.integer = 0;
-		} else if ( ui_serverFilterType.integer < 0 ) {
+		} else if (ui_serverFilterType.integer < 0) {
 			ui_serverFilterType.integer = numServerFilters - 1;
 		}
-		UI_BuildServerDisplayList( qtrue );
+		UI_BuildServerDisplayList(qtrue);
 		return qtrue;
 	}
 #endif  // #ifdef MISSIONPACK
 	return qfalse;
 }
 
-static qboolean UI_OpponentName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
+static qboolean UI_OpponentName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		if (select < 0) {
 			UI_PriorOpponent();
 		} else {
 			UI_NextOpponent();
@@ -3294,27 +3265,24 @@ static qboolean UI_OpponentName_HandleKey( int flags, float *special, int key )
 	return qfalse;
 }
 
-static qboolean UI_BotName_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		int game = trap_Cvar_VariableValue( "g_gametype" );
+static qboolean UI_BotName_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		int game = trap_Cvar_VariableValue("g_gametype");
 		int value = uiInfo.botIndex;
 
-		if ( key == K_MOUSE2 ) {
-			value--;
-		} else {
-			value++;
-		}
+		value += select;
 
-		if ( game >= GT_TEAM ) {
-			if ( value >= uiInfo.characterCount + 2 ) {
+		if (game >= GT_TEAM) {
+			if (value >= uiInfo.characterCount + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = uiInfo.characterCount + 2 - 1;
 			}
 		} else {
-			if ( value >= UI_GetNumBots() + 2 ) {
+			if (value >= UI_GetNumBots() + 2) {
 				value = 0;
-			} else if ( value < 0 ) {
+			} else if (value < 0) {
 				value = UI_GetNumBots() + 2 - 1;
 			}
 		}
@@ -3324,45 +3292,41 @@ static qboolean UI_BotName_HandleKey( int flags, float *special, int key ) {
 	return qfalse;
 }
 
-static qboolean UI_BotSkill_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
-			uiInfo.skillIndex--;
-		} else {
-			uiInfo.skillIndex++;
-		}
-		if ( uiInfo.skillIndex >= numSkillLevels ) {
+static qboolean UI_BotSkill_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.skillIndex += select;
+
+		if (uiInfo.skillIndex >= numSkillLevels) {
 			uiInfo.skillIndex = 0;
-		} else if ( uiInfo.skillIndex < 0 ) {
-			uiInfo.skillIndex = numSkillLevels - 1;
+		} else if (uiInfo.skillIndex < 0) {
+			uiInfo.skillIndex = numSkillLevels-1;
 		}
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_RedBlue_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_RedBlue_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		uiInfo.redBlue ^= 1;
 		return qtrue;
 	}
 	return qfalse;
 }
 
-static qboolean UI_Crosshair_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
-		if ( key == K_MOUSE2 ) {
-			uiInfo.currentCrosshair--;
-		} else {
-			uiInfo.currentCrosshair++;
-		}
+static qboolean UI_Crosshair_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
+		uiInfo.currentCrosshair += select;
 
-		if ( uiInfo.currentCrosshair >= NUM_CROSSHAIRS ) {
+		if (uiInfo.currentCrosshair >= NUM_CROSSHAIRS) {
 			uiInfo.currentCrosshair = 0;
-		} else if ( uiInfo.currentCrosshair < 0 ) {
+		} else if (uiInfo.currentCrosshair < 0) {
 			uiInfo.currentCrosshair = NUM_CROSSHAIRS - 1;
 		}
-		trap_Cvar_Set( "cg_drawCrosshair", va( "%d", uiInfo.currentCrosshair ) );
+		trap_Cvar_SetValue("cg_drawCrosshair", uiInfo.currentCrosshair);
 		return qtrue;
 	}
 	return qfalse;
@@ -3370,34 +3334,31 @@ static qboolean UI_Crosshair_HandleKey( int flags, float *special, int key ) {
 
 
 
-static qboolean UI_SelectedPlayer_HandleKey( int flags, float *special, int key ) {
-	if ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_ENTER || key == K_KP_ENTER ) {
+static qboolean UI_SelectedPlayer_HandleKey(int flags, float *special, int key) {
+	int select = UI_SelectForKey(key);
+	if (select != 0) {
 		int selected;
 
 		UI_BuildPlayerList();
-		if ( !uiInfo.teamLeader ) {
+		if (!uiInfo.teamLeader) {
 			return qfalse;
 		}
-		selected = trap_Cvar_VariableValue( "cg_selectedPlayer" );
+		selected = trap_Cvar_VariableValue("cg_selectedPlayer");
 
-		if ( key == K_MOUSE2 ) {
-			selected--;
-		} else {
-			selected++;
-		}
+		selected += select;
 
-		if ( selected > uiInfo.myTeamCount ) {
+		if (selected > uiInfo.myTeamCount) {
 			selected = 0;
-		} else if ( selected < 0 ) {
+		} else if (selected < 0) {
 			selected = uiInfo.myTeamCount;
 		}
 
-		if ( selected == uiInfo.myTeamCount ) {
-			trap_Cvar_Set( "cg_selectedPlayerName", "Everyone" );
+		if (selected == uiInfo.myTeamCount) {
+			trap_Cvar_Set( "cg_selectedPlayerName", "Everyone");
 		} else {
-			trap_Cvar_Set( "cg_selectedPlayerName", uiInfo.teamNames[selected] );
+			trap_Cvar_Set( "cg_selectedPlayerName", uiInfo.teamNames[selected]);
 		}
-		trap_Cvar_Set( "cg_selectedPlayer", va( "%d", selected ) );
+		trap_Cvar_SetValue( "cg_selectedPlayer", selected);
 	}
 	return qfalse;
 }
diff --git a/SP/code/ui/ui_shared.c b/SP/code/ui/ui_shared.c
index ed0efd1..bf77d9a 100644
--- a/SP/code/ui/ui_shared.c
+++ b/SP/code/ui/ui_shared.c
@@ -2309,10 +2309,17 @@ qboolean Item_ListBox_HandleKey( itemDef_t *item, int key, qboolean down, qboole
 }
 
 qboolean Item_YesNo_HandleKey( itemDef_t *item, int key ) {
-
-	if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && item->window.flags & WINDOW_HASFOCUS && item->cvar ) {
-		if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
-			DC->setCVar( item->cvar, va( "%i", !DC->getCVarValue( item->cvar ) ) );
+	if (item->cvar) {
+		qboolean action = qfalse;
+		if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
+			if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
+				action = qtrue;
+			}
+		} else if (UI_SelectForKey(key) != 0) {
+			action = qtrue;
+ 		}
+		if (action) {
+			DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar)));
 			return qtrue;
 		}
 	}
@@ -2384,11 +2391,21 @@ const char *Item_Multi_Setting( itemDef_t *item ) {
 qboolean Item_Multi_HandleKey( itemDef_t *item, int key ) {
 	multiDef_t *multiPtr = (multiDef_t*)item->typeData;
 	if ( multiPtr ) {
-		if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && item->window.flags & WINDOW_HASFOCUS && item->cvar ) {
-			if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
-				int current = Item_Multi_FindCvarByValue( item ) + 1;
+		if (item->cvar) {
+			int select = 0;
+			if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
+				if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
+					select = (key == K_MOUSE2) ? -1 : 1;
+				}
+			} else {
+				select = UI_SelectForKey(key);
+			}
+			if (select != 0) {
+				int current = Item_Multi_FindCvarByValue(item) + select;
 				int max = Item_Multi_CountSettings( item );
-				if ( current < 0 || current >= max ) {
+				if ( current < 0 ) {
+					current = max-1;
+				} else if ( current >= max ) {
 					current = 0;
 				}
 				if ( multiPtr->strDef ) {
@@ -2722,10 +2739,10 @@ qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down ) {
 	float x, value, width, work;
 
 	//DC->Print("slider handle key\n");
-	if ( item->window.flags & WINDOW_HASFOCUS && item->cvar && Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) ) {
-		if ( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 ) {
+	if (item->cvar) {
+		if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) {
 			editFieldDef_t *editDef = item->typeData;
-			if ( editDef ) {
+			if (editDef && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS) {
 				rectDef_t testRect;
 				width = SLIDER_WIDTH;
 				if ( item->text ) {
@@ -2752,6 +2769,23 @@ qboolean Item_Slider_HandleKey( itemDef_t *item, int key, qboolean down ) {
 					return qtrue;
 				}
 			}
+		} else {
+			int select = UI_SelectForKey(key);
+			if (select != 0) {
+				editFieldDef_t *editDef = item->typeData;
+				if (editDef) {
+					// 20 is number of steps
+					value = DC->getCVarValue(item->cvar) + (((editDef->maxVal - editDef->minVal)/20) * select);
+
+					if (value < editDef->minVal)
+						value = editDef->minVal;
+					else if (value > editDef->maxVal)
+						value = editDef->maxVal;
+
+					DC->setCVar(item->cvar, va("%f", value));
+					return qtrue;
+				}
+			}
 		}
 	}
 	//DC->Print("slider handle key exit\n");
@@ -2993,6 +3027,32 @@ static rectDef_t *Item_CorrectedTextRect( itemDef_t *item ) {
 	return ▭
 }
 
+// menu item key horizontal action: -1 = previous value, 1 = next value, 0 = no change
+int UI_SelectForKey(int key)
+{
+	switch (key) {
+		case K_MOUSE1:
+		case K_MOUSE3:
+		case K_ENTER:
+		case K_KP_ENTER:
+		case K_RIGHTARROW:
+		case K_KP_RIGHTARROW:
+		case K_JOY1:
+		case K_JOY2:
+		case K_JOY3:
+		case K_JOY4:
+			return 1; // next
+
+		case K_MOUSE2:
+		case K_LEFTARROW:
+		case K_KP_LEFTARROW:
+			return -1; // previous
+	}
+
+	// no change
+	return 0;
+}
+
 void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) {
 	int i;
 	itemDef_t *item = NULL;
@@ -3141,7 +3201,6 @@ void Menu_HandleKey( menuDef_t *menu, int key, qboolean down ) {
 	case K_AUX14:
 	case K_AUX15:
 	case K_AUX16:
-		break;
 	case K_KP_ENTER:
 	case K_ENTER:
 	case K_MOUSE3:
@@ -3886,15 +3945,18 @@ qboolean Item_Bind_HandleKey( itemDef_t *item, int key, qboolean down ) {
 	int id;
 	int i;
 
-	if ( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) && !g_waitingForKey ) {
-		if ( down && ( key == K_MOUSE1 || key == K_ENTER ) ) {
+	if (!g_waitingForKey)
+ 	{
+		if (down && ((key == K_MOUSE1 && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory))
+				|| key == K_ENTER || key == K_KP_ENTER || key == K_JOY1 || key == K_JOY2 || key == K_JOY3 || key == K_JOY4)) {
 			g_waitingForKey = qtrue;
 			g_bindItem = item;
 		}
 		return qtrue;
-	} else
+	}
+	else
 	{
-		if ( !g_waitingForKey || g_bindItem == NULL ) {
+		if (g_bindItem == NULL) {
 			return qtrue;
 		}
 
diff --git a/SP/code/ui/ui_shared.h b/SP/code/ui/ui_shared.h
index ca4d681..719718f 100644
--- a/SP/code/ui/ui_shared.h
+++ b/SP/code/ui/ui_shared.h
@@ -474,6 +474,7 @@ void Menu_Reset( void );
 qboolean Menus_AnyFullScreenVisible( void );
 void  Menus_Activate( menuDef_t *menu );
 
+int UI_SelectForKey(int key);
 displayContextDef_t *Display_GetContext( void );
 void        *Display_CaptureItem( int x, int y );
 qboolean    Display_MouseMove( void *p, int x, int y );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list