summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/ministatus.cpp27
-rw-r--r--src/gui/ministatus.h8
-rw-r--r--src/gui/statuswindow.cpp21
-rw-r--r--src/gui/statuswindow.h3
4 files changed, 53 insertions, 6 deletions
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index 71e81abf8..ab894b3a8 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -87,6 +87,9 @@ MiniStatusWindow::MiniStatusWindow():
mWeightBar = createBar(0, 140, 20, Theme::PROG_WEIGHT,
"weight bar", _("weight bar"));
+ mInvSlotsBar = createBar(0, 45, 20, Theme::PROG_INVY_SLOTS,
+ "inventory slots bar", _("inventory slots bar"));
+
mStatusBar = createBar(100, 150, 20, Theme::PROG_EXP,
"status bar", _("status bar"));
@@ -99,6 +102,9 @@ MiniStatusWindow::MiniStatusWindow():
mTextPopup = new TextPopup();
addMouseListener(this);
+ Inventory *inv = PlayerInfo::getInventory();
+ if (inv)
+ inv->addInventoyListener(this);
updateStatus();
}
@@ -109,6 +115,10 @@ MiniStatusWindow::~MiniStatusWindow()
delete mStatusPopup;
mStatusPopup = 0;
+ Inventory *inv = PlayerInfo::getInventory();
+ if (inv)
+ inv->removeInventoyListener(this);
+
std::list <ProgressBar*>::iterator it, it_end;
for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it)
{
@@ -203,7 +213,7 @@ void MiniStatusWindow::event(Channels channel _UNUSED_,
else if (id == EXP || id == EXP_NEEDED)
StatusWindow::updateXPBar(mXpBar);
else if (id == TOTAL_WEIGHT || id == MAX_WEIGHT)
- StatusWindow::updateWeightBar(mWeightBar, false);
+ StatusWindow::updateWeightBar(mWeightBar);
}
else if (event.getName() == EVENT_UPDATESTAT)
{
@@ -348,10 +358,12 @@ void MiniStatusWindow::showBar(std::string name, bool isVisible)
void MiniStatusWindow::loadBars()
{
- if (!config.getValue("ministatussaved", false))
+ if (!config.getValue("ministatussaved", 0))
{
if (mWeightBar)
mWeightBar->setVisible(false);
+ if (mInvSlotsBar)
+ mInvSlotsBar->setVisible(false);
return;
}
@@ -386,4 +398,13 @@ void MiniStatusWindow::saveBars()
config.deleteKey("ministatus" + toString(f));
config.setValue("ministatussaved", true);
-} \ No newline at end of file
+}
+
+void MiniStatusWindow::slotsChanged(Inventory* inventory)
+{
+ if (!inventory)
+ return;
+
+ if (inventory->getType() == Inventory::INVENTORY)
+ StatusWindow::updateInvSlotsBar(mInvSlotsBar);
+}
diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h
index ead2a5f51..3cf9eef16 100644
--- a/src/gui/ministatus.h
+++ b/src/gui/ministatus.h
@@ -22,6 +22,7 @@
#ifndef MINISTATUS_H
#define MINISTATUS_H
+#include "inventory.h"
#include "listener.h"
#include "gui/widgets/popup.h"
@@ -46,7 +47,9 @@ class TextPopup;
*
* \ingroup Interface
*/
-class MiniStatusWindow : public Popup, public Mana::Listener
+class MiniStatusWindow : public Popup,
+ public InventoryListener,
+ public Mana::Listener
{
public:
MiniStatusWindow();
@@ -80,6 +83,8 @@ class MiniStatusWindow : public Popup, public Mana::Listener
void updateBars();
+ void slotsChanged(Inventory* inventory);
+
std::list <ProgressBar*> &getBars()
{ return mBars; }
@@ -102,6 +107,7 @@ class MiniStatusWindow : public Popup, public Mana::Listener
ProgressBar *mXpBar;
ProgressBar *mJobBar;
ProgressBar *mWeightBar;
+ ProgressBar *mInvSlotsBar;
ProgressBar *mStatusBar;
TextPopup *mTextPopup;
StatusPopup *mStatusPopup;
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 853c490bf..30fec8773 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -23,6 +23,7 @@
#include "configuration.h"
#include "event.h"
+#include "inventory.h"
#include "localplayer.h"
#include "playerinfo.h"
#include "units.h"
@@ -522,7 +523,7 @@ void StatusWindow::updateProgressBar(ProgressBar *bar, int id, bool percent)
updateProgressBar(bar, exp.first, exp.second, percent);
}
-void StatusWindow::updateWeightBar(ProgressBar *bar, bool percent)
+void StatusWindow::updateWeightBar(ProgressBar *bar)
{
if (!bar)
return;
@@ -547,6 +548,24 @@ void StatusWindow::updateWeightBar(ProgressBar *bar, bool percent)
}
}
+void StatusWindow::updateInvSlotsBar(ProgressBar *bar)
+{
+ Inventory *inv = PlayerInfo::getInventory();
+ if (!inv)
+ return;
+
+ const int usedSlots = inv->getNumberOfSlotsUsed();
+ const int maxSlots = inv->getSize();
+
+ if (maxSlots)
+ {
+ bar->setProgress(static_cast<float>(usedSlots)
+ / static_cast<float>(maxSlots));
+ }
+
+ bar->setText(strprintf("%d", usedSlots));
+}
+
void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent _UNUSED_)
{
if (!player_node || !viewport)
diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h
index 47f87254f..38ae16e37 100644
--- a/src/gui/statuswindow.h
+++ b/src/gui/statuswindow.h
@@ -66,7 +66,8 @@ class StatusWindow : public Window, public Mana::Listener
static void updateMPBar(ProgressBar *bar, bool showMax = false);
static void updateJobBar(ProgressBar *bar, bool percent = true);
static void updateXPBar(ProgressBar *bar, bool percent = true);
- static void updateWeightBar(ProgressBar *bar, bool percent = true);
+ static void updateWeightBar(ProgressBar *bar);
+ static void updateInvSlotsBar(ProgressBar *bar);
static void updateStatusBar(ProgressBar *bar, bool percent = true);
static void updateProgressBar(ProgressBar *bar, int value, int max,
bool percent);