GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/clanwindow.cpp Lines: 53 71 74.6 %
Date: 2021-03-17 Branches: 41 94 43.6 %

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/windows/clanwindow.h"
23
24
#include "being/localclan.h"
25
26
#include "gui/windows/setupwindow.h"
27
28
#include "gui/widgets/createwidget.h"
29
#include "gui/widgets/tabbedarea.h"
30
31
#include "gui/widgets/tabs/clanwindowtabs.h"
32
33
#include "utils/delete2.h"
34
#include "utils/gettext.h"
35
36
#include "debug.h"
37
38
ClanWindow *clanWindow = nullptr;
39
40
1
ClanWindow::ClanWindow() :
41
    // TRANSLATORS: clan window name
42
1
    Window(_("Clan"), Modal_false, nullptr, "clan.xml"),
43


1
    mTabs(CREATEWIDGETR(TabbedArea, this)),
44

1
    mInfoWidget(new InfoClanTab(this)),
45

1
    mStatsWidget(new StatsClanTab(this)),
46

1
    mAllyWidget(new RelationClanTab(this)),
47


11
    mAntagonistWidget(new RelationClanTab(this))
48
{
49
4
    setWindowName("clan");
50
1
    if (setupWindow != nullptr)
51
        setupWindow->registerWindowForReset(this);
52
53
1
    setResizable(true);
54
1
    setCloseButton(true);
55
2
    setSaveVisible(true);
56
1
    setStickyButtonLock(true);
57
58
1
    setDefaultSize(400, 300, ImagePosition::CENTER, 0, 0);
59
60
2
    mTabs->setSelectable(false);
61
3
    mTabs->getWidgetContainer()->setSelectable(false);
62
3
    mTabs->getTabContainer()->setSelectable(false);
63
    // TRANSLATORS: clan window tab
64

3
    mTabs->addTab(std::string(_("Info")), mInfoWidget);
65
    // TRANSLATORS: clan window tab
66

3
    mTabs->addTab(std::string(_("Stats")), mStatsWidget);
67
    // TRANSLATORS: clan window tab
68

3
    mTabs->addTab(std::string(_("Ally")), mAllyWidget);
69
    // TRANSLATORS: clan window tab
70

4
    mTabs->addTab(std::string(_("Antagonist")), mAntagonistWidget);
71
72
1
    mTabs->setDimension(Rect(0, 0, 600, 300));
73
74
1
    const int w = mDimension.width;
75
1
    const int h = mDimension.height;
76
1
    mInfoWidget->setDimension(Rect(0, 0, w, h));
77
1
    mStatsWidget->setDimension(Rect(0, 0, w, h));
78
1
    mAllyWidget->setDimension(Rect(0, 0, w, h));
79
1
    mAntagonistWidget->setDimension(Rect(0, 0, w, h));
80
1
    loadWindowState();
81
2
    enableVisibleSound(true);
82
1
    resetClan();
83
1
}
84
85
3
ClanWindow::~ClanWindow()
86
{
87
2
    delete2(mInfoWidget)
88
2
    delete2(mStatsWidget)
89
2
    delete2(mAllyWidget)
90
2
    delete2(mAntagonistWidget)
91
2
}
92
93
1
void ClanWindow::postInit()
94
{
95
1
    Window::postInit();
96
1
    add(mTabs);
97
1
}
98
99
void ClanWindow::slowLogic()
100
{
101
    BLOCK_START("ClanWindow::slowLogic")
102
    if (!isWindowVisible() || (mTabs == nullptr))
103
    {
104
        BLOCK_END("ClanWindow::slowLogic")
105
        return;
106
    }
107
108
    switch (mTabs->getSelectedTabIndex())
109
    {
110
        default:
111
        case 0:
112
            mInfoWidget->logic();
113
            break;
114
        case 1:
115
            mStatsWidget->logic();
116
            break;
117
        case 2:
118
            mAllyWidget->logic();
119
            break;
120
        case 3:
121
            mAntagonistWidget->logic();
122
            break;
123
    }
124
125
    BLOCK_END("ClanWindow::slowLogic")
126
}
127
128
1
void ClanWindow::widgetResized(const Event &event)
129
{
130
1
    Window::widgetResized(event);
131
132
3
    mTabs->setDimension(Rect(0, 0,
133
1
        mDimension.width, mDimension.height));
134
1
}
135
136
void ClanWindow::updateClan()
137
{
138
    mInfoWidget->updateClan();
139
    mStatsWidget->updateClan();
140
    mAllyWidget->updateClan(localClan.allyClans);
141
    mAntagonistWidget->updateClan(localClan.antagonistClans);
142
}
143
144
1
void ClanWindow::resetClan()
145
{
146
1
    mInfoWidget->resetClan();
147
1
    mStatsWidget->resetClan();
148
1
    mAllyWidget->resetClan();
149
1
    mAntagonistWidget->resetClan();
150
1
}
151
152
void ClanWindow::updateClanMembers()
153
{
154
}
155
156
#ifdef USE_PROFILER
157
void ClanWindow::logicChildren()
158
{
159
    BLOCK_START("ClanWindow::logicChildren")
160
    BasicContainer::logicChildren();
161
    BLOCK_END("ClanWindow::logicChildren")
162
}
163
#endif  // USE_PROFILER