diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-22 12:16:20 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-29 00:49:56 +0300 |
commit | 76c98ce0c8e78778f73d6a5728441897e134fb9e (patch) | |
tree | 63753c9b80004c2f66314d8ea883a9b378656a12 /src/gui/widgets | |
parent | ecf7284930fc6b67db33146819bedf6ec0ed7e7b (diff) | |
download | manaverse-76c98ce0c8e78778f73d6a5728441897e134fb9e.tar.gz manaverse-76c98ce0c8e78778f73d6a5728441897e134fb9e.tar.bz2 manaverse-76c98ce0c8e78778f73d6a5728441897e134fb9e.tar.xz manaverse-76c98ce0c8e78778f73d6a5728441897e134fb9e.zip |
Improve a bit look in character selection window.
Add selection skin for playerbox.
New theme file: playerboxselected.xml
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/characterdisplay.cpp | 83 | ||||
-rw-r--r-- | src/gui/widgets/characterdisplay.h | 79 | ||||
-rw-r--r-- | src/gui/widgets/characterviewbase.h | 65 | ||||
-rw-r--r-- | src/gui/widgets/characterviewnormal.cpp | 85 | ||||
-rw-r--r-- | src/gui/widgets/characterviewnormal.h | 50 | ||||
-rw-r--r-- | src/gui/widgets/characterviewsmall.cpp | 112 | ||||
-rw-r--r-- | src/gui/widgets/characterviewsmall.h | 54 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.cpp | 52 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.h | 16 |
9 files changed, 577 insertions, 19 deletions
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp new file mode 100644 index 000000000..35af15efc --- /dev/null +++ b/src/gui/widgets/characterdisplay.cpp @@ -0,0 +1,83 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/characterdisplay.h" + +#include "gui/charselectdialog.h" + +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" + +#include "debug.h" + +CharacterDisplay::CharacterDisplay(const Widget2 *const widget, + CharSelectDialog *const charSelectDialog) : + Container(widget), + mCharacter(nullptr), + mPlayerBox(new PlayerBox(nullptr)), + mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww")) +{ + mPlayerBox->setActionEventId("select"); + mPlayerBox->addActionListener(charSelectDialog); + + LayoutHelper h(this); + ContainerPlacer placer = h.getPlacer(0, 0); + + placer(0, 0, mPlayerBox, 3, 5); + placer(0, 5, mName, 3); + + update(); + + mName->setAlignment(Graphics::CENTER); + mName->adjustSize(); + + setWidth(80); + setHeight(100); +} + +void CharacterDisplay::setCharacter(Net::Character *const character) +{ + if (mCharacter == character) + return; + + mCharacter = character; + mPlayerBox->setPlayer(character ? character->dummy : nullptr); + update(); +} + +void CharacterDisplay::requestFocus() +{ +} + +void CharacterDisplay::setActive(const bool active A_UNUSED) +{ +} + +void CharacterDisplay::update() +{ + if (mCharacter) + mName->setCaption(mCharacter->dummy->getName()); + else + mName->setCaption(""); + + distributeResizedEvent(); +} diff --git a/src/gui/widgets/characterdisplay.h b/src/gui/widgets/characterdisplay.h new file mode 100644 index 000000000..5c602b4f9 --- /dev/null +++ b/src/gui/widgets/characterdisplay.h @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WIDGETS_CHARACTER_DISPLAY_H +#define WIDGETS_CHARACTER_DISPLAY_H + +#include "gui/widgets/container.h" +#include "gui/widgets/playerbox.h" + +#include "net/charserverhandler.h" +#include "net/net.h" + +class Button; +class CharSelectDialog; +class Label; +class PlayerBox; + +class CharacterDisplay final : public Container +{ + public: + CharacterDisplay(const Widget2 *const widget, + CharSelectDialog *const charSelectDialog); + + A_DELETE_COPY(CharacterDisplay) + + void setCharacter(Net::Character *const character); + + Net::Character *getCharacter() const + { return mCharacter; } + + void requestFocus(); + + void setActive(const bool active); + + bool isSelectFocused() const + { return false; } + + bool isDeleteFocused() const + { return false; } + + void focusSelect() + { } + + void focusDelete() + { } + + void setSelect(bool b) + { + mPlayerBox->setSelected(b); + } + + private: + void update(); + + Net::Character *mCharacter; + PlayerBox *mPlayerBox; + Label *mName; +}; + +#endif diff --git a/src/gui/widgets/characterviewbase.h b/src/gui/widgets/characterviewbase.h new file mode 100644 index 000000000..42e4025eb --- /dev/null +++ b/src/gui/widgets/characterviewbase.h @@ -0,0 +1,65 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WIDGETS_CHARACTERVIEWBASE_H +#define WIDGETS_CHARACTERVIEWBASE_H + +#include "gui/charselectdialog.h" + +#include "gui/widgets/container.h" + +#include <guichan/actionlistener.hpp> + +#include "debug.h" + +class CharacterViewBase : public Container, + public gcn::ActionListener +{ + public: + CharacterViewBase(CharSelectDialog *const widget, const int padding) : + Container(widget), + gcn::ActionListener(), + mParent(widget), + mPadding(padding), + mSelected(0) + { + } + + A_DELETE_COPY(CharacterViewBase) + + virtual ~CharacterViewBase() + { } + + virtual void show(const int i) = 0; + + virtual void resize() = 0; + + int getSelected() const + { + return mSelected; + } + + protected: + CharSelectDialog *mParent; + int mPadding; + int mSelected; +}; + +#endif diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp new file mode 100644 index 000000000..920fde61c --- /dev/null +++ b/src/gui/widgets/characterviewnormal.cpp @@ -0,0 +1,85 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/characterviewnormal.h" + +#include "gui/widgets/characterdisplay.h" +#include "gui/widgets/characterviewsmall.h" + +#include "debug.h" + +CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, + std::vector<CharacterDisplay*> *const entries, + const int padding) : + CharacterViewBase(widget, padding), + mSelectedEntry(nullptr), + mCharacterEntries(entries) +{ + addKeyListener(widget); + if (entries) + { + FOR_EACHP (std::vector<CharacterDisplay*>::iterator, + it, entries) + { + CharacterDisplay *character = *it; + add(character); + character->setVisible(true); + } + show(0); + } + const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; + setWidth(firtChar->getWidth() * 5 + mPadding * 2); + setHeight(200); +} + +CharacterViewNormal::~CharacterViewNormal() +{ + removeKeyListener(mParent); +} + +void CharacterViewNormal::show(const int i) +{ + const int sz = static_cast<signed>(mCharacterEntries->size()); + if (i >= 0 && i < sz) + { + if (mSelected >= 0) + (*mCharacterEntries)[mSelected]->setSelect(false); + mSelected = i; + (*mCharacterEntries)[i]->setSelect(true); + } +} + +void CharacterViewNormal::resize() +{ + 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 < 10; f ++) + (*mCharacterEntries)[f]->setPosition((f - 5) * width, y); +} + +void CharacterViewNormal::action(const gcn::ActionEvent &event A_UNUSED) +{ +} diff --git a/src/gui/widgets/characterviewnormal.h b/src/gui/widgets/characterviewnormal.h new file mode 100644 index 000000000..ab45bee8a --- /dev/null +++ b/src/gui/widgets/characterviewnormal.h @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WIDGETS_CHARACTERVIEWNORMAL_H +#define WIDGETS_CHARACTERVIEWNORMAL_H + +#include "gui/widgets/characterviewbase.h" + +#include "debug.h" + +class CharacterViewNormal final : public CharacterViewBase +{ + public: + CharacterViewNormal(CharSelectDialog *const widget, + std::vector<CharacterDisplay*> *const entries, + const int padding); + + A_DELETE_COPY(CharacterViewNormal) + + ~CharacterViewNormal(); + + void show(const int i); + + void resize(); + + void action(const gcn::ActionEvent &event A_UNUSED) override; + + private: + CharacterDisplay *mSelectedEntry; + std::vector<CharacterDisplay*> *mCharacterEntries; +}; + +#endif diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp new file mode 100644 index 000000000..59cdd8150 --- /dev/null +++ b/src/gui/widgets/characterviewsmall.cpp @@ -0,0 +1,112 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/characterviewsmall.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/characterdisplay.h" +#include "gui/widgets/label.h" + +#include "debug.h" + +CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget, + std::vector<CharacterDisplay*> + *const entries, + const int padding) : + CharacterViewBase(widget, padding), + mSelectedEntry(nullptr), + mPrevious(new Button(this, "<", "prev", this)), + mNext(new Button(this, ">", "next", this)), + mNumber(new Label(this, "??")), + mCharacterEntries(entries) +{ + addKeyListener(widget); + if (entries) + { + FOR_EACHP (std::vector<CharacterDisplay*>::iterator, + it, entries) + { + CharacterDisplay *character = *it; + add(character); + } + show(0); + } + add(mPrevious); + add(mNext); + add(mNumber); + + setHeight(200); +} + +CharacterViewSmall::~CharacterViewSmall() +{ + removeKeyListener(mParent); +} + +void CharacterViewSmall::show(const int i) +{ + const int sz = static_cast<signed>(mCharacterEntries->size()); + if (mSelectedEntry) + mSelectedEntry->setVisible(false); + if (i >= sz) + mSelected = 0; + else if (i < 0) + mSelected = mCharacterEntries->size() - 1; + else + mSelected = i; + mSelectedEntry = (*mCharacterEntries)[mSelected]; + mSelectedEntry->setVisible(true); + mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz)); + mNumber->adjustSize(); +} + +void CharacterViewSmall::resize() +{ + const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; + const int x = (getWidth() - firtChar->getWidth()) / 2; + const int y = (getHeight() - firtChar->getHeight()) / 2; + FOR_EACHP (std::vector<CharacterDisplay*>::iterator, + it, mCharacterEntries) + { + (*it)->setPosition(x, y); + } + const int y2 = (getHeight() - mPrevious->getHeight()) / 2; + const int y3 = y2 - 55; + mPrevious->setPosition(x - mPrevious->getWidth() - 10, y3); + mNext->setPosition(getWidth() - x + 10, y3); + mNumber->setPosition(10, y2); +} + +void CharacterViewSmall::action(const gcn::ActionEvent &event) +{ + const std::string &eventId = event.getId(); + if (eventId == "next") + { + mSelected ++; + show(mSelected); + mParent->updateState(); + } + else if (eventId == "prev") + { + mSelected --; + show(mSelected); + mParent->updateState(); + } +} diff --git a/src/gui/widgets/characterviewsmall.h b/src/gui/widgets/characterviewsmall.h new file mode 100644 index 000000000..f42500b79 --- /dev/null +++ b/src/gui/widgets/characterviewsmall.h @@ -0,0 +1,54 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WIDGETS_CHARACTERVIEWSMALL_H +#define WIDGETS_CHARACTERVIEWSMALL_H + +#include "gui/widgets/characterviewbase.h" + +#include "debug.h" + +class CharacterViewBase; + +class CharacterViewSmall final : public CharacterViewBase +{ + public: + CharacterViewSmall(CharSelectDialog *const widget, + std::vector<CharacterDisplay*> *const entries, + const int padding); + A_DELETE_COPY(CharacterViewSmall) + + ~CharacterViewSmall(); + + void show(const int i); + + void resize(); + + void action(const gcn::ActionEvent &event) override; + + private: + CharacterDisplay *mSelectedEntry; + Button *mPrevious; + Button *mNext; + Label *mNumber; + std::vector<CharacterDisplay*> *mCharacterEntries; +}; + +#endif diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 98c0adc42..38e7f1f57 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -33,31 +33,39 @@ #include "debug.h" -PlayerBox::PlayerBox(Being *const being, const std::string &skin) : +PlayerBox::PlayerBox(Being *const being, const std::string &skin, + const std::string &selectedSkin) : Widget2(), ScrollArea(), mBeing(being), mAlpha(1.0), mBackground(), + mSelectedBackground(), mSkin(nullptr), - mDrawBackground(false), + mSelectedSkin(nullptr), mOffsetX(-16), - mOffsetY(-32) + mOffsetY(-32), + mDrawBackground(false), + mSelected(false) { - init(skin); + init(skin, selectedSkin); } -PlayerBox::PlayerBox(std::string skin) : +PlayerBox::PlayerBox(const std::string &skin, + const std::string &selectedSkin) : ScrollArea(), mBeing(nullptr), mAlpha(1.0), mBackground(), + mSelectedBackground(), mSkin(nullptr), - mDrawBackground(false), + mSelectedSkin(nullptr), mOffsetX(-16), - mOffsetY(-32) + mOffsetY(-32), + mDrawBackground(false), + mSelected(false) { - init(skin); + init(skin, selectedSkin); } PlayerBox::~PlayerBox() @@ -68,23 +76,23 @@ PlayerBox::~PlayerBox() Theme *const theme = Theme::instance(); if (theme) { - theme->unload(mSkin); theme->unloadRect(mBackground); + theme->unloadRect(mSelectedBackground); } mBeing = nullptr; } -void PlayerBox::init(std::string skin) +void PlayerBox::init(std::string name, std::string selectedName) { setFrameSize(2); if (Theme::instance()) { - if (skin.empty()) - skin = "playerbox.xml"; + if (name.empty()) + name = "playerbox.xml"; mSkin = Theme::instance()->loadSkinRect(mBackground, - skin, "playerbox_background.xml"); + name, "playerbox_background.xml"); if (mSkin) { mDrawBackground = (mSkin->getOption("drawbackground") != 0); @@ -92,11 +100,17 @@ void PlayerBox::init(std::string skin) mOffsetY = mSkin->getOption("offsetY", -32); mFrameSize = mSkin->getOption("frameSize", 2); } + if (selectedName.empty()) + selectedName = "playerboxselected.xml"; + mSelectedSkin = Theme::instance()->loadSkinRect(mSelectedBackground, + selectedName, "playerbox_background.xml"); } else { for (int f = 0; f < 9; f ++) mBackground.grid[f] = nullptr; + for (int f = 0; f < 9; f ++) + mSelectedBackground.grid[f] = nullptr; } } @@ -133,8 +147,16 @@ void PlayerBox::drawFrame(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - static_cast<Graphics*>(graphics)->drawImageRect( - 0, 0, w, h, mBackground); + if (!mSelected) + { + static_cast<Graphics*>(graphics)->drawImageRect( + 0, 0, w, h, mBackground); + } + else + { + static_cast<Graphics*>(graphics)->drawImageRect( + 0, 0, w, h, mSelectedBackground); + } } BLOCK_END("PlayerBox::drawFrame") } diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 61ad7dae4..f2b0a0616 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -46,9 +46,11 @@ class PlayerBox final : public Widget2, * Constructor. Takes the initial player character that this box should * display, which defaults to <code>NULL</code>. */ - PlayerBox(Being *const being, const std::string &skin = ""); + PlayerBox(Being *const being, const std::string &skin = "", + const std::string &selectedSkin = ""); - explicit PlayerBox(std::string skin = ""); + PlayerBox(const std::string &skin = "", + const std::string &selectedSkin = ""); A_DELETE_COPY(PlayerBox) @@ -57,7 +59,7 @@ class PlayerBox final : public Widget2, */ ~PlayerBox(); - void init(std::string skin); + void init(std::string name, std::string selectedName); /** * Sets a new player character to be displayed by this box. Setting the @@ -80,6 +82,9 @@ class PlayerBox final : public Widget2, Being *getBeing() A_WARN_UNUSED { return mBeing; } + void setSelected(bool b) + { mSelected = b; } + void mouseReleased(gcn::MouseEvent& event); private: @@ -87,10 +92,13 @@ class PlayerBox final : public Widget2, float mAlpha; ImageRect mBackground; + ImageRect mSelectedBackground; Skin *mSkin; - bool mDrawBackground; + Skin *mSelectedSkin; int mOffsetX; int mOffsetY; + bool mDrawBackground; + bool mSelected; }; #endif |