diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index d85c28fe2..ab4c943bf 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -265,6 +265,8 @@ namespace MWBase virtual void changePointer (const std::string& name) = 0; + virtual void setEnemy (const MWWorld::Ptr& enemy) = 0; + virtual const Translation::Storage& getTranslationDataStorage() const = 0; virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index f767ac670..30ae1880c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -418,6 +418,9 @@ namespace MWClass // NOTE: 'object' and/or 'attacker' may be empty. + if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player") + MWBase::Environment::get().getWindowManager()->setEnemy(ptr); + if(!successful) { // TODO: Handle HitAttemptOnMe script function diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 469c45936..4eea0d0d0 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -9,6 +9,8 @@ #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include "inventorywindow.hpp" #include "console.hpp" #include "spellicons.hpp" @@ -47,6 +49,7 @@ namespace MWGui , mWeaponVisible(true) , mSpellVisible(true) , mWorldMouseOver(false) + , mEnemyHealthTimer(0) { setCoord(0,0, width, height); @@ -55,6 +58,7 @@ namespace MWGui getWidget(mHealth, "Health"); getWidget(mMagicka, "Magicka"); getWidget(mStamina, "Stamina"); + getWidget(mEnemyHealth, "EnemyHealth"); mHealthManaStaminaBaseLeft = mHealthFrame->getLeft(); MyGUI::Widget *healthFrame, *magickaFrame, *fatigueFrame; @@ -320,6 +324,13 @@ namespace MWGui mCellNameBox->setVisible(false); if (mWeaponSpellTimer < 0) mWeaponSpellBox->setVisible(false); + + mEnemyHealthTimer -= dt; + if (mEnemyHealth->getVisible() && mEnemyHealthTimer < 0) + { + mEnemyHealth->setVisible(false); + mWeaponSpellBox->setPosition(mWeaponSpellBox->getPosition() + MyGUI::IntPoint(0,20)); + } } void HUD::onResChange(int width, int height) @@ -535,6 +546,25 @@ namespace MWGui void HUD::update() { mSpellIcons->updateWidgets(mEffectBox, true); + + if (!mEnemy.isEmpty() && mEnemyHealth->getVisible()) + { + MWMechanics::CreatureStats& stats = MWWorld::Class::get(mEnemy).getCreatureStats(mEnemy); + mEnemyHealth->setProgressRange(100); + mEnemyHealth->setProgressPosition(stats.getHealth().getCurrent() / stats.getHealth().getModified() * 100); + } + } + + void HUD::setEnemy(const MWWorld::Ptr &enemy) + { + mEnemy = enemy; + mEnemyHealthTimer = 5; + if (!mEnemyHealth->getVisible()) + mWeaponSpellBox->setPosition(mWeaponSpellBox->getPosition() - MyGUI::IntPoint(0,20)); + mEnemyHealth->setVisible(true); + MWMechanics::CreatureStats& stats = MWWorld::Class::get(mEnemy).getCreatureStats(mEnemy); + mEnemyHealth->setProgressRange(100); + mEnemyHealth->setProgressPosition(stats.getHealth().getCurrent() / stats.getHealth().getModified() * 100); } } diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index 1dd53683b..76d878269 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -46,12 +46,14 @@ namespace MWGui void update(); + void setEnemy(const MWWorld::Ptr& enemy); + private: - MyGUI::ProgressPtr mHealth, mMagicka, mStamina; + MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth; MyGUI::Widget* mHealthFrame; MyGUI::Widget *mWeapBox, *mSpellBox; MyGUI::ImageBox *mWeapImage, *mSpellImage; - MyGUI::ProgressPtr mWeapStatus, mSpellStatus; + MyGUI::ProgressBar *mWeapStatus, *mSpellStatus; MyGUI::Widget *mEffectBox, *mMinimapBox; MyGUI::Button* mMinimapButton; MyGUI::ScrollView* mMinimap; @@ -89,6 +91,9 @@ namespace MWGui SpellIcons* mSpellIcons; + MWWorld::Ptr mEnemy; + float mEnemyHealthTimer; + void onWorldClicked(MyGUI::Widget* _sender); void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y); void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 6fcc19a47..9327ea7b9 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1300,4 +1300,9 @@ namespace MWGui SDL_StopTextInput(); } + void WindowManager::setEnemy(const MWWorld::Ptr &enemy) + { + mHud->setEnemy(enemy); + } + } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 6395b1bb5..cbfab2fa2 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -256,6 +256,8 @@ namespace MWGui virtual void changePointer (const std::string& name); + virtual void setEnemy (const MWWorld::Ptr& enemy); + virtual const Translation::Storage& getTranslationDataStorage() const; void onSoulgemDialogButtonPressed (int button); diff --git a/files/mygui/openmw_hud.layout b/files/mygui/openmw_hud.layout index 67d0632f8..c69323fe5 100644 --- a/files/mygui/openmw_hud.layout +++ b/files/mygui/openmw_hud.layout @@ -3,6 +3,11 @@ + + + + + diff --git a/files/mygui/openmw_hud_energybar.skin.xml b/files/mygui/openmw_hud_energybar.skin.xml index 03d2835d6..9ec065e36 100644 --- a/files/mygui/openmw_hud_energybar.skin.xml +++ b/files/mygui/openmw_hud_energybar.skin.xml @@ -42,6 +42,11 @@ + + + + + @@ -69,4 +74,12 @@ + + + + + + + + diff --git a/files/mygui/smallbars.png b/files/mygui/smallbars.png index f938412c2..3c007a55c 100644 Binary files a/files/mygui/smallbars.png and b/files/mygui/smallbars.png differ