GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/popups/statuspopup.cpp Lines: 33 79 41.8 %
Date: 2017-11-29 Branches: 9 58 15.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  The Legend of Mazzeroth Development Team
4
 *  Copyright (C) 2009  The Mana World Development Team
5
 *  Copyright (C) 2009-2010  Andrei Karas
6
 *  Copyright (C) 2011-2017  The ManaPlus Developers
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "gui/popups/statuspopup.h"
25
26
#include "gamemodifiers.h"
27
28
#include "gui/widgets/label.h"
29
30
#include "input/inputmanager.h"
31
32
#include "utils/stringutils.h"
33
34
#include "gui/fonts/font.h"
35
36
#include "debug.h"
37
38
#define addLabel(num) \
39
    { \
40
        Label *const label = mLabels[num]; \
41
        label->setPosition(0, y); \
42
        label->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), \
43
            getThemeColor(ThemeColorId::POPUP_OUTLINE)); \
44
        add(label); \
45
        y += fontHeight; \
46
    }
47
48
4
StatusPopup::StatusPopup() :
49
    Popup("StatusPopup", "statuspopup.xml"),
50


28
    mLabels()
51
{
52
132
    for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
53

64
        mLabels[f] = new Label(this);
54
4
}
55
56
4
void StatusPopup::postInit()
57
{
58
8
    Popup::postInit();
59
4
    const int fontHeight = getFont()->getHeight();
60
4
    int y = 0;
61
12
    addLabel(0);
62
12
    addLabel(1);
63
12
    addLabel(2);
64
12
    addLabel(3);
65
4
    y += 4;
66
12
    addLabel(4);
67
12
    addLabel(5);
68
12
    addLabel(9);
69
12
    addLabel(10);
70
4
    y += 4;
71
12
    addLabel(6);
72
12
    addLabel(7);
73
4
    y += 4;
74
12
    addLabel(8);
75
4
    y += 4;
76
12
    addLabel(12);
77
12
    addLabel(13);
78
12
    addLabel(14);
79
12
    addLabel(15);
80
4
    y += 4;
81
12
    addLabel(11);
82
4
}
83
84
4
StatusPopup::~StatusPopup()
85
{
86
4
}
87
88
void StatusPopup::update()
89
{
90
    updateLabels();
91
92
    int maxWidth = mLabels[0]->getWidth();
93
94
    for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
95
    {
96
        const int width = mLabels[f]->getWidth();
97
        if (width > maxWidth)
98
            maxWidth = width;
99
    }
100
101
    const int pad2 = 2 * mPadding;
102
    maxWidth += pad2;
103
    setWidth(maxWidth);
104
    setHeight(mLabels[11]->getY()
105
        + mLabels[11]->getHeight() + pad2);
106
}
107
108
void StatusPopup::view(const int x, const int y)
109
{
110
    const int distance = 20;
111
112
    int posX = std::max(0, x - getWidth() / 2);
113
    int posY = y + distance;
114
115
    if (posX + getWidth() > mainGraphics->mWidth)
116
        posX = mainGraphics->mWidth - getWidth();
117
    if (posY + getHeight() > mainGraphics->mHeight)
118
        posY = y - getHeight() - distance;
119
120
    update();
121
122
    setPosition(posX, posY);
123
    setVisible(Visible_true);
124
    requestMoveToTop();
125
}
126
127
void StatusPopup::setLabelText(const int num,
128
                               const std::string &text,
129
                               const InputActionT key) const
130
{
131
    Label *const label = mLabels[num];
132
    label->setCaption(strprintf("%s  %s", text.c_str(),
133
        inputManager.getKeyValueString(key).c_str()));
134
    label->adjustSize();
135
}
136
137
void StatusPopup::updateLabels() const
138
{
139
    setLabelText(0, GameModifiers::getMoveTypeString(),
140
        InputAction::INVERT_DIRECTION);
141
    setLabelText(1, GameModifiers::getCrazyMoveTypeString(),
142
        InputAction::CHANGE_CRAZY_MOVES_TYPE);
143
    setLabelText(2, GameModifiers::getMoveToTargetTypeString(),
144
        InputAction::CHANGE_MOVE_TO_TARGET);
145
    setLabelText(3, GameModifiers::getFollowModeString(),
146
        InputAction::CHANGE_FOLLOW_MODE);
147
    setLabelText(4, GameModifiers::getAttackWeaponTypeString(),
148
        InputAction::CHANGE_ATTACK_WEAPON_TYPE);
149
    setLabelText(5, GameModifiers::getAttackTypeString(),
150
        InputAction::CHANGE_ATTACK_TYPE);
151
    setLabelText(6, GameModifiers::getQuickDropCounterString(),
152
        InputAction::SWITCH_QUICK_DROP);
153
    setLabelText(7, GameModifiers::getPickUpTypeString(),
154
        InputAction::CHANGE_PICKUP_TYPE);
155
    setLabelText(8, GameModifiers::getMapDrawTypeString(),
156
        InputAction::PATHFIND);
157
    setLabelText(9, GameModifiers::getMagicAttackTypeString(),
158
        InputAction::SWITCH_MAGIC_ATTACK);
159
    setLabelText(10, GameModifiers::getPvpAttackTypeString(),
160
        InputAction::SWITCH_PVP_ATTACK);
161
    setLabelText(11, GameModifiers::getGameModifiersString(),
162
        InputAction::DISABLE_GAME_MODIFIERS);
163
    setLabelText(12, GameModifiers::getImitationModeString(),
164
        InputAction::CHANGE_IMITATION_MODE);
165
    setLabelText(13, GameModifiers::getAwayModeString(),
166
        InputAction::AWAY);
167
    setLabelText(14, GameModifiers::getCameraModeString(),
168
        InputAction::CAMERA);
169
    setLabelText(15, GameModifiers::getTargetingTypeString(),
170
        InputAction::CHANGE_TARGETING_TYPE);
171
}