Skip to content

Commit

Permalink
add: /clear and /cls alias chat commands
Browse files Browse the repository at this point in the history
Very basic command processing, we can expand it if we end up having more client-side chat system commands, otherwise keep as-is.
  • Loading branch information
zpl-zak committed Feb 20, 2025
1 parent c45bddf commit 96b61e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion code/client/src/core/ui/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ namespace MafiaMP::Core::UI {

if (_wasFocused && gApplication->GetInput()->IsKeyPressed(FW_KEY_RETURN)) {
if (strlen(_inputText)) {
onMessageSentProc(_inputText);
if (!ProcessBuiltinCommand()) {
onMessageSentProc(_inputText);
}
_history.emplace(_history.begin(), _inputText);
strcpy(_inputText, "");
}
Expand All @@ -98,4 +100,17 @@ namespace MafiaMP::Core::UI {

ImGui::End();
}

void Chat::Clear() {
_chatMessages.clear();
}

bool Chat::ProcessBuiltinCommand() {
if (std::strcmp(_inputText, "/clear") == 0 || std::strcmp(_inputText, "/cls") == 0) {
Clear();
return true;
}

return false;
}
} // namespace MafiaMP::Core::UI
3 changes: 3 additions & 0 deletions code/client/src/core/ui/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ namespace MafiaMP::Core::UI {
_chatMessages.push_back(msg);
_newMsgArrived = true;
}

void Clear();
bool ProcessBuiltinCommand();
};
} // namespace MafiaMP::Core::UI

0 comments on commit 96b61e2

Please sign in to comment.