MasterWord: Use numeric InputBox for settings

And use proper ellipses and capitalization in related action text.
This commit is contained in:
thankyouverycool 2023-04-16 16:06:40 -04:00 committed by Andreas Kling
parent 14072ce8f0
commit a55d2be147
Notes: sideshowbarker 2024-07-17 18:13:59 +09:00

View file

@ -73,32 +73,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto settings_menu = TRY(window->try_add_menu("&Settings"));
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Word Length", [&](auto&) {
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Word Length...", [&](auto&) {
auto word_length = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);
auto word_length_string = String::number(word_length).release_value_but_fixme_should_propagate_errors();
if (GUI::InputBox::show(window, word_length_string, "Word length:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_word_length = AK::StringUtils::convert_to_uint(word_length_string);
if (!maybe_word_length.has_value() || maybe_word_length.value() < shortest_word || maybe_word_length.value() > longest_word) {
GUI::MessageBox::show(window, DeprecatedString::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord"sv);
return;
}
word_length = maybe_word_length.value();
auto result = GUI::InputBox::show_numeric(window, word_length, shortest_word, longest_word, "Word length"sv);
if (!result.is_error() && result.value() == GUI::InputBox::ExecResult::OK) {
Config::write_i32("MasterWord"sv, ""sv, "word_length"sv, word_length);
game.set_word_length(word_length);
}
})));
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Number Of Guesses", [&](auto&) {
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Number of Guesses...", [&](auto&) {
auto max_guesses = Config::read_i32("MasterWord"sv, ""sv, "max_guesses"sv, 5);
auto max_guesses_string = String::number(max_guesses).release_value_but_fixme_should_propagate_errors();
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_max_guesses = AK::StringUtils::convert_to_uint(max_guesses_string);
if (!maybe_max_guesses.has_value() || maybe_max_guesses.value() < 1 || maybe_max_guesses.value() > 20) {
GUI::MessageBox::show(window, "Please enter a number between 1 and 20."sv, "MasterWord"sv);
return;
}
max_guesses = maybe_max_guesses.value();
auto result = GUI::InputBox::show_numeric(window, max_guesses, 1, 20, "Number of guesses"sv);
if (!result.is_error() && result.value() == GUI::InputBox::ExecResult::OK) {
Config::write_i32("MasterWord"sv, ""sv, "max_guesses"sv, max_guesses);
game.set_max_guesses(max_guesses);
}