Player12
An open source football management simulator
Loading...
Searching...
No Matches
nav_history.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 <cstddef>
12#include <cstdint>
13#include <optional>
14#include <vector>
15
16#include "global/types.h"
17#include "model/gamedate.h"
18
25enum class NavSection : uint8_t
26{
27 HOME,
28 INBOX,
29 CLUB,
30 SQUAD,
31 LINEUP,
32 TACTICS,
39 STAFF,
40 YOUTH,
41 MANAGER,
42 MEDICAL,
45 COMPARE,
50 AWARDS,
51 RECORDS,
55 NEWS,
57 NONE
58};
59
65{
66 enum class Kind : uint8_t
67 {
68 SECTION,
69 PLAYER,
70 CLUB,
72 COMPARE
73 };
74
85 static NavEntry ofClub(TeamID team);
87 static NavEntry ofCompare(PlayerID first, PlayerID second);
88
93 [[nodiscard]] bool isDetail() const;
94
95 bool operator==(const NavEntry& other) const = default;
96};
97
109{
110 public:
111 static constexpr std::size_t DEFAULT_CAPACITY = 50;
112
113 explicit NavHistory(std::size_t capacity = DEFAULT_CAPACITY);
114
116 void visit(const NavEntry& entry);
117
119 void clear();
120
128 void stepBackTo(const NavEntry& entry);
129
131 [[nodiscard]] std::optional<NavEntry> current() const;
132
134 template <typename Valid>
135 [[nodiscard]] std::optional<NavEntry> peekBack(const Valid& valid) const
136 {
137 const std::optional<std::size_t> index = findBack(valid);
138 return index ? std::optional<NavEntry>(entries[*index]) : std::nullopt;
139 }
140
142 template <typename Valid>
143 [[nodiscard]] std::optional<NavEntry> peekForward(const Valid& valid) const
144 {
145 const std::optional<std::size_t> index = findForward(valid);
146 return index ? std::optional<NavEntry>(entries[*index]) : std::nullopt;
147 }
148
150 template <typename Valid>
151 std::optional<NavEntry> back(const Valid& valid)
152 {
153 const std::optional<std::size_t> index = findBack(valid);
154 if (!index.has_value()) return std::nullopt;
155 cursor = *index;
156 return entries[cursor];
157 }
158
160 template <typename Valid>
161 std::optional<NavEntry> forward(const Valid& valid)
162 {
163 const std::optional<std::size_t> index = findForward(valid);
164 if (!index.has_value()) return std::nullopt;
165 cursor = *index;
166 return entries[cursor];
167 }
168
169 [[nodiscard]] std::size_t size() const { return entries.size(); }
170 [[nodiscard]] std::size_t capacity() const { return limit; }
172 [[nodiscard]] std::size_t position() const { return cursor; }
173
174 private:
175 template <typename Valid>
176 [[nodiscard]] std::optional<std::size_t> findBack(const Valid& valid) const
177 {
178 for (std::size_t index = cursor; index-- > 0;)
179 if (entries[index] != entries[cursor] && valid(entries[index]))
180 return index;
181 return std::nullopt;
182 }
183
184 template <typename Valid>
185 [[nodiscard]] std::optional<std::size_t> findForward(const Valid& valid) const
186 {
187 for (std::size_t index = cursor + 1; index < entries.size(); ++index)
188 if (entries[index] != entries[cursor] && valid(entries[index]))
189 return index;
190 return std::nullopt;
191 }
192
193 std::vector<NavEntry> entries;
194 std::size_t cursor = 0;
195 std::size_t limit;
196};
Browser-style history of the screens visited in a career.
Definition nav_history.h:109
std::optional< std::size_t > findBack(const Valid &valid) const
Definition nav_history.h:176
void stepBackTo(const NavEntry &entry)
Steps back onto entry, a screen shown beneath the current one that the history cannot step back to (n...
Definition nav_history.cpp:91
std::optional< NavEntry > peekForward(const Valid &valid) const
Next screen valid accepts, without moving.
Definition nav_history.h:143
void visit(const NavEntry &entry)
Records a newly shown screen (repeating the current: ignored).
Definition nav_history.cpp:78
static constexpr std::size_t DEFAULT_CAPACITY
Definition nav_history.h:111
std::size_t capacity() const
Definition nav_history.h:170
std::size_t limit
Definition nav_history.h:195
std::size_t cursor
Definition nav_history.h:194
std::vector< NavEntry > entries
Definition nav_history.h:193
std::optional< NavEntry > back(const Valid &valid)
Steps back to the previous screen valid accepts.
Definition nav_history.h:151
std::size_t size() const
Definition nav_history.h:169
std::optional< NavEntry > peekBack(const Valid &valid) const
Previous screen valid accepts, without moving.
Definition nav_history.h:135
std::optional< std::size_t > findForward(const Valid &valid) const
Definition nav_history.h:185
std::size_t position() const
Index of the current entry (0 when empty).
Definition nav_history.h:172
std::optional< NavEntry > current() const
Screen shown now, if any was recorded.
Definition nav_history.cpp:127
std::optional< NavEntry > forward(const Valid &valid)
Steps forward to the next screen valid accepts.
Definition nav_history.h:161
void clear()
Forgets every entry (a career was started or loaded).
Definition nav_history.cpp:121
NavSection
Screens of the management shell. The sidebar groups them into a few hubs (Home, Inbox,...
Definition nav_history.h:26
int index
Definition runtime_editor.cpp:94
Represents a specific date in the game world.
Definition gamedate.h:20
A screen of the career as the recipe to open it again (which section, player, club or fixture),...
Definition nav_history.h:65
static NavEntry ofClub(TeamID team)
Definition nav_history.cpp:28
static NavEntry ofMatchReport(GameDateValue date, TeamID home, TeamID away)
Definition nav_history.cpp:36
GameDateValue date
Definition nav_history.h:81
TeamID away_team
Definition nav_history.h:80
bool operator==(const NavEntry &other) const =default
PlayerID player
Definition nav_history.h:77
bool isDetail() const
True for screens opened on top of another one (a profile, a report, a comparison of chosen players) r...
Definition nav_history.cpp:55
Kind kind
Definition nav_history.h:75
TeamID team
Definition nav_history.h:79
static NavEntry ofPlayer(PlayerID player)
Definition nav_history.cpp:20
PlayerID second_player
Definition nav_history.h:78
Kind
Definition nav_history.h:67
static NavEntry ofCompare(PlayerID first, PlayerID second)
Definition nav_history.cpp:46
static NavEntry ofSection(NavSection section)
Definition nav_history.cpp:13
NavSection section
Definition nav_history.h:76
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21