Player12
An open source football management simulator
Loading...
Searching...
No Matches
GUIView Class Reference

Main view manager for the GUI. Handles scenes and overlays. More...

#include <gui_view.h>

Public Member Functions

 GUIView (GameController &controller_ref)
 Constructs a new GUIView.
 
 ~GUIView ()
 Destroys the GUIView.
 
void run ()
 Starts the scene run loop.
 
bool runMatchRenderProfile ()
 Profiles the first live-match frames and exits automatically.
 
void changeScene (std::unique_ptr< GUIScene > newScene)
 Changes the current scene.
 
void overlayScene (std::unique_ptr< GUIScene > overlay)
 Overlays a new scene on top of the current one.
 
void popScene ()
 Pops the top overlaid scene.
 
void navigateTo (std::unique_ptr< GUIScene > scene)
 Routine navigation: removes every overlay and shows a new screen.
 
GUIScene * getBaseScene () const
 The scene underneath all overlays (e.g. the club dashboard).
 
size_t getOverlayDepth () const
 Number of overlays currently stacked above the base scene.
 
GUIScene * getTopScene () const
 The scene shown now (the top overlay, else the base scene).
 
GUIScene * getSceneBelowTop () const
 The scene popScene() would reveal (nullptr without overlays).
 
NavHistory & navHistory ()
 Screens visited in this career, recorded whenever the shown screen changes; cleared whenever the base scene changes (a career is started, loaded or left).
 
const NavHistory & navHistory () const
 
void markHistoryStep ()
 Marks the scene change just requested as a step through the history (Back / Forward), so it is not recorded as a new visit. Any scene request made after it cancels the mark.
 
SwipeGesture & swipeGesture ()
 Sideways touchpad swipe, shared by every career screen.
 
void quit ()
 Stops the run loop and quits.
 
SDL_Renderer * getRenderer () const
 Gets the SDL renderer.
 
SDL_Window * getWindow () const
 Gets the SDL window.
 
GameController & getController () const
 Gets the game controller.
 
void requestBackdropCapture ()
 Freezes the frame being rendered into a texture at its end.
 
bool isBackdropPending () const
 True until the requested frame has been frozen.
 
SDL_Texture * getBackdrop () const
 Frozen frame from requestBackdropCapture(), or nullptr.
 
void releaseBackdrop ()
 Frees the frozen frame.
 
void refreshTheme ()
 
void applySavePolicy ()
 
void applyWindowSettings (bool resize=true)
 
bool captureScreenshot (std::string_view path) const
 
void openEditor (const std::optional< NavEntry > &context)
 
void openEditor (const EditorContext &context)
 

Private Types

enum class  PendingAction {
  NONE , CHANGE , OVERLAY , POP ,
  NAVIGATE
}
 

Private Member Functions

bool initialize ()
 
void applyManagementTheme ()
 
float displayScale () const
 
void handleEvents ()
 
void update (float deltaTime)
 
void render ()
 
GUIScene * getActiveScene () const
 
void applyEditorRequest ()
 
void beginMatchRenderTimings ()
 
void reportMatchRenderTimings ()
 
void recordHistory ()
 
void applyPendingSceneChanges ()
 

Private Attributes

GameController & controller
 
SDL_Window * window = nullptr
 
SDL_Renderer * renderer = nullptr
 
bool running
 
bool screenshotPending = false
 
bool backdropPending = false
 
std::unique_ptr< RuntimeEditorDialog > editor_dialog
 
SDL_Texture * backdropTexture = nullptr
 
bool rendererIsSoftware = false
 
std::array< float, MATCH_FRAME_TIMING_COUNT > matchFrameTimes {}
 
int matchFramesTimed = -1
 
std::unique_ptr< GUIScene > currentScene
 
std::vector< std::unique_ptr< GUIScene > > sceneStack
 
NavHistory nav_history
 
bool history_step = false
 
SwipeGesture swipe_gesture
 
PendingAction pendingAction = PendingAction::NONE
 
std::unique_ptr< GUIScene > pendingScene
 

Static Private Attributes

static constexpr int MATCH_FRAME_TIMING_COUNT = 120
 
static constexpr float MATCH_PROFILE_FRAME_SECONDS = 1.0f / 60.0f
 

Friends

class GameFlowTest_GUIFlowLifecycle_Test
 
class GameFlowTest_ManagementScreensMidSeason_Test
 
class GameFlowTest
 

Detailed Description

Main view manager for the GUI. Handles scenes and overlays.

Member Enumeration Documentation

◆ PendingAction

enum class GUIView::PendingAction
strongprivate
Enumerator
NONE 
CHANGE 
OVERLAY 
POP 
NAVIGATE 

Constructor & Destructor Documentation

◆ GUIView()

GUIView::GUIView ( GameController &  controller_ref)
explicit

Constructs a new GUIView.

Parameters
controller_refReference to the game controller.

◆ ~GUIView()

GUIView::~GUIView ( )

Destroys the GUIView.

Member Function Documentation

◆ applyEditorRequest()

void GUIView::applyEditorRequest ( )
private

◆ applyManagementTheme()

void GUIView::applyManagementTheme ( )
private

◆ applyPendingSceneChanges()

void GUIView::applyPendingSceneChanges ( )
private

◆ applySavePolicy()

void GUIView::applySavePolicy ( )

Hands the saved autosave frequency and backup count to the controller.

◆ applyWindowSettings()

void GUIView::applyWindowSettings ( bool  resize = true)

Applies the saved window mode and size. The size is in logical units: where window coordinates are physical pixels (Windows, scaled X11) it is multiplied by the display scale, so 1280x720 at 200% opens a 2560x1440-pixel window instead of a 640x360 layout, always kept within the display's usable area. With resize false only the mode, VSync and language are applied (a maximised window stays maximised).

◆ beginMatchRenderTimings()

void GUIView::beginMatchRenderTimings ( )
private

◆ captureScreenshot()

bool GUIView::captureScreenshot ( std::string_view  path) const

Captures the current renderer contents as a BMP image.

◆ changeScene()

void GUIView::changeScene ( std::unique_ptr< GUIScene >  newScene)

Changes the current scene.

Parameters
newSceneThe new scene to switch to.

Function to change the scene, this should be used when we also want to remove the previous scene from the Scenes Stack.

◆ displayScale()

float GUIView::displayScale ( ) const
private

◆ getActiveScene()

GUIScene * GUIView::getActiveScene ( ) const
private

◆ getBackdrop()

SDL_Texture * GUIView::getBackdrop ( ) const
inline

Frozen frame from requestBackdropCapture(), or nullptr.

◆ getBaseScene()

GUIScene * GUIView::getBaseScene ( ) const

The scene underneath all overlays (e.g. the club dashboard).

◆ getController()

GameController & GUIView::getController ( ) const

Gets the game controller.

Returns
Reference to the GameController.

◆ getOverlayDepth()

size_t GUIView::getOverlayDepth ( ) const

Number of overlays currently stacked above the base scene.

◆ getRenderer()

SDL_Renderer * GUIView::getRenderer ( ) const

Gets the SDL renderer.

Returns
The SDL_Renderer pointer.

◆ getSceneBelowTop()

GUIScene * GUIView::getSceneBelowTop ( ) const

The scene popScene() would reveal (nullptr without overlays).

◆ getTopScene()

GUIScene * GUIView::getTopScene ( ) const
inline

The scene shown now (the top overlay, else the base scene).

◆ getWindow()

SDL_Window * GUIView::getWindow ( ) const

Gets the SDL window.

Returns
The SDL_Window pointer.

◆ handleEvents()

void GUIView::handleEvents ( )
private

◆ initialize()

bool GUIView::initialize ( )
private

◆ isBackdropPending()

bool GUIView::isBackdropPending ( ) const
inline

True until the requested frame has been frozen.

◆ markHistoryStep()

void GUIView::markHistoryStep ( )
inline

Marks the scene change just requested as a step through the history (Back / Forward), so it is not recorded as a new visit. Any scene request made after it cancels the mark.

◆ navHistory() [1/2]

NavHistory & GUIView::navHistory ( )
inline

Screens visited in this career, recorded whenever the shown screen changes; cleared whenever the base scene changes (a career is started, loaded or left).

◆ navHistory() [2/2]

const NavHistory & GUIView::navHistory ( ) const
inline

◆ navigateTo()

void GUIView::navigateTo ( std::unique_ptr< GUIScene >  scene)

Routine navigation: removes every overlay and shows a new screen.

Parameters
sceneScreen to show above the base scene, or nullptr to return to the base scene itself.

Unlike popScene() followed by overlayScene(), this is a single deferred action, so it can safely be requested from inside a scene's render().

◆ openEditor() [1/2]

void GUIView::openEditor ( const EditorContext &  context)

◆ openEditor() [2/2]

void GUIView::openEditor ( const std::optional< NavEntry > &  context)

Opens a schema-driven editor with optional page/entity context.

◆ overlayScene()

void GUIView::overlayScene ( std::unique_ptr< GUIScene >  overlay)

Overlays a new scene on top of the current one.

Parameters
overlayThe scene to overlay.

This functions adds a scene as an overlay, this makes it possible to show faster the scene that was previously dispalyed. Example: When we are on the main game dashboard if we want to display the Lineup, we could just overlay on the main game dashboard since we will for sure go back. Then if we click on a player to see his profile, we can make a new overlay, and these scenes will be just popped at the end of their usage.

◆ popScene()

void GUIView::popScene ( )

Pops the top overlaid scene.

This is the functio to pop Overlaid scenes

◆ quit()

void GUIView::quit ( )

Stops the run loop and quits.

◆ recordHistory()

void GUIView::recordHistory ( )
private

Records the screen shown after a scene change.

◆ refreshTheme()

void GUIView::refreshTheme ( )

Re-applies appearance settings (theme, scale, density) live.

◆ releaseBackdrop()

void GUIView::releaseBackdrop ( )

Frees the frozen frame.

◆ render()

void GUIView::render ( )
private

◆ reportMatchRenderTimings()

void GUIView::reportMatchRenderTimings ( )
private

◆ requestBackdropCapture()

void GUIView::requestBackdropCapture ( )

Freezes the frame being rendered into a texture at its end.

Used as a dimmed backdrop while the game state must not be read (e.g. days simulated in the background), so the screen stays visible without any scene touching live data. While it exists it is drawn behind the UI every frame, so scenes shown over it must use transparent windows.

◆ run()

void GUIView::run ( )

Starts the scene run loop.

◆ runMatchRenderProfile()

bool GUIView::runMatchRenderProfile ( )

Profiles the first live-match frames and exits automatically.

Returns
True when all profiling frames were rendered.

◆ swipeGesture()

SwipeGesture & GUIView::swipeGesture ( )
inline

Sideways touchpad swipe, shared by every career screen.

◆ update()

void GUIView::update ( float  deltaTime)
private

Friends And Related Symbol Documentation

◆ GameFlowTest

friend class GameFlowTest
friend

◆ GameFlowTest_GUIFlowLifecycle_Test

friend class GameFlowTest_GUIFlowLifecycle_Test
friend

◆ GameFlowTest_ManagementScreensMidSeason_Test

friend class GameFlowTest_ManagementScreensMidSeason_Test
friend

Member Data Documentation

◆ backdropPending

bool GUIView::backdropPending = false
private

◆ backdropTexture

SDL_Texture* GUIView::backdropTexture = nullptr
private

◆ controller

GameController& GUIView::controller
private

◆ currentScene

std::unique_ptr<GUIScene> GUIView::currentScene
private

◆ editor_dialog

std::unique_ptr<RuntimeEditorDialog> GUIView::editor_dialog
private

◆ history_step

bool GUIView::history_step = false
private

◆ MATCH_FRAME_TIMING_COUNT

constexpr int GUIView::MATCH_FRAME_TIMING_COUNT = 120
staticconstexprprivate

◆ MATCH_PROFILE_FRAME_SECONDS

constexpr float GUIView::MATCH_PROFILE_FRAME_SECONDS = 1.0f / 60.0f
staticconstexprprivate

◆ matchFramesTimed

int GUIView::matchFramesTimed = -1
private

◆ matchFrameTimes

std::array<float, MATCH_FRAME_TIMING_COUNT> GUIView::matchFrameTimes {}
private

◆ nav_history

NavHistory GUIView::nav_history
private

◆ pendingAction

PendingAction GUIView::pendingAction = PendingAction::NONE
private

◆ pendingScene

std::unique_ptr<GUIScene> GUIView::pendingScene
private

◆ renderer

SDL_Renderer* GUIView::renderer = nullptr
private

◆ rendererIsSoftware

bool GUIView::rendererIsSoftware = false
private

◆ running

bool GUIView::running
private

◆ sceneStack

std::vector<std::unique_ptr<GUIScene> > GUIView::sceneStack
private

◆ screenshotPending

bool GUIView::screenshotPending = false
private

◆ swipe_gesture

SwipeGesture GUIView::swipe_gesture
private

◆ window

SDL_Window* GUIView::window = nullptr
private

The documentation for this class was generated from the following files: