summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-07-10 19:00:50 +0200
committerPhilipp Sehmisch <mana@crushnet.org>2010-07-10 19:00:50 +0200
commit105438d77ce83972d70a1ce67728aaf72c9ec2b6 (patch)
treeb290e4f106e33226bac0ada8c30377674683dfda /src/gui
parent9b72b2760e333e92877ec1e4d002fec6e612ad0e (diff)
downloadMana-105438d77ce83972d70a1ce67728aaf72c9ec2b6.tar.gz
Mana-105438d77ce83972d70a1ce67728aaf72c9ec2b6.tar.bz2
Mana-105438d77ce83972d70a1ce67728aaf72c9ec2b6.tar.xz
Mana-105438d77ce83972d70a1ce67728aaf72c9ec2b6.zip
Moved parsing of specials.xml from gui/specialswindow.cpp to separate source files.
Restored functional recharge bars in specials window. Individual specials are only shown after the server informed the client about their status. Made level label, use button and progress bars optional. Their use is controlled through specials.xml. The special window button is again shown even when the player has no specials. This problem needs to be solved differently now for architecture reasons. Reviewed-by: Jaxad0127
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/specialswindow.cpp177
-rw-r--r--src/gui/specialswindow.h20
-rw-r--r--src/gui/windowmenu.cpp2
3 files changed, 94 insertions, 105 deletions
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
index 44551825..4f9a9652 100644
--- a/src/gui/specialswindow.cpp
+++ b/src/gui/specialswindow.cpp
@@ -20,7 +20,6 @@
#include "gui/specialswindow.h"
-#include "localplayer.h"
#include "log.h"
#include "gui/setup.h"
@@ -42,6 +41,8 @@
#include "net/net.h"
#include "net/specialhandler.h"
+#include "resources/specialdb.h"
+
#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -54,31 +55,24 @@
class SpecialEntry;
-struct SpecialInfo
-{
- unsigned short id;
- std::string name;
- std::string icon;
- SpecialEntry *display;
-};
class SpecialEntry : public Container
{
public:
SpecialEntry(SpecialInfo *info);
- void update();
+ void update(int current, int needed);
protected:
friend class SpecialsWindow;
SpecialInfo *mInfo;
private:
- Icon *mIcon;
- Label *mNameLabel;
- Label *mLevelLabel;
- Label *mTechLabel;
- Button *mUse;
+ Icon *mIcon; // icon to display
+ Label *mNameLabel; // name to display
+ Label *mLevelLabel; // level number label (only shown when applicable)
+ Button *mUse; // use button (only shown when applicable)
+ ProgressBar *mRechargeBar; // recharge bar (only shown when applicable)
};
SpecialsWindow::SpecialsWindow():
@@ -102,7 +96,6 @@ SpecialsWindow::SpecialsWindow():
SpecialsWindow::~SpecialsWindow()
{
// Clear gui
- loadSpecials("");
}
void SpecialsWindow::action(const gcn::ActionEvent &event)
@@ -127,91 +120,70 @@ void SpecialsWindow::action(const gcn::ActionEvent &event)
}
}
-std::string SpecialsWindow::update(int id)
-{
- // TODO
-
- return std::string();
-}
-
-void SpecialsWindow::loadSpecials(const std::string &file)
+void SpecialsWindow::draw(gcn::Graphics *graphics)
{
- // TODO: mTabs->clear();
- while (mTabs->getSelectedTabIndex() != -1)
+ // update the progress bars
+ std::map<int, Special> specialData = player_node->getSpecialStatus();
+ bool foundNew = false;
+ unsigned int found = 0; // number of entries in specialData which match mEntries
+
+ for (std::map<int, Special>::iterator i = specialData.begin();
+ i != specialData.end();
+ i++)
{
- mTabs->removeTabWithIndex(mTabs->getSelectedTabIndex());
- }
-
- for (SpecialMap::iterator it = mSpecials.begin(); it != mSpecials.end(); it++)
- {
- delete (*it).second->display;
+ std::map<int, SpecialEntry *>::iterator e = mEntries.find(i->first);
+ if (e == mEntries.end())
+ {
+ // found a new special - abort update and rebuild from scratch
+ foundNew = true;
+ break;
+ } else {
+ // update progress bar of special
+ e->second->update(i->second.currentMana, i->second.neededMana);
+ found++;
+ }
}
- delete_all(mSpecials);
- mSpecials.clear();
+ // a rebuild is needed when a) the number of specials changed or b) an existing entry isn't found anymore
+ if (foundNew || found != mEntries.size()) rebuild(specialData);
- if (file.length() == 0)
- return;
+ Window::draw(graphics);
+}
- XML::Document doc(file);
- xmlNodePtr root = doc.rootNode();
+void SpecialsWindow::rebuild(const std::map<int, Special> &specialData)
+{
+ make_dtor(mEntries);
+ mEntries.clear();
+ int vPos = 0; //vertical position of next placed element
- if (!root || !xmlStrEqual(root->name, BAD_CAST "specials"))
+ for (std::map<int, Special>::const_iterator i = specialData.begin();
+ i != specialData.end();
+ i++)
{
- logger->log("Error loading specials file: %s", file.c_str());
- return;
- }
-
- int setCount = 0;
- std::string setName;
- ScrollArea *scroll;
- FlowContainer *container;
+ logger->log("Updating special GUI for %d", i->first);
- for_each_xml_child_node(set, root)
- {
- if (xmlStrEqual(set->name, BAD_CAST "set"))
+ SpecialInfo* info = SpecialDB::get(i->first);
+ if (info)
{
- setCount++;
- setName = XML::getProperty(set, "name", strprintf(_("Specials Set %d"), setCount));
-
- container = new FlowContainer(SPECIALS_WIDTH, SPECIALS_HEIGHT);
- container->setOpaque(false);
- scroll = new ScrollArea(container);
- scroll->setOpaque(false);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
-
- mTabs->addTab(setName, scroll);
- for_each_xml_child_node(node, set)
- {
- if (xmlStrEqual(node->name, BAD_CAST "special"))
- {
- int id = atoi(XML::getProperty(node, "id", "-1").c_str());
- if (id == -1)
- continue;
- std::string name = XML::getProperty(node, "name", strprintf(_("Special %d"), id));
- std::string icon = XML::getProperty(node, "icon", "");
-
- SpecialInfo *special = new SpecialInfo;
- special->id = id;
- special->name = name;
- special->icon = icon;
- special->display = new SpecialEntry(special);
-
- container->add(special->display);
-
- mSpecials[id] = special;
- }
- }
+ info->rechargeCurrent = i->second.currentMana;
+ info->rechargeNeeded = i->second.neededMana;
+ SpecialEntry* entry = new SpecialEntry(info);
+ entry->setPosition(0, vPos);
+ vPos += entry->getHeight();
+ add(entry);
+ mEntries[i->first] = entry;
+ } else {
+ logger->log("Warning: No info available of special %d", i->first);
}
}
}
+
SpecialEntry::SpecialEntry(SpecialInfo *info) :
mInfo(info),
mIcon(NULL),
- mNameLabel(new Label(info->name)),
- mLevelLabel(new Label("999")),
- mUse(new Button("Use", "use", specialsWindow))
+ mLevelLabel(NULL),
+ mUse(NULL),
+ mRechargeBar(NULL)
{
setFrameSize(1);
setOpaque(false);
@@ -225,21 +197,42 @@ SpecialEntry::SpecialEntry(SpecialInfo *info) :
mIcon->setPosition(1, 0);
add(mIcon);
+
+ mNameLabel = new Label(info->name);
mNameLabel->setPosition(35, 0);
add(mNameLabel);
- mLevelLabel->setPosition(getWidth() - mLevelLabel->getWidth(), 0);
- add(mLevelLabel);
+ if (info->hasLevel)
+ {
+ mLevelLabel = new Label(toString(info->level));
+ mLevelLabel->setPosition(getWidth() - mLevelLabel->getWidth(), 0);
+ add(mLevelLabel);
+ }
+
- mNameLabel->setWidth(mLevelLabel->getX() - mNameLabel->getX() - 1);
+ if (info->isActive)
+ {
+ mUse = new Button("Use", "use", specialsWindow);
+ mUse->setPosition(getWidth() - mUse->getWidth(), 13);
+ add(mUse);
+ }
- mUse->setPosition(getWidth() - mUse->getWidth(), 13);
- add(mUse);
+ if (info->hasRechargeBar)
+ {
+ float progress = (float)info->rechargeCurrent / (float)info->rechargeNeeded;
+ mRechargeBar = new ProgressBar(progress, 100, 10, Theme::PROG_MP);
+ mRechargeBar->setSmoothProgress(false);
+ mRechargeBar->setPosition(0, 13);
+ add(mRechargeBar);
+ }
- update();
}
-void SpecialEntry::update()
+void SpecialEntry::update(int current, int needed)
{
- // TODO
+ if (mRechargeBar)
+ {
+ float progress = (float)current / (float)needed;
+ mRechargeBar->setProgress(progress);
+ }
}
diff --git a/src/gui/specialswindow.h b/src/gui/specialswindow.h
index 81384856..634727e5 100644
--- a/src/gui/specialswindow.h
+++ b/src/gui/specialswindow.h
@@ -25,6 +25,8 @@
#include "guichanfwd.h"
+#include "localplayer.h"
+
#include "gui/widgets/window.h"
#include <guichan/actionlistener.hpp>
@@ -36,7 +38,7 @@ class ScrollArea;
class Tab;
class TabbedArea;
-struct SpecialInfo;
+struct SpecialEntry;
class SpecialsWindow : public Window, public gcn::ActionListener {
public:
@@ -49,20 +51,14 @@ class SpecialsWindow : public Window, public gcn::ActionListener {
*/
void action(const gcn::ActionEvent &actionEvent);
- /**
- * Update the given special's display
- */
- std::string update(int id);
-
- void loadSpecials(const std::string &file);
-
- bool hasSpecials() { return !mSpecials.empty(); }
+ void draw(gcn::Graphics *graphics);
private:
- std::vector<gcn::Button *> mSpellButtons;
- typedef std::map<int, SpecialInfo*> SpecialMap;
- SpecialMap mSpecials;
+ // (re)constructs the list of specials
+ void rebuild(const std::map<int, Special> &specialData);
+
TabbedArea *mTabs;
+ std::map<int, SpecialEntry *> mEntries;
};
extern SpecialsWindow *specialsWindow;
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 5af5a202..76e6bc1f 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -58,7 +58,7 @@ WindowMenu::WindowMenu():
if (skillDialog->hasSkills())
addButton(N_("Skills"), x, h);
- if (specialsWindow->hasSpecials())
+ // if (specialsWindow->hasSpecials())
addButton(N_("Specials"), x, h);
addButton(N_("Social"), x, h);