1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:57:34 +00:00

LibGUI+Userland: Make Dialog::ExecResult an enum class

This commit is contained in:
Sam Atkins 2022-05-13 13:10:27 +01:00 committed by Linus Groh
parent 1f82beded3
commit cdffe556c8
90 changed files with 232 additions and 232 deletions

View file

@ -74,10 +74,10 @@ GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t ta
button_layout.set_spacing(10);
buttonbox.add<GUI::Button>("Cancel").on_click = [this](auto) {
done(Dialog::ExecCancel);
done(ExecResult::Cancel);
};
buttonbox.add<GUI::Button>("OK").on_click = [this](auto) {
done(Dialog::ExecOK);
done(ExecResult::OK);
};
}

View file

@ -99,7 +99,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto change_settings = [&] {
auto size_dialog = GameSizeDialog::construct(window, board_size, target_tile, evil_ai);
if (size_dialog->exec() || size_dialog->result() != GUI::Dialog::ExecOK)
if (size_dialog->exec() != GUI::Dialog::ExecResult::OK)
return;
board_size = size_dialog->board_size();
@ -152,7 +152,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
"Congratulations!",
GUI::MessageBox::Type::Question,
GUI::MessageBox::InputType::YesNo);
if (want_to_continue == GUI::MessageBox::ExecYes)
if (want_to_continue == GUI::MessageBox::ExecResult::Yes)
game.set_want_to_continue();
else
start_a_new_game();

View file

@ -20,7 +20,7 @@ Game::Game()
{
set_override_cursor(Gfx::StandardCursor::Hidden);
auto level_dialog = LevelSelectDialog::show(m_board, window());
if (level_dialog != GUI::Dialog::ExecOK)
if (level_dialog != GUI::Dialog::ExecResult::OK)
m_board = -1;
set_paused(false);
start_timer(16);

View file

@ -20,7 +20,7 @@ LevelSelectDialog::LevelSelectDialog(Window* parent_window)
build();
}
int LevelSelectDialog::show(int& board_number, Window* parent_window)
GUI::Dialog::ExecResult LevelSelectDialog::show(int& board_number, Window* parent_window)
{
auto box = LevelSelectDialog::construct(parent_window);
box->set_resizable(false);
@ -47,12 +47,12 @@ void LevelSelectDialog::build()
level_list.add<GUI::Button>("Rainbow").on_click = [this](auto) {
m_level = -1;
done(Dialog::ExecOK);
done(ExecResult::OK);
};
level_list.add<GUI::Button>(":^)").on_click = [this](auto) {
m_level = 0;
done(Dialog::ExecOK);
done(ExecResult::OK);
};
}
}

View file

@ -13,7 +13,7 @@ class LevelSelectDialog : public GUI::Dialog {
C_OBJECT(LevelSelectDialog)
public:
virtual ~LevelSelectDialog() override = default;
static int show(int& board_number, Window* parent_window);
static ExecResult show(int& board_number, Window* parent_window);
int level() const { return m_level; }
private:

View file

@ -235,7 +235,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
Chess::Move move = { m_moving_square, target_square };
if (board().is_promotion_move(move)) {
auto promotion_dialog = PromotionDialog::construct(*this);
if (promotion_dialog->exec() == PromotionDialog::ExecOK)
if (promotion_dialog->exec() == PromotionDialog::ExecResult::OK)
move.promote_to = promotion_dialog->selected_piece();
}
@ -262,7 +262,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
update();
if (GUI::MessageBox::show(window(), "50 moves have elapsed without a capture. Claim Draw?", "Claim Draw?",
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
== GUI::Dialog::ExecYes) {
== GUI::Dialog::ExecResult::Yes) {
msg = "Draw by 50 move rule.";
} else {
over = false;
@ -275,7 +275,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
update();
if (GUI::MessageBox::show(window(), "The same board state has repeated three times. Claim Draw?", "Claim Draw?",
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
== GUI::Dialog::ExecYes) {
== GUI::Dialog::ExecResult::Yes) {
msg = "Draw by threefold repetition.";
} else {
over = false;
@ -691,7 +691,7 @@ int ChessWidget::resign()
}
auto result = GUI::MessageBox::show(window(), "Are you sure you wish to resign?", "Resign", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNo);
if (result != GUI::MessageBox::ExecYes)
if (result != GUI::MessageBox::ExecResult::Yes)
return -1;
board().set_resigned(m_board.turn());

View file

@ -28,7 +28,7 @@ PromotionDialog::PromotionDialog(ChessWidget& chess_widget)
button.set_icon(chess_widget.get_piece_graphic({ chess_widget.board().turn(), type }));
button.on_click = [this, type](auto) {
m_selected_piece = type;
done(ExecOK);
done(ExecResult::OK);
};
}
}

View file

@ -137,7 +137,7 @@ void Game::show_score_card(bool game_over)
auto& close_button = button_container.add<GUI::Button>("OK");
close_button.on_click = [&score_dialog](auto) {
score_dialog->done(GUI::Dialog::ExecOK);
score_dialog->done(GUI::Dialog::ExecResult::OK);
};
close_button.set_min_width(70);
close_button.resize(70, 30);

View file

@ -43,10 +43,10 @@ SettingsDialog::SettingsDialog(GUI::Window* parent, String player_name)
button_layout.set_spacing(10);
button_box.add<GUI::Button>("Cancel").on_click = [this](auto) {
done(Dialog::ExecCancel);
done(ExecResult::Cancel);
};
button_box.add<GUI::Button>("OK").on_click = [this](auto) {
done(Dialog::ExecOK);
done(ExecResult::OK);
};
}

View file

@ -75,7 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto change_settings = [&] {
auto settings_dialog = SettingsDialog::construct(window, player_name);
if (settings_dialog->exec() || settings_dialog->result() != GUI::Dialog::ExecOK)
if (settings_dialog->exec() != GUI::Dialog::ExecResult::OK)
return;
player_name = settings_dialog->player_name();

View file

@ -62,7 +62,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_action(GUI::Action::create("Set &Word Length", [&](auto&) {
auto word_length = Config::read_i32("MasterWord", "", "word_length", 5);
auto word_length_string = String::number(word_length);
if (GUI::InputBox::show(window, word_length_string, "Word length:", "MasterWord") == GUI::InputBox::ExecOK && !word_length_string.is_empty()) {
if (GUI::InputBox::show(window, word_length_string, "Word length:", "MasterWord") == GUI::InputBox::ExecResult::OK && !word_length_string.is_empty()) {
auto maybe_word_length = word_length_string.template to_uint();
if (!maybe_word_length.has_value() || maybe_word_length.value() < shortest_word || maybe_word_length.value() > longest_word) {
GUI::MessageBox::show(window, String::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord");
@ -78,7 +78,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_action(GUI::Action::create("Set &Number Of Guesses", [&](auto&) {
auto max_guesses = Config::read_i32("MasterWord", "", "max_guesses", 5);
auto max_guesses_string = String::number(max_guesses);
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:", "MasterWord") == GUI::InputBox::ExecOK && !max_guesses_string.is_empty()) {
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:", "MasterWord") == GUI::InputBox::ExecResult::OK && !max_guesses_string.is_empty()) {
auto maybe_max_guesses = max_guesses_string.template to_uint();
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.", "MasterWord");

View file

@ -9,7 +9,7 @@
#include "Field.h"
#include <Games/Minesweeper/MinesweeperCustomGameWindowGML.h>
int CustomGameDialog::show(GUI::Window* parent_window, Field& field)
GUI::Dialog::ExecResult CustomGameDialog::show(GUI::Window* parent_window, Field& field)
{
auto dialog = CustomGameDialog::construct(parent_window);
@ -24,12 +24,12 @@ int CustomGameDialog::show(GUI::Window* parent_window, Field& field)
auto result = dialog->exec();
if (result != GUI::Dialog::ExecOK)
if (result != ExecResult::OK)
return result;
field.set_field_size(Field::Difficulty::Custom, dialog->m_rows_spinbox->value(), dialog->m_columns_spinbox->value(), dialog->m_mines_spinbox->value());
return GUI::Dialog::ExecOK;
return ExecResult::OK;
}
void CustomGameDialog::set_max_mines()
@ -66,11 +66,11 @@ CustomGameDialog::CustomGameDialog(Window* parent_window)
};
m_ok_button->on_click = [this](auto) {
done(ExecResult::ExecOK);
done(ExecResult::OK);
};
m_cancel_button->on_click = [this](auto) {
done(ExecResult::ExecCancel);
done(ExecResult::Cancel);
};
set_max_mines();

View file

@ -17,7 +17,7 @@ class CustomGameDialog : public GUI::Dialog {
C_OBJECT(CustomGameDialog);
public:
static int show(GUI::Window* parent_window, Field& field);
static ExecResult show(GUI::Window* parent_window, Field& field);
private:
CustomGameDialog(GUI::Window* parent_window);

View file

@ -144,7 +144,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::YesNo);
if (result == GUI::MessageBox::ExecYes)
if (result == GUI::MessageBox::ExecResult::Yes)
return GUI::Window::CloseRequestDecision::Close;
else
return GUI::Window::CloseRequestDecision::StayOpen;

View file

@ -201,7 +201,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::YesNo);
if (result == GUI::MessageBox::ExecYes)
if (result == GUI::MessageBox::ExecResult::Yes)
return GUI::Window::CloseRequestDecision::Close;
else
return GUI::Window::CloseRequestDecision::StayOpen;