1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:19:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/hud.cpp

694 lines
24 KiB
C++
Raw Normal View History

#include "hud.hpp"
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
2016-10-23 10:30:32 +00:00
#include "../mwmp/Main.hpp"
2016-12-16 08:59:15 +00:00
#include "../mwmp/Networking.hpp"
#include "../mwmp/WorldEvent.hpp"
#include "../mwmp/LocalPlayer.hpp"
2016-10-23 10:30:32 +00:00
#include "../mwworld/cellstore.hpp"
/*
End of tes3mp addition
*/
2016-10-23 10:30:32 +00:00
2015-01-10 01:50:43 +00:00
#include <MyGUI_RenderManager.h>
#include <MyGUI_ProgressBar.h>
#include <MyGUI_Button.h>
#include <MyGUI_InputManager.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_ScrollView.h>
2015-01-31 22:27:34 +00:00
#include <components/settings/settings.hpp>
#include <components/openmw-mp/Log.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
2013-05-11 16:38:27 +00:00
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
2013-07-30 04:00:20 +00:00
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
2015-08-21 09:12:39 +00:00
#include "../mwmechanics/actorutil.hpp"
2013-07-30 04:00:20 +00:00
#include "inventorywindow.hpp"
2013-03-03 11:01:19 +00:00
#include "spellicons.hpp"
2013-05-11 16:38:27 +00:00
#include "itemmodel.hpp"
#include "draganddrop.hpp"
#include "itemmodel.hpp"
#include "itemwidget.hpp"
2013-04-17 22:56:48 +00:00
namespace MWGui
{
/**
* Makes it possible to use ItemModel::moveItem to move an item from an inventory to the world.
*/
class WorldItemModel : public ItemModel
{
public:
WorldItemModel(float left, float top) : mLeft(left), mTop(top) {}
virtual ~WorldItemModel() {}
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
{
MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Ptr dropped;
if (world->canPlaceObject(mLeft, mTop))
dropped = world->placeObject(item.mBase, mLeft, mTop, count);
else
dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count);
if (setNewOwner)
dropped.getCellRef().setOwner("");
/*
Start of tes3mp addition
Send an ID_OBJECT_PLACE packet every time an object is dropped into the world from
the inventory screen
*/
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectPlace(dropped);
/*
End of tes3mp addition
*/
2016-10-23 10:30:32 +00:00
/*
Start of tes3mp change (major)
Instead of actually keeping this object as is, delete it after sending the packet
and wait for the server to send it back with the correct mpNum
*/
MWBase::Environment::get().getWorld()->deleteObject(dropped);
/*
End of tes3mp change (major)
*/
return dropped;
}
virtual void removeItem (const ItemStack& item, size_t count) { throw std::runtime_error("removeItem not implemented"); }
virtual ModelIndex getIndex (ItemStack item) { throw std::runtime_error("getIndex not implemented"); }
virtual void update() {}
virtual size_t getItemCount() { return 0; }
virtual ItemStack getItem (ModelIndex index) { throw std::runtime_error("getItem not implemented"); }
private:
// Where to drop the item
float mLeft;
float mTop;
};
2015-11-06 23:13:13 +00:00
HUD::HUD(CustomMarkerCollection &customMarkers, DragAndDrop* dragAndDrop, MWRender::LocalMap* localMapRender)
2013-04-17 22:56:48 +00:00
: Layout("openmw_hud.layout")
, LocalMapBase(customMarkers, localMapRender, Settings::Manager::getBool("local map hud fog of war", "Map"))
2013-04-17 22:56:48 +00:00
, mHealth(NULL)
, mMagicka(NULL)
, mStamina(NULL)
, mDrowning(NULL)
2013-04-17 22:56:48 +00:00
, mWeapImage(NULL)
, mSpellImage(NULL)
, mWeapStatus(NULL)
, mSpellStatus(NULL)
, mEffectBox(NULL)
, mMinimap(NULL)
, mCompass(NULL)
, mCrosshair(NULL)
2015-04-25 18:37:42 +00:00
, mCellNameBox(NULL)
, mDrowningFrame(NULL)
, mDrowningFlash(NULL)
2013-04-17 22:56:48 +00:00
, mHealthManaStaminaBaseLeft(0)
, mWeapBoxBaseLeft(0)
, mSpellBoxBaseLeft(0)
, mMinimapBoxBaseRight(0)
2015-04-25 18:37:42 +00:00
, mEffectBoxBaseRight(0)
2013-04-17 22:56:48 +00:00
, mDragAndDrop(dragAndDrop)
, mCellNameTimer(0.0f)
2015-04-25 18:37:42 +00:00
, mWeaponSpellTimer(0.f)
2013-04-17 22:56:48 +00:00
, mMapVisible(true)
, mWeaponVisible(true)
, mSpellVisible(true)
, mWorldMouseOver(false)
, mEnemyActorId(-1)
2015-04-25 18:37:42 +00:00
, mEnemyHealthTimer(-1)
2013-10-27 08:05:01 +00:00
, mIsDrowning(false)
, mDrowningFlashTheta(0.f)
2013-04-17 22:56:48 +00:00
{
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
2013-04-17 22:56:48 +00:00
// Energy bars
getWidget(mHealthFrame, "HealthFrame");
getWidget(mHealth, "Health");
getWidget(mMagicka, "Magicka");
getWidget(mStamina, "Stamina");
2013-07-30 04:00:20 +00:00
getWidget(mEnemyHealth, "EnemyHealth");
2013-04-17 22:56:48 +00:00
mHealthManaStaminaBaseLeft = mHealthFrame->getLeft();
2012-05-29 13:36:48 +00:00
2013-04-17 22:56:48 +00:00
MyGUI::Widget *healthFrame, *magickaFrame, *fatigueFrame;
getWidget(healthFrame, "HealthFrame");
getWidget(magickaFrame, "MagickaFrame");
getWidget(fatigueFrame, "FatigueFrame");
healthFrame->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onHMSClicked);
magickaFrame->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onHMSClicked);
fatigueFrame->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onHMSClicked);
//Drowning bar
getWidget(mDrowningFrame, "DrowningFrame");
getWidget(mDrowning, "Drowning");
2013-10-27 08:05:01 +00:00
getWidget(mDrowningFlash, "Flash");
mDrowning->setProgressRange(200);
2013-04-17 22:56:48 +00:00
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
2013-04-17 22:56:48 +00:00
// Item and spell images and status bars
getWidget(mWeapBox, "WeapBox");
getWidget(mWeapImage, "WeapImage");
getWidget(mWeapStatus, "WeapStatus");
mWeapBoxBaseLeft = mWeapBox->getLeft();
mWeapBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWeaponClicked);
2013-04-17 22:56:48 +00:00
getWidget(mSpellBox, "SpellBox");
getWidget(mSpellImage, "SpellImage");
getWidget(mSpellStatus, "SpellStatus");
mSpellBoxBaseLeft = mSpellBox->getLeft();
mSpellBox->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMagicClicked);
getWidget(mSneakBox, "SneakBox");
mSneakBoxBaseLeft = mSneakBox->getLeft();
2013-04-17 22:56:48 +00:00
getWidget(mEffectBox, "EffectBox");
mEffectBoxBaseRight = viewSize.width - mEffectBox->getRight();
2013-04-17 22:56:48 +00:00
getWidget(mMinimapBox, "MiniMapBox");
mMinimapBoxBaseRight = viewSize.width - mMinimapBox->getRight();
getWidget(mMinimap, "MiniMap");
getWidget(mCompass, "Compass");
getWidget(mMinimapButton, "MiniMapButton");
mMinimapButton->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMapClicked);
2013-04-17 22:56:48 +00:00
getWidget(mCellNameBox, "CellName");
getWidget(mWeaponSpellBox, "WeaponSpellName");
2012-04-13 11:17:50 +00:00
2013-04-17 22:56:48 +00:00
getWidget(mCrosshair, "Crosshair");
LocalMapBase::init(mMinimap, mCompass, Settings::Manager::getInt("local map hud widget size", "Map"), Settings::Manager::getInt("local map cell distance", "Map"));
2013-03-03 11:01:19 +00:00
2013-04-17 22:56:48 +00:00
mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked);
mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver);
mMainWidget->eventMouseLostFocus += MyGUI::newDelegate(this, &HUD::onWorldMouseLostFocus);
2013-04-17 22:56:48 +00:00
mSpellIcons = new SpellIcons();
}
2012-04-13 11:17:50 +00:00
2013-04-17 22:56:48 +00:00
HUD::~HUD()
2012-04-13 11:17:50 +00:00
{
2015-01-31 15:26:15 +00:00
mMainWidget->eventMouseLostFocus.clear();
mMainWidget->eventMouseMove.clear();
mMainWidget->eventMouseButtonClick.clear();
2013-04-17 22:56:48 +00:00
delete mSpellIcons;
2012-04-13 11:17:50 +00:00
}
2013-04-17 22:56:48 +00:00
void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<float>& value)
{
int current = std::max(0, static_cast<int>(value.getCurrent()));
int modified = static_cast<int>(value.getModified());
MyGUI::Widget* w;
std::string valStr = MyGUI::utility::toString(current) + "/" + MyGUI::utility::toString(modified);
if (id == "HBar")
{
mHealth->setProgressRange(modified);
mHealth->setProgressPosition(current);
getWidget(w, "HealthFrame");
w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr);
}
else if (id == "MBar")
{
mMagicka->setProgressRange (modified);
mMagicka->setProgressPosition (current);
getWidget(w, "MagickaFrame");
2015-11-21 01:05:27 +00:00
w->setUserString("Caption_HealthDescription", "#{sMagDesc}\n" + valStr);
}
else if (id == "FBar")
{
mStamina->setProgressRange (modified);
mStamina->setProgressPosition (current);
getWidget(w, "FatigueFrame");
w->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr);
}
2013-04-17 22:56:48 +00:00
}
2012-08-12 23:26:15 +00:00
void HUD::setDrowningTimeLeft(float time, float maxTime)
{
size_t progress = static_cast<size_t>(time / maxTime * 200);
2013-10-27 08:05:01 +00:00
mDrowning->setProgressPosition(progress);
bool isDrowning = (progress == 0);
if (isDrowning && !mIsDrowning) // Just started drowning
mDrowningFlashTheta = 0.0f; // Start out on bright red every time.
mDrowningFlash->setVisible(isDrowning);
mIsDrowning = isDrowning;
}
void HUD::setDrowningBarVisible(bool visible)
{
mDrowningFrame->setVisible(visible);
}
2013-04-17 22:56:48 +00:00
void HUD::onWorldClicked(MyGUI::Widget* _sender)
{
2013-04-17 22:56:48 +00:00
if (!MWBase::Environment::get().getWindowManager ()->isGuiMode ())
return;
2013-04-17 22:56:48 +00:00
if (mDragAndDrop->mIsOnDragAndDrop)
{
// drop item into the gameworld
MWBase::Environment::get().getWorld()->breakInvisibility(
2015-08-21 09:12:39 +00:00
MWMechanics::getPlayer());
2013-04-17 22:56:48 +00:00
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
float mouseX = cursorPosition.left / float(viewSize.width);
float mouseY = cursorPosition.top / float(viewSize.height);
2012-05-15 21:28:04 +00:00
WorldItemModel drop (mouseX, mouseY);
mDragAndDrop->drop(&drop, NULL);
2012-05-14 15:41:17 +00:00
/*
Start of tes3mp addition
Send an ID_PLAYER_INVENTORY packet every time a player loses an item
by dropping it in the world
*/
mwmp::Main::get().getLocalPlayer()->sendInventory();
/*
End of tes3mp addition
*/
2013-04-17 22:56:48 +00:00
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
}
else
{
GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();
2013-04-17 22:56:48 +00:00
if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
return;
2013-04-17 22:56:48 +00:00
MWWorld::Ptr object = MWBase::Environment::get().getWorld()->getFacedObject();
if (mode == GM_Console)
2015-03-11 19:04:25 +00:00
MWBase::Environment::get().getWindowManager()->setConsoleSelectedObject(object);
2013-04-17 22:56:48 +00:00
else if ((mode == GM_Container) || (mode == GM_Inventory))
{
// pick up object
if (!object.isEmpty())
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->pickUpObject(object);
2013-04-17 22:56:48 +00:00
}
}
}
2013-04-17 22:56:48 +00:00
void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y)
{
2013-04-17 22:56:48 +00:00
if (mDragAndDrop->mIsOnDragAndDrop)
{
mWorldMouseOver = false;
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
float mouseX = cursorPosition.left / float(viewSize.width);
float mouseY = cursorPosition.top / float(viewSize.height);
2013-04-17 22:56:48 +00:00
MWBase::World* world = MWBase::Environment::get().getWorld();
2013-04-17 22:56:48 +00:00
// if we can't drop the object at the wanted position, show the "drop on ground" cursor.
bool canDrop = world->canPlaceObject(mouseX, mouseY);
2013-04-17 22:56:48 +00:00
if (!canDrop)
MWBase::Environment::get().getWindowManager()->changePointer("drop_ground");
else
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
2013-04-17 22:56:48 +00:00
}
else
2013-04-17 22:56:48 +00:00
{
2013-03-07 11:46:26 +00:00
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
2013-04-17 22:56:48 +00:00
mWorldMouseOver = true;
}
}
2013-04-17 22:56:48 +00:00
void HUD::onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new)
{
2013-03-07 11:46:26 +00:00
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
2013-04-17 22:56:48 +00:00
mWorldMouseOver = false;
}
2013-04-17 22:56:48 +00:00
void HUD::onHMSClicked(MyGUI::Widget* _sender)
{
MWBase::Environment::get().getWindowManager()->toggleVisible(GW_Stats);
}
2013-04-17 22:56:48 +00:00
void HUD::onMapClicked(MyGUI::Widget* _sender)
{
MWBase::Environment::get().getWindowManager()->toggleVisible(GW_Map);
}
2013-04-17 22:56:48 +00:00
void HUD::onWeaponClicked(MyGUI::Widget* _sender)
{
2015-08-21 09:12:39 +00:00
const MWWorld::Ptr& player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf())
{
MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}");
return;
}
2013-04-17 22:56:48 +00:00
MWBase::Environment::get().getWindowManager()->toggleVisible(GW_Inventory);
}
2013-04-17 22:56:48 +00:00
void HUD::onMagicClicked(MyGUI::Widget* _sender)
{
2015-08-21 09:12:39 +00:00
const MWWorld::Ptr& player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf())
{
MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}");
return;
}
2013-04-17 22:56:48 +00:00
MWBase::Environment::get().getWindowManager()->toggleVisible(GW_Magic);
}
2013-04-17 22:56:48 +00:00
void HUD::setCellName(const std::string& cellName)
{
if (mCellName != cellName)
{
mCellNameTimer = 5.0f;
mCellName = cellName;
2013-04-17 22:56:48 +00:00
mCellNameBox->setCaptionWithReplacing("#{sCell=" + mCellName + "}");
mCellNameBox->setVisible(mMapVisible);
}
}
2013-04-17 22:56:48 +00:00
void HUD::onFrame(float dt)
{
LocalMapBase::onFrame(dt);
2013-04-17 22:56:48 +00:00
mCellNameTimer -= dt;
mWeaponSpellTimer -= dt;
if (mCellNameTimer < 0)
mCellNameBox->setVisible(false);
if (mWeaponSpellTimer < 0)
mWeaponSpellBox->setVisible(false);
2013-07-30 04:00:20 +00:00
mEnemyHealthTimer -= dt;
if (mEnemyHealth->getVisible() && mEnemyHealthTimer < 0)
{
mEnemyHealth->setVisible(false);
mWeaponSpellBox->setPosition(mWeaponSpellBox->getPosition() + MyGUI::IntPoint(0,20));
}
2013-10-27 08:05:01 +00:00
if (mIsDrowning)
2015-06-03 17:41:19 +00:00
mDrowningFlashTheta += dt * osg::PI*2;
2013-04-17 22:56:48 +00:00
}
2013-04-17 22:56:48 +00:00
void HUD::setSelectedSpell(const std::string& spellId, int successChancePercent)
{
const ESM::Spell* spell =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
2013-04-17 22:56:48 +00:00
std::string spellName = spell->mName;
if (spellName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;
mSpellName = spellName;
mWeaponSpellBox->setCaption(mSpellName);
mWeaponSpellBox->setVisible(true);
}
2013-04-17 22:56:48 +00:00
mSpellStatus->setProgressRange(100);
mSpellStatus->setProgressPosition(successChancePercent);
2013-04-17 22:56:48 +00:00
mSpellBox->setUserString("ToolTipType", "Spell");
mSpellBox->setUserString("Spell", spellId);
2013-04-17 22:56:48 +00:00
// use the icon of the first effect
const ESM::MagicEffect* effect =
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(spell->mEffects.mList.front().mEffectID);
std::string icon = effect->mIcon;
int slashPos = icon.rfind('\\');
2013-04-17 22:56:48 +00:00
icon.insert(slashPos+1, "b_");
icon = MWBase::Environment::get().getWindowManager()->correctIconPath(icon);
mSpellImage->setItem(MWWorld::Ptr());
mSpellImage->setIcon(icon);
}
2013-04-17 22:56:48 +00:00
void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent)
{
std::string itemName = item.getClass().getName(item);
2013-04-17 22:56:48 +00:00
if (itemName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;
mSpellName = itemName;
mWeaponSpellBox->setCaption(mSpellName);
mWeaponSpellBox->setVisible(true);
}
2013-04-17 22:56:48 +00:00
mSpellStatus->setProgressRange(100);
mSpellStatus->setProgressPosition(chargePercent);
2013-04-17 22:56:48 +00:00
mSpellBox->setUserString("ToolTipType", "ItemPtr");
mSpellBox->setUserData(MWWorld::Ptr(item));
mSpellImage->setItem(item);
}
2013-04-17 22:56:48 +00:00
void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent)
{
std::string itemName = item.getClass().getName(item);
2013-04-17 22:56:48 +00:00
if (itemName != mWeaponName && mWeaponVisible)
{
mWeaponSpellTimer = 5.0f;
mWeaponName = itemName;
mWeaponSpellBox->setCaption(mWeaponName);
mWeaponSpellBox->setVisible(true);
}
2014-08-25 01:15:28 +00:00
mWeapBox->clearUserStrings();
2013-04-17 22:56:48 +00:00
mWeapBox->setUserString("ToolTipType", "ItemPtr");
mWeapBox->setUserData(MWWorld::Ptr(item));
2013-04-17 22:56:48 +00:00
mWeapStatus->setProgressRange(100);
mWeapStatus->setProgressPosition(durabilityPercent);
mWeapImage->setItem(item);
}
2013-04-17 22:56:48 +00:00
void HUD::unsetSelectedSpell()
{
2013-04-17 22:56:48 +00:00
std::string spellName = "#{sNone}";
if (spellName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;
mSpellName = spellName;
mWeaponSpellBox->setCaptionWithReplacing(mSpellName);
mWeaponSpellBox->setVisible(true);
}
2013-04-17 22:56:48 +00:00
mSpellStatus->setProgressRange(100);
mSpellStatus->setProgressPosition(0);
mSpellImage->setItem(MWWorld::Ptr());
2013-04-17 22:56:48 +00:00
mSpellBox->clearUserStrings();
}
2013-04-17 22:56:48 +00:00
void HUD::unsetSelectedWeapon()
{
2013-04-17 22:56:48 +00:00
std::string itemName = "#{sSkillHandtohand}";
if (itemName != mWeaponName && mWeaponVisible)
{
mWeaponSpellTimer = 5.0f;
mWeaponName = itemName;
mWeaponSpellBox->setCaptionWithReplacing(mWeaponName);
mWeaponSpellBox->setVisible(true);
}
mWeapStatus->setProgressRange(100);
mWeapStatus->setProgressPosition(0);
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr();
mWeapImage->setItem(MWWorld::Ptr());
2014-08-25 01:15:28 +00:00
std::string icon = (player.getClass().getNpcStats(player).isWerewolf()) ? "icons\\k\\tx_werewolf_hand.dds" : "icons\\k\\stealth_handtohand.dds";
mWeapImage->setIcon(icon);
2013-04-17 22:56:48 +00:00
mWeapBox->clearUserStrings();
2014-08-25 01:15:28 +00:00
mWeapBox->setUserString("ToolTipType", "Layout");
mWeapBox->setUserString("ToolTipLayout", "HandToHandToolTip");
mWeapBox->setUserString("Caption_HandToHandText", itemName);
mWeapBox->setUserString("ImageTexture_HandToHandImage", icon);
}
2013-04-17 22:56:48 +00:00
void HUD::setCrosshairVisible(bool visible)
{
mCrosshair->setVisible (visible);
}
2015-07-17 15:29:00 +00:00
void HUD::setCrosshairOwned(bool owned)
{
if(owned)
{
mCrosshair->changeWidgetSkin("HUD_Crosshair_Owned");
2015-07-17 15:29:00 +00:00
}
else
{
mCrosshair->changeWidgetSkin("HUD_Crosshair");
2015-07-17 15:29:00 +00:00
}
}
2013-04-17 22:56:48 +00:00
void HUD::setHmsVisible(bool visible)
{
mHealth->setVisible(visible);
mMagicka->setVisible(visible);
mStamina->setVisible(visible);
updatePositions();
}
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
void HUD::setWeapVisible(bool visible)
{
mWeapBox->setVisible(visible);
updatePositions();
}
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
void HUD::setSpellVisible(bool visible)
{
mSpellBox->setVisible(visible);
updatePositions();
}
2012-08-27 17:18:55 +00:00
void HUD::setSneakVisible(bool visible)
{
mSneakBox->setVisible(visible);
updatePositions();
}
2013-04-17 22:56:48 +00:00
void HUD::setEffectVisible(bool visible)
{
mEffectBox->setVisible (visible);
updatePositions();
}
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
void HUD::setMinimapVisible(bool visible)
{
mMinimapBox->setVisible (visible);
updatePositions();
}
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
void HUD::updatePositions()
{
int weapDx = 0, spellDx = 0, sneakDx = 0;
2013-04-17 22:56:48 +00:00
if (!mHealth->getVisible())
sneakDx = spellDx = weapDx = mWeapBoxBaseLeft - mHealthManaStaminaBaseLeft;
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
if (!mWeapBox->getVisible())
{
2013-04-17 22:56:48 +00:00
spellDx += mSpellBoxBaseLeft - mWeapBoxBaseLeft;
sneakDx = spellDx;
}
if (!mSpellBox->getVisible())
sneakDx += mSneakBoxBaseLeft - mSpellBoxBaseLeft;
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
mWeaponVisible = mWeapBox->getVisible();
mSpellVisible = mSpellBox->getVisible();
if (!mWeaponVisible && !mSpellVisible)
mWeaponSpellBox->setVisible(false);
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
mWeapBox->setPosition(mWeapBoxBaseLeft - weapDx, mWeapBox->getTop());
mSpellBox->setPosition(mSpellBoxBaseLeft - spellDx, mSpellBox->getTop());
mSneakBox->setPosition(mSneakBoxBaseLeft - sneakDx, mSneakBox->getTop());
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
// effect box can have variable width -> variable left coordinate
int effectsDx = 0;
if (!mMinimapBox->getVisible ())
effectsDx = (viewSize.width - mMinimapBoxBaseRight) - (viewSize.width - mEffectBoxBaseRight);
2012-08-27 17:18:55 +00:00
2013-04-17 22:56:48 +00:00
mMapVisible = mMinimapBox->getVisible ();
2014-05-20 07:45:39 +00:00
if (!mMapVisible)
mCellNameBox->setVisible(false);
2013-04-17 22:56:48 +00:00
mEffectBox->setPosition((viewSize.width - mEffectBoxBaseRight) - mEffectBox->getWidth() + effectsDx, mEffectBox->getTop());
}
2012-08-27 17:18:55 +00:00
void HUD::updateEnemyHealthBar()
{
MWWorld::Ptr enemy = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mEnemyActorId);
if (enemy.isEmpty())
return;
MWMechanics::CreatureStats& stats = enemy.getClass().getCreatureStats(enemy);
mEnemyHealth->setProgressRange(100);
// Health is usually cast to int before displaying. Actors die whenever they are < 1 health.
// Therefore any value < 1 should show as an empty health bar. We do the same in statswindow :)
mEnemyHealth->setProgressPosition(static_cast<size_t>(stats.getHealth().getCurrent() / stats.getHealth().getModified() * 100));
static const float fNPCHealthBarFade = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCHealthBarFade")->getFloat();
if (fNPCHealthBarFade > 0.f)
mEnemyHealth->setAlpha(std::max(0.f, std::min(1.f, mEnemyHealthTimer/fNPCHealthBarFade)));
}
2013-04-17 22:56:48 +00:00
void HUD::update()
{
mSpellIcons->updateWidgets(mEffectBox, true);
2013-07-30 04:00:20 +00:00
if (mEnemyActorId != -1 && mEnemyHealth->getVisible())
2013-07-30 04:00:20 +00:00
{
updateEnemyHealthBar();
2013-07-30 04:00:20 +00:00
}
2013-10-27 08:05:01 +00:00
if (mIsDrowning)
{
float intensity = (cos(mDrowningFlashTheta) + 2.0f) / 3.0f;
mDrowningFlash->setAlpha(intensity);
2013-10-27 08:05:01 +00:00
}
2013-07-30 04:00:20 +00:00
}
void HUD::setEnemy(const MWWorld::Ptr &enemy)
{
mEnemyActorId = enemy.getClass().getCreatureStats(enemy).getActorId();
mEnemyHealthTimer = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCHealthBarTime")->getFloat();
2013-07-30 04:00:20 +00:00
if (!mEnemyHealth->getVisible())
mWeaponSpellBox->setPosition(mWeaponSpellBox->getPosition() - MyGUI::IntPoint(0,20));
mEnemyHealth->setVisible(true);
updateEnemyHealthBar();
2013-04-17 22:56:48 +00:00
}
2013-03-03 11:01:19 +00:00
2014-04-23 17:49:09 +00:00
void HUD::resetEnemy()
{
mEnemyActorId = -1;
2014-04-23 17:49:09 +00:00
mEnemyHealthTimer = -1;
}
void HUD::customMarkerCreated(MyGUI::Widget *marker)
{
marker->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMapClicked);
}
void HUD::doorMarkerCreated(MyGUI::Widget *marker)
{
marker->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onMapClicked);
}
2013-03-03 11:01:19 +00:00
}