Add option to auto-complete friends in chat first

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2024-02-05 13:47:07 +01:00
parent 5ddf6aefa1
commit c3805e2552
No known key found for this signature in database
GPG key ID: E13DFD4B47127951
3 changed files with 7 additions and 4 deletions

View file

@ -624,6 +624,7 @@ MACRO_CONFIG_INT(ClChatReset, cl_chat_reset, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_S
MACRO_CONFIG_INT(ClChatOld, cl_chat_old, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Old chat style: No tee, no background")
MACRO_CONFIG_INT(ClChatFontSize, cl_chat_size, 60, 10, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Chat font size")
MACRO_CONFIG_INT(ClChatWidth, cl_chat_width, 200, 140, 400, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Chat width")
MACRO_CONFIG_INT(ClChatCompleteFriendsFirst, cl_chat_complete_friends_first, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Auto-complete friend names first")
MACRO_CONFIG_INT(ClShowDirection, cl_show_direction, 1, 0, 3, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Show key presses (1 = other players', 2 = also your own, 3 = only your own")
MACRO_CONFIG_INT(ClOldGunPosition, cl_old_gun_position, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Tees hold gun a bit higher like in TW 0.6.1 and older")

View file

@ -310,13 +310,14 @@ bool CChat::OnInput(const IInput::CEvent &Event)
m_aPlayerCompletionList[m_PlayerCompletionListLength].ClientID = PlayerInfo->m_ClientID;
// The score for suggesting a player name is determined by the distance of the search input to the beginning of the player name
m_aPlayerCompletionList[m_PlayerCompletionListLength].Score = (int)(FoundInput - PlayerName);
m_aPlayerCompletionList[m_PlayerCompletionListLength].IsFriend = m_pClient->m_aClients[PlayerInfo->m_ClientID].m_Friend;
m_PlayerCompletionListLength++;
}
}
}
std::stable_sort(m_aPlayerCompletionList, m_aPlayerCompletionList + m_PlayerCompletionListLength,
[](const CRateablePlayer &p1, const CRateablePlayer &p2) -> bool {
return p1.Score < p2.Score;
[](const CCompletablePlayer &p1, const CCompletablePlayer &p2) -> bool {
return (g_Config.m_ClChatCompleteFriendsFirst && p1.IsFriend && !p2.IsFriend) || p1.Score < p2.Score;
});
}

View file

@ -86,12 +86,13 @@ class CChat : public CComponent
int m_PlaceholderOffset;
int m_PlaceholderLength;
static char ms_aDisplayText[MAX_LINE_LENGTH];
struct CRateablePlayer
struct CCompletablePlayer
{
int ClientID;
int Score;
bool IsFriend;
};
CRateablePlayer m_aPlayerCompletionList[MAX_CLIENTS];
CCompletablePlayer m_aPlayerCompletionList[MAX_CLIENTS];
int m_PlayerCompletionListLength;
struct CCommand