diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-06-14 23:23:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-06-14 23:36:38 +0300 |
commit | bf9bccc30a186e338f96c230a4f63cc924c77bd8 (patch) | |
tree | e46dbc2f022842982d89164ee598e1bcf827aa39 /src/gui | |
parent | fb0f86589ae9e2d582383cea43e0a391e8d4739d (diff) | |
download | manaplus-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.gz manaplus-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.bz2 manaplus-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.xz manaplus-bf9bccc30a186e338f96c230a4f63cc924c77bd8.zip |
Add ability to add comments to any players.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/beingpopup.cpp | 26 | ||||
-rw-r--r-- | src/gui/beingpopup.h | 1 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 55 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 19 |
4 files changed, 100 insertions, 1 deletions
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 1b32d2b7b..2ba79d1a1 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -59,10 +59,14 @@ BeingPopup::BeingPopup(): mBeingRank = new Label("A"); mBeingRank->setPosition(getPadding(), 3 * fontHeight); + mBeingComment = new Label("A"); + mBeingComment->setPosition(getPadding(), 4 * fontHeight); + add(mBeingName); add(mBeingParty); add(mBeingGuild); add(mBeingRank); + add(mBeingComment); } BeingPopup::~BeingPopup() @@ -80,6 +84,9 @@ void BeingPopup::show(int x, int y, Being *b) Label *label1 = mBeingParty; Label *label2 = mBeingGuild; Label *label3 = mBeingRank; + Label *label4 = mBeingComment; + + b->updateComment(); mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace()); if (gui) @@ -94,6 +101,7 @@ void BeingPopup::show(int x, int y, Being *b) label1->setCaption(""); label2->setCaption(""); label3->setCaption(""); + label4->setCaption(""); if (!(b->getPartyName().empty())) { @@ -103,6 +111,7 @@ void BeingPopup::show(int x, int y, Being *b) } else { + label4 = label3; label3 = label2; label2 = label1; label1 = 0; @@ -116,6 +125,7 @@ void BeingPopup::show(int x, int y, Being *b) } else { + label4 = label3; label3 = label2; label2 = 0; } @@ -127,9 +137,21 @@ void BeingPopup::show(int x, int y, Being *b) } else { + label4 = label3; label3 = 0; } + if (!b->getComment().empty()) + { + label4->setCaption(strprintf(_("Comment: %s"), + b->getComment().c_str())); + label4->adjustSize(); + } + else + { + label4 = 0; + } + int minWidth = mBeingName->getWidth(); if (label1 && label1->getWidth() > minWidth) minWidth = label1->getWidth(); @@ -137,6 +159,8 @@ void BeingPopup::show(int x, int y, Being *b) minWidth = label2->getWidth(); if (label3 && label3->getWidth() > minWidth) minWidth = label3->getWidth(); + if (label4 && label4->getWidth() > minWidth) + minWidth = label4->getWidth(); int height = getFont()->getHeight(); if (label1) @@ -145,6 +169,8 @@ void BeingPopup::show(int x, int y, Being *b) height += getFont()->getHeight(); if (label3) height += getFont()->getHeight(); + if (label4) + height += getFont()->getHeight(); setContentSize(minWidth + 10, height + 10); diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h index ea4ece110..2aeb6c20c 100644 --- a/src/gui/beingpopup.h +++ b/src/gui/beingpopup.h @@ -55,6 +55,7 @@ class BeingPopup : public Popup Label *mBeingParty; Label *mBeingGuild; Label *mBeingRank; + Label *mBeingComment; }; #endif // BEINGPOPUP_H diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index aaf47f36a..0c5e7a365 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -103,6 +103,8 @@ PopupMenu::PopupMenu(): mBrowserBox->setLinkHandler(this); mRenameListener.setMapItem(0); mRenameListener.setDialog(0); + mPlayerListener.setNick(""); + mPlayerListener.setDialog(0); add(mBrowserBox); } @@ -240,6 +242,8 @@ void PopupMenu::showPopup(int x, int y, Being *being) mBrowserBox->addRow(strprintf("@@items|%s@@", _("Show Items"))); mBrowserBox->addRow(strprintf("@@undress|%s@@", _("Undress"))); + mBrowserBox->addRow(strprintf( + "@@addcomment|%s@@", _("Add comment"))); if (player_relations.getDefault() & PlayerRelation::TRADE) { @@ -391,7 +395,7 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) mBrowserBox->addRow("##3---"); mBrowserBox->addRow(strprintf("@@follow|%s@@", _("Follow"))); mBrowserBox->addRow(strprintf("@@imitation|%s@@", _("Imitation"))); - + mBrowserBox->addRow(strprintf("@@addcomment|%s@@", _("Add comment"))); if (player_node->isInParty() && player_node->getParty()) { @@ -642,6 +646,8 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) mBrowserBox->addRow(strprintf("@@move|%s@@", _("Move"))); mBrowserBox->addRow(strprintf("@@items|%s@@", _("Show Items"))); mBrowserBox->addRow(strprintf("@@undress|%s@@", _("Undress"))); + mBrowserBox->addRow(strprintf( + "@@addcomment|%s@@", _("Add comment"))); if (player_relations.getDefault() & PlayerRelation::TRADE) { @@ -690,6 +696,12 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) } } } + else + { + mBrowserBox->addRow(strprintf( + "@@addcomment|%s@@", _("Add comment"))); + mBrowserBox->addRow("##3---"); + } } mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); @@ -1170,6 +1182,27 @@ void PopupMenu::handleLink(const std::string &link, { Net::getBeingHandler()->undress(being); } + else if (link == "addcomment" && !mNick.empty()) + { + // TRANSLATORS: number of chars in string should be near original + TextDialog *dialog = new TextDialog(_("Player comment "), + // TRANSLATORS: number of chars in string should be near original + _("Comment: ")); + mPlayerListener.setDialog(dialog); + mPlayerListener.setNick(mNick); + + if (being) + { + being->updateComment(); + dialog->setText(being->getComment()); + } + else + { + dialog->setText(Being::loadComment(mNick)); + } + dialog->setActionEventId("ok"); + dialog->addActionListener(&mPlayerListener); + } else if (link == "guild-kick" && !mNick.empty()) { if (player_node) @@ -1923,3 +1956,23 @@ void RenameListener::action(const gcn::ActionEvent &event) } mDialog = 0; } + +PlayerListener::PlayerListener() : + mNick(""), + mDialog(0) +{ +} + +void PlayerListener::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "ok" && !mNick.empty() && mDialog) + { + std::string comment = mDialog->getText(); + Being* being = actorSpriteManager->findBeingByName( + mNick, Being::PLAYER); + if (being) + being->setComment(comment); + Being::saveComment(mNick, comment); + } + mDialog = 0; +} diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 976e3e5d2..50d86ff37 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -65,6 +65,24 @@ class RenameListener : public gcn::ActionListener TextDialog *mDialog; }; +class PlayerListener : public gcn::ActionListener +{ + public: + PlayerListener(); + + void action(const gcn::ActionEvent &event); + + void setNick(std::string name) + { mNick = name; } + + void setDialog(TextDialog *dialog) + { mDialog = dialog; } + + private: + std::string mNick; + TextDialog *mDialog; +}; + /** * Window showing popup menu. */ @@ -149,6 +167,7 @@ class PopupMenu : public Popup, public LinkHandler TextCommand *mSpell; Window *mWindow; RenameListener mRenameListener; + PlayerListener mPlayerListener; TextDialog *mDialog; Button *mButton; std::string mNick; |