forked from teamnwah/openmw-tes3coop
Move HUD implementation out of the header file
This commit is contained in:
parent
2a53afc2bf
commit
0695e8d8b2
2 changed files with 121 additions and 112 deletions
|
@ -10,3 +10,115 @@
|
||||||
|
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
|
|
||||||
|
|
||||||
|
HUD::HUD(int width, int height, bool fpsSwitch)
|
||||||
|
: Layout("openmw_hud_layout.xml")
|
||||||
|
{
|
||||||
|
setCoord(0,0, width, height);
|
||||||
|
|
||||||
|
// Energy bars
|
||||||
|
getWidget(health, "Health");
|
||||||
|
getWidget(magicka, "Magicka");
|
||||||
|
getWidget(stamina, "Stamina");
|
||||||
|
|
||||||
|
// Item and spell images and status bars
|
||||||
|
getWidget(weapImage, "WeapImage");
|
||||||
|
getWidget(weapStatus, "WeapStatus");
|
||||||
|
getWidget(spellImage, "SpellImage");
|
||||||
|
getWidget(spellStatus, "SpellStatus");
|
||||||
|
|
||||||
|
getWidget(effectBox, "EffectBox");
|
||||||
|
getWidget(effect1, "Effect1");
|
||||||
|
|
||||||
|
getWidget(minimap, "MiniMap");
|
||||||
|
getWidget(compass, "Compass");
|
||||||
|
|
||||||
|
getWidget(crosshair, "Crosshair");
|
||||||
|
|
||||||
|
getWidget(fpsbox, "FPSBox");
|
||||||
|
getWidget(fpscounter, "FPSCounter");
|
||||||
|
|
||||||
|
fpsbox->setVisible(fpsSwitch);
|
||||||
|
|
||||||
|
compass->setImageTexture("textures\\compass.dds");
|
||||||
|
crosshair->setImageTexture("textures\\target.dds");
|
||||||
|
|
||||||
|
// These are just demo values, you should replace these with
|
||||||
|
// real calls from outside the class later.
|
||||||
|
setWeapIcon("icons\\w\\tx_knife_iron.dds");
|
||||||
|
setWeapStatus(90, 100);
|
||||||
|
setSpellIcon("icons\\s\\b_tx_s_rstor_health.dds");
|
||||||
|
setSpellStatus(65, 100);
|
||||||
|
setEffect("icons\\s\\tx_s_chameleon.dds");
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setFPS(float fps)
|
||||||
|
{
|
||||||
|
fpscounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HUD::setStats(int h, int hmax, int m, int mmax, int s, int smax)
|
||||||
|
{
|
||||||
|
health->setProgressRange(hmax);
|
||||||
|
health->setProgressPosition(h);
|
||||||
|
magicka->setProgressRange(mmax);
|
||||||
|
magicka->setProgressPosition(m);
|
||||||
|
stamina->setProgressRange(smax);
|
||||||
|
stamina->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setWeapIcon(const char *str)
|
||||||
|
{
|
||||||
|
weapImage->setImageTexture(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setSpellIcon(const char *str)
|
||||||
|
{
|
||||||
|
spellImage->setImageTexture(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setWeapStatus(int s, int smax)
|
||||||
|
{
|
||||||
|
weapStatus->setProgressRange(smax);
|
||||||
|
weapStatus->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setSpellStatus(int s, int smax)
|
||||||
|
{
|
||||||
|
spellStatus->setProgressRange(smax);
|
||||||
|
spellStatus->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::setEffect(const char *img)
|
||||||
|
{
|
||||||
|
effect1->setImageTexture(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HUD::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,126 +36,23 @@ namespace MWGui
|
||||||
class HUD : public OEngine::GUI::Layout
|
class HUD : public OEngine::GUI::Layout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HUD(int width, int height, bool fpsSwitch)
|
HUD(int width, int height, bool fpsSwitch);
|
||||||
: Layout("openmw_hud_layout.xml")
|
void setStats(int h, int hmax, int m, int mmax, int s, int smax);
|
||||||
{
|
void setWeapIcon(const char *str);
|
||||||
setCoord(0,0, width, height);
|
void setSpellIcon(const char *str);
|
||||||
|
void setWeapStatus(int s, int smax);
|
||||||
// Energy bars
|
void setSpellStatus(int s, int smax);
|
||||||
getWidget(health, "Health");
|
void setEffect(const char *img);
|
||||||
getWidget(magicka, "Magicka");
|
void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value);
|
||||||
getWidget(stamina, "Stamina");
|
void setFPS(float fps);
|
||||||
|
|
||||||
// Item and spell images and status bars
|
|
||||||
getWidget(weapImage, "WeapImage");
|
|
||||||
getWidget(weapStatus, "WeapStatus");
|
|
||||||
getWidget(spellImage, "SpellImage");
|
|
||||||
getWidget(spellStatus, "SpellStatus");
|
|
||||||
|
|
||||||
getWidget(effectBox, "EffectBox");
|
|
||||||
getWidget(effect1, "Effect1");
|
|
||||||
|
|
||||||
getWidget(minimap, "MiniMap");
|
|
||||||
getWidget(compass, "Compass");
|
|
||||||
|
|
||||||
getWidget(crosshair, "Crosshair");
|
|
||||||
|
|
||||||
getWidget(fpsbox, "FPSBox");
|
|
||||||
getWidget(fpscounter, "FPSCounter");
|
|
||||||
|
|
||||||
fpsbox->setVisible(fpsSwitch);
|
|
||||||
|
|
||||||
compass->setImageTexture("textures\\compass.dds");
|
|
||||||
crosshair->setImageTexture("textures\\target.dds");
|
|
||||||
|
|
||||||
// These are just demo values, you should replace these with
|
|
||||||
// real calls from outside the class later.
|
|
||||||
setWeapIcon("icons\\w\\tx_knife_iron.dds");
|
|
||||||
setWeapStatus(90, 100);
|
|
||||||
setSpellIcon("icons\\s\\b_tx_s_rstor_health.dds");
|
|
||||||
setSpellStatus(65, 100);
|
|
||||||
setEffect("icons\\s\\tx_s_chameleon.dds");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFPS(float fps)
|
|
||||||
{
|
|
||||||
fpscounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setStats(int h, int hmax, int m, int mmax, int s, int smax)
|
|
||||||
{
|
|
||||||
health->setProgressRange(hmax);
|
|
||||||
health->setProgressPosition(h);
|
|
||||||
magicka->setProgressRange(mmax);
|
|
||||||
magicka->setProgressPosition(m);
|
|
||||||
stamina->setProgressRange(smax);
|
|
||||||
stamina->setProgressPosition(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setWeapIcon(const char *str)
|
|
||||||
{ weapImage->setImageTexture(str); }
|
|
||||||
void setSpellIcon(const char *str)
|
|
||||||
{ spellImage->setImageTexture(str); }
|
|
||||||
|
|
||||||
void setWeapStatus(int s, int smax)
|
|
||||||
{
|
|
||||||
weapStatus->setProgressRange(smax);
|
|
||||||
weapStatus->setProgressPosition(s);
|
|
||||||
}
|
|
||||||
void setSpellStatus(int s, int smax)
|
|
||||||
{
|
|
||||||
spellStatus->setProgressRange(smax);
|
|
||||||
spellStatus->setProgressPosition(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::ProgressPtr health, magicka, stamina;
|
||||||
|
|
||||||
MyGUI::StaticImagePtr weapImage, spellImage;
|
MyGUI::StaticImagePtr weapImage, spellImage;
|
||||||
MyGUI::ProgressPtr weapStatus, spellStatus;
|
MyGUI::ProgressPtr weapStatus, spellStatus;
|
||||||
|
|
||||||
MyGUI::WidgetPtr effectBox;
|
MyGUI::WidgetPtr effectBox;
|
||||||
MyGUI::StaticImagePtr effect1;
|
MyGUI::StaticImagePtr effect1;
|
||||||
|
|
||||||
MyGUI::StaticImagePtr minimap;
|
MyGUI::StaticImagePtr minimap;
|
||||||
MyGUI::StaticImagePtr compass;
|
MyGUI::StaticImagePtr compass;
|
||||||
|
|
||||||
MyGUI::StaticImagePtr crosshair;
|
MyGUI::StaticImagePtr crosshair;
|
||||||
|
|
||||||
MyGUI::WidgetPtr fpsbox;
|
MyGUI::WidgetPtr fpsbox;
|
||||||
|
|
Loading…
Reference in a new issue