Player12
An open source football management simulator
Loading...
Searching...
No Matches
main_menu_scene.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <filesystem>
12#include <future>
13#include <optional>
14#include <string>
15#include <thread>
16#include <vector>
17
19#include "global/crash_report.h"
20#include "gui/gui_scene.h"
21#include "gui/gui_view.h"
22
26class MainMenuScene : public GUIScene
27{
28 public:
33 explicit MainMenuScene(GUIView* guiView_ptr);
34
38 ~MainMenuScene() override = default;
39
43 void onEnter() override;
44
49 void update(float deltaTime) override;
50
54 void render() override;
55
60 [[nodiscard]] SceneID getID() const override;
61
62 private:
64 bool is_new_game = false;
65 bool slot_picker_requested = false;
66 int loading_slot = 0;
67 bool is_loading_rendered = false;
69 std::jthread loading_worker;
70 std::future<bool> loading_operation;
71 std::vector<GameController::SaveSlotMetadata> cached_metadata;
75 // Save management: backups, restore, delete and load errors.
76 int backups_slot = 0;
77 bool backups_requested = false;
78 std::vector<SaveBackup> backups;
79 std::vector<std::string> backup_labels;
80 std::filesystem::path restore_candidate;
81 std::filesystem::path pending_restore;
82 int delete_slot = 0;
83 std::string delete_text;
86 std::string load_error_text;
87 std::filesystem::path recovery_backup;
88 std::string recovery_text;
89
90 // Report of a crashed earlier session, shown once until acknowledged.
91 std::optional<CrashReport::Pending> crash_notice;
93 std::string crash_notice_text;
94
96 std::string language_notice;
97
98 void loadCachedMetadata();
99 void renderBackdrop() const;
100 void renderSlotPicker();
101 void renderSlotActions(int slot,
102 const GameController::SaveSlotMetadata& metadata);
103 void renderBackups();
104 void renderLoadError();
105 void renderCrashNotice();
106 void renderVersion() const;
107 void renderLanguageNotice() const;
108 void openBackups(int slot);
110 void showLoadError(int slot, std::string text);
111 void startSlot(int slot, bool newGame);
112};
Base class for all GUI scenes.
Definition gui_scene.h:68
Main view manager for the GUI. Handles scenes and overlays.
Definition gui_view.h:29
Scene for the main menu.
Definition main_menu_scene.h:27
std::filesystem::path restore_candidate
Definition main_menu_scene.h:80
std::string load_error_text
Definition main_menu_scene.h:86
void renderBackdrop() const
Definition main_menu_scene.cpp:220
void renderBackups()
Definition main_menu_scene.cpp:543
bool backups_requested
Definition main_menu_scene.h:77
std::vector< SaveBackup > backups
Definition main_menu_scene.h:78
void onEnter() override
Populated when the scene is entered. Caches the save slot metadata.
Definition main_menu_scene.cpp:72
std::filesystem::path recovery_backup
Definition main_menu_scene.h:87
std::string recovery_text
Definition main_menu_scene.h:88
bool loading_operation_started
Definition main_menu_scene.h:68
~MainMenuScene() override=default
Destroys the MainMenuScene.
std::jthread loading_worker
Definition main_menu_scene.h:69
int latest_career_slot
Definition main_menu_scene.h:72
int loading_slot
Definition main_menu_scene.h:66
bool is_new_game
Definition main_menu_scene.h:64
std::vector< GameController::SaveSlotMetadata > cached_metadata
Definition main_menu_scene.h:71
int overwrite_slot
Definition main_menu_scene.h:73
void update(float deltaTime) override
Updates scene logic.
Definition main_menu_scene.cpp:132
std::string language_notice
Definition main_menu_scene.h:96
void showLoadError(int slot, std::string text)
Definition main_menu_scene.cpp:203
void renderLanguageNotice() const
Definition main_menu_scene.cpp:377
std::string delete_text
Definition main_menu_scene.h:83
void renderLoadError()
Definition main_menu_scene.cpp:489
void loadCachedMetadata()
Definition main_menu_scene.cpp:101
std::future< bool > loading_operation
Definition main_menu_scene.h:70
void render() override
Renders the scene.
Definition main_menu_scene.cpp:276
std::filesystem::path pending_restore
Definition main_menu_scene.h:81
bool slot_picker_requested
Definition main_menu_scene.h:65
int delete_slot
Definition main_menu_scene.h:82
std::string crash_notice_text
Definition main_menu_scene.h:93
void renderCrashNotice()
Definition main_menu_scene.cpp:408
std::optional< CrashReport::Pending > crash_notice
Definition main_menu_scene.h:91
bool is_loading_rendered
Definition main_menu_scene.h:67
bool crash_notice_requested
Definition main_menu_scene.h:92
int load_error_slot
Definition main_menu_scene.h:84
SceneID getID() const override
Gets the ID of this scene.
Definition main_menu_scene.cpp:35
void renderSlotActions(int slot, const GameController::SaveSlotMetadata &metadata)
Definition main_menu_scene.cpp:457
void renderVersion() const
Definition main_menu_scene.cpp:395
int backups_slot
Definition main_menu_scene.h:76
void startSlot(int slot, bool newGame)
Definition main_menu_scene.cpp:125
std::vector< std::string > backup_labels
Definition main_menu_scene.h:79
bool load_error_requested
Definition main_menu_scene.h:85
void renderSlotPicker()
Definition main_menu_scene.cpp:626
friend class GameFlowTest_GUIFlowLifecycle_Test
Definition main_menu_scene.h:63
void openBackups(int slot)
Definition main_menu_scene.cpp:446
SceneID
Identifiers for different GUI scenes.
Definition gui_scene.h:24
Definition game_controller.h:79