diff options
author | Majin Sniper <majinsniper@gmx.de> | 2009-02-20 00:19:52 +0100 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-02-19 18:27:45 -0700 |
commit | 1713f33dbd71b6378c8a4e58452fb16147f320d7 (patch) | |
tree | 19edc1a3291b06bf1680394bb1a68986ddca6f0c /src | |
parent | fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9 (diff) | |
download | mana-1713f33dbd71b6378c8a4e58452fb16147f320d7.tar.gz mana-1713f33dbd71b6378c8a4e58452fb16147f320d7.tar.bz2 mana-1713f33dbd71b6378c8a4e58452fb16147f320d7.tar.xz mana-1713f33dbd71b6378c8a4e58452fb16147f320d7.zip |
Added a pickup notification as particle effect. Also make a ui option to enable/disable this effect (default is off) and another option to disable the pickup notification in the chat log (default is on).
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui.cpp | 1 | ||||
-rw-r--r-- | src/gui/gui.h | 8 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 41 | ||||
-rw-r--r-- | src/gui/setup_video.h | 6 | ||||
-rw-r--r-- | src/gui/truetypefont.cpp | 3 | ||||
-rw-r--r-- | src/gui/truetypefont.h | 2 | ||||
-rw-r--r-- | src/localplayer.cpp | 12 | ||||
-rw-r--r-- | src/localplayer.h | 5 | ||||
-rw-r--r-- | src/net/inventoryhandler.cpp | 15 | ||||
-rw-r--r-- | src/particle.cpp | 11 | ||||
-rw-r--r-- | src/particle.h | 8 | ||||
-rw-r--r-- | src/textparticle.cpp | 23 | ||||
-rw-r--r-- | src/textparticle.h | 4 |
13 files changed, 118 insertions, 21 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 9b9e74f4..431e4d2d 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -112,6 +112,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); + mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 5c0c24f7..d5680412 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,13 @@ class Gui : public gcn::Gui { return mGuiFont; } /** + * Return the Font used for "Info Particles", i.e. ones showing, what + * you picked up, etc. + */ + gcn::Font* getInfoParticleFont() const + { return mInfoParicleFont; } + + /** * Sets whether a custom cursor should be rendered. */ void setUseCustomCursor(bool customCursor); @@ -107,6 +114,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ + gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index aa39dd36..37197cd2 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -109,6 +109,8 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", true)), mParticleEffectsEnabled(config.getValue("particleeffects", true)), mNameEnabled(config.getValue("showownname", false)), + mPickupChatEnabled(config.getValue("showpickupchat", true)), + mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 0)), mSpeechMode((int) config.getValue("speech", 3)), @@ -136,7 +138,11 @@ Setup_Video::Setup_Video(): mOverlayDetailField(new gcn::Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")) + mParticleDetailField(new gcn::Label("")), + mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + mPickupParticleCheckBox(new CheckBox(_("as particle"), + mPickupParticleEnabled)) { setOpaque(false); @@ -169,6 +175,8 @@ Setup_Video::Setup_Video(): mModeList->setActionEventId("videomode"); mCustomCursorCheckBox->setActionEventId("customcursor"); mParticleEffectsCheckBox->setActionEventId("particleeffects"); + mPickupChatCheckBox->setActionEventId("pickupchat"); + mPickupParticleCheckBox->setActionEventId("pickupparticle"); mNameCheckBox->setActionEventId("showownname"); mAlphaSlider->setActionEventId("guialpha"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); @@ -186,6 +194,8 @@ Setup_Video::Setup_Video(): mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); + mPickupChatCheckBox->addActionListener(this); + mPickupParticleCheckBox->addActionListener(this); mNameCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); @@ -260,11 +270,14 @@ Setup_Video::Setup_Video(): ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, scrollArea, 1, 6).setPadding(2); - place(1, 0, mFsCheckBox, 3); - place(1, 1, mOpenGLCheckBox, 3); - place(1, 2, mCustomCursorCheckBox, 3); - place(1, 3, mNameCheckBox, 3); - place(1, 4, mParticleEffectsCheckBox, 3); + place(1, 0, mFsCheckBox, 2); + place(3, 0, mOpenGLCheckBox, 1); + place(1, 1, mCustomCursorCheckBox, 3); + place(1, 2, mNameCheckBox, 3); + place(1, 3, mParticleEffectsCheckBox, 3); + place(1, 4, mPickupNotifyLabel, 3); + place(1, 5, mPickupChatCheckBox, 1); + place(2, 5, mPickupParticleCheckBox, 2); place(0, 6, mAlphaSlider); place(0, 7, mFpsSlider); @@ -354,6 +367,8 @@ void Setup_Video::apply() mOpacity = config.getValue("guialpha", 0.8); mOverlayDetail = (int) config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", false); + mPickupChatEnabled = config.getValue("showpickupchat", true); + mPickupParticleEnabled = config.getValue("showpickupparticle", false); } int Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, @@ -400,6 +415,9 @@ void Setup_Video::cancel() config.setValue("showownname", mNameEnabled ? true : false); config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); + config.setValue("showpickupchat", mPickupChatEnabled ? true : false); + config.setValue("showpickupparticle", mPickupParticleEnabled ? + true : false); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -433,6 +451,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) new OkDialog(_("Particle effect settings changed"), _("Restart your client or change maps for the change to take effect.")); } + else if (event.getId() == "pickupchat") + { + config.setValue("showpickupchat", mPickupChatCheckBox->isSelected() + ? true : false); + } + else if (event.getId() == "pickupparticle") + { + config.setValue("showpickupparticle", + mPickupParticleCheckBox->isSelected() + ? true : false); + } else if (event.getId() == "speech") { int val = (int) mSpeechSlider->getValue(); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index e57e33cc..7d9732a1 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -52,6 +52,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mNameEnabled; + bool mPickupChatEnabled; + bool mPickupParticleEnabled; double mOpacity; int mFps; int mSpeechMode; @@ -72,6 +74,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mParticleEffectsCheckBox; gcn::CheckBox *mNameCheckBox; + gcn::Label *mPickupNotifyLabel; + gcn::CheckBox *mPickupChatCheckBox; + gcn::CheckBox *mPickupParticleCheckBox; + gcn::Slider *mSpeechSlider; gcn::Label *mSpeechLabel; gcn::Slider *mAlphaSlider; diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 7c72e2f5..b4b839e9 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -76,7 +76,7 @@ typedef std::list<TextChunk>::iterator CacheIterator; static int fontCounter; -TrueTypeFont::TrueTypeFont(const std::string &filename, int size) +TrueTypeFont::TrueTypeFont(const std::string &filename, int size, int style) { if (fontCounter == 0 && TTF_Init() == -1) { @@ -86,6 +86,7 @@ TrueTypeFont::TrueTypeFont(const std::string &filename, int size) ++fontCounter; mFont = TTF_OpenFont(filename.c_str(), size); + TTF_SetFontStyle (mFont, style); if (!mFont) { diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 71b45fd1..de146087 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -48,7 +48,7 @@ class TrueTypeFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - TrueTypeFont(const std::string &filename, int size); + TrueTypeFont(const std::string &filename, int size, int style = 0); /** * Destructor. diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b9654e63..ea05bd7e 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -587,6 +587,18 @@ void LocalPlayer::setXp(int xp) mXp = xp; } +void LocalPlayer::pickedUp(std::string item) +{ + if (mMap) + { + // Show pickup notification + particleEngine->addTextRiseFadeOutEffect(item, + gui->getInfoParticleFont (), + mPx + 16, mPy - 16, + 40, 220, 40, true); + } +} + bool LocalPlayer::withinAttackRange(Being *target) { int dist_x = abs(target->mX - mX); diff --git a/src/localplayer.h b/src/localplayer.h index 5f02de4f..2226671b 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -203,6 +203,11 @@ class LocalPlayer : public Player void setXp(int xp); /** + * Shows item pickup effect if the player is on a map. + */ + void pickedUp(std::string item); + + /** * Returns the amount of experience points. */ int getXp() const { return mXp; } diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index d5ac0c29..a227701e 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -25,6 +25,7 @@ #include "messagein.h" #include "protocol.h" +#include "../configuration.h" #include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" @@ -141,13 +142,21 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemType = msg->readInt8(); if (msg->readInt8() > 0) { - chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + } } else { const ItemInfo &itemInfo = ItemDB::get(itemId); const std::string amountStr = (amount > 1) ? toString(amount) : "a"; - chatWindow->chatLog(strprintf(_("You picked up %s %s"), - amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(strprintf(_("You picked up %s %s"), + amountStr.c_str(), itemInfo.getName().c_str()), + BY_SERVER); + } + if (config.getValue("showpickupparticle", false)) { + player_node->pickedUp(itemInfo.getName()); + } if (Item *item = inventory->getItem(index)) { item->setId(itemId); diff --git a/src/particle.cpp b/src/particle.cpp index 45cbb4c9..6dc45a08 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -326,10 +326,10 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, Particle *Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y) + gcn::Font *font, int x, int y, bool outline) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font); + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -346,9 +346,12 @@ Particle *Particle::addTextSplashEffect(const std::string &text, Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y) + int x, int y, + int colorR, int colorG, + int colorB, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index 1baf11f8..b4c80194 100644 --- a/src/particle.h +++ b/src/particle.h @@ -107,15 +107,17 @@ class Particle : public Sprite */ Particle *addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y); + gcn::Font *font, int x, int y, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y); - + int x, int y, int colorR = 255, + int colorG = 255, int colorB = 255, + bool outline = false); /** * Adds an emitter to the particle. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp index f38c32ce..3494b97f 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -23,16 +23,18 @@ #include "graphics.h" #include "textparticle.h" +#include <SDL/SDL_ttf.h> TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font): + gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), mColorR(colorR), mColorG(colorG), - mColorB(colorB) + mColorB(colorB), + mOutline(outline) { } @@ -59,6 +61,23 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); + if (mOutline) + { + graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); + // Text outline + graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); + graphics->drawText(mText, screenX + 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX - 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY + 1, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY - 1, + gcn::Graphics::CENTER); + } graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index 76c247bf..d72df138 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,7 +33,7 @@ class TextParticle : public Particle */ TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font); + gcn::Font *font, bool outline = false); /** * Draws the particle image. @@ -48,6 +48,8 @@ class TextParticle : public Particle std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text readable - draw it the way + a Text is usually drawn: with outline */ }; #endif |