update attribute values in stats window

pull/7/head
Marc Zinnschlag 15 years ago
parent 335425bb12
commit 63f686ffab

@ -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::update()
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…
Cancel
Save