summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/charcreatedialog.cpp46
-rw-r--r--src/gui/charcreatedialog.h8
-rw-r--r--src/gui/charselectdialog.h3
-rw-r--r--src/gui/chat.cpp43
-rw-r--r--src/gui/chat.h8
-rw-r--r--src/gui/magic.cpp113
-rw-r--r--src/gui/playerbox.cpp6
-rw-r--r--src/gui/skilldialog.cpp50
-rw-r--r--src/gui/skilldialog.h12
-rw-r--r--src/gui/specialswindow.cpp244
-rw-r--r--src/gui/specialswindow.h (renamed from src/gui/magic.h)52
-rw-r--r--src/gui/widgets/flowcontainer.cpp78
-rw-r--r--src/gui/widgets/flowcontainer.h68
-rw-r--r--src/gui/widgets/scrollarea.cpp5
-rw-r--r--src/gui/widgets/scrollarea.h5
-rw-r--r--src/gui/widgets/tabbedarea.cpp20
-rw-r--r--src/gui/widgets/tabbedarea.h13
-rw-r--r--src/gui/windowmenu.cpp10
18 files changed, 519 insertions, 265 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index e09eee55..7c2b0ed9 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -59,8 +59,9 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot):
int numberOfHairColors = ColorDB::size();
- mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(),
- rand() % numberOfHairColors);
+ mHairStyle = rand() % mPlayer->getNumOfHairstyles();
+ mHairColor = rand() % numberOfHairColors;
+ updateHair();
mNameField = new TextField("");
mNameLabel = new Label(_("Name:"));
@@ -153,7 +154,6 @@ CharCreateDialog::~CharCreateDialog()
void CharCreateDialog::action(const gcn::ActionEvent &event)
{
- int numberOfColors = ColorDB::size();
if (event.getId() == "create")
{
if (getName().length() >= 4)
@@ -168,8 +168,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
}
Net::getCharHandler()->newCharacter(getName(), mSlot,
- mFemale->isSelected(), mPlayer->getHairStyle(),
- mPlayer->getHairColor(), atts);
+ mFemale->isSelected(), mHairStyle,
+ mHairColor, atts);
}
else
{
@@ -181,19 +181,25 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
else if (event.getId() == "cancel")
scheduleDelete();
else if (event.getId() == "nextcolor")
- mPlayer->setHairStyle(mPlayer->getHairStyle(),
- (mPlayer->getHairColor() + 1) % numberOfColors);
+ {
+ mHairColor++;
+ updateHair();
+ }
else if (event.getId() == "prevcolor")
- mPlayer->setHairStyle(mPlayer->getHairStyle(),
- (mPlayer->getHairColor() + numberOfColors - 1) %
- numberOfColors);
+ {
+ mHairColor--;
+ updateHair();
+ }
else if (event.getId() == "nextstyle")
- mPlayer->setHairStyle(mPlayer->getHairStyle() + 1,
- mPlayer->getHairColor());
+ {
+ mHairStyle++;
+ updateHair();
+ }
else if (event.getId() == "prevstyle")
- mPlayer->setHairStyle(mPlayer->getHairStyle() +
- mPlayer->getNumOfHairstyles() - 1,
- mPlayer->getHairColor());
+ {
+ mHairStyle--;
+ updateHair();
+ }
else if (event.getId() == "statslider") {
updateSliders();
}
@@ -334,3 +340,13 @@ void CharCreateDialog::setFixedGender(bool fixed, Gender gender)
mFemale->setEnabled(false);
}
}
+
+void CharCreateDialog::updateHair()
+{
+ mHairStyle %= Being::getNumOfHairstyles();
+
+ mHairColor %= ColorDB::size();
+
+ mPlayer->setSprite(Player::HAIR_SPRITE,
+ mHairStyle * -1, ColorDB::get(mHairColor));
+}
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
index 5dbc6050..a30aadd3 100644
--- a/src/gui/charcreatedialog.h
+++ b/src/gui/charcreatedialog.h
@@ -22,7 +22,7 @@
#ifndef CHAR_CREATE_H
#define CHAR_CREATE_H
-#include "being.h"
+#include "player.h"
#include "guichanfwd.h"
#include "lockedarray.h"
@@ -34,7 +34,6 @@
#include <vector>
class LocalPlayer;
-class Player;
class PlayerBox;
/**
@@ -82,6 +81,8 @@ class CharCreateDialog : public Window, public gcn::ActionListener
*/
void attemptCharCreate();
+ void updateHair();
+
gcn::TextField *mNameField;
gcn::Label *mNameLabel;
gcn::Button *mNextHairColorButton;
@@ -108,6 +109,9 @@ class CharCreateDialog : public Window, public gcn::ActionListener
Player *mPlayer;
PlayerBox *mPlayerBox;
+ int mHairStyle;
+ int mHairColor;
+
int mSlot;
};
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 06ce4b55..4427017e 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -24,7 +24,7 @@
#include "gui/widgets/window.h"
-#include "being.h"
+#include "player.h"
#include "guichanfwd.h"
#include "lockedarray.h"
@@ -32,7 +32,6 @@
class LocalPlayer;
class LoginData;
-class Player;
class PlayerBox;
/**
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index c337d33b..f1814d93 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -98,8 +98,8 @@ ChatWindow::ChatWindow():
mChatTabs = new TabbedArea;
- add(mChatTabs);
- add(mChatInput);
+ place(0, 0, mChatTabs, 3, 3);
+ place(0, 3, mChatInput, 3);
loadWindowState();
@@ -126,40 +126,6 @@ void ChatWindow::resetToDefaultSize()
Window::resetToDefaultSize();
}
-void ChatWindow::adjustTabSize()
-{
- const gcn::Rectangle area = getChildrenArea();
-
- mChatInput->setPosition(mChatInput->getFrameSize(),
- area.height - mChatInput->getHeight() -
- mChatInput->getFrameSize());
- mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize());
-
- mChatTabs->setWidth(area.width - 2 * mChatTabs->getFrameSize());
- mChatTabs->setHeight(area.height - 2 * mChatTabs->getFrameSize() -
- (mChatInput->getHeight() + mChatInput->getFrameSize() * 2));
-
- ChatTab *tab = getFocused();
- if (tab) {
- gcn::Widget *content = tab->mScrollArea;
- bool scrollLock = false;
- if(tab->mScrollArea->getVerticalMaxScroll() == tab->mScrollArea->getVerticalScrollAmount())
- scrollLock = true;
- content->setSize(mChatTabs->getWidth() - 2 * content->getFrameSize(),
- mChatTabs->getContainerHeight() - 2 * content->getFrameSize());
- content->logic();
- if(scrollLock)
- tab->mScrollArea->setVerticalScrollAmount(tab->mScrollArea->getVerticalMaxScroll());
- }
-}
-
-void ChatWindow::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- adjustTabSize();
-}
-
void ChatWindow::logic()
{
Window::logic();
@@ -167,7 +133,6 @@ void ChatWindow::logic()
Tab *tab = getFocused();
if (tab != mCurrentTab) {
mCurrentTab = tab;
- adjustTabSize();
}
}
@@ -291,10 +256,6 @@ void ChatWindow::addTab(ChatTab *tab)
mChatTabs->addTab(tab, tab->mScrollArea);
- // Fix for layout issues when adding the first tab
- if (tab == localChatTab)
- adjustTabSize();
-
// Update UI
logic();
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 2de3a634..af5f760b 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -74,12 +74,6 @@ class ChatWindow : public Window,
*/
~ChatWindow();
- /**
- * Called when the widget changes size. Used for adapting the size of
- * the tabbed area.
- */
- void widgetResized(const gcn::Event &event);
-
void logic();
/**
@@ -193,8 +187,6 @@ class ChatWindow : public Window,
void removeWhisper(const std::string &nick);
- void adjustTabSize();
-
/** Used for showing item popup on clicking links **/
ItemLinkHandler *mItemLinkHandler;
Recorder *mRecorder;
diff --git a/src/gui/magic.cpp b/src/gui/magic.cpp
deleted file mode 100644
index 6e314656..00000000
--- a/src/gui/magic.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 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 "gui/magic.h"
-
-#include "gui/widgets/button.h"
-#include "gui/setup.h"
-
-#include "localplayer.h"
-
-#include "utils/dtor.h"
-#include "utils/gettext.h"
-
-MagicDialog::MagicDialog():
- Window(_("Magic"))
-{
- setWindowName("Magic");
- setCloseButton(true);
- setSaveVisible(true);
- setDefaultSize(255, 30, 175, 225);
- setupWindow->registerWindowForReset(this);
-
- mSpellButtons.resize(4);
-
- mSpellButtons[1] = new Button(_("Spell 1"), "spell_1", this);
- mSpellButtons[2] = new Button(_("Spell 2"), "spell_2", this);
- mSpellButtons[3] = new Button(_("Spell 3"), "spell_3", this);
-
- mSpellButtons[1]->setPosition(10, 60);
- mSpellButtons[2]->setPosition(10, 90);
- mSpellButtons[3]->setPosition(10, 120);
-
- add(mSpellButtons[1]);
- add(mSpellButtons[2]);
- add(mSpellButtons[3]);
-
- update();
-
- setLocationRelativeTo(getParent());
- loadWindowState();
-}
-
-MagicDialog::~MagicDialog()
-{
-}
-
-void MagicDialog::action(const gcn::ActionEvent &event)
-{
- if (event.getId() == "spell_1")
- {
- player_node->useSpecial(1);
- }
- if (event.getId() == "spell_2")
- {
- player_node->useSpecial(2);
- }
- if (event.getId() == "spell_3")
- {
- player_node->useSpecial(3);
- }
- else if (event.getId() == "close")
- {
- setVisible(false);
- }
-}
-
-void MagicDialog::draw(gcn::Graphics *g)
-{
- update();
-
- Window::draw(g);
-}
-
-void MagicDialog::update()
-{
- std::map<int, Special> specials = player_node->getSpecialStatus();
-
- for (size_t i = 1; i < mSpellButtons.size(); i++)
- {
- if (specials.find(i) != specials.end())
- {
- std::stringstream s;
- s <<
- "Spell" <<
- i <<
- " (" <<
- specials[i].currentMana <<
- "/" <<
- specials[i].neededMana <<
- ")";
- mSpellButtons[i]->setCaption(s.str());
- mSpellButtons[i]->adjustSize();
- }
- }
-}
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index d00194bd..9a1f4805 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -82,11 +82,11 @@ void PlayerBox::draw(gcn::Graphics *graphics)
{
// Draw character
const int bs = getFrameSize();
-#ifdef TMWSERV_SUPPORT
+//#ifdef TMWSERV_SUPPORT
const int x = getWidth() / 2 + bs;
const int y = getHeight() - bs - 8;
mPlayer->draw(static_cast<Graphics*>(graphics), x, y);
-#else
+/*#else
const int x = getWidth() / 2 - 16 + bs;
const int y = getHeight() / 2 + bs;
for (int i = 0; i < Being::VECTOREND_SPRITE; i++)
@@ -96,7 +96,7 @@ void PlayerBox::draw(gcn::Graphics *graphics)
mPlayer->getSprite(i)->draw(static_cast<Graphics*>(graphics), x, y);
}
}
-#endif
+#endif*/
}
if (config.getValue("guialpha", 0.8) != mAlpha)
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 14e0e5a4..6e7b3e70 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -47,7 +47,6 @@
#include "utils/xml.h"
#include <string>
-#include <vector>
class SkillEntry;
@@ -96,7 +95,7 @@ SkillDialog::SkillDialog():
mPointsLabel = new Label("0");
place(0, 0, mTabs, 5, 5);
- place(0, 5, mPointsLabel);
+ place(0, 5, mPointsLabel, 2);
setLocationRelativeTo(getParent());
loadWindowState();
@@ -104,7 +103,8 @@ SkillDialog::SkillDialog():
SkillDialog::~SkillDialog()
{
- //delete_all(mTabs);
+ // Clear gui
+ loadSkills("");
}
void SkillDialog::action(const gcn::ActionEvent &event)
@@ -122,36 +122,6 @@ void SkillDialog::action(const gcn::ActionEvent &event)
}
}
-void SkillDialog::adjustTabSize()
-{
- gcn::Widget *content = mTabs->getCurrentWidget();
- if (content) {
- int width = mTabs->getWidth() - 2 * content->getFrameSize() - 2 * mTabs->getFrameSize();
- int height = mTabs->getContainerHeight() - 2 * content->getFrameSize();
- content->setSize(width, height);
- content->setVisible(true);
- content->logic();
- }
-}
-
-void SkillDialog::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- adjustTabSize();
-}
-
-void SkillDialog::logic()
-{
- Window::logic();
-
- Tab *tab = dynamic_cast<Tab*>(mTabs->getSelectedTab());
- if (tab != mCurrentTab) {
- mCurrentTab = tab;
- adjustTabSize();
- }
-}
-
std::string SkillDialog::update(int id)
{
SkillMap::iterator i = mSkills.find(id);
@@ -182,9 +152,21 @@ void SkillDialog::update()
void SkillDialog::loadSkills(const std::string &file)
{
// TODO: mTabs->clear();
+ while (mTabs->getSelectedTabIndex() != -1)
+ {
+ mTabs->removeTabWithIndex(mTabs->getSelectedTabIndex());
+ }
+
+ for (SkillMap::iterator it = mSkills.begin(); it != mSkills.end(); it++)
+ {
+ delete (*it).second->display;
+ }
delete_all(mSkills);
mSkills.clear();
+ if (file.length() == 0)
+ return;
+
XML::Document doc(file);
xmlNodePtr root = doc.rootNode();
@@ -236,8 +218,6 @@ void SkillDialog::loadSkills(const std::string &file)
}
}
}
-
- adjustTabSize();
update();
}
diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h
index ce8f091a..12cb3581 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -28,7 +28,6 @@
#include <guichan/actionlistener.hpp>
-#include <list>
#include <map>
class Label;
@@ -56,14 +55,6 @@ class SkillDialog : public Window, public gcn::ActionListener
void action(const gcn::ActionEvent &event);
/**
- * Called when the widget changes size. Used for adapting the size of
- * the tabbed area.
- */
- void widgetResized(const gcn::Event &event);
-
- void logic();
-
- /**
* Update the given skill's display
*/
std::string update(int id);
@@ -78,11 +69,8 @@ class SkillDialog : public Window, public gcn::ActionListener
void setModifiable(int id, bool modifiable);
private:
- void adjustTabSize();
-
typedef std::map<int, SkillInfo*> SkillMap;
SkillMap mSkills;
- Tab *mCurrentTab;
TabbedArea *mTabs;
Label *mPointsLabel;
};
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
new file mode 100644
index 00000000..35839b39
--- /dev/null
+++ b/src/gui/specialswindow.cpp
@@ -0,0 +1,244 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 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 "gui/specialswindow.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/container.h"
+#include "gui/widgets/icon.h"
+#include "gui/widgets/label.h"
+#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/listbox.h"
+#include "gui/widgets/progressbar.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/tab.h"
+#include "gui/widgets/tabbedarea.h"
+#include "gui/widgets/flowcontainer.h"
+#include "gui/widgets/windowcontainer.h"
+#include "gui/setup.h"
+
+#include "localplayer.h"
+#include "log.h"
+
+#include "net/net.h"
+#include "net/specialhandler.h"
+
+#include "utils/dtor.h"
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+#include "utils/xml.h"
+
+#include <string>
+
+#define SPECIALS_WIDTH 200
+#define SPECIALS_HEIGHT 32
+
+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();
+
+ protected:
+ friend class SpecialsWindow;
+ SpecialInfo *mInfo;
+
+ private:
+ Icon *mIcon;
+ Label *mNameLabel;
+ Label *mLevelLabel;
+ Label *mTechLabel;
+ Button *mUse;
+};
+
+SpecialsWindow::SpecialsWindow():
+ Window(_("Specials"))
+{
+ setWindowName("Specials");
+ setCloseButton(true);
+ setResizable(true);
+ setSaveVisible(true);
+ setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
+ setupWindow->registerWindowForReset(this);
+
+ mTabs = new TabbedArea();
+
+ place(0, 0, mTabs, 5, 5);
+
+ setLocationRelativeTo(getParent());
+ loadWindowState();
+}
+
+SpecialsWindow::~SpecialsWindow()
+{
+ // Clear gui
+ loadSpecials("");
+}
+
+void SpecialsWindow::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "use")
+ {
+ SpecialEntry *disp = dynamic_cast<SpecialEntry*>(event.getSource()->getParent());
+
+ if (disp)
+ {
+ /*Being *target = player_node->getTarget();
+
+ if (target)
+ Net::getSpecialHandler()->use(disp->mInfo->id, 1, target->getId());
+ else*/
+ Net::getSpecialHandler()->use(disp->mInfo->id);
+ }
+ }
+ else if (event.getId() == "close")
+ {
+ setVisible(false);
+ }
+}
+
+std::string SpecialsWindow::update(int id)
+{
+ // TODO
+
+ return std::string();
+}
+
+void SpecialsWindow::loadSpecials(const std::string &file)
+{
+ // TODO: mTabs->clear();
+ while (mTabs->getSelectedTabIndex() != -1)
+ {
+ mTabs->removeTabWithIndex(mTabs->getSelectedTabIndex());
+ }
+
+ for (SpecialMap::iterator it = mSpecials.begin(); it != mSpecials.end(); it++)
+ {
+ delete (*it).second->display;
+ }
+ delete_all(mSpecials);
+ mSpecials.clear();
+
+ if (file.length() == 0)
+ return;
+
+ XML::Document doc(file);
+ xmlNodePtr root = doc.rootNode();
+
+ if (!root || !xmlStrEqual(root->name, BAD_CAST "specials"))
+ {
+ logger->log("Error loading specials file: %s", file.c_str());
+ return;
+ }
+
+ int setCount = 0;
+ std::string setName;
+ ScrollArea *scroll;
+ FlowContainer *container;
+
+ for_each_xml_child_node(set, root)
+ {
+ if (xmlStrEqual(set->name, BAD_CAST "set"))
+ {
+ 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;
+ }
+ }
+ }
+ }
+}
+
+SpecialEntry::SpecialEntry(SpecialInfo *info) :
+ mInfo(info),
+ mIcon(NULL),
+ mNameLabel(new Label(info->name)),
+ mLevelLabel(new Label("999")),
+ mUse(new Button("Use", "use", specialsWindow))
+{
+ setFrameSize(1);
+ setOpaque(false);
+ setSize(SPECIALS_WIDTH, SPECIALS_HEIGHT);
+
+ if (!info->icon.empty())
+ mIcon = new Icon(info->icon);
+ else
+ mIcon = new Icon("graphics/gui/unknown-item.png");
+
+ mIcon->setPosition(1, 0);
+ add(mIcon);
+
+ mNameLabel->setPosition(35, 0);
+ add(mNameLabel);
+
+ mLevelLabel->setPosition(getWidth() - mLevelLabel->getWidth(), 0);
+ add(mLevelLabel);
+
+ mNameLabel->setWidth(mLevelLabel->getX() - mNameLabel->getX() - 1);
+
+ mUse->setPosition(getWidth() - mUse->getWidth(), 13);
+ add(mUse);
+
+ update();
+}
+
+void SpecialEntry::update()
+{
+ // TODO
+}
diff --git a/src/gui/magic.h b/src/gui/specialswindow.h
index 44a1a6fc..cd92c065 100644
--- a/src/gui/magic.h
+++ b/src/gui/specialswindow.h
@@ -1,6 +1,6 @@
/*
* The Mana World
- * Copyright (C) 2004 The Mana World Development Team
+ * Copyright (C) 2009 The Mana World Development Team
*
* This file is part of The Mana World.
*
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef MAGIC_H
-#define MAGIC_H
+#ifndef SPECIALSWINDOW_H
+#define SPECIALSWINDOW_H
#include <vector>
@@ -30,43 +30,41 @@
#include <guichan/actionlistener.hpp>
-/**
- * The magic interface.
- *
- * This window is hacked together quickly to test the spell
- * recharge netcode.
- * It does in no way represent how the interface is going to
- * look in the final version. Optimization / cleanup is
- * pointless, as it will be redesigned from scratch.
- *
- * \ingroup Interface
- */
-class MagicDialog : public Window, public gcn::ActionListener
-{
+
+#include <map>
+
+class Label;
+class ScrollArea;
+class Tab;
+class TabbedArea;
+
+struct SpecialInfo;
+
+class SpecialsWindow : public Window, public gcn::ActionListener {
public:
- MagicDialog();
+ SpecialsWindow();
- ~MagicDialog();
+ ~SpecialsWindow();
/**
* Called when receiving actions from widget.
*/
- void action(const gcn::ActionEvent &event);
+ void action(const gcn::ActionEvent &actionEvent);
/**
- * Update the tabs in this dialog
+ * Update the given special's display
*/
- void update();
+ std::string update(int id);
- /**
- * Draw this window.
- */
- void draw(gcn::Graphics *g);
+ void loadSpecials(const std::string &file);
private:
std::vector<gcn::Button *> mSpellButtons;
+ typedef std::map<int, SpecialInfo*> SpecialMap;
+ SpecialMap mSpecials;
+ TabbedArea *mTabs;
};
-extern MagicDialog *magicDialog;
+extern SpecialsWindow *specialsWindow;
-#endif
+#endif // SPECIALSWINDOW_H
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
new file mode 100644
index 00000000..6ce4284b
--- /dev/null
+++ b/src/gui/widgets/flowcontainer.cpp
@@ -0,0 +1,78 @@
+/*
+ * The Mana World
+ * Copyright (C) 2007 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 "flowcontainer.h"
+
+FlowContainer::FlowContainer(int boxWidth, int boxHeight):
+ mBoxWidth(boxWidth), mBoxHeight(boxHeight),
+ mGridWidth(1), mGridHeight(1)
+{
+ addWidgetListener(this);
+}
+
+void FlowContainer::widgetResized(const gcn::Event &event)
+{
+ if (getWidth() < mBoxWidth)
+ {
+ setWidth(mBoxWidth);
+ return;
+ }
+
+ int itemCount = mWidgets.size();
+
+ mGridWidth = getWidth() / mBoxWidth;
+
+ if (mGridWidth < 1)
+ mGridWidth = 1;
+
+ mGridHeight = itemCount / mGridWidth;
+
+ if (itemCount % mGridWidth != 0 || mGridHeight < 1)
+ ++mGridHeight;
+
+ int height = mGridHeight * mBoxHeight;
+
+ if (getHeight() != height)
+ {
+ setHeight(height);
+ return;
+ }
+
+ int i = 0;
+ height = 0;
+ for (WidgetList::iterator it = mWidgets.begin(); it != mWidgets.end(); it++)
+ {
+ int x = i % mGridWidth * mBoxWidth;
+ (*it)->setPosition(x, height);
+
+ i++;
+
+ if (i % mGridWidth == 0)
+ height += mBoxHeight;
+ }
+}
+
+void FlowContainer::add(gcn::Widget *widget)
+{
+ Container::add(widget);
+ widget->setSize(mBoxWidth, mBoxHeight);
+ widgetResized(NULL);
+}
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
new file mode 100644
index 00000000..afecde25
--- /dev/null
+++ b/src/gui/widgets/flowcontainer.h
@@ -0,0 +1,68 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 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 FLOWCONTAINER_H
+#define FLOWCONTAINER_H
+
+#include "container.h"
+
+#include <guichan/widgetlistener.hpp>
+
+/**
+ * A container that arranges its contents like words on a page.
+ *
+ * \ingroup GUI
+ */
+class FlowContainer : public Container,
+ public gcn::WidgetListener
+{
+ public:
+ /**
+ * Constructor. Initializes the shortcut container.
+ */
+ FlowContainer(int boxWidth, int boxHeight);
+
+ /**
+ * Destructor.
+ */
+ ~FlowContainer() {}
+
+ /**
+ * Invoked when a widget changes its size. This is used to determine
+ * the new height of the container.
+ */
+ void widgetResized(const gcn::Event &event);
+
+ int getBoxWidth() const
+ { return mBoxWidth; }
+
+ int getBoxHeight() const
+ { return mBoxHeight; }
+
+ void add(gcn::Widget *widget);
+
+ private:
+ int mBoxWidth;
+ int mBoxHeight;
+ int mGridWidth, mGridHeight;
+};
+
+#endif
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 52322b05..6cf27bb6 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -42,6 +42,7 @@ ScrollArea::ScrollArea():
mY(0),
mOpaque(true)
{
+ addWidgetListener(this);
init();
}
@@ -346,3 +347,7 @@ void ScrollArea::mouseExited(gcn::MouseEvent& event)
mHasMouse = false;
}
+void ScrollArea::widgetResized(const gcn::Event &event)
+{
+ getContent()->setSize(getWidth() - 2 * getFrameSize(), getHeight() - 2 * getFrameSize());
+}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 8fd92b5f..69e99b1f 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -23,6 +23,7 @@
#define SCROLLAREA_H
#include <guichan/widgets/scrollarea.hpp>
+#include <guichan/widgetlistener.hpp>
class Image;
class ImageRect;
@@ -36,7 +37,7 @@ class ImageRect;
*
* \ingroup GUI
*/
-class ScrollArea : public gcn::ScrollArea
+class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener
{
public:
/**
@@ -98,6 +99,8 @@ class ScrollArea : public gcn::ScrollArea
*/
void mouseExited(gcn::MouseEvent& event);
+ void widgetResized(const gcn::Event &event);
+
protected:
enum BUTTON_DIR {
UP,
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index bb5ae9a4..13bb884b 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -27,6 +27,7 @@
TabbedArea::TabbedArea() : gcn::TabbedArea()
{
mWidgetContainer->setOpaque(false);
+ addWidgetListener(this);
}
int TabbedArea::getNumberOfTabs() const
@@ -79,6 +80,15 @@ gcn::Widget *TabbedArea::getCurrentWidget()
return NULL;
}
+void TabbedArea::addTab(gcn::Tab* tab, gcn::Widget* widget)
+{
+ gcn::TabbedArea::addTab(tab, widget);
+
+ int width = getWidth() - 2 * getFrameSize();
+ int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight();
+ widget->setSize(width, height);
+}
+
void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget)
{
Tab *tab = new Tab;
@@ -152,3 +162,13 @@ void TabbedArea::setSelectedTab(gcn::Tab *tab)
if (newTab)
newTab->setCurrent();
}
+
+void TabbedArea::widgetResized(const gcn::Event &event)
+{
+ int width = getWidth() - 2 * getFrameSize();
+ int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight();
+ mWidgetContainer->setSize(width, height);
+ gcn::Widget *w = getCurrentWidget();
+ if (w)
+ w->setSize(width, height);
+}
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index 29ba2f76..a64d855f 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -23,6 +23,7 @@
#define TABBEDAREA_H
#include <guichan/widget.hpp>
+#include <guichan/widgetlistener.hpp>
#include <guichan/widgets/container.hpp>
#include <guichan/widgets/tabbedarea.hpp>
@@ -33,7 +34,7 @@ class Tab;
/**
* A tabbed area, the same as the guichan tabbed area in 0.8, but extended
*/
-class TabbedArea : public gcn::TabbedArea
+class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
{
public:
/**
@@ -71,6 +72,14 @@ class TabbedArea : public gcn::TabbedArea
using gcn::TabbedArea::addTab;
/**
+ * Add a tab. Overridden since it needs to size the widget.
+ *
+ * @param tab The tab widget for the tab.
+ * @param widget The widget to view when the tab is selected.
+ */
+ void addTab(gcn::Tab* tab, gcn::Widget* widget);
+
+ /**
* Add a tab. Overridden since it needs to create an instance of Tab
* instead of gcn::Tab.
*
@@ -97,6 +106,8 @@ class TabbedArea : public gcn::TabbedArea
void setSelectedTab(gcn::Tab *tab);
+ void widgetResized(const gcn::Event &event);
+
private:
typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer;
};
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 96776617..b73558c0 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -41,11 +41,11 @@ extern Window *inventoryWindow;
extern Window *itemShortcutWindow;
extern Window *setupWindow;
extern Window *skillDialog;
+extern Window *specialsWindow;
extern Window *statusWindow;
#ifdef TMWSERV_SUPPORT
extern Window *buddyWindow;
extern Window *guildWindow;
-extern Window *magicDialog;
#endif
WindowMenu::WindowMenu():
@@ -59,8 +59,8 @@ WindowMenu::WindowMenu():
N_("Equipment"),
N_("Inventory"),
N_("Skills"),
+ N_("Specials"),
#ifdef TMWSERV_SUPPORT
- N_("Magic"),
N_("Guilds"),
N_("Buddies"),
#endif
@@ -129,11 +129,11 @@ void WindowMenu::action(const gcn::ActionEvent &event)
{
window = skillDialog;
}
-#ifdef TMWSERV_SUPPORT
- else if (event.getId() == "Magic")
+ else if (event.getId() == "Specials")
{
- window = magicDialog;
+ window = specialsWindow;
}
+#ifdef TMWSERV_SUPPORT
else if (event.getId() == "Guilds")
{
window = guildWindow;