Mana
Loading...
Searching...
No Matches
beingpopup.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2010-2012 The Mana Developers
4 *
5 * This file is part of The Mana Client.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "gui/beingpopup.h"
22
23#include "being.h"
24
25#include "gui/gui.h"
26
27#include "gui/widgets/label.h"
28
29#include "utils/gettext.h"
30#include "utils/stringutils.h"
31
32#include <guichan/font.hpp>
33
34
36 Popup("BeingPopup")
37{
38 setMinWidth(0);
39 setMinHeight(0);
40
41 const int fontHeight = getFont()->getHeight();
42
43 // Being Name
44 mBeingName = new Label("A");
45 mBeingName->setFont(boldFont);
46 mBeingName->setPosition(0, 0);
47
48 // Being's party
49 mBeingParty = new Label("A");
50 mBeingParty->setPosition(0, fontHeight);
51
54
55 addMouseListener(this);
56}
57
58BeingPopup::~BeingPopup() = default;
59
60void BeingPopup::show(int x, int y, Being *b)
61{
62 if (!b)
63 {
64 setVisible(false);
65 return;
66 }
67
68 mBeingName->setCaption(b->getName());
69 mBeingName->adjustSize();
70
71 int minWidth = mBeingName->getWidth();
72 const int fontHeight = getFont()->getHeight();
73
74 if (!(b->getPartyName().empty()))
75 {
76 mBeingParty->setCaption(strprintf(_("Party: %s"),
77 b->getPartyName().c_str()));
78 mBeingParty->adjustSize();
79
80 minWidth = std::max(minWidth, mBeingParty->getWidth());
81
82 setContentSize(minWidth, (fontHeight * 2));
83 }
84 else
85 {
86 mBeingParty->setCaption(std::string());
87 setContentSize(minWidth, fontHeight);
88 }
89
90 position(x, y);
91}
Label * mBeingParty
Definition beingpopup.h:47
void show(int x, int y, Being *b)
Sets the info to be displayed given a particular player.
Label * mBeingName
Definition beingpopup.h:46
~BeingPopup() override
Definition being.h:65
const std::string & getPartyName() const
Definition being.h:210
const std::string & getName() const
Returns the name of the being.
Definition being.h:190
Label widget.
Definition label.h:34
A light version of the Window class.
Definition popup.h:48
void setMinHeight(int height)
Sets the minimum height of the popup.
Definition popup.cpp:163
void add(gcn::Widget *widget) override
Definition popup.cpp:69
void setMinWidth(int width)
Sets the minimum width of the popup.
Definition popup.cpp:158
void setContentSize(int width, int height)
Sets the size of this popup.
Definition popup.cpp:127
void position(int x, int y)
Sets the location to display the popup.
Definition popup.cpp:183
#define _(s)
Definition gettext.h:38
gcn::Font * boldFont
Bolded text font.
Definition gui.cpp:54
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.