mirror of
https://github.com/RGBCube/serenity
synced 2025-07-29 06:27:44 +00:00
LibGUI+Userland: Port StatusBar::text() and set_text functions to String
This commit is contained in:
parent
2064f544c6
commit
2029750519
27 changed files with 88 additions and 88 deletions
|
@ -89,7 +89,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto update = [&]() {
|
||||
board_view->set_board(&game.board());
|
||||
board_view->update();
|
||||
statusbar->set_text(DeprecatedString::formatted("Score: {}", game.score()));
|
||||
statusbar->set_text(String::formatted("Score: {}", game.score()).release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
update();
|
||||
|
|
|
@ -105,7 +105,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto update = [&]() {
|
||||
board_widget->update();
|
||||
statusbar->set_text(DeprecatedString::formatted("Moves remaining: {}", ai_moves - moves_made));
|
||||
statusbar->set_text(String::formatted("Moves remaining: {}", ai_moves - moves_made).release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
update();
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
#include <LibGUI/Window.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
char const* click_tip = "Tip: click the board to toggle individual cells, or click+drag to toggle multiple cells";
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
|
||||
|
@ -41,6 +39,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/res", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto click_tip = TRY("Tip: click the board to toggle individual cells, or click+drag to toggle multiple cells"_string);
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-gameoflife"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
|
@ -147,7 +147,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
board_widget->on_running_state_change = [&]() {
|
||||
if (board_widget->is_running()) {
|
||||
statusbar.set_text("Running...");
|
||||
statusbar.set_text("Running..."_string.release_value_but_fixme_should_propagate_errors());
|
||||
toggle_running_toolbar_button->set_icon(*paused_icon);
|
||||
main_widget->set_override_cursor(Gfx::StandardCursor::None);
|
||||
} else {
|
||||
|
@ -171,7 +171,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
board_widget->on_stall = [&] {
|
||||
toggle_running_action->activate();
|
||||
statusbar.set_text("Stalled...");
|
||||
statusbar.set_text("Stalled..."_string.release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
board_widget->on_cell_toggled = [&](auto, auto, auto) {
|
||||
|
|
|
@ -57,7 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
game.set_focus(true);
|
||||
|
||||
auto& statusbar = *widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
statusbar.set_text(0, "Score: 0");
|
||||
statusbar.set_text(0, TRY("Score: 0"_string));
|
||||
|
||||
DeprecatedString player_name = Config::read_string("Hearts"sv, ""sv, "player_name"sv, "Gunnar"sv);
|
||||
|
||||
|
|
|
@ -130,9 +130,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
game.on_message = [&](auto message) {
|
||||
if (!message.has_value())
|
||||
statusbar.set_text("");
|
||||
statusbar.set_text({});
|
||||
else
|
||||
statusbar.set_text(*message);
|
||||
statusbar.set_text(String::from_utf8(*message).release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
window->show();
|
||||
|
|
|
@ -62,15 +62,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto snake_skin_name = Config::read_string("Snake"sv, "Snake"sv, "SnakeSkin"sv, "Classic"sv);
|
||||
|
||||
auto& statusbar = *widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar"sv);
|
||||
statusbar.set_text(0, "Score: 0"sv);
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score));
|
||||
statusbar.set_text(0, TRY("Score: 0"_string));
|
||||
statusbar.set_text(1, TRY(String::formatted("High Score: {}", high_score)));
|
||||
|
||||
game.on_score_update = [&](auto score) {
|
||||
statusbar.set_text(0, DeprecatedString::formatted("Score: {}", score));
|
||||
statusbar.set_text(0, String::formatted("Score: {}", score).release_value_but_fixme_should_propagate_errors());
|
||||
if (score <= high_score)
|
||||
return false;
|
||||
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", score));
|
||||
statusbar.set_text(1, String::formatted("High Score: {}", score).release_value_but_fixme_should_propagate_errors());
|
||||
Config::write_u32("Snake"sv, "Snake"sv, "HighScore"sv, score);
|
||||
|
||||
high_score = score;
|
||||
|
|
|
@ -90,9 +90,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
game.set_focus(true);
|
||||
|
||||
auto& statusbar = *widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
statusbar.set_text(0, "Score: 0");
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
|
||||
statusbar.set_text(2, "Time: 00:00:00");
|
||||
statusbar.set_text(0, TRY("Score: 0"_string));
|
||||
statusbar.set_text(1, TRY(String::formatted("High Score: {}", high_score())));
|
||||
statusbar.set_text(2, TRY("Time: 00:00:00"_string));
|
||||
|
||||
app->on_action_enter = [&](GUI::Action& action) {
|
||||
auto text = action.status_tip();
|
||||
|
@ -106,7 +106,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
};
|
||||
|
||||
game.on_score_update = [&](uint32_t score) {
|
||||
statusbar.set_text(0, DeprecatedString::formatted("Score: {}", score));
|
||||
statusbar.set_text(0, String::formatted("Score: {}", score).release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
uint64_t seconds_elapsed = 0;
|
||||
|
@ -118,13 +118,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
uint64_t minutes = (seconds_elapsed / 60) % 60;
|
||||
uint64_t seconds = seconds_elapsed % 60;
|
||||
|
||||
statusbar.set_text(2, DeprecatedString::formatted("Time: {:02}:{:02}:{:02}", hours, minutes, seconds));
|
||||
statusbar.set_text(2, String::formatted("Time: {:02}:{:02}:{:02}", hours, minutes, seconds).release_value_but_fixme_should_propagate_errors());
|
||||
}));
|
||||
|
||||
game.on_game_start = [&]() {
|
||||
seconds_elapsed = 0;
|
||||
timer->start();
|
||||
statusbar.set_text(2, "Time: 00:00:00");
|
||||
statusbar.set_text(2, "Time: 00:00:00"_string.release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
game.on_game_end = [&](Solitaire::GameOverReason reason, uint32_t score) {
|
||||
if (timer->is_active())
|
||||
|
@ -133,16 +133,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (reason == Solitaire::GameOverReason::Victory) {
|
||||
if (seconds_elapsed >= 30) {
|
||||
uint32_t bonus = (20'000 / seconds_elapsed) * 35;
|
||||
statusbar.set_text(0, DeprecatedString::formatted("Score: {} (Bonus: {})", score, bonus));
|
||||
statusbar.set_text(0, String::formatted("Score: {} (Bonus: {})", score, bonus).release_value_but_fixme_should_propagate_errors());
|
||||
score += bonus;
|
||||
}
|
||||
|
||||
if (score > high_score()) {
|
||||
update_high_score(score);
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", score));
|
||||
statusbar.set_text(1, String::formatted("High Score: {}", score).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
}
|
||||
statusbar.set_text(2, "Timer starts after your first move");
|
||||
statusbar.set_text(2, "Timer starts after your first move"_string.release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
auto confirm_end_current_game = [&]() {
|
||||
|
@ -175,7 +175,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (!confirm_end_current_game())
|
||||
return;
|
||||
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
|
||||
statusbar.set_text(1, String::formatted("High Score: {}", high_score()).release_value_but_fixme_should_propagate_errors());
|
||||
game.setup(mode);
|
||||
});
|
||||
single_card_draw_action->set_checked(mode == Solitaire::Mode::SingleCardDraw);
|
||||
|
@ -188,7 +188,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (!confirm_end_current_game())
|
||||
return;
|
||||
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
|
||||
statusbar.set_text(1, String::formatted("High Score: {}", high_score()).release_value_but_fixme_should_propagate_errors());
|
||||
game.setup(mode);
|
||||
});
|
||||
three_card_draw_action->set_checked(mode == Solitaire::Mode::ThreeCardDraw);
|
||||
|
|
|
@ -127,19 +127,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto reset_statistic_status = [&]() {
|
||||
switch (statistic_display) {
|
||||
case StatisticDisplay::HighScore:
|
||||
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
|
||||
statusbar.set_text(1, String::formatted("High Score: {}", high_score()).release_value_but_fixme_should_propagate_errors());
|
||||
break;
|
||||
case StatisticDisplay::BestTime:
|
||||
statusbar.set_text(1, DeprecatedString::formatted("Best Time: {}", format_seconds(best_time())));
|
||||
statusbar.set_text(1, String::formatted("Best Time: {}", format_seconds(best_time())).release_value_but_fixme_should_propagate_errors());
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
statusbar.set_text(0, "Score: 0");
|
||||
statusbar.set_text(0, TRY("Score: 0"_string));
|
||||
reset_statistic_status();
|
||||
statusbar.set_text(2, "Time: 00:00:00");
|
||||
statusbar.set_text(2, TRY("Time: 00:00:00"_string));
|
||||
|
||||
app->on_action_enter = [&](GUI::Action& action) {
|
||||
auto text = action.status_tip();
|
||||
|
@ -153,7 +153,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
};
|
||||
|
||||
game.on_score_update = [&](uint32_t score) {
|
||||
statusbar.set_text(0, DeprecatedString::formatted("Score: {}", score));
|
||||
statusbar.set_text(0, String::formatted("Score: {}", score).release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
uint64_t seconds_elapsed = 0;
|
||||
|
@ -161,13 +161,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto timer = TRY(Core::Timer::create_repeating(1000, [&]() {
|
||||
++seconds_elapsed;
|
||||
|
||||
statusbar.set_text(2, DeprecatedString::formatted("Time: {}", format_seconds(seconds_elapsed)));
|
||||
statusbar.set_text(2, String::formatted("Time: {}", format_seconds(seconds_elapsed)).release_value_but_fixme_should_propagate_errors());
|
||||
}));
|
||||
|
||||
game.on_game_start = [&]() {
|
||||
seconds_elapsed = 0;
|
||||
timer->start();
|
||||
statusbar.set_text(2, "Time: 00:00:00");
|
||||
statusbar.set_text(2, "Time: 00:00:00"_string.release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
game.on_game_end = [&](Spider::GameOverReason reason, uint32_t score) {
|
||||
auto game_was_in_progress = timer->is_active();
|
||||
|
@ -192,7 +192,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
reset_statistic_status();
|
||||
}
|
||||
statusbar.set_text(2, "Timer starts after your first move");
|
||||
statusbar.set_text(2, "Timer starts after your first move"_string.release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
||||
auto confirm_end_current_game = [&]() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue