summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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/widgets
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/widgets')
-rw-r--r--src/gui/widgets/attrs/attrdisplay.h3
-rw-r--r--src/gui/widgets/statspage.cpp77
-rw-r--r--src/gui/widgets/statspage.h54
-rw-r--r--src/gui/widgets/statspagebasic.cpp156
-rw-r--r--src/gui/widgets/statspagebasic.h67
5 files changed, 357 insertions, 0 deletions
diff --git a/src/gui/widgets/attrs/attrdisplay.h b/src/gui/widgets/attrs/attrdisplay.h
index 693bbc349..7659ff0cd 100644
--- a/src/gui/widgets/attrs/attrdisplay.h
+++ b/src/gui/widgets/attrs/attrdisplay.h
@@ -31,6 +31,7 @@
#include "localconsts.h"
+class AttrDisplay;
class LayoutHelper;
class AttrDisplay notfinal : public Container
@@ -78,4 +79,6 @@ class AttrDisplay notfinal : public Container
Label *mValue;
};
+typedef std::map<AttributesT, AttrDisplay*> Attrs;
+
#endif // GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
diff --git a/src/gui/widgets/statspage.cpp b/src/gui/widgets/statspage.cpp
new file mode 100644
index 000000000..b41cc6224
--- /dev/null
+++ b/src/gui/widgets/statspage.cpp
@@ -0,0 +1,77 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/statspage.h"
+
+#include "being/playerinfo.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/vertcontainer.h"
+
+#include "gui/widgets/attrs/derdisplay.h"
+
+#include "gui/windows/chatwindow.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+#include "resources/db/statdb.h"
+
+#include "debug.h"
+
+StatsPage::StatsPage(const Widget2 *const widget) :
+ Container(widget),
+ WidgetListener(),
+ StatListener(),
+ mAttrs(),
+ mAttrCont(new VertContainer(this, 32)),
+ mAttrScroll(new ScrollArea(this, mAttrCont, false))
+{
+ addWidgetListener(this);
+
+ mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
+
+ add(mAttrScroll);
+ const std::vector<BasicStat> &basicStats = StatDb::getExtendedStats();
+ FOR_EACH (std::vector<BasicStat>::const_iterator, it, basicStats)
+ {
+ const BasicStat &stat = *it;
+ AttrDisplay *disp = new DerDisplay(this, stat.attr, stat.name, stat.tag);
+ disp->update();
+ mAttrCont->add2(disp, true);
+ mAttrs[stat.attr] = disp;
+ }
+}
+
+void StatsPage::widgetResized(const Event &event A_UNUSED)
+{
+ mAttrScroll->setSize(getWidth(), getHeight());
+}
+
+void StatsPage::statChanged(const AttributesT id,
+ const int oldVal1 A_UNUSED,
+ const int oldVal2 A_UNUSED)
+{
+ const Attrs::const_iterator it = mAttrs.find(id);
+ if (it != mAttrs.end() && it->second)
+ it->second->update();
+}
diff --git a/src/gui/widgets/statspage.h b/src/gui/widgets/statspage.h
new file mode 100644
index 000000000..2bfb144d2
--- /dev/null
+++ b/src/gui/widgets/statspage.h
@@ -0,0 +1,54 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_STATSPAGE_H
+#define GUI_WIDGETS_STATSPAGE_H
+
+#include "gui/widgets/attrs/attrdisplay.h"
+
+#include "listeners/statlistener.h"
+
+#include "localconsts.h"
+
+class ScrollArea;
+class VertContainer;
+
+class StatsPage final : public Container,
+ public WidgetListener,
+ public StatListener
+{
+ public:
+ StatsPage(const Widget2 *const widget);
+
+ A_DELETE_COPY(StatsPage)
+
+ void widgetResized(const Event &event) override final;
+
+ void statChanged(const AttributesT id,
+ const int oldVal1,
+ const int oldVal2) override final;
+
+ private:
+ Attrs mAttrs;
+ VertContainer *mAttrCont A_NONNULLPOINTER;
+ ScrollArea *mAttrScroll A_NONNULLPOINTER;
+};
+
+#endif // GUI_WIDGETS_STATSPAGE_H
diff --git a/src/gui/widgets/statspagebasic.cpp b/src/gui/widgets/statspagebasic.cpp
new file mode 100644
index 000000000..04252abf5
--- /dev/null
+++ b/src/gui/widgets/statspagebasic.cpp
@@ -0,0 +1,156 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/statspagebasic.h"
+
+#include "being/playerinfo.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/label.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/vertcontainer.h"
+
+#include "gui/widgets/attrs/changedisplay.h"
+
+#include "gui/windows/chatwindow.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+#include "resources/db/statdb.h"
+
+#include "debug.h"
+
+StatsPageBasic::StatsPageBasic(const Widget2 *const widget) :
+ Container(widget),
+ WidgetListener(),
+ StatListener(),
+ mAttrs(),
+ mAttrCont(new VertContainer(this, 32)),
+ mAttrScroll(new ScrollArea(this, mAttrCont, false)),
+ mCharacterPointsLabel(new Label(this, "C"))
+{
+ addWidgetListener(this);
+
+ mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
+
+ add(mAttrScroll);
+ const std::vector<BasicStat> &basicStats = StatDb::getBasicStats();
+ FOR_EACH (std::vector<BasicStat>::const_iterator, it, basicStats)
+ {
+ const BasicStat &stat = *it;
+ AttrDisplay *disp = new ChangeDisplay(this, stat.attr, stat.name, stat.tag);
+ disp->update();
+ mAttrCont->add2(disp, true);
+ mAttrs[stat.attr] = disp;
+ }
+
+ // TRANSLATORS: status window label
+ mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"),
+ PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)));
+ mCharacterPointsLabel->adjustSize();
+ mAttrCont->add1(mCharacterPointsLabel);
+}
+
+void StatsPageBasic::widgetResized(const Event &event A_UNUSED)
+{
+ mAttrScroll->setSize(getWidth(), getHeight());
+}
+
+void StatsPageBasic::statChanged(const AttributesT id,
+ const int oldVal1 A_UNUSED,
+ const int oldVal2 A_UNUSED)
+{
+ const Attrs::const_iterator it = mAttrs.find(id);
+ if (it != mAttrs.end() && it->second)
+ it->second->update();
+}
+
+void StatsPageBasic::attributeChanged(const AttributesT id,
+ const int oldVal A_UNUSED,
+ const int newVal)
+{
+ PRAGMA45(GCC diagnostic push)
+ PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
+ switch (id)
+ {
+ 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;
+
+ default:
+ break;
+ }
+ PRAGMA45(GCC diagnostic pop)
+}
+
+void StatsPageBasic::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);
+ }
+}
+
+std::string StatsPageBasic::getStatsStr() const
+{
+ 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;
+ }
+ return str;
+}
diff --git a/src/gui/widgets/statspagebasic.h b/src/gui/widgets/statspagebasic.h
new file mode 100644
index 000000000..2f1b24e6f
--- /dev/null
+++ b/src/gui/widgets/statspagebasic.h
@@ -0,0 +1,67 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_STATSPAGEBASIC_H
+#define GUI_WIDGETS_STATSPAGEBASIC_H
+
+#include "gui/widgets/attrs/attrdisplay.h"
+
+#include "listeners/attributelistener.h"
+#include "listeners/statlistener.h"
+
+#include "localconsts.h"
+
+class Label;
+class ScrollArea;
+class VertContainer;
+
+class StatsPageBasic final : public Container,
+ public WidgetListener,
+ public AttributeListener,
+ public StatListener
+{
+ public:
+ StatsPageBasic(const Widget2 *const widget);
+
+ A_DELETE_COPY(StatsPageBasic)
+
+ void widgetResized(const Event &event) override final;
+
+ void attributeChanged(const AttributesT id,
+ const int oldVal,
+ const int newVal) override final;
+
+ void statChanged(const AttributesT id,
+ const int oldVal1,
+ const int oldVal2) override final;
+
+ void setPointsNeeded(const AttributesT id,
+ const int needed);
+
+ std::string getStatsStr() const;
+
+ private:
+ Attrs mAttrs;
+ VertContainer *mAttrCont A_NONNULLPOINTER;
+ ScrollArea *mAttrScroll A_NONNULLPOINTER;
+ Label *mCharacterPointsLabel A_NONNULLPOINTER;
+};
+
+#endif // GUI_WIDGETS_STATSPAGEBASIC_H