summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-26 18:10:09 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-26 21:30:20 +0300
commit8f3d5cce14912a4c955a02f50a13130ca15b585e (patch)
tree7a3d944c9a8841383b97e1824c2c1335924fd9f0 /src/gui/windows
parentdbe86e8285d4029bb641500849f696118d3d5949 (diff)
downloadplus-8f3d5cce14912a4c955a02f50a13130ca15b585e.tar.gz
plus-8f3d5cce14912a4c955a02f50a13130ca15b585e.tar.bz2
plus-8f3d5cce14912a4c955a02f50a13130ca15b585e.tar.xz
plus-8f3d5cce14912a4c955a02f50a13130ca15b585e.zip
Add tabs for stats in status window.
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/statuswindow.cpp158
-rw-r--r--src/gui/windows/statuswindow.h29
2 files changed, 35 insertions, 152 deletions
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
index c762084fd..461d5e01d 100644
--- a/src/gui/windows/statuswindow.cpp
+++ b/src/gui/windows/statuswindow.cpp
@@ -36,21 +36,18 @@
#include "gui/windows/setupwindow.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/createwidget.h"
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/layouttype.h"
#include "gui/widgets/progressbar.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/vertcontainer.h"
+#include "gui/widgets/statspage.h"
+#include "gui/widgets/statspagebasic.h"
+#include "gui/widgets/tabbedarea.h"
#include "gui/widgets/windowcontainer.h"
-#include "gui/widgets/attrs/changedisplay.h"
-#include "gui/widgets/attrs/derdisplay.h"
-
#include "net/inventoryhandler.h"
#include "net/playerhandler.h"
-#include "resources/db/statdb.h"
-
#include "resources/item/item.h"
#include "utils/gettext.h"
@@ -65,6 +62,7 @@ StatusWindow::StatusWindow() :
ActionListener(),
AttributeListener(),
StatListener(),
+ mTabs(CREATEWIDGETR(TabbedArea, this)),
// TRANSLATORS: status window label
mLvlLabel(new Label(this, strprintf(_("Level: %d"), 0))),
// TRANSLATORS: status window label
@@ -80,14 +78,9 @@ StatusWindow::StatusWindow() :
mJobLvlLabel(nullptr),
mJobLabel(nullptr),
mJobBar(nullptr),
- mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(this, mAttrCont, false)),
- mDAttrCont(new VertContainer(this, 32)),
- mDAttrScroll(new ScrollArea(this, mDAttrCont, false)),
- mCharacterPointsLabel(new Label(this, "C")),
+ mBasicStatsPage(new StatsPageBasic(this)),
// TRANSLATORS: status window button
- mCopyButton(new Button(this, _("Copy to chat"), "copy", this)),
- mAttrs()
+ mCopyButton(new Button(this, _("Copy to chat"), "copy", this))
{
setWindowName("Status");
if (setupWindow)
@@ -193,21 +186,10 @@ StatusWindow::StatusWindow() :
place(3, 0, mMoneyLabel, 3);
}
- // ----------------------
- // Stats Part
- // ----------------------
-
- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- place(0, 3, mAttrScroll, 5, 3);
-
- mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- place(6, 3, mDAttrScroll, 5, 3);
+ place(0, 3, mTabs, 9, 3);
getLayout().setRowHeight(3, LayoutType::SET);
- place(0, 6, mCharacterPointsLabel, 5);
place(0, 5, mCopyButton);
loadWindowState();
@@ -222,35 +204,30 @@ StatusWindow::StatusWindow() :
mMoneyLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency(
PlayerInfo::getAttribute(Attributes::MONEY)).c_str()));
mMoneyLabel->adjustSize();
- // TRANSLATORS: status window label
- mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)));
- mCharacterPointsLabel->adjustSize();
updateLevelLabel();
+ addTabs();
}
-void StatusWindow::addAttributes()
+void StatusWindow::addTabs()
{
- clearAttributes();
+ // TRANSLATORS: status window tab name
+ addTabBasic(_("Basic"));
+ // TRANSLATORS: status window tab name
+ addTab(_("Extended"));
+ mTabs->adjustSize();
+}
- const std::vector<BasicStat> &basicStats = StatDb::getBasicStats();
- FOR_EACH (std::vector<BasicStat>::const_iterator, it, basicStats)
- {
- const BasicStat &stat = *it;
- addAttribute(stat.attr,
- stat.name,
- stat.tag,
- Modifiable_true);
- }
+void StatusWindow::addTab(const std::string &name)
+{
+ mTabs->addTab(name,
+ new StatsPage(this));
+}
- const std::vector<BasicStat> &extendedStats = StatDb::getExtendedStats();
- FOR_EACH (std::vector<BasicStat>::const_iterator, it, extendedStats)
- {
- const BasicStat &stat = *it;
- addAttribute(stat.attr,
- stat.name);
- }
+void StatusWindow::addTabBasic(const std::string &name)
+{
+ mTabs->addTab(name,
+ mBasicStatsPage);
}
void StatusWindow::updateLevelLabel()
@@ -325,9 +302,6 @@ void StatusWindow::statChanged(const AttributesT id,
else
{
updateMPBar(mMpBar, true);
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && it->second)
- it->second->update();
}
}
@@ -361,32 +335,6 @@ void StatusWindow::attributeChanged(const AttributesT id,
mMoneyLabel->adjustSize();
break;
- case Attributes::PLAYER_CHAR_POINTS:
- mCharacterPointsLabel->setCaption(strprintf(
- // TRANSLATORS: status window label
- _("Character points: %d"), newVal));
-
- mCharacterPointsLabel->adjustSize();
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second)
- it->second->update();
- }
- break;
-
- // ??
- case Attributes::PLAYER_CORR_POINTS:
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second)
- it->second->update();
- }
- break;
-
case Attributes::PLAYER_LEVEL:
// TRANSLATORS: status window label
mLvlLabel->setCaption(strprintf(_("Level: %d"), newVal));
@@ -402,45 +350,7 @@ void StatusWindow::attributeChanged(const AttributesT id,
void StatusWindow::setPointsNeeded(const AttributesT id,
const int needed)
{
- const Attrs::const_iterator it = mAttrs.find(id);
-
- if (it != mAttrs.end())
- {
- AttrDisplay *const disp = it->second;
- if (disp && disp->getType() == AttrDisplay::CHANGEABLE)
- static_cast<ChangeDisplay*>(disp)->setPointsNeeded(needed);
- }
-}
-
-void StatusWindow::addAttribute(const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName,
- const Modifiable modifiable)
-{
- AttrDisplay *disp;
-
- if (modifiable == Modifiable_true)
- {
- disp = new ChangeDisplay(this, id, name, shortName);
- disp->update();
- mAttrCont->add1(disp);
- }
- else
- {
- disp = new DerDisplay(this, id, name, shortName);
- disp->update();
- mDAttrCont->add1(disp);
- }
- mAttrs[id] = disp;
-}
-
-void StatusWindow::clearAttributes()
-{
- mAttrCont->clear();
- mDAttrCont->clear();
- FOR_EACH (Attrs::iterator, it, mAttrs)
- delete (*it).second;
- mAttrs.clear();
+ mBasicStatsPage->setPointsNeeded(id, needed);
}
void StatusWindow::updateHPBar(ProgressBar *const bar, const bool showMax)
@@ -694,20 +604,6 @@ void StatusWindow::action(const ActionEvent &event)
if (event.getId() == "copy")
{
- Attrs::const_iterator it = mAttrs.begin();
- const Attrs::const_iterator it_end = mAttrs.end();
- std::string str;
- while (it != it_end)
- {
- const ChangeDisplay *const attr = dynamic_cast<ChangeDisplay*>(
- (*it).second);
- if (attr)
- {
- str.append(strprintf("%s:%s ", attr->getShortName().c_str(),
- attr->getValue().c_str()));
- }
- ++ it;
- }
- chatWindow->addInputText(str);
+ chatWindow->addInputText(mBasicStatsPage->getStatsStr());
}
}
diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h
index 539c23a39..2bb457acf 100644
--- a/src/gui/windows/statuswindow.h
+++ b/src/gui/windows/statuswindow.h
@@ -25,8 +25,6 @@
#include "gui/widgets/window.h"
-#include "enums/simpletypes/modifiable.h"
-
#include "listeners/actionlistener.h"
#include "listeners/attributelistener.h"
#include "listeners/statlistener.h"
@@ -36,6 +34,8 @@ class Button;
class Label;
class ProgressBar;
class ScrollArea;
+class StatsPageBasic;
+class TabbedArea;
class VertContainer;
/**
@@ -59,11 +59,6 @@ class StatusWindow final : public Window,
void setPointsNeeded(const AttributesT id,
const int needed);
- void addAttribute(const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName = "",
- const Modifiable modifiable = Modifiable_false);
-
static void updateHPBar(ProgressBar *const bar,
const bool showMax = false);
void updateMPBar(ProgressBar *bar, const bool showMax = false) const;
@@ -87,8 +82,6 @@ class StatusWindow final : public Window,
void action(const ActionEvent &event) override;
- void clearAttributes();
-
void attributeChanged(const AttributesT id,
const int oldVal,
const int newVal) override final;
@@ -99,15 +92,15 @@ class StatusWindow final : public Window,
void updateLevelLabel();
- void addAttributes();
-
private:
+ void addTabs();
+ void addTab(const std::string &name);
+ void addTabBasic(const std::string &name);
+
static std::string translateLetter(const char *const letters);
static std::string translateLetter2(const std::string &letters);
- /**
- * Status Part
- */
+ TabbedArea *mTabs A_NONNULLPOINTER;
Label *mLvlLabel A_NONNULLPOINTER;
Label *mMoneyLabel A_NONNULLPOINTER;
Label *mHpLabel A_NONNULLPOINTER;
@@ -121,16 +114,10 @@ class StatusWindow final : public Window,
Label *mJobLabel;
ProgressBar *mJobBar;
- VertContainer *mAttrCont A_NONNULLPOINTER;
- ScrollArea *mAttrScroll A_NONNULLPOINTER;
- VertContainer *mDAttrCont A_NONNULLPOINTER;
- ScrollArea *mDAttrScroll A_NONNULLPOINTER;
+ StatsPageBasic *mBasicStatsPage;
Label *mCharacterPointsLabel A_NONNULLPOINTER;
Button *mCopyButton;
-
- typedef std::map<AttributesT, AttrDisplay*> Attrs;
- Attrs mAttrs;
};
extern StatusWindow *statusWindow;