summaryrefslogtreecommitdiff
path: root/Userland/Games/Hearts/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Games/Hearts/main.cpp')
-rw-r--r--Userland/Games/Hearts/main.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/Userland/Games/Hearts/main.cpp b/Userland/Games/Hearts/main.cpp
index 02ea160de9..4744ca2691 100644
--- a/Userland/Games/Hearts/main.cpp
+++ b/Userland/Games/Hearts/main.cpp
@@ -6,6 +6,7 @@
*/
#include "Game.h"
+#include "SettingsDialog.h"
#include <Games/Hearts/HeartsGML.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/Timer.h>
@@ -59,6 +60,8 @@ int main(int argc, char** argv)
auto& statusbar = *widget.find_descendant_of_type_named<GUI::Statusbar>("statusbar");
statusbar.set_text(0, "Score: 0");
+ String player_name = config->read_entry("", "player_name", "Gunnar");
+
game.on_status_change = [&](const AK::StringView& status) {
statusbar.set_override_text(status);
};
@@ -74,11 +77,32 @@ int main(int argc, char** argv)
statusbar.set_override_text({});
};
+ auto change_settings = [&] {
+ auto settings_dialog = SettingsDialog::construct(window, player_name);
+ if (settings_dialog->exec() || settings_dialog->result() != GUI::Dialog::ExecOK)
+ return;
+
+ player_name = settings_dialog->player_name();
+
+ config->write_entry("", "player_name", player_name);
+
+ if (!config->sync()) {
+ GUI::MessageBox::show(window, "Settings could not be saved!", "Error", GUI::MessageBox::Type::Error);
+ return;
+ }
+
+ GUI::MessageBox::show(window, "Settings have been successfully saved and will take effect in the next game.", "Settings Changed Successfully", GUI::MessageBox::Type::Information);
+ };
+
auto menubar = GUI::Menubar::construct();
auto& game_menu = menubar->add_menu("&Game");
game_menu.add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, [&](auto&) {
- game.setup();
+ game.setup(player_name);
+ }));
+ game_menu.add_separator();
+ game_menu.add_action(GUI::Action::create("&Settings...", [&](auto&) {
+ change_settings();
}));
game_menu.add_separator();
game_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
@@ -91,7 +115,7 @@ int main(int argc, char** argv)
window->set_menubar(move(menubar));
window->set_icon(app_icon.bitmap_for_size(16));
window->show();
- game.setup();
+ game.setup(player_name);
return app->exec();
}