From 3961c276b85d993b00f146f4ec486ddfdf200f5d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 30 Jul 2013 06:00:20 +0200 Subject: [PATCH] Added enemy health meter --- apps/openmw/mwbase/windowmanager.hpp | 2 ++ apps/openmw/mwclass/npc.cpp | 3 +++ apps/openmw/mwgui/hud.cpp | 30 ++++++++++++++++++++++ apps/openmw/mwgui/hud.hpp | 9 +++++-- apps/openmw/mwgui/windowmanagerimp.cpp | 5 ++++ apps/openmw/mwgui/windowmanagerimp.hpp | 2 ++ files/mygui/openmw_hud.layout | 5 ++++ files/mygui/openmw_hud_energybar.skin.xml | 13 ++++++++++ files/mygui/smallbars.png | Bin 3205 -> 2985 bytes 9 files changed, 67 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index d85c28fe24..ab4c943bf0 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 f767ac6704..30ae1880ce 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 469c45936f..4eea0d0d0d 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 1dd53683b8..76d8782696 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 6fcc19a477..9327ea7b9f 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 6395b1bb57..cbfab2fa29 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 67d0632f84..c69323fe56 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 03d2835d6e..9ec065e360 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 f938412c259c540d8e085a339fa0d94c4294a361..3c007a55cea32c99bbb4acb41e27419cc0290d49 100644 GIT binary patch delta 303 zcmV+~0nq-18L1bL7YZl{1^@s6*`Hf8u{K@`4+dgOM??Vs0RI60puMM)ks%j<00(qQ zO+^RY2Oa|$Dm!$xI{*Lx+et)0R4C6~(mhTCF%X8~cLqx-K%%6er{p$VgA1jn<21Cn zKtxu_CQE|6YY)ZlO89d#(&HKbjBVT3r{Ld6ZZsn$H)?r$FgMJch>Drx08!?Db)po~l!vxt%)P*`LO!*yfBTkmxb%aKK>-}7;N+!) zV=NihNlGqR;4})HC1cx3gVuK`w!x^RkC#sX39%OKGAA^)QjI38R01Nus0yA2(q6aWAK07*p#PDHLkV1m~s Bgf0L8 delta 526 zcmYk3Jxc>Y5Qg752aG|mJjEs;YA4oqN)%I=B4`&#z}_?pVsoNc2_o7EX{-bbgK6#a z3;Y$)1oEZP``C3hxp+Ipd-u%jymLGE>|QP0y6H^H0q|DK&)nan-TG27?PU&k3wyxX zGH`wg{AzhNfs=LMqYP|30B+^3)Yt*&HJ9DoKP5a;Nl|sp6|ZryLz7p4g_MS*jE2fo zqLFfcOrx{h4kEyd`?&23O`v7N`{L2000x;GjDyJ`B1dZ_YSKC~9-