summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-20 22:47:48 -0700
committerIra Rice <irarice@gmail.com>2009-01-20 22:47:48 -0700
commit8b88dffb8222bb4c59d09e11c00b1046f93d51fe (patch)
treec8356ddf4e4c72734c5f33bab72c82ef82fc29fc /src/gui
parentb0ff8cc281d7e7f8f3c2666d6bbe6424fec74f9c (diff)
downloadmana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.gz
mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.bz2
mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.tar.xz
mana-8b88dffb8222bb4c59d09e11c00b1046f93d51fe.zip
Reflowed inventory window to use layout code, as well as fixed the npc
list dialog to be more consistant with other windows. Also revised the skill window to default to being only as big as the number of skills listed. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp93
-rw-r--r--src/gui/inventorywindow.h17
-rw-r--r--src/gui/npclistdialog.cpp22
-rw-r--r--src/gui/npclistdialog.h7
-rw-r--r--src/gui/skill.cpp42
5 files changed, 62 insertions, 119 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index efe1cd51..72507d23 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -21,8 +21,11 @@
#include <string>
+#include <guichan/font.hpp>
#include <guichan/mouseinput.hpp>
+#include <guichan/widgets/label.hpp>
+
#include "button.h"
#include "gui.h"
#include "inventorywindow.h"
@@ -31,6 +34,8 @@
#include "scrollarea.h"
#include "viewport.h"
+#include "widgets/layout.h"
+
#include "../inventory.h"
#include "../item.h"
#include "../localplayer.h"
@@ -48,7 +53,7 @@ InventoryWindow::InventoryWindow():
setWindowName(_("Inventory"));
setResizable(true);
setCloseButton(true);
- setMinWidth(240);
+
// If you adjust these defaults, don't forget to adjust the trade window's.
setDefaultSize(115, 25, 322, 200);
@@ -68,19 +73,24 @@ InventoryWindow::InventoryWindow():
mMaxWeight + _(" g Slots: ") +
toString(player_node->getInventory()->getNumberOfSlotsUsed()) +
"/" + toString(player_node->getInventory()->getInventorySize());
- mWeightLabel = new TextBox();
- mWeightLabel->setPosition(8, 8);
+ mWeightLabel = new gcn::Label(mWeight);
- draw();
+ setMinHeight(130);
+ setMinWidth(getFont()->getWidth(mWeight));
- add(mUseButton);
- add(mDropButton);
- add(mInvenScroll);
- add(mWeightLabel);
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
- mUseButton->setSize(60, mUseButton->getHeight());
+ place(0, 0, mInvenScroll, 5, 4);
+ place(0, 4, mWeightLabel, 5);
+ place(3, 5, mDropButton);
+ place(4, 5, mUseButton);
+
+ Layout &layout = getLayout();
+ layout.setRowHeight(0, Layout::AUTO_SET);
loadWindowState();
+ setLocationRelativeTo(getParent());
}
void InventoryWindow::logic()
@@ -103,7 +113,7 @@ void InventoryWindow::logic()
toString(player_node->getInventory()->getNumberOfSlotsUsed()) +
"/" + toString(player_node->getInventory()->getInventorySize());
- draw();
+ setMinWidth(getFont()->getWidth(mWeight));
}
}
@@ -114,36 +124,30 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
if (!item)
return;
- if (event.getId() == "use") {
- if (item->isEquipment()) {
- if (item->isEquipped()) {
+ if (event.getId() == "use")
+ {
+ if (item->isEquipment())
+ {
+ if (item->isEquipped())
player_node->unequipItem(item);
- }
- else {
+ else
player_node->equipItem(item);
- }
}
- else {
+ else
player_node->useItem(item);
- }
}
else if (event.getId() == "drop")
{
- if (item->getQuantity() == 1) {
+ if (item->getQuantity() == 1)
player_node->dropItem(item, 1);
- }
- else {
+ else
+ {
// Choose amount of items to drop
new ItemAmountWindow(AMOUNT_ITEM_DROP, this, item);
}
}
}
-void InventoryWindow::valueChanged(const gcn::SelectionEvent &event)
-{
- draw();
-}
-
void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
Window::mouseClicked(event);
@@ -164,48 +168,19 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
}
-void InventoryWindow::draw()
-{
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
- const int height = area.height;
-
- // Update weight information
- mWeightLabel->setTextWrapped(mWeight);
- mWeightLabel->setMinWidth(width - 16);
-
- mUseButton->setPosition(8, height - 8 - mUseButton->getHeight());
- mDropButton->setPosition(8 + mUseButton->getWidth() + 5,
- mUseButton->getY());
-
- mInvenScroll->setSize(width - 16,
- mUseButton->getY() - (mWeightLabel->getNumberOfRows()*15) - 18);
- mInvenScroll->setPosition(8, (mWeightLabel->getNumberOfRows()*15) + 10);
-
- setMinHeight(130 + (mWeightLabel->getNumberOfRows()*15));
-}
-
-void InventoryWindow::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
- draw();
-}
-
void InventoryWindow::updateButtons()
{
const Item *selectedItem = mItems->getSelectedItem();
if (selectedItem && selectedItem->isEquipment())
{
- if (selectedItem->isEquipped()) {
+ if (selectedItem->isEquipped())
mUseButton->setCaption(_("Unequip"));
- }
- else {
+ else
mUseButton->setCaption(_("Equip"));
- } }
- else {
- mUseButton->setCaption(_("Use"));
}
+ else
+ mUseButton->setCaption(_("Use"));
mUseButton->setEnabled(selectedItem != 0);
mDropButton->setEnabled(selectedItem != 0);
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 922dd28f..166bf1c4 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -62,23 +62,8 @@ class InventoryWindow : public Window, gcn::ActionListener,
*/
Item* getSelectedItem() const;
- /**
- * Updates labels to currently selected item.
- */
- void valueChanged(const gcn::SelectionEvent &event);
-
void mouseClicked(gcn::MouseEvent &event);
- /**
- * Updates window drawing.
- */
- void draw();
-
- /**
- * Called whenever the widget changes size.
- */
- void widgetResized(const gcn::Event &event);
-
private:
void updateButtons(); /**< Updates button states. */
@@ -89,7 +74,7 @@ class InventoryWindow : public Window, gcn::ActionListener,
std::string mMaxWeight;
gcn::Button *mUseButton, *mDropButton;
gcn::ScrollArea *mInvenScroll;
- TextBox *mWeightLabel;
+ gcn::Label *mWeightLabel;
bool mItemDesc;
};
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index e18b2ae8..7ecd0a74 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -47,8 +47,8 @@ NpcListDialog::NpcListDialog():
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
place(0, 0, scrollArea, 5).setPadding(3);
- place(3, 1, cancelButton);
- place(4, 1, okButton);
+ place(3, 1, okButton);
+ place(4, 1, cancelButton);
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -81,24 +81,6 @@ void NpcListDialog::reset()
mItems.clear();
}
-void NpcListDialog::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- const gcn::Rectangle &area = getChildrenArea();
- const int width = area.width;
- const int height = area.height;
-
- scrollArea->setDimension(gcn::Rectangle(
- 5, 5, width - 10, height - 15 - okButton->getHeight()));
- cancelButton->setPosition(
- width - 5 - cancelButton->getWidth(),
- height - 5 - cancelButton->getHeight());
- okButton->setPosition(
- cancelButton->getX() - 5 - okButton->getWidth(),
- cancelButton->getY());
-}
-
void NpcListDialog::action(const gcn::ActionEvent &event)
{
int choice = 0;
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index 099d03c0..bc58cdcd 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -51,13 +51,6 @@ class NpcListDialog : public Window, public gcn::ActionListener,
NpcListDialog();
/**
- * Called when resizing the window
- *
- * @param event The calling event
- */
- void widgetResized(const gcn::Event &event);
-
- /**
* Called when receiving actions from the widgets.
*/
void action(const gcn::ActionEvent &event);
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 35a41659..bc28123a 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -60,14 +60,17 @@ public:
update();
}
- virtual int getRows(void) { return mEntriesNr; }
+ virtual int getRows(void)
+ {
+ return mEntriesNr;
+ }
virtual int getColumnWidth(int index)
{
- switch (index) {
- case 0: return 160;
- default: return 35;
- }
+ if (index == 0)
+ return 160;
+
+ return 35;
}
virtual int getRowHeight(void)
@@ -82,7 +85,8 @@ public:
mEntriesNr = mDialog->getSkills().size();
resize();
- for (int i = 0; i < mEntriesNr; i++) {
+ for (int i = 0; i < mEntriesNr; i++)
+ {
SKILL *skill = mDialog->getSkills()[i];
SkillInfo const *info;
char tmp[128];
@@ -127,6 +131,9 @@ SkillDialog::SkillDialog():
setCloseButton(true);
setDefaultSize(windowContainer->getWidth() - 260, 25, 255, 260);
+ setMinHeight(50 + mTableModel->getHeight());
+ setMinWidth(200);
+
// mSkillListBox = new ListBox(this);
ScrollArea *skillScrollArea = new ScrollArea(&mTable);
mPointsLabel = new gcn::Label(strprintf(_("Skill points: %d"), 0));
@@ -166,9 +173,7 @@ void SkillDialog::action(const gcn::ActionEvent &event)
// Increment skill
int selectedSkill = mTable.getSelectedRow();//mSkillListBox->getSelected();
if (selectedSkill >= 0)
- {
player_node->raiseSkill(mSkillList[selectedSkill]->id);
- }
}
else if (event.getId() == "skill")
{
@@ -177,9 +182,7 @@ void SkillDialog::action(const gcn::ActionEvent &event)
player_node->mSkillPoint > 0);
}
else if (event.getId() == "close")
- {
setVisible(false);
- }
}
void SkillDialog::update()
@@ -189,7 +192,8 @@ void SkillDialog::update()
int selectedSkill = mTable.getSelectedRow();
- if (selectedSkill >= 0) {
+ if (selectedSkill >= 0)
+ {
int skillId = mSkillList[selectedSkill]->id;
bool modifiable;
@@ -200,10 +204,12 @@ void SkillDialog::update()
mIncButton->setEnabled(modifiable
&& player_node->mSkillPoint > 0);
- } else
+ }
+ else
mIncButton->setEnabled(false);
mTableModel->update();
+ setMinHeight(50 + mTableModel->getHeight());
}
int SkillDialog::getNumberOfElements()
@@ -213,10 +219,10 @@ int SkillDialog::getNumberOfElements()
bool SkillDialog::hasSkill(int id)
{
- for (unsigned int i = 0; i < mSkillList.size(); i++) {
- if (mSkillList[i]->id == id) {
+ for (unsigned int i = 0; i < mSkillList.size(); i++)
+ {
+ if (mSkillList[i]->id == id)
return true;
- }
}
return false;
}
@@ -232,8 +238,10 @@ void SkillDialog::addSkill(int id, int lvl, int mp)
void SkillDialog::setSkill(int id, int lvl, int mp)
{
- for (unsigned int i = 0; i < mSkillList.size(); i++) {
- if (mSkillList[i]->id == id) {
+ for (unsigned int i = 0; i < mSkillList.size(); i++)
+ {
+ if (mSkillList[i]->id == id)
+ {
mSkillList[i]->lv = lvl;
mSkillList[i]->sp = mp;
}