1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Merge pull request #2161 from IvanSavenko/gui_handler_separate_window_handler

Separate Gui Handler into components - Window management
This commit is contained in:
Ivan Savenko 2023-05-18 22:49:58 +03:00 committed by GitHub
commit 796666ede1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 605 additions and 428 deletions

View File

@ -20,6 +20,7 @@
#include "CVideoHandler.h"
#include "CMusicHandler.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "CServerHandler.h"
#include "gui/NotificationHandler.h"
#include "ClientCommandManager.h"
@ -523,14 +524,14 @@ static void handleEvent(SDL_Event & ev)
{
if(ourCampaign->mapsRemaining.size())
{
GH.pushInt(CMM);
GH.pushInt(CMM->menu);
GH.windows().pushWindow(CMM);
GH.windows().pushWindow(CMM->menu);
CMM->openCampaignLobby(ourCampaign);
}
};
if(epilogue.hasPrologEpilog)
{
GH.pushIntT<CPrologEpilogVideo>(epilogue, finisher);
GH.windows().createAndPushWindow<CPrologEpilogVideo>(epilogue, finisher);
}
else
{
@ -547,7 +548,7 @@ static void handleEvent(SDL_Event & ev)
case EUserEvent::FULLSCREEN_TOGGLED:
{
boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
GH.screenHandler().onScreenResize();
GH.onScreenResize();
break;
}
default:
@ -564,7 +565,7 @@ static void handleEvent(SDL_Event & ev)
#ifndef VCMI_IOS
{
boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
GH.screenHandler().onScreenResize();
GH.onScreenResize();
}
#endif
break;
@ -622,8 +623,7 @@ static void quitApplication()
CSH->endGameplay();
}
GH.listInt.clear();
GH.objsToBlit.clear();
GH.windows().clear();
CMM.reset();

View File

@ -34,6 +34,7 @@ set(client_SRCS
gui/FramerateManager.cpp
gui/NotificationHandler.cpp
gui/ShortcutHandler.cpp
gui/WindowHandler.cpp
lobby/CBonusSelection.cpp
lobby/CCampaignInfoScreen.cpp
@ -169,6 +170,7 @@ set(client_HEADERS
gui/Shortcut.h
gui/ShortcutHandler.h
gui/TextAlignment.h
gui/WindowHandler.h
lobby/CBonusSelection.h
lobby/CCampaignInfoScreen.h

View File

@ -65,6 +65,7 @@
#include "../lib/CPlayerState.h"
#include "../lib/GameConstants.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "windows/InfoWindows.h"
#include "../lib/UnlockGuard.h"
#include "../lib/CPathfinder.h"
@ -168,16 +169,17 @@ void CPlayerInterface::initGameInterface(std::shared_ptr<Environment> ENV, std::
void CPlayerInterface::playerStartsTurn(PlayerColor player)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
if (!vstd::contains (GH.listInt, adventureInt))
if(GH.windows().findWindows<AdventureMapInterface>().empty())
{
// after map load - remove all active windows and replace them with adventure map
GH.popInts ((int)GH.listInt.size());
GH.pushInt (adventureInt);
GH.windows().clear();
GH.windows().pushWindow(adventureInt);
}
// remove all dialogs that do not expect query answer
while (GH.listInt.front() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.listInt.front().get()))
GH.popInts(1);
while (!GH.windows().topWindow<AdventureMapInterface>() && !GH.windows().topWindow<CInfoWindow>())
GH.windows().popWindows(1);
if (player != playerID && LOCPLINT == this)
{
@ -245,7 +247,7 @@ void CPlayerInterface::acceptTurn()
{
if (settings["session"]["autoSkip"].Bool())
{
while(CInfoWindow *iw = dynamic_cast<CInfoWindow *>(GH.topInt().get()))
while(auto iw = GH.windows().topWindow<CInfoWindow>())
iw->close();
}
@ -439,7 +441,7 @@ void CPlayerInterface::openTownWindow(const CGTownInstance * town)
auto newCastleInt = std::make_shared<CCastleInterface>(town);
GH.pushInt(newCastleInt);
GH.windows().pushWindow(newCastleInt);
}
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
@ -447,7 +449,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int
EVENT_HANDLER_CALLED_BY_CLIENT;
if (which == 4)
{
if (CAltarWindow *ctw = dynamic_cast<CAltarWindow *>(GH.topInt().get()))
for (auto ctw : GH.windows().findWindows<CAltarWindow>())
ctw->setExpToLevel();
}
else
@ -457,11 +459,8 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int
void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
CUniversityWindow* cuw = dynamic_cast<CUniversityWindow*>(GH.topInt().get());
if (cuw) //university window is open
{
GH.totalRedraw();
}
for (auto cuw : GH.windows().findWindows<CUniversityWindow>())
cuw->redraw();
}
void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
@ -480,10 +479,10 @@ void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
void CPlayerInterface::receivedResource()
{
EVENT_HANDLER_CALLED_BY_CLIENT;
if (CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(GH.topInt().get()))
for (auto mw : GH.windows().findWindows<CMarketplaceWindow>())
mw->resourceChanged();
GH.totalRedraw();
GH.windows().totalRedraw();
}
void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill>& skills, QueryID queryID)
@ -491,7 +490,7 @@ void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, PrimarySkill::Pr
EVENT_HANDLER_CALLED_BY_CLIENT;
waitWhileDialog();
CCS->soundh->playSound(soundBase::heroNewLevel);
GH.pushIntT<CLevelWindow>(hero, pskill, skills, [=](ui32 selection)
GH.windows().createAndPushWindow<CLevelWindow>(hero, pskill, skills, [=](ui32 selection)
{
cb->selectionMade(selection, queryID);
});
@ -502,7 +501,7 @@ void CPlayerInterface::commanderGotLevel (const CCommanderInstance * commander,
EVENT_HANDLER_CALLED_BY_CLIENT;
waitWhileDialog();
CCS->soundh->playSound(soundBase::heroNewLevel);
GH.pushIntT<CStackWindow>(commander, skills, [=](ui32 selection)
GH.windows().createAndPushWindow<CStackWindow>(commander, skills, [=](ui32 selection)
{
cb->selectionMade(selection, queryID);
});
@ -537,17 +536,15 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
castleInt->heroes->update();
castleInt->redraw();
}
for (auto isa : GH.listInt)
for (auto ki : GH.windows().findWindows<CKingdomInterface>())
{
CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa.get());
if (ki)
{
ki->townChanged(town);
ki->updateGarrisons();
ki->redraw();
}
ki->townChanged(town);
ki->updateGarrisons();
ki->redraw();
}
}
void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
@ -589,20 +586,16 @@ void CPlayerInterface::garrisonsChanged(std::vector<const CGObjectInstance *> ob
adventureInt->onTownChanged(town);
}
for (auto & elem : GH.listInt)
{
CGarrisonHolder *cgh = dynamic_cast<CGarrisonHolder*>(elem.get());
if (cgh)
cgh->updateGarrisons();
for (auto cgh : GH.windows().findWindows<CGarrisonHolder>())
cgh->updateGarrisons();
if (CTradeWindow *cmw = dynamic_cast<CTradeWindow*>(elem.get()))
{
if (vstd::contains(objs, cmw->hero))
cmw->garrisonChanged();
}
for (auto cmw : GH.windows().findWindows<CTradeWindow>())
{
if (vstd::contains(objs, cmw->hero))
cmw->garrisonChanged();
}
GH.totalRedraw();
GH.windows().totalRedraw();
}
void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID buildingID, int what) //what: 1 - built, 2 - demolished
@ -861,7 +854,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br, QueryID queryID)
{
cb->selectionMade(selection, queryID);
};
GH.pushInt(wnd);
GH.windows().pushWindow(wnd);
// #1490 - during AI turn when quick combat is on, we need to display the message and wait for user to close it.
// Otherwise NewTurn causes freeze.
waitWhileDialog();
@ -1015,7 +1008,7 @@ void CPlayerInterface::showInfoDialog(EInfoWindowMode type, const std::string &t
waitWhileDialog(); //Fix for mantis #98
adventureInt->showInfoBoxMessage(components, text, timer);
if (makingTurn && GH.listInt.size() && LOCPLINT == this)
if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
return;
}
@ -1056,12 +1049,12 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
}
std::shared_ptr<CInfoWindow> temp = CInfoWindow::create(text, playerID, components);
if (makingTurn && GH.listInt.size() && LOCPLINT == this)
if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
{
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
showingDialog->set(true);
stopMovement(); // interrupt movement to show dialog
GH.pushInt(temp);
GH.windows().pushWindow(temp);
}
else
{
@ -1121,7 +1114,7 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v
int charperline = 35;
if (pom.size() > 1)
charperline = 50;
GH.pushIntT<CSelWindow>(text, playerID, charperline, intComps, pom, askID);
GH.windows().createAndPushWindow<CSelWindow>(text, playerID, charperline, intComps, pom, askID);
intComps[0]->clickLeft(true, false);
}
}
@ -1170,7 +1163,7 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
std::shared_ptr<CObjectListWindow> wnd = std::make_shared<CObjectListWindow>(tempList, localIcon, localTitle, localDescription, selectCallback);
wnd->onExit = cancelCallback;
GH.pushInt(wnd);
GH.windows().pushWindow(wnd);
}
void CPlayerInterface::tileRevealed(const std::unordered_set<int3> &pos)
@ -1189,7 +1182,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set<int3> &pos)
void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
GH.pushIntT<CHeroWindow>(hero);
GH.windows().createAndPushWindow<CHeroWindow>(hero);
}
void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
@ -1197,27 +1190,22 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
EVENT_HANDLER_CALLED_BY_CLIENT;
if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
{
CFortScreen * fortScreen = dynamic_cast<CFortScreen*>(GH.topInt().get());
CCastleInterface * castleInterface = dynamic_cast<CCastleInterface*>(GH.topInt().get());
if (fortScreen)
for (auto fortScreen : GH.windows().findWindows<CFortScreen>())
fortScreen->creaturesChangedEventHandler();
else if(castleInterface)
for (auto castleInterface : GH.windows().findWindows<CCastleInterface>())
castleInterface->creaturesChangedEventHandler();
for(auto isa : GH.listInt)
{
CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa.get());
if (ki && townObj)
if (townObj)
for (auto ki : GH.windows().findWindows<CKingdomInterface>())
ki->townChanged(townObj);
}
}
else if(town && GH.listInt.size() && (town->ID == Obj::CREATURE_GENERATOR1
else if(town && GH.windows().count() > 0 && (town->ID == Obj::CREATURE_GENERATOR1
|| town->ID == Obj::CREATURE_GENERATOR4 || town->ID == Obj::WAR_MACHINE_FACTORY))
{
CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt().get());
if (crw && crw->dwelling == town)
crw->availableCreaturesChanged();
for (auto crw : GH.windows().findWindows<CRecruitmentWindow>())
if (crw->dwelling == town)
crw->availableCreaturesChanged();
}
}
@ -1283,7 +1271,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer
auto cgw = std::make_shared<CGarrisonWindow>(up, down, removableUnits);
cgw->quit->addCallback(onEnd);
GH.pushInt(cgw);
GH.windows().pushWindow(cgw);
}
/**
@ -1341,7 +1329,7 @@ void CPlayerInterface::showHeroExchange(ObjectInstanceID hero1, ObjectInstanceID
void CPlayerInterface::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CExchangeWindow>(hero1, hero2, query);
GH.windows().createAndPushWindow<CExchangeWindow>(hero1, hero2, query);
}
void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
@ -1402,7 +1390,7 @@ void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const C
{
LOCPLINT->cb->recruitCreatures(dwelling, dst, id, count, -1);
};
GH.pushIntT<CRecruitmentWindow>(dwelling, level, dst, recruitCb);
GH.windows().createAndPushWindow<CRecruitmentWindow>(dwelling, level, dst, recruitCb);
}
void CPlayerInterface::waitWhileDialog(bool unlockPim)
@ -1425,7 +1413,7 @@ void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
auto state = obj->shipyardStatus();
TResources cost;
obj->getBoatCost(cost);
GH.pushIntT<CShipyardWindow>(cost, state, obj->getBoatType(), [=](){ cb->buildBoat(obj); });
GH.windows().createAndPushWindow<CShipyardWindow>(cost, state, obj->getBoatType(), [=](){ cb->buildBoat(obj); });
}
void CPlayerInterface::newObject( const CGObjectInstance * obj )
@ -1449,7 +1437,7 @@ void CPlayerInterface::centerView (int3 pos, int focusTime)
adventureInt->centerOnTile(pos);
if (focusTime)
{
GH.totalRedraw();
GH.windows().totalRedraw();
{
auto unlockPim = vstd::makeUnlockGuard(*pim);
IgnoreEvents ignore(*this);
@ -1518,7 +1506,7 @@ void CPlayerInterface::update()
if ((CSH->howManyPlayerInterfaces() <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get())
{
showingDialog->set(true);
GH.pushInt(dialogs.front());
GH.windows().pushWindow(dialogs.front());
dialogs.pop_front();
}
@ -1527,7 +1515,7 @@ void CPlayerInterface::update()
// Handles mouse and key input
GH.updateTime();
GH.handleEvents();
GH.simpleRedraw();
GH.windows().simpleRedraw();
}
int CPlayerInterface::getLastIndex( std::string namePrefix)
@ -1593,7 +1581,7 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
if(adventureInt)
{
GH.terminate_cond->setn(true);
GH.popInts(GH.listInt.size());
GH.windows().popWindows(GH.windows().count());
adventureInt.reset();
}
}
@ -1639,7 +1627,7 @@ void CPlayerInterface::showPuzzleMap()
double ratio = 0;
int3 grailPos = cb->getGrailPos(&ratio);
GH.pushIntT<CPuzzleWindow>(grailPos, ratio);
GH.windows().createAndPushWindow<CPuzzleWindow>(grailPos, ratio);
}
void CPlayerInterface::viewWorldMap()
@ -1651,8 +1639,8 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI
{
EVENT_HANDLER_CALLED_BY_CLIENT;
if(dynamic_cast<CSpellWindow *>(GH.topInt().get()))
GH.popInts(1);
if(GH.windows().topWindow<CSpellWindow>())
GH.windows().popWindows(1);
if(spellID == SpellID::FLY || spellID == SpellID::WATER_WALK)
localState->erasePath(caster);
@ -1714,50 +1702,50 @@ void CPlayerInterface::showMarketWindow(const IMarket *market, const CGHeroInsta
EVENT_HANDLER_CALLED_BY_CLIENT;
if(market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL)
GH.pushIntT<CAltarWindow>(market, visitor, EMarketMode::ARTIFACT_EXP);
GH.windows().createAndPushWindow<CAltarWindow>(market, visitor, EMarketMode::ARTIFACT_EXP);
else if(market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD)
GH.pushIntT<CAltarWindow>(market, visitor, EMarketMode::CREATURE_EXP);
GH.windows().createAndPushWindow<CAltarWindow>(market, visitor, EMarketMode::CREATURE_EXP);
else if(market->allowsTrade(EMarketMode::CREATURE_UNDEAD))
GH.pushIntT<CTransformerWindow>(market, visitor);
GH.windows().createAndPushWindow<CTransformerWindow>(market, visitor);
else if(!market->availableModes().empty())
GH.pushIntT<CMarketplaceWindow>(market, visitor, market->availableModes().front());
GH.windows().createAndPushWindow<CMarketplaceWindow>(market, visitor, market->availableModes().front());
}
void CPlayerInterface::showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CUniversityWindow>(visitor, market);
GH.windows().createAndPushWindow<CUniversityWindow>(visitor, market);
}
void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CHillFortWindow>(visitor, object);
GH.windows().createAndPushWindow<CHillFortWindow>(visitor, object);
}
void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket * bm)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
if (CMarketplaceWindow *cmw = dynamic_cast<CMarketplaceWindow*>(GH.topInt().get()))
for (auto cmw : GH.windows().findWindows<CMarketplaceWindow>())
cmw->artifactsChanged(false);
}
void CPlayerInterface::showTavernWindow(const CGObjectInstance *townOrTavern)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CTavernWindow>(townOrTavern);
GH.windows().createAndPushWindow<CTavernWindow>(townOrTavern);
}
void CPlayerInterface::showThievesGuildWindow (const CGObjectInstance * obj)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CThievesGuildWindow>(obj);
GH.windows().createAndPushWindow<CThievesGuildWindow>(obj);
}
void CPlayerInterface::showQuestLog()
{
EVENT_HANDLER_CALLED_BY_CLIENT;
GH.pushIntT<CQuestLog>(LOCPLINT->cb->getMyQuests());
GH.windows().createAndPushWindow<CQuestLog>(LOCPLINT->cb->getMyQuests());
}
void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
@ -1808,12 +1796,9 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
adventureInt->onHeroChanged(hero);
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
if (artWin)
artWin->artifactRemoved(al);
}
for(auto artWin : GH.windows().findWindows<CArtifactHolder>())
artWin->artifactRemoved(al);
waitWhileDialog();
}
@ -1833,12 +1818,9 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact
redraw = false;
}
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
if (artWin)
artWin->artifactMoved(src, dst, redraw);
}
for(auto artWin : GH.windows().findWindows<CArtifactHolder>())
artWin->artifactMoved(src, dst, redraw);
waitWhileDialog();
}
@ -1852,12 +1834,9 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
adventureInt->onHeroChanged(hero);
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
if (artWin)
artWin->artifactAssembled(al);
}
for(auto artWin : GH.windows().findWindows<CArtifactHolder>())
artWin->artifactAssembled(al);
}
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
@ -1865,12 +1844,9 @@ void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
adventureInt->onHeroChanged(hero);
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
if (artWin)
artWin->artifactDisassembled(al);
}
for(auto artWin : GH.windows().findWindows<CArtifactHolder>())
artWin->artifactDisassembled(al);
}
void CPlayerInterface::waitForAllDialogs(bool unlockPim)

View File

@ -14,6 +14,7 @@
#include "CGameInfo.h"
#include "CPlayerInterface.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "lobby/CSelectionBase.h"
#include "lobby/CLobbyScreen.h"
@ -325,7 +326,7 @@ void CServerHandler::applyPacksOnLobbyScreen()
packsForLobbyScreen.pop_front();
CBaseForLobbyApply * apply = applier->getApplier(typeList.getTypeID(pack)); //find the applier
apply->applyOnLobbyScreen(static_cast<CLobbyScreen *>(SEL), this, pack);
GH.totalRedraw();
GH.windows().totalRedraw();
delete pack;
}
}
@ -749,8 +750,9 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
while(!settings["session"]["headless"].Bool() && !dynamic_cast<CLobbyScreen *>(GH.topInt().get()))
while(!settings["session"]["headless"].Bool() && !GH.windows().topWindow<CLobbyScreen>())
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
while(!mi || mapInfo->fileURI != CSH->mi->fileURI)
{
setMapInfo(mapInfo);

View File

@ -18,6 +18,7 @@
#include "adventureMap/AdventureMapInterface.h"
#include "battle/BattleInterface.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "mapView/mapHandler.h"
#include "../CCallback.h"
@ -766,12 +767,8 @@ void CClient::removeGUI()
{
// CClient::endGame
GH.curInt = nullptr;
if(GH.topInt())
GH.topInt()->deactivate();
GH.windows().clear();
adventureInt.reset();
GH.listInt.clear();
GH.objsToBlit.clear();
GH.statusbar.reset();
logGlobal->info("Removed GUI.");
LOCPLINT = nullptr;

View File

@ -16,6 +16,7 @@
#include "PlayerLocalState.h"
#include "CServerHandler.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "../lib/NetPacks.h"
#include "ClientNetPackVisitors.h"
#include "../lib/CConfigHandler.h"
@ -100,7 +101,7 @@ void ClientCommandManager::handleGoSoloCommand()
CSH->client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
}
}
GH.totalRedraw();
GH.windows().totalRedraw();
giveTurn(color);
}
session["aiSolo"].Bool() = !session["aiSolo"].Bool();
@ -141,7 +142,7 @@ void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWord
CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
}
GH.totalRedraw();
GH.windows().totalRedraw();
if(color != PlayerColor::NEUTRAL)
giveTurn(color);
}
@ -170,7 +171,7 @@ void ClientCommandManager::handleSetBattleAICommand(std::istringstream& singleWo
void ClientCommandManager::handleRedrawCommand()
{
GH.totalRedraw();
GH.windows().totalRedraw();
}
void ClientCommandManager::handleScreenCommand()
@ -195,14 +196,8 @@ void ClientCommandManager::handleNotDialogCommand()
void ClientCommandManager::handleGuiCommand()
{
for(const auto & child : GH.listInt)
{
const auto childPtr = child.get();
if(const CIntObject * obj = dynamic_cast<const CIntObject*>(childPtr))
printInfoAboutInterfaceObject(obj, 0);
else
printCommandMessage(std::string(typeid(childPtr).name()) + "\n");
}
for(const auto & child : GH.windows().findWindows<CIntObject>())
printInfoAboutInterfaceObject(child.get(), 0);
}
void ClientCommandManager::handleConvertTextCommand()

View File

@ -21,6 +21,7 @@
#include "CServerHandler.h"
#include "CGameInfo.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "widgets/Buttons.h"
#include "widgets/TextControls.h"
@ -38,7 +39,7 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
{
handler.c->connectionID = pack.clientId;
if(!settings["session"]["headless"].Bool())
GH.pushIntT<CLobbyScreen>(static_cast<ESelectionScreen>(handler.screenType));
GH.windows().createAndPushWindow<CLobbyScreen>(static_cast<ESelectionScreen>(handler.screenType));
handler.state = EClientState::LOBBY;
}
}
@ -56,8 +57,8 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClient
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
{
if(GH.listInt.size())
GH.popInts(1);
if(GH.windows().count() > 0)
GH.windows().popWindows(1);
}
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
@ -128,7 +129,7 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack
if(pack.clientId != -1 && pack.clientId != handler.c->connectionID)
return;
GH.pushIntT<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, &handler, pack.initializedGameState));
GH.windows().createAndPushWindow<CLoadingScreen>(std::bind(&CServerHandler::startGameplay, &handler, pack.initializedGameState));
}
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)
@ -145,7 +146,7 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState &
if(!lobby->bonusSel && handler.si->campState && handler.state == EClientState::LOBBY_CAMPAIGN)
{
lobby->bonusSel = std::make_shared<CBonusSelection>();
GH.pushInt(lobby->bonusSel);
GH.windows().pushWindow(lobby->bonusSel);
}
if(lobby->bonusSel)

View File

@ -27,6 +27,7 @@
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../CMT.h"
#include "../PlayerLocalState.h"
#include "../CPlayerInterface.h"
@ -395,7 +396,7 @@ void AdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
if(settings["session"]["autoSkip"].Bool() && !GH.isKeyboardShiftDown())
{
if(CInfoWindow *iw = dynamic_cast<CInfoWindow *>(GH.topInt().get()))
if(auto iw = GH.windows().topWindow<CInfoWindow>())
iw->close();
hotkeyEndingTurn();
@ -527,7 +528,7 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
if(!LOCPLINT->cb->isVisible(mapPos))
{
CCS->curh->set(Cursor::Map::POINTER);
GH.statusbar->clear();
GH.statusbar()->clear();
return;
}
auto objRelations = PlayerRelations::ALLIES;
@ -537,12 +538,12 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner);
std::string text = LOCPLINT->localState->getCurrentHero() ? objAtTile->getHoverText(LOCPLINT->localState->getCurrentHero()) : objAtTile->getHoverText(LOCPLINT->playerID);
boost::replace_all(text,"\n"," ");
GH.statusbar->write(text);
GH.statusbar()->write(text);
}
else
{
std::string hlp = CGI->mh->getTerrainDescr(mapPos, false);
GH.statusbar->write(hlp);
GH.statusbar()->write(hlp);
}
if(spellBeingCasted)
@ -679,7 +680,7 @@ void AdventureMapInterface::showMoveDetailsInStatusbar(const CGHeroInstance & he
boost::replace_first(result, "%POINTS", std::to_string(movementPointsLastTurnCost));
boost::replace_first(result, "%REMAINING", std::to_string(remainingPointsAfterMove));
GH.statusbar->write(result);
GH.statusbar()->write(result);
}
void AdventureMapInterface::onTileRightClicked(const int3 &mapPos)

View File

@ -16,6 +16,7 @@
#include "../PlayerLocalState.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../lobby/CSavingScreen.h"
#include "../mapView/mapHandler.h"
#include "../windows/CKingdomInterface.h"
@ -96,7 +97,7 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
void AdventureMapShortcuts::showOverview()
{
GH.pushIntT<CKingdomInterface>();
GH.windows().createAndPushWindow<CKingdomInterface>();
}
void AdventureMapShortcuts::worldViewBack()
@ -186,17 +187,17 @@ void AdventureMapShortcuts::showSpellbook()
owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
GH.pushIntT<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
GH.windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
}
void AdventureMapShortcuts::adventureOptions()
{
GH.pushIntT<AdventureOptions>();
GH.windows().createAndPushWindow<AdventureOptions>();
}
void AdventureMapShortcuts::systemOptions()
{
GH.pushIntT<SettingsMainWindow>();
GH.windows().createAndPushWindow<SettingsMainWindow>();
}
void AdventureMapShortcuts::nextHero()
@ -266,7 +267,7 @@ void AdventureMapShortcuts::showScenarioInfo()
void AdventureMapShortcuts::saveGame()
{
GH.pushIntT<CSavingScreen>();
GH.windows().createAndPushWindow<CSavingScreen>();
}
void AdventureMapShortcuts::loadGame()
@ -326,7 +327,7 @@ void AdventureMapShortcuts::showMarketplace()
}
if(townWithMarket) //if any town has marketplace, open window
GH.pushIntT<CMarketplaceWindow>(townWithMarket);
GH.windows().createAndPushWindow<CMarketplaceWindow>(townWithMarket);
else //if not - complain
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
}

View File

@ -17,6 +17,7 @@
#include "../lobby/CCampaignInfoScreen.h"
#include "../lobby/CScenarioInfoScreen.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../gui/Shortcut.h"
#include "../widgets/Buttons.h"
@ -50,11 +51,11 @@ void AdventureOptions::showScenarioInfo()
{
if(LOCPLINT->cb->getStartInfo()->campState)
{
GH.pushIntT<CCampaignInfoScreen>();
GH.windows().createAndPushWindow<CCampaignInfoScreen>();
}
else
{
GH.pushIntT<CScenarioInfoScreen>();
GH.windows().createAndPushWindow<CScenarioInfoScreen>();
}
}

View File

@ -17,6 +17,7 @@
#include "../PlayerLocalState.h"
#include "../ClientCommandManager.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../gui/Shortcut.h"
#include "../render/Colors.h"
#include "../adventureMap/AdventureMapInterface.h"
@ -77,7 +78,7 @@ void CInGameConsole::tick(uint32_t msPassed)
}
if(sizeBefore != texts.size())
GH.totalRedraw(); // FIXME: ingame console has no parent widget set
GH.windows().totalRedraw(); // FIXME: ingame console has no parent widget set
}
void CInGameConsole::print(const std::string & txt)
@ -101,7 +102,7 @@ void CInGameConsole::print(const std::string & txt)
texts.erase(texts.begin());
}
GH.totalRedraw(); // FIXME: ingame console has no parent widget set
GH.windows().totalRedraw(); // FIXME: ingame console has no parent widget set
}
void CInGameConsole::keyPressed (EShortcut key)
@ -216,16 +217,15 @@ void CInGameConsole::startEnteringText()
if (captureAllKeys)
return;
assert(GH.statusbar);
assert(currentStatusBar.expired());//effectively, nullptr check
currentStatusBar = GH.statusbar;
currentStatusBar = GH.statusbar();
captureAllKeys = true;
enteredText = "_";
GH.statusbar->setEnteringMode(true);
GH.statusbar->setEnteredText(enteredText);
GH.statusbar()->setEnteringMode(true);
GH.statusbar()->setEnteredText(enteredText);
}
void CInGameConsole::endEnteringText(bool processEnteredText)

View File

@ -24,6 +24,7 @@
#include "../CPlayerInterface.h"
#include "../PlayerLocalState.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../../CCallback.h"
#include "../../lib/CGeneralTextHandler.h"
@ -261,7 +262,7 @@ void CInfoBar::tick(uint32_t msPassed)
{
timerCounter = 0;
removeUsedEvents(TIME);
if(GH.topInt() == adventureInt)
if(GH.windows().isTopWindow(adventureInt))
popComponents(true);
}
else
@ -292,9 +293,9 @@ void CInfoBar::clickRight(tribool down, bool previousState)
void CInfoBar::hover(bool on)
{
if(on)
GH.statusbar->write(CGI->generaltexth->zelp[292].first);
GH.statusbar()->write(CGI->generaltexth->zelp[292].first);
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
CInfoBar::CInfoBar(const Rect & position)

View File

@ -68,9 +68,9 @@ void CList::CListItem::clickLeft(tribool down, bool previousState)
void CList::CListItem::hover(bool on)
{
if (on)
GH.statusbar->write(getHoverText());
GH.statusbar()->write(getHoverText());
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
void CList::CListItem::onSelect(bool on)

View File

@ -17,6 +17,7 @@
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../render/Colors.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../render/Canvas.h"
@ -131,7 +132,7 @@ void CMinimap::moveAdvMapSelection()
adventureInt->centerOnTile(newLocation);
if (!(adventureInt->active & GENERAL))
GH.totalRedraw(); //redraw this as well as inactive adventure map
GH.windows().totalRedraw(); //redraw this as well as inactive adventure map
else
redraw();//redraw only this
}
@ -151,9 +152,9 @@ void CMinimap::clickRight(tribool down, bool previousState)
void CMinimap::hover(bool on)
{
if(on)
GH.statusbar->write(CGI->generaltexth->zelp[291].first);
GH.statusbar()->write(CGI->generaltexth->zelp[291].first);
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
void CMinimap::mouseMoved(const Point & cursorPosition)

View File

@ -22,6 +22,7 @@
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/CIntObject.h"
#include "../gui/WindowHandler.h"
#include "../windows/CCreatureWindow.h"
#include "../../CCallback.h"
@ -668,7 +669,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
case PossiblePlayerBattleAction::CREATURE_INFO:
{
GH.pushIntT<CStackWindow>(targetStack, false);
GH.windows().createAndPushWindow<CStackWindow>(targetStack, false);
return;
}
@ -772,7 +773,7 @@ void BattleActionsController::onHexHovered(BattleHex hoveredHex)
if (owner.openingPlaying())
{
currentConsoleMsg = VLC->generaltexth->translate("vcmi.battleWindow.pressKeyToSkipIntro");
GH.statusbar->write(currentConsoleMsg);
GH.statusbar()->write(currentConsoleMsg);
return;
}
@ -782,7 +783,7 @@ void BattleActionsController::onHexHovered(BattleHex hoveredHex)
if (hoveredHex == BattleHex::INVALID)
{
if (!currentConsoleMsg.empty())
GH.statusbar->clearIfMatching(currentConsoleMsg);
GH.statusbar()->clearIfMatching(currentConsoleMsg);
currentConsoleMsg.clear();
CCS->curh->set(Cursor::Combat::BLOCKED);
@ -805,10 +806,10 @@ void BattleActionsController::onHexHovered(BattleHex hoveredHex)
}
if (!currentConsoleMsg.empty())
GH.statusbar->clearIfMatching(currentConsoleMsg);
GH.statusbar()->clearIfMatching(currentConsoleMsg);
if (!newConsoleMsg.empty())
GH.statusbar->write(newConsoleMsg);
GH.statusbar()->write(newConsoleMsg);
currentConsoleMsg = newConsoleMsg;
}
@ -818,7 +819,7 @@ void BattleActionsController::onHoverEnded()
CCS->curh->set(Cursor::Combat::POINTER);
if (!currentConsoleMsg.empty())
GH.statusbar->clearIfMatching(currentConsoleMsg);
GH.statusbar()->clearIfMatching(currentConsoleMsg);
currentConsoleMsg.clear();
}
@ -849,7 +850,7 @@ void BattleActionsController::onHexLeftClicked(BattleHex clickedHex)
{
actionRealize(action, clickedHex);
GH.statusbar->clear();
GH.statusbar()->clear();
}
else
{
@ -973,7 +974,7 @@ void BattleActionsController::onHexRightClicked(BattleHex clickedHex)
auto selectedStack = owner.curInt->cb->battleGetStackByPos(clickedHex, true);
if (selectedStack != nullptr)
GH.pushIntT<CStackWindow>(selectedStack, true);
GH.windows().createAndPushWindow<CStackWindow>(selectedStack, true);
if (clickedHex == BattleHex::HERO_ATTACKER && owner.attackingHero)
owner.attackingHero->heroRightClicked();

View File

@ -28,6 +28,7 @@
#include "../CPlayerInterface.h"
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../render/Canvas.h"
#include "../adventureMap/AdventureMapInterface.h"
@ -95,7 +96,7 @@ BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *
adventureInt->onAudioPaused();
ongoingAnimationsState.set(true);
GH.pushInt(windowObject);
GH.windows().pushWindow(windowObject);
windowObject->blockUI(true);
windowObject->updateQueue();
@ -167,7 +168,7 @@ BattleInterface::~BattleInterface()
void BattleInterface::redrawBattlefield()
{
fieldController->redrawBackgroundWithHexes();
GH.totalRedraw();
GH.windows().totalRedraw();
}
void BattleInterface::stackReset(const CStack * stack)
@ -328,7 +329,7 @@ void BattleInterface::battleFinished(const BattleResult& br, QueryID queryID)
{
curInt->cb->selectionMade(selection, queryID);
};
GH.pushInt(wnd);
GH.windows().pushWindow(wnd);
curInt->waitWhileDialog(); // Avoid freeze when AI end turn after battle. Check bug #1897
CPlayerInterface::battleInt = nullptr;

View File

@ -25,6 +25,7 @@
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../render/Canvas.h"
#include "../render/IImage.h"
#include "../widgets/Buttons.h"
@ -289,7 +290,7 @@ void BattleHero::heroLeftClicked()
if(owner.getCurrentPlayerInterface()->cb->battleCanCastSpell(hero, spells::Mode::HERO) == ESpellCastProblem::OK) //check conditions
{
CCS->curh->set(Cursor::Map::POINTER);
GH.pushIntT<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
GH.windows().createAndPushWindow<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
}
}
@ -304,7 +305,7 @@ void BattleHero::heroRightClicked()
{
auto h = defender ? owner.defendingHeroInstance : owner.attackingHeroInstance;
targetHero.initFromHero(h, InfoAboutHero::EInfoLevel::INBATTLE);
GH.pushIntT<HeroInfoWindow>(targetHero, &windowPosition);
GH.windows().createAndPushWindow<HeroInfoWindow>(targetHero, &windowPosition);
}
}
@ -591,8 +592,8 @@ void BattleResultWindow::buttonPressed(int button)
close();
if(dynamic_cast<BattleWindow*>(GH.topInt().get()))
GH.popInts(1); //pop battle interface if present
if(GH.windows().topWindow<BattleWindow>())
GH.windows().popWindows(1); //pop battle interface if present
//Result window and battle interface are gone. We requested all dialogs to be closed before opening the battle,
//so we can be sure that there is no dialogs left on GUI stack.

View File

@ -22,6 +22,7 @@
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../windows/CSpellWindow.h"
#include "../widgets/Buttons.h"
#include "../widgets/Images.h"
@ -152,7 +153,7 @@ void BattleWindow::hideQueue()
pos.h -= queue->pos.h;
pos = center();
}
GH.totalRedraw();
GH.windows().totalRedraw();
}
void BattleWindow::showQueue()
@ -165,7 +166,7 @@ void BattleWindow::showQueue()
createQueue();
updateQueue();
GH.totalRedraw();
GH.windows().totalRedraw();
}
void BattleWindow::updateQueue()
@ -175,13 +176,14 @@ void BattleWindow::updateQueue()
void BattleWindow::activate()
{
GH.statusbar = console;
GH.setStatusbar(console);
CIntObject::activate();
LOCPLINT->cingconsole->activate();
}
void BattleWindow::deactivate()
{
GH.setStatusbar(nullptr);
CIntObject::deactivate();
LOCPLINT->cingconsole->deactivate();
}
@ -256,7 +258,7 @@ void BattleWindow::bOptionsf()
CCS->curh->set(Cursor::Map::POINTER);
GH.pushIntT<SettingsMainWindow>(&owner);
GH.windows().createAndPushWindow<SettingsMainWindow>(&owner);
}
void BattleWindow::bSurrenderf()
@ -424,7 +426,7 @@ void BattleWindow::bSpellf()
if(spellCastProblem == ESpellCastProblem::OK)
{
GH.pushIntT<CSpellWindow>(myHero, owner.curInt.get());
GH.windows().createAndPushWindow<CSpellWindow>(myHero, owner.curInt.get());
}
else if (spellCastProblem == ESpellCastProblem::MAGIC_IS_BLOCKED)
{
@ -569,7 +571,7 @@ void BattleWindow::show(SDL_Surface *to)
void BattleWindow::close()
{
if(GH.topInt().get() != this)
if(!GH.windows().isTopWindow(this))
logGlobal->error("Only top interface must be closed");
GH.popInts(1);
GH.windows().popWindows(1);
}

View File

@ -15,6 +15,7 @@
#include "CursorHandler.h"
#include "ShortcutHandler.h"
#include "FramerateManager.h"
#include "WindowHandler.h"
#include "../CGameInfo.h"
#include "../render/Colors.h"
@ -99,6 +100,7 @@ void CGuiHandler::processLists(const ui16 activityFlag, std::function<void (std:
void CGuiHandler::init()
{
windowHandlerInstance = std::make_unique<WindowHandler>();
screenHandlerInstance = std::make_unique<ScreenHandler>();
shortcutsHandlerInstance = std::make_unique<ShortcutHandler>();
framerateManagerInstance = std::make_unique<FramerateManager>(settings["video"]["targetfps"].Integer());
@ -125,73 +127,6 @@ void CGuiHandler::handleElementDeActivate(CIntObject * elem, ui16 activityFlag)
elem->active_m &= ~activityFlag;
}
void CGuiHandler::popInt(std::shared_ptr<IShowActivatable> top)
{
assert(listInt.front() == top);
top->deactivate();
disposed.push_back(top);
listInt.pop_front();
objsToBlit -= top;
if(!listInt.empty())
listInt.front()->activate();
totalRedraw();
}
void CGuiHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
{
assert(newInt);
assert(!vstd::contains(listInt, newInt)); // do not add same object twice
//a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
screenBuf = screen2;
if(!listInt.empty())
listInt.front()->deactivate();
listInt.push_front(newInt);
CCS->curh->set(Cursor::Map::POINTER);
newInt->activate();
objsToBlit.push_back(newInt);
totalRedraw();
}
void CGuiHandler::popInts(int howMany)
{
if(!howMany) return; //senseless but who knows...
assert(listInt.size() >= howMany);
listInt.front()->deactivate();
for(int i=0; i < howMany; i++)
{
objsToBlit -= listInt.front();
disposed.push_back(listInt.front());
listInt.pop_front();
}
if(!listInt.empty())
{
listInt.front()->activate();
totalRedraw();
}
fakeMouseMove();
}
std::shared_ptr<IShowActivatable> CGuiHandler::topInt()
{
if(listInt.empty())
return std::shared_ptr<IShowActivatable>();
else
return listInt.front();
}
void CGuiHandler::totalRedraw()
{
CSDL_Ext::fillSurface( screen2, Colors::BLACK);
for(auto & elem : objsToBlit)
elem->showAll(screen2);
CSDL_Ext::blitAt(screen2,0,0,screen);
}
void CGuiHandler::updateTime()
{
int ms = framerateManager().getElapsedMilliseconds();
@ -397,7 +332,7 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
//not working yet since CClient::run remain locked after BattleInterface removal
// if(LOCPLINT->battleInt)
// {
// GH.popInts(1);
// GH.windows().popInts(1);
// vstd::clear_pointer(LOCPLINT->battleInt);
// }
break;
@ -635,15 +570,6 @@ void CGuiHandler::handleMouseMotion(const SDL_Event & current)
handleMoveInterested(current.motion);
}
void CGuiHandler::simpleRedraw()
{
//update only top interface and draw background
if(objsToBlit.size() > 1)
CSDL_Ext::blitAt(screen2,0,0,screen); //blit background
if(!objsToBlit.empty())
objsToBlit.back()->show(screen); //blit active interface/window
}
void CGuiHandler::handleMoveInterested(const SDL_MouseMotionEvent & motion)
{
//sending active, MotionInterested objects mouseMoved() call
@ -690,7 +616,7 @@ void CGuiHandler::renderFrame()
SDL_RenderPresent(mainRenderer);
disposed.clear();
windows().onFrameRendered();
}
framerateManager().framerateDelay(); // holds a constant FPS
@ -705,9 +631,9 @@ CGuiHandler::CGuiHandler()
, mouseButtonsMask(0)
, continueEventHandling(true)
, curInt(nullptr)
, statusbar(nullptr)
, fakeStatusBar(std::make_shared<EmptyStatusBar>())
, terminate_cond (new CondSh<bool>(false))
{
terminate_cond = new CondSh<bool>(false);
}
CGuiHandler::~CGuiHandler()
@ -816,15 +742,29 @@ IScreenHandler & CGuiHandler::screenHandler()
return *screenHandlerInstance;
}
WindowHandler & CGuiHandler::windows()
{
assert(windowHandlerInstance);
return *windowHandlerInstance;
}
std::shared_ptr<IStatusBar> CGuiHandler::statusbar()
{
auto locked = currentStatusBar.lock();
if (!locked)
return fakeStatusBar;
return locked;
}
void CGuiHandler::setStatusbar(std::shared_ptr<IStatusBar> newStatusBar)
{
currentStatusBar = newStatusBar;
}
void CGuiHandler::onScreenResize()
{
for (auto const & entry : listInt)
{
auto intObject = std::dynamic_pointer_cast<CIntObject>(entry);
if (intObject)
intObject->onScreenResize();
}
totalRedraw();
screenHandler().onScreenResize();
windows().onScreenResize();
}

View File

@ -30,6 +30,7 @@ class IUpdateable;
class IShowActivatable;
class IShowable;
class IScreenHandler;
class WindowHandler;
// TODO: event handling need refactoring
enum class EUserEvent
@ -49,16 +50,19 @@ class CGuiHandler
{
public:
std::list<std::shared_ptr<IShowActivatable>> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
std::shared_ptr<IStatusBar> statusbar;
private:
/// Fake no-op version status bar, for use in windows that have no status bar
std::shared_ptr<IStatusBar> fakeStatusBar;
/// Status bar of current window, if any. Uses weak_ptr to allow potential hanging reference after owned window has been deleted
std::weak_ptr<IStatusBar> currentStatusBar;
Point cursorPosition;
uint32_t mouseButtonsMask;
std::vector<std::shared_ptr<IShowActivatable>> disposed;
std::unique_ptr<ShortcutHandler> shortcutsHandlerInstance;
std::unique_ptr<WindowHandler> windowHandlerInstance;
std::atomic<bool> continueEventHandling;
using CIntObjectList = std::list<CIntObject *>;
@ -91,8 +95,6 @@ public:
void handleElementActivate(CIntObject * elem, ui16 activityFlag);
void handleElementDeActivate(CIntObject * elem, ui16 activityFlag);
public:
//objs to blit
std::vector<std::shared_ptr<IShowActivatable>> objsToBlit;
/// returns current position of mouse cursor, relative to vcmi window
const Point & getCursorPosition() const;
@ -123,6 +125,14 @@ public:
IScreenHandler & screenHandler();
WindowHandler & windows();
/// Returns currently active status bar. Guaranteed to be non-null
std::shared_ptr<IStatusBar> statusbar();
/// Set currently active status bar
void setStatusbar(std::shared_ptr<IStatusBar>);
IUpdateable *curInt;
Point lastClick;
@ -141,26 +151,9 @@ public:
void init();
void renderFrame();
void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering
/// called whenever user selects different resolution, requiring to center/resize all windows
void onScreenResize();
void pushInt(std::shared_ptr<IShowActivatable> newInt); //deactivate old top interface, activates this one and pushes to the top
template <typename T, typename ... Args>
void pushIntT(Args && ... args)
{
auto newInt = std::make_shared<T>(std::forward<Args>(args)...);
pushInt(newInt);
}
void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
void popInt(std::shared_ptr<IShowActivatable> top); //removes given interface from the top and activates next
std::shared_ptr<IShowActivatable> topInt(); //returns top interface
void updateTime(); //handles timeInterested
void handleEvents(); //takes events from queue and calls interested objects
void fakeMouseMove();

View File

@ -11,6 +11,7 @@
#include "CIntObject.h"
#include "CGuiHandler.h"
#include "WindowHandler.h"
#include "Shortcut.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../windows/CMessage.h"
@ -356,9 +357,9 @@ WindowBase::WindowBase(int used_, Point pos_)
void WindowBase::close()
{
if(GH.topInt().get() != this)
if(!GH.windows().isTopWindow(this))
logGlobal->error("Only top interface must be closed");
GH.popInts(1);
GH.windows().popWindows(1);
}
IStatusBar::~IStatusBar()

View File

@ -231,3 +231,12 @@ public:
virtual void setEnteredText(const std::string & text) = 0;
};
class EmptyStatusBar : public IStatusBar
{
virtual void write(const std::string & text){};
virtual void clear(){};
virtual void clearIfMatching(const std::string & testedText){};
virtual void setEnteringMode(bool on){};
virtual void setEnteredText(const std::string & text){};
};

View File

@ -0,0 +1,138 @@
/*
* WindowHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "WindowHandler.h"
#include "CGuiHandler.h"
#include "CIntObject.h"
#include "CursorHandler.h"
#include "../CMT.h"
#include "../CGameInfo.h"
#include "../render/Colors.h"
#include "../renderSDL/SDL_Extensions.h"
void WindowHandler::popWindow(std::shared_ptr<IShowActivatable> top)
{
assert(windowsStack.back() == top);
top->deactivate();
disposed.push_back(top);
windowsStack.pop_back();
if(!windowsStack.empty())
windowsStack.back()->activate();
totalRedraw();
}
void WindowHandler::pushWindow(std::shared_ptr<IShowActivatable> newInt)
{
assert(newInt);
assert(!vstd::contains(windowsStack, newInt)); // do not add same object twice
//a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
screenBuf = screen2;
if(!windowsStack.empty())
windowsStack.back()->deactivate();
windowsStack.push_back(newInt);
CCS->curh->set(Cursor::Map::POINTER);
newInt->activate();
totalRedraw();
}
void WindowHandler::popWindows(int howMany)
{
if(!howMany)
return; //senseless but who knows...
assert(windowsStack.size() >= howMany);
windowsStack.back()->deactivate();
for(int i = 0; i < howMany; i++)
{
disposed.push_back(windowsStack.back());
windowsStack.pop_back();
}
if(!windowsStack.empty())
{
windowsStack.back()->activate();
totalRedraw();
}
GH.fakeMouseMove();
}
std::shared_ptr<IShowActivatable> WindowHandler::topWindowImpl() const
{
if(windowsStack.empty())
return nullptr;
return windowsStack.back();
}
bool WindowHandler::isTopWindow(std::shared_ptr<IShowActivatable> window) const
{
assert(window != nullptr);
return !windowsStack.empty() && windowsStack.back() == window;
}
bool WindowHandler::isTopWindow(IShowActivatable * window) const
{
assert(window != nullptr);
return !windowsStack.empty() && windowsStack.back().get() == window;
}
void WindowHandler::totalRedraw()
{
CSDL_Ext::fillSurface(screen2, Colors::BLACK);
for(auto & elem : windowsStack)
elem->showAll(screen2);
CSDL_Ext::blitAt(screen2, 0, 0, screen);
}
void WindowHandler::simpleRedraw()
{
//update only top interface and draw background
if(windowsStack.size() > 1)
CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
if(!windowsStack.empty())
windowsStack.back()->show(screen); //blit active interface/window
}
void WindowHandler::onScreenResize()
{
for(const auto & entry : windowsStack)
{
auto intObject = std::dynamic_pointer_cast<CIntObject>(entry);
if(intObject)
intObject->onScreenResize();
}
totalRedraw();
}
void WindowHandler::onFrameRendered()
{
disposed.clear();
}
size_t WindowHandler::count() const
{
return windowsStack.size();
}
void WindowHandler::clear()
{
if(!windowsStack.empty())
windowsStack.back()->deactivate();
windowsStack.clear();
disposed.clear();
}

View File

@ -0,0 +1,97 @@
/*
* WindowHandler.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
class IShowActivatable;
class WindowHandler
{
/// list of windows. front = bottom-most (background), back = top-most (foreground)
/// (includes adventure map, window windows, all kind of active dialogs, and so on)
std::vector<std::shared_ptr<IShowActivatable>> windowsStack;
/// Temporary list of recently popped windows
std::vector<std::shared_ptr<IShowActivatable>> disposed;
/// returns top windows
std::shared_ptr<IShowActivatable> topWindowImpl() const;
public:
/// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
void totalRedraw();
/// update only top windows and draw background from buffer, sets a flag, method gets called at the end of the rendering
void simpleRedraw();
/// called whenever user selects different resolution, requiring to center/resize all windows
void onScreenResize();
/// deactivate old top windows, activates this one and pushes to the top
void pushWindow(std::shared_ptr<IShowActivatable> newInt);
/// creates window of class T and pushes it to the top
template <typename T, typename ... Args>
void createAndPushWindow(Args && ... args);
/// pops one or more windows - deactivates top, deletes and removes given number of windows, activates new front
void popWindows(int howMany);
/// removes given windows from the top and activates next
void popWindow(std::shared_ptr<IShowActivatable> top);
/// returns true if selected interface is on top
bool isTopWindow(std::shared_ptr<IShowActivatable> window) const;
bool isTopWindow(IShowActivatable * window) const;
/// returns top window if it matches requested class
template <typename T>
std::shared_ptr<T> topWindow() const;
/// should be called after frame has been rendered to screen
void onFrameRendered();
/// returns current number of windows in the stack
size_t count() const;
/// erases all currently existing windows from the stack
void clear();
/// returns all existing windows of selected type
template <typename T>
std::vector<std::shared_ptr<T>> findWindows() const;
};
template <typename T, typename ... Args>
void WindowHandler::createAndPushWindow(Args && ... args)
{
auto newWindow = std::make_shared<T>(std::forward<Args>(args)...);
pushWindow(newWindow);
}
template <typename T>
std::vector<std::shared_ptr<T>> WindowHandler::findWindows() const
{
std::vector<std::shared_ptr<T>> result;
for(const auto & window : windowsStack)
{
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(window);
if (casted)
result.push_back(casted);
}
return result;
}
template <typename T>
std::shared_ptr<T> WindowHandler::topWindow() const
{
return std::dynamic_pointer_cast<T>(topWindowImpl());
}

View File

@ -34,6 +34,7 @@
#include "../render/CAnimation.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/CGeneralTextHandler.h"
@ -367,7 +368,7 @@ void CBonusSelection::goBack()
{
if(CSH->state != EClientState::GAMEPLAY)
{
GH.popInts(2);
GH.windows().popWindows(2);
}
else
{
@ -397,7 +398,7 @@ void CBonusSelection::startMap()
const CCampaignScenario & scenario = getCampaign()->camp->scenarios[CSH->campaignMap];
if(scenario.prolog.hasPrologEpilog)
{
GH.pushIntT<CPrologEpilogVideo>(scenario.prolog, exitCb);
GH.windows().createAndPushWindow<CPrologEpilogVideo>(scenario.prolog, exitCb);
}
else
{

View File

@ -26,6 +26,7 @@
#include "../CServerHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../mainmenu/CMainMenu.h"
#include "../widgets/CComponent.h"
#include "../widgets/Buttons.h"
@ -105,7 +106,7 @@ void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
{
curTab.reset();
}
GH.totalRedraw();
GH.windows().totalRedraw();
}
InfoCard::InfoCard()
@ -299,7 +300,7 @@ void InfoCard::setChat(bool activateChat)
}
showChat = activateChat;
GH.totalRedraw();
GH.windows().totalRedraw();
}
CChatBox::CChatBox(const Rect & rect)
@ -378,7 +379,7 @@ void CFlagBox::recreate()
void CFlagBox::clickRight(tribool down, bool previousState)
{
if(down && SEL->getMapInfo())
GH.pushIntT<CFlagBoxTooltipBox>(iconsTeamFlags);
GH.windows().createAndPushWindow<CFlagBoxTooltipBox>(iconsTeamFlags);
}
CFlagBox::CFlagBoxTooltipBox::CFlagBoxTooltipBox(std::shared_ptr<CAnimation> icons)

View File

@ -15,6 +15,7 @@
#include "../CGameInfo.h"
#include "../CServerHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
#include "../widgets/Buttons.h"
#include "../widgets/MiscWidgets.h"
@ -435,7 +436,7 @@ void OptionsTab::SelectedBox::clickRight(tribool down, bool previousState)
if(settings.hero == -2 && !SEL->getPlayerInfo(settings.color.getNum()).hasCustomMainHero() && CPlayerSettingsHelper::type == HERO)
return;
GH.pushIntT<CPlayerOptionTooltipBox>(*this);
GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(*this);
}
}

View File

@ -15,6 +15,7 @@
#include "../CGameInfo.h"
#include "../CServerHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
#include "../widgets/Buttons.h"
#include "../widgets/MiscWidgets.h"
@ -102,12 +103,12 @@ RandomMapTab::RandomMapTab():
//new callbacks available only from mod
addCallback("templateSelection", [&](int)
{
GH.pushIntT<TemplatesDropBox>(*this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()});
GH.windows().createAndPushWindow<TemplatesDropBox>(*this, int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()});
});
addCallback("teamAlignments", [&](int)
{
GH.pushIntT<TeamAlignmentsWidget>(*this);
GH.windows().createAndPushWindow<TeamAlignmentsWidget>(*this);
});
for(auto road : VLC->roadTypeHandler->objects)
@ -482,8 +483,8 @@ void TemplatesDropBox::clickLeft(tribool down, bool previousState)
// pop the interface only if the mouse is not clicking on the slider
if (!w || !w->mouseState(MouseButton::LEFT))
{
assert(GH.topInt().get() == this);
GH.popInt(GH.topInt());
assert(GH.windows().isTopWindow(this));
GH.windows().popWindows(1);
}
}
}
@ -511,8 +512,8 @@ void TemplatesDropBox::updateListItems()
void TemplatesDropBox::setTemplate(const CRmgTemplate * tmpl)
{
randomMapTab.setTemplate(tmpl);
assert(GH.topInt().get() == this);
GH.popInt(GH.topInt());
assert(GH.windows().isTopWindow(this));
GH.windows().popWindows(1);
}
TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
@ -547,14 +548,14 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
randomMapTab.obtainMapGenOptions().setPlayerTeam(PlayerColor(plId), TeamID(players[plId]->getSelected()));
}
randomMapTab.updateMapInfoByHost();
assert(GH.topInt().get() == this);
GH.popInt(GH.topInt());
assert(GH.windows().isTopWindow(this));
GH.windows().popWindows(1);
});
addCallback("cancel", [&](int)
{
assert(GH.topInt().get() == this);
GH.popInt(GH.topInt());
assert(GH.windows().isTopWindow(this));
GH.windows().popWindows(1);
});
build(config);

View File

@ -21,6 +21,7 @@
#include "../gui/CGuiHandler.h"
#include "../gui/ShortcutHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
#include "../widgets/Buttons.h"
#include "../widgets/MiscWidgets.h"
@ -177,7 +178,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
case 0:
return std::bind(CMainMenu::openLobby, ESelectionScreen::newGame, true, nullptr, ELoadMode::NONE);
case 1:
return []() { GH.pushIntT<CMultiMode>(ESelectionScreen::newGame); };
return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::newGame); };
case 2:
return std::bind(CMainMenu::openLobby, ESelectionScreen::campaignList, true, nullptr, ELoadMode::NONE);
case 3:
@ -192,7 +193,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
case 0:
return std::bind(CMainMenu::openLobby, ESelectionScreen::loadGame, true, nullptr, ELoadMode::SINGLE);
case 1:
return []() { GH.pushIntT<CMultiMode>(ESelectionScreen::loadGame); };
return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::loadGame); };
case 2:
return std::bind(CMainMenu::openLobby, ESelectionScreen::loadGame, true, nullptr, ELoadMode::CAMPAIGN);
case 3:
@ -324,10 +325,10 @@ void CMainMenu::update()
if(CMM != this->shared_from_this()) //don't update if you are not a main interface
return;
if(GH.listInt.empty())
if(GH.windows().count() == 0)
{
GH.pushInt(CMM);
GH.pushInt(menu);
GH.windows().pushWindow(CMM);
GH.windows().pushWindow(menu);
menu->switchToTab(menu->getActiveTab());
}
@ -336,9 +337,9 @@ void CMainMenu::update()
GH.handleEvents();
// check for null othervice crash on finishing a campaign
// /FIXME: find out why GH.listInt is empty to begin with
if(GH.topInt())
GH.topInt()->show(screen);
// /FIXME: find out why GH.windows().listInt is empty to begin with
if(GH.windows().topWindow<CIntObject>())
GH.windows().topWindow<CIntObject>()->show(screen);
}
void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode)
@ -347,7 +348,7 @@ void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vec
CSH->screenType = screenType;
CSH->loadMode = loadMode;
GH.pushIntT<CSimpleJoinScreen>(host);
GH.windows().createAndPushWindow<CSimpleJoinScreen>(host);
}
void CMainMenu::openCampaignLobby(const std::string & campaignFileName)
@ -361,14 +362,14 @@ void CMainMenu::openCampaignLobby(std::shared_ptr<CCampaignState> campaign)
CSH->resetStateForLobby(StartInfo::CAMPAIGN);
CSH->screenType = ESelectionScreen::campaignList;
CSH->campaignStateToSend = campaign;
GH.pushIntT<CSimpleJoinScreen>();
GH.windows().createAndPushWindow<CSimpleJoinScreen>();
}
void CMainMenu::openCampaignScreen(std::string name)
{
if(vstd::contains(CMainMenuConfig::get().getCampaigns().Struct(), name))
{
GH.pushIntT<CCampaignScreen>(CMainMenuConfig::get().getCampaigns()[name]);
GH.windows().createAndPushWindow<CCampaignScreen>(CMainMenuConfig::get().getCampaigns()[name]);
return;
}
logGlobal->error("Unknown campaign set: %s", name);
@ -413,14 +414,14 @@ void CMultiMode::hostTCP()
{
auto savedScreenType = screenType;
close();
GH.pushIntT<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, true, ELoadMode::MULTI);
GH.windows().createAndPushWindow<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, true, ELoadMode::MULTI);
}
void CMultiMode::joinTCP()
{
auto savedScreenType = screenType;
close();
GH.pushIntT<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, false, ELoadMode::MULTI);
GH.windows().createAndPushWindow<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, false, ELoadMode::MULTI);
}
void CMultiMode::onNameChange(std::string newText)
@ -522,7 +523,7 @@ void CSimpleJoinScreen::leaveScreen()
textTitle->setText("Closing...");
CSH->state = EClientState::CONNECTION_CANCELLED;
}
else if(GH.listInt.size() && GH.listInt.front().get() == this)
else if(GH.windows().isTopWindow(this))
{
close();
}
@ -552,7 +553,7 @@ void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
else
CSH->justConnectToServer(addr, port);
if(GH.listInt.size() && GH.listInt.front().get() == this)
if(GH.windows().isTopWindow(this))
{
close();
}

View File

@ -154,7 +154,7 @@ void MapViewActions::hover(bool on)
{
if(!on)
{
GH.statusbar->clear();
GH.statusbar()->clear();
CCS->curh->set(Cursor::Map::POINTER);
}
}

View File

@ -19,6 +19,7 @@
#include "../CPlayerInterface.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CPathfinder.h"
@ -208,7 +209,7 @@ bool MapViewController::isEventVisible(const CGObjectInstance * obj)
if(!LOCPLINT->makingTurn && settings["adventure"]["enemyMoveTime"].Float() < 0)
return false; // enemy move speed set to "hidden/none"
if(GH.topInt() != adventureInt)
if(!GH.windows().isTopWindow(adventureInt))
return false;
if(obj->isVisitable())
@ -225,7 +226,7 @@ bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 &
if(!LOCPLINT->makingTurn && settings["adventure"]["enemyMoveTime"].Float() < 0)
return false; // enemy move speed set to "hidden/none"
if(GH.topInt() != adventureInt)
if(!GH.windows().isTopWindow(adventureInt))
return false;
if(context->isVisible(obj->convertToVisitablePos(from)))

View File

@ -14,6 +14,7 @@
#include "../../lib/CConfigHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/NotificationHandler.h"
#include "../gui/WindowHandler.h"
#include "CMT.h"
#include "SDL_Extensions.h"
@ -270,7 +271,7 @@ void ScreenHandler::initializeScreenBuffers()
throw std::runtime_error("Unable to copy surface\n");
}
if (GH.listInt.size() > 1)
if (GH.windows().count() > 1)
screenBuf = screen2;
else
screenBuf = screen;
@ -329,7 +330,6 @@ SDL_Window * ScreenHandler::createWindow()
void ScreenHandler::onScreenResize()
{
recreateWindowAndScreenBuffers();
GH.onScreenResize();
}
void ScreenHandler::validateSettings()

View File

@ -218,9 +218,9 @@ void CButton::hover (bool on)
if(!name.empty() && !isBlocked()) //if there is no name, there is nothing to display also
{
if (on)
GH.statusbar->write(name);
GH.statusbar()->write(name);
else
GH.statusbar->clearIfMatching(name);
GH.statusbar()->clearIfMatching(name);
}
}
@ -532,8 +532,8 @@ void CVolumeSlider::clickRight(tribool down, bool previousState)
if(!helpBox.empty())
CRClickPopup::createAndPush(helpBox);
if(GH.statusbar)
GH.statusbar->write(helpBox);
GH.statusbar()->write(helpBox);
}
}

View File

@ -14,6 +14,7 @@
#include "TextControls.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../windows/CCreatureWindow.h"
#include "../windows/GUIClasses.h"
@ -115,11 +116,11 @@ void CGarrisonSlot::hover (bool on)
temp = CGI->generaltexth->tcommands[11]; //Empty
}
}
GH.statusbar->write(temp);
GH.statusbar()->write(temp);
}
else
{
GH.statusbar->clear();
GH.statusbar()->clear();
}
}
@ -174,7 +175,7 @@ bool CGarrisonSlot::viewInfo()
elem->block(true);
redraw();
GH.pushIntT<CStackWindow>(myStack, dism, pom, upgr);
GH.windows().createAndPushWindow<CStackWindow>(myStack, dism, pom, upgr);
return true;
}
@ -183,7 +184,7 @@ bool CGarrisonSlot::viewInfo()
bool CGarrisonSlot::highlightOrDropArtifact()
{
bool artSelected = false;
if (CWindowWithArtifacts* chw = dynamic_cast<CWindowWithArtifacts*>(GH.topInt().get())) //dirty solution
if (auto chw = GH.windows().topWindow<CWindowWithArtifacts>()) //dirty solution
{
const auto pickedArtInst = chw->getPickedArtifact();
@ -252,7 +253,7 @@ bool CGarrisonSlot::split()
int countLeft = selection->myStack ? selection->myStack->count : 0;
int countRight = myStack ? myStack->count : 0;
GH.pushIntT<CSplitWindow>(selection->creature, std::bind(&CGarrisonInt::splitStacks, owner, _1, _2),
GH.windows().createAndPushWindow<CSplitWindow>(selection->creature, std::bind(&CGarrisonInt::splitStacks, owner, _1, _2),
minLeft, minRight, countLeft, countRight);
return true;
}
@ -289,7 +290,7 @@ void CGarrisonSlot::clickRight(tribool down, bool previousState)
{
if(creature && down)
{
GH.pushIntT<CStackWindow>(myStack, true);
GH.windows().createAndPushWindow<CStackWindow>(myStack, true);
}
}

View File

@ -12,6 +12,7 @@
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/WindowHandler.h"
#include "CComponent.h"
@ -65,7 +66,7 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
{
if(artPlace.getArt()->getTypeId() == ArtifactID::SPELLBOOK)
{
GH.pushIntT<CSpellWindow>(hero, LOCPLINT, LOCPLINT->battleInt.get());
GH.windows().createAndPushWindow<CSpellWindow>(hero, LOCPLINT, LOCPLINT->battleInt.get());
return false;
}
if(artPlace.getArt()->getTypeId() == ArtifactID::CATAPULT)
@ -359,4 +360,4 @@ std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::f
return res;
}
return res;
}
}

View File

@ -36,9 +36,9 @@
void CHoverableArea::hover (bool on)
{
if (on)
GH.statusbar->write(hoverText);
GH.statusbar()->write(hoverText);
else
GH.statusbar->clearIfMatching(hoverText);
GH.statusbar()->clearIfMatching(hoverText);
}
CHoverableArea::CHoverableArea()
@ -152,9 +152,9 @@ void CHeroArea::clickRight(tribool down, bool previousState)
void CHeroArea::hover(bool on)
{
if (on && hero)
GH.statusbar->write(hero->getObjectName());
GH.statusbar()->write(hero->getObjectName());
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
void LRClickableAreaOpenTown::clickLeft(tribool down, bool previousState)

View File

@ -434,9 +434,7 @@ CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
CGStatusBar::~CGStatusBar()
{
assert(GH.statusbar.get() != this || GH.statusbar == nullptr);
if (GH.statusbar.get() == this)
GH.statusbar = nullptr;
assert(GH.statusbar().get() != this);
}
void CGStatusBar::show(SDL_Surface * to)
@ -455,13 +453,14 @@ void CGStatusBar::clickLeft(tribool down, bool previousState)
void CGStatusBar::activate()
{
GH.statusbar = shared_from_this();
GH.setStatusbar(shared_from_this());
CIntObject::activate();
}
void CGStatusBar::deactivate()
{
assert(GH.statusbar.get() == this);
assert(GH.statusbar().get() == this);
GH.setStatusbar(nullptr);
if (enteringText)
LOCPLINT->cingconsole->endEnteringText(false);

View File

@ -22,6 +22,7 @@
#include "../PlayerLocalState.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/CComponent.h"
#include "../widgets/Buttons.h"
@ -125,7 +126,7 @@ void CBuildingRect::hover(bool on)
if(parent->selectedBuilding == this)
{
parent->selectedBuilding = nullptr;
GH.statusbar->clear();
GH.statusbar()->clear();
}
}
}
@ -158,7 +159,7 @@ void CBuildingRect::clickRight(tribool down, bool previousState)
else
{
int level = ( bid - BuildingID::DWELL_FIRST ) % GameConstants::CREATURES_PER_TOWN;
GH.pushIntT<CDwellingInfoBox>(parent->pos.x+parent->pos.w / 2, parent->pos.y+parent->pos.h /2, town, level);
GH.windows().createAndPushWindow<CDwellingInfoBox>(parent->pos.x+parent->pos.w / 2, parent->pos.y+parent->pos.h /2, town, level);
}
}
}
@ -255,7 +256,7 @@ void CBuildingRect::mouseMoved (const Point & cursorPosition)
if(parent->selectedBuilding == this)
{
parent->selectedBuilding = nullptr;
GH.statusbar->clear();
GH.statusbar()->clear();
}
}
else //inside the area of this building
@ -264,7 +265,7 @@ void CBuildingRect::mouseMoved (const Point & cursorPosition)
|| (*parent->selectedBuilding)<(*this)) //or we are on top
{
parent->selectedBuilding = this;
GH.statusbar->write(getSubtitle());
GH.statusbar()->write(getSubtitle());
}
}
}
@ -338,7 +339,7 @@ void CHeroGSlot::hover(bool on)
{
if(!on)
{
GH.statusbar->clear();
GH.statusbar()->clear();
return;
}
std::shared_ptr<CHeroGSlot> other = upg ? owner->garrisonedHero : owner->visitingHero;
@ -383,7 +384,7 @@ void CHeroGSlot::hover(bool on)
}
}
if(temp.size())
GH.statusbar->write(temp);
GH.statusbar()->write(temp);
}
void CHeroGSlot::clickLeft(tribool down, bool previousState)
@ -420,7 +421,7 @@ void CHeroGSlot::clickRight(tribool down, bool previousState)
{
if(hero && down)
{
GH.pushIntT<CInfoBoxPopup>(Point(pos.x + 175, pos.y + 100), hero);
GH.windows().createAndPushWindow<CInfoBoxPopup>(Point(pos.x + 175, pos.y + 100), hero);
}
}
@ -696,7 +697,7 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
case BuildingID::FORT:
case BuildingID::CITADEL:
case BuildingID::CASTLE:
GH.pushIntT<CFortScreen>(town);
GH.windows().createAndPushWindow<CFortScreen>(town);
break;
case BuildingID::VILLAGE_HALL:
@ -707,7 +708,7 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
break;
case BuildingID::MARKETPLACE:
GH.pushIntT<CMarketplaceWindow>(town, town->visitingHero);
GH.windows().createAndPushWindow<CMarketplaceWindow>(town, town->visitingHero);
break;
case BuildingID::BLACKSMITH:
@ -733,7 +734,7 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
case BuildingSubID::ARTIFACT_MERCHANT:
if(town->visitingHero)
GH.pushIntT<CMarketplaceWindow>(town, town->visitingHero, EMarketMode::RESOURCE_ARTIFACT);
GH.windows().createAndPushWindow<CMarketplaceWindow>(town, town->visitingHero, EMarketMode::RESOURCE_ARTIFACT);
else
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->getNameTranslated())); //Only visiting heroes may use the %s.
break;
@ -744,14 +745,14 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
case BuildingSubID::FREELANCERS_GUILD:
if(getHero())
GH.pushIntT<CMarketplaceWindow>(town, getHero(), EMarketMode::CREATURE_RESOURCE);
GH.windows().createAndPushWindow<CMarketplaceWindow>(town, getHero(), EMarketMode::CREATURE_RESOURCE);
else
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->getNameTranslated())); //Only visiting heroes may use the %s.
break;
case BuildingSubID::MAGIC_UNIVERSITY:
if (getHero())
GH.pushIntT<CUniversityWindow>(getHero(), town);
GH.windows().createAndPushWindow<CUniversityWindow>(getHero(), town);
else
enterBuilding(building);
break;
@ -768,7 +769,7 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil
break;
case BuildingSubID::CREATURE_TRANSFORMER: //Skeleton Transformer
GH.pushIntT<CTransformerWindow>(town, getHero());
GH.windows().createAndPushWindow<CTransformerWindow>(town, getHero());
break;
case BuildingSubID::PORTAL_OF_SUMMONING:
@ -823,7 +824,7 @@ void CCastleBuildings::enterBlacksmith(ArtifactID artifactID)
}
}
CreatureID cre = art->getWarMachine();
GH.pushIntT<CBlacksmithDialog>(possible, cre, artifactID, hero->id);
GH.windows().createAndPushWindow<CBlacksmithDialog>(possible, cre, artifactID, hero->id);
}
void CCastleBuildings::enterBuilding(BuildingID building)
@ -852,7 +853,7 @@ void CCastleBuildings::enterCastleGate()
}
}
auto gateIcon = std::make_shared<CAnimImage>(town->town->clientInfo.buildingsIcons, BuildingID::CASTLE_GATE);//will be deleted by selection window
GH.pushIntT<CObjectListWindow>(availableTowns, gateIcon, CGI->generaltexth->jktexts[40],
GH.windows().createAndPushWindow<CObjectListWindow>(availableTowns, gateIcon, CGI->generaltexth->jktexts[40],
CGI->generaltexth->jktexts[41], std::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1));
}
@ -863,7 +864,7 @@ void CCastleBuildings::enterDwelling(int level)
{
LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
};
GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, -87);
GH.windows().createAndPushWindow<CRecruitmentWindow>(town, level, town, recruitCb, -87);
}
void CCastleBuildings::enterToTheQuickRecruitmentWindow()
@ -875,7 +876,7 @@ void CCastleBuildings::enterToTheQuickRecruitmentWindow()
const auto hasSomeoneToRecruit = std::any_of(beginIt, afterLastIt,
[](const auto & creatureInfo) { return creatureInfo.first > 0; });
if(hasSomeoneToRecruit)
GH.pushIntT<QuickRecruitmentWindow>(town, pos);
GH.windows().createAndPushWindow<QuickRecruitmentWindow>(town, pos);
else
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.townHall.noCreaturesToRecruit"), {});
}
@ -973,7 +974,8 @@ void CCastleBuildings::enterTownHall()
else
{
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[673]);
dynamic_cast<CInfoWindow*>(GH.topInt().get())->buttons[0]->addCallback(std::bind(&CCastleBuildings::openTownHall, this));
assert(GH.windows().topWindow<CInfoWindow>() != nullptr);
GH.windows().topWindow<CInfoWindow>()->buttons[0]->addCallback(std::bind(&CCastleBuildings::openTownHall, this));
}
}
else
@ -986,12 +988,12 @@ void CCastleBuildings::openMagesGuild()
{
std::string mageGuildBackground;
mageGuildBackground = LOCPLINT->castleInt->town->town->clientInfo.guildBackground;
GH.pushIntT<CMageGuildScreen>(LOCPLINT->castleInt,mageGuildBackground);
GH.windows().createAndPushWindow<CMageGuildScreen>(LOCPLINT->castleInt,mageGuildBackground);
}
void CCastleBuildings::openTownHall()
{
GH.pushIntT<CHallInterface>(town);
GH.windows().createAndPushWindow<CHallInterface>(town);
}
CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact, bool _showAvailable):
@ -1057,11 +1059,11 @@ void CCreaInfo::hover(bool on)
if(on)
{
GH.statusbar->write(message);
GH.statusbar()->write(message);
}
else
{
GH.statusbar->clearIfMatching(message);
GH.statusbar()->clearIfMatching(message);
}
}
@ -1074,7 +1076,7 @@ void CCreaInfo::clickLeft(tribool down, bool previousState)
{
LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
};
GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, offset);
GH.windows().createAndPushWindow<CRecruitmentWindow>(town, level, town, recruitCb, offset);
}
}
@ -1094,7 +1096,7 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
if(down)
{
if (showAvailable)
GH.pushIntT<CDwellingInfoBox>(GH.screenDimensions().x / 2, GH.screenDimensions().y / 2, town, level);
GH.windows().createAndPushWindow<CDwellingInfoBox>(GH.screenDimensions().x / 2, GH.screenDimensions().y / 2, town, level);
else
CRClickPopup::createAndPush(genGrowthText(), std::make_shared<CComponent>(CComponent::creature, creature->getId()));
}
@ -1136,11 +1138,11 @@ void CTownInfo::hover(bool on)
if(on)
{
if(building )
GH.statusbar->write(building->getNameTranslated());
GH.statusbar()->write(building->getNameTranslated());
}
else
{
GH.statusbar->clear();
GH.statusbar()->clear();
}
}
@ -1253,7 +1255,7 @@ void CCastleInterface::townChange()
if ( dest == town )
return;
close();
GH.pushIntT<CCastleInterface>(dest, town);
GH.windows().createAndPushWindow<CCastleInterface>(dest, town);
}
void CCastleInterface::addBuilding(BuildingID bid)
@ -1382,24 +1384,24 @@ void CHallInterface::CBuildingBox::hover(bool on)
else
toPrint = CGI->generaltexth->hcommands[state];
boost::algorithm::replace_first(toPrint,"%s",building->getNameTranslated());
GH.statusbar->write(toPrint);
GH.statusbar()->write(toPrint);
}
else
{
GH.statusbar->clear();
GH.statusbar()->clear();
}
}
void CHallInterface::CBuildingBox::clickLeft(tribool down, bool previousState)
{
if(previousState && (!down))
GH.pushIntT<CBuildWindow>(town,building,state,0);
GH.windows().createAndPushWindow<CBuildWindow>(town,building,state,0);
}
void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState)
{
if(down)
GH.pushIntT<CBuildWindow>(town,building,state,1);
GH.windows().createAndPushWindow<CBuildWindow>(town,building,state,1);
}
CHallInterface::CHallInterface(const CGTownInstance * Town):
@ -1493,7 +1495,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
void CBuildWindow::buyFunc()
{
LOCPLINT->cb->buildBuilding(town,building->bid);
GH.popInts(2); //we - build window and hall screen
GH.windows().popWindows(2); //we - build window and hall screen
}
std::string CBuildWindow::getTextForState(int state)
@ -1570,11 +1572,11 @@ void LabeledValue::hover(bool on)
{
if(on)
{
GH.statusbar->write(hoverText);
GH.statusbar()->write(hoverText);
}
else
{
GH.statusbar->clear();
GH.statusbar()->clear();
parent->hovered = false;
}
}
@ -1739,9 +1741,9 @@ const CBuilding * CFortScreen::RecruitArea::getMyBuilding()
void CFortScreen::RecruitArea::hover(bool on)
{
if(on)
GH.statusbar->write(hoverText);
GH.statusbar()->write(hoverText);
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
void CFortScreen::RecruitArea::creaturesChangedEventHandler()
@ -1829,9 +1831,9 @@ void CMageGuildScreen::Scroll::clickRight(tribool down, bool previousState)
void CMageGuildScreen::Scroll::hover(bool on)
{
if(on)
GH.statusbar->write(spell->getNameTranslated());
GH.statusbar()->write(spell->getNameTranslated());
else
GH.statusbar->clear();
GH.statusbar()->clear();
}

View File

@ -20,6 +20,7 @@
#include "../gui/CGuiHandler.h"
#include "../gui/TextAlignment.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/CComponent.h"
#include "../widgets/TextControls.h"
@ -96,8 +97,8 @@ void CHeroSwitcher::clickLeft(tribool down, bool previousState)
else
{
const CGHeroInstance * buf = hero;
GH.popInts(1);
GH.pushIntT<CHeroWindow>(buf);
GH.windows().popWindows(1);
GH.windows().createAndPushWindow<CHeroWindow>(buf);
}
}
}
@ -313,18 +314,17 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
//if we have exchange window with this curHero open
bool noDismiss=false;
for(auto isa : GH.listInt)
{
if(CExchangeWindow * cew = dynamic_cast<CExchangeWindow*>(isa.get()))
{
for(int g=0; g < cew->heroInst.size(); ++g)
if(cew->heroInst[g] == curHero)
noDismiss = true;
}
if(dynamic_cast<CKingdomInterface*>(isa.get()))
noDismiss = true;
for(auto cew : GH.windows().findWindows<CExchangeWindow>())
{
for(int g=0; g < cew->heroInst.size(); ++g)
if(cew->heroInst[g] == curHero)
noDismiss = true;
}
for(auto ki : GH.windows().findWindows<CKingdomInterface>())
noDismiss = true;
//if player only have one hero and no towns
if(!LOCPLINT->cb->howManyTowns() && LOCPLINT->cb->howManyHeroes() == 1)
noDismiss = true;
@ -389,7 +389,7 @@ void CHeroWindow::commanderWindow()
}
else
{
GH.pushIntT<CStackWindow>(curHero->commander, false);
GH.windows().createAndPushWindow<CStackWindow>(curHero->commander, false);
}
}

View File

@ -24,6 +24,7 @@
#include "../battle/BattleInterface.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/CComponent.h"
#include "../widgets/TextControls.h"
@ -525,7 +526,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
else //adventure spell
{
const CGHeroInstance * h = owner->myHero;
GH.popInts(1);
GH.windows().popWindows(1);
auto guard = vstd::makeScopeGuard([this]()
{

View File

@ -16,6 +16,7 @@
#include "../renderSDL/SDL_Extensions.h"
#include "../gui/TextAlignment.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/Buttons.h"
#include "../widgets/TextControls.h"
#include "../windows/InfoWindows.h"
@ -242,7 +243,7 @@ void CTradeWindow::CTradeableItem::hover(bool on)
{
if(!on)
{
GH.statusbar->clear();
GH.statusbar()->clear();
return;
}
@ -250,13 +251,13 @@ void CTradeWindow::CTradeableItem::hover(bool on)
{
case CREATURE:
case CREATURE_PLACEHOLDER:
GH.statusbar->write(boost::str(boost::format(CGI->generaltexth->allTexts[481]) % CGI->creh->objects[id]->getNamePluralTranslated()));
GH.statusbar()->write(boost::str(boost::format(CGI->generaltexth->allTexts[481]) % CGI->creh->objects[id]->getNamePluralTranslated()));
break;
case ARTIFACT_PLACEHOLDER:
if(id < 0)
GH.statusbar->write(CGI->generaltexth->zelp[582].first);
GH.statusbar()->write(CGI->generaltexth->zelp[582].first);
else
GH.statusbar->write(CGI->artifacts()->getByIndex(id)->getNameTranslated());
GH.statusbar()->write(CGI->artifacts()->getByIndex(id)->getNameTranslated());
break;
}
}
@ -628,10 +629,10 @@ void CTradeWindow::setMode(EMarketMode::EMarketMode Mode)
{
case EMarketMode::CREATURE_EXP:
case EMarketMode::ARTIFACT_EXP:
GH.pushIntT<CAltarWindow>(m, h, Mode);
GH.windows().createAndPushWindow<CAltarWindow>(m, h, Mode);
break;
default:
GH.pushIntT<CMarketplaceWindow>(m, h, Mode);
GH.windows().createAndPushWindow<CMarketplaceWindow>(m, h, Mode);
break;
}
}

View File

@ -17,6 +17,7 @@
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/TextAlignment.h"
#include "../gui/WindowHandler.h"
#include "../widgets/Buttons.h"
#include "../widgets/TextControls.h"
#include "../widgets/CreatureCostBox.h"
@ -124,5 +125,5 @@ CreaturePurchaseCard::CCreatureClickArea::CCreatureClickArea(const Point & posit
void CreaturePurchaseCard::CCreatureClickArea::clickRight(tribool down, bool previousState)
{
if (down)
GH.pushIntT<CStackWindow>(creatureOnTheCard, true);
GH.windows().createAndPushWindow<CStackWindow>(creatureOnTheCard, true);
}

View File

@ -29,6 +29,7 @@
#include "../gui/CursorHandler.h"
#include "../gui/TextAlignment.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
#include "../widgets/MiscWidgets.h"
@ -98,7 +99,7 @@ void CRecruitmentWindow::CCreatureCard::clickLeft(tribool down, bool previousSta
void CRecruitmentWindow::CCreatureCard::clickRight(tribool down, bool previousState)
{
if(down)
GH.pushIntT<CStackWindow>(creature, true);
GH.windows().createAndPushWindow<CStackWindow>(creature, true);
}
void CRecruitmentWindow::CCreatureCard::showAll(SDL_Surface * to)
@ -507,7 +508,7 @@ void CTavernWindow::recruitb()
void CTavernWindow::thievesguildb()
{
GH.pushIntT<CThievesGuildWindow>(tavernObj);
GH.windows().createAndPushWindow<CThievesGuildWindow>(tavernObj);
}
CTavernWindow::~CTavernWindow()
@ -547,7 +548,7 @@ void CTavernWindow::HeroPortrait::clickLeft(tribool down, bool previousState)
void CTavernWindow::HeroPortrait::clickRight(tribool down, bool previousState)
{
if(h && down)
GH.pushIntT<CRClickPopupInt>(std::make_shared<CHeroWindow>(h));
GH.windows().createAndPushWindow<CRClickPopupInt>(std::make_shared<CHeroWindow>(h));
}
CTavernWindow::HeroPortrait::HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H)
@ -585,9 +586,9 @@ void CTavernWindow::HeroPortrait::hover(bool on)
{
//Hoverable::hover(on);
if(on)
GH.statusbar->write(hoverName);
GH.statusbar()->write(hoverName);
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
static const std::string QUICK_EXCHANGE_MOD_PREFIX = "quick-exchange";
@ -1240,7 +1241,7 @@ void CUniversityWindow::CItem::clickLeft(tribool down, bool previousState)
if(previousState && (!down))
{
if(state() == 2)
GH.pushIntT<CUnivConfirmWindow>(parent, ID, LOCPLINT->cb->getResourceAmount(EGameResID::GOLD) >= 2000);
GH.windows().createAndPushWindow<CUnivConfirmWindow>(parent, ID, LOCPLINT->cb->getResourceAmount(EGameResID::GOLD) >= 2000);
}
}
@ -1255,9 +1256,9 @@ void CUniversityWindow::CItem::clickRight(tribool down, bool previousState)
void CUniversityWindow::CItem::hover(bool on)
{
if(on)
GH.statusbar->write(CGI->skillh->getByIndex(ID)->getNameTranslated());
GH.statusbar()->write(CGI->skillh->getByIndex(ID)->getNameTranslated());
else
GH.statusbar->clear();
GH.statusbar()->clear();
}
int CUniversityWindow::CItem::state()

View File

@ -20,6 +20,7 @@
#include "../widgets/Buttons.h"
#include "../widgets/TextControls.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../battle/BattleInterface.h"
#include "../battle/BattleInterfaceClasses.h"
#include "../adventureMap/AdventureMapInterface.h"
@ -182,7 +183,7 @@ void CInfoWindow::showAll(SDL_Surface * to)
void CInfoWindow::showInfoDialog(const std::string &text, const TCompsInfo & components, PlayerColor player)
{
GH.pushInt(CInfoWindow::create(text, player, components));
GH.windows().pushWindow(CInfoWindow::create(text, player, components));
}
void CInfoWindow::showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, PlayerColor player)
@ -196,7 +197,7 @@ void CInfoWindow::showYesNoDialog(const std::string & text, const TCompsInfo & c
temp->buttons[0]->addCallback( onYes );
temp->buttons[1]->addCallback( onNo );
GH.pushInt(temp);
GH.windows().pushWindow(temp);
}
std::shared_ptr<CInfoWindow> CInfoWindow::create(const std::string &text, PlayerColor playerID, const TCompsInfo & components)
@ -313,7 +314,7 @@ void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCom
#endif
temp->fitToScreen(10);
GH.pushIntT<CRClickPopupInt>(temp);
GH.windows().createAndPushWindow<CRClickPopupInt>(temp);
}
void CRClickPopup::createAndPush(const std::string & txt, std::shared_ptr<CComponent> component)
@ -329,7 +330,7 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
auto iWin = createInfoWin(p, obj); //try get custom infowindow for this obj
if(iWin)
{
GH.pushInt(iWin);
GH.windows().pushWindow(iWin);
}
else
{

View File

@ -14,6 +14,7 @@
#include "../../../lib/CGeneralTextHandler.h"
#include "../../../lib/filesystem/ResourceID.h"
#include "../../gui/CGuiHandler.h"
#include "../../gui/WindowHandler.h"
#include "../../widgets/Buttons.h"
#include "../../widgets/TextControls.h"
#include "../../widgets/Images.h"
@ -197,7 +198,7 @@ void GeneralOptionsTab::selectGameResolution()
items.push_back(std::move(resolutionStr));
++i;
}
GH.pushIntT<CObjectListWindow>(items, nullptr,
GH.windows().createAndPushWindow<CObjectListWindow>(items, nullptr,
CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.hover"),
CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.help"),
[this](int index)
@ -252,7 +253,7 @@ void GeneralOptionsTab::selectGameScaling()
++i;
}
GH.pushIntT<CObjectListWindow>(
GH.windows().createAndPushWindow<CObjectListWindow>(
items,
nullptr,
CGI->generaltexth->translate("vcmi.systemOptions.scalingMenu.hover"),

View File

@ -22,6 +22,7 @@
#include "CServerHandler.h"
#include "filesystem/ResourceID.h"
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "lobby/CSavingScreen.h"
#include "widgets/Buttons.h"
#include "widgets/Images.h"
@ -103,9 +104,9 @@ void SettingsMainWindow::openTab(size_t index)
void SettingsMainWindow::close()
{
if(GH.topInt().get() != this)
if(!GH.windows().isTopWindow(this))
logGlobal->error("Only top interface must be closed");
GH.popInts(1);
GH.windows().popWindows(1);
}
void SettingsMainWindow::quitGameButtonCallback()
@ -132,7 +133,7 @@ void SettingsMainWindow::loadGameButtonCallback()
void SettingsMainWindow::saveGameButtonCallback()
{
close();
GH.pushIntT<CSavingScreen>();
GH.windows().createAndPushWindow<CSavingScreen>();
}
void SettingsMainWindow::restartGameButtonCallback()