GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/targetdebugtab.cpp Lines: 37 102 36.3 %
Date: 2019-10-15 Branches: 61 194 31.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus 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/widgets/tabs/targetdebugtab.h"
22
23
#include "being/localplayer.h"
24
25
#include "gui/widgets/containerplacer.h"
26
#include "gui/widgets/label.h"
27
#include "gui/widgets/layouthelper.h"
28
29
#include "utils/gettext.h"
30
#include "utils/stringutils.h"
31
32
#include "debug.h"
33
34
2
TargetDebugTab::TargetDebugTab(const Widget2 *const widget) :
35
    DebugTab(widget),
36
    // TRANSLATORS: debug window label
37

4
    mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
38
    // TRANSLATORS: debug window label
39

4
    mTargetIdLabel(new Label(this, strprintf("%s ?     ", _("Target Id:")))),
40
4
    mTargetTypeLabel(new Label(this, strprintf(
41
        // TRANSLATORS: debug window label
42

2
        "%s ?     ", _("Target type:")))),
43
    // TRANSLATORS: debug window label
44

4
    mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
45
    // TRANSLATORS: debug window label
46

4
    mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
47
    // TRANSLATORS: debug window label
48

4
    mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
49
    // TRANSLATORS: debug window label
50

4
    mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
51
    // TRANSLATORS: debug window label
52

4
    mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
53
    // TRANSLATORS: debug window label
54

4
    mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
55
    // TRANSLATORS: debug window label
56

4
    mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
57
    // TRANSLATORS: debug window label
58

4
    mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
59
    // TRANSLATORS: debug window label
60

4
    mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
61
    // TRANSLATORS: debug window label
62

4
    mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
63
    // TRANSLATORS: debug window label
64

34
    mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
65
{
66
4
    LayoutHelper h(this);
67
2
    ContainerPlacer place = h.getPlacer(0, 0);
68
69
2
    place(0, 0, mTargetLabel, 2, 1);
70
2
    place(0, 1, mTargetIdLabel, 2, 1);
71
2
    place(0, 2, mTargetTypeLabel, 2, 1);
72
2
    place(0, 3, mTargetLevelLabel, 2, 1);
73
2
    place(0, 4, mTargetRaceLabel, 2, 1);
74
2
    place(0, 5, mAttackDelayLabel, 2, 1);
75
2
    place(0, 6, mTargetPartyLabel, 2, 1);
76
2
    place(0, 7, mTargetGuildLabel, 2, 1);
77
2
    place(0, 8, mMinHitLabel, 2, 1);
78
2
    place(0, 9, mMaxHitLabel, 2, 1);
79
2
    place(0, 10, mCriticalHitLabel, 2, 1);
80
2
    place(0, 11, mKarmaLabel, 2, 1);
81
2
    place(0, 12, mMannerLabel, 2, 1);
82
2
    place(0, 13, mEffectsLabel, 2, 1);
83
84
2
    place.getCell().matchColWidth(0, 0);
85
2
    place = h.getPlacer(0, 1);
86
2
    setDimension(Rect(0, 0, 600, 300));
87
2
}
88
89
void TargetDebugTab::logic()
90
{
91
    BLOCK_START("TargetDebugTab::logic")
92
    if ((localPlayer != nullptr) && (localPlayer->getTarget() != nullptr))
93
    {
94
        const Being *const target = localPlayer->getTarget();
95
96
        // TRANSLATORS: debug window label
97
        mTargetLabel->setCaption(strprintf("%s %s (%d, %d)", _("Target:"),
98
            target->getName().c_str(), target->getTileX(),
99
            target->getTileY()));
100
101
        mTargetIdLabel->setCaption(strprintf("%s %d",
102
            // TRANSLATORS: debug window label
103
            _("Target Id:"), toInt(target->getId(), int)));
104
        mTargetTypeLabel->setCaption(strprintf("%s %d",
105
            // TRANSLATORS: debug window label
106
            _("Target type:"), toInt(target->getSubType(), int)));
107
        if (target->getLevel() != 0)
108
        {
109
            mTargetLevelLabel->setCaption(strprintf("%s %d",
110
                // TRANSLATORS: debug window label
111
                _("Target Level:"), target->getLevel()));
112
        }
113
        else
114
        {
115
            mTargetLevelLabel->setCaption(strprintf("%s ?",
116
                // TRANSLATORS: debug window label
117
                _("Target Level:")));
118
        }
119
120
        mTargetRaceLabel->setCaption(strprintf("%s %s",
121
            // TRANSLATORS: debug window label
122
            _("Target race:"), target->getRaceName().c_str()));
123
124
        // TRANSLATORS: debug window label
125
        mTargetPartyLabel->setCaption(strprintf("%s %s", _("Target Party:"),
126
            target->getPartyName().c_str()));
127
128
        // TRANSLATORS: debug window label
129
        mTargetGuildLabel->setCaption(strprintf("%s %s", _("Target Guild:"),
130
            target->getGuildName().c_str()));
131
132
        mMinHitLabel->setCaption(strprintf("%s %d",
133
            // TRANSLATORS: debug window label
134
            _("Minimal hit:"), target->getMinHit()));
135
        mMaxHitLabel->setCaption(strprintf("%s %d",
136
            // TRANSLATORS: debug window label
137
            _("Maximum hit:"), target->getMaxHit()));
138
        mCriticalHitLabel->setCaption(strprintf("%s %d",
139
            // TRANSLATORS: debug window label
140
            _("Critical hit:"), target->getCriticalHit()));
141
        mKarmaLabel->setCaption(strprintf("%s %d",
142
            // TRANSLATORS: debug window label
143
            _("Karma:"), target->getKarma()));
144
        mMannerLabel->setCaption(strprintf("%s %d",
145
            // TRANSLATORS: debug window label
146
            _("Manner:"), target->getManner()));
147
        mEffectsLabel->setCaption(strprintf("%s %s",
148
            // TRANSLATORS: debug window label
149
            _("Effects:"), target->getStatusEffectsString().c_str()));
150
151
        const int delay = target->getAttackDelay();
152
        if (delay != 0)
153
        {
154
            mAttackDelayLabel->setCaption(strprintf("%s %d",
155
                // TRANSLATORS: debug window label
156
                _("Attack delay:"), delay));
157
        }
158
        else
159
        {
160
            mAttackDelayLabel->setCaption(strprintf(
161
                // TRANSLATORS: debug window label
162
                "%s ?", _("Attack delay:")));
163
        }
164
    }
165
    else
166
    {
167
        // TRANSLATORS: debug window label
168
        mTargetLabel->setCaption(strprintf("%s ?", _("Target:")));
169
        // TRANSLATORS: debug window label
170
        mTargetIdLabel->setCaption(strprintf("%s ?", _("Target Id:")));
171
        // TRANSLATORS: debug window label
172
        mTargetTypeLabel->setCaption(strprintf("%s ?", _("Target type:")));
173
        // TRANSLATORS: debug window label
174
        mTargetLevelLabel->setCaption(strprintf("%s ?", _("Target Level:")));
175
        // TRANSLATORS: debug window label
176
        mTargetPartyLabel->setCaption(strprintf("%s ?", _("Target Party:")));
177
        // TRANSLATORS: debug window label
178
        mTargetGuildLabel->setCaption(strprintf("%s ?", _("Target Guild:")));
179
        // TRANSLATORS: debug window label
180
        mAttackDelayLabel->setCaption(strprintf("%s ?", _("Attack delay:")));
181
        // TRANSLATORS: debug window label
182
        mMinHitLabel->setCaption(strprintf("%s ?", _("Minimal hit:")));
183
        // TRANSLATORS: debug window label
184
        mMaxHitLabel->setCaption(strprintf("%s ?", _("Maximum hit:")));
185
        // TRANSLATORS: debug window label
186
        mCriticalHitLabel->setCaption(strprintf("%s ?", _("Critical hit:")));
187
        // TRANSLATORS: debug window label
188
        mKarmaLabel->setCaption(strprintf("%s ?", _("Karma:")));
189
        // TRANSLATORS: debug window label
190
        mMannerLabel->setCaption(strprintf("%s ?", _("Manner:")));
191
        // TRANSLATORS: debug window label
192
        mEffectsLabel->setCaption(strprintf("%s ?", _("Effects:")));
193
    }
194
195
    mTargetLabel->adjustSize();
196
    mTargetIdLabel->adjustSize();
197
    mTargetTypeLabel->adjustSize();
198
    mTargetLevelLabel->adjustSize();
199
    mTargetPartyLabel->adjustSize();
200
    mTargetGuildLabel->adjustSize();
201
    mAttackDelayLabel->adjustSize();
202
    mMinHitLabel->adjustSize();
203
    mMaxHitLabel->adjustSize();
204
    mCriticalHitLabel->adjustSize();
205
    mKarmaLabel->adjustSize();
206
    mMannerLabel->adjustSize();
207
    mEffectsLabel->adjustSize();
208
    BLOCK_END("TargetDebugTab::logic")
209
2
}