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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "gui/widgets/tabs/targetdebugtab.h"
23
24
#include "being/localplayer.h"
25
26
#include "gui/widgets/containerplacer.h"
27
#include "gui/widgets/label.h"
28
#include "gui/widgets/layouthelper.h"
29
30
#include "utils/gettext.h"
31
#include "utils/stringutils.h"
32
33
#include "debug.h"
34
35
2
TargetDebugTab::TargetDebugTab(const Widget2 *const widget) :
36
    DebugTab(widget),
37
    // TRANSLATORS: debug window label
38

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

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

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

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

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

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

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

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

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

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

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

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

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

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