diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-30 15:01:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-30 15:01:42 +0300 |
commit | 64781090e80fa93a43ce37f0705bbb1cf22ed8bf (patch) | |
tree | 6932ff7f29b4a1e1fe2f3834592587c33d7c4651 /src/gui/popups/beingpopup.cpp | |
parent | 25d77892d72d455f8a89372687db45aefbc61cec (diff) | |
download | manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.gz manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.bz2 manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.tar.xz manaverse-64781090e80fa93a43ce37f0705bbb1cf22ed8bf.zip |
move popups into popups directory.
Diffstat (limited to 'src/gui/popups/beingpopup.cpp')
-rw-r--r-- | src/gui/popups/beingpopup.cpp | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/src/gui/popups/beingpopup.cpp b/src/gui/popups/beingpopup.cpp new file mode 100644 index 000000000..ae16d8eb2 --- /dev/null +++ b/src/gui/popups/beingpopup.cpp @@ -0,0 +1,211 @@ +/* + * The ManaPlus Client + * Copyright (C) 2010 The Mana Developers + * Copyright (C) 2011-2013 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/popups/beingpopup.h" + +#include "being/being.h" +#include "being/playerrelations.h" + +#include "gui/gui.h" +#include "gui/sdlfont.h" + +#include "gui/widgets/label.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include <guichan/font.hpp> + +#include "debug.h" + +BeingPopup::BeingPopup() : + Popup("BeingPopup", "beingpopup.xml"), + mBeingName(new Label(this, "A")), + mBeingParty(new Label(this, "A")), + mBeingGuild(new Label(this, "A")), + mBeingRank(new Label(this, "A")), + mBeingComment(new Label(this, "A")) +{ + // Being Name + mBeingName->setFont(boldFont); + mBeingName->setPosition(0, 0); + + const int fontHeight = mBeingName->getHeight(); + + // Being's party + mBeingParty->setPosition(0, fontHeight); + // Being's party + mBeingGuild->setPosition(0, 2 * fontHeight); + mBeingRank->setPosition(0, 3 * fontHeight); + mBeingComment->setPosition(0, 4 * fontHeight); + + mBeingParty->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + mBeingGuild->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + mBeingRank->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + mBeingComment->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + + add(mBeingName); + add(mBeingParty); + add(mBeingGuild); + add(mBeingRank); + add(mBeingComment); +} + +BeingPopup::~BeingPopup() +{ +} + +void BeingPopup::show(const int x, const int y, Being *const b) +{ + if (!b) + { + setVisible(false); + return; + } + + Label *label1 = mBeingParty; + Label *label2 = mBeingGuild; + Label *label3 = mBeingRank; + Label *label4 = mBeingComment; + + b->updateComment(); + + if (b->getType() == Being::NPC && b->getComment().empty()) + { + setVisible(false); + return; + } + + mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace()); + if (gui) + { + if (player_relations.isGoodName(b)) + mBeingName->setFont(boldFont); + else + mBeingName->setFont(gui->getSecureFont()); + } + if (b->isAdvanced()) + { + mBeingName->setForegroundColorAll(getThemeColor( + Theme::PLAYER_ADVANCED), getThemeColor( + Theme::PLAYER_ADVANCED_OUTLINE)); + } + else + { + mBeingName->setForegroundColorAll(getThemeColor(Theme::POPUP), + getThemeColor(Theme::POPUP_OUTLINE)); + } + + mBeingName->adjustSize(); + label1->setCaption(""); + label2->setCaption(""); + label3->setCaption(""); + label4->setCaption(""); + + if (!(b->getPartyName().empty())) + { + // TRANSLATORS: being popup label + label1->setCaption(strprintf(_("Party: %s"), + b->getPartyName().c_str())); + label1->adjustSize(); + } + else + { + label4 = label3; + label3 = label2; + label2 = label1; + label1 = nullptr; + } + + if (!(b->getGuildName().empty())) + { + // TRANSLATORS: being popup label + label2->setCaption(strprintf(_("Guild: %s"), + b->getGuildName().c_str())); + label2->adjustSize(); + } + else + { + label4 = label3; + label3 = label2; + label2 = nullptr; + } + + if (b->getPvpRank() > 0) + { + // TRANSLATORS: being popup label + label3->setCaption(strprintf(_("Pvp rank: %u"), b->getPvpRank())); + label3->adjustSize(); + } + else + { + label4 = label3; + label3 = nullptr; + } + + if (!b->getComment().empty()) + { + // TRANSLATORS: being popup label + label4->setCaption(strprintf(_("Comment: %s"), + b->getComment().c_str())); + label4->adjustSize(); + } + else + { + label4 = nullptr; + } + + int minWidth = mBeingName->getWidth(); + if (label1 && label1->getWidth() > minWidth) + minWidth = label1->getWidth(); + if (label2 && label2->getWidth() > minWidth) + minWidth = label2->getWidth(); + if (label3 && label3->getWidth() > minWidth) + minWidth = label3->getWidth(); + if (label4 && label4->getWidth() > minWidth) + minWidth = label4->getWidth(); + + const int height1 = getFont()->getHeight(); + int height = height1; + if (label1) + height += height1; + if (label2) + height += height1; + if (label3) + height += height1; + if (label4) + height += height1; + + setContentSize(minWidth, height); + position(x, y); + return; +} + +#ifdef USE_PROFILER +void BeingPopup::logic() +{ + logicChildren(); +} +#endif |