mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Added reverse tab completion logic
This commit is contained in:
parent
f137f77826
commit
7990d05ccb
1 changed files with 32 additions and 10 deletions
|
|
@ -140,6 +140,10 @@ static void djui_chat_box_input_enter(struct DjuiInputbox* chatInput) {
|
|||
sent_history_add_message(&sentHistory, chatInput->buffer);
|
||||
if (chatInput->buffer[0] == '/') {
|
||||
if (strcmp(chatInput->buffer, "/help") == 0 || strcmp(chatInput->buffer, "/?") == 0 || strcmp(chatInput->buffer, "/") == 0) {
|
||||
char tabcompletionHint[MAX_CHAT_MSG_LENGTH];
|
||||
snprintf(tabcompletionHint, sizeof(tabcompletionHint), "\\#ff2020\\%s \\#ffa020\\(%s)\\#ff2020\\:\\#000000\\",
|
||||
DLANG(CHAT, ALL_COMMANDS), DLANG(CHAT, TAB_COMPLETE_INFO));
|
||||
djui_chat_message_create(tabcompletionHint);
|
||||
display_chat_commands();
|
||||
} else if (!exec_chat_command(chatInput->buffer)) {
|
||||
char extendedUnknownCommandMessage[MAX_CHAT_MSG_LENGTH];
|
||||
|
|
@ -176,7 +180,7 @@ static char* get_main_command_from_input(const char* input) {
|
|||
return command;
|
||||
}
|
||||
|
||||
static bool complete_subcommand(const char* mainCommand, const char* subCommandPrefix) {
|
||||
static bool complete_subcommand(const char* mainCommand, const char* subCommandPrefix, bool reverse) {
|
||||
char** subcommands = smlua_get_chat_subcommands_list(mainCommand);
|
||||
|
||||
if (!subcommands || !subcommands[0]) {
|
||||
|
|
@ -192,7 +196,13 @@ static bool complete_subcommand(const char* mainCommand, const char* subCommandP
|
|||
|
||||
bool completionSuccess = false;
|
||||
if (foundSubCommandsCount > 0) {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex + 1) % foundSubCommandsCount;
|
||||
if (reverse) {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex <= 0)
|
||||
? foundSubCommandsCount - 1
|
||||
: (sCommandsTabCompletionIndex - 1) % foundSubCommandsCount;
|
||||
} else {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex + 1) % foundSubCommandsCount;
|
||||
}
|
||||
s32 currentIndex = 0;
|
||||
|
||||
for (s32 i = 0; subcommands[i] != NULL; i++) {
|
||||
|
|
@ -273,7 +283,7 @@ void djui_inputbox_replace_current_word(struct DjuiInputbox* inputbox, char* tex
|
|||
djui_inputbox_move_cursor_to_position(inputbox, currentWordStart + strlen(text));
|
||||
}
|
||||
|
||||
static bool complete_player_name(const char* namePrefix) {
|
||||
static bool complete_player_name(const char* namePrefix, bool reverse) {
|
||||
char** playerNames = smlua_get_chat_player_list();
|
||||
if (!playerNames || !playerNames[0]) {
|
||||
if (playerNames) {
|
||||
|
|
@ -291,7 +301,13 @@ static bool complete_player_name(const char* namePrefix) {
|
|||
|
||||
bool completionSuccess = false;
|
||||
if (foundNamesCount > 0) {
|
||||
sPlayersTabCompletionIndex = (sPlayersTabCompletionIndex + 1) % foundNamesCount;
|
||||
if (reverse) {
|
||||
sPlayersTabCompletionIndex = (sPlayersTabCompletionIndex <= 0)
|
||||
? foundNamesCount - 1
|
||||
: (sPlayersTabCompletionIndex - 1) % foundNamesCount;
|
||||
} else {
|
||||
sPlayersTabCompletionIndex = (sPlayersTabCompletionIndex + 1) % foundNamesCount;
|
||||
}
|
||||
s32 currentIndex = 0;
|
||||
|
||||
for (s32 i = 0; playerNames[i] != NULL; i++) {
|
||||
|
|
@ -314,14 +330,14 @@ static bool complete_player_name(const char* namePrefix) {
|
|||
return completionSuccess;
|
||||
}
|
||||
|
||||
static void handle_tab_completion(void) {
|
||||
static void handle_tab_completion(bool reverse) {
|
||||
bool alreadyTabCompleted = false;
|
||||
if (gDjuiChatBox->chatInput->buffer[0] == '/') {
|
||||
char* spacePosition = strrchr(sCommandsTabCompletionOriginalText, ' ');
|
||||
if (spacePosition != NULL) {
|
||||
char* mainCommand = get_main_command_from_input(sCommandsTabCompletionOriginalText);
|
||||
if (mainCommand) {
|
||||
if (!complete_subcommand(mainCommand + 1, spacePosition + 1)) {
|
||||
if (!complete_subcommand(mainCommand + 1, spacePosition + 1, reverse)) {
|
||||
reset_tab_completion_all();
|
||||
} else {
|
||||
alreadyTabCompleted = true;
|
||||
|
|
@ -344,7 +360,13 @@ static void handle_tab_completion(void) {
|
|||
}
|
||||
|
||||
if (foundCommandsCount > 0) {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex + 1) % foundCommandsCount;
|
||||
if (reverse) {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex <= 0)
|
||||
? foundCommandsCount - 1
|
||||
: (sCommandsTabCompletionIndex - 1) % foundCommandsCount;
|
||||
} else {
|
||||
sCommandsTabCompletionIndex = (sCommandsTabCompletionIndex + 1) % foundCommandsCount;
|
||||
}
|
||||
s32 currentIndex = 0;
|
||||
|
||||
for (s32 i = 0; commands[i] != NULL; i++) {
|
||||
|
|
@ -364,7 +386,7 @@ static void handle_tab_completion(void) {
|
|||
if (spacePositionB != NULL) {
|
||||
char* mainCommandB = get_main_command_from_input(sCommandsTabCompletionOriginalText);
|
||||
if (mainCommandB) {
|
||||
if (!complete_subcommand(mainCommandB + 1, spacePositionB + 1)) {
|
||||
if (!complete_subcommand(mainCommandB + 1, spacePositionB + 1, reverse)) {
|
||||
reset_tab_completion_all();
|
||||
} else {
|
||||
alreadyTabCompleted = true;
|
||||
|
|
@ -404,7 +426,7 @@ static void handle_tab_completion(void) {
|
|||
if (sPlayersTabCompletionIndex == -1) {
|
||||
snprintf(sPlayersTabCompletionOriginalText, MAX_CHAT_MSG_LENGTH, "%s", wordInfo.word);
|
||||
}
|
||||
if (!complete_player_name(sPlayersTabCompletionOriginalText)) {
|
||||
if (!complete_player_name(sPlayersTabCompletionOriginalText, reverse)) {
|
||||
reset_tab_completion_players();
|
||||
} else {
|
||||
alreadyTabCompleted = true;
|
||||
|
|
@ -457,7 +479,7 @@ static bool djui_chat_box_input_on_key_down(UNUSED struct DjuiBase* base, int sc
|
|||
gDjuiChatBox->scrollY -= pageAmount;
|
||||
break;
|
||||
case SCANCODE_TAB:
|
||||
handle_tab_completion();
|
||||
handle_tab_completion(gDjuiInputHeldShift);
|
||||
return true;
|
||||
case SCANCODE_ENTER:
|
||||
reset_tab_completion_all();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue