2013-11-16 10:31:46 +01:00
|
|
|
#ifndef GAME_STATE_STATEMANAGER_H
|
|
|
|
#define GAME_STATE_STATEMANAGER_H
|
|
|
|
|
2022-06-08 23:25:50 +02:00
|
|
|
#include <filesystem>
|
2014-01-27 13:27:42 +01:00
|
|
|
#include <map>
|
|
|
|
|
2013-11-16 10:31:46 +01:00
|
|
|
#include "../mwbase/statemanager.hpp"
|
|
|
|
|
2013-11-19 15:38:26 +01:00
|
|
|
#include "charactermanager.hpp"
|
|
|
|
|
2013-11-16 10:31:46 +01:00
|
|
|
namespace MWState
|
|
|
|
{
|
|
|
|
class StateManager : public MWBase::StateManager
|
|
|
|
{
|
2013-11-16 11:07:23 +01:00
|
|
|
bool mQuitRequest;
|
2013-12-19 22:08:34 +02:00
|
|
|
bool mAskLoadRecent;
|
2023-09-05 22:45:38 +02:00
|
|
|
bool mNewGameRequest = false;
|
|
|
|
std::optional<std::filesystem::path> mLoadRequest;
|
2013-11-18 15:15:47 +01:00
|
|
|
State mState;
|
2013-11-19 15:38:26 +01:00
|
|
|
CharacterManager mCharacterManager;
|
2013-11-28 09:33:50 +01:00
|
|
|
double mTimePlayed;
|
2024-01-01 13:22:11 +03:00
|
|
|
std::filesystem::path mLastSavegame;
|
2013-11-28 11:22:34 +01:00
|
|
|
|
2015-01-10 23:58:55 +01:00
|
|
|
private:
|
|
|
|
void cleanup(bool force = false);
|
|
|
|
|
2024-01-21 12:54:33 +04:00
|
|
|
void printSavegameFormatError(const std::string& exceptionText, const std::string& messageBoxText);
|
|
|
|
|
2023-11-16 11:41:19 +04:00
|
|
|
bool confirmLoading(const std::vector<std::string_view>& missingFiles) const;
|
2015-06-03 16:40:16 +02:00
|
|
|
|
2014-01-27 13:27:42 +01:00
|
|
|
void writeScreenshot(std::vector<char>& imageData) const;
|
|
|
|
|
|
|
|
std::map<int, int> buildContentFileIndexMap(const ESM::ESMReader& reader) const;
|
2013-11-16 10:31:46 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2022-06-08 23:25:50 +02:00
|
|
|
StateManager(const std::filesystem::path& saves, const std::vector<std::string>& contentFiles);
|
2013-11-16 10:31:46 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void requestQuit() override;
|
2013-11-16 11:07:23 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool hasQuitRequest() const override;
|
2013-11-16 12:22:28 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void askLoadRecent() override;
|
2013-12-19 22:08:34 +02:00
|
|
|
|
2023-09-05 22:45:38 +02:00
|
|
|
void requestNewGame() override { mNewGameRequest = true; }
|
|
|
|
void requestLoad(const std::filesystem::path& filepath) override { mLoadRequest = filepath; }
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
State getState() const override;
|
2013-11-16 12:22:28 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void newGame(bool bypass = false) override;
|
2013-11-16 12:22:28 +01:00
|
|
|
///< Start a new game.
|
|
|
|
///
|
|
|
|
/// \param bypass Skip new game mechanics.
|
2013-11-18 15:38:08 +01:00
|
|
|
|
2022-05-06 19:56:10 +02:00
|
|
|
void endGame();
|
2013-11-19 15:38:26 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void resumeGame() override;
|
2018-07-26 19:54:08 +03:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void deleteGame(const MWState::Character* character, const MWState::Slot* slot) override;
|
2014-04-28 20:57:45 +02:00
|
|
|
///< Delete a saved game slot from this character. If all save slots are deleted, the character will be deleted
|
|
|
|
///< too.
|
|
|
|
|
2023-07-23 14:40:46 -04:00
|
|
|
void saveGame(std::string_view description, const Slot* slot = nullptr) override;
|
2013-11-19 15:38:26 +01:00
|
|
|
///< Write a saved game to \a slot or create a new slot if \a slot == 0.
|
|
|
|
///
|
|
|
|
/// \note Slot must belong to the current character.
|
|
|
|
|
2014-04-24 03:06:36 -04:00
|
|
|
/// Saves a file, using supplied filename, overwritting if needed
|
2014-04-24 03:14:47 -04:00
|
|
|
/** This is mostly used for quicksaving and autosaving, for they use the same name over and over again
|
|
|
|
\param name Name of save, defaults to "Quicksave"**/
|
2020-10-16 22:18:54 +04:00
|
|
|
void quickSave(std::string name = "Quicksave") override;
|
2014-04-24 03:06:36 -04:00
|
|
|
|
2014-04-24 03:14:47 -04:00
|
|
|
/// Loads the last saved file
|
|
|
|
/** Used for quickload **/
|
2020-10-16 22:18:54 +04:00
|
|
|
void quickLoad() override;
|
2014-04-24 03:14:47 -04:00
|
|
|
|
2022-06-19 13:28:33 +02:00
|
|
|
void loadGame(const std::filesystem::path& filepath) override;
|
2015-01-07 03:03:56 +01:00
|
|
|
///< Load a saved game directly from the given file path. This will search the CharacterManager
|
|
|
|
/// for a Character containing this save file, and set this Character current if one was found.
|
|
|
|
/// Otherwise, a new Character will be created.
|
|
|
|
|
2022-06-19 13:28:33 +02:00
|
|
|
void loadGame(const Character* character, const std::filesystem::path& filepath) override;
|
2015-01-07 03:03:56 +01:00
|
|
|
///< Load a saved game file belonging to the given character.
|
2013-11-21 12:24:24 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
Character* getCurrentCharacter() override;
|
2016-03-14 00:00:11 +01:00
|
|
|
///< @note May return null.
|
2013-11-21 11:10:18 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
CharacterIterator characterBegin() override;
|
2013-11-21 12:29:24 +01:00
|
|
|
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
|
|
|
/// iterator.
|
2013-11-21 11:10:18 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
CharacterIterator characterEnd() override;
|
2013-11-28 09:33:50 +01:00
|
|
|
|
2022-05-06 18:23:57 +02:00
|
|
|
void update(float duration);
|
2013-11-16 10:31:46 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|