2012-09-18 16:29:03 +00:00
|
|
|
#include "waitdialog.hpp"
|
|
|
|
|
2012-09-18 18:53:32 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
#include <libs/openengine/ogre/fader.hpp>
|
|
|
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
2012-09-21 15:53:16 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-09-18 18:53:32 +00:00
|
|
|
|
|
|
|
#include "../mwworld/timestamp.hpp"
|
2012-09-19 00:53:06 +00:00
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-09-18 18:53:32 +00:00
|
|
|
|
|
|
|
#include "widgets.hpp"
|
|
|
|
|
|
|
|
|
2012-09-18 16:29:03 +00:00
|
|
|
namespace MWGui
|
|
|
|
{
|
|
|
|
|
2012-09-19 00:53:06 +00:00
|
|
|
WaitDialogProgressBar::WaitDialogProgressBar(MWBase::WindowManager &parWindowManager)
|
|
|
|
: WindowBase("openmw_wait_dialog_progressbar.layout", parWindowManager)
|
|
|
|
{
|
|
|
|
getWidget(mProgressBar, "ProgressBar");
|
|
|
|
getWidget(mProgressText, "ProgressText");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialogProgressBar::open()
|
|
|
|
{
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialogProgressBar::setProgress (int cur, int total)
|
|
|
|
{
|
|
|
|
mProgressBar->setProgressRange (total);
|
|
|
|
mProgressBar->setProgressPosition (cur);
|
|
|
|
mProgressText->setCaption(boost::lexical_cast<std::string>(cur) + "/" + boost::lexical_cast<std::string>(total));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
2012-09-18 16:29:03 +00:00
|
|
|
WaitDialog::WaitDialog(MWBase::WindowManager &parWindowManager)
|
|
|
|
: WindowBase("openmw_wait_dialog.layout", parWindowManager)
|
2012-09-19 00:53:06 +00:00
|
|
|
, mProgressBar(parWindowManager)
|
|
|
|
, mWaiting(false)
|
|
|
|
, mSleeping(false)
|
|
|
|
, mHours(1)
|
|
|
|
, mRemainingTime(0.05)
|
2012-09-18 16:29:03 +00:00
|
|
|
{
|
2012-09-18 18:53:32 +00:00
|
|
|
getWidget(mDateTimeText, "DateTimeText");
|
|
|
|
getWidget(mRestText, "RestText");
|
|
|
|
getWidget(mHourText, "HourText");
|
|
|
|
getWidget(mHourSlider, "HourSlider");
|
|
|
|
getWidget(mUntilHealedButton, "UntilHealedButton");
|
|
|
|
getWidget(mWaitButton, "WaitButton");
|
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onCancelButtonClicked);
|
|
|
|
mUntilHealedButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onUntilHealedButtonClicked);
|
|
|
|
mWaitButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onWaitButtonClicked);
|
|
|
|
|
|
|
|
mHourSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &WaitDialog::onHourSliderChangedPosition);
|
2012-09-19 00:53:06 +00:00
|
|
|
|
|
|
|
mProgressBar.setVisible (false);
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::open()
|
|
|
|
{
|
2012-09-19 00:53:06 +00:00
|
|
|
if (!MWBase::Environment::get().getWindowManager ()->getRestEnabled ())
|
|
|
|
{
|
|
|
|
mWindowManager.popGuiMode ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int canRest = MWBase::Environment::get().getWorld ()->canRest ();
|
|
|
|
|
|
|
|
if (canRest == 2)
|
|
|
|
{
|
|
|
|
// resting underwater or mid-air not allowed
|
|
|
|
mWindowManager.messageBox ("#{sNotifyMessage1}", std::vector<std::string>());
|
|
|
|
mWindowManager.popGuiMode ();
|
|
|
|
}
|
|
|
|
|
|
|
|
setCanRest(canRest == 0);
|
2012-09-18 18:53:32 +00:00
|
|
|
|
|
|
|
onHourSliderChangedPosition(mHourSlider, 0);
|
|
|
|
mHourSlider->setScrollPosition (0);
|
|
|
|
|
|
|
|
// http://www.uesp.net/wiki/Lore:Calendar
|
|
|
|
std::string month;
|
|
|
|
int m = MWBase::Environment::get().getWorld ()->getMonth ();
|
|
|
|
if (m == 0)
|
|
|
|
month = "#{sMonthMorningstar}";
|
|
|
|
else if (m == 1)
|
|
|
|
month = "#{sMonthSunsdawn}";
|
|
|
|
else if (m == 2)
|
|
|
|
month = "#{sMonthFirstseed}";
|
|
|
|
else if (m == 3)
|
|
|
|
month = "#{sMonthRainshand}";
|
|
|
|
else if (m == 4)
|
|
|
|
month = "#{sMonthSecondseed}";
|
|
|
|
else if (m == 5)
|
|
|
|
month = "#{sMonthMidyear}";
|
|
|
|
else if (m == 6)
|
|
|
|
month = "#{sMonthSunsheight}";
|
|
|
|
else if (m == 7)
|
|
|
|
month = "#{sMonthLastseed}";
|
|
|
|
else if (m == 8)
|
|
|
|
month = "#{sMonthHeartfire}";
|
|
|
|
else if (m == 9)
|
|
|
|
month = "#{sMonthFrostfall}";
|
|
|
|
else if (m == 10)
|
|
|
|
month = "#{sMonthSunsdusk}";
|
|
|
|
else if (m == 11)
|
|
|
|
month = "#{sMonthEveningstar}";
|
|
|
|
|
|
|
|
int hour = MWBase::Environment::get().getWorld ()->getTimeStamp ().getHour ();
|
|
|
|
bool pm = hour >= 12;
|
|
|
|
if (hour >= 13) hour -= 12;
|
2012-11-06 18:19:35 +00:00
|
|
|
if (hour == 0) hour = 12;
|
2012-09-18 18:53:32 +00:00
|
|
|
|
|
|
|
std::string dateTimeText =
|
2012-11-05 17:01:50 +00:00
|
|
|
boost::lexical_cast<std::string>(MWBase::Environment::get().getWorld ()->getDay ()) + " "
|
2012-09-18 18:53:32 +00:00
|
|
|
+ month + " (#{sDay} " + boost::lexical_cast<std::string>(MWBase::Environment::get().getWorld ()->getTimeStamp ().getDay ()+1)
|
|
|
|
+ ") " + boost::lexical_cast<std::string>(hour) + " " + (pm ? "#{sSaveMenuHelp05}" : "#{sSaveMenuHelp04}");
|
|
|
|
|
|
|
|
mDateTimeText->setCaptionWithReplacing (dateTimeText);
|
2012-09-18 16:29:03 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 18:53:32 +00:00
|
|
|
void WaitDialog::onUntilHealedButtonClicked(MyGUI::Widget* sender)
|
|
|
|
{
|
2012-09-19 00:53:06 +00:00
|
|
|
startWaiting();
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::onWaitButtonClicked(MyGUI::Widget* sender)
|
|
|
|
{
|
2012-09-19 00:53:06 +00:00
|
|
|
startWaiting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::startWaiting ()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.2);
|
|
|
|
setVisible(false);
|
|
|
|
mProgressBar.setVisible (true);
|
|
|
|
mWaiting = true;
|
|
|
|
mCurHour = 0;
|
|
|
|
mRemainingTime = 0.05;
|
|
|
|
mProgressBar.setProgress (0, mHours);
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::onCancelButtonClicked(MyGUI::Widget* sender)
|
|
|
|
{
|
2012-09-19 00:53:06 +00:00
|
|
|
mWindowManager.popGuiMode ();
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position)
|
|
|
|
{
|
|
|
|
mHourText->setCaptionWithReplacing (boost::lexical_cast<std::string>(position+1) + " #{sRestMenu2}");
|
2012-09-19 00:53:06 +00:00
|
|
|
mHours = position+1;
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::setCanRest (bool canRest)
|
|
|
|
{
|
|
|
|
mUntilHealedButton->setVisible(canRest);
|
|
|
|
mWaitButton->setCaptionWithReplacing (canRest ? "#{sRest}" : "#{sWait}");
|
|
|
|
mRestText->setCaptionWithReplacing (canRest ? "#{sRestMenu3}" : "#{sRestIllegal}");
|
2012-09-19 00:53:06 +00:00
|
|
|
|
|
|
|
mSleeping = canRest;
|
|
|
|
|
|
|
|
dynamic_cast<Widgets::Box*>(mMainWidget)->notifyChildrenSizeChanged();
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::onFrame(float dt)
|
|
|
|
{
|
|
|
|
if (!mWaiting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mRemainingTime -= dt;
|
|
|
|
|
|
|
|
if (mRemainingTime < 0)
|
|
|
|
{
|
|
|
|
mRemainingTime = 0.05;
|
|
|
|
++mCurHour;
|
|
|
|
mProgressBar.setProgress (mCurHour, mHours);
|
|
|
|
|
|
|
|
if (mCurHour <= mHours)
|
2012-09-21 15:53:16 +00:00
|
|
|
{
|
2012-09-19 00:53:06 +00:00
|
|
|
MWBase::Environment::get().getWorld ()->advanceTime (1);
|
2012-09-21 15:53:16 +00:00
|
|
|
if (mSleeping)
|
|
|
|
MWBase::Environment::get().getMechanicsManager ()->restoreDynamicStats ();
|
|
|
|
}
|
2012-09-19 00:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurHour > mHours)
|
|
|
|
stopWaiting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitDialog::stopWaiting ()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.2);
|
|
|
|
mProgressBar.setVisible (false);
|
2012-09-29 07:41:34 +00:00
|
|
|
mWindowManager.removeGuiMode (GM_Rest);
|
2012-12-03 04:32:12 +00:00
|
|
|
mWindowManager.removeGuiMode (GM_RestBed);
|
2012-09-19 00:53:06 +00:00
|
|
|
mWaiting = false;
|
|
|
|
|
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
|
|
|
MWMechanics::NpcStats pcstats = MWWorld::Class::get(player).getNpcStats(player);
|
|
|
|
|
|
|
|
// trigger levelup if possible
|
|
|
|
if (mSleeping && pcstats.getLevelProgress () >= 10)
|
|
|
|
{
|
|
|
|
mWindowManager.pushGuiMode (GM_Levelup);
|
|
|
|
}
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
|
|
|
|
2012-09-29 07:41:34 +00:00
|
|
|
void WaitDialog::wakeUp ()
|
|
|
|
{
|
|
|
|
mSleeping = false;
|
|
|
|
mWaiting = false;
|
|
|
|
stopWaiting();
|
|
|
|
}
|
|
|
|
|
2012-09-18 16:29:03 +00:00
|
|
|
}
|