1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Add game pause

This commit is contained in:
nordsoft 2023-10-07 01:44:37 +02:00
parent 088ce9b948
commit d7d435dcb7
23 changed files with 83 additions and 18 deletions

View File

@ -274,6 +274,19 @@ void CCallback::save( const std::string &fname )
cl->save(fname);
}
void CCallback::gamePause(bool pause)
{
if(pause)
{
GamePause pack;
pack.player = *player;
sendRequest(&pack);
}
else
{
sendQueryReply(0, QueryID::CLIENT);
}
}
void CCallback::sendMessage(const std::string &mess, const CGObjectInstance * currentObject)
{

View File

@ -98,6 +98,7 @@ public:
virtual void save(const std::string &fname) = 0;
virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 0;
virtual void gamePause(bool pause) = 0;
virtual void buildBoat(const IShipyard *obj) = 0;
// To implement high-level army management bulk actions
@ -186,6 +187,7 @@ public:
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero) override;
void save(const std::string &fname) override;
void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
void gamePause(bool pause) override;
void buildBoat(const IShipyard *obj) override;
void dig(const CGObjectInstance *hero) override;
void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1)) override;

View File

@ -265,6 +265,11 @@ void CPlayerInterface::performAutosave()
}
}
void CPlayerInterface::gamePause(bool pause)
{
cb->gamePause(pause);
}
void CPlayerInterface::yourTurn(QueryID queryID)
{
EVENT_HANDLER_CALLED_BY_CLIENT;

View File

@ -200,6 +200,7 @@ public: // public interface for use by client via LOCPLINT access
void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
void proposeLoadingGame();
void performAutosave();
void gamePause(bool pause);
///returns true if all events are processed internally
bool capturedAllEvents();

View File

@ -144,7 +144,7 @@ class WindowBase : public CIntObject
public:
WindowBase(int used_ = 0, Point pos_ = Point());
protected:
void close();
virtual void close();
};
class IGarrisonHolder

View File

@ -41,6 +41,8 @@ CSavingScreen::CSavingScreen()
curTab = tabSel;
buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRSAV.DEF"), CGI->generaltexth->zelp[103], std::bind(&CSavingScreen::saveGame, this), EShortcut::LOBBY_SAVE_GAME);
LOCPLINT->gamePause(true);
}
const CMapInfo * CSavingScreen::getMapInfo()
@ -65,6 +67,12 @@ void CSavingScreen::changeSelection(std::shared_ptr<CMapInfo> to)
card->redraw();
}
void CSavingScreen::close()
{
LOCPLINT->gamePause(false);
CSelectionBase::close();
}
void CSavingScreen::saveGame()
{
if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))

View File

@ -32,4 +32,7 @@ public:
const CMapInfo * getMapInfo() override;
const StartInfo * getStartInfo() override;
protected:
void close() override;
};

View File

@ -250,7 +250,7 @@ public:
void townChange();
void keyPressed(EShortcut key) override;
void close();
void close() override;
void addBuilding(BuildingID bid);
void removeBuilding(BuildingID bid);
void recreateIcons();

View File

@ -86,7 +86,7 @@ public:
CTradeWindow(const ImagePath & bgName, const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode); //c
void showAll(Canvas & to) override;
void close();
void close() override;
void initSubs(bool Left);
void initTypes();

View File

@ -90,7 +90,7 @@ public:
const CGDwelling * const dwelling;
CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function<void(CreatureID,int)> & Recruit, const std::function<void()> & onClose, int y_offset = 0);
void availableCreaturesChanged();
void close();
void close() override;
};
/// Split window where creatures can be split up into two single unit stacks
@ -240,7 +240,7 @@ public:
CTavernWindow(const CGObjectInstance * TavernObj, const std::function<void()> & onWindowClosed);
~CTavernWindow();
void close();
void close() override;
void recruitb();
void thievesguildb();
void show(Canvas & to) override;
@ -360,7 +360,7 @@ public:
void makeDeal();
void addAll();
void close();
void close() override;
void updateGarrisons() override;
CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function<void()> & onWindowClosed);
};

View File

@ -56,7 +56,7 @@ public:
std::vector<std::shared_ptr<CButton>> buttons;
TCompsInfo components;
virtual void close();
void close() override;
void show(Canvas & to) override;
void showAll(Canvas & to) override;
@ -79,7 +79,7 @@ public:
class CRClickPopup : public WindowBase
{
public:
virtual void close();
virtual void close() override;
bool isPopupWindow() const override;
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);

View File

@ -75,6 +75,8 @@ SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : Inter
std::shared_ptr<CToggleGroup> mainTabs = widget<CToggleGroup>("settingsTabs");
mainTabs->setSelected(defaultTabIndex);
LOCPLINT->gamePause(true);
}
std::shared_ptr<CIntObject> SettingsMainWindow::createTab(size_t index)
@ -108,6 +110,8 @@ void SettingsMainWindow::close()
{
if(!GH.windows().isTopWindow(this))
logGlobal->error("Only top interface must be closed");
LOCPLINT->gamePause(false);
GH.windows().popWindows(1);
}

View File

@ -29,6 +29,7 @@ public:
virtual void visitPlayerStartsTurn(PlayerStartsTurn & pack) {}
virtual void visitDaysWithoutTown(DaysWithoutTown & pack) {}
virtual void visitTurnTimeUpdate(TurnTimeUpdate & pack) {}
virtual void visitGamePause(GamePause & pack) {}
virtual void visitEntitiesChanged(EntitiesChanged & pack) {}
virtual void visitSetResources(SetResources & pack) {}
virtual void visitSetPrimSkill(SetPrimSkill & pack) {}

View File

@ -2093,6 +2093,16 @@ protected:
/***********************************************************************************************************/
struct DLL_LINKAGE GamePause : public CPackForServer
{
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & static_cast<CPackForServer &>(*this);
}
};
struct DLL_LINKAGE EndTurn : public CPackForServer
{
virtual void visitTyped(ICPackVisitor & visitor) override;

View File

@ -520,6 +520,11 @@ void EndTurn::visitTyped(ICPackVisitor & visitor)
visitor.visitEndTurn(*this);
}
void GamePause::visitTyped(ICPackVisitor & visitor)
{
visitor.visitGamePause(*this);
}
void DismissHero::visitTyped(ICPackVisitor & visitor)
{
visitor.visitDismissHero(*this);

View File

@ -40,6 +40,7 @@ VCMI_LIB_NAMESPACE_BEGIN
const BattleID BattleID::NONE(-1);
const QueryID QueryID::NONE(-1);
const QueryID QueryID::CLIENT(-2);
const HeroTypeID HeroTypeID::NONE(-1);
const HeroTypeID HeroTypeID::RANDOM(-2);
const ObjectInstanceID ObjectInstanceID::NONE(-1);

View File

@ -203,6 +203,7 @@ class QueryID : public Identifier<QueryID>
public:
using Identifier<QueryID>::Identifier;
DLL_LINKAGE static const QueryID NONE;
DLL_LINKAGE static const QueryID CLIENT;
};
class BattleID : public Identifier<BattleID>

View File

@ -367,6 +367,7 @@ void registerTypesServerPacks(Serializer &s)
s.template registerType<CPackForServer, BulkMoveArmy>();
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
s.template registerType<CPackForServer, EraseArtifactByClient>();
s.template registerType<CPackForServer, GamePause>();
}
template<typename Serializer>

View File

@ -16,6 +16,7 @@
#include "processors/PlayerMessageProcessor.h"
#include "processors/TurnOrderProcessor.h"
#include "queries/QueriesProcessor.h"
#include "queries/MapQueries.h"
#include "../lib/IGameCallback.h"
#include "../lib/mapObjects/CGTownInstance.h"
@ -35,6 +36,14 @@ void ApplyGhNetPackVisitor::visitSaveGame(SaveGame & pack)
result = true;
}
void ApplyGhNetPackVisitor::visitGamePause(GamePause & pack)
{
auto turnQuery = std::make_shared<TimerPauseQuery>(&gh, pack.player);
turnQuery->queryID = QueryID::CLIENT;
gh.queries->addQuery(turnQuery);
result = true;
}
void ApplyGhNetPackVisitor::visitEndTurn(EndTurn & pack)
{
gh.throwIfWrongPlayer(&pack);

View File

@ -29,6 +29,7 @@ public:
}
virtual void visitSaveGame(SaveGame & pack) override;
virtual void visitGamePause(GamePause & pack) override;
virtual void visitEndTurn(EndTurn & pack) override;
virtual void visitDismissHero(DismissHero & pack) override;
virtual void visitMoveHero(MoveHero & pack) override;

View File

@ -216,7 +216,7 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
awaitingPlayers.erase(which);
gameHandler->onPlayerTurnStarted(which);
auto turnQuery = std::make_shared<PlayerStartsTurnQuery>(gameHandler, which);
auto turnQuery = std::make_shared<TimerPauseQuery>(gameHandler, which);
gameHandler->queries->addQuery(turnQuery);
PlayerStartsTurn pst;

View File

@ -15,28 +15,28 @@
#include "../../lib/mapObjects/MiscObjects.h"
#include "../../lib/serializer/Cast.h"
PlayerStartsTurnQuery::PlayerStartsTurnQuery(CGameHandler * owner, PlayerColor player):
TimerPauseQuery::TimerPauseQuery(CGameHandler * owner, PlayerColor player):
CQuery(owner)
{
addPlayer(player);
}
bool PlayerStartsTurnQuery::blocksPack(const CPack *pack) const
bool TimerPauseQuery::blocksPack(const CPack *pack) const
{
return blockAllButReply(pack);
}
void PlayerStartsTurnQuery::onAdding(PlayerColor color)
void TimerPauseQuery::onAdding(PlayerColor color)
{
gh->turnTimerHandler.setTimerEnabled(color, false);
}
void PlayerStartsTurnQuery::onRemoval(PlayerColor color)
void TimerPauseQuery::onRemoval(PlayerColor color)
{
gh->turnTimerHandler.setTimerEnabled(color, true);
}
bool PlayerStartsTurnQuery::endsByPlayerAnswer() const
bool TimerPauseQuery::endsByPlayerAnswer() const
{
return true;
}

View File

@ -15,12 +15,12 @@
class TurnTimerHandler;
//Created when player starts turn
//Removed when player accepts a turn
class PlayerStartsTurnQuery : public CQuery
//Created when player starts turn or when player puts game on [ause
//Removed when player accepts a turn or continur play
class TimerPauseQuery : public CQuery
{
public:
PlayerStartsTurnQuery(CGameHandler * owner, PlayerColor player);
TimerPauseQuery(CGameHandler * owner, PlayerColor player);
bool blocksPack(const CPack *pack) const override;
void onAdding(PlayerColor color) override;