1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:19:56 +00:00
openmw-tes3mp/apps/openmw/mwgui/levelupdialog.cpp

329 lines
11 KiB
C++
Raw Normal View History

2012-09-14 17:44:00 +00:00
#include "levelupdialog.hpp"
2015-01-10 01:50:43 +00:00
#include <MyGUI_Button.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_EditBox.h>
2012-09-14 17:44:00 +00:00
2016-01-06 11:46:06 +00:00
#include <components/fallback/fallback.hpp>
2012-09-14 17:44:00 +00:00
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp"
2012-09-15 15:12:42 +00:00
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp"
2012-09-15 15:12:42 +00:00
#include "../mwworld/class.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/cellstore.hpp"
2012-09-15 15:12:42 +00:00
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
2015-08-21 09:12:39 +00:00
#include "../mwmechanics/actorutil.hpp"
2012-09-15 15:12:42 +00:00
#include "class.hpp"
2012-09-14 17:44:00 +00:00
namespace MWGui
{
const unsigned int LevelupDialog::sMaxCoins = 3;
LevelupDialog::LevelupDialog()
: WindowBase("openmw_levelup_dialog.layout"),
mCoinCount(sMaxCoins)
2012-09-14 17:44:00 +00:00
{
getWidget(mOkButton, "OkButton");
getWidget(mClassImage, "ClassImage");
getWidget(mLevelText, "LevelText");
getWidget(mLevelDescription, "LevelDescription");
getWidget(mCoinBox, "Coins");
2014-09-03 01:03:03 +00:00
getWidget(mAssignWidget, "AssignWidget");
2012-09-14 17:44:00 +00:00
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &LevelupDialog::onOkButtonClicked);
for (int i=1; i<9; ++i)
{
MyGUI::TextBox* t;
2015-01-10 01:50:43 +00:00
getWidget(t, "AttribVal" + MyGUI::utility::toString(i));
mAttributeValues.push_back(t);
2012-09-14 17:44:00 +00:00
MyGUI::Button* b;
2015-01-10 01:50:43 +00:00
getWidget(b, "Attrib" + MyGUI::utility::toString(i));
2012-09-14 17:44:00 +00:00
b->setUserData (i-1);
b->eventMouseButtonClick += MyGUI::newDelegate(this, &LevelupDialog::onAttributeClicked);
2012-09-15 15:12:42 +00:00
mAttributes.push_back(b);
2012-09-14 17:44:00 +00:00
2015-01-10 01:50:43 +00:00
getWidget(t, "AttribMultiplier" + MyGUI::utility::toString(i));
2012-09-14 17:44:00 +00:00
mAttributeMultipliers.push_back(t);
}
for (unsigned int i = 0; i < mCoinCount; ++i)
2012-09-15 15:12:42 +00:00
{
MyGUI::ImageBox* image = mCoinBox->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(0,0,16,16), MyGUI::Align::Default);
2012-09-15 15:12:42 +00:00
image->setImageTexture ("icons\\tx_goldicon.dds");
mCoins.push_back(image);
}
2012-09-14 17:44:00 +00:00
center();
2012-09-15 15:12:42 +00:00
}
void LevelupDialog::setAttributeValues()
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWMechanics::CreatureStats& creatureStats = player.getClass().getCreatureStats(player);
MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player);
2012-09-15 15:12:42 +00:00
for (int i = 0; i < 8; ++i)
2012-09-15 15:12:42 +00:00
{
int val = creatureStats.getAttribute(i).getBase();
2012-09-15 15:12:42 +00:00
if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), i) != mSpentAttributes.end())
{
val += pcStats.getLevelupAttributeMultiplier(i);
2012-09-15 15:12:42 +00:00
}
if (val >= 100)
val = 100;
2015-01-10 01:50:43 +00:00
mAttributeValues[i]->setCaption(MyGUI::utility::toString(val));
2012-09-15 15:12:42 +00:00
}
}
void LevelupDialog::resetCoins()
2012-09-15 15:12:42 +00:00
{
2017-05-01 16:48:39 +00:00
const int coinSpacing = 33;
int curX = mCoinBox->getWidth()/2 - (coinSpacing*(mCoinCount - 1) + 16*mCoinCount)/2;
for (unsigned int i=0; i<sMaxCoins; ++i)
2012-09-15 15:12:42 +00:00
{
MyGUI::ImageBox* image = mCoins[i];
image->detachFromWidget();
image->attachToWidget(mCoinBox);
if (i < mCoinCount)
{
mCoins[i]->setVisible(true);
image->setCoord(MyGUI::IntCoord(curX,0,16,16));
curX += 16+coinSpacing;
}
else
mCoins[i]->setVisible(false);
2012-09-15 15:12:42 +00:00
}
}
void LevelupDialog::assignCoins()
2012-09-15 15:12:42 +00:00
{
resetCoins();
for (unsigned int i=0; i<mSpentAttributes.size(); ++i)
{
MyGUI::ImageBox* image = mCoins[i];
image->detachFromWidget();
2014-09-03 01:03:03 +00:00
image->attachToWidget(mAssignWidget);
2012-09-15 15:12:42 +00:00
int attribute = mSpentAttributes[i];
int xdiff = mAttributeMultipliers[attribute]->getCaption() == "" ? 0 : 20;
2012-09-15 15:12:42 +00:00
2014-09-03 01:03:03 +00:00
MyGUI::IntPoint pos = mAttributes[attribute]->getAbsolutePosition() - mAssignWidget->getAbsolutePosition() - MyGUI::IntPoint(22+xdiff,0);
pos.top += (mAttributes[attribute]->getHeight() - image->getHeight())/2;
2012-09-15 15:12:42 +00:00
image->setPosition(pos);
}
2012-09-14 17:44:00 +00:00
2012-09-15 15:12:42 +00:00
setAttributeValues();
2012-09-14 17:44:00 +00:00
}
void LevelupDialog::onOpen()
2012-09-14 17:44:00 +00:00
{
2012-11-08 12:37:57 +00:00
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr();
MWMechanics::CreatureStats& creatureStats = player.getClass().getCreatureStats(player);
MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats(player);
2012-09-15 15:12:42 +00:00
setClassImage(mClassImage, getLevelupClassImage(pcStats.getSkillIncreasesForSpecialization(0),
pcStats.getSkillIncreasesForSpecialization(1),
pcStats.getSkillIncreasesForSpecialization(2)));
2012-09-15 15:12:42 +00:00
int level = creatureStats.getLevel ()+1;
2015-01-10 01:50:43 +00:00
mLevelText->setCaptionWithReplacing("#{sLevelUpMenu1} " + MyGUI::utility::toString(level));
2012-09-15 15:12:42 +00:00
std::string levelupdescription;
levelupdescription = Fallback::Map::getString("Level_Up_Level"+MyGUI::utility::toString(level));
if (levelupdescription == "")
levelupdescription = Fallback::Map::getString("Level_Up_Default");
mLevelDescription->setCaption (levelupdescription);
unsigned int availableAttributes = 0;
for (int i = 0; i < 8; ++i)
2012-09-15 15:12:42 +00:00
{
MyGUI::TextBox* text = mAttributeMultipliers[i];
if (pcStats.getAttribute(i).getBase() < 100)
{
mAttributes[i]->setEnabled(true);
2015-02-05 00:15:42 +00:00
mAttributeValues[i]->setEnabled(true);
availableAttributes++;
float mult = pcStats.getLevelupAttributeMultiplier (i);
mult = std::min(mult, 100-pcStats.getAttribute(i).getBase());
2015-01-10 01:50:43 +00:00
text->setCaption(mult <= 1 ? "" : "x" + MyGUI::utility::toString(mult));
}
else
{
mAttributes[i]->setEnabled(false);
2015-02-05 00:15:42 +00:00
mAttributeValues[i]->setEnabled(false);
text->setCaption("");
}
}
mCoinCount = std::min(sMaxCoins, availableAttributes);
mSpentAttributes.clear();
resetCoins();
setAttributeValues();
center();
// Play LevelUp Music
MWBase::Environment::get().getSoundManager()->streamMusic("Special/MW_Triumph.mp3");
2012-09-14 17:44:00 +00:00
}
void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender)
2012-09-14 17:44:00 +00:00
{
2015-08-21 09:12:39 +00:00
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player);
2012-09-15 15:12:42 +00:00
if (mSpentAttributes.size() < mCoinCount)
MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage36}");
2012-09-15 15:12:42 +00:00
else
{
// increase attributes
for (unsigned int i = 0; i < mCoinCount; ++i)
2012-09-15 15:12:42 +00:00
{
MWMechanics::AttributeValue attribute = pcStats.getAttribute(mSpentAttributes[i]);
attribute.setBase(attribute.getBase() + pcStats.getLevelupAttributeMultiplier(mSpentAttributes[i]));
2012-09-15 15:12:42 +00:00
if (attribute.getBase() >= 100)
attribute.setBase(100);
pcStats.setAttribute(mSpentAttributes[i], attribute);
2012-09-15 15:12:42 +00:00
}
pcStats.levelUp();
2012-09-15 15:12:42 +00:00
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Levelup);
2012-09-15 15:12:42 +00:00
}
2012-09-14 17:44:00 +00:00
}
void LevelupDialog::onAttributeClicked(MyGUI::Widget *sender)
2012-09-14 17:44:00 +00:00
{
2012-09-15 15:12:42 +00:00
int attribute = *sender->getUserData<int>();
std::vector<int>::iterator found = std::find(mSpentAttributes.begin(), mSpentAttributes.end(), attribute);
if (found != mSpentAttributes.end())
mSpentAttributes.erase(found);
2012-09-15 15:12:42 +00:00
else
{
if (mSpentAttributes.size() == mCoinCount)
mSpentAttributes[mCoinCount - 1] = attribute;
2012-09-15 15:12:42 +00:00
else
mSpentAttributes.push_back(attribute);
}
assignCoins();
2012-09-14 17:44:00 +00:00
}
std::string LevelupDialog::getLevelupClassImage(const int combatIncreases, const int magicIncreases, const int stealthIncreases)
{
std::string ret = "acrobat";
int total = combatIncreases + magicIncreases + stealthIncreases;
if (total == 0)
return ret;
int combatFraction = static_cast<int>(static_cast<float>(combatIncreases) / total * 10.f);
int magicFraction = static_cast<int>(static_cast<float>(magicIncreases) / total * 10.f);
int stealthFraction = static_cast<int>(static_cast<float>(stealthIncreases) / total * 10.f);
if (combatFraction > 7)
ret = "warrior";
else if (magicFraction > 7)
ret = "mage";
else if (stealthFraction > 7)
ret = "thief";
switch (combatFraction)
{
case 7:
ret = "warrior";
break;
case 6:
if (stealthFraction == 1)
ret = "barbarian";
else if (stealthFraction == 3)
ret = "crusader";
else
ret = "knight";
break;
case 5:
if (stealthFraction == 3)
ret = "scout";
else
ret = "archer";
break;
case 4:
ret = "rogue";
break;
default:
break;
}
switch (magicFraction)
{
case 7:
ret = "mage";
break;
case 6:
if (combatFraction == 2)
ret = "sorcerer";
else if (combatIncreases == 3)
ret = "healer";
else
ret = "battlemage";
break;
case 5:
ret = "witchhunter";
break;
case 4:
ret = "spellsword";
// In vanilla there's also code for "nightblade", however it seems to be unreachable.
break;
default:
break;
}
switch (stealthFraction)
{
case 7:
ret = "thief";
break;
case 6:
if (magicFraction == 1)
ret = "agent";
else if (magicIncreases == 3)
ret = "assassin";
else
ret = "acrobat";
break;
case 5:
if (magicIncreases == 3)
ret = "monk";
else
ret = "pilgrim";
break;
case 3:
2016-06-26 13:17:52 +00:00
if (magicFraction == 3)
ret = "bard";
break;
default:
break;
}
return ret;
}
2012-09-14 17:44:00 +00:00
}