summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp3
-rw-r--r--src/gui/magic.cpp92
-rw-r--r--src/gui/specialswindow.cpp254
-rw-r--r--src/gui/specialswindow.h (renamed from src/gui/magic.h)50
-rw-r--r--src/gui/widgets/flowcontainer.cpp78
-rw-r--r--src/gui/widgets/flowcontainer.h68
-rw-r--r--src/gui/windowmenu.cpp10
7 files changed, 437 insertions, 118 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index c337d33b..be302dc3 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -98,6 +98,8 @@ ChatWindow::ChatWindow():
mChatTabs = new TabbedArea;
+ //place(0, 0, mChatTabs, 3, 3);
+ //place(0, 3, mChatInput, 3);
add(mChatTabs);
add(mChatInput);
@@ -128,6 +130,7 @@ void ChatWindow::resetToDefaultSize()
void ChatWindow::adjustTabSize()
{
+ //return;
const gcn::Rectangle area = getChildrenArea();
mChatInput->setPosition(mChatInput->getFrameSize(),
diff --git a/src/gui/magic.cpp b/src/gui/magic.cpp
deleted file mode 100644
index 48cfc5dc..00000000
--- a/src/gui/magic.cpp
+++ /dev/null
@@ -1,92 +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);
-
- gcn::Button *spellButton1 = new Button(_("Cast Test Spell 1"), "spell_1", this);
- gcn::Button *spellButton2 = new Button(_("Cast Test Spell 2"), "spell_2", this);
- gcn::Button *spellButton3 = new Button(_("Cast Test Spell 3"), "spell_3", this);
-
- spellButton1->setPosition(10, 30);
- spellButton2->setPosition(10, 60);
- spellButton3->setPosition(10, 90);
-
- add(spellButton1);
- add(spellButton2);
- add(spellButton3);
-
- 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()
-{
-}
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
new file mode 100644
index 00000000..5d2ab676
--- /dev/null
+++ b/src/gui/specialswindow.cpp
@@ -0,0 +1,254 @@
+/*
+ * 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);
+ }
+}
+
+void SpecialsWindow::logic()
+{
+ Window::logic();
+
+ Tab *tab = dynamic_cast<Tab*>(mTabs->getSelectedTab());
+ if (tab != mCurrentTab) {
+ mCurrentTab = tab;
+ }
+}
+
+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 734ad799..17c29597 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 "gui/widgets/window.h"
@@ -28,34 +28,42 @@
#include <guichan/actionlistener.hpp>
-/**
- * The skill dialog.
- *
- * \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);
+
+ void logic();
/**
- * 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:
+ typedef std::map<int, SpecialInfo*> SpecialMap;
+ SpecialMap mSpecials;
+ Tab *mCurrentTab;
+ 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/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;