From 243628a5d2d12a02708b14b0cbac1498bdcec844 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 15:47:09 +0300 Subject: Add button in status window to copy player stats to chat. --- src/gui/statuswindow.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/gui/statuswindow.cpp') diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index b96720341..fcc324730 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -22,6 +22,7 @@ #include "gui/statuswindow.h" +#include "chatwindow.h" #include "configuration.h" #include "event.h" #include "equipment.h" @@ -71,6 +72,14 @@ class AttrDisplay : public Container virtual Type getType() { return UNKNOWN; } + std::string getValue() + { + if (!mValue) + return "-"; + else + return mValue->getCaption(); + } + protected: AttrDisplay(int id, const std::string &name); @@ -228,6 +237,10 @@ StatusWindow::StatusWindow(): mCharacterPointsLabel = new Label("C"); place(0, 6, mCharacterPointsLabel, 5); + mCopyButton = new Button(_("Copy to chat"), "copy", this); + + place(0, 5, mCopyButton); + if (Net::getPlayerHandler()->canCorrectAttributes()) { mCorrectionPointsLabel = new Label("C"); @@ -890,6 +903,27 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) } } +void StatusWindow::action(const gcn::ActionEvent &event) +{ + if (!chatWindow) + return; + + if (event.getId() == "copy") + { + Attrs::iterator it = mAttrs.begin(); + Attrs::iterator it_end = mAttrs.end(); + std::string str; + while (it != it_end) + { + ChangeDisplay *attr = dynamic_cast((*it).second); + if (attr) + str += attr->getValue() + " "; + ++ it; + } + chatWindow->addInputText(str); + } +} + AttrDisplay::AttrDisplay(int id, const std::string &name): mId(id), mName(name) -- cgit v1.2.3-60-g2f50