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

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


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

1
    mInfoWidget(new InfoClanTab(this)),
44

1
    mStatsWidget(new StatsClanTab(this)),
45

1
    mAllyWidget(new RelationClanTab(this)),
46


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

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

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

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

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