From 827f91446c550fdf066cb9bec1d6b15ae8662b78 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 5 Jan 2011 04:52:43 +0200 Subject: Add gettext to missing strings. Update POTFILES.in and update russian translation. --- src/being.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 08893c2f4..3a9285750 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -71,6 +71,7 @@ #include "gui/widgets/chattab.h" #include "utils/dtor.h" +#include "utils/gettext.h" #include "utils/stringutils.h" #include "utils/xml.h" @@ -476,7 +477,7 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font = 0; std::string damage = amount ? toString(amount) : type == FLEE ? - "dodge" : "miss"; + _("dodge") : _("miss"); const gcn::Color *color; if (gui) -- cgit v1.2.3-70-g09d2 From 1c49a83df05dbf6837687e1bfc5b142a680144ed Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 5 Jan 2011 22:56:42 +0200 Subject: Add hp bar to local player. --- src/being.cpp | 46 ++++++++++++++++++++++++++-------------------- src/being.h | 3 ++- src/defaults.cpp | 1 + src/gui/setup_colors.cpp | 2 ++ src/gui/setup_other.cpp | 17 ++++++++++++++++- src/gui/setup_other.h | 3 +++ src/gui/userpalette.cpp | 5 +++++ src/gui/userpalette.h | 2 ++ 8 files changed, 57 insertions(+), 22 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 3a9285750..2372cfe1b 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -169,6 +169,7 @@ bool Being::mLowTraffic = true; bool Being::mDrawHotKeys = true; bool Being::mShowBattleEvents = false; bool Being::mShowMobHP = false; +bool Being::mShowOwnHP = false; std::list beingInfoCache; @@ -1551,6 +1552,7 @@ void Being::reReadConfig() mDrawHotKeys = config.getBoolValue("drawHotKeys"); mShowBattleEvents = config.getBoolValue("showBattleEvents"); mShowMobHP = config.getBoolValue("showMobHP"); + mShowOwnHP = config.getBoolValue("showOwnHP"); mUpdateConfigTime = cur_time; } @@ -1745,42 +1747,48 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const 2 * attackRange + 32, 2 * attackRange + 32)); } - if (mShowMobHP && player_node && player_node->getTarget() == this + if (mShowMobHP && mInfo && player_node && player_node->getTarget() == this && getType() == MONSTER) { // show hp bar here - drawHpBar(graphics, x - 50 + 16, y + 32 - 6, 2 * 50, 4); + int maxHP = mMaxHP; + if (!maxHP) + maxHP = mInfo->getMaxHP(); + + drawHpBar(graphics, maxHP, mHP, mDamageTaken, + UserPalette::MONSTER_HP, UserPalette::MONSTER_HP2, + x - 50 + 16, y + 32 - 6, 2 * 50, 4); + } + if (mShowOwnHP && player_node == this) + { + drawHpBar(graphics, PlayerInfo::getAttribute(MAX_HP), + PlayerInfo::getAttribute(HP), 0, + UserPalette::PLAYER_HP, UserPalette::PLAYER_HP2, + x - 50 + 16, y + 32 - 6, 2 * 50, 4); } return res; } -void Being::drawHpBar(Graphics *graphics, int x, int y, +void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, + int color1, int color2, int x, int y, int width, int height) const { - if (!mInfo) - return; - - int maxHP = mMaxHP; - - if (!maxHP) - maxHP = mInfo->getMaxHP(); - if (maxHP <= 0) return; - if (!mHP && maxHP < mHP) + if (!hp && maxHP < hp) return; float p; - if (mHP) + if (hp) { - p = static_cast(maxHP) / static_cast(mHP); + p = static_cast(maxHP) / static_cast(hp); } - else if (maxHP != mDamageTaken) + else if (maxHP != damage) { p = static_cast(maxHP) - / static_cast(maxHP - mDamageTaken); + / static_cast(maxHP - damage); } else { @@ -1792,8 +1800,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y, int dx = width / p; - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::MONSTER_HP)); + graphics->setColor(userPalette->getColorWithAlpha(color1)); graphics->fillRectangle(gcn::Rectangle( x, y, dx, height)); @@ -1801,8 +1808,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y, if (width - dx <= 0) return; - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::MONSTER_HP2)); + graphics->setColor(userPalette->getColorWithAlpha(color2)); graphics->fillRectangle(gcn::Rectangle( x + dx, y, width - dx, height)); diff --git a/src/being.h b/src/being.h index 09466f5af..f9731366a 100644 --- a/src/being.h +++ b/src/being.h @@ -520,6 +520,7 @@ class Being : public ActorSprite, public ConfigListener int posX, int posY) const; void drawHpBar(Graphics *graphics, int x, int y, + int maxHP, int hp, int damage, int color1, int color2, int width, int height) const; static void load(); @@ -751,7 +752,7 @@ class Being : public ActorSprite, public ConfigListener static bool mDrawHotKeys; static bool mShowBattleEvents; static bool mShowMobHP; -// std::string mDisplayName; + static bool mShowOwnHP; unsigned int mMoveTime; unsigned int mAttackTime; diff --git a/src/defaults.cpp b/src/defaults.cpp index 916c20398..190c1816c 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -189,6 +189,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "enableBattleTab", false); AddDEF(configData, "showBattleEvents", false); AddDEF(configData, "showMobHP", true); + AddDEF(configData, "showOwnHP", true); return configData; } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 76510a283..68d517cae 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -302,6 +302,8 @@ void Setup_Colors::valueChanged(const gcn::SelectionEvent &event _UNUSED_) case UserPalette::ROAD_POINT: case UserPalette::MONSTER_HP: case UserPalette::MONSTER_HP2: + case UserPalette::PLAYER_HP: + case UserPalette::PLAYER_HP2: mGradDelayLabel->setCaption(_("Alpha:")); mGradDelayText->setRange(0, 255); mGradDelaySlider->setScale(0, 255); diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 54ec1c65d..5a2b77a81 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -63,6 +63,7 @@ #define ACTION_WARP_PARTICLE "warp particle" #define ACTION_AUTO_SHOP "auto shop" #define ACTION_SHOW_MOB_HP "show mob hp" +#define ACTION_SHOW_OWN_HP "show own hp" Setup_Other::Setup_Other(): mShowMonstersTakedDamage(config.getBoolValue("showMonstersTakedDamage")), @@ -87,7 +88,8 @@ Setup_Other::Setup_Other(): mQuickStats(config.getBoolValue("quickStats")), mWarpParticle(config.getBoolValue("warpParticle")), mAutoShop(config.getBoolValue("autoShop")), - mShowMobHP(config.getBoolValue("showMobHP")) + mShowMobHP(config.getBoolValue("showMobHP")), + mShowOwnHP(config.getBoolValue("showOwnHP")) { setName(_("Misc")); @@ -178,6 +180,10 @@ Setup_Other::Setup_Other(): mShowMobHP, this, ACTION_SHOW_MOB_HP); + mShowOwnHPCheckBox = new CheckBox(_("Show own hp bar"), + mShowOwnHP, + this, ACTION_SHOW_OWN_HP); + // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); @@ -192,6 +198,7 @@ Setup_Other::Setup_Other(): place(12, 4, mWarpParticleCheckBox, 10); place(12, 5, mAutoShopCheckBox, 10); place(12, 6, mShowMobHPCheckBox, 10); + place(12, 7, mShowOwnHPCheckBox, 10); place(0, 3, mFloorItemsHighlightCheckBox, 12); place(0, 4, mHighlightAttackRangeCheckBox, 12); place(0, 5, mHighlightMonsterAttackRangeCheckBox, 12); @@ -320,6 +327,10 @@ void Setup_Other::action(const gcn::ActionEvent &event) { mShowMobHP = mShowMobHPCheckBox->isSelected(); } + else if (event.getId() == ACTION_SHOW_OWN_HP) + { + mShowOwnHP = mShowOwnHPCheckBox->isSelected(); + } } void Setup_Other::cancel() @@ -389,6 +400,9 @@ void Setup_Other::cancel() mShowMobHP = config.getBoolValue("showMobHP"); mShowMobHPCheckBox->setSelected(mShowMobHP); + + mShowOwnHP = config.getBoolValue("showOwnHP"); + mShowOwnHPCheckBox->setSelected(mShowOwnHP); } void Setup_Other::apply() @@ -416,6 +430,7 @@ void Setup_Other::apply() config.setValue("warpParticle", mWarpParticle); config.setValue("autoShop", mAutoShop); config.setValue("showMobHP", mShowMobHP); + config.setValue("showOwnHP", mShowOwnHP); logger->setDebugLog(mDebugLog); } diff --git a/src/gui/setup_other.h b/src/gui/setup_other.h index b20401be5..6a092e93f 100644 --- a/src/gui/setup_other.h +++ b/src/gui/setup_other.h @@ -119,6 +119,9 @@ class Setup_Other : public SetupTab, public gcn::ActionListener gcn::CheckBox *mShowMobHPCheckBox; bool mShowMobHP; + gcn::CheckBox *mShowOwnHPCheckBox; + bool mShowOwnHP; + EditDialog *mEditDialog; }; diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 03e5c1eed..46f1b72b3 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -52,6 +52,8 @@ const std::string ColorTypeNames[] = "ColorParticle", "ColorPickupInfo", "ColorExpInfo", + "ColorPlayerHp", + "ColorPlayerHp2", "ColorHitPlayerMonster", "ColorHitMonsterPlayer", "ColorHitPlayerPlayer", @@ -124,6 +126,9 @@ UserPalette::UserPalette(): addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup Notification")); addColor(EXP_INFO, 0xffff00, STATIC, _("Exp Notification")); + addColor(PLAYER_HP, 0x00ff00, STATIC, _("Player HP bar"), 50); + addColor(PLAYER_HP2, 0xff0000, STATIC, + _("Player HP bar (second color)"), 50); addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player Hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster Hits Player")); addColor(HIT_PLAYER_PLAYER, 0xff5050, STATIC, diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 057d47113..db2463e20 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -53,6 +53,8 @@ class UserPalette : public Palette, public gcn::ListModel PARTICLE, PICKUP_INFO, EXP_INFO, + PLAYER_HP, + PLAYER_HP2, HIT_PLAYER_MONSTER, HIT_MONSTER_PLAYER, HIT_PLAYER_PLAYER, -- cgit v1.2.3-70-g09d2 From ef7f53e43ce4306080efae3b86443a6016a3e66a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 6 Jan 2011 21:25:25 +0200 Subject: Set sound volume depends on distance to object. --- src/being.cpp | 14 +++++++++++--- src/sound.cpp | 32 ++++++++++++++++++++++++++++++++ src/sound.h | 2 ++ 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 2372cfe1b..1d8178670 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -568,7 +568,15 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) mDamageTaken += amount; if (mInfo) { - sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + if (attacker) + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT), + attacker->getTileX(), attacker->getTileY()); + } + else + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + } if (!mInfo->isStaticMaxHP()) { if (!mHP && mInfo->getMaxHP() < mDamageTaken) @@ -618,7 +626,7 @@ void Being::handleAttack(Being *victim, int damage, } sound.playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS)); + SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); } void Being::setName(const std::string &name) @@ -904,7 +912,7 @@ void Being::setAction(Action action, int attackType _UNUSED_) case DEAD: currentAction = SpriteAction::DEAD; if (mInfo) - sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE)); + sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY); break; case STAND: currentAction = SpriteAction::STAND; diff --git a/src/sound.cpp b/src/sound.cpp index 8742ce361..080426a39 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -22,6 +22,7 @@ #include #include "configuration.h" +#include "localplayer.h" #include "log.h" #include "sound.h" @@ -280,6 +281,37 @@ void Sound::playSfx(const std::string &path) } } +void Sound::playSfx(const std::string &path, int x, int y) +{ + if (!mInstalled || path.empty() || !mPlayBattle) + return; + + std::string tmpPath; + if (!path.find("sfx/")) + tmpPath = path; + else + tmpPath = paths.getValue("sfx", "sfx/") + path; + ResourceManager *resman = ResourceManager::getInstance(); + SoundEffect *sample = resman->getSoundEffect(tmpPath); + if (sample) + { + logger->log("Sound::playSfx() Playing: %s", path.c_str()); + int vol = 120; + if (player_node) + { + int dx = player_node->getTileX() - x; + int dy = player_node->getTileY() - y; + if (dx < 0) + dx = -dx; + if (dy < 0) + dy = -dy; + int dist = dx > dy ? dx : dy; + vol -= dist * 8; + } + sample->play(0, vol); + } +} + void Sound::playGuiSfx(const std::string &path) { if (!mInstalled || path.empty() || !mPlayGui) diff --git a/src/sound.h b/src/sound.h index 100c228c1..92c0ab41a 100644 --- a/src/sound.h +++ b/src/sound.h @@ -93,6 +93,8 @@ class Sound : public ConfigListener */ void playSfx(const std::string &path); + void playSfx(const std::string &path, int x, int y); + /** * Plays an item for gui. * -- cgit v1.2.3-70-g09d2 From 5992d792bc8dffc92251cea4d292635943801520 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 10 Jan 2011 19:55:38 +0200 Subject: Hide own hp bar if player dead. --- src/being.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 1d8178670..4f31e402c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1767,7 +1767,7 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const UserPalette::MONSTER_HP, UserPalette::MONSTER_HP2, x - 50 + 16, y + 32 - 6, 2 * 50, 4); } - if (mShowOwnHP && player_node == this) + if (mShowOwnHP && player_node == this && mAction != DEAD) { drawHpBar(graphics, PlayerInfo::getAttribute(MAX_HP), PlayerInfo::getAttribute(HP), 0, -- cgit v1.2.3-70-g09d2