Add training progress bar, implement jail screen, tweak wait dialog (Fixes #1714)
parent
6c4920c58e
commit
1d9e973573
@ -0,0 +1,136 @@
|
||||
#include <MyGUI_RenderManager.h>
|
||||
#include <MyGUI_ScrollBar.h>
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_TextBox.h>
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
#include "../mwworld/store.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "jailscreen.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
JailScreen::JailScreen()
|
||||
: WindowBase("openmw_loading_screen.layout"),
|
||||
mTimeAdvancer(0.0125),
|
||||
mDays(1),
|
||||
mFadeTimeRemaining(0)
|
||||
{
|
||||
getWidget(mLoadingText, "LoadingText");
|
||||
getWidget(mProgressBar, "ProgressBar");
|
||||
getWidget(mLoadingBox, "LoadingBox");
|
||||
|
||||
setVisible(false);
|
||||
|
||||
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &JailScreen::onJailProgressChanged);
|
||||
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &JailScreen::onJailFinished);
|
||||
|
||||
mLoadingText->setCaptionWithReplacing("#{sInPrisonTitle}");
|
||||
|
||||
center();
|
||||
}
|
||||
|
||||
void JailScreen::goToJail(int days)
|
||||
{
|
||||
mDays = days;
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
|
||||
mFadeTimeRemaining = 0.5;
|
||||
|
||||
setVisible(false);
|
||||
mProgressBar->setScrollRange(days*24+1);
|
||||
mProgressBar->setScrollPosition(0);
|
||||
mProgressBar->setTrackSize(0);
|
||||
}
|
||||
|
||||
void JailScreen::onFrame(float dt)
|
||||
{
|
||||
mTimeAdvancer.onFrame(dt);
|
||||
|
||||
if (mFadeTimeRemaining <= 0)
|
||||
return;
|
||||
|
||||
mFadeTimeRemaining -= dt;
|
||||
|
||||
if (mFadeTimeRemaining <= 0)
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker");
|
||||
|
||||
setVisible(true);
|
||||
mTimeAdvancer.run(mDays*24);
|
||||
}
|
||||
}
|
||||
|
||||
void JailScreen::onJailProgressChanged(int cur, int /*total*/)
|
||||
{
|
||||
mProgressBar->setScrollPosition(0);
|
||||
mProgressBar->setTrackSize(cur / (float)(mProgressBar->getScrollRange()) * mProgressBar->getLineSize());
|
||||
}
|
||||
|
||||
void JailScreen::onJailFinished()
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->popGuiMode();
|
||||
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
|
||||
MWBase::Environment::get().getWorld()->advanceTime(mDays * 24);
|
||||
for (int i=0; i<mDays*24; ++i)
|
||||
MWBase::Environment::get().getMechanicsManager()->rest(true);
|
||||
|
||||
std::set<int> skills;
|
||||
for (int day=0; day<mDays; ++day)
|
||||
{
|
||||
int skill = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * ESM::Skill::Length;
|
||||
skills.insert(skill);
|
||||
|
||||
MWMechanics::SkillValue& value = player.getClass().getNpcStats(player).getSkill(skill);
|
||||
if (skill == ESM::Skill::Security || skill == ESM::Skill::Sneak)
|
||||
value.setBase(std::min(100, value.getBase()+1));
|
||||
else
|
||||
value.setBase(value.getBase()-1);
|
||||
}
|
||||
|
||||
const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||
|
||||
std::string message;
|
||||
if (mDays == 1)
|
||||
message = gmst.find("sNotifyMessage42")->getString();
|
||||
else
|
||||
message = gmst.find("sNotifyMessage43")->getString();
|
||||
|
||||
std::stringstream dayStr;
|
||||
dayStr << mDays;
|
||||
if (message.find("%d") != std::string::npos)
|
||||
message.replace(message.find("%d"), 2, dayStr.str());
|
||||
|
||||
for (std::set<int>::iterator it = skills.begin(); it != skills.end(); ++it)
|
||||
{
|
||||
std::string skillName = gmst.find(ESM::Skill::sSkillNameIds[*it])->getString();
|
||||
std::stringstream skillValue;
|
||||
skillValue << player.getClass().getNpcStats(player).getSkill(*it).getBase();
|
||||
std::string skillMsg = gmst.find("sNotifyMessage44")->getString();
|
||||
if (*it == ESM::Skill::Sneak || *it == ESM::Skill::Security)
|
||||
skillMsg = gmst.find("sNotifyMessage39")->getString();
|
||||
|
||||
if (skillMsg.find("%s") != std::string::npos)
|
||||
skillMsg.replace(skillMsg.find("%s"), 2, skillName);
|
||||
if (skillMsg.find("%d") != std::string::npos)
|
||||
skillMsg.replace(skillMsg.find("%d"), 2, skillValue.str());
|
||||
message += "\n" + skillMsg;
|
||||
}
|
||||
|
||||
std::vector<std::string> buttons;
|
||||
buttons.push_back("#{sOk}");
|
||||
MWBase::Environment::get().getWindowManager()->interactiveMessageBox(message, buttons);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef MWGUI_JAILSCREEN_H
|
||||
#define MWGUI_JAILSCREEN_H
|
||||
|
||||
#include "windowbase.hpp"
|
||||
#include "timeadvancer.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class JailScreen : public WindowBase
|
||||
{
|
||||
public:
|
||||
JailScreen();
|
||||
void goToJail(int days);
|
||||
|
||||
void onFrame(float dt);
|
||||
|
||||
private:
|
||||
int mDays;
|
||||
|
||||
float mFadeTimeRemaining;
|
||||
|
||||
MyGUI::Widget* mLoadingBox;
|
||||
MyGUI::TextBox* mLoadingText;
|
||||
MyGUI::ScrollBar* mProgressBar;
|
||||
|
||||
void onJailProgressChanged(int cur, int total);
|
||||
void onJailFinished();
|
||||
|
||||
TimeAdvancer mTimeAdvancer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,73 @@
|
||||
#include "timeadvancer.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
TimeAdvancer::TimeAdvancer(float delay)
|
||||
: mRunning(false),
|
||||
mCurHour(0),
|
||||
mHours(1),
|
||||
mInterruptAt(-1),
|
||||
mDelay(delay),
|
||||
mRemainingTime(delay)
|
||||
{
|
||||
}
|
||||
|
||||
void TimeAdvancer::run(int hours, int interruptAt)
|
||||
{
|
||||
mHours = hours;
|
||||
mCurHour = 0;
|
||||
mInterruptAt = interruptAt;
|
||||
mRemainingTime = mDelay;
|
||||
|
||||
mRunning = true;
|
||||
}
|
||||
|
||||
void TimeAdvancer::stop()
|
||||
{
|
||||
mRunning = false;
|
||||
}
|
||||
|
||||
void TimeAdvancer::onFrame(float dt)
|
||||
{
|
||||
if (!mRunning)
|
||||
return;
|
||||
|
||||
if (mCurHour == mInterruptAt)
|
||||
{
|
||||
stop();
|
||||
eventInterrupted();
|
||||
return;
|
||||
}
|
||||
|
||||
mRemainingTime -= dt;
|
||||
|
||||
while (mRemainingTime <= 0)
|
||||
{
|
||||
mRemainingTime += mDelay;
|
||||
++mCurHour;
|
||||
|
||||
if (mCurHour <= mHours)
|
||||
eventProgressChanged(mCurHour, mHours);
|
||||
else
|
||||
{
|
||||
stop();
|
||||
eventFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int TimeAdvancer::getHours()
|
||||
{
|
||||
return mHours;
|
||||
}
|
||||
|
||||
bool TimeAdvancer::isRunning()
|
||||
{
|
||||
return mRunning;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#ifndef MWGUI_TIMEADVANCER_H
|
||||
#define MWGUI_TIMEADVANCER_H
|
||||
|
||||
#include <MyGUI_Widget.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class TimeAdvancer
|
||||
{
|
||||
public:
|
||||
TimeAdvancer(float delay);
|
||||
|
||||
void run(int hours, int interruptAt=-1);
|
||||
void stop();
|
||||
void onFrame(float dt);
|
||||
|
||||
int getHours();
|
||||
bool isRunning();
|
||||
|
||||
// signals
|
||||
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
|
||||
typedef MyGUI::delegates::CMultiDelegate2<int, int> EventHandle_IntInt;
|
||||
|
||||
EventHandle_IntInt eventProgressChanged;
|
||||
EventHandle_Void eventInterrupted;
|
||||
EventHandle_Void eventFinished;
|
||||
|
||||
private:
|
||||
bool mRunning;
|
||||
|
||||
int mCurHour;
|
||||
int mHours;
|
||||
int mInterruptAt;
|
||||
|
||||
float mDelay;
|
||||
float mRemainingTime;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue