diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-07-11 19:42:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-07-11 19:42:49 +0300 |
commit | fcae7d8902839890220fc240ae2f3a700a5a863b (patch) | |
tree | c8af3e931c9a4b8d0bdec76a22fd844800bfca0e | |
parent | aebc6b4c1e047e8d864e961777b1d23a7c756b1a (diff) | |
download | mv-fcae7d8902839890220fc240ae2f3a700a5a863b.tar.gz mv-fcae7d8902839890220fc240ae2f3a700a5a863b.tar.bz2 mv-fcae7d8902839890220fc240ae2f3a700a5a863b.tar.xz mv-fcae7d8902839890220fc240ae2f3a700a5a863b.zip |
Fix char select dialog size if server allow more than 10 slots.
-rw-r--r-- | src/gui/widgets/characterviewnormal.cpp | 37 | ||||
-rw-r--r-- | src/gui/widgets/characterviewnormal.h | 1 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp index 288428d60..35032c4c9 100644 --- a/src/gui/widgets/characterviewnormal.cpp +++ b/src/gui/widgets/characterviewnormal.cpp @@ -28,12 +28,18 @@ #include "debug.h" +namespace +{ + int perRowCount = 5; +} // namespace + CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, std::vector<CharacterDisplay*> *const entries, const int padding) : CharacterViewBase(widget, padding), - mCharacterEntries(entries) + mCharacterEntries(entries), + mRows(2) { addKeyListener(widget); if (entries != nullptr) @@ -57,14 +63,19 @@ CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, mSelected = 0; CharacterDisplay *const display = (*mCharacterEntries)[0]; display->setSelect(true); - setWidth(display->getWidth() * 5 + mPadding * 2); + setWidth(display->getWidth() * perRowCount + mPadding * 2); } else { mSelected = -1; } + mRows = CAST_S32(sz / perRowCount); + + if (mRows * perRowCount != CAST_S32(sz)) + mRows ++; } - setHeight(210 + config.getIntValue("fontSize") * 2); + + setHeight((105 + config.getIntValue("fontSize")) * mRows); } CharacterViewNormal::~CharacterViewNormal() @@ -86,19 +97,23 @@ void CharacterViewNormal::show(const int i) void CharacterViewNormal::resize() { - const int sz = CAST_S32(mCharacterEntries->size()); - if (sz <= 0) + const size_t sz = mCharacterEntries->size(); + if (sz == 0) return; const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; int y = 0; const int width = firtChar->getWidth(); const int height = firtChar->getHeight(); - for (int f = 0; f < 5; f ++) - (*mCharacterEntries)[f]->setPosition(f * width, y); - y += height; - - for (int f = 5; f < sz; f ++) - (*mCharacterEntries)[f]->setPosition((f - 5) * width, y); + int x = 0; + for (size_t f = 0; f < sz; f ++, x ++) + { + if (x >= perRowCount) + { + x = 0; + y += height; + } + (*mCharacterEntries)[f]->setPosition(x * width, y); + } } void CharacterViewNormal::action(const ActionEvent &event A_UNUSED) diff --git a/src/gui/widgets/characterviewnormal.h b/src/gui/widgets/characterviewnormal.h index 450de7a71..4a48a725b 100644 --- a/src/gui/widgets/characterviewnormal.h +++ b/src/gui/widgets/characterviewnormal.h @@ -44,6 +44,7 @@ class CharacterViewNormal final : public CharacterViewBase private: std::vector<CharacterDisplay*> *mCharacterEntries; + int mRows; }; #endif // GUI_WIDGETS_CHARACTERVIEWNORMAL_H |