CLIENT: Render controller Glyphs on user interface

This commit is contained in:
cypress 2024-06-29 20:27:35 -07:00
parent 6a40f9aef3
commit 526ee7f1e6
3 changed files with 139 additions and 10 deletions

View file

@ -25,6 +25,9 @@
*/
float(string bind) Key_IsControllerGlyph;
void(vector position, string bind, vector scale) Key_DrawControllerGlyph;
// vid_ultrawide_limiter
#define ULTRAWIDE_OFFSET 250
@ -940,8 +943,17 @@ void(float width, float height) HUD_Useprint =
tokenize(findkeysforcommandex("+button7"));
usebutton = strtoupper(argv(0));
for(float i = 0; i < strlen(usebutton); i++) {
usespace = strcat(usespace, " ");
// If this is a gamepad button, the space we want to reserve
// in the usestring should be a fixed width.
if (Key_IsControllerGlyph(usebutton)) {
usespace = " ";
}
// Scale the space in the usestring for the bind according to
// the bind's name.
else {
for(float i = 0; i < strlen(usebutton); i++) {
usespace = strcat(usespace, " ");
}
}
switch (useprint_type) {
@ -1034,10 +1046,14 @@ void(float width, float height) HUD_Useprint =
drawstring([x3, g_height/2 + 78, 0], usecost, [12, 12, 0], [1, 1, 1], 1, 0);
}
// Draw highlighted usebutton (or button icon in the future)
// Draw highlighted usebutton
if (substring(usestring, 0, 4) == "Hold") {
button_width = x + stringwidth ("Hold ", 0, [12, 12, 0]);
drawstring([button_width, g_height/2 + 65, 0], usebutton, [12, 12, 0], [1, 1, 0], 1, 0);
if (Key_IsControllerGlyph(usebutton))
Key_DrawControllerGlyph([button_width - 5, g_height/2 + 60], usebutton, [22, 22]);
else
drawstring([button_width, g_height/2 + 65, 0], usebutton, [12, 12, 0], [1, 1, 0], 1, 0);
}
}
@ -1173,15 +1189,23 @@ void(float width, float height) HUD_BouncingBetty =
{
float top_x, bot_x, but_x;
string betty_key;
string betty_space;
string betty_space = "";
string activate_string, activate_string2;
tokenize(findkeysforcommandex("impulse 33"));
betty_key = strtoupper(argv(0));
betty_space = "";
for(float i = 0; i < strlen(betty_key); i++) {
betty_space = strcat(betty_space, " ");
// If this is a gamepad button, the space we want to reserve
// in the betty string should be a fixed width.
if (Key_IsControllerGlyph(betty_key)) {
betty_space = " ";
}
// Scale the space in the betty string for the bind according to
// the bind's name.
else {
for(float i = 0; i < strlen(betty_key); i++) {
betty_space = strcat(betty_space, " ");
}
}
activate_string = strcat("Press ", betty_space, " to place a");
@ -1195,7 +1219,11 @@ void(float width, float height) HUD_BouncingBetty =
// Draw the highlighted button
but_x = top_x + stringwidth("Press ", 0, [12, 12, 0]);
drawstring([but_x, g_height - 303], betty_key, [12, 12], [1, 1, 0], 1, 0);
if (Key_IsControllerGlyph(betty_key))
Key_DrawControllerGlyph([but_x - 5, g_height - 308], betty_key, [22, 22]);
else
drawstring([but_x, g_height - 303], betty_key, [12, 12], [1, 1, 0], 1, 0);
}
/*******************

View file

@ -619,6 +619,101 @@ noref void(float width, float height, float notmenu) CSQC_UpdateViewLoading =
drawstring([width/2 - (stringwidth("Loading...", 0, [14, 14])/2), height - 40, 0], "Loading...", [14, 14], [1, 1, 1], 1, 0);
};
//
// Key_IsControllerGlyph(bind)
// Returns TRUE if the string provided belongs to
// a gamepad/controller.
//
float(string bind) Key_IsControllerGlyph =
{
switch(bind) {
case "GP_A":
case "GP_B":
case "GP_X":
case "GP_Y":
case "GP_LSHOULDER":
case "GP_RSHOULDER":
case "GP_LTRIGGER":
case "GP_RTRIGGER":
case "GP_BACK":
case "GP_START":
case "GP_LTHUMB":
case "GP_RTHUMB":
case "GP_DPAD_UP":
case "GP_DPAD_DOWN":
case "GP_DPAD_LEFT":
case "GP_DPAD_RIGHT":
return true;
}
return false;
};
//
// Key_DrawControllerGlyph(position, bind, scale)
// Draws the associated glyph for the bind name from the
// Glyph tilemap at the provided position, with the
// provided scale.
//
void(vector position, string bind, vector scale) Key_DrawControllerGlyph =
{
vector tilemap_position = [0, 0];
// The coordinates in 0-1 range of each button in the glyph tilemap.
switch(bind) {
case "GP_A":
tilemap_position = [0, 0];
break;
case "GP_B":
tilemap_position = [0.125, 0];
break;
case "GP_X":
tilemap_position = [0.250, 0];
break;
case "GP_Y":
tilemap_position = [0.375, 0];
break;
case "GP_LSHOULDER":
tilemap_position = [0.250, 0.125];
break;
case "GP_RSHOULDER":
tilemap_position = [0.375, 0.125];
break;
case "GP_LTRIGGER":
tilemap_position = [0.500, 0.125];
break;
case "GP_RTRIGGER":
tilemap_position = [0.625, 0.125];
break;
case "GP_BACK":
tilemap_position = [0.875, 0.125];
break;
case "GP_START":
tilemap_position = [0.750, 0.125];
break;
case "GP_LTHUMB":
tilemap_position = [0, 0.125];
break;
case "GP_RTHUMB":
tilemap_position = [0.125, 0.125];
break;
case "GP_DPAD_UP":
tilemap_position = [0.500, 0];
break;
case "GP_DPAD_DOWN":
tilemap_position = [0.625, 0];
break;
case "GP_DPAD_LEFT":
tilemap_position = [0.750, 0];
break;
case "GP_DPAD_RIGHT":
tilemap_position = [0.875, 0];
break;
}
drawsubpic([position_x, position_y], [scale_x, scale_y], sprintf("gfx/controller_glyphs/%s.tga", cvar_string("cl_controllerglyphs")), [tilemap_position_x, tilemap_position_y], [0.125, 0.125], [1, 1, 1], 1);
};
#define SCALE_CONSTANT 8
//MOVEME

View file

@ -25,6 +25,9 @@
*/
float(string bind) Key_IsControllerGlyph;
void(vector position, string bind, vector scale) Key_DrawControllerGlyph;
float current_custom_map_page;
float custom_map_pages;
float last_active_custom_select;
@ -1744,7 +1747,10 @@ void() Draw_Extra_Controls =
if (buttoncon[i] == "01")
buttoncon[i] = "UNBOUND";
drawstring([320, 75+(20*i)], buttoncon[i], [g_height * 0.030, g_height * 0.030, 1], [0.8,0.8,0.8], 1, 0);
if (Key_IsControllerGlyph(buttoncon[i]))
Key_DrawControllerGlyph([320, 75+(20*i)], buttoncon[i], [22, 22]);
else
drawstring([320, 75+(20*i)], buttoncon[i], [g_height * 0.030, g_height * 0.030, 1], [0.8,0.8,0.8], 1, 0);
}
}