Added enemy health meter

actorid
scrawl 12 years ago
parent 90ab7b2bf5
commit 3961c276b8

@ -265,6 +265,8 @@ namespace MWBase
virtual void changePointer (const std::string& name) = 0; virtual void changePointer (const std::string& name) = 0;
virtual void setEnemy (const MWWorld::Ptr& enemy) = 0;
virtual const Translation::Storage& getTranslationDataStorage() const = 0; virtual const Translation::Storage& getTranslationDataStorage() const = 0;
virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0; virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0;

@ -418,6 +418,9 @@ namespace MWClass
// NOTE: 'object' and/or 'attacker' may be empty. // NOTE: 'object' and/or 'attacker' may be empty.
if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player")
MWBase::Environment::get().getWindowManager()->setEnemy(ptr);
if(!successful) if(!successful)
{ {
// TODO: Handle HitAttemptOnMe script function // TODO: Handle HitAttemptOnMe script function

@ -9,6 +9,8 @@
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
#include "console.hpp" #include "console.hpp"
#include "spellicons.hpp" #include "spellicons.hpp"
@ -47,6 +49,7 @@ namespace MWGui
, mWeaponVisible(true) , mWeaponVisible(true)
, mSpellVisible(true) , mSpellVisible(true)
, mWorldMouseOver(false) , mWorldMouseOver(false)
, mEnemyHealthTimer(0)
{ {
setCoord(0,0, width, height); setCoord(0,0, width, height);
@ -55,6 +58,7 @@ namespace MWGui
getWidget(mHealth, "Health"); getWidget(mHealth, "Health");
getWidget(mMagicka, "Magicka"); getWidget(mMagicka, "Magicka");
getWidget(mStamina, "Stamina"); getWidget(mStamina, "Stamina");
getWidget(mEnemyHealth, "EnemyHealth");
mHealthManaStaminaBaseLeft = mHealthFrame->getLeft(); mHealthManaStaminaBaseLeft = mHealthFrame->getLeft();
MyGUI::Widget *healthFrame, *magickaFrame, *fatigueFrame; MyGUI::Widget *healthFrame, *magickaFrame, *fatigueFrame;
@ -320,6 +324,13 @@ namespace MWGui
mCellNameBox->setVisible(false); mCellNameBox->setVisible(false);
if (mWeaponSpellTimer < 0) if (mWeaponSpellTimer < 0)
mWeaponSpellBox->setVisible(false); 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) void HUD::onResChange(int width, int height)
@ -535,6 +546,25 @@ namespace MWGui
void HUD::update() void HUD::update()
{ {
mSpellIcons->updateWidgets(mEffectBox, true); 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);
} }
} }

@ -46,12 +46,14 @@ namespace MWGui
void update(); void update();
void setEnemy(const MWWorld::Ptr& enemy);
private: private:
MyGUI::ProgressPtr mHealth, mMagicka, mStamina; MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth;
MyGUI::Widget* mHealthFrame; MyGUI::Widget* mHealthFrame;
MyGUI::Widget *mWeapBox, *mSpellBox; MyGUI::Widget *mWeapBox, *mSpellBox;
MyGUI::ImageBox *mWeapImage, *mSpellImage; MyGUI::ImageBox *mWeapImage, *mSpellImage;
MyGUI::ProgressPtr mWeapStatus, mSpellStatus; MyGUI::ProgressBar *mWeapStatus, *mSpellStatus;
MyGUI::Widget *mEffectBox, *mMinimapBox; MyGUI::Widget *mEffectBox, *mMinimapBox;
MyGUI::Button* mMinimapButton; MyGUI::Button* mMinimapButton;
MyGUI::ScrollView* mMinimap; MyGUI::ScrollView* mMinimap;
@ -89,6 +91,9 @@ namespace MWGui
SpellIcons* mSpellIcons; SpellIcons* mSpellIcons;
MWWorld::Ptr mEnemy;
float mEnemyHealthTimer;
void onWorldClicked(MyGUI::Widget* _sender); void onWorldClicked(MyGUI::Widget* _sender);
void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y); void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y);
void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new); void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new);

@ -1300,4 +1300,9 @@ namespace MWGui
SDL_StopTextInput(); SDL_StopTextInput();
} }
void WindowManager::setEnemy(const MWWorld::Ptr &enemy)
{
mHud->setEnemy(enemy);
}
} }

@ -256,6 +256,8 @@ namespace MWGui
virtual void changePointer (const std::string& name); virtual void changePointer (const std::string& name);
virtual void setEnemy (const MWWorld::Ptr& enemy);
virtual const Translation::Storage& getTranslationDataStorage() const; virtual const Translation::Storage& getTranslationDataStorage() const;
void onSoulgemDialogButtonPressed (int button); void onSoulgemDialogButtonPressed (int button);

@ -3,6 +3,11 @@
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="Widget" layer="HUD" position="0 0 300 200" name="_Main"> <Widget type="Widget" layer="HUD" position="0 0 300 200" name="_Main">
<!-- Energy bars --> <!-- Energy bars -->
<Widget type="Widget" skin="" position="13 131 65 12" align="Left Bottom" name="EnemyHealthFrame">
<Widget type="ProgressBar" skin="MW_EnergyBar_Yellow" position="0 0 65 12" align="Left Bottom" name="EnemyHealth">
<Property key="Visible" value="false"/>
</Widget>
</Widget>
<Widget type="Button" skin="" position="13 146 65 12" align="Left Bottom" name="HealthFrame"> <Widget type="Button" skin="" position="13 146 65 12" align="Left Bottom" name="HealthFrame">
<UserString key="ToolTipType" value="Layout"/> <UserString key="ToolTipType" value="Layout"/>
<UserString key="ToolTipLayout" value="HealthToolTip"/> <UserString key="ToolTipLayout" value="HealthToolTip"/>

@ -42,6 +42,11 @@
<State name="normal" offset = "0 8 4 8"/> <State name="normal" offset = "0 8 4 8"/>
</BasisSkin> </BasisSkin>
</Skin> </Skin>
<Skin name = "MW_BarTrack_Yellow" size = "4 8" texture = "smallbars.png" >
<BasisSkin type="MainSkin" offset = "0 0 4 8" align = "ALIGN_STRETCH">
<State name="normal" offset = "0 32 4 8"/>
</BasisSkin>
</Skin>
<!-- Main energy bar widget definitions. There's one for each color.--> <!-- Main energy bar widget definitions. There's one for each color.-->
@ -69,4 +74,12 @@
<Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/> <Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/>
</Skin> </Skin>
<Skin name="MW_EnergyBar_Yellow" size="64 12">
<Property key="TrackSkin" value = "MW_BarTrack_Yellow" />
<Property key="TrackWidth" value = "1" />
<Child type="Widget" skin="MW_BarFrame" offset="0 0 64 12" align="ALIGN_STRETCH"/>
<Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/>
</Skin>
</MyGUI> </MyGUI>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Loading…
Cancel
Save