summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/itemcontainer.cpp26
-rw-r--r--src/gui/itemcontainer.h65
-rw-r--r--src/gui/setup.cpp27
3 files changed, 63 insertions, 55 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index f727d820..51d093b7 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -34,16 +34,18 @@ ItemContainer::ItemContainer()
itemset = new Spriteset(itemImg, 20, 20);
selImg = resman->getImage("graphics/gui/selection.png", IMG_ALPHA);
- if (!selImg) logger.error("Unable to load items.png");
+ if (!selImg) logger.error("Unable to load selection.png");
+
+ selectedItem = -1; // No item selected
- selectedItem = -1; /**< No item selected */
-
for (int i = 0; i < INVENTORY_SIZE; i++) {
items[i].id = -1;
items[i].quantity = 0;
items[i].equipment = false;
items[i].equipped = false;
}
+
+ addMouseListener(this);
}
ItemContainer::~ItemContainer()
@@ -60,12 +62,12 @@ void ItemContainer::draw(gcn::Graphics* graphics)
if (items[selectedItem].quantity <= 0) {
selectedItem = -1;
}
-
+
if (selectedItem >= 0) {
int itemX = (((selectedItem - 2) * 24) % (getWidth() - 24));
int itemY = (((selectedItem - 2) * 24) / (getWidth() - 24)) * 24;
itemX -= itemX % 24;
- selImg->draw(screen, x + itemX, y+itemY);
+ selImg->draw(screen, x + itemX, y+itemY);
}
for (int i = 0; i < INVENTORY_SIZE; i++) {
@@ -183,17 +185,11 @@ void ItemContainer::increaseQuantity(int index, int quantity)
void ItemContainer::mousePress(int mx, int my, int button)
{
- if (button == gcn::MouseInput::LEFT)
+ if (button == gcn::MouseInput::LEFT) {
selectedItem = ((mx + 48) / 24) + ((my / 24) * (getWidth() / 24));
- if (selectedItem > INVENTORY_SIZE)
+ }
+ if (selectedItem > INVENTORY_SIZE) {
selectedItem = INVENTORY_SIZE;
-}
-
-void ItemContainer::_mouseInputMessage(const gcn::MouseInput &mouseInput)
-{
- if (mouseInput.getButton() == gcn::MouseInput::LEFT) {
- gcn::Widget::_mouseInputMessage(mouseInput);
- mousePress(mouseInput.x, mouseInput.y, mouseInput.getButton());
}
}
@@ -227,7 +223,7 @@ int ItemContainer::getNumberOfSlotsUsed()
NumberOfFilledSlot++;
}
}
-
+
return NumberOfFilledSlot;
}
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index ed332345..849bd252 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -32,11 +32,15 @@
#define INVENTORY_SIZE 100
-struct ITEM_HOLDER { // the holder of a item
- int id; // the id of the item
- int quantity; // number of items
- bool equipment;
- bool equipped;
+/**
+ * The holder of a item.
+ */
+struct ITEM_HOLDER
+{
+ int id; /**< The id of the item */
+ int quantity; /**< The number of items */
+ bool equipment; /**< Whether this item is equipment */
+ bool equipped; /**< Whether this item is equipped */
};
/**
@@ -44,15 +48,14 @@ struct ITEM_HOLDER { // the holder of a item
*
* \ingroup GUI
*/
-class ItemContainer : public gcn::Widget
+class ItemContainer : public gcn::Widget, public gcn::MouseListener
{
private:
-
Spriteset *itemset;
- Image *selImg;
+ Image *selImg;
int selectedItem;
int itemNumber;
- ITEM_HOLDER items[INVENTORY_SIZE]; /**< this is the holder of items */
+ ITEM_HOLDER items[INVENTORY_SIZE]; /**< The holder of items */
public:
/**
@@ -74,52 +77,52 @@ class ItemContainer : public gcn::Widget
* Handles mouse click.
*/
void mousePress(int mx, int my, int button);
-
+
/**
* Returns index of the selected item.
*/
int getIndex();
-
+
/**
* Finds the index of an item.
*/
int getIndex(int id);
-
+
/**
* Returns the id of the selected item.
*/
int getId();
-
+
/**
* Returns the id of an item.
*/
int getId(int index);
-
+
/**
* Returns the quantity of the selected item.
*/
int getQuantity();
-
+
/**
* Returns the quantity of an item.
*/
int getQuantity(int index);
-
+
/**
* Returns id of next free slot or -1 if all occupied.
*/
int getFreeSlot();
-
+
/**
* Adds a new item.
*/
void addItem(int index, int id, int quantity, bool equipment);
-
+
/**
* Reset all item slots.
*/
void resetItems();
-
+
/**
* Remove a item from the inventory.
*/
@@ -134,17 +137,27 @@ class ItemContainer : public gcn::Widget
* Increase quantity of an item.
*/
void increaseQuantity(int index, int quantity);
-
- void _mouseInputMessage(const gcn::MouseInput &mouseInput);
-
+
+ /**
+ * Returns whether the item at the specified index is equipment.
+ */
bool isEquipment(int index);
-
+
+ /**
+ * Returns whether the item at the specified index is equipped.
+ */
bool isEquipped(int index);
-
+
+ /**
+ * Sets whether the item at the specified index is equipped.
+ */
void setEquipped(int index, bool equipped);
-
+
+ /**
+ * Sets whether the item at the specified index is equipment.
+ */
void setEquipment(int index, bool equipment);
-
+
/**
* Get the number of slots filled with an item
*/
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 42b770f9..a0be66cc 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -39,15 +39,15 @@ ModeListModel::ModeListModel()
SDL_Rect **modes;
/* Get available fullscreen/hardware modes */
- modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
-
+ modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
+
/* Check is there are any modes available */
- if(modes == (SDL_Rect **)0) {
+ if (modes == (SDL_Rect **)0) {
logger.log("No modes available");
}
-
+
/* Check if our resolution is restricted */
- if(modes == (SDL_Rect **)-1) {
+ if (modes == (SDL_Rect **)-1) {
logger.log("All resolutions available");
}
else{
@@ -64,7 +64,6 @@ ModeListModel::ModeListModel()
ModeListModel::~ModeListModel()
{
- //delete videoModes;
}
int ModeListModel::getNumberOfElements()
@@ -89,7 +88,7 @@ Setup::Setup():
fsCheckBox = new CheckBox("Full screen", false);
openGlCheckBox = new CheckBox("OpenGL", false);
openGlCheckBox->setEnabled(false);
- alphaLabel = new gcn::Label("Gui opacity:");
+ alphaLabel = new gcn::Label("Gui opacity");
alphaSlider = new Slider(0.2, 1.0);
audioLabel = new gcn::Label("Audio settings");
soundCheckBox = new CheckBox("Sound", false);
@@ -128,14 +127,14 @@ Setup::Setup():
applyButton->setPosition(
cancelButton->getX() - 5 - applyButton->getWidth(),
216 - 5 - applyButton->getHeight());
-
+
// Listen for actions
applyButton->addActionListener(this);
cancelButton->addActionListener(this);
alphaSlider->addActionListener(this);
sfxSlider->addActionListener(this);
musicSlider->addActionListener(this);
-
+
// Assemble dialog
add(videoLabel);
add(scrollArea);
@@ -202,7 +201,7 @@ void Setup::action(const std::string &eventId)
else if (eventId == "apply")
{
setVisible(false);
-
+
if (fsCheckBox->isMarked()) { // Fullscreen
config.setValue("screen", 1);
displayFlags |= SDL_FULLSCREEN;
@@ -211,16 +210,16 @@ void Setup::action(const std::string &eventId)
config.setValue("screen", 0);
displayFlags &= ~SDL_FULLSCREEN;
}
-
+
displayFlags |= SDL_DOUBLEBUF;
-
+
screen = SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags);
if (screen == NULL) {
std::cerr << "Couldn't set " << screenW << "x" << screenH << "x" <<
bitDepth << " video mode: " << SDL_GetError() << std::endl;
exit(1);
}
-
+
// Sound settings
if (soundCheckBox->isMarked()) {
config.setValue("sound", 1);
@@ -229,7 +228,7 @@ void Setup::action(const std::string &eventId)
}
catch (const char *err) {
new OkDialog(this, "Sound Engine", err);
- logger.log("Warning: %s", err);
+ logger.log("Warning: %s", err);
}
} else {
config.setValue("sound", 0);