summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-05 15:22:13 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-05 15:22:13 +0000
commit6374ef220d8f46647190074338f868b5d6bb4a45 (patch)
treea833453c2e712c3e992f71433f6d21c8c379ad15 /src
parentde61b658590630cfc59960c012c8e533b361a8b0 (diff)
downloadmana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.gz
mana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.bz2
mana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.xz
mana-6374ef220d8f46647190074338f868b5d6bb4a45.zip
Merged 0.0 changes from revision 2800 to 2825 to trunk.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being.cpp12
-rw-r--r--src/being.h2
-rw-r--r--src/gui/buy.cpp36
-rw-r--r--src/gui/buy.h3
-rw-r--r--src/gui/sell.cpp56
-rw-r--r--src/gui/sell.h10
-rw-r--r--src/gui/shop.cpp44
-rw-r--r--src/gui/shop.h37
-rw-r--r--src/gui/shoplistbox.cpp200
-rw-r--r--src/gui/shoplistbox.h124
-rw-r--r--src/gui/updatewindow.cpp3
-rw-r--r--src/main.cpp2
-rw-r--r--src/net/buysellhandler.cpp1
-rw-r--r--src/player.cpp38
-rw-r--r--src/player.h3
-rw-r--r--src/resources/resourcemanager.cpp8
18 files changed, 521 insertions, 62 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6a46aba4..8523b066 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -134,6 +134,8 @@ SET(SRCS
gui/setup_video.h
gui/shop.cpp
gui/shop.h
+ gui/shoplistbox.cpp
+ gui/shoplistbox.h
gui/skill.cpp
gui/skill.h
gui/slider.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ab16e32..5c8d77a0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,6 +95,8 @@ tmw_SOURCES = graphic/imagerect.h \
gui/setup_video.h \
gui/shop.cpp \
gui/shop.h \
+ gui/shoplistbox.cpp \
+ gui/shoplistbox.h \
gui/skill.cpp \
gui/skill.h \
gui/slider.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index fa24ad69..50a2dc35 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -321,6 +321,9 @@ Being::setAction(Uint8 action)
else {
switch (getWeapon())
{
+ case 3:
+ currentAction = ACTION_ATTACK;
+ break;
case 2:
currentAction = ACTION_ATTACK_BOW;
break;
@@ -565,12 +568,17 @@ Being::getType() const
void
Being::setWeaponById(Uint16 weapon)
{
+ //TODO: Use an external file to map weapon IDs to weapon types
switch (weapon)
{
case 529: // iron arrows
case 1199: // arrows
break;
+ case 623: //scythe
+ setWeapon(3);
+ break;
+
case 1200: // bow
case 530: // short bow
case 545: // forest bow
@@ -578,6 +586,10 @@ Being::setWeaponById(Uint16 weapon)
break;
case 521: // sharp knife
+ /* UNCOMMENT TO TEST SHARP KNIFE AS SCYTHE
+ * setWeapon(3)
+ * break;
+ */
case 522: // dagger
case 536: // short sword
case 1201: // knife
diff --git a/src/being.h b/src/being.h
index d8db9375..2804b20b 100644
--- a/src/being.h
+++ b/src/being.h
@@ -258,7 +258,7 @@ class Being : public Sprite
*
* @param weapon the picture id
*/
- void
+ virtual void
setWeapon(Uint16 weapon) { mWeapon = weapon; }
/**
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 73f696b7..b681b683 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -26,14 +26,12 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
-#include "listbox.h"
#include "scrollarea.h"
#include "shop.h"
#include "slider.h"
#include "../npc.h"
-#include "../resources/iteminfo.h"
#include "../resources/itemmanager.h"
#include "../utils/tostring.h"
@@ -45,8 +43,8 @@ BuyDialog::BuyDialog():
{
mShopItems = new ShopItems;
- mItemList = new ListBox(mShopItems);
- mScrollArea = new ScrollArea(mItemList);
+ mShopItemList = new ShopListBox(mShopItems, mShopItems);
+ mScrollArea = new ScrollArea(mShopItemList);
mSlider = new Slider(1.0);
mQuantityLabel = new gcn::Label("0");
mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP");
@@ -60,7 +58,7 @@ BuyDialog::BuyDialog():
setContentSize(260, 210);
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mScrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
- mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
+ mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10));
mSlider->setEnabled(false);
@@ -84,11 +82,11 @@ BuyDialog::BuyDialog():
mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14));
mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14));
- mItemList->setEventId("item");
+ mShopItemList->setEventId("item");
mSlider->setEventId("slider");
- mItemList->addActionListener(this);
- mItemList->addSelectionListener(this);
+ mShopItemList->addActionListener(this);
+ mShopItemList->addSelectionListener(this);
mSlider->addActionListener(this);
add(mScrollArea);
@@ -113,6 +111,7 @@ BuyDialog::~BuyDialog()
void BuyDialog::setMoney(int amount)
{
mMoney = amount;
+ mShopItemList->setPlayersMoney(amount);
mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
mMoneyLabel->adjustSize();
}
@@ -125,7 +124,7 @@ void BuyDialog::reset()
mAmountItems = 0;
// Reset Previous Selected Items to prevent failing asserts
- mItemList->setSelected(-1);
+ mShopItemList->setSelected(-1);
mIncreaseButton->setEnabled(false);
mDecreaseButton->setEnabled(false);
mQuantityLabel->setCaption("0");
@@ -138,20 +137,13 @@ void BuyDialog::reset()
void BuyDialog::addItem(short id, int price)
{
- ITEM_SHOP item_shop;
-
- item_shop.name = itemDb->getItemInfo(id).getName() + " "
- + toString(price) + " GP";
- item_shop.price = price;
- item_shop.id = id;
-
- mShopItems->push_back(item_shop);
- mItemList->adjustSize();
+ mShopItems->addItem(id, price);
+ mShopItemList->adjustSize();
}
void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (eventId == "item")
{
@@ -169,7 +161,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
// If no item was selected, none can be bought, otherwise
// calculate how many the player can afford
- mMaxItems = (mItemList->getSelected() == -1) ? 0 :
+ mMaxItems = (mShopItemList->getSelected() == -1) ? 0 :
mMoney / mShopItems->at(selectedItem).price;
// When at least one item can be bought, enable the slider and the
@@ -184,7 +176,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
}
// The following actions require a valid selection
- if (selectedItem < 0 || selectedItem >= int(mShopItems->size()))
+ if (selectedItem < 0 || selectedItem >= int(mShopItems->getNumberOfElements()))
{
return;
}
@@ -269,7 +261,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
void BuyDialog::selectionChanged(const SelectionEvent &event)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (selectedItem > -1)
{
diff --git a/src/gui/buy.h b/src/gui/buy.h
index f5c163e1..b83b6f2f 100644
--- a/src/gui/buy.h
+++ b/src/gui/buy.h
@@ -28,6 +28,7 @@
#include "window.h"
#include "selectionlistener.h"
+#include "shoplistbox.h"
#include "../guichanfwd.h"
@@ -96,7 +97,7 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener
gcn::Button *mQuitButton;
gcn::Button *mIncreaseButton;
gcn::Button *mDecreaseButton;
- ListBox *mItemList;
+ ShopListBox *mShopItemList;
gcn::ScrollArea *mScrollArea;
gcn::Label *mItemDescLabel;
gcn::Label *mItemEffectLabel;
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 9c25aced..fd63633c 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -28,7 +28,7 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
-#include "listbox.h"
+#include "shoplistbox.h"
#include "scrollarea.h"
#include "shop.h"
#include "slider.h"
@@ -47,11 +47,11 @@ SellDialog::SellDialog():
{
mShopItems = new ShopItems();
- mItemList = new ListBox(mShopItems);
- ScrollArea *scrollArea = new ScrollArea(mItemList);
+ mShopItemList = new ShopListBox(mShopItems, mShopItems);
+ ScrollArea *scrollArea = new ScrollArea(mShopItemList);
mSlider = new Slider(1.0);
mQuantityLabel = new gcn::Label("0");
- mMoneyLabel = new gcn::Label("Price: 0");
+ mMoneyLabel = new gcn::Label("Money: 0 GP / Total: 0 GP");
mItemDescLabel = new gcn::Label("Description:");
mItemEffectLabel = new gcn::Label("Effect:");
mIncreaseButton = new Button("+", "+", this);
@@ -63,7 +63,7 @@ SellDialog::SellDialog():
setContentSize(260, 210);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
- mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
+ mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10));
mSlider->setEnabled(false);
@@ -87,11 +87,13 @@ SellDialog::SellDialog():
quitButton->setPosition(208, 186);
- mItemList->setEventId("item");
+ mShopItemList->setEventId("item");
mSlider->setEventId("mSlider");
- mItemList->addActionListener(this);
- mItemList->addSelectionListener(this);
+ mShopItemList->setPriceCheck(false);
+
+ mShopItemList->addActionListener(this);
+ mShopItemList->addSelectionListener(this);
mSlider->addActionListener(this);
add(scrollArea);
@@ -121,13 +123,14 @@ void SellDialog::reset()
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->setCaption("Money: 0 GP / Total: "
+ + toString(mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
mItemDescLabel->setCaption("");
mItemEffectLabel->setCaption("");
// Reset Previous Selected Items to prevent failing asserts
- mItemList->setSelected(-1);
+ mShopItemList->setSelected(-1);
mIncreaseButton->setEnabled(false);
mDecreaseButton->setEnabled(false);
}
@@ -144,14 +147,15 @@ void SellDialog::addItem(Item *item, int price)
item_shop.index = item->getInvIndex();
item_shop.id = item->getId();
item_shop.quantity = item->getQuantity();
+ item_shop.image = item->getInfo().getImage();
mShopItems->push_back(item_shop);
- mItemList->adjustSize();
+ mShopItemList->adjustSize();
}
void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (eventId == "item")
{
@@ -160,19 +164,22 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
mDecreaseButton->setEnabled(false);
mSellButton->setEnabled(false);
- mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->setCaption("Money: 0 GP / Total: "
+ + toString(mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
if (selectedItem > -1) {
mSlider->setEnabled(true);
mIncreaseButton->setEnabled(true);
mMaxItems = mShopItems->at(selectedItem).quantity;
+ mQuantityLabel->setCaption("0 / " + toString(mMaxItems));
} else {
mSlider->setEnabled(false);
mIncreaseButton->setEnabled(false);
+ mQuantityLabel->setCaption("0");
}
+ mQuantityLabel->adjustSize();
}
else if (eventId == "quit")
{
@@ -181,7 +188,7 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
}
// The following actions require a valid item selection
- if (selectedItem == -1 || selectedItem >= int(mShopItems->size())) {
+ if (selectedItem == -1 || selectedItem >= int(mShopItems->getNumberOfElements())) {
return;
}
@@ -224,14 +231,16 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
*/
mMaxItems -= mAmountItems;
+ mShopItems->getShop()->at(selectedItem).quantity = mMaxItems;
mAmountItems = 0;
mSlider->setValue(0);
mSlider->setEnabled(mMaxItems != 0);
// All were sold
if (!mMaxItems) {
- mItemList->setSelected(-1);
- mShopItems->erase(mShopItems->begin() + selectedItem);
+
+ mShopItemList->setSelected(-1);
+ mShopItems->getShop()->erase(mShopItems->getShop()->begin() + selectedItem);
}
// Update only when there are items left, the entry doesn't exist
@@ -243,11 +252,12 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
if (updateButtonsAndLabels)
{
// Update labels
- mQuantityLabel->setCaption(toString(mAmountItems));
+ mQuantityLabel->setCaption(toString(mAmountItems) + " / " + toString(mMaxItems));
mQuantityLabel->adjustSize();
int price = mAmountItems * mShopItems->at(selectedItem).price;
- mMoneyLabel->setCaption("Price: " + toString(price));
+ mMoneyLabel->setCaption("Money: " + toString(price) + " GP / Total: "
+ + toString(price + mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
// Update Buttons
@@ -259,7 +269,7 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget)
void SellDialog::selectionChanged(const SelectionEvent &event)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (selectedItem > -1)
{
@@ -275,3 +285,9 @@ void SellDialog::selectionChanged(const SelectionEvent &event)
mItemEffectLabel->setCaption("Effect");
}
}
+
+void SellDialog::setMoney(int amount)
+{
+ mPlayerMoney = amount;
+ mShopItemList->setPlayersMoney(amount);
+}
diff --git a/src/gui/sell.h b/src/gui/sell.h
index 69f8b089..ba324576 100644
--- a/src/gui/sell.h
+++ b/src/gui/sell.h
@@ -33,7 +33,7 @@
class Item;
class ShopItems;
-class ListBox;
+class ShopListBox;
/**
* The sell dialog.
@@ -77,11 +77,16 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener
*/
void selectionChanged(const SelectionEvent &event);
+ /**
+ * Gives Player's Money amount
+ */
+ void setMoney(int amount);
+
private:
gcn::Button *mSellButton;
gcn::Button *mIncreaseButton;
gcn::Button *mDecreaseButton;
- ListBox *mItemList;
+ ShopListBox *mShopItemList;
gcn::Label *mMoneyLabel;
gcn::Label *mItemDescLabel;
gcn::Label *mItemEffectLabel;
@@ -89,6 +94,7 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener
gcn::Slider *mSlider;
ShopItems *mShopItems;
+ int mPlayerMoney;
int mMaxItems;
int mAmountItems;
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index 3706cdf8..3f30732a 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -22,13 +22,53 @@
*/
#include "shop.h"
+#include "../utils/tostring.h"
+#include "../resources/itemmanager.h"
+
+ShopItems::~ShopItems()
+{
+ clear();
+}
int ShopItems::getNumberOfElements()
{
- return size();
+ return mItemsShop.size();
}
std::string ShopItems::getElementAt(int i)
{
- return at(i).name;
+ return mItemsShop.at(i).name;
+}
+
+void ShopItems::addItem(short id, int price)
+{
+ ITEM_SHOP item_shop;
+
+ item_shop.name = itemDb->getItemInfo(id).getName()
+ + " " + toString(price) + " GP";
+ item_shop.price = price;
+ item_shop.id = id;
+ item_shop.image = itemDb->getItemInfo(id).getImage();
+
+ mItemsShop.push_back(item_shop);
+}
+
+ITEM_SHOP ShopItems::at(int i)
+{
+ return mItemsShop.at(i);
+}
+
+void ShopItems::push_back(ITEM_SHOP item_shop)
+{
+ mItemsShop.push_back(item_shop);
+}
+
+void ShopItems::clear()
+{
+ mItemsShop.clear();
+}
+
+std::vector<ITEM_SHOP>* ShopItems::getShop()
+{
+ return &mItemsShop;
}
diff --git a/src/gui/shop.h b/src/gui/shop.h
index fb1f33fd..de452b5c 100644
--- a/src/gui/shop.h
+++ b/src/gui/shop.h
@@ -28,22 +28,34 @@
#include <vector>
#include <guichan/listmodel.hpp>
+#include "../resources/image.h"
struct ITEM_SHOP {
+ short id;
std::string name;
+ Image *image;
int price;
- short id;
int index;
int quantity;
};
-class ShopItems : public std::vector<ITEM_SHOP>, public gcn::ListModel
+class ShopItems : public gcn::ListModel
{
public:
/**
* Destructor
*/
- virtual ~ShopItems() {};
+ ~ShopItems();
+
+ /**
+ * Adds an item and its associated picture
+ */
+ void addItem(short id, int price);
+
+ /**
+ * Convenience function for adding items
+ */
+ void push_back(ITEM_SHOP item_shop);
/**
* Returns the number of items in the shop.
@@ -54,6 +66,25 @@ class ShopItems : public std::vector<ITEM_SHOP>, public gcn::ListModel
* Returns the name of item number i in the shop.
*/
std::string getElementAt(int i);
+
+ /**
+ * Returns the item number i in the shop.
+ */
+ ITEM_SHOP at(int i);
+
+ /**
+ * Clear the vector.
+ */
+ void clear();
+
+ /**
+ * Direct access to the vector
+ */
+ std::vector<ITEM_SHOP>* getShop();
+
+ private:
+ std::vector<ITEM_SHOP> mItemsShop;
+
};
#endif
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
new file mode 100644
index 00000000..61abff35
--- /dev/null
+++ b/src/gui/shoplistbox.cpp
@@ -0,0 +1,200 @@
+/*
+ * The Mana World
+ * Copyright 2004 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
+ *
+ * $Id: listbox.cpp 2655 2006-09-03 21:25:02Z b_lindeijer $
+ */
+
+#include "shoplistbox.h"
+
+#include "selectionlistener.h"
+
+#include <guichan/font.hpp>
+#include <guichan/graphics.hpp>
+#include <guichan/listmodel.hpp>
+#include <guichan/mouseinput.hpp>
+#include <guichan/imagefont.hpp>
+#include <guichan/basiccontainer.hpp>
+
+#include "../graphics.h"
+
+const int ITEM_SPRITE_HEIGHT = 32;
+
+ShopListBox::ShopListBox(gcn::ListModel *listModel):
+ gcn::ListBox(listModel),
+ mMousePressed(false),
+ mPlayerMoney(0)
+{
+ mRowHeight = getFont()->getHeight();
+ mPriceCheck = true;
+}
+
+ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel):
+ gcn::ListBox(listModel),
+ mMousePressed(false),
+ mPlayerMoney(0),
+ mShopItems(shopListModel)
+{
+ mRowHeight = (getFont()->getHeight() > ITEM_SPRITE_HEIGHT ?
+ getFont()->getHeight() : ITEM_SPRITE_HEIGHT);
+ mPriceCheck = true;
+}
+
+
+void ShopListBox::setPlayersMoney(int money)
+{
+ mPlayerMoney = money;
+}
+
+void ShopListBox::draw(gcn::Graphics *graphics)
+{
+ if (mListModel == NULL) {
+ return;
+ }
+
+ graphics->setFont(getFont());
+
+ // Draw the list elements
+ for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += mRowHeight)
+ {
+ graphics->setColor(gcn::Color(0xffffff));
+ if (mShopItems != NULL)
+ {
+ if(mPlayerMoney < mShopItems->at(i).price && mPriceCheck)
+ {
+ graphics->setColor(gcn::Color(0x919191));
+ }
+ }
+ graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight));
+ if (mShopItems)
+ dynamic_cast<Graphics*>(graphics)->drawImage(mShopItems->at(i).image, 1, y);
+ graphics->drawText(mListModel->getElementAt(i), ITEM_SPRITE_HEIGHT, y);
+ }
+
+ // Draw rectangle below the selected list element and the list element
+ // not shown.
+ if (mSelected >= 0) {
+ graphics->setColor(gcn::Color(110, 160, 255));
+ graphics->fillRectangle(gcn::Rectangle(0, mRowHeight * mSelected,
+ getWidth(), mRowHeight));
+ if (mShopItems)
+ dynamic_cast<Graphics*>(graphics)->drawImage(
+ mShopItems->at(mSelected).image, 1, mRowHeight * mSelected);
+ graphics->drawText(mListModel->getElementAt(mSelected),
+ ITEM_SPRITE_HEIGHT, mRowHeight * mSelected);
+ }
+}
+
+void ShopListBox::setSelected(int selected)
+{
+ gcn::ListBox::setSelected(selected);
+ if (mListModel != NULL)
+ {
+ gcn::BasicContainer *par = getParent();
+ if (par == NULL)
+ {
+ return;
+ }
+
+ gcn::Rectangle scroll;
+
+ if (mSelected < 0)
+ {
+ scroll.y = 0;
+ }
+ else
+ {
+ scroll.y = mRowHeight * mSelected;
+ }
+
+ scroll.height = mRowHeight;
+ par->showWidgetPart(this, scroll);
+ }
+ fireSelectionChangedEvent();
+}
+
+void ShopListBox::mousePress(int x, int y, int button)
+{
+
+ bool enoughMoney = false;
+ if (button == gcn::MouseInput::LEFT && hasMouse())
+ {
+ if (mShopItems)
+ {
+ if(mPlayerMoney >= mShopItems->at(y / mRowHeight).price)
+ enoughMoney = true;
+ }
+ else // Old Behaviour
+ enoughMoney = true;
+
+ if (!mPriceCheck)
+ enoughMoney = true;
+
+ if (enoughMoney)
+ {
+ setSelected(y / mRowHeight);
+ generateAction();
+ mMousePressed = true;
+ }
+ }
+}
+
+void ShopListBox::mouseRelease(int x, int y, int button)
+{
+ gcn::ListBox::mouseRelease(x, y, button);
+
+ mMousePressed = false;
+}
+
+void ShopListBox::mouseMotion(int x, int y)
+{
+ gcn::ListBox::mouseMotion(x, y);
+
+ // Pretend mouse is pressed continuously while dragged. Causes list
+ // selection to be updated as is default in many GUIs.
+ if (mMousePressed)
+ {
+ mousePress(x, y, gcn::MouseInput::LEFT);
+ }
+}
+
+void ShopListBox::fireSelectionChangedEvent()
+{
+ SelectionEvent event(this);
+ SelectionListeners::iterator i_end = mListeners.end();
+ SelectionListeners::iterator i;
+
+ for (i = mListeners.begin(); i != i_end; ++i)
+ {
+ (*i)->selectionChanged(event);
+ }
+}
+
+void ShopListBox::adjustSize()
+{
+ if (mListModel != NULL)
+ {
+ setHeight(mRowHeight * mListModel->getNumberOfElements());
+ }
+}
+
+void ShopListBox::setPriceCheck(bool check)
+{
+ mPriceCheck = check;
+}
diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h
new file mode 100644
index 00000000..2dff8977
--- /dev/null
+++ b/src/gui/shoplistbox.h
@@ -0,0 +1,124 @@
+/*
+ * The Mana World
+ * Copyright 2004 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
+ *
+ * $Id: listbox.h 2655 2006-09-03 21:25:02Z b_lindeijer $
+ */
+
+#ifndef _TMW_LISTBOX_H
+#define _TMW_LISTBOX_H
+
+#include <guichan/widgets/listbox.hpp>
+#include "shop.h"
+
+class SelectionListener;
+
+/**
+ * A list box, meant to be used inside a scroll area. Same as the Guichan list
+ * box except this one doesn't have a background, instead completely relying
+ * on the scroll area. It also adds selection listener functionality.
+ *
+ * \ingroup GUI
+ */
+class ShopListBox : public gcn::ListBox
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ShopListBox(gcn::ListModel *listModel);
+
+ /**
+ * Constructor with shopitems
+ */
+ ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel);
+
+ /**
+ * Draws the list box.
+ */
+ void draw(gcn::Graphics *graphics);
+
+ void mousePress(int x, int y, int button);
+ void mouseRelease(int x, int y, int button);
+ void mouseMotion(int x, int y);
+
+ /**
+ * Adds a listener to the list that's notified each time a change to
+ * the selection occurs.
+ */
+ void addSelectionListener(SelectionListener *listener)
+ {
+ mListeners.push_back(listener);
+ }
+
+ /**
+ * Removes a listener from the list that's notified each time a change
+ * to the selection occurs.
+ */
+ void removeSelectionListener(SelectionListener *listener)
+ {
+ mListeners.remove(listener);
+ }
+
+ /**
+ * Sets the index of the selected element.
+ */
+ void setSelected(int selected);
+
+ /**
+ * gives information about the current player's money
+ */
+ void setPlayersMoney(int money);
+
+ /**
+ * Adjust List draw size
+ */
+ void adjustSize();
+
+ /**
+ * Set on/off the disabling of too expensive items.
+ * (Good for selling mode.)
+ */
+ void setPriceCheck(bool check);
+
+ private:
+ /**
+ * Sends out selection events to the list of selection listeners.
+ */
+ void fireSelectionChangedEvent();
+
+ bool mMousePressed; /**< Keeps track of mouse pressed status. */
+
+ std::list<SelectionListener*> mListeners;
+
+ int mPlayerMoney;
+
+ /**
+ * Keeps another pointer to the same listModel, permitting to
+ * use the ShopItems specific functions.
+ */
+ ShopItems *mShopItems;
+
+ int mRowHeight; /**< Row Height */
+
+ bool mPriceCheck;
+
+};
+
+#endif
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 510e10ba..c29906a1 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -86,7 +86,8 @@ UpdaterWindow::UpdaterWindow():
mCancelButton->requestFocus();
setLocationRelativeTo(getParent());
- mUpdateHost = config.getValue("updatehost", "themanaworld.org/files");
+ mUpdateHost =
+ config.getValue("updatehost", "http://updates.themanaworld.org");
mBasePath = config.getValue("homeDir", ".");
// Try to download the updates list
diff --git a/src/main.cpp b/src/main.cpp
index c1919bc0..59bb1566 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -186,7 +186,7 @@ void initConfiguration(const Options &options)
config.setValue("sfxVolume", 100);
config.setValue("musicVolume", 60);
config.setValue("fpslimit", 0);
- config.setValue("updatehost", "http://themanaworld.org/files");
+ config.setValue("updatehost", "http://updates.themanaworld.org");
config.setValue("customcursor", 1);
config.setValue("homeDir", homeDir);
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp
index 173c59d2..473a706c 100644
--- a/src/net/buysellhandler.cpp
+++ b/src/net/buysellhandler.cpp
@@ -89,6 +89,7 @@ void BuySellHandler::handleMessage(MessageIn &msg)
msg.readShort(); // length
n_items = (msg.getLength() - 4) / 10;
if (n_items > 0) {
+ sellDialog->setMoney(player_node->mMoney);
sellDialog->reset();
sellDialog->setVisible(true);
diff --git a/src/player.cpp b/src/player.cpp
index 12f5f3d5..0acf8262 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -35,11 +35,10 @@
Player::Player(Uint16 id, Uint16 job, Map *map):
Being(id, job, map)
{
- /* Load the weapon sprite. When there are more different weapons this
- * should be moved to the setWeapon Method.
- */
- mSprites[WEAPON_SPRITE] =
- new AnimatedSprite("graphics/sprites/weapons.xml", 0);
+ // Load the weapon sprite.
+ // When there are more different weapons this should be moved to the
+ // setWeapon Method.
+ setWeapon(0);
}
Being::Type
@@ -88,6 +87,35 @@ Player::setSex(Uint8 sex)
}
}
+
+void
+Player::setWeapon(Uint16 weapon)
+{
+ if (weapon != mWeapon)
+ {
+ delete mSprites[WEAPON_SPRITE];
+ mSprites[WEAPON_SPRITE] = NULL;
+
+ switch (weapon)
+ {
+ case 0:
+ mSprites[WEAPON_SPRITE] = new AnimatedSprite("graphics/sprites/weapon-fist.xml", 0);
+ break;
+ case 1:
+ mSprites[WEAPON_SPRITE] = new AnimatedSprite("graphics/sprites/weapon-dagger.xml", 0);
+ break;
+ case 2:
+ mSprites[WEAPON_SPRITE] = new AnimatedSprite("graphics/sprites/weapon-bow.xml", 0);
+ break;
+ case 3:
+ mSprites[WEAPON_SPRITE] = new AnimatedSprite("graphics/sprites/weapon-scythe.xml", 0);
+ break;
+ }
+ }
+ Being::setWeapon(weapon);
+}
+
+
void
Player::setHairColor(Uint16 color)
{
diff --git a/src/player.h b/src/player.h
index 6ff4babe..3c061be6 100644
--- a/src/player.h
+++ b/src/player.h
@@ -58,6 +58,9 @@ class Player : public Being
virtual void
setVisibleEquipment(Uint8 slot, Uint8 id);
+ virtual void
+ setWeapon(Uint16 weapon);
+
private:
/**
* Resets all animations associated with this player. This is used to
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 23a73497..bb51d023 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -122,13 +122,9 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
return resIter->second;
}
- logger->log("ResourceManager::get(%s)", idPath.c_str());
-
int fileSize;
void *buffer = loadFile(idPath, fileSize);
-
if (!buffer) {
- logger->log("Warning: resource doesn't exist!");
return NULL;
}
@@ -265,6 +261,10 @@ ResourceManager::loadFile(const std::string &fileName, int &fileSize)
return NULL;
}
+ // Log the real dir of the file
+ logger->log("Loaded %s/%s", PHYSFS_getRealDir(fileName.c_str()),
+ fileName.c_str());
+
// Get the size of the file
fileSize = PHYSFS_fileLength(file);