1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

MasterWord: Display the last word in a different color for short input

Previously, the word was highlighted red in case it was not found in the
dictionary. That color was repurposed as a general "invalid input" color
to nudge the player that something was wrong with the last input.
Accordingly, the field m_last_word_not_in_dictionary was renamed to
m_last_word_invalid
This commit is contained in:
Arda Cinar 2022-12-08 14:39:48 +03:00 committed by Andreas Kling
parent cc5ea3aa4c
commit 1d687b0b31
2 changed files with 7 additions and 6 deletions

View file

@ -83,22 +83,23 @@ void WordGame::keydown_event(GUI::KeyEvent& event)
// If we can still add a letter and the key was alpha
if (m_current_guess.length() < m_num_letters && is_ascii_alpha(event.code_point())) {
m_current_guess = DeprecatedString::formatted("{}{}", m_current_guess, event.text().to_uppercase());
m_last_word_not_in_dictionary = false;
m_last_word_invalid = false;
}
// If backspace pressed and already have some letters entered
else if (event.key() == KeyCode::Key_Backspace && m_current_guess.length() > 0) {
m_current_guess = m_current_guess.substring(0, m_current_guess.length() - 1);
m_last_word_not_in_dictionary = false;
m_last_word_invalid = false;
}
// If return pressed
else if (event.key() == KeyCode::Key_Return) {
if (m_current_guess.length() < m_num_letters) {
show_message("Not enough letters"sv);
m_last_word_invalid = true;
} else if (!is_in_dictionary(m_current_guess)) {
show_message("Not in dictionary"sv);
m_last_word_not_in_dictionary = true;
m_last_word_invalid = true;
} else {
m_last_word_not_in_dictionary = false;
m_last_word_invalid = false;
clear_message();
add_guess(m_current_guess);
@ -147,7 +148,7 @@ void WordGame::paint_event(GUI::PaintEvent& event)
} else if (guess_index == m_guesses.size()) {
if (letter_index < m_current_guess.length())
painter.draw_text(this_rect, m_current_guess.substring_view(letter_index, 1), font(), Gfx::TextAlignment::Center, m_text_color);
if (m_last_word_not_in_dictionary) {
if (m_last_word_invalid) {
painter.fill_rect(this_rect, m_word_not_in_dict_color);
}
}