1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-23 00:09:42 +00:00

vanilla style messagebox 2

This commit is contained in:
kuyondo 2021-11-26 05:20:58 +08:00
parent a231037449
commit 1f2311538d
7 changed files with 34 additions and 8 deletions

View file

@ -69,6 +69,7 @@ namespace MWGui
class DialogueWindow;
class WindowModal;
class JailScreen;
class MessageBox;
enum ShowInDialogueMode {
ShowInDialogueMode_IfPossible,
@ -145,6 +146,7 @@ namespace MWBase
virtual MWGui::CountDialog* getCountDialog() = 0;
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
virtual MWGui::TradeWindow* getTradeWindow() = 0;
virtual std::vector<MWGui::MessageBox*> getActiveMessageBoxes() = 0;
/// Make the player use an item, while updating GUI state accordingly
virtual void useItem(const MWWorld::Ptr& item, bool force=false) = 0;

View file

@ -161,6 +161,12 @@ namespace MWGui
return false;
}
std::vector<MessageBox*> MessageBoxManager::getActiveMessageBoxes()
{
return mMessageBoxes;
}
int MessageBoxManager::readPressedButton (bool reset)
{
int pressed = mLastButtonPressed;
@ -202,6 +208,11 @@ namespace MWGui
mMainWidget->setPosition(pos);
}
std::string MessageBox::getMessage()
{
return mMessage;
}
int MessageBox::getHeight ()
{
return mMainWidget->getHeight()+mNextBoxPadding;

View file

@ -49,6 +49,8 @@ namespace MWGui
void setVisible(bool value);
std::vector<MessageBox*> getActiveMessageBoxes();
private:
std::vector<MessageBox*> mMessageBoxes;
InteractiveMessageBox* mInterMessageBoxe;
@ -63,6 +65,7 @@ namespace MWGui
public:
MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message);
void setMessage (const std::string& message);
std::string getMessage();
int getHeight ();
void update (int height);
void setVisible(bool value);
@ -72,7 +75,7 @@ namespace MWGui
protected:
MessageBoxManager& mMessageBoxManager;
const std::string& mMessage;
const std::string mMessage;
MyGUI::EditBox* mMessageWidget;
int mBottomPadding;
int mNextBoxPadding;

View file

@ -771,6 +771,11 @@ namespace MWGui
mMessageBoxManager->removeStaticMessageBox();
}
std::vector<MWGui::MessageBox*> WindowManager::getActiveMessageBoxes()
{
return mMessageBoxManager->getActiveMessageBoxes();
}
int WindowManager::readPressedButton ()
{
return mMessageBoxManager->readPressedButton();

View file

@ -187,6 +187,7 @@ namespace MWGui
MWGui::CountDialog* getCountDialog() override;
MWGui::ConfirmationDialog* getConfirmationDialog() override;
MWGui::TradeWindow* getTradeWindow() override;
std::vector<MWGui::MessageBox*> getActiveMessageBoxes() override;
/// Make the player use an item, while updating GUI state accordingly
void useItem(const MWWorld::Ptr& item, bool bypassBeastRestrictions=false) override;

View file

@ -22,6 +22,8 @@
#include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwgui/messagebox.hpp"
#include "actions.hpp"
#include "bindingsmanager.hpp"
@ -39,7 +41,6 @@ namespace MWInput
, mAlwaysRunActive(Settings::Manager::getBool("always run", "Input"))
, mSneaking(false)
, mAttemptJump(false)
, mOverencumberedMessageDelay(0.f)
, mTimeIdle(0.f)
{
}
@ -88,22 +89,26 @@ namespace MWInput
{
player.setUpDown(1);
triedToMove = true;
mOverencumberedMessageDelay = 0.f;
}
// if player tried to start moving, but can't (due to being overencumbered), display a notification.
if (triedToMove)
{
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld ()->getPlayerPtr();
mOverencumberedMessageDelay -= dt;
if (playerPtr.getClass().getEncumbrance(playerPtr) > playerPtr.getClass().getCapacity(playerPtr))
{
player.setAutoMove (false);
if (mOverencumberedMessageDelay <= 0)
std::vector<MWGui::MessageBox*> msgboxs = MWBase::Environment::get().getWindowManager()->getActiveMessageBoxes();
std::vector<MWGui::MessageBox*>::iterator it = std::find_if(msgboxs.begin(), msgboxs.end(), [](MWGui::MessageBox*& msg)
{
return (msg->getMessage() == "#{sNotifyMessage59}");
});
// if an overencumbered messagebox is already present, reset its expiry timer, otherwise create new one.
if (it != msgboxs.end())
(*it)->mCurrentTime = 0;
else
MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage59}");
mOverencumberedMessageDelay = 1.0;
}
}
}

View file

@ -67,7 +67,6 @@ namespace MWInput
bool mSneaking;
bool mAttemptJump;
float mOverencumberedMessageDelay;
float mTimeIdle;
};
}