diff options
-rw-r--r-- | data/graphics/gui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/graphics/gui/Makefile.am | 1 | ||||
-rw-r--r-- | data/graphics/gui/progress-indicator.png | bin | 0 -> 5533 bytes | |||
-rw-r--r-- | mana.files | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/being.cpp | 26 | ||||
-rw-r--r-- | src/being.h | 4 | ||||
-rw-r--r-- | src/gui/connectiondialog.cpp | 41 | ||||
-rw-r--r-- | src/gui/connectiondialog.h | 16 | ||||
-rw-r--r-- | src/gui/widgets/progressindicator.cpp | 64 | ||||
-rw-r--r-- | src/gui/widgets/progressindicator.h | 46 | ||||
-rw-r--r-- | src/main.cpp | 21 | ||||
-rw-r--r-- | src/resources/animation.cpp | 3 | ||||
-rw-r--r-- | src/resources/animation.h | 3 | ||||
-rw-r--r-- | src/simpleanimation.cpp | 126 | ||||
-rw-r--r-- | src/simpleanimation.h | 7 |
17 files changed, 245 insertions, 120 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index ed436151..01b8674f 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -18,6 +18,7 @@ SET (FILES hscroll_right_pressed.png item_shortcut_bgr.png mouse.png + progress-indicator.png radioin.png radioin_highlight.png radioout.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 842522ab..ed48c012 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -21,6 +21,7 @@ gui_DATA = \ hscroll_right_pressed.png \ item_shortcut_bgr.png \ mouse.png \ + progress-indicator.png \ radioin.png \ radioin_highlight.png \ radioout.png \ diff --git a/data/graphics/gui/progress-indicator.png b/data/graphics/gui/progress-indicator.png Binary files differnew file mode 100644 index 00000000..907f334e --- /dev/null +++ b/data/graphics/gui/progress-indicator.png @@ -237,6 +237,8 @@ ./src/gui/widgets/popup.h ./src/gui/widgets/progressbar.cpp ./src/gui/widgets/progressbar.h +./src/gui/widgets/progressindicator.cpp +./src/gui/widgets/progressindicator.h ./src/gui/widgets/radiobutton.cpp ./src/gui/widgets/radiobutton.h ./src/gui/widgets/resizegrip.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fbf17f49..a7b1322b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,6 +152,8 @@ SET(SRCS gui/widgets/popup.h gui/widgets/progressbar.cpp gui/widgets/progressbar.h + gui/widgets/progressindicator.cpp + gui/widgets/progressindicator.h gui/widgets/radiobutton.cpp gui/widgets/radiobutton.h gui/widgets/resizegrip.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 3b9b711a..9d02ea84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -57,6 +57,8 @@ mana_SOURCES = gui/widgets/avatar.cpp \ gui/widgets/popup.h \ gui/widgets/progressbar.cpp \ gui/widgets/progressbar.h \ + gui/widgets/progressindicator.cpp \ + gui/widgets/progressindicator.h \ gui/widgets/radiobutton.cpp \ gui/widgets/radiobutton.h \ gui/widgets/resizegrip.cpp \ diff --git a/src/being.cpp b/src/being.cpp index 9331e8de..20d7319a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -638,12 +638,14 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const mUsedTargetCursor->draw(graphics, px, py); for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) + { if (*it) { if ((*it)->getAlpha() != mAlpha) (*it)->setAlpha(mAlpha); (*it)->draw(graphics, px, py); } + } } void Being::drawSpriteAt(Graphics *graphics, int x, int y) const @@ -652,12 +654,14 @@ void Being::drawSpriteAt(Graphics *graphics, int x, int y) const const int py = y - 32; for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) + { if (*it) { if ((*it)->getAlpha() != mAlpha) (*it)->setAlpha(mAlpha); (*it)->draw(graphics, px, py); } + } } void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) @@ -819,8 +823,8 @@ int Being::getWidth() const if (base) return std::max(base->getWidth(), DEFAULT_BEING_WIDTH); - else - return DEFAULT_BEING_WIDTH; + + return DEFAULT_BEING_WIDTH; } int Being::getHeight() const @@ -833,11 +837,11 @@ int Being::getHeight() const if (base) return std::max(base->getHeight(), DEFAULT_BEING_HEIGHT); - else - return DEFAULT_BEING_HEIGHT; + + return DEFAULT_BEING_HEIGHT; } -void Being::setTargetAnimation(SimpleAnimation* animation) +void Being::setTargetAnimation(SimpleAnimation *animation) { mUsedTargetCursor = animation; mUsedTargetCursor->reset(); @@ -889,13 +893,13 @@ static EffectDescription *getEffectDescription(int effectId) } else if (xmlStrEqual(node->name, BAD_CAST "default")) { - EffectDescription *EffectDescription = + EffectDescription *effectDescription = getEffectDescription(node, &id); if (default_effect) delete default_effect; - default_effect = EffectDescription; + default_effect = effectDescription; } } @@ -904,10 +908,7 @@ static EffectDescription *getEffectDescription(int effectId) EffectDescription *ed = effects[effectId]; - if (!ed) - return default_effect; - else - return ed; + return ed ? ed : default_effect; } void Being::internalTriggerEffect(int effectId, bool sfx, bool gfx) @@ -965,7 +966,6 @@ void Being::showName() mDispName = new FlashText(mDisplayName, getPixelX(), getPixelY(), gcn::Graphics::CENTER, mNameColor); - } int Being::getNumberOfLayers() const @@ -988,7 +988,5 @@ void Being::load() void Being::updateName() { if (mShowName) - { showName(); - } } diff --git a/src/being.h b/src/being.h index 39987daf..79bcc020 100644 --- a/src/being.h +++ b/src/being.h @@ -456,7 +456,7 @@ class Being : public Sprite, public ConfigListener /** * Sets the target animation for this being. */ - void setTargetAnimation(SimpleAnimation* animation); + void setTargetAnimation(SimpleAnimation *animation); /** * Untargets the being @@ -658,7 +658,7 @@ class Being : public Sprite, public ConfigListener int mDamageTaken; /** Target cursor being used */ - SimpleAnimation* mUsedTargetCursor; + SimpleAnimation *mUsedTargetCursor; }; #endif diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 4c7bbcbf..5452e275 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -26,26 +26,28 @@ #include "gui/widgets/button.h" #include "gui/widgets/label.h" -#include "gui/widgets/progressbar.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/progressindicator.h" #include "utils/gettext.h" -ConnectionDialog::ConnectionDialog(State previousState): - Window(_("Info")), mProgress(0), mPreviousState(previousState) +ConnectionDialog::ConnectionDialog(const std::string &text, + State cancelState): + Window(""), + mCancelState(cancelState) { - setContentSize(200, 100); + setTitleBarHeight(0); + setMovable(false); + setMinWidth(0); + ProgressIndicator *progressIndicator = new ProgressIndicator; + gcn::Label *label = new Label(text); Button *cancelButton = new Button(_("Cancel"), "cancelButton", this); - mProgressBar = new ProgressBar(0.0, 200 - 10, 20, gcn::Color(128, 128, 128)); - gcn::Label *label = new Label(_("Connecting...")); - cancelButton->setPosition(5, 100 - 5 - cancelButton->getHeight()); - mProgressBar->setPosition(5, cancelButton->getY() - 25); - label->setPosition(5, mProgressBar->getY() - 25); - - add(label); - add(cancelButton); - add(mProgressBar); + place(0, 0, progressIndicator); + place(0, 1, label); + place(0, 2, cancelButton).setHAlign(LayoutCell::CENTER); + reflowLayout(); center(); setVisible(true); @@ -54,16 +56,11 @@ ConnectionDialog::ConnectionDialog(State previousState): void ConnectionDialog::action(const gcn::ActionEvent &) { logger->log("Cancel pressed"); - state = mPreviousState; + state = mCancelState; } -void ConnectionDialog::logic() +void ConnectionDialog::draw(gcn::Graphics *graphics) { - mProgress += 0.005f; - - if (mProgress > 1.0f) - mProgress = 0.0f; - - mProgressBar->setProgress(mProgress); - Window::logic(); + // Don't draw the window background, only draw the children + drawChildren(graphics); } diff --git a/src/gui/connectiondialog.h b/src/gui/connectiondialog.h index ac799791..32da2b9a 100644 --- a/src/gui/connectiondialog.h +++ b/src/gui/connectiondialog.h @@ -28,8 +28,6 @@ #include <guichan/actionlistener.hpp> -class ProgressBar; - /** * The connection dialog. * @@ -39,11 +37,14 @@ class ConnectionDialog : public Window, gcn::ActionListener { public: /** - * Constructor + * Constructor. + * + * @param text The text to display + * @param cancelState The state to enter when Cancel is pressed * * @see Window::Window */ - ConnectionDialog(State previousState); + ConnectionDialog(const std::string &text, State cancelState); /** * Called when the user presses Cancel. Restores the global state to @@ -51,12 +52,11 @@ class ConnectionDialog : public Window, gcn::ActionListener */ void action(const gcn::ActionEvent &); - void logic(); + void draw(gcn::Graphics *graphics); private: - ProgressBar *mProgressBar; - float mProgress; - State mPreviousState; + gcn::Label *mLabel; + State mCancelState; }; #endif diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp new file mode 100644 index 00000000..d67dd101 --- /dev/null +++ b/src/gui/widgets/progressindicator.cpp @@ -0,0 +1,64 @@ +/* + * The Mana World + * Copyright (C) 2010 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "progressindicator.h" + +#include "resources/animation.h" +#include "resources/imageset.h" +#include "resources/resourcemanager.h" + +#include "graphics.h" +#include "simpleanimation.h" + +#include <guichan/widgets/label.hpp> + +ProgressIndicator::ProgressIndicator() +{ + ResourceManager *rm = ResourceManager::getInstance(); + ImageSet *images = rm->getImageSet("graphics/gui/progress-indicator.png", + 32, 32); + + Animation *anim = new Animation; + for (ImageSet::size_type i = 0; i < images->size(); ++i) + anim->addFrame(images->get(i), 100, 0, 0); + + mIndicator = new SimpleAnimation(anim); + + setSize(32, 32); +} + +ProgressIndicator::~ProgressIndicator() +{ + delete mIndicator; +} + +void ProgressIndicator::logic() +{ + mIndicator->update(10); +} + +void ProgressIndicator::draw(gcn::Graphics *graphics) +{ + // Draw the indicator centered on the widget + const int x = (getWidth() - 32) / 2; + const int y = (getHeight() - 32) / 2; + mIndicator->draw(static_cast<Graphics*>(graphics), x, y); +} diff --git a/src/gui/widgets/progressindicator.h b/src/gui/widgets/progressindicator.h new file mode 100644 index 00000000..91a44a28 --- /dev/null +++ b/src/gui/widgets/progressindicator.h @@ -0,0 +1,46 @@ +/* + * The Mana World + * Copyright (C) 2010 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PROGRESSINDICATOR_H +#define PROGRESSINDICATOR_H + +#include <guichan/widget.hpp> + +class SimpleAnimation; + +/** + * A widget that indicates progress. Suitable to use instead of a progress bar + * in cases where it is unknown how long something is going to take. + */ +class ProgressIndicator : public gcn::Widget +{ +public: + ProgressIndicator(); + ~ProgressIndicator(); + + void logic(); + void draw(gcn::Graphics *graphics); + +private: + SimpleAnimation *mIndicator; +}; + +#endif // PROGRESSINDICATOR_H diff --git a/src/main.cpp b/src/main.cpp index aec59ce5..b886545b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -572,7 +572,6 @@ static void parseOptions(int argc, char *argv[], Options &options) while (optind < argc) { - int result = getopt_long(argc, argv, optstring, long_options, NULL); if (result == -1) @@ -925,7 +924,8 @@ int main(int argc, char *argv[]) case STATE_CONNECT_SERVER: logger->log("State: CONNECT SERVER"); - currentDialog = new ConnectionDialog(STATE_SWITCH_SERVER); + currentDialog = new ConnectionDialog( + _("Connecting to server"), STATE_SWITCH_SERVER); break; case STATE_LOGIN: @@ -951,7 +951,8 @@ int main(int argc, char *argv[]) case STATE_LOGIN_ATTEMPT: logger->log("State: LOGIN ATTEMPT"); accountLogin(&loginData); - currentDialog = new ConnectionDialog(STATE_SWITCH_SERVER); + currentDialog = new ConnectionDialog( + _("Logging in"), STATE_SWITCH_SERVER); break; case STATE_WORLD_SELECT: @@ -983,7 +984,8 @@ int main(int argc, char *argv[]) case STATE_WORLD_SELECT_ATTEMPT: logger->log("State: WORLD SELECT ATTEMPT"); - currentDialog = new ConnectionDialog(STATE_WORLD_SELECT); + currentDialog = new ConnectionDialog( + _("Entering game world"), STATE_WORLD_SELECT); break; case STATE_UPDATE: @@ -1039,7 +1041,9 @@ int main(int argc, char *argv[]) case STATE_GET_CHARACTERS: logger->log("State: GET CHARACTERS"); Net::getCharHandler()->getCharacters(); - currentDialog = new ConnectionDialog(STATE_SWITCH_SERVER); + currentDialog = new ConnectionDialog( + _("Requesting characters"), + STATE_SWITCH_SERVER); break; case STATE_CHAR_SELECT: @@ -1072,7 +1076,9 @@ int main(int argc, char *argv[]) logger->log("State: CONNECT GAME"); Net::getGameHandler()->connect(); - currentDialog = new ConnectionDialog(STATE_SWITCH_CHARACTER); + currentDialog = new ConnectionDialog( + _("Connecting to the game server"), + STATE_SWITCH_CHARACTER); break; case STATE_GAME: @@ -1124,7 +1130,8 @@ int main(int argc, char *argv[]) case STATE_REGISTER_PREP: logger->log("State: REGISTER_PREP"); Net::getLoginHandler()->getRegistrationDetails(); - currentDialog = new ConnectionDialog(STATE_LOGIN); + currentDialog = new ConnectionDialog( + _("Requesting registration details"), STATE_LOGIN); break; case STATE_REGISTER: diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index af9db7be..18c882eb 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -28,8 +28,7 @@ Animation::Animation(): { } -void Animation::addFrame(Image *image, unsigned int delay, - int offsetX, int offsetY) +void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY) { Frame frame = { image, delay, offsetX, offsetY }; mFrames.push_back(frame); diff --git a/src/resources/animation.h b/src/resources/animation.h index 7a64eeb3..d5c171ab 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -51,8 +51,7 @@ class Animation /** * Appends a new animation at the end of the sequence. */ - void addFrame(Image *image, unsigned int delay, - int offsetX, int offsetY); + void addFrame(Image *image, int delay, int offsetX, int offsetY); /** * Appends an animation terminator that states that the animation diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index b90ee685..f13ed18b 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -19,9 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "simpleanimation.h" + #include "graphics.h" #include "log.h" -#include "simpleanimation.h" #include "resources/animation.h" #include "resources/image.h" @@ -37,11 +38,73 @@ SimpleAnimation::SimpleAnimation(Animation *animation): } SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): + mAnimation(new Animation), mAnimationTime(0), mAnimationPhase(0) { - mAnimation = new Animation; + initializeAnimation(animationNode); + mCurrentFrame = mAnimation->getFrame(0); +} + +SimpleAnimation::~SimpleAnimation() +{ + delete mAnimation; +} + +bool SimpleAnimation::draw(Graphics *graphics, int posX, int posY) const +{ + if (!mCurrentFrame || !mCurrentFrame->image) + return false; + + return graphics->drawImage(mCurrentFrame->image, + posX + mCurrentFrame->offsetX, + posY + mCurrentFrame->offsetY); +} + +void SimpleAnimation::reset() +{ + mAnimationTime = 0; + mAnimationPhase = 0; +} + +void SimpleAnimation::setFrame(int frame) +{ + if (frame < 0) + frame = 0; + if (frame >= mAnimation->getLength()) + frame = mAnimation->getLength() - 1; + mAnimationPhase = frame; + mCurrentFrame = mAnimation->getFrame(mAnimationPhase); +} + +void SimpleAnimation::update(int timePassed) +{ + mAnimationTime += timePassed; + + while (mAnimationTime > mCurrentFrame->delay && mCurrentFrame->delay > 0) + { + mAnimationTime -= mCurrentFrame->delay; + mAnimationPhase++; + + if (mAnimationPhase >= mAnimation->getLength()) + mAnimationPhase = 0; + + mCurrentFrame = mAnimation->getFrame(mAnimationPhase); + } +} + +int SimpleAnimation::getLength() const +{ + return mAnimation->getLength(); +} + +Image *SimpleAnimation::getCurrentImage() const +{ + return mCurrentFrame->image; +} +void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode) +{ ImageSet *imageset = ResourceManager::getInstance()->getImageSet( XML::getProperty(animationNode, "imageset", ""), XML::getProperty(animationNode, "width", 0), @@ -109,63 +172,4 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): mAnimation->addTerminator(); } } - - mCurrentFrame = mAnimation->getFrame(0); -} - -bool SimpleAnimation::draw(Graphics* graphics, int posX, int posY) const -{ - if (!mCurrentFrame || !mCurrentFrame->image) - return false; - - return graphics->drawImage(mCurrentFrame->image, - posX + mCurrentFrame->offsetX, - posY + mCurrentFrame->offsetY); -} - -void SimpleAnimation::reset() -{ - mAnimationTime = 0; - mAnimationPhase = 0; -} - -void SimpleAnimation::setFrame(int frame) -{ - if (frame < 0) - frame = 0; - if (frame >= mAnimation->getLength()) - frame = mAnimation->getLength() - 1; - mAnimationPhase = frame; - mCurrentFrame = mAnimation->getFrame(mAnimationPhase); -} - -void SimpleAnimation::update(int timePassed) -{ - mAnimationTime += timePassed; - - while (mAnimationTime > mCurrentFrame->delay && mCurrentFrame->delay > 0) - { - mAnimationTime -= mCurrentFrame->delay; - mAnimationPhase++; - - if (mAnimationPhase >= mAnimation->getLength()) - mAnimationPhase = 0; - - mCurrentFrame = mAnimation->getFrame(mAnimationPhase); - } -} - -int SimpleAnimation::getLength() const -{ - return mAnimation->getLength(); -} - -Image *SimpleAnimation::getCurrentImage() const -{ - return mCurrentFrame->image; -} - -SimpleAnimation::~SimpleAnimation() -{ - delete mAnimation; } diff --git a/src/simpleanimation.h b/src/simpleanimation.h index bf79f606..3fb95c44 100644 --- a/src/simpleanimation.h +++ b/src/simpleanimation.h @@ -37,7 +37,8 @@ class SimpleAnimation { public: /** - * Creates a simple animation with an already created animation. + * Creates a simple animation with an already created \a animation. + * Takes ownership over the given animation. */ SimpleAnimation(Animation *animation); @@ -54,7 +55,7 @@ class SimpleAnimation void update(int timePassed); - bool draw(Graphics* graphics, int posX, int posY) const; + bool draw(Graphics *graphics, int posX, int posY) const; /** * Resets the animation. @@ -64,6 +65,8 @@ class SimpleAnimation Image *getCurrentImage() const; private: + void initializeAnimation(xmlNodePtr animationNode); + /** The hosted animation. */ Animation *mAnimation; |