1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2013-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/characterviewnormal.h" |
23 |
|
|
|
24 |
|
|
#include "configuration.h" |
25 |
|
|
|
26 |
|
|
#include "gui/widgets/characterdisplay.h" |
27 |
|
|
|
28 |
|
|
#include "utils/foreach.h" |
29 |
|
|
|
30 |
|
|
#include "debug.h" |
31 |
|
|
|
32 |
|
|
namespace |
33 |
|
|
{ |
34 |
|
|
int perRowCount = 5; |
35 |
|
|
} // namespace |
36 |
|
|
|
37 |
|
1 |
CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, |
38 |
|
|
STD_VECTOR<CharacterDisplay*> |
39 |
|
|
*const entries, |
40 |
|
1 |
const int padding) : |
41 |
|
|
CharacterViewBase(widget, padding), |
42 |
|
|
mCharacterEntries(entries), |
43 |
|
2 |
mRows(2) |
44 |
|
|
{ |
45 |
✓✗✓✗
|
1 |
addKeyListener(widget); |
46 |
✓✗ |
1 |
if (entries != nullptr) |
47 |
|
|
{ |
48 |
✓✓ |
12 |
FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator, |
49 |
|
|
it, entries) |
50 |
|
|
{ |
51 |
|
9 |
CharacterDisplay *const character = *it; |
52 |
✓✗ |
9 |
add(character); |
53 |
✓✗ |
9 |
character->setVisible(Visible_true); |
54 |
|
|
} |
55 |
|
2 |
const size_t sz = mCharacterEntries->size(); |
56 |
✓✗✓✗
|
1 |
if (mSelected >= 0 && mSelected < CAST_S32(sz)) |
57 |
|
|
{ |
58 |
|
2 |
CharacterDisplay *const display = (*mCharacterEntries)[mSelected]; |
59 |
✓✗ |
1 |
if (display != nullptr) |
60 |
|
|
display->setSelect(false); |
61 |
|
|
} |
62 |
✓✗ |
1 |
if (sz > 0) |
63 |
|
|
{ |
64 |
|
1 |
mSelected = 0; |
65 |
|
1 |
CharacterDisplay *const display = (*mCharacterEntries)[0]; |
66 |
|
1 |
display->setSelect(true); |
67 |
✓✗ |
2 |
setWidth(display->getWidth() * perRowCount + mPadding * 2); |
68 |
|
|
} |
69 |
|
|
else |
70 |
|
|
{ |
71 |
|
|
mSelected = -1; |
72 |
|
|
} |
73 |
|
1 |
mRows = CAST_S32(sz / perRowCount); |
74 |
|
|
|
75 |
✓✗ |
1 |
if (mRows * perRowCount != CAST_S32(sz)) |
76 |
|
1 |
mRows ++; |
77 |
|
|
} |
78 |
|
|
|
79 |
✓✗✓✗ ✓✗ |
3 |
setHeight((105 + config.getIntValue("fontSize")) * mRows); |
80 |
|
1 |
} |
81 |
|
|
|
82 |
|
4 |
CharacterViewNormal::~CharacterViewNormal() |
83 |
|
|
{ |
84 |
✓✗ |
1 |
removeKeyListener(mParent); |
85 |
|
2 |
} |
86 |
|
|
|
87 |
|
1 |
void CharacterViewNormal::show(const int i) |
88 |
|
|
{ |
89 |
|
2 |
const int sz = CAST_S32(mCharacterEntries->size()); |
90 |
✓✗ |
1 |
if (i >= 0 && i < sz) |
91 |
|
|
{ |
92 |
✓✗ |
1 |
if (mSelected >= 0) |
93 |
|
2 |
(*mCharacterEntries)[mSelected]->setSelect(false); |
94 |
|
1 |
mSelected = i; |
95 |
|
2 |
(*mCharacterEntries)[i]->setSelect(true); |
96 |
|
|
} |
97 |
|
1 |
} |
98 |
|
|
|
99 |
|
1 |
void CharacterViewNormal::resize() |
100 |
|
|
{ |
101 |
|
2 |
const size_t sz = mCharacterEntries->size(); |
102 |
✓✗ |
1 |
if (sz == 0) |
103 |
|
|
return; |
104 |
|
1 |
const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; |
105 |
|
1 |
unsigned int y = 0; |
106 |
|
2 |
const int width = firtChar->getWidth(); |
107 |
|
2 |
const int height = firtChar->getHeight(); |
108 |
|
1 |
int x = 0; |
109 |
✓✓ |
10 |
for (size_t f = 0; f < sz; f ++, x ++) |
110 |
|
|
{ |
111 |
✓✓ |
9 |
if (x >= perRowCount) |
112 |
|
|
{ |
113 |
|
1 |
x = 0; |
114 |
|
1 |
y += height; |
115 |
|
|
} |
116 |
|
18 |
(*mCharacterEntries)[f]->setPosition(x * width, y); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
void CharacterViewNormal::action(const ActionEvent &event A_UNUSED) |
121 |
|
|
{ |
122 |
|
|
} |