forked from mirror/openmw-tes3mp
update attribute values in stats window
This commit is contained in:
parent
0383ad550a
commit
089a385686
7 changed files with 86 additions and 1 deletions
|
@ -205,6 +205,35 @@ namespace MWGui
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Set value for the given ID.
|
||||
void setValue (const std::string& id, const MWMechanics::Stat<int>& value)
|
||||
{
|
||||
static const char *ids[] =
|
||||
{
|
||||
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
|
||||
"AttribVal6", "AttribVal7", "AttribVal8",
|
||||
0
|
||||
};
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
std::ostringstream valueString;
|
||||
valueString << value.getModified();
|
||||
setText (id, valueString.str());
|
||||
|
||||
if (value.getModified()>value.getBase())
|
||||
setTextColor (id, 0, 1, 0);
|
||||
else if (value.getModified()<value.getBase())
|
||||
setTextColor (id, 1, 0, 0);
|
||||
else
|
||||
setTextColor (id, 1, 1, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -90,3 +90,8 @@ void WindowManager::setLabel (const std::string& id, const std::string& label)
|
|||
stats->setLabel (id, label);
|
||||
}
|
||||
|
||||
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
|
||||
{
|
||||
stats->setValue (id, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "../mwmechanics/stat.hpp"
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class Gui;
|
||||
|
@ -139,6 +141,9 @@ namespace MWGui
|
|||
|
||||
void setLabel (const std::string& id, const std::string& label);
|
||||
///< Set label text for the value with the given ID.
|
||||
|
||||
void setValue (const std::string& id, const MWMechanics::Stat<int>& value);
|
||||
///< Set value for the given ID.
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -63,9 +63,33 @@ namespace MWMechanics
|
|||
++iter;
|
||||
}
|
||||
|
||||
void MechanicsManager::watchActor (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
mWatched = ptr;
|
||||
}
|
||||
|
||||
void MechanicsManager::update()
|
||||
{
|
||||
if (!mWatched.isEmpty())
|
||||
{
|
||||
MWMechanics::CreatureStats& stats = mWatched.getCreatureStats();
|
||||
|
||||
static const char *attributeNames[8] =
|
||||
{
|
||||
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
|
||||
"AttribVal6", "AttribVal7", "AttribVal8"
|
||||
};
|
||||
|
||||
for (int i=0; i<8; ++i)
|
||||
{
|
||||
if (stats.mAttributes[i]!=mWatchedCreature.mAttributes[i])
|
||||
{
|
||||
mWatchedCreature.mAttributes[i] = stats.mAttributes[i];
|
||||
|
||||
mWindowManager.setValue (attributeNames[i], stats.mAttributes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
#include "creaturestats.hpp"
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
class ESMStore;
|
||||
|
@ -22,6 +24,8 @@ namespace MWMechanics
|
|||
const ESMS::ESMStore& mStore;
|
||||
MWGui::WindowManager& mWindowManager;
|
||||
std::set<MWWorld::Ptr> mActors;
|
||||
MWWorld::Ptr mWatched;
|
||||
CreatureStats mWatchedCreature;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -38,6 +42,10 @@ namespace MWMechanics
|
|||
void dropActors (const MWWorld::Ptr::CellStore *cellStore);
|
||||
///< Deregister all actors in the given cell.
|
||||
|
||||
void watchActor (const MWWorld::Ptr& ptr);
|
||||
///< On each update look for changes in a previously registered actor and update the
|
||||
/// GUI accordingly.
|
||||
|
||||
void update();
|
||||
///< Update actor stats
|
||||
};
|
||||
|
|
|
@ -65,6 +65,19 @@ namespace MWMechanics
|
|||
mModified += diff;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline bool operator== (const Stat<T>& left, const Stat<T>& right)
|
||||
{
|
||||
return left.getBase()==right.getBase() &&
|
||||
left.getModified()==right.getModified();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool operator!= (const Stat<T>& left, const Stat<T>& right)
|
||||
{
|
||||
return !(left==right);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -465,6 +465,7 @@ namespace MWWorld
|
|||
|
||||
// Actors
|
||||
mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer());
|
||||
mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer());
|
||||
|
||||
for (ESMS::CellRefList<ESM::Creature, RefData>::List::iterator iter (
|
||||
cell->creatures.list.begin());
|
||||
|
|
Loading…
Reference in a new issue