MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CorrectHudMessage

Function CorrectHudMessage

Descent3/hudmessage.cpp:685–702  ·  view source on GitHub ↗

This function takes a HUD messages, ensures it isn't too long, and if it is, it correctly fixes it

Source from the content-addressed store, hash-verified

683
684// This function takes a HUD messages, ensures it isn't too long, and if it is, it correctly fixes it
685void CorrectHudMessage(char *str) {
686 // if (strlen(str)<=(HUD_MESSAGE_LENGTH-1))
687 if (grtext_GetTextLineWidth(str) <= Game_window_w)
688 return;
689
690 mprintf(0, "Message '%s' is too long!\n", str);
691 // the line is too long, we need to shorten it, but when we do, we need to make sure that it isn't in the middle
692 // of a color (0x01 0xFF 0xFF 0xFF)
693 str[HUD_MESSAGE_LENGTH - 1] = '\0';
694
695 // go back the last 3 characters and look for an 0x01, if we find one, than make it an '\0' to cut the string
696 for (int i = (HUD_MESSAGE_LENGTH - 2); i >= (HUD_MESSAGE_LENGTH - 4); i--) {
697 if (str[i] == 0x01) {
698 // we found a color start
699 str[i] = '\0';
700 }
701 }
702}
703
704// Called when the player hit the Multiplayer message key.
705// Puts the player in input mode, or if already inputting resets the hud input message.

Callers 2

AddLineToHUDMessagesFunction · 0.85
AddBlinkingHUDMessageFunction · 0.85

Calls 1

grtext_GetTextLineWidthFunction · 0.85

Tested by

no test coverage detected