added GUI update for health, magicka and fatigue

pull/7/head
Marc Zinnschlag 15 years ago
parent 455bcf3b01
commit 3b6b343c9b

@ -89,6 +89,40 @@ namespace MWGui
void setEffect(const char *img)
{ effect1->setImageTexture(img); }
void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
{
static const char *ids[] =
{
"HBar", "MBar", "FBar",
0
};
for (int i=0; ids[i]; ++i)
if (ids[i]==id)
{
switch (i)
{
case 0:
health->setProgressRange (value.getModified());
health->setProgressPosition (value.getCurrent());
break;
case 1:
magicka->setProgressRange (value.getModified());
magicka->setProgressPosition (value.getCurrent());
break;
case 2:
stamina->setProgressRange (value.getModified());
stamina->setProgressPosition (value.getCurrent());
break;
}
}
}
MyGUI::ProgressPtr health, magicka, stamina;
MyGUI::StaticImagePtr weapImage, spellImage;
@ -136,7 +170,7 @@ namespace MWGui
class StatsWindow : public OEngine::GUI::Layout
{
public:
void setBar(const char* name, const char* tname, int val, int max)
void setBar(const std::string& name, const std::string& tname, int val, int max)
{
MyGUI::ProgressPtr pt;
getWidget(pt, name);
@ -169,10 +203,6 @@ namespace MWGui
setText("RaceText", "Wood Elf");
setText("ClassText", "Pilgrim");
setBar("HBar", "HBarT", 60, 100);
setBar("MBar", "MBarT", 30, 100);
setBar("FBar", "FBarT", 80, 100);
setText("AttribVal1", "30");
setText("AttribVal2", "40");
setText("AttribVal3", "30");
@ -187,7 +217,7 @@ namespace MWGui
{
mMainWidget->setCaption(playerName);
}
/// Set label text for the value with the given ID.
void setLabel (const std::string& id, const std::string& label)
{
@ -197,7 +227,7 @@ namespace MWGui
"Attrib7", "Attrib8",
0
};
for (int i=0; ids[i]; ++i)
if (ids[i]==id)
{
@ -205,7 +235,7 @@ namespace MWGui
break;
}
}
/// Set value for the given ID.
void setValue (const std::string& id, const MWMechanics::Stat<int>& value)
{
@ -214,7 +244,7 @@ namespace MWGui
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
"AttribVal6", "AttribVal7", "AttribVal8",
0
};
};
for (int i=0; ids[i]; ++i)
if (ids[i]==id)
@ -222,18 +252,33 @@ namespace MWGui
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;
}
}
}
void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
{
static const char *ids[] =
{
"HBar", "MBar", "FBar",
0
};
for (int i=0; ids[i]; ++i)
if (ids[i]==id)
{
std::string id (ids[i]);
setBar (id, id + "T", value.getCurrent(), value.getModified());
}
}
};
}
#endif

@ -95,3 +95,8 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int
stats->setValue (id, value);
}
void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
{
stats->setValue (id, value);
hud->setValue (id, value);
}

@ -113,7 +113,7 @@ namespace MWGui
{
if (newMode==GM_Inventory && allowed==GW_None)
return;
mode = newMode;
updateVisible();
}
@ -138,12 +138,15 @@ namespace MWGui
}
MyGUI::Gui* getGui() const { return gui; }
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.
void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value);
///< Set value for the given ID.
};
}
#endif

@ -6,12 +6,12 @@
#include "../mwgui/window_manager.hpp"
namespace MWMechanics
{
{
MechanicsManager::MechanicsManager (const ESMS::ESMStore& store,
MWGui::WindowManager& windowManager)
: mStore (store), mWindowManager (windowManager)
{
}
void MechanicsManager::configureGUI()
@ -28,32 +28,32 @@ namespace MWMechanics
{ "Attrib8", "sAttributeLuck" },
{ 0, 0 }
};
for (int i=0; names[i][0]; ++i)
{
// This crashes because of encoding problems:
// This crashes because of encoding problems:
// std::string label = mStore.gameSettings.find (names[i][1])->str;
std::string label = names[i][1]; // until the problem is fixed, use the GMST ID as label
mWindowManager.setLabel (names[i][0], label);
}
}
void MechanicsManager::addActor (const MWWorld::Ptr& ptr)
{
mActors.insert (ptr);
}
void MechanicsManager::removeActor (const MWWorld::Ptr& ptr)
{
mActors.erase (ptr);
}
void MechanicsManager::dropActors (const MWWorld::Ptr::CellStore *cellStore)
{
std::set<MWWorld::Ptr>::iterator iter = mActors.begin();
while (iter!=mActors.end())
if (iter->getCell()==cellStore)
{
@ -62,24 +62,29 @@ namespace MWMechanics
else
++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"
};
static const char *dynamicNames[3] =
{
"HBar", "MBar", "FBar"
};
for (int i=0; i<8; ++i)
{
if (stats.mAttributes[i]!=mWatchedCreature.mAttributes[i])
@ -89,7 +94,16 @@ namespace MWMechanics
mWindowManager.setValue (attributeNames[i], stats.mAttributes[i]);
}
}
for (int i=0; i<3; ++i)
{
if (stats.mDynamic[i]!=mWatchedCreature.mDynamic[i])
{
mWatchedCreature.mDynamic[i] = stats.mDynamic[i];
mWindowManager.setValue (dynamicNames[i], stats.mDynamic[i]);
}
}
}
}
}

@ -87,6 +87,8 @@ namespace MWMechanics
public:
DynamicStat() : mCurrent (0) {}
const T& getBase() const
{
return mStatic.getBase();

Loading…
Cancel
Save