diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-02-07 19:07:04 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-02-07 19:07:04 +0100 |
commit | a3157908d23fd711ea96797dffce064953cb8fb6 (patch) | |
tree | 2f237b21118461a9948f3ccb829f62038564dedf /src/gui | |
parent | 1208d5383a9bfd03f338ccf71fb9764790b2e1a9 (diff) | |
download | mana-client-a3157908d23fd711ea96797dffce064953cb8fb6.tar.gz mana-client-a3157908d23fd711ea96797dffce064953cb8fb6.tar.bz2 mana-client-a3157908d23fd711ea96797dffce064953cb8fb6.tar.xz mana-client-a3157908d23fd711ea96797dffce064953cb8fb6.zip |
Nicer way of indicating that we're waiting on the server
No longer a dialog with an annoying progress bar (due to going back and
forth), but rather a progress indicator that integrates better with the
background.
Diffstat (limited to 'src/gui')
-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 |
4 files changed, 137 insertions, 30 deletions
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 |