2015-02-07 03:05:28 +00:00
|
|
|
#include <MyGUI_ScrollBar.h>
|
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
#include <components/misc/rng.hpp>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2015-02-07 03:05:28 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2015-02-07 03:05:28 +00:00
|
|
|
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
#include "../mwworld/store.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
|
|
|
#include "jailscreen.hpp"
|
|
|
|
|
|
|
|
namespace MWGui
|
|
|
|
{
|
|
|
|
JailScreen::JailScreen()
|
2015-02-07 17:38:41 +00:00
|
|
|
: WindowBase("openmw_jail_screen.layout"),
|
2015-02-07 03:05:28 +00:00
|
|
|
mDays(1),
|
2015-05-01 00:24:27 +00:00
|
|
|
mFadeTimeRemaining(0),
|
|
|
|
mTimeAdvancer(0.01f)
|
2015-02-07 03:05:28 +00:00
|
|
|
{
|
|
|
|
getWidget(mProgressBar, "ProgressBar");
|
|
|
|
|
|
|
|
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &JailScreen::onJailProgressChanged);
|
|
|
|
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &JailScreen::onJailFinished);
|
|
|
|
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JailScreen::goToJail(int days)
|
|
|
|
{
|
|
|
|
mDays = days;
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
|
|
|
|
mFadeTimeRemaining = 0.5;
|
|
|
|
|
|
|
|
setVisible(false);
|
2015-02-22 23:23:09 +00:00
|
|
|
mProgressBar->setScrollRange(100+1);
|
2015-02-07 03:05:28 +00:00
|
|
|
mProgressBar->setScrollPosition(0);
|
|
|
|
mProgressBar->setTrackSize(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JailScreen::onFrame(float dt)
|
|
|
|
{
|
|
|
|
mTimeAdvancer.onFrame(dt);
|
|
|
|
|
|
|
|
if (mFadeTimeRemaining <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mFadeTimeRemaining -= dt;
|
|
|
|
|
|
|
|
if (mFadeTimeRemaining <= 0)
|
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2015-02-07 03:05:28 +00:00
|
|
|
MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker");
|
2017-10-14 14:02:20 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.f); // override fade-in caused by cell transition
|
2015-02-07 03:05:28 +00:00
|
|
|
|
|
|
|
setVisible(true);
|
2015-02-22 23:23:09 +00:00
|
|
|
mTimeAdvancer.run(100);
|
2015-02-07 03:05:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JailScreen::onJailProgressChanged(int cur, int /*total*/)
|
|
|
|
{
|
|
|
|
mProgressBar->setScrollPosition(0);
|
2015-03-08 00:07:29 +00:00
|
|
|
mProgressBar->setTrackSize(static_cast<int>(cur / (float)(mProgressBar->getScrollRange()) * mProgressBar->getLineSize()));
|
2015-02-07 03:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JailScreen::onJailFinished()
|
|
|
|
{
|
2015-02-07 17:38:41 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Jail);
|
2015-02-07 03:05:28 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2015-02-07 03:05:28 +00:00
|
|
|
|
2019-01-25 16:04:35 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->rest(mDays * 24, true);
|
2016-07-05 22:20:23 +00:00
|
|
|
MWBase::Environment::get().getWorld()->advanceTime(mDays * 24);
|
2015-02-07 03:05:28 +00:00
|
|
|
|
2019-09-30 16:27:42 +00:00
|
|
|
// We should not worsen corprus when in prison
|
|
|
|
for (auto& spell : player.getClass().getCreatureStats(player).getCorprusSpells())
|
|
|
|
{
|
|
|
|
spell.second.mNextWorsening += mDays * 24;
|
|
|
|
}
|
|
|
|
|
2015-02-07 03:05:28 +00:00
|
|
|
std::set<int> skills;
|
|
|
|
for (int day=0; day<mDays; ++day)
|
|
|
|
{
|
2015-04-22 15:58:55 +00:00
|
|
|
int skill = Misc::Rng::rollDice(ESM::Skill::Length);
|
2015-02-07 03:05:28 +00:00
|
|
|
skills.insert(skill);
|
|
|
|
|
|
|
|
MWMechanics::SkillValue& value = player.getClass().getNpcStats(player).getSkill(skill);
|
|
|
|
if (skill == ESM::Skill::Security || skill == ESM::Skill::Sneak)
|
2018-12-23 11:18:33 +00:00
|
|
|
value.setBase(std::min(100.f, value.getBase()+1));
|
2015-02-07 03:05:28 +00:00
|
|
|
else
|
2018-12-23 11:18:33 +00:00
|
|
|
value.setBase(std::max(0.f, value.getBase()-1));
|
2015-02-07 03:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
|
|
|
|
|
|
std::string message;
|
|
|
|
if (mDays == 1)
|
2018-08-29 15:38:12 +00:00
|
|
|
message = gmst.find("sNotifyMessage42")->mValue.getString();
|
2015-02-07 03:05:28 +00:00
|
|
|
else
|
2018-08-29 15:38:12 +00:00
|
|
|
message = gmst.find("sNotifyMessage43")->mValue.getString();
|
2015-02-07 03:05:28 +00:00
|
|
|
|
2019-05-19 08:33:57 +00:00
|
|
|
message = Misc::StringUtils::format(message, mDays);
|
2015-02-07 03:05:28 +00:00
|
|
|
|
2019-03-02 09:27:59 +00:00
|
|
|
for (const int& skill : skills)
|
2015-02-07 03:05:28 +00:00
|
|
|
{
|
2019-03-02 09:27:59 +00:00
|
|
|
std::string skillName = gmst.find(ESM::Skill::sSkillNameIds[skill])->mValue.getString();
|
|
|
|
int skillValue = player.getClass().getNpcStats(player).getSkill(skill).getBase();
|
2018-08-29 15:38:12 +00:00
|
|
|
std::string skillMsg = gmst.find("sNotifyMessage44")->mValue.getString();
|
2019-03-02 09:27:59 +00:00
|
|
|
if (skill == ESM::Skill::Sneak || skill == ESM::Skill::Security)
|
2018-08-29 15:38:12 +00:00
|
|
|
skillMsg = gmst.find("sNotifyMessage39")->mValue.getString();
|
2015-02-07 03:05:28 +00:00
|
|
|
|
2019-05-19 08:33:57 +00:00
|
|
|
skillMsg = Misc::StringUtils::format(skillMsg, skillName, skillValue);
|
2015-02-07 03:05:28 +00:00
|
|
|
message += "\n" + skillMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> buttons;
|
2020-10-17 08:26:35 +00:00
|
|
|
buttons.emplace_back("#{sOk}");
|
2015-02-07 03:05:28 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->interactiveMessageBox(message, buttons);
|
|
|
|
}
|
|
|
|
}
|