summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-21 15:11:19 +0000
committerJoshua Langley <joshlangley[at]optusnet.com.au>2007-08-21 15:11:19 +0000
commit0f8e80bcfe92ca39803f0443cf4b30e3f9171eb9 (patch)
treea07d923f09e8c9aa4a478e2bd572ab94edf09ae4 /src/gui
parent148b62c05337eaaaf3a1ead212b3792122812cee (diff)
downloadmana-0f8e80bcfe92ca39803f0443cf4b30e3f9171eb9.tar.gz
mana-0f8e80bcfe92ca39803f0443cf4b30e3f9171eb9.tar.bz2
mana-0f8e80bcfe92ca39803f0443cf4b30e3f9171eb9.tar.xz
mana-0f8e80bcfe92ca39803f0443cf4b30e3f9171eb9.zip
mantis id=118 - Added Item Shortcut Bar.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp5
-rw-r--r--src/gui/itemcontainer.cpp18
-rw-r--r--src/gui/itemshortcutcontainer.cpp222
-rw-r--r--src/gui/itemshortcutcontainer.h116
-rw-r--r--src/gui/itemshortcutwindow.cpp95
-rw-r--r--src/gui/itemshortcutwindow.h69
-rw-r--r--src/gui/menuwindow.cpp7
-rw-r--r--src/gui/setup_keyboard.cpp6
-rw-r--r--src/gui/window.h6
9 files changed, 533 insertions, 11 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 3f9dfd73..3e7541cf 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -207,10 +207,9 @@ Gui::draw()
int mouseX, mouseY;
Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
- if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
- && mCustomCursor)
+ if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) &&
+ mCustomCursor)
{
-
static_cast<Graphics*>(mGraphics)->drawImage(
mMouseCursor->get(mCursorType),
mouseX - 15,
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 334770f8..43de8db3 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -30,6 +30,7 @@
#include "../graphics.h"
#include "../inventory.h"
#include "../item.h"
+#include "../itemshortcut.h"
#include "../log.h"
#include "../resources/image.h"
@@ -197,9 +198,18 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
int my = event.getY();
int index = mx / gridWidth + ((my / gridHeight) * columns) + 2;
- if (index > INVENTORY_SIZE)
- index = INVENTORY_SIZE - 1;
-
- setSelectedItem(mInventory->getItem(index));
+ itemShortcut->setItemSelected(NULL);
+ // Fix for old server, it should be: if (index >= mMaxItems)
+ if (index > mMaxItems + 1)
+ {
+ setSelectedItem(NULL);
+ return;
+ }
+ Item *item = mInventory->getItem(index);
+ setSelectedItem(item);
+ if (!item->isEquipment())
+ {
+ itemShortcut->setItemSelected(item);
+ }
}
}
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
new file mode 100644
index 00000000..d9ece8d0
--- /dev/null
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -0,0 +1,222 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "itemshortcutcontainer.h"
+
+#include "../graphics.h"
+#include "../item.h"
+#include "../itemshortcut.h"
+#include "../keyboardconfig.h"
+
+#include "../resources/image.h"
+#include "../resources/resourcemanager.h"
+
+#include "../utils/tostring.h"
+
+ItemShortcutContainer::ItemShortcutContainer():
+ mItemClicked(false),
+ mItemMoved(NULL)
+{
+ addMouseListener(this);
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png");
+ mMaxItems = itemShortcut->getItemCount();
+
+ mBoxHeight = 42;
+ mBoxWidth = 36;
+}
+
+ItemShortcutContainer::~ItemShortcutContainer()
+{
+ mBackgroundImg->decRef();
+}
+
+void
+ItemShortcutContainer::logic()
+{
+ gcn::Widget::logic();
+
+ int i = itemShortcut->getItemCount();
+
+ if (i != mMaxItems)
+ {
+ mMaxItems = i;
+ setWidth(getWidth());
+ }
+}
+
+void
+ItemShortcutContainer::draw(gcn::Graphics *graphics)
+{
+ Graphics *g = static_cast<Graphics*>(graphics);
+
+ for (int i = 0; i < mMaxItems; i++)
+ {
+ const int itemX = (i % mGridWidth) * mBoxWidth;
+ const int itemY = (i / mGridWidth) * mBoxHeight;
+
+ g->drawImage(mBackgroundImg, itemX, itemY);
+
+ // Draw item keyboard shortcut.
+ const char *key = SDL_GetKeyName(
+ (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0+i));
+ g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
+
+ Item *item = itemShortcut->getItem(i);
+ if (item) {
+ // Draw item icon.
+ Image* image = item->getInfo().getImage();
+ if (image) {
+ g->drawImage(image, itemX, itemY);
+ g->drawText(
+ toString(item->getQuantity()),
+ itemX + mBoxWidth / 2,
+ itemY + mBoxHeight - 14,
+ gcn::Graphics::CENTER);
+ }
+ }
+ }
+ if (mItemMoved)
+ {
+ // Draw the item image being dragged by the cursor.
+ Image* image = mItemMoved->getInfo().getImage();
+ if (image)
+ {
+ const int tPosX = mCursorPosX - (image->getWidth() / 2);
+ const int tPosY = mCursorPosY - (image->getHeight() / 2);
+
+ g->drawImage(image, tPosX, tPosY);
+ g->drawText(
+ toString(mItemMoved->getQuantity()),
+ tPosX + mBoxWidth / 2,
+ tPosY + mBoxHeight - 14,
+ gcn::Graphics::CENTER);
+ }
+ }
+}
+
+void
+ItemShortcutContainer::setWidth(int width)
+{
+ gcn::Widget::setWidth(width);
+
+ mGridWidth = getWidth() / mBoxWidth;
+ if (mGridWidth < 1) {
+ mGridWidth = 1;
+ }
+
+ setHeight(((mMaxItems / mGridWidth) +
+ (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
+
+ mGridHeight = getHeight() / mBoxHeight;
+ if (mGridHeight < 1) {
+ mGridHeight = 1;
+ }
+}
+
+void
+ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
+{
+ if (event.getButton() == gcn::MouseEvent::LEFT) {
+ if (!mItemMoved && mItemClicked) {
+ const int index = getIndexFromGrid(event.getX(), event.getY());
+ if (index == -1) {
+ return;
+ }
+ Item *item = itemShortcut->getItem(index);
+ if (item)
+ {
+ mItemMoved = item;
+ itemShortcut->removeItem(index);
+ }
+ }
+ if (mItemMoved) {
+ mCursorPosX = event.getX();
+ mCursorPosY = event.getY();
+ }
+ }
+}
+
+void
+ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
+{
+ const int index = getIndexFromGrid(event.getX(), event.getY());
+ if (index == -1) {
+ return;
+ }
+
+ // Stores the selected item if theirs one.
+ if (itemShortcut->isItemSelected()) {
+ itemShortcut->setItem(index);
+ itemShortcut->setItemSelected(NULL);
+ }
+ else if (itemShortcut->getItem(index)) {
+ mItemClicked = true;
+ }
+}
+
+void
+ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
+{
+ if (event.getButton() == gcn::MouseEvent::LEFT)
+ {
+ if (itemShortcut->isItemSelected())
+ {
+ itemShortcut->setItemSelected(NULL);
+ }
+ const int index = getIndexFromGrid(event.getX(), event.getY());
+ if (index == -1) {
+ mItemMoved = NULL;
+ return;
+ }
+ if (mItemMoved) {
+ itemShortcut->setItems(index, mItemMoved);
+ mItemMoved = NULL;
+ }
+ else if (itemShortcut->getItem(index) && mItemClicked)
+ {
+ itemShortcut->useItem(index);
+ }
+ if (mItemClicked) {
+ mItemClicked = false;
+ }
+ }
+}
+
+int
+ItemShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
+{
+ const gcn::Rectangle tRect = gcn::Rectangle(
+ 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
+ if (!tRect.isPointInRect(pointX, pointY)) {
+ return -1;
+ }
+ const int index = ((pointY / mBoxHeight) * mGridWidth) +
+ (pointX / mBoxWidth);
+ if (index >= mMaxItems)
+ {
+ return -1;
+ }
+ return index;
+}
diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h
new file mode 100644
index 00000000..a1ad53b7
--- /dev/null
+++ b/src/gui/itemshortcutcontainer.h
@@ -0,0 +1,116 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _TMW_ITEMSHORTCUTCONTAINER_H__
+#define _TMW_ITEMSHORTCUTCONTAINER_H__
+
+#include <guichan/mouselistener.hpp>
+#include <guichan/widget.hpp>
+
+#include <list>
+
+class Image;
+class Item;
+
+/**
+ * An item shortcut container. Used to quickly use items.
+ *
+ * \ingroup GUI
+ */
+class ItemShortcutContainer : public gcn::Widget, public gcn::MouseListener
+{
+ public:
+ /**
+ * Constructor. Initializes the graphic.
+ */
+ ItemShortcutContainer();
+
+ /**
+ * Destructor.
+ */
+ virtual ~ItemShortcutContainer();
+
+ /**
+ * Handles the logic of the ItemContainer
+ */
+ void logic();
+
+ /**
+ * Draws the items.
+ */
+ void draw(gcn::Graphics *graphics);
+
+ /**
+ * Sets the width of the container. This is used to determine the new
+ * height of the container.
+ */
+ void setWidth(int width);
+
+ /**
+ * Handles mouse when dragged.
+ */
+ void mouseDragged(gcn::MouseEvent &event);
+
+ /**
+ * Handles mouse when pressed.
+ */
+ void mousePressed(gcn::MouseEvent &event);
+
+ /**
+ * Handles mouse release.
+ */
+ void mouseReleased(gcn::MouseEvent &event);
+
+
+ int getMaxItems()
+ { return mMaxItems; }
+
+ int getBoxWidth()
+ { return mBoxWidth; }
+
+ int getBoxHeight()
+ { return mBoxHeight; }
+
+ private:
+ /**
+ * Gets the index from the grid provided the point is in an item box.
+ *
+ * @param pointX X coordinate of the point.
+ * @param pointY Y coordinate of the point.
+ * @return index on success, -1 on failure.
+ */
+ int ItemShortcutContainer::getIndexFromGrid(
+ int pointX, int pointY) const;
+
+ Image *mBackgroundImg;
+
+ int mMaxItems;
+ int mBoxWidth;
+ int mBoxHeight;
+ int mCursorPosX, mCursorPosY;
+ int mGridWidth, mGridHeight;
+ bool mItemClicked;
+ Item *mItemMoved;
+
+};
+
+#endif
diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp
new file mode 100644
index 00000000..2ee2cfde
--- /dev/null
+++ b/src/gui/itemshortcutwindow.cpp
@@ -0,0 +1,95 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "itemshortcutwindow.h"
+
+#include "itemshortcutcontainer.h"
+#include "scrollarea.h"
+
+static const int SCROLL_PADDING = 0;
+
+ItemShortcutWindow::ItemShortcutWindow()
+{
+ setWindowName("itemShortcut");
+ // no title presented, title bar is padding so window can be moved.
+ gcn::Window::setTitleBarHeight(gcn::Window::getPadding());
+ setShowTitle(false);
+ setResizable(true);
+ setDefaultSize(758, 174, 42, 426);
+
+ mItems = new ItemShortcutContainer();
+
+ int border = (SCROLL_PADDING * 2) + (getPadding() * 2);
+ setMinWidth(mItems->getBoxWidth() + border);
+ setMinHeight(mItems->getBoxHeight() + border);
+ setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border);
+ setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border);
+
+ mInvenScroll = new ScrollArea(mItems);
+ mInvenScroll->setPosition(SCROLL_PADDING, SCROLL_PADDING);
+ mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+
+ add(mInvenScroll);
+
+ loadWindowState();
+}
+
+ItemShortcutWindow::~ItemShortcutWindow()
+{
+ delete mItems;
+ delete mInvenScroll;
+}
+
+void ItemShortcutWindow::logic()
+{
+ Window::logic();
+}
+
+void ItemShortcutWindow::mouseDragged(gcn::MouseEvent &event)
+{
+ const int tWidth = getWidth(), tHeight = getHeight();
+ Window::mouseDragged(event);
+ if (getWidth() != tWidth || getHeight() != tHeight)
+ {
+ updateWidgets();
+ }
+}
+
+void ItemShortcutWindow::updateWidgets()
+{
+ const gcn::Rectangle area = getChildrenArea();
+
+ mInvenScroll->setSize(area.width - SCROLL_PADDING,
+ area.height - SCROLL_PADDING);
+}
+
+void ItemShortcutWindow::loadWindowState()
+{
+ Window::loadWindowState();
+ updateWidgets();
+}
+
+void ItemShortcutWindow::resetToDefaultSize()
+{
+ Window::resetToDefaultSize();
+ updateWidgets();
+}
diff --git a/src/gui/itemshortcutwindow.h b/src/gui/itemshortcutwindow.h
new file mode 100644
index 00000000..54611efe
--- /dev/null
+++ b/src/gui/itemshortcutwindow.h
@@ -0,0 +1,69 @@
+/*
+ * The Mana World
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _TMW_ITEMSHORTCUTWINDOW_H
+#define _TMW_ITEMSHORTCUTWINDOW_H
+
+#include "window.h"
+
+#include "../guichanfwd.h"
+
+class ItemShortcutContainer;
+
+/**
+ * Inventory dialog.
+ *
+ * \ingroup Interface
+ */
+class ItemShortcutWindow : public Window
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ItemShortcutWindow();
+
+ /**
+ * Destructor.
+ */
+ ~ItemShortcutWindow();
+
+ /**
+ * Logic (updates buttons and weight information).
+ */
+ void logic();
+
+ void mouseDragged(gcn::MouseEvent &event);
+
+ void loadWindowState();
+
+ void resetToDefaultSize();
+
+ private:
+ void updateWidgets(); /**< Updates widgets size/position. */
+
+ ItemShortcutContainer *mItems;
+
+ gcn::ScrollArea *mInvenScroll;
+};
+extern ItemShortcutWindow *itemShortcutWindow;
+#endif
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 943cc6f0..c7505bae 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -35,6 +35,7 @@ extern Window *inventoryWindow;
extern Window *equipmentWindow;
extern Window *skillDialog;
extern Window *statusWindow;
+extern Window *itemShortcutWindow;
namespace {
struct MenuWindowListener : public gcn::ActionListener
@@ -61,6 +62,7 @@ MenuWindow::MenuWindow():
"Equipment",
"Inventory",
"Skills",
+ "Shortcut",
"Setup",
0
};
@@ -108,11 +110,14 @@ void MenuWindowListener::action(const gcn::ActionEvent &event)
{
window = skillDialog;
}
+ else if (event.getId() == "Shortcut")
+ {
+ window = itemShortcutWindow;
+ }
else if (event.getId() == "Setup")
{
window = setupWindow;
}
-
if (window) {
window->setVisible(!window->isVisible());
if (window->isVisible()) {
diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp
index 3c8c8163..e88080b5 100644
--- a/src/gui/setup_keyboard.cpp
+++ b/src/gui/setup_keyboard.cpp
@@ -78,16 +78,16 @@ Setup_Keyboard::Setup_Keyboard():
refreshKeys();
- mKeyList->setDimension(gcn::Rectangle(0, 0, 180, 140));
+ mKeyList->setDimension(gcn::Rectangle(0, 0, 185, 140));
mKeyList->addActionListener(this);
mKeyList->setSelected(-1);
ScrollArea *scrollArea = new ScrollArea(mKeyList);
- scrollArea->setDimension(gcn::Rectangle(10, 10, 180, 140));
+ scrollArea->setDimension(gcn::Rectangle(10, 10, 200, 140));
add(scrollArea);
mAssignKeyButton = new Button("Assign", "assign", this);
- mAssignKeyButton->setPosition(145, 155);
+ mAssignKeyButton->setPosition(165, 155);
mAssignKeyButton->addActionListener(this);
mAssignKeyButton->setEnabled(false);
add(mAssignKeyButton);
diff --git a/src/gui/window.h b/src/gui/window.h
index a44a56d8..03dfafb2 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -155,6 +155,12 @@ class Window : public gcn::Window
void setMaxHeight(unsigned int height);
/**
+ * Sets flag to show a title or not.
+ */
+ void setShowTitle(bool flag)
+ { mShowTitle = flag; }
+
+ /**
* Sets whether the window is sticky.
* A sticky window will not have its visibility set to false
* on a general setVisible(false) call.