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:
parent
088ce9b948
commit
d7d435dcb7
@ -274,6 +274,19 @@ void CCallback::save( const std::string &fname )
|
|||||||
cl->save(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)
|
void CCallback::sendMessage(const std::string &mess, const CGObjectInstance * currentObject)
|
||||||
{
|
{
|
||||||
|
@ -98,6 +98,7 @@ public:
|
|||||||
|
|
||||||
virtual void save(const std::string &fname) = 0;
|
virtual void save(const std::string &fname) = 0;
|
||||||
virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 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;
|
virtual void buildBoat(const IShipyard *obj) = 0;
|
||||||
|
|
||||||
// To implement high-level army management bulk actions
|
// To implement high-level army management bulk actions
|
||||||
@ -186,6 +187,7 @@ public:
|
|||||||
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero) override;
|
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero) override;
|
||||||
void save(const std::string &fname) override;
|
void save(const std::string &fname) override;
|
||||||
void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
|
void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
|
||||||
|
void gamePause(bool pause) override;
|
||||||
void buildBoat(const IShipyard *obj) override;
|
void buildBoat(const IShipyard *obj) override;
|
||||||
void dig(const CGObjectInstance *hero) override;
|
void dig(const CGObjectInstance *hero) override;
|
||||||
void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1)) override;
|
void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1)) override;
|
||||||
|
@ -265,6 +265,11 @@ void CPlayerInterface::performAutosave()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPlayerInterface::gamePause(bool pause)
|
||||||
|
{
|
||||||
|
cb->gamePause(pause);
|
||||||
|
}
|
||||||
|
|
||||||
void CPlayerInterface::yourTurn(QueryID queryID)
|
void CPlayerInterface::yourTurn(QueryID queryID)
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
|
@ -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 showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
|
||||||
void proposeLoadingGame();
|
void proposeLoadingGame();
|
||||||
void performAutosave();
|
void performAutosave();
|
||||||
|
void gamePause(bool pause);
|
||||||
|
|
||||||
///returns true if all events are processed internally
|
///returns true if all events are processed internally
|
||||||
bool capturedAllEvents();
|
bool capturedAllEvents();
|
||||||
|
@ -144,7 +144,7 @@ class WindowBase : public CIntObject
|
|||||||
public:
|
public:
|
||||||
WindowBase(int used_ = 0, Point pos_ = Point());
|
WindowBase(int used_ = 0, Point pos_ = Point());
|
||||||
protected:
|
protected:
|
||||||
void close();
|
virtual void close();
|
||||||
};
|
};
|
||||||
|
|
||||||
class IGarrisonHolder
|
class IGarrisonHolder
|
||||||
|
@ -41,6 +41,8 @@ CSavingScreen::CSavingScreen()
|
|||||||
curTab = tabSel;
|
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);
|
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()
|
const CMapInfo * CSavingScreen::getMapInfo()
|
||||||
@ -65,6 +67,12 @@ void CSavingScreen::changeSelection(std::shared_ptr<CMapInfo> to)
|
|||||||
card->redraw();
|
card->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSavingScreen::close()
|
||||||
|
{
|
||||||
|
LOCPLINT->gamePause(false);
|
||||||
|
CSelectionBase::close();
|
||||||
|
}
|
||||||
|
|
||||||
void CSavingScreen::saveGame()
|
void CSavingScreen::saveGame()
|
||||||
{
|
{
|
||||||
if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))
|
if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))
|
||||||
|
@ -32,4 +32,7 @@ public:
|
|||||||
|
|
||||||
const CMapInfo * getMapInfo() override;
|
const CMapInfo * getMapInfo() override;
|
||||||
const StartInfo * getStartInfo() override;
|
const StartInfo * getStartInfo() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void close() override;
|
||||||
};
|
};
|
||||||
|
@ -250,7 +250,7 @@ public:
|
|||||||
void townChange();
|
void townChange();
|
||||||
void keyPressed(EShortcut key) override;
|
void keyPressed(EShortcut key) override;
|
||||||
|
|
||||||
void close();
|
void close() override;
|
||||||
void addBuilding(BuildingID bid);
|
void addBuilding(BuildingID bid);
|
||||||
void removeBuilding(BuildingID bid);
|
void removeBuilding(BuildingID bid);
|
||||||
void recreateIcons();
|
void recreateIcons();
|
||||||
|
@ -86,7 +86,7 @@ public:
|
|||||||
CTradeWindow(const ImagePath & bgName, const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode); //c
|
CTradeWindow(const ImagePath & bgName, const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode); //c
|
||||||
|
|
||||||
void showAll(Canvas & to) override;
|
void showAll(Canvas & to) override;
|
||||||
void close();
|
void close() override;
|
||||||
|
|
||||||
void initSubs(bool Left);
|
void initSubs(bool Left);
|
||||||
void initTypes();
|
void initTypes();
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
const CGDwelling * const dwelling;
|
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);
|
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 availableCreaturesChanged();
|
||||||
void close();
|
void close() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Split window where creatures can be split up into two single unit stacks
|
/// 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(const CGObjectInstance * TavernObj, const std::function<void()> & onWindowClosed);
|
||||||
~CTavernWindow();
|
~CTavernWindow();
|
||||||
|
|
||||||
void close();
|
void close() override;
|
||||||
void recruitb();
|
void recruitb();
|
||||||
void thievesguildb();
|
void thievesguildb();
|
||||||
void show(Canvas & to) override;
|
void show(Canvas & to) override;
|
||||||
@ -360,7 +360,7 @@ public:
|
|||||||
|
|
||||||
void makeDeal();
|
void makeDeal();
|
||||||
void addAll();
|
void addAll();
|
||||||
void close();
|
void close() override;
|
||||||
void updateGarrisons() override;
|
void updateGarrisons() override;
|
||||||
CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function<void()> & onWindowClosed);
|
CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero, const std::function<void()> & onWindowClosed);
|
||||||
};
|
};
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
std::vector<std::shared_ptr<CButton>> buttons;
|
std::vector<std::shared_ptr<CButton>> buttons;
|
||||||
TCompsInfo components;
|
TCompsInfo components;
|
||||||
|
|
||||||
virtual void close();
|
void close() override;
|
||||||
|
|
||||||
void show(Canvas & to) override;
|
void show(Canvas & to) override;
|
||||||
void showAll(Canvas & to) override;
|
void showAll(Canvas & to) override;
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
class CRClickPopup : public WindowBase
|
class CRClickPopup : public WindowBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void close();
|
virtual void close() override;
|
||||||
bool isPopupWindow() const override;
|
bool isPopupWindow() const override;
|
||||||
|
|
||||||
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
|
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
|
||||||
|
@ -75,6 +75,8 @@ SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : Inter
|
|||||||
|
|
||||||
std::shared_ptr<CToggleGroup> mainTabs = widget<CToggleGroup>("settingsTabs");
|
std::shared_ptr<CToggleGroup> mainTabs = widget<CToggleGroup>("settingsTabs");
|
||||||
mainTabs->setSelected(defaultTabIndex);
|
mainTabs->setSelected(defaultTabIndex);
|
||||||
|
|
||||||
|
LOCPLINT->gamePause(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CIntObject> SettingsMainWindow::createTab(size_t index)
|
std::shared_ptr<CIntObject> SettingsMainWindow::createTab(size_t index)
|
||||||
@ -108,6 +110,8 @@ void SettingsMainWindow::close()
|
|||||||
{
|
{
|
||||||
if(!GH.windows().isTopWindow(this))
|
if(!GH.windows().isTopWindow(this))
|
||||||
logGlobal->error("Only top interface must be closed");
|
logGlobal->error("Only top interface must be closed");
|
||||||
|
|
||||||
|
LOCPLINT->gamePause(false);
|
||||||
GH.windows().popWindows(1);
|
GH.windows().popWindows(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ public:
|
|||||||
virtual void visitPlayerStartsTurn(PlayerStartsTurn & pack) {}
|
virtual void visitPlayerStartsTurn(PlayerStartsTurn & pack) {}
|
||||||
virtual void visitDaysWithoutTown(DaysWithoutTown & pack) {}
|
virtual void visitDaysWithoutTown(DaysWithoutTown & pack) {}
|
||||||
virtual void visitTurnTimeUpdate(TurnTimeUpdate & pack) {}
|
virtual void visitTurnTimeUpdate(TurnTimeUpdate & pack) {}
|
||||||
|
virtual void visitGamePause(GamePause & pack) {}
|
||||||
virtual void visitEntitiesChanged(EntitiesChanged & pack) {}
|
virtual void visitEntitiesChanged(EntitiesChanged & pack) {}
|
||||||
virtual void visitSetResources(SetResources & pack) {}
|
virtual void visitSetResources(SetResources & pack) {}
|
||||||
virtual void visitSetPrimSkill(SetPrimSkill & pack) {}
|
virtual void visitSetPrimSkill(SetPrimSkill & pack) {}
|
||||||
|
@ -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
|
struct DLL_LINKAGE EndTurn : public CPackForServer
|
||||||
{
|
{
|
||||||
virtual void visitTyped(ICPackVisitor & visitor) override;
|
virtual void visitTyped(ICPackVisitor & visitor) override;
|
||||||
|
@ -520,6 +520,11 @@ void EndTurn::visitTyped(ICPackVisitor & visitor)
|
|||||||
visitor.visitEndTurn(*this);
|
visitor.visitEndTurn(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GamePause::visitTyped(ICPackVisitor & visitor)
|
||||||
|
{
|
||||||
|
visitor.visitGamePause(*this);
|
||||||
|
}
|
||||||
|
|
||||||
void DismissHero::visitTyped(ICPackVisitor & visitor)
|
void DismissHero::visitTyped(ICPackVisitor & visitor)
|
||||||
{
|
{
|
||||||
visitor.visitDismissHero(*this);
|
visitor.visitDismissHero(*this);
|
||||||
|
@ -40,6 +40,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
const BattleID BattleID::NONE(-1);
|
const BattleID BattleID::NONE(-1);
|
||||||
const QueryID QueryID::NONE(-1);
|
const QueryID QueryID::NONE(-1);
|
||||||
|
const QueryID QueryID::CLIENT(-2);
|
||||||
const HeroTypeID HeroTypeID::NONE(-1);
|
const HeroTypeID HeroTypeID::NONE(-1);
|
||||||
const HeroTypeID HeroTypeID::RANDOM(-2);
|
const HeroTypeID HeroTypeID::RANDOM(-2);
|
||||||
const ObjectInstanceID ObjectInstanceID::NONE(-1);
|
const ObjectInstanceID ObjectInstanceID::NONE(-1);
|
||||||
|
@ -203,6 +203,7 @@ class QueryID : public Identifier<QueryID>
|
|||||||
public:
|
public:
|
||||||
using Identifier<QueryID>::Identifier;
|
using Identifier<QueryID>::Identifier;
|
||||||
DLL_LINKAGE static const QueryID NONE;
|
DLL_LINKAGE static const QueryID NONE;
|
||||||
|
DLL_LINKAGE static const QueryID CLIENT;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BattleID : public Identifier<BattleID>
|
class BattleID : public Identifier<BattleID>
|
||||||
|
@ -367,6 +367,7 @@ void registerTypesServerPacks(Serializer &s)
|
|||||||
s.template registerType<CPackForServer, BulkMoveArmy>();
|
s.template registerType<CPackForServer, BulkMoveArmy>();
|
||||||
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
|
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
|
||||||
s.template registerType<CPackForServer, EraseArtifactByClient>();
|
s.template registerType<CPackForServer, EraseArtifactByClient>();
|
||||||
|
s.template registerType<CPackForServer, GamePause>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Serializer>
|
template<typename Serializer>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "processors/PlayerMessageProcessor.h"
|
#include "processors/PlayerMessageProcessor.h"
|
||||||
#include "processors/TurnOrderProcessor.h"
|
#include "processors/TurnOrderProcessor.h"
|
||||||
#include "queries/QueriesProcessor.h"
|
#include "queries/QueriesProcessor.h"
|
||||||
|
#include "queries/MapQueries.h"
|
||||||
|
|
||||||
#include "../lib/IGameCallback.h"
|
#include "../lib/IGameCallback.h"
|
||||||
#include "../lib/mapObjects/CGTownInstance.h"
|
#include "../lib/mapObjects/CGTownInstance.h"
|
||||||
@ -35,6 +36,14 @@ void ApplyGhNetPackVisitor::visitSaveGame(SaveGame & pack)
|
|||||||
result = true;
|
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)
|
void ApplyGhNetPackVisitor::visitEndTurn(EndTurn & pack)
|
||||||
{
|
{
|
||||||
gh.throwIfWrongPlayer(&pack);
|
gh.throwIfWrongPlayer(&pack);
|
||||||
|
@ -29,6 +29,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void visitSaveGame(SaveGame & pack) override;
|
virtual void visitSaveGame(SaveGame & pack) override;
|
||||||
|
virtual void visitGamePause(GamePause & pack) override;
|
||||||
virtual void visitEndTurn(EndTurn & pack) override;
|
virtual void visitEndTurn(EndTurn & pack) override;
|
||||||
virtual void visitDismissHero(DismissHero & pack) override;
|
virtual void visitDismissHero(DismissHero & pack) override;
|
||||||
virtual void visitMoveHero(MoveHero & pack) override;
|
virtual void visitMoveHero(MoveHero & pack) override;
|
||||||
|
@ -216,7 +216,7 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
|
|||||||
awaitingPlayers.erase(which);
|
awaitingPlayers.erase(which);
|
||||||
gameHandler->onPlayerTurnStarted(which);
|
gameHandler->onPlayerTurnStarted(which);
|
||||||
|
|
||||||
auto turnQuery = std::make_shared<PlayerStartsTurnQuery>(gameHandler, which);
|
auto turnQuery = std::make_shared<TimerPauseQuery>(gameHandler, which);
|
||||||
gameHandler->queries->addQuery(turnQuery);
|
gameHandler->queries->addQuery(turnQuery);
|
||||||
|
|
||||||
PlayerStartsTurn pst;
|
PlayerStartsTurn pst;
|
||||||
|
@ -15,28 +15,28 @@
|
|||||||
#include "../../lib/mapObjects/MiscObjects.h"
|
#include "../../lib/mapObjects/MiscObjects.h"
|
||||||
#include "../../lib/serializer/Cast.h"
|
#include "../../lib/serializer/Cast.h"
|
||||||
|
|
||||||
PlayerStartsTurnQuery::PlayerStartsTurnQuery(CGameHandler * owner, PlayerColor player):
|
TimerPauseQuery::TimerPauseQuery(CGameHandler * owner, PlayerColor player):
|
||||||
CQuery(owner)
|
CQuery(owner)
|
||||||
{
|
{
|
||||||
addPlayer(player);
|
addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerStartsTurnQuery::blocksPack(const CPack *pack) const
|
bool TimerPauseQuery::blocksPack(const CPack *pack) const
|
||||||
{
|
{
|
||||||
return blockAllButReply(pack);
|
return blockAllButReply(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerStartsTurnQuery::onAdding(PlayerColor color)
|
void TimerPauseQuery::onAdding(PlayerColor color)
|
||||||
{
|
{
|
||||||
gh->turnTimerHandler.setTimerEnabled(color, false);
|
gh->turnTimerHandler.setTimerEnabled(color, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerStartsTurnQuery::onRemoval(PlayerColor color)
|
void TimerPauseQuery::onRemoval(PlayerColor color)
|
||||||
{
|
{
|
||||||
gh->turnTimerHandler.setTimerEnabled(color, true);
|
gh->turnTimerHandler.setTimerEnabled(color, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerStartsTurnQuery::endsByPlayerAnswer() const
|
bool TimerPauseQuery::endsByPlayerAnswer() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
|
|
||||||
class TurnTimerHandler;
|
class TurnTimerHandler;
|
||||||
|
|
||||||
//Created when player starts turn
|
//Created when player starts turn or when player puts game on [ause
|
||||||
//Removed when player accepts a turn
|
//Removed when player accepts a turn or continur play
|
||||||
class PlayerStartsTurnQuery : public CQuery
|
class TimerPauseQuery : public CQuery
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerStartsTurnQuery(CGameHandler * owner, PlayerColor player);
|
TimerPauseQuery(CGameHandler * owner, PlayerColor player);
|
||||||
|
|
||||||
bool blocksPack(const CPack *pack) const override;
|
bool blocksPack(const CPack *pack) const override;
|
||||||
void onAdding(PlayerColor color) override;
|
void onAdding(PlayerColor color) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user