Alignment Issue Code Changes

Before you can add the code changes to implement the Alignment Issue feature you first must have added the code changes for the Scripted Hud as described here and here. That done, we can move on to the new code changes. All changes take place in the CGame module. It must be stressed that you have the latest version of the UI source code in your source tree before attempting any code changes.

 

cg_newdraw.c

About line 191 add :

static void CG_DrawPlayerArmorValue(rectDef_t *rect, float scale, vec4_t color,
qhandle_t shader, int textStyle, int align) {
char num[16];
int value;
centity_t *cent;
playerState_t *ps;
int tx;

About line 212 add :

		Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
switch( align )
{
case ITEM_ALIGN_LEFT:
tx = rect->x;
break;
case ITEM_ALIGN_RIGHT:
tx = rect->x + rect->w - value;
break;
case ITEM_ALIGN_CENTER:
tx = rect->x + ( rect->w / 2.0f ) - ( value / 2.0f );
break;
default:
tx = rect->x;
break;
}
CG_Text_Paint(tx, rect->y + rect->h, scale, color, num, 0, 0, textStyle);

}
}

About line 271 add :

static void CG_DrawPlayerAmmoValue(rectDef_t *rect, float scale, vec4_t color,
qhandle_t shader, int textStyle, int align) {
char num[16];
int value;
centity_t *cent;
playerState_t *ps;
int tx;

About line 291 add :

				Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
switch( align )
{
case ITEM_ALIGN_LEFT:
tx = rect->x;
break;
case ITEM_ALIGN_RIGHT:
tx = rect->x + rect->w - value;
break;
case ITEM_ALIGN_CENTER:
tx = rect->x + ( rect->w / 2.0f ) - ( value / 2.0f );
break;
default:
tx = rect->x;
break;
}
CG_Text_Paint(tx, rect->y + rect->h, scale, color, num, 0, 0, textStyle);

}

About line 627 add :

static void CG_DrawPlayerHealth(rectDef_t *rect, float scale, vec4_t color,
qhandle_t shader, int textStyle, int align ) {
playerState_t *ps;
int value;
char num[16];
int tx;

About line 643 add :

		Com_sprintf (num, sizeof(num), "%i", value);
value = CG_Text_Width(num, scale, 0);
switch( align )
{
case ITEM_ALIGN_LEFT:
tx = rect->x;
break;
case ITEM_ALIGN_RIGHT:
tx = rect->x + rect->w - value;
break;
case ITEM_ALIGN_CENTER:
tx = rect->x + ( rect->w / 2.0f ) - ( value / 2.0f );
break;
default:
tx = rect->x;
break;
}
CG_Text_Paint(tx, rect->y + rect->h, scale, color, num, 0, 0, textStyle);

}

About line 2785 add :

  case CG_PLAYER_ARMOR_VALUE:
CG_DrawPlayerArmorValue(&rect, scale, color, shader, textStyle, align);
break;
case CG_PLAYER_AMMO_ICON:
CG_DrawPlayerAmmoIcon(&rect, ownerDrawFlags & CG_SHOW_2DONLY);
break;
case CG_PLAYER_AMMO_ICON2D:
CG_DrawPlayerAmmoIcon(&rect, qtrue);
break;
case CG_PLAYER_AMMO_VALUE:
CG_DrawPlayerAmmoValue(&rect, scale, color, shader, textStyle, align);
break;

About line 2838 add :

  case CG_PLAYER_HEALTH:
CG_DrawPlayerHealth(&rect, scale, color, shader, textStyle, align);
break;

 

 

Return to Home Page