summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-19 15:40:32 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-19 15:40:32 +0200
commit124865b5d67c8c7b199046d19380e1e154ee99e4 (patch)
treece9b63c4eb87f3b8d930fd73a98cf63929fba365
parent3a15ac0bf3519173b9fd767a05c146793ba7eb1f (diff)
parente7f9c983dd7a8d2aeb4b14e5621cef89ecc398f6 (diff)
downloadmana-124865b5d67c8c7b199046d19380e1e154ee99e4.tar.gz
mana-124865b5d67c8c7b199046d19380e1e154ee99e4.tar.bz2
mana-124865b5d67c8c7b199046d19380e1e154ee99e4.tar.xz
mana-124865b5d67c8c7b199046d19380e1e154ee99e4.zip
Merge branch '0.0.29'
-rw-r--r--src/gui/inventorywindow.cpp14
-rw-r--r--src/gui/inventorywindow.h1
-rw-r--r--src/gui/itemcontainer.cpp72
-rw-r--r--src/gui/itemcontainer.h12
-rw-r--r--src/gui/storagewindow.cpp9
-rw-r--r--src/gui/storagewindow.h1
-rw-r--r--src/gui/trade.cpp10
-rw-r--r--src/gui/widgets/browserbox.cpp58
-rw-r--r--src/gui/widgets/browserbox.h5
-rw-r--r--src/gui/widgets/window.cpp3
10 files changed, 105 insertions, 80 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index a808945e..50b0bd78 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -54,10 +54,12 @@ InventoryWindow::InventoryWindow(int invSize):
mItemDesc(false)
{
setWindowName("Inventory");
- setResizable(false);
+ setResizable(true);
setCloseButton(true);
setDefaultSize(387, 307, ImageRect::CENTER);
+ setMinWidth(316);
+ setMinHeight(179);
addKeyListener(this);
std::string longestUseString = getFont()->getWidth(_("Equip")) >
@@ -74,14 +76,14 @@ InventoryWindow::InventoryWindow(int invSize):
mDropButton = new Button(_("Drop"), "drop", this);
#ifdef TMWSERV_SUPPORT
mSplitButton = new Button(_("Split"), "split", this);
- mItems = new ItemContainer(player_node->getInventory(), 10, 5);
+ mItems = new ItemContainer(player_node->getInventory());
#else
- mItems = new ItemContainer(player_node->getInventory(), 10, 10);
+ mItems = new ItemContainer(player_node->getInventory());
#endif
mItems->addSelectionListener(this);
- mInvenScroll = new ScrollArea(mItems);
- mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
+ invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mTotalWeight = -1;
mMaxWeight = -1;
@@ -97,7 +99,7 @@ InventoryWindow::InventoryWindow(int invSize):
place(1, 0, mWeightBar, 3);
place(4, 0, mSlotsLabel).setPadding(3);
place(5, 0, mSlotsBar, 2);
- place(0, 1, mInvenScroll, 7).setPadding(3);
+ place(0, 1, invenScroll, 7).setPadding(3);
place(0, 2, mUseButton);
place(1, 2, mDropButton);
#ifdef TMWSERV_SUPPORT
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 93ffdc11..a39ea34b 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -112,7 +112,6 @@ class InventoryWindow : public Window,
#ifdef TMWSERV_SUPPORT
gcn::Button *mSplitButton;
#endif
- gcn::ScrollArea *mInvenScroll; /**< Inventory Scroll Area. */
gcn::Label *mWeightLabel;
gcn::Label *mSlotsLabel;
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index a672f3b5..4779b004 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -46,15 +46,13 @@
// TODO: Add support for adding items to the item shortcut window (global
// itemShortcut).
-static const int BOX_WIDTH = 36;
-static const int BOX_HEIGHT = 44;
+static const int BOX_WIDTH = 35;
+static const int BOX_HEIGHT = 43;
-ItemContainer::ItemContainer(Inventory *inventory,
- int gridColumns, int gridRows,
- bool forceQuantity):
+ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mInventory(inventory),
- mGridColumns(gridColumns),
- mGridRows(gridRows),
+ mGridColumns(1),
+ mGridRows(1),
mSelectedItem(NULL),
mHighlightedItem(NULL),
mSelectionStatus(SEL_NONE),
@@ -68,13 +66,12 @@ ItemContainer::ItemContainer(Inventory *inventory,
ResourceManager *resman = ResourceManager::getInstance();
mSelImg = resman->getImage("graphics/gui/selection.png");
- if (!mSelImg) logger->error("Unable to load selection.png");
+ if (!mSelImg)
+ logger->error("Unable to load selection.png");
addKeyListener(this);
addMouseListener(this);
-
- setSize((BOX_WIDTH - 1) * mGridColumns + 1,
- (BOX_HEIGHT - 1) * mGridRows + 1);
+ addWidgetListener(this);
}
ItemContainer::~ItemContainer()
@@ -87,19 +84,14 @@ void ItemContainer::draw(gcn::Graphics *graphics)
{
Graphics *g = static_cast<Graphics*>(graphics);
+ g->setFont(getFont());
+
for (int i = 0; i < mGridColumns; i++)
{
for (int j = 0; j < mGridRows; j++)
{
- // Items positions made to overlap on another.
- int itemX = i * (BOX_WIDTH - 1);
- int itemY = j * (BOX_HEIGHT - 1);
-
- // Set color to black.
- g->setColor(gcn::Color(0, 0, 0));
- // Draw box border.
- g->drawRectangle(
- gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT));
+ int itemX = i * BOX_WIDTH;
+ int itemY = j * BOX_HEIGHT;
Item *item = mInventory->getItem((j * mGridColumns) + i);
@@ -128,23 +120,25 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (item->getQuantity() > 1 || mForceQuantity)
caption = toString(item->getQuantity());
else if (item->isEquipped())
- caption = "(Eq)";
+ caption = "Eq.";
if (item->isEquipped())
g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
+ else
+ g->setColor(gcn::Color(0, 0, 0));
+
g->drawText(caption, itemX + BOX_WIDTH / 2,
itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER);
}
}
- if (isFocused() && mHighlightedItem) {
- // Items positions made to overlap on another.
+ // Draw an orange box around the selected item
+ if (isFocused() && mHighlightedItem)
+ {
const int i = mHighlightedItem->getInvIndex();
- const int itemX = (i % mGridColumns) * (BOX_WIDTH - 1);
- const int itemY = (i / mGridColumns) * (BOX_HEIGHT - 1);
- // Set color to orange.
+ const int itemX = (i % mGridColumns) * BOX_WIDTH;
+ const int itemY = (i / mGridColumns) * BOX_HEIGHT;
g->setColor(gcn::Color(255, 128, 0));
- // Draw box border.
g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT));
}
}
@@ -165,13 +159,13 @@ void ItemContainer::setSelectedItem(Item *item)
void ItemContainer::distributeValueChangedEvent()
{
- SelectionListenerIterator iter;
+ SelectionListenerIterator i, i_end;
- for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end();
- ++iter)
+ for (i = mSelectionListeners.begin(), i_end = mSelectionListeners.end();
+ i != i_end; ++i)
{
gcn::SelectionEvent event(this);
- (*iter)->valueChanged(event);
+ (*i)->valueChanged(event);
}
}
@@ -224,9 +218,8 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX) {
+ if (index == Inventory::NO_SLOT_INDEX)
return;
- }
Item *item = mInventory->getItem(index);
@@ -317,12 +310,21 @@ void ItemContainer::mouseExited(gcn::MouseEvent &event)
mItemPopup->setVisible(false);
}
+void ItemContainer::widgetResized(const gcn::Event &event)
+{
+ mGridColumns = std::max(1, getWidth() / BOX_WIDTH);
+ mGridRows = mInventory->getSize() / mGridColumns;
+ if (mGridRows == 0 || mInventory->getSize() % mGridColumns > 0)
+ ++mGridRows;
+
+ setHeight(mGridRows * BOX_HEIGHT);
+}
+
int ItemContainer::getSlotIndex(int x, int y) const
{
if (x < getWidth() && y < getHeight())
{
- // Takes into account, boxes are overlapping each other.
- return (y / (BOX_HEIGHT - 1)) * mGridColumns + (x / (BOX_WIDTH - 1));
+ return (y / BOX_HEIGHT) * mGridColumns + (x / BOX_WIDTH);
}
return Inventory::NO_SLOT_INDEX;
}
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index ba834d01..bc7caf5d 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -25,6 +25,7 @@
#include <guichan/keylistener.hpp>
#include <guichan/mouselistener.hpp>
#include <guichan/widget.hpp>
+#include <guichan/widgetlistener.hpp>
#include <list>
@@ -44,7 +45,8 @@ namespace gcn {
*/
class ItemContainer : public gcn::Widget,
public gcn::KeyListener,
- public gcn::MouseListener
+ public gcn::MouseListener,
+ public gcn::WidgetListener
{
public:
/**
@@ -55,8 +57,7 @@ class ItemContainer : public gcn::Widget,
* @param gridRows Amount of rows in grid.
* @param offset Index offset
*/
- ItemContainer(Inventory *inventory, int gridColumns, int gridRows,
- bool forceQuantity = false);
+ ItemContainer(Inventory *inventory, bool forceQuantity = false);
/**
* Destructor.
@@ -68,15 +69,20 @@ class ItemContainer : public gcn::Widget,
*/
void draw(gcn::Graphics *graphics);
+ // KeyListener
void keyPressed(gcn::KeyEvent &event);
void keyReleased(gcn::KeyEvent &event);
+ // MouseListener
void mousePressed(gcn::MouseEvent &event);
void mouseDragged(gcn::MouseEvent &event);
void mouseReleased(gcn::MouseEvent &event);
void mouseMoved(gcn::MouseEvent &event);
void mouseExited(gcn::MouseEvent &event);
+ // WidgetListener
+ void widgetResized(const gcn::Event &event);
+
/**
* Returns the selected item.
*/
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index 076dfccf..efa2bdd4 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -64,11 +64,11 @@ StorageWindow::StorageWindow(int invSize):
mStoreButton = new Button(_("Store"), "store", this);
mRetrieveButton = new Button(_("Retrieve"), "retrieve", this);
- mItems = new ItemContainer(player_node->getStorage(), 10, 30, true);
+ mItems = new ItemContainer(player_node->getStorage(), true);
mItems->addSelectionListener(this);
- mInvenScroll = new ScrollArea(mItems);
- mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ gcn::ScrollArea *invenScroll = new ScrollArea(mItems);
+ invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mUsedSlots = player_node->getStorage()->getNumberOfSlotsUsed();
@@ -83,7 +83,7 @@ StorageWindow::StorageWindow(int invSize):
place(0, 0, mSlotsLabel).setPadding(3);
place(1, 0, mSlotsBar, 3);
- place(0, 1, mInvenScroll, 4, 4);
+ place(0, 1, invenScroll, 4, 4);
place(2, 5, mStoreButton);
place(3, 5, mRetrieveButton);
@@ -95,7 +95,6 @@ StorageWindow::StorageWindow(int invSize):
StorageWindow::~StorageWindow()
{
- delete mItems;
}
void StorageWindow::logic()
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
index caf31b90..4ccf324c 100644
--- a/src/gui/storagewindow.h
+++ b/src/gui/storagewindow.h
@@ -92,7 +92,6 @@ class StorageWindow : public Window, gcn::ActionListener,
int mSlots;
int mUsedSlots;
gcn::Button *mStoreButton, *mRetrieveButton;
- gcn::ScrollArea *mInvenScroll;
gcn::Label *mSlotsLabel;
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 899c55d5..c67b0b7b 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -59,9 +59,11 @@ TradeWindow::TradeWindow():
mStatus(PROPOSING)
{
setWindowName("Trade");
- setResizable(false);
+ setResizable(true);
setCloseButton(true);
setDefaultSize(386, 180, ImageRect::CENTER);
+ setMinWidth(386);
+ setMinHeight(180);
std::string longestName = getFont()->getWidth(_("OK")) >
getFont()->getWidth(_("Trade")) ?
@@ -76,15 +78,17 @@ TradeWindow::TradeWindow():
mOkButton->setWidth(8 + width);
- mMyItemContainer = new ItemContainer(mMyInventory.get(), 5, 2);
+ mMyItemContainer = new ItemContainer(mMyInventory.get());
mMyItemContainer->addSelectionListener(this);
ScrollArea *myScroll = new ScrollArea(mMyItemContainer);
+ myScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 5, 2);
+ mPartnerItemContainer = new ItemContainer(mPartnerInventory.get());
mPartnerItemContainer->addSelectionListener(this);
ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer);
+ partnerScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mMoneyLabel = new Label(strprintf(_("You get %s."), ""));
gcn::Label *mMoneyLabel2 = new Label(_("You give:"));
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 603f2056..a1e5b07a 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -82,7 +82,7 @@ void BrowserBox::addRow(const std::string &row)
{
idx2 = tmp.find("|", idx1);
idx3 = tmp.find("@@", idx2);
-
+
if (idx2 == std::string::npos || idx3 == std::string::npos)
break;
bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
@@ -286,9 +286,10 @@ void BrowserBox::draw(gcn::Graphics *graphics)
graphics->setColor(guiPalette->getColor(Palette::TEXT));
for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
{
- const gcn::Color *selColor = &guiPalette->getColor(Palette::TEXT);
- const gcn::Color *prevColor = selColor;
- std::string row = *(i);
+ const gcn::Color textColor = guiPalette->getColor(Palette::TEXT);
+ gcn::Color selColor = textColor;
+ gcn::Color prevColor = selColor;
+ const std::string row = *(i);
bool wrapped = false;
x = 0;
@@ -327,28 +328,45 @@ void BrowserBox::draw(gcn::Graphics *graphics)
// Check for color change in format "##x", x = [L,P,0..9]
if (row.find("##", start) == start && row.size() > start + 2)
{
- char c = row.at(start + 2);
+ const char c = row.at(start + 2);
+ bool valid;
+ const gcn::Color col = guiPalette->getColor(c, valid);
+
if (c == '>')
{
selColor = prevColor;
}
+ else if (c == '<')
+ {
+ const int size = mLinks[link].x2 - mLinks[link].x1;
+ mLinks[link].x1 = x;
+ mLinks[link].y1 = y;
+ mLinks[link].x2 = mLinks[link].x1 + size;
+ mLinks[link].y2 = y + font->getHeight();
+ link++;
+ selColor = col;
+ prevColor = selColor;
+ }
+ else if (valid)
+ {
+ selColor = col;
+ }
else
{
- bool valid;
- const gcn::Color *col = &guiPalette->getColor(c, valid);
- if (c == '<')
- {
- const int size = mLinks[link].x2 - mLinks[link].x1;
- mLinks[link].x1 = x;
- mLinks[link].y1 = y;
- mLinks[link].x2 = mLinks[link].x1 + size;
- mLinks[link].y2 = y + font->getHeight();
- link++;
- prevColor = selColor;
- }
- if (valid)
+ switch (c)
{
- selColor = col;
+ case '1': selColor = RED; break;
+ case '2': selColor = GREEN; break;
+ case '3': selColor = BLUE; break;
+ case '4': selColor = ORANGE; break;
+ case '5': selColor = YELLOW; break;
+ case '6': selColor = PINK; break;
+ case '7': selColor = PURPLE; break;
+ case '8': selColor = GRAY; break;
+ case '9': selColor = BROWN; break;
+ case '0':
+ default:
+ selColor = textColor;
}
}
start += 3;
@@ -358,7 +376,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
break;
}
}
- graphics->setColor(*selColor);
+ graphics->setColor(selColor);
}
std::string::size_type len =
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index 090c03e1..42af5b11 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -113,13 +113,11 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
* NOTES (by Javila):
* - color values is "0x" prefix followed by HTML color style.
* - we can add up to 10 different colors: [0..9].
- * - we need a link and a highlighted link colors.
* - not all colors will be fine with all backgrounds due transparent
* windows and widgets. So, I think it's better keep BrowserBox
* opaque (white background) by default.
*/
enum {
- BLACK = 0x000000, /**< Color 0 */
RED = 0xff0000, /**< Color 1 */
GREEN = 0x009000, /**< Color 2 */
BLUE = 0x0000ff, /**< Color 3 */
@@ -129,9 +127,6 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
PURPLE = 0x8415e2, /**< Color 7 */
GRAY = 0x919191, /**< Color 8 */
BROWN = 0x8e4c17, /**< Color 9 */
- BGCOLOR = 0xffffff, /**< Bg color for opacity */
- LINK = 0xe50d0d, /**< Color L */
- HIGHLIGHT = 0xcacaca /**< Bg color for highlighted link */
};
/**
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index f252c5f6..de48dfa2 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -242,7 +242,8 @@ void Window::setMaxHeight(int height)
void Window::setResizable(bool r)
{
- if ((bool) mGrip == r) return;
+ if ((bool) mGrip == r)
+ return;
if (r)
{