Add chat history #100

Merged
TheBrokenRail merged 6 commits from bigjango13/minecraft-pi-reborn:master into master 2024-03-19 02:06:04 +00:00
1 changed files with 2 additions and 8 deletions
Showing only changes of commit a6ad1994de - Show all commits

View File

@ -100,23 +100,17 @@ CUSTOM_VTABLE(chat_screen, Screen) {
// Up
local_history.at(self->history_pos) = self->chat->getText();
// Change
int old_pos = self->history_pos;
self->history_pos -= 1;
if (self->history_pos < 0) self->history_pos = local_history.size() - 1;
if (old_pos != self->history_pos) {
self->chat->setText(local_history.at(self->history_pos));
}
self->chat->setText(local_history.at(self->history_pos));
return;
bigjango13 marked this conversation as resolved
Review

Is this check needed? Because if old_pos == self->history_pos, wouldn't that just call setText with the current text, doing nothing?

Is this check needed? Because if `old_pos == self->history_pos`, wouldn't that just call `setText` with the current text, doing nothing?
Review

Yep, that's left over.

Yep, that's left over.
} else if (key == 0x28) {
// Down
local_history.at(self->history_pos) = self->chat->getText();
// Change
int old_pos = self->history_pos;
self->history_pos += 1;
if (self->history_pos > int(local_history.size()) - 1) self->history_pos = 0;
if (old_pos != self->history_pos) {
self->chat->setText(local_history.at(self->history_pos));
}
self->chat->setText(local_history.at(self->history_pos));
return;
}
}