2010-09-17 23:30:23 +00:00
|
|
|
#include "layouts.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
2011-02-21 19:36:35 +00:00
|
|
|
#include "window_manager.hpp"
|
2010-09-17 23:30:23 +00:00
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
#include <cmath>
|
2010-09-18 17:26:45 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
2010-09-17 23:30:23 +00:00
|
|
|
|
2011-02-19 18:18:03 +00:00
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2010-09-17 23:30:23 +00:00
|
|
|
using namespace MWGui;
|
|
|
|
|
2010-09-17 23:44:40 +00:00
|
|
|
|
2012-01-16 15:33:21 +00:00
|
|
|
HUD::HUD(int width, int height, int fpsLevel)
|
2011-01-02 16:24:57 +00:00
|
|
|
: Layout("openmw_hud_layout.xml")
|
2012-03-25 19:56:22 +00:00
|
|
|
, health(NULL)
|
|
|
|
, magicka(NULL)
|
|
|
|
, stamina(NULL)
|
|
|
|
, weapImage(NULL)
|
|
|
|
, spellImage(NULL)
|
|
|
|
, weapStatus(NULL)
|
|
|
|
, spellStatus(NULL)
|
|
|
|
, effectBox(NULL)
|
|
|
|
, effect1(NULL)
|
|
|
|
, minimap(NULL)
|
|
|
|
, compass(NULL)
|
|
|
|
, crosshair(NULL)
|
|
|
|
, fpsbox(NULL)
|
|
|
|
, fpscounter(NULL)
|
|
|
|
, trianglecounter(NULL)
|
|
|
|
, batchcounter(NULL)
|
2010-09-18 19:24:05 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
setCoord(0,0, width, height);
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
// Energy bars
|
|
|
|
getWidget(health, "Health");
|
|
|
|
getWidget(magicka, "Magicka");
|
|
|
|
getWidget(stamina, "Stamina");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
// Item and spell images and status bars
|
|
|
|
getWidget(weapImage, "WeapImage");
|
|
|
|
getWidget(weapStatus, "WeapStatus");
|
|
|
|
getWidget(spellImage, "SpellImage");
|
|
|
|
getWidget(spellStatus, "SpellStatus");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
getWidget(effectBox, "EffectBox");
|
|
|
|
getWidget(effect1, "Effect1");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
getWidget(minimap, "MiniMap");
|
|
|
|
getWidget(compass, "Compass");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
getWidget(crosshair, "Crosshair");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2012-01-16 15:33:21 +00:00
|
|
|
if ( fpsLevel == 2 ){
|
2012-01-17 11:58:06 +00:00
|
|
|
getWidget(fpsbox, "FPSBoxAdv");
|
|
|
|
fpsbox->setVisible(true);
|
2012-01-16 15:33:21 +00:00
|
|
|
getWidget(fpscounter, "FPSCounterAdv");
|
|
|
|
}else if ( fpsLevel == 1 ){
|
2012-01-17 11:58:06 +00:00
|
|
|
getWidget(fpsbox, "FPSBox");
|
|
|
|
fpsbox->setVisible(true);
|
2012-01-16 15:33:21 +00:00
|
|
|
getWidget(fpscounter, "FPSCounter");
|
|
|
|
}else{
|
|
|
|
getWidget(fpscounter, "FPSCounter");
|
|
|
|
}
|
|
|
|
getWidget(trianglecounter, "TriangleCounter");
|
|
|
|
getWidget(batchcounter, "BatchCounter");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
compass->setImageTexture("textures\\compass.dds");
|
|
|
|
crosshair->setImageTexture("textures\\target.dds");
|
2010-09-18 19:24:05 +00:00
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
// 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");
|
2012-03-23 15:51:56 +00:00
|
|
|
|
|
|
|
LocalMapBase::init(minimap, this);
|
2010-09-18 19:24:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setFPS(float fps)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
fpscounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 15:33:21 +00:00
|
|
|
void HUD::setTriangleCount(size_t count)
|
|
|
|
{
|
|
|
|
trianglecounter->setCaption(boost::lexical_cast<std::string>(count));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HUD::setBatchCount(size_t count)
|
|
|
|
{
|
|
|
|
batchcounter->setCaption(boost::lexical_cast<std::string>(count));
|
|
|
|
}
|
2011-01-02 16:24:57 +00:00
|
|
|
|
|
|
|
void HUD::setStats(int h, int hmax, int m, int mmax, int s, int smax)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
health->setProgressRange(hmax);
|
|
|
|
health->setProgressPosition(h);
|
|
|
|
magicka->setProgressRange(mmax);
|
|
|
|
magicka->setProgressPosition(m);
|
|
|
|
stamina->setProgressRange(smax);
|
|
|
|
stamina->setProgressPosition(s);
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setWeapIcon(const char *str)
|
2010-09-18 16:04:53 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
weapImage->setImageTexture(str);
|
2010-09-18 16:04:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setSpellIcon(const char *str)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
spellImage->setImageTexture(str);
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setWeapStatus(int s, int smax)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
weapStatus->setProgressRange(smax);
|
|
|
|
weapStatus->setProgressPosition(s);
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setSpellStatus(int s, int smax)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
spellStatus->setProgressRange(smax);
|
|
|
|
spellStatus->setProgressPosition(s);
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setEffect(const char *img)
|
2010-09-18 19:34:49 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
effect1->setImageTexture(img);
|
2010-09-18 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 16:24:57 +00:00
|
|
|
void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<int>& value)
|
2010-09-18 16:04:53 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
static const char *ids[] =
|
2010-09-18 16:04:53 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
"HBar", "MBar", "FBar", 0
|
2010-09-18 16:04:53 +00:00
|
|
|
};
|
2011-01-02 16:24:57 +00:00
|
|
|
|
|
|
|
for (int i=0; ids[i]; ++i)
|
|
|
|
if (ids[i]==id)
|
2010-09-18 16:04:53 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
switch (i)
|
2010-09-18 16:04:53 +00:00
|
|
|
{
|
2011-01-02 16:24:57 +00:00
|
|
|
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;
|
2010-09-18 16:04:53 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-17 23:30:23 +00:00
|
|
|
}
|
2012-03-23 14:26:24 +00:00
|
|
|
|
|
|
|
void HUD::setPlayerDir(const float x, const float y)
|
|
|
|
{
|
|
|
|
MyGUI::ISubWidget* main = compass->getSubWidgetMain();
|
|
|
|
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
|
|
|
|
rotatingSubskin->setCenter(MyGUI::IntPoint(16,16));
|
|
|
|
float angle = std::atan2(x,y);
|
|
|
|
rotatingSubskin->setAngle(angle);
|
|
|
|
}
|
|
|
|
|
2012-03-23 15:51:56 +00:00
|
|
|
void HUD::setPlayerPos(const float x, const float y)
|
|
|
|
{
|
|
|
|
MyGUI::IntSize size = minimap->getCanvasSize();
|
|
|
|
MyGUI::IntPoint middle = MyGUI::IntPoint((1/3.f + x/3.f)*size.width,(1/3.f + y/3.f)*size.height);
|
|
|
|
MyGUI::IntCoord viewsize = minimap->getCoord();
|
|
|
|
MyGUI::IntPoint pos(0.5*viewsize.width - middle.left, 0.5*viewsize.height - middle.top);
|
|
|
|
|
|
|
|
minimap->setViewOffset(pos);
|
|
|
|
compass->setPosition(MyGUI::IntPoint(x*512-16, y*512-16));
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:07:25 +00:00
|
|
|
LocalMapBase::LocalMapBase()
|
|
|
|
: mCurX(0)
|
|
|
|
, mCurY(0)
|
|
|
|
, mInterior(false)
|
|
|
|
, mLocalMap(NULL)
|
|
|
|
, mPrefix()
|
2012-03-28 19:36:38 +00:00
|
|
|
, mChanged(true)
|
2012-03-27 21:07:25 +00:00
|
|
|
, mLayout(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-23 15:16:31 +00:00
|
|
|
void LocalMapBase::init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout)
|
|
|
|
{
|
|
|
|
mLocalMap = widget;
|
|
|
|
mLayout = layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalMapBase::setCellPrefix(const std::string& prefix)
|
|
|
|
{
|
|
|
|
mPrefix = prefix;
|
2012-03-23 16:37:56 +00:00
|
|
|
mChanged = true;
|
2012-03-23 15:16:31 +00:00
|
|
|
}
|
2012-03-23 14:34:54 +00:00
|
|
|
|
2012-03-23 15:16:31 +00:00
|
|
|
void LocalMapBase::setActiveCell(const int x, const int y, bool interior)
|
|
|
|
{
|
2012-03-23 16:37:56 +00:00
|
|
|
if (x==mCurX && y==mCurY && mInterior==interior && !mChanged) return; // don't do anything if we're still in the same cell
|
2012-03-23 15:16:31 +00:00
|
|
|
for (int mx=0; mx<3; ++mx)
|
|
|
|
{
|
|
|
|
for (int my=0; my<3; ++my)
|
|
|
|
{
|
|
|
|
std::string name = "Map_" + boost::lexical_cast<std::string>(mx) + "_"
|
|
|
|
+ boost::lexical_cast<std::string>(my);
|
|
|
|
|
|
|
|
std::string image = mPrefix+"_"+ boost::lexical_cast<std::string>(x + (mx-1)) + "_"
|
|
|
|
+ boost::lexical_cast<std::string>(y + (interior ? (my-1) : -1*(my-1)));
|
|
|
|
|
|
|
|
MyGUI::ImageBox* box;
|
|
|
|
mLayout->getWidget(box, name);
|
|
|
|
MyGUI::ImageBox* fog;
|
|
|
|
mLayout->getWidget(fog, name+"_fog");
|
|
|
|
|
|
|
|
if (MyGUI::RenderManager::getInstance().getTexture(image) != 0)
|
|
|
|
box->setImageTexture(image);
|
|
|
|
else
|
|
|
|
box->setImageTexture("black.png");
|
|
|
|
|
|
|
|
if (MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0)
|
|
|
|
fog->setImageTexture(image+"_fog");
|
|
|
|
else
|
|
|
|
fog->setImageTexture("black.png");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mInterior = interior;
|
|
|
|
mCurX = x;
|
|
|
|
mCurY = y;
|
2012-03-23 16:37:56 +00:00
|
|
|
mChanged = false;
|
2012-03-23 15:16:31 +00:00
|
|
|
}
|
2012-03-23 14:34:54 +00:00
|
|
|
|