From 7202f457719f03a3277ccc5246e46609d10dfe74 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 4 Apr 2019 17:18:49 +0300 Subject: [PATCH] Only allow resting in air when a bed is used --- apps/openmw/mwbase/world.hpp | 5 +++-- apps/openmw/mwgui/waitdialog.cpp | 20 ++++++++++++++++++-- apps/openmw/mwgui/waitdialog.hpp | 5 ++++- apps/openmw/mwworld/worldimp.cpp | 5 ++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index f5ca91dc6..1517d36a3 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -459,8 +459,9 @@ namespace MWBase { Rest_Allowed = 0, Rest_OnlyWaiting = 1, - Rest_PlayerIsUnderwater = 2, - Rest_EnemiesAreNearby = 3 + Rest_PlayerIsInAir = 2, + Rest_PlayerIsUnderwater = 3, + Rest_EnemiesAreNearby = 4 }; /// check if the player is allowed to rest diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 48384d4b5..eda4242fd 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -80,10 +80,17 @@ namespace MWGui mTimeAdvancer.eventInterrupted += MyGUI::newDelegate(this, &WaitDialog::onWaitingInterrupted); mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &WaitDialog::onWaitingFinished); } + + void WaitDialog::onReferenceUnavailable () + { + MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Rest); + resetReference(); + } void WaitDialog::setPtr(const MWWorld::Ptr &ptr) { - setCanRest(!ptr.isEmpty() || MWBase::Environment::get().getWorld ()->canRest () == MWBase::World::Rest_Allowed); + mPtr = ptr; + setCanRest(!mPtr.isEmpty() || MWBase::Environment::get().getWorld ()->canRest () == MWBase::World::Rest_Allowed); if (mUntilHealedButton->getVisible()) MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mUntilHealedButton); @@ -100,6 +107,7 @@ namespace MWGui { mSleeping = false; mTimeAdvancer.stop(); + resetReference(); } void WaitDialog::onOpen() @@ -129,7 +137,13 @@ namespace MWGui } else if (canRest == MWBase::World::Rest_PlayerIsUnderwater) { - // resting underwater or mid-air not allowed + // resting underwater not allowed + MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage1}"); + MWBase::Environment::get().getWindowManager()->popGuiMode (); + } + else if (mPtr.isEmpty() && canRest == MWBase::World::Rest_PlayerIsInAir) + { + // Resting in air is not allowed either, unless you're using a bed MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage1}"); MWBase::Environment::get().getWindowManager()->popGuiMode (); } @@ -289,6 +303,8 @@ namespace MWGui void WaitDialog::onFrame(float dt) { + checkReferenceAvailable(); + mTimeAdvancer.onFrame(dt); if (mFadeTimeRemaining <= 0) diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp index 2aecb002f..b54a9e254 100644 --- a/apps/openmw/mwgui/waitdialog.hpp +++ b/apps/openmw/mwgui/waitdialog.hpp @@ -4,6 +4,7 @@ #include "timeadvancer.hpp" #include "windowbase.hpp" +#include "referenceinterface.hpp" namespace MWGui { @@ -22,7 +23,7 @@ namespace MWGui MyGUI::TextBox* mProgressText; }; - class WaitDialog : public WindowBase + class WaitDialog : public WindowBase, public ReferenceInterface { public: WaitDialog(); @@ -63,6 +64,8 @@ namespace MWGui WaitDialogProgressBar mProgressBar; + virtual void onReferenceUnavailable(); + void onUntilHealedButtonClicked(MyGUI::Widget* sender); void onWaitButtonClicked(MyGUI::Widget* sender); void onCancelButtonClicked(MyGUI::Widget* sender); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7455bd28e..034e8c901 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2477,9 +2477,12 @@ namespace MWWorld if(mPlayer->enemiesNearby()) return Rest_EnemiesAreNearby; - if ((actor->getCollisionMode() && !mPhysics->isOnSolidGround(player)) || isUnderwater(currentCell, playerPos) || isWalkingOnWater(player)) + if (isUnderwater(currentCell, playerPos) || isWalkingOnWater(player)) return Rest_PlayerIsUnderwater; + if ((actor->getCollisionMode() && !mPhysics->isOnSolidGround(player)) || isFlying(player)) + return Rest_PlayerIsInAir; + if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) || player.getClass().getNpcStats(player).isWerewolf()) return Rest_OnlyWaiting;