Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_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 <imgui.h>
12
13#include <cstdint>
14#include <future>
15#include <memory>
16#include <optional>
17#include <string>
18#include <thread>
19#include <vector>
20
21#include "audio/match_audio.h"
23#include "gui/gui_scene.h"
33#include "model/match_engine.h"
34
36enum class MatchViewMode : std::uint8_t
37{
40};
41
57class MatchScene : public GUIScene
58{
59 public:
60 MatchScene(class GUIView* guiView_ptr, uint16_t home_id, uint16_t away_id);
61
62 void onEnter() override;
63 void handleEvent(const SDL_Event& event) override;
64 void update(float deltaTime) override;
65 void render() override;
66 void onExit() override;
67 SceneID getID() const override;
68
69 private:
76
79 {
81 std::string name;
82 std::string reason;
84 std::string replacement;
85 };
86
87 // What the assistant may decide for the manager; kept for the session.
90 inline static bool assistant_substitutions = false;
91
92 uint16_t home_team_id;
93 uint16_t away_team_id;
94
95 std::string home_name;
96 std::string away_name;
97
99 std::optional<bool> managed_is_home;
101 std::optional<MatchType> fixture_type;
103 std::string fixture_when;
104 std::vector<LineupProblem> lineup_problems;
105 std::string lineup_status;
107 std::string pre_match_note;
108
109 std::unique_ptr<MatchEngine> engine;
113 std::future<void> quick_result;
115 std::unique_ptr<MatchAudio> audio;
118 std::unique_ptr<IMatchRenderer> renderer_2d;
119 std::unique_ptr<IMatchRenderer> renderer_3d;
122 bool show_player_names = false;
126 bool day_look = false;
128 bool pressure_overlay = false;
129 float pending_zoom_steps = 0.0f;
133 bool free_follow_ball = false;
135 bool pitch_focus = false;
137 bool side_panels_hidden = false;
140 float frame_seconds = 0.0f;
141
142 bool match_finished = false;
144 std::string decided_by;
145 bool decided_by_ready = false;
146
148 float match_speed = 1.0f;
149 bool highlights_only = false;
150 bool is_paused = false;
153
154 bool show_substitutions = false;
157 bool show_tactics = false;
161 bool paused_for_dialog = false;
164 bool in_break = false;
168#ifdef DEBUG
169 bool show_ai_debug = false;
170#endif
171
172 // --- Play mode -------------------------------------------------------------
176 bool play_confirm = false;
178 bool play_menu = false;
181 bool play_menu_resume = false;
183 enum class PlayMenuNext : std::uint8_t
184 {
185 NONE,
186 TACTICS,
188 };
191 float watch_speed = 1.0f;
192 bool watch_highlights = false;
194 bool watch_focus = false;
199 bool play_follow_ready = false;
204
207 std::vector<std::size_t> visible_events;
208 std::size_t indexed_events = 0;
209 bool show_all_events = false;
210 bool indexed_show_all = false;
212 std::string debug_status;
216 std::uint64_t slow_update_count = 0;
219
223 void applyLineupFix();
225 void startMatch();
229 bool substitute(PlayerID outgoing, PlayerID incoming);
231 [[nodiscard]] std::optional<TouchlineContext> touchline();
233 void showSubstitutions(bool show);
234 void showTactics(bool show);
236 void dialogClosed();
238 void renderPitchArea(ImVec2 size);
240 void renderFocusShouts(ImVec2 origin, ImVec2 size);
242 bool finishMatch();
244 bool quickResult();
245 [[nodiscard]] std::string clockText() const;
246 [[nodiscard]] ImU32 teamColor(bool home) const;
247
249 void pauseAtBreak();
250
251 // Play mode (match_scene_play.cpp).
252 [[nodiscard]] MatchPlayController::Options playOptions() const;
254 [[nodiscard]] bool canTakeControl() const;
256 void requestTakeControl();
258 void startPlaying();
260 [[nodiscard]] bool canHandBack() const;
261 void handBack();
262 void openPlayMenu();
263 void closePlayMenu();
265 void updatePlay(float deltaTime);
267 void suspendKeyboardNavigation(bool suspend);
269 void renderPlayOverlay(const IMatchRenderer& renderer, ImVec2 viewMin,
270 ImVec2 viewMax);
272 [[nodiscard]] MatchViewport playViewport2D(const MatchViewport& fitted,
273 ImVec2 viewMin, ImVec2 viewMax);
275 void renderPlayButtons();
276 void renderPlayConfirm();
277 void renderPlayMenu();
279 void renderPlayControlsHelp() const;
280 void setPlaybackSpeed(float speed);
281 void setHighlightsOnly(bool enabled);
282 void setViewMode(MatchViewMode mode);
285 void setPitchFocus(bool enabled);
286 void setSidePanelsHidden(bool hidden);
288 void takeFreeCamera();
289 void setFreeFollowBall(bool follow);
293 void handleViewInput();
294 void renderPitchFocus();
295 void renderFocusHud(ImVec2 origin, ImVec2 size);
296 void renderLineupGate();
298 void renderScoreboard();
299 void renderTimeline();
302 void renderControls();
303 void renderViewControls();
304 void renderPitch(ImVec2 size);
305 void renderStatistics(ImVec2 size);
306 void renderEvents(ImVec2 size);
308 void renderTacticsModal();
309#ifdef DEBUG
310 void renderDebugLines();
311 void exportDebugSnapshot();
312#endif
313};
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
Definition imatch_renderer.h:97
The assistant's half-time / full-time analysis of a live match: where the chances came from,...
Definition match_analysis_panel.h:31
Definition match_play_controller.h:55
Definition match_scene.h:58
void showSubstitutions(bool show)
Definition match_scene.cpp:672
void takeFreeCamera()
Definition match_scene.cpp:903
bool show_tactics
Definition match_scene.h:157
float focus_controls_width
Definition match_scene.h:139
std::jthread quick_result_worker
Definition match_scene.h:112
bool highlights_only
Definition match_scene.h:149
void openPlayMenu()
Definition match_scene_play.cpp:119
std::uint64_t slow_update_count
Definition match_scene.h:216
bool free_follow_ball
Definition match_scene.h:133
MatchTacticsPanel tactics_panel
Definition match_scene.h:159
void renderQuickResultProgress()
Definition match_scene.cpp:1202
bool day_look
Definition match_scene.h:126
void renderControls()
Definition match_scene.cpp:1510
bool show_all_events
Definition match_scene.h:209
void renderSubstitutionsModal()
Definition match_scene.cpp:2297
float match_speed
Definition match_scene.h:148
void handBack()
Definition match_scene_play.cpp:106
bool pressure_overlay
Definition match_scene.h:128
float average_render_milliseconds
Definition match_scene.h:218
std::unique_ptr< IMatchRenderer > renderer_2d
Definition match_scene.h:118
std::string clockText() const
Definition match_scene.cpp:766
void renderPitch(ImVec2 size)
Definition match_scene.cpp:1803
float last_render_milliseconds
Definition match_scene.h:217
bool watch_focus
Definition match_scene.h:194
bool paused_for_dialog
Definition match_scene.h:161
bool is_paused
Definition match_scene.h:150
void suspendKeyboardNavigation(bool suspend)
Definition match_scene_play.cpp:136
float skip_indicator_seconds
Definition match_scene.h:117
static bool assistant_substitutions
Definition match_scene.h:90
void renderPitchArea(ImVec2 size)
Definition match_scene.cpp:1766
MatchCameraMode camera_mode
Definition match_scene.h:121
MatchPlayController play
Definition match_scene.h:174
bool finishMatch()
Definition match_scene.cpp:730
void updatePlay(float deltaTime)
Definition match_scene_play.cpp:147
bool canHandBack() const
Definition match_scene_play.cpp:100
std::string substitution_status
Definition match_scene.h:205
MatchAnalysisPanel analysis_panel
Definition match_scene.h:152
void renderFocusShouts(ImVec2 origin, ImVec2 size)
Definition match_scene.cpp:1783
MatchViewMode view_mode
Definition match_scene.h:120
std::string pre_match_note
Definition match_scene.h:107
bool show_player_names
Definition match_scene.h:122
std::string home_name
Definition match_scene.h:95
void handleViewInput()
Definition match_scene.cpp:1882
bool play_follow_ready
Definition match_scene.h:199
uint16_t home_team_id
Definition match_scene.h:92
void render() override
Renders the scene.
Definition match_scene.cpp:1074
void renderPitchFocus()
Definition match_scene.cpp:1932
bool nav_keyboard_suspended
Definition match_scene.h:196
PlayMenuNext play_menu_next
Definition match_scene.h:189
void renderEvents(ImVec2 size)
Definition match_scene.cpp:2244
std::string debug_status
Definition match_scene.h:212
bool quickResult()
Definition match_scene.cpp:756
bool play_confirm
Definition match_scene.h:176
int kickoff_minutes
Definition match_scene.h:124
void renderPlayConfirm()
Definition match_scene_play.cpp:338
MatchPlayController::Options playOptions() const
Definition match_scene_play.cpp:47
void renderPlayOverlay(const IMatchRenderer &renderer, ImVec2 viewMin, ImVec2 viewMax)
Definition match_scene_play.cpp:233
float pending_zoom_steps
Definition match_scene.h:129
void startMatch()
Definition match_scene.cpp:550
MatchSubsPanel subs_panel
Definition match_scene.h:156
bool skipped_last_update
Definition match_scene.h:167
bool canTakeControl() const
Definition match_scene_play.cpp:58
void renderPlayButtons()
Definition match_scene_play.cpp:274
float scene_entry_milliseconds
Definition match_scene.h:213
std::future< void > quick_result
Definition match_scene.h:113
void refreshVisibleEvents()
Definition match_scene.cpp:2228
MatchRenderSnapshot snapshot
Definition match_scene.h:203
void renderScoreboard()
Definition match_scene.cpp:1282
MatchViewport playViewport2D(const MatchViewport &fitted, ImVec2 viewMin, ImVec2 viewMax)
Definition match_scene_play.cpp:185
void renderStatistics(ImVec2 size)
Definition match_scene.cpp:2190
TeamTalkDialog team_talk
Definition match_scene.h:151
float frame_seconds
Definition match_scene.h:140
std::unique_ptr< MatchAudio > audio
Definition match_scene.h:115
MatchCameraInput pending_camera_input
Definition match_scene.h:131
void renderPlayMenu()
Definition match_scene_play.cpp:374
std::vector< std::size_t > visible_events
Definition match_scene.h:207
void closePlayMenu()
Definition match_scene_play.cpp:129
PlayScreenBasis play_basis
Definition match_scene.h:201
void dialogClosed()
Definition match_scene.cpp:723
void update(float deltaTime) override
Updates scene logic.
Definition match_scene.cpp:796
friend class GameFlowTest_ManagedMatchIntegration_Test
Definition match_scene.h:71
float last_update_milliseconds
Definition match_scene.h:214
void pauseAtBreak()
Definition match_scene.cpp:863
void setViewMode(MatchViewMode mode)
Definition match_scene.cpp:880
bool indexed_show_all
Definition match_scene.h:210
uint16_t away_team_id
Definition match_scene.h:93
std::optional< MatchType > fixture_type
Definition match_scene.h:101
std::string decided_by
Definition match_scene.h:144
std::unique_ptr< MatchEngine > engine
Definition match_scene.h:109
std::optional< TouchlineContext > touchline()
Definition match_scene.cpp:643
bool match_finished
Definition match_scene.h:142
bool show_substitutions
Definition match_scene.h:154
bool watch_highlights
Definition match_scene.h:192
std::vector< LineupProblem > lineup_problems
Definition match_scene.h:104
void renderTimeline()
Definition match_scene.cpp:1421
bool substitution_refused
Definition match_scene.h:211
float maximum_update_milliseconds
Definition match_scene.h:215
Vector2F play_follow
Definition match_scene.h:198
std::string lineup_status
Definition match_scene.h:105
friend class GameFlowTest_ManagementScreensMidSeason_Test
Definition match_scene.h:72
void applySubstitutionPolicy()
Definition match_scene.cpp:633
void renderViewControls()
Definition match_scene.cpp:1667
bool pitch_focus
Definition match_scene.h:135
void setPlaybackSpeed(float speed)
Definition match_scene.cpp:613
ImU32 teamColor(bool home) const
Definition match_scene.cpp:788
bool in_break
Definition match_scene.h:164
void renderPlayControlsHelp() const
Definition match_scene_play.cpp:303
void applyLineupFix()
Definition match_scene.cpp:511
std::size_t indexed_events
Definition match_scene.h:208
void refreshLineupProblems()
Definition match_scene.cpp:465
void startPlaying()
Definition match_scene_play.cpp:75
void handleEvent(const SDL_Event &event) override
Handles SDL events for the scene.
Definition match_scene.cpp:926
std::string fixture_when
Definition match_scene.h:103
void onExit() override
Called when the scene is exited/becomes inactive.
Definition match_scene_play.cpp:178
friend class GameFlowTest_WatchedMatchSeedIsDeterministic_Test
Definition match_scene.h:73
void renderTacticsModal()
Definition match_scene.cpp:2307
std::unique_ptr< IMatchRenderer > renderer_3d
Definition match_scene.h:119
bool side_panels_hidden
Definition match_scene.h:137
bool play_menu_resume
Definition match_scene.h:181
void setFreeFollowBall(bool follow)
Definition match_scene.cpp:911
float watch_speed
Definition match_scene.h:191
MatchCameraMode watch_camera
Definition match_scene.h:193
void setSidePanelsHidden(bool hidden)
Definition match_scene.cpp:897
void toggleWindowFullscreen()
Definition match_scene.cpp:917
void showTactics(bool show)
Definition match_scene.cpp:698
SceneID getID() const override
Gets the ID of the scene.
Definition match_scene.cpp:405
bool play_menu
Definition match_scene.h:178
std::string away_name
Definition match_scene.h:96
std::optional< bool > managed_is_home
Definition match_scene.h:99
friend class GameFlowTest_WatchedCupTieIsPlayedToAWinner_Test
Definition match_scene.h:74
bool substitute(PlayerID outgoing, PlayerID incoming)
Definition match_scene.cpp:658
void requestTakeControl()
Definition match_scene_play.cpp:66
void renderLineupGate()
Definition match_scene.cpp:1220
PlayMenuNext
Definition match_scene.h:184
bool decided_by_ready
Definition match_scene.h:145
friend class GameFlowTest_GUIFlowLifecycle_Test
Definition match_scene.h:70
void setPitchFocus(bool enabled)
Definition match_scene.cpp:895
void onEnter() override
Called when the scene is entered/becomes active.
Definition match_scene.cpp:407
void setHighlightsOnly(bool enabled)
Definition match_scene.cpp:624
void renderFocusHud(ImVec2 origin, ImVec2 size)
Definition match_scene.cpp:1941
friend class MatchRenderer3DSceneTest_SwitchesViewsAndCapturesFrames_Test
Definition match_scene.h:75
void setCameraMode(MatchCameraMode mode)
Definition match_scene.cpp:886
Substitutions dialog of the live match.
Definition match_subs_panel.h:37
Tactics dialog of the live match: style presets, the five instructions and the formation,...
Definition match_tactics_panel.h:27
Modal pre-match / half-time team talk of the managed club.
Definition team_talk_dialog.h:38
SceneID
Identifiers for different GUI scenes.
Definition gui_scene.h:24
MatchCameraMode
Definition imatch_renderer.h:26
MatchViewMode
Definition match_scene.h:37
Definition imatch_renderer.h:42
Definition match_play_controller.h:59
Definition match_render_snapshot.h:89
Definition match_scene.h:79
std::string reason
Definition match_scene.h:82
std::string name
Definition match_scene.h:81
std::string replacement
Definition match_scene.h:84
static constexpr float CENTRE
Definition match_tuning.h:37
Definition imatch_renderer.h:17
Definition match_play_controller.h:36
A simple 2D float vector for pitch coordinates.
Definition types.h:84
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21