mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Encapsulation of WindowHandler state
This commit is contained in:
@@ -623,8 +623,7 @@ static void quitApplication()
|
|||||||
CSH->endGameplay();
|
CSH->endGameplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
GH.windows().listInt.clear();
|
GH.windows().clear();
|
||||||
GH.windows().objsToBlit.clear();
|
|
||||||
|
|
||||||
CMM.reset();
|
CMM.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -169,15 +169,16 @@ void CPlayerInterface::initGameInterface(std::shared_ptr<Environment> ENV, std::
|
|||||||
void CPlayerInterface::playerStartsTurn(PlayerColor player)
|
void CPlayerInterface::playerStartsTurn(PlayerColor player)
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
if (!vstd::contains (GH.windows().listInt, adventureInt))
|
|
||||||
|
if(GH.windows().findInts<AdventureMapInterface>().empty())
|
||||||
{
|
{
|
||||||
// after map load - remove all active windows and replace them with adventure map
|
// after map load - remove all active windows and replace them with adventure map
|
||||||
GH.windows().popInts ((int)GH.windows().listInt.size());
|
GH.windows().clear();
|
||||||
GH.windows().pushInt (adventureInt);
|
GH.windows().pushInt(adventureInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all dialogs that do not expect query answer
|
// remove all dialogs that do not expect query answer
|
||||||
while (GH.windows().listInt.front() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.windows().listInt.front().get()))
|
while (GH.windows().topInt() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.windows().topInt().get()))
|
||||||
GH.windows().popInts(1);
|
GH.windows().popInts(1);
|
||||||
|
|
||||||
if (player != playerID && LOCPLINT == this)
|
if (player != playerID && LOCPLINT == this)
|
||||||
@@ -538,17 +539,15 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
|
|||||||
castleInt->heroes->update();
|
castleInt->heroes->update();
|
||||||
castleInt->redraw();
|
castleInt->redraw();
|
||||||
}
|
}
|
||||||
for (auto isa : GH.windows().listInt)
|
|
||||||
|
for (auto ki : GH.windows().findInts<CKingdomInterface>())
|
||||||
{
|
{
|
||||||
CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa.get());
|
ki->townChanged(town);
|
||||||
if (ki)
|
ki->updateGarrisons();
|
||||||
{
|
ki->redraw();
|
||||||
ki->townChanged(town);
|
|
||||||
ki->updateGarrisons();
|
|
||||||
ki->redraw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
|
void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
|
||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
@@ -590,17 +589,13 @@ void CPlayerInterface::garrisonsChanged(std::vector<const CGObjectInstance *> ob
|
|||||||
adventureInt->onTownChanged(town);
|
adventureInt->onTownChanged(town);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto & elem : GH.windows().listInt)
|
for (auto cgh : GH.windows().findInts<CGarrisonHolder>())
|
||||||
{
|
cgh->updateGarrisons();
|
||||||
CGarrisonHolder *cgh = dynamic_cast<CGarrisonHolder*>(elem.get());
|
|
||||||
if (cgh)
|
|
||||||
cgh->updateGarrisons();
|
|
||||||
|
|
||||||
if (CTradeWindow *cmw = dynamic_cast<CTradeWindow*>(elem.get()))
|
for (auto cmw : GH.windows().findInts<CTradeWindow>())
|
||||||
{
|
{
|
||||||
if (vstd::contains(objs, cmw->hero))
|
if (vstd::contains(objs, cmw->hero))
|
||||||
cmw->garrisonChanged();
|
cmw->garrisonChanged();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GH.windows().totalRedraw();
|
GH.windows().totalRedraw();
|
||||||
@@ -1016,7 +1011,7 @@ void CPlayerInterface::showInfoDialog(EInfoWindowMode type, const std::string &t
|
|||||||
waitWhileDialog(); //Fix for mantis #98
|
waitWhileDialog(); //Fix for mantis #98
|
||||||
adventureInt->showInfoBoxMessage(components, text, timer);
|
adventureInt->showInfoBoxMessage(components, text, timer);
|
||||||
|
|
||||||
if (makingTurn && GH.windows().listInt.size() && LOCPLINT == this)
|
if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
|
||||||
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
|
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1057,7 +1052,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
|
|||||||
}
|
}
|
||||||
std::shared_ptr<CInfoWindow> temp = CInfoWindow::create(text, playerID, components);
|
std::shared_ptr<CInfoWindow> temp = CInfoWindow::create(text, playerID, components);
|
||||||
|
|
||||||
if (makingTurn && GH.windows().listInt.size() && LOCPLINT == this)
|
if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
|
||||||
{
|
{
|
||||||
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
|
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
|
||||||
showingDialog->set(true);
|
showingDialog->set(true);
|
||||||
@@ -1206,14 +1201,11 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
|
|||||||
else if(castleInterface)
|
else if(castleInterface)
|
||||||
castleInterface->creaturesChangedEventHandler();
|
castleInterface->creaturesChangedEventHandler();
|
||||||
|
|
||||||
for(auto isa : GH.windows().listInt)
|
if (townObj)
|
||||||
{
|
for (auto ki : GH.windows().findInts<CKingdomInterface>())
|
||||||
CKingdomInterface *ki = dynamic_cast<CKingdomInterface*>(isa.get());
|
|
||||||
if (ki && townObj)
|
|
||||||
ki->townChanged(townObj);
|
ki->townChanged(townObj);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(town && GH.windows().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))
|
|| town->ID == Obj::CREATURE_GENERATOR4 || town->ID == Obj::WAR_MACHINE_FACTORY))
|
||||||
{
|
{
|
||||||
CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.windows().topInt().get());
|
CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.windows().topInt().get());
|
||||||
@@ -1594,7 +1586,7 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
|
|||||||
if(adventureInt)
|
if(adventureInt)
|
||||||
{
|
{
|
||||||
GH.terminate_cond->setn(true);
|
GH.terminate_cond->setn(true);
|
||||||
GH.windows().popInts(GH.windows().listInt.size());
|
GH.windows().popInts(GH.windows().count());
|
||||||
adventureInt.reset();
|
adventureInt.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1809,12 +1801,9 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
|
|||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
||||||
adventureInt->onHeroChanged(hero);
|
adventureInt->onHeroChanged(hero);
|
||||||
for(auto isa : GH.windows().listInt)
|
|
||||||
{
|
for(auto artWin : GH.windows().findInts<CArtifactHolder>())
|
||||||
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
|
artWin->artifactRemoved(al);
|
||||||
if (artWin)
|
|
||||||
artWin->artifactRemoved(al);
|
|
||||||
}
|
|
||||||
|
|
||||||
waitWhileDialog();
|
waitWhileDialog();
|
||||||
}
|
}
|
||||||
@@ -1834,12 +1823,9 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact
|
|||||||
redraw = false;
|
redraw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto isa : GH.windows().listInt)
|
for(auto artWin : GH.windows().findInts<CArtifactHolder>())
|
||||||
{
|
artWin->artifactMoved(src, dst, redraw);
|
||||||
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
|
|
||||||
if (artWin)
|
|
||||||
artWin->artifactMoved(src, dst, redraw);
|
|
||||||
}
|
|
||||||
waitWhileDialog();
|
waitWhileDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1853,12 +1839,9 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
|
|||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
||||||
adventureInt->onHeroChanged(hero);
|
adventureInt->onHeroChanged(hero);
|
||||||
for(auto isa : GH.windows().listInt)
|
|
||||||
{
|
for(auto artWin : GH.windows().findInts<CArtifactHolder>())
|
||||||
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
|
artWin->artifactAssembled(al);
|
||||||
if (artWin)
|
|
||||||
artWin->artifactAssembled(al);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
|
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
|
||||||
@@ -1866,12 +1849,9 @@ void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
|
|||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
|
||||||
adventureInt->onHeroChanged(hero);
|
adventureInt->onHeroChanged(hero);
|
||||||
for(auto isa : GH.windows().listInt)
|
|
||||||
{
|
for(auto artWin : GH.windows().findInts<CArtifactHolder>())
|
||||||
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
|
artWin->artifactDisassembled(al);
|
||||||
if (artWin)
|
|
||||||
artWin->artifactDisassembled(al);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::waitForAllDialogs(bool unlockPim)
|
void CPlayerInterface::waitForAllDialogs(bool unlockPim)
|
||||||
|
|||||||
@@ -770,8 +770,7 @@ void CClient::removeGUI()
|
|||||||
if(GH.windows().topInt())
|
if(GH.windows().topInt())
|
||||||
GH.windows().topInt()->deactivate();
|
GH.windows().topInt()->deactivate();
|
||||||
adventureInt.reset();
|
adventureInt.reset();
|
||||||
GH.windows().listInt.clear();
|
GH.windows().clear();
|
||||||
GH.windows().objsToBlit.clear();
|
|
||||||
GH.statusbar.reset();
|
GH.statusbar.reset();
|
||||||
logGlobal->info("Removed GUI.");
|
logGlobal->info("Removed GUI.");
|
||||||
|
|
||||||
|
|||||||
@@ -196,14 +196,8 @@ void ClientCommandManager::handleNotDialogCommand()
|
|||||||
|
|
||||||
void ClientCommandManager::handleGuiCommand()
|
void ClientCommandManager::handleGuiCommand()
|
||||||
{
|
{
|
||||||
for(const auto & child : GH.windows().listInt)
|
for(const auto & child : GH.windows().findInts<CIntObject>())
|
||||||
{
|
printInfoAboutInterfaceObject(child.get(), 0);
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientCommandManager::handleConvertTextCommand()
|
void ClientCommandManager::handleConvertTextCommand()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClient
|
|||||||
|
|
||||||
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
|
||||||
{
|
{
|
||||||
if(GH.windows().listInt.size())
|
if(GH.windows().count() > 0)
|
||||||
GH.windows().popInts(1);
|
GH.windows().popInts(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,30 +21,29 @@
|
|||||||
|
|
||||||
void WindowHandler::popInt(std::shared_ptr<IShowActivatable> top)
|
void WindowHandler::popInt(std::shared_ptr<IShowActivatable> top)
|
||||||
{
|
{
|
||||||
assert(listInt.front() == top);
|
assert(windowsStack.back() == top);
|
||||||
top->deactivate();
|
top->deactivate();
|
||||||
disposed.push_back(top);
|
disposed.push_back(top);
|
||||||
listInt.pop_front();
|
windowsStack.pop_back();
|
||||||
objsToBlit -= top;
|
if(!windowsStack.empty())
|
||||||
if(!listInt.empty())
|
windowsStack.back()->activate();
|
||||||
listInt.front()->activate();
|
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
|
void WindowHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
|
||||||
{
|
{
|
||||||
assert(newInt);
|
assert(newInt);
|
||||||
assert(!vstd::contains(listInt, newInt)); // do not add same object twice
|
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)
|
//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;
|
screenBuf = screen2;
|
||||||
|
|
||||||
if(!listInt.empty())
|
if(!windowsStack.empty())
|
||||||
listInt.front()->deactivate();
|
windowsStack.back()->deactivate();
|
||||||
listInt.push_front(newInt);
|
windowsStack.push_back(newInt);
|
||||||
CCS->curh->set(Cursor::Map::POINTER);
|
CCS->curh->set(Cursor::Map::POINTER);
|
||||||
newInt->activate();
|
newInt->activate();
|
||||||
objsToBlit.push_back(newInt);
|
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,36 +52,35 @@ void WindowHandler::popInts(int howMany)
|
|||||||
if(!howMany)
|
if(!howMany)
|
||||||
return; //senseless but who knows...
|
return; //senseless but who knows...
|
||||||
|
|
||||||
assert(listInt.size() >= howMany);
|
assert(windowsStack.size() >= howMany);
|
||||||
listInt.front()->deactivate();
|
windowsStack.back()->deactivate();
|
||||||
for(int i = 0; i < howMany; i++)
|
for(int i = 0; i < howMany; i++)
|
||||||
{
|
{
|
||||||
objsToBlit -= listInt.front();
|
disposed.push_back(windowsStack.back());
|
||||||
disposed.push_back(listInt.front());
|
windowsStack.pop_back();
|
||||||
listInt.pop_front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!listInt.empty())
|
if(!windowsStack.empty())
|
||||||
{
|
{
|
||||||
listInt.front()->activate();
|
windowsStack.back()->activate();
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
}
|
}
|
||||||
GH.fakeMouseMove();
|
GH.fakeMouseMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IShowActivatable> WindowHandler::topInt()
|
std::shared_ptr<IShowActivatable> WindowHandler::topInt() const
|
||||||
{
|
{
|
||||||
if(listInt.empty())
|
if(windowsStack.empty())
|
||||||
return std::shared_ptr<IShowActivatable>();
|
return nullptr;
|
||||||
else
|
|
||||||
return listInt.front();
|
return windowsStack.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHandler::totalRedraw()
|
void WindowHandler::totalRedraw()
|
||||||
{
|
{
|
||||||
CSDL_Ext::fillSurface(screen2, Colors::BLACK);
|
CSDL_Ext::fillSurface(screen2, Colors::BLACK);
|
||||||
|
|
||||||
for(auto & elem : objsToBlit)
|
for(auto & elem : windowsStack)
|
||||||
elem->showAll(screen2);
|
elem->showAll(screen2);
|
||||||
CSDL_Ext::blitAt(screen2, 0, 0, screen);
|
CSDL_Ext::blitAt(screen2, 0, 0, screen);
|
||||||
}
|
}
|
||||||
@@ -90,22 +88,21 @@ void WindowHandler::totalRedraw()
|
|||||||
void WindowHandler::simpleRedraw()
|
void WindowHandler::simpleRedraw()
|
||||||
{
|
{
|
||||||
//update only top interface and draw background
|
//update only top interface and draw background
|
||||||
if(objsToBlit.size() > 1)
|
if(windowsStack.size() > 1)
|
||||||
CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
|
CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
|
||||||
if(!objsToBlit.empty())
|
if(!windowsStack.empty())
|
||||||
objsToBlit.back()->show(screen); //blit active interface/window
|
windowsStack.back()->show(screen); //blit active interface/window
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHandler::onScreenResize()
|
void WindowHandler::onScreenResize()
|
||||||
{
|
{
|
||||||
for(const auto & entry : listInt)
|
for(const auto & entry : windowsStack)
|
||||||
{
|
{
|
||||||
auto intObject = std::dynamic_pointer_cast<CIntObject>(entry);
|
auto intObject = std::dynamic_pointer_cast<CIntObject>(entry);
|
||||||
|
|
||||||
if(intObject)
|
if(intObject)
|
||||||
intObject->onScreenResize();
|
intObject->onScreenResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,3 +110,14 @@ void WindowHandler::onFrameRendered()
|
|||||||
{
|
{
|
||||||
disposed.clear();
|
disposed.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t WindowHandler::count() const
|
||||||
|
{
|
||||||
|
return windowsStack.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowHandler::clear()
|
||||||
|
{
|
||||||
|
windowsStack.clear();
|
||||||
|
disposed.clear();
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,15 +13,14 @@ class IShowActivatable;
|
|||||||
|
|
||||||
class WindowHandler
|
class WindowHandler
|
||||||
{
|
{
|
||||||
public:
|
/// list of interfaces. front = bottom-most (background), back = top-most (foreground)
|
||||||
/// list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
|
/// (includes adventure map, window interfaces, all kind of active dialogs, and so on)
|
||||||
std::list<std::shared_ptr<IShowActivatable>> listInt;
|
std::vector<std::shared_ptr<IShowActivatable>> windowsStack;
|
||||||
|
|
||||||
|
/// Temporary list of recently popped windows
|
||||||
std::vector<std::shared_ptr<IShowActivatable>> disposed;
|
std::vector<std::shared_ptr<IShowActivatable>> disposed;
|
||||||
|
|
||||||
// objs to blit
|
public:
|
||||||
std::vector<std::shared_ptr<IShowActivatable>> objsToBlit;
|
|
||||||
|
|
||||||
/// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
|
/// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
|
||||||
void totalRedraw();
|
void totalRedraw();
|
||||||
|
|
||||||
@@ -33,12 +32,10 @@ public:
|
|||||||
|
|
||||||
/// deactivate old top interface, activates this one and pushes to the top
|
/// deactivate old top interface, activates this one and pushes to the top
|
||||||
void pushInt(std::shared_ptr<IShowActivatable> newInt);
|
void pushInt(std::shared_ptr<IShowActivatable> newInt);
|
||||||
|
|
||||||
|
/// creates window of class T and pushes it to the top
|
||||||
template <typename T, typename ... Args>
|
template <typename T, typename ... Args>
|
||||||
void pushIntT(Args && ... args)
|
void pushIntT(Args && ... args);
|
||||||
{
|
|
||||||
auto newInt = std::make_shared<T>(std::forward<Args>(args)...);
|
|
||||||
pushInt(newInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
|
/// pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
|
||||||
void popInts(int howMany);
|
void popInts(int howMany);
|
||||||
@@ -47,8 +44,41 @@ public:
|
|||||||
void popInt(std::shared_ptr<IShowActivatable> top);
|
void popInt(std::shared_ptr<IShowActivatable> top);
|
||||||
|
|
||||||
/// returns top interface
|
/// returns top interface
|
||||||
std::shared_ptr<IShowActivatable> topInt();
|
std::shared_ptr<IShowActivatable> topInt() const;
|
||||||
|
|
||||||
|
|
||||||
|
/// should be called after frame has been rendered to screen
|
||||||
void onFrameRendered();
|
void onFrameRendered();
|
||||||
|
|
||||||
|
/// returns current number of windows in the stack
|
||||||
|
size_t count() const;
|
||||||
|
|
||||||
|
/// erases all currently existing windows from the stacl
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/// returns all existing windows of selected type
|
||||||
|
template <typename T>
|
||||||
|
std::vector<std::shared_ptr<T>> findInts() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T, typename ... Args>
|
||||||
|
void WindowHandler::pushIntT(Args && ... args)
|
||||||
|
{
|
||||||
|
auto newInt = std::make_shared<T>(std::forward<Args>(args)...);
|
||||||
|
pushInt(newInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::vector<std::shared_ptr<T>> WindowHandler::findInts() const
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<T>> result;
|
||||||
|
|
||||||
|
for (auto const & window : windowsStack)
|
||||||
|
{
|
||||||
|
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(window);
|
||||||
|
|
||||||
|
if (casted)
|
||||||
|
result.push_back(casted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ void CMainMenu::update()
|
|||||||
if(CMM != this->shared_from_this()) //don't update if you are not a main interface
|
if(CMM != this->shared_from_this()) //don't update if you are not a main interface
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(GH.windows().listInt.empty())
|
if(GH.windows().count() == 0)
|
||||||
{
|
{
|
||||||
GH.windows().pushInt(CMM);
|
GH.windows().pushInt(CMM);
|
||||||
GH.windows().pushInt(menu);
|
GH.windows().pushInt(menu);
|
||||||
@@ -523,7 +523,7 @@ void CSimpleJoinScreen::leaveScreen()
|
|||||||
textTitle->setText("Closing...");
|
textTitle->setText("Closing...");
|
||||||
CSH->state = EClientState::CONNECTION_CANCELLED;
|
CSH->state = EClientState::CONNECTION_CANCELLED;
|
||||||
}
|
}
|
||||||
else if(GH.windows().listInt.size() && GH.windows().listInt.front().get() == this)
|
else if(GH.windows().topInt().get() == this)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
|
|||||||
else
|
else
|
||||||
CSH->justConnectToServer(addr, port);
|
CSH->justConnectToServer(addr, port);
|
||||||
|
|
||||||
if(GH.windows().listInt.size() && GH.windows().listInt.front().get() == this)
|
if(GH.windows().topInt().get() == this)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ void ScreenHandler::initializeScreenBuffers()
|
|||||||
throw std::runtime_error("Unable to copy surface\n");
|
throw std::runtime_error("Unable to copy surface\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GH.windows().listInt.size() > 1)
|
if (GH.windows().count() > 1)
|
||||||
screenBuf = screen2;
|
screenBuf = screen2;
|
||||||
else
|
else
|
||||||
screenBuf = screen;
|
screenBuf = screen;
|
||||||
|
|||||||
@@ -314,18 +314,17 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
|||||||
|
|
||||||
//if we have exchange window with this curHero open
|
//if we have exchange window with this curHero open
|
||||||
bool noDismiss=false;
|
bool noDismiss=false;
|
||||||
for(auto isa : GH.windows().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()))
|
for(auto cew : GH.windows().findInts<CExchangeWindow>())
|
||||||
noDismiss = true;
|
{
|
||||||
|
for(int g=0; g < cew->heroInst.size(); ++g)
|
||||||
|
if(cew->heroInst[g] == curHero)
|
||||||
|
noDismiss = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto ki : GH.windows().findInts<CKingdomInterface>())
|
||||||
|
noDismiss = true;
|
||||||
|
|
||||||
//if player only have one hero and no towns
|
//if player only have one hero and no towns
|
||||||
if(!LOCPLINT->cb->howManyTowns() && LOCPLINT->cb->howManyHeroes() == 1)
|
if(!LOCPLINT->cb->howManyTowns() && LOCPLINT->cb->howManyHeroes() == 1)
|
||||||
noDismiss = true;
|
noDismiss = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user