summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-22 00:57:39 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-28 12:46:07 +0300
commitecf7284930fc6b67db33146819bedf6ec0ed7e7b (patch)
tree16628bb1b0d5e028ef673a1a39976e946f628f37 /src
parent865a8d966b8ec08dc52d5edb10c479138a5a92ca (diff)
downloadmv-ecf7284930fc6b67db33146819bedf6ec0ed7e7b.tar.gz
mv-ecf7284930fc6b67db33146819bedf6ec0ed7e7b.tar.bz2
mv-ecf7284930fc6b67db33146819bedf6ec0ed7e7b.tar.xz
mv-ecf7284930fc6b67db33146819bedf6ec0ed7e7b.zip
create shared class for different players list visualisation.
Diffstat (limited to 'src')
-rw-r--r--src/gui/charselectdialog.cpp84
-rw-r--r--src/gui/charselectdialog.h4
2 files changed, 50 insertions, 38 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 977e06726..6b6036cd3 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -135,19 +135,45 @@ class CharacterDisplay final : public Container
Button *mDelete;
};
-class CharacterScroller final : public Container,
- public gcn::ActionListener
+class CharacterViewBase : public Container,
+ public gcn::ActionListener
{
public:
- CharacterScroller(CharSelectDialog *const widget,
- std::vector<CharacterDisplay*> *const entries) :
+ CharacterViewBase(CharSelectDialog *const widget) :
Container(widget),
gcn::ActionListener(),
+ mSelected(0)
+ {
+ }
+
+ A_DELETE_COPY(CharacterViewBase)
+
+ virtual ~CharacterViewBase()
+ { }
+
+ virtual void show(const int i) = 0;
+
+ virtual void resize() = 0;
+
+ int getSelected()
+ {
+ return mSelected;
+ }
+
+ protected:
+ int mSelected;
+};
+
+class CharacterViewSmall final : public CharacterViewBase
+{
+ public:
+ CharacterViewSmall(CharSelectDialog *const widget,
+ std::vector<CharacterDisplay*> *const entries) :
+ CharacterViewBase(widget),
mSelectedEntry(nullptr),
mPrevious(new Button(this, "<", "prev", this)),
mNext(new Button(this, ">", "next", this)),
mNumber(new Label(this, "??")),
- mSelected(0),
mCharacterEntries(entries)
{
addKeyListener(widget);
@@ -164,9 +190,11 @@ class CharacterScroller final : public Container,
add(mPrevious);
add(mNext);
add(mNumber);
+
+ setHeight(200);
}
- A_DELETE_COPY(CharacterScroller)
+ A_DELETE_COPY(CharacterViewSmall)
void show(const int i)
{
@@ -217,17 +245,11 @@ class CharacterScroller final : public Container,
}
}
- int getSelected() const
- {
- return mSelected;
- }
-
private:
CharacterDisplay *mSelectedEntry;
Button *mPrevious;
Button *mNext;
Label *mNumber;
- int mSelected;
std::vector<CharacterDisplay*> *mCharacterEntries;
};
@@ -244,7 +266,7 @@ CharSelectDialog::CharSelectDialog(LoginData *const data):
"change_password", this)),
mUnregisterButton(nullptr),
mChangeEmailButton(nullptr),
- mCharacterScroller(nullptr),
+ mCharacterView(nullptr),
mCharacterEntries(0),
mCharServerHandler(Net::getCharServerHandler()),
mDeleteDialog(nullptr),
@@ -303,11 +325,10 @@ CharSelectDialog::CharSelectDialog(LoginData *const data):
character->setVisible(false);
mCharacterEntries.push_back(character);
}
- mCharacterScroller = new CharacterScroller(this, &mCharacterEntries);
- mCharacterScroller->setWidth(mainGraphics->getWidth()
+ mCharacterView = new CharacterViewSmall(this, &mCharacterEntries);
+ mCharacterView->setWidth(mainGraphics->getWidth()
- 2 * getPadding());
- mCharacterScroller->setHeight(200);
- placer(0, 0, mCharacterScroller);
+ placer(0, 0, mCharacterView);
}
reflowLayout();
@@ -328,9 +349,9 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
// Check if a button of a character was pressed
const gcn::Widget *const sourceParent = event.getSource()->getParent();
int selected = -1;
- if (mCharacterScroller)
+ if (mCharacterView)
{
- selected = mCharacterScroller->getSelected();
+ selected = mCharacterView->getSelected();
}
else
{
@@ -418,7 +439,7 @@ void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
case Input::KEY_GUI_RIGHT:
{
- if (mCharacterScroller)
+ if (mCharacterView)
return;
keyEvent.consume();
int idx;
@@ -435,7 +456,7 @@ void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
case Input::KEY_GUI_LEFT:
{
- if (mCharacterScroller)
+ if (mCharacterView)
return;
keyEvent.consume();
int idx;
@@ -463,7 +484,7 @@ void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
idx2 = 0;
}
- else if (!mCharacterScroller)
+ else if (!mCharacterView)
{
idx -= SLOTS_PER_ROW;
if (mCharacterEntries[idx]->getCharacter())
@@ -490,7 +511,7 @@ void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
idx += SLOTS_PER_ROW;
idx2 = 0;
}
- else if (!mCharacterScroller)
+ else if (!mCharacterView)
{
if (mCharacterEntries[idx]->getCharacter())
idx2 = 1;
@@ -696,15 +717,15 @@ void CharSelectDialog::focusCharacter(const int i)
{
if (mCharacterEntries[i])
mCharacterEntries[i]->requestFocus();
- if (mCharacterScroller)
- mCharacterScroller->show(i);
+ if (mCharacterView)
+ mCharacterView->show(i);
}
void CharSelectDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
- if (mCharacterScroller)
- mCharacterScroller->resize();
+ if (mCharacterView)
+ mCharacterView->resize();
}
CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
@@ -736,15 +757,6 @@ CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
// Setting the width so that the largest label fits.
mName->adjustSize();
mMoney->adjustSize();
-/*
- int width = 74;
- if (width - 20 < mName->getWidth())
- width = 20 + mName->getWidth();
- if (width - 20 < mMoney->getWidth())
- width = 20 + mMoney->getWidth();
- h.reflowLayout(width, 112 + mName->getHeight() + mLevel->getHeight() +
- mMoney->getHeight() + mButton->getHeight() + mDelete->getHeight());
-*/
setWidth(110);
setHeight(200);
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 5b4ba47af..b24b8e225 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -35,7 +35,7 @@
class Button;
class CharacterDisplay;
-class CharacterScroller;
+class CharacterViewBase;
class Label;
class LocalPlayer;
class LoginData;
@@ -124,7 +124,7 @@ class CharSelectDialog final : public Window,
Button *mChangePasswordButton;
Button *mUnregisterButton;
Button *mChangeEmailButton;
- CharacterScroller *mCharacterScroller;
+ CharacterViewBase *mCharacterView;
/** The player boxes */
std::vector<CharacterDisplay*> mCharacterEntries;