ソースを参照

enable/disable quickload button

Laserlicht 1 週間 前
コミット
27f040af5c

+ 24 - 14
client/CPlayerInterface.cpp

@@ -147,6 +147,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player):
 	isAutoFightOn = false;
 	isAutoFightEndBattle = false;
 	ignoreEvents = false;
+	hasQuickSave = checkQuickLoadingGame();
 }
 
 CPlayerInterface::~CPlayerInterface()
@@ -1804,30 +1805,39 @@ void CPlayerInterface::proposeLoadingGame()
 
 void CPlayerInterface::quickSaveGame()
 {
-	std::string path = "Saves/Quicksave";
 	// notify player about saving
-	GAME->server().getGameChat().sendMessageGameplay("Saving game to " + path);
-	GAME->interface()->cb->save(path);
+	GAME->server().getGameChat().sendMessageGameplay("Saving game to " + QUICKSAVE_PATH);
+	GAME->interface()->cb->save(QUICKSAVE_PATH);
+	hasQuickSave = true;
+	adventureInt->updateActiveState();
 }
 
-void CPlayerInterface::proposeQuickLoadingGame()
+bool CPlayerInterface::checkQuickLoadingGame(bool verbose)
 {
-	std::string path = "Saves/Quicksave";
-
-	if(!CResourceHandler::get("local")->existsResource(ResourcePath(path, EResType::SAVEGAME)))
+	if(!CResourceHandler::get("local")->existsResource(ResourcePath(QUICKSAVE_PATH, EResType::SAVEGAME)))
 	{
-		logGlobal->error("No quicksave file found at %s", path);
-		return;
+		if(verbose)
+			logGlobal->error("No quicksave file found at %s", QUICKSAVE_PATH);
+		return false;
 	}
-	auto error = GAME->server().canQuickLoadGame(path);
+	auto error = GAME->server().canQuickLoadGame(QUICKSAVE_PATH);
 	if (error)
 	{
-		logGlobal->error("Cannot quick load game at %s: %s", path, *error);
-		return;
+		if(verbose)
+			logGlobal->error("Cannot quick load game at %s: %s", QUICKSAVE_PATH, *error);
+		return false;
 	}
-	auto onYes = [path]() -> void
+	return true;
+}
+
+void CPlayerInterface::proposeQuickLoadingGame()
+{
+	if(!checkQuickLoadingGame(true))
+		return;
+
+	auto onYes = [this]() -> void
 	{
-		GAME->server().quickLoadGame(path);
+		GAME->server().quickLoadGame(QUICKSAVE_PATH);
 	};
 
 	GAME->interface()->showYesNoDialog(LIBRARY->generaltexth->translate("vcmi.adventureMap.confirmQuickLoadGame"), onYes, nullptr);

+ 5 - 0
client/CPlayerInterface.h

@@ -64,6 +64,8 @@ class CPlayerInterface : public CGameInterface
 	bool ignoreEvents;
 	int autosaveCount;
 
+	const std::string QUICKSAVE_PATH = "Saves/Quicksave";
+
 	std::list<std::shared_ptr<CInfoWindow>> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
 
 	std::unique_ptr<HeroMovementController> movementController;
@@ -85,6 +87,8 @@ public: // TODO: make private
 
 	std::shared_ptr<CCallback> cb; //to communicate with engine
 
+	bool hasQuickSave;
+
 	//During battle is quick combat mode is used
 	std::shared_ptr<CBattleGameInterface> autofightingAI; //AI that makes decisions
 	bool isAutoFightOn; //Flag, switch it to stop quick combat. Don't touch if there is no battle interface.
@@ -201,6 +205,7 @@ public: // public interface for use by client via GAME->interface() access
 	void tryDigging(const CGHeroInstance *h);
 	void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
 	void proposeLoadingGame();
+	bool checkQuickLoadingGame(bool verbose = false);
 	void proposeQuickLoadingGame();
 	void quickSaveGame();
 	void performAutosave();

+ 5 - 0
client/adventureMap/AdventureMapInterface.cpp

@@ -932,3 +932,8 @@ bool AdventureMapInterface::isValidAdventureSpellTarget(int3 targetPosition) con
 
 	return spellBeingCasted->getAdventureMechanics().canBeCastAt(problem, GAME->interface()->cb.get(), GAME->interface()->localState->getCurrentHero(), targetPosition);
 }
+
+void AdventureMapInterface::updateActiveState()
+{
+	widget->updateActiveState();
+}

+ 3 - 0
client/adventureMap/AdventureMapInterface.h

@@ -192,6 +192,9 @@ public:
 
 	/// opens world view with specific info, e.g. after View Earth/Air is shown
 	void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
+
+	/// update state of buttons
+	void updateActiveState();
 };
 
 extern std::shared_ptr<AdventureMapInterface> adventureInt;

+ 6 - 1
client/adventureMap/AdventureMapShortcuts.cpp

@@ -98,7 +98,7 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
 		{ EShortcut::ADVENTURE_NEW_GAME,         optionInMapView(),      [this]() { this->newGame(); } },
 		{ EShortcut::ADVENTURE_LOAD_GAME,        optionInMapView(),      [this]() { this->loadGame(); } },
 		{ EShortcut::ADVENTURE_QUICK_SAVE,       optionIsLocal(),        [this]() { this->quickSaveGame(); } },
-		{ EShortcut::ADVENTURE_QUICK_LOAD,       optionIsLocal(),        [this]() { this->quickLoadGame(); } },
+		{ EShortcut::ADVENTURE_QUICK_LOAD,       optionQuickSaveLoad(),  [this]() { this->quickLoadGame(); } },
 		{ EShortcut::ADVENTURE_RESTART_GAME,     optionInMapView(),      [this]() { this->restartGame(); } },
 		{ EShortcut::ADVENTURE_DIG_GRAIL,        optionHeroDig(),        [this]() { this->digGrail(); } },
 		{ EShortcut::ADVENTURE_VIEW_PUZZLE,      optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } },
@@ -718,3 +718,8 @@ bool AdventureMapShortcuts::optionIsLocal()
 	}
 	return true;
 }
+
+bool AdventureMapShortcuts::optionQuickSaveLoad()
+{
+	return optionIsLocal() && GAME->interface()->hasQuickSave;
+}

+ 1 - 0
client/adventureMap/AdventureMapShortcuts.h

@@ -108,6 +108,7 @@ public:
 	bool optionHeroDig();
 	bool optionViewStatistic();
 	bool optionIsLocal();
+	bool optionQuickSaveLoad();
 
 	void setState(EAdventureState newState);
 	EAdventureState getState() const;