summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-30 14:37:49 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-01 17:51:01 +0300
commitc01aec243610016c2cd5e4211fee484627bc69ea (patch)
tree46a0b704701a9c1229fafa5e7ed7117002fc1579 /src/gui
parent8321043b76660235a5ebbfbb8f43504f43c1af8b (diff)
downloadmanaverse-c01aec243610016c2cd5e4211fee484627bc69ea.tar.gz
manaverse-c01aec243610016c2cd5e4211fee484627bc69ea.tar.bz2
manaverse-c01aec243610016c2cd5e4211fee484627bc69ea.tar.xz
manaverse-c01aec243610016c2cd5e4211fee484627bc69ea.zip
Add npc avatars for evol server.
Change protocol version to 6.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npcdialog.cpp198
-rw-r--r--src/gui/npcdialog.h21
-rw-r--r--src/gui/widgets/playerbox.cpp2
-rw-r--r--src/gui/widgets/playerbox.h9
4 files changed, 201 insertions, 29 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index ffd8e8e2d..ec76ea3f5 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/npcdialog.h"
+#include "being.h"
#include "configuration.h"
#include "client.h"
@@ -37,6 +38,7 @@
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/listbox.h"
+#include "gui/widgets/playerbox.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textbox.h"
#include "gui/widgets/textfield.h"
@@ -68,7 +70,10 @@ NpcDialog::NpcDialog(int npcId) :
mLastNextTime(0),
mCameraMode(-1),
mCameraX(0),
- mCameraY(0)
+ mCameraY(0),
+ mPlayerBox(new PlayerBox),
+ mAvatarBeing(nullptr),
+ mShowAvatar(false)
{
// Basic Window Setup
setWindowName("NpcText");
@@ -82,6 +87,9 @@ NpcDialog::NpcDialog(int npcId) :
setDefaultSize(400, 400, ImageRect::CENTER);
+ mPlayerBox->setWidth(70);
+ mPlayerBox->setHeight(100);
+
mItemLinkHandler = new ItemLinkHandler;
// Setup output text box
mTextBox = new BrowserBox(BrowserBox::AUTO_WRAP);
@@ -155,6 +163,12 @@ NpcDialog::~NpcDialog()
clearLayout();
+ if (mPlayerBox)
+ {
+ delete mPlayerBox->getBeing();
+ delete mPlayerBox;
+ }
+
delete mTextBox;
mTextBox = nullptr;
delete mClearButton;
@@ -469,6 +483,88 @@ void NpcDialog::closeAll()
}
}
+void NpcDialog::placeNormalControls()
+{
+ if (mShowAvatar)
+ {
+ place(0, 0, mPlayerBox);
+ place(1, 0, mScrollArea, 5, 3);
+ place(4, 3, mClearButton);
+ place(5, 3, mButton);
+ }
+ else
+ {
+ place(0, 0, mScrollArea, 5, 3);
+ place(3, 3, mClearButton);
+ place(4, 3, mButton);
+ }
+}
+
+void NpcDialog::placeMenuControls()
+{
+ if (mShowAvatar)
+ {
+ place(0, 0, mPlayerBox);
+ place(1, 0, mScrollArea, 6, 3);
+ place(0, 3, mListScrollArea, 7, 3);
+ place(3, 6, mClearButton, 2);
+ place(5, 6, mButton, 2);
+ }
+ else
+ {
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mListScrollArea, 6, 3);
+ place(2, 6, mClearButton, 2);
+ place(4, 6, mButton, 2);
+ }
+}
+
+void NpcDialog::placeTextInputControls()
+{
+ if (mShowAvatar)
+ {
+ place(0, 0, mPlayerBox);
+ place(1, 0, mScrollArea, 6, 3);
+ place(0, 3, mTextField, 6);
+ place(0, 4, mResetButton, 2);
+ place(4, 4, mClearButton, 2);
+ place(5, 4, mButton, 2);
+ }
+ else
+ {
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mTextField, 6);
+ place(0, 4, mResetButton, 2);
+ place(2, 4, mClearButton, 2);
+ place(4, 4, mButton, 2);
+ }
+}
+
+void NpcDialog::placeIntInputControls()
+{
+ if (mShowAvatar)
+ {
+ place(0, 0, mPlayerBox);
+ place(1, 0, mScrollArea, 6, 3);
+ place(1, 3, mMinusButton, 1);
+ place(2, 3, mIntField, 4);
+ place(6, 3, mPlusButton, 1);
+ place(0, 4, mResetButton, 2);
+ place(3, 4, mClearButton, 2);
+ place(5, 4, mButton, 2);
+ }
+ else
+ {
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mMinusButton, 1);
+ place(1, 3, mIntField, 4);
+ place(5, 3, mPlusButton, 1);
+ place(0, 4, mResetButton, 2);
+ place(2, 4, mClearButton, 2);
+ place(4, 4, mButton, 2);
+ }
+}
+
void NpcDialog::buildLayout()
{
clearLayout();
@@ -481,47 +577,28 @@ void NpcDialog::buildLayout()
mButton->setCaption(CAPTION_NEXT);
else if (mActionState == NPC_ACTION_CLOSE)
mButton->setCaption(CAPTION_CLOSE);
- place(0, 0, mScrollArea, 5, 3);
- place(3, 3, mClearButton);
- place(4, 3, mButton);
+ placeNormalControls();
}
else if (mInputState != NPC_INPUT_NONE)
{
-// if (!mLogInteraction)
-// setText(mNewText);
-
mButton->setCaption(CAPTION_SUBMIT);
if (mInputState == NPC_INPUT_LIST)
{
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mListScrollArea, 6, 3);
- place(2, 6, mClearButton, 2);
- place(4, 6, mButton, 2);
-
+ placeMenuControls();
mItemList->setSelected(-1);
}
else if (mInputState == NPC_INPUT_STRING)
{
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mTextField, 6);
- place(0, 4, mResetButton, 2);
- place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
+ placeTextInputControls();
}
else if (mInputState == NPC_INPUT_INTEGER)
{
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mMinusButton, 1);
- place(1, 3, mIntField, 4);
- place(5, 3, mPlusButton, 1);
- place(0, 4, mResetButton, 2);
- place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
+ placeIntInputControls();
}
}
Layout &layout = getLayout();
- layout.setRowHeight(0, Layout::AUTO_SET);
+ layout.setRowHeight(1, Layout::AUTO_SET);
redraw();
@@ -557,3 +634,74 @@ void NpcDialog::restoreCamera()
}
mCameraMode = -1;
}
+
+void NpcDialog::showAvatar(int avatarId)
+{
+ bool needShow = (avatarId != 0);
+ if (needShow)
+ {
+ delete mAvatarBeing;
+ mAvatarBeing = new Being(0, ActorSprite::NPC, avatarId, nullptr);
+ mPlayerBox->setPlayer(mAvatarBeing);
+ if (mAvatarBeing && !mAvatarBeing->empty())
+ {
+ mAvatarBeing->logic();
+ Sprite *sprite = mAvatarBeing->getSprite(0);
+ if (sprite)
+ {
+ int width = sprite->getWidth() + 2 * getPadding();
+ mPlayerBox->setWidth(width);
+ int height = sprite->getHeight() + 2 * getPadding();
+ mPlayerBox->setHeight(height);
+ }
+ }
+ }
+ else
+ {
+ delete mAvatarBeing;
+ mAvatarBeing = nullptr;
+ mPlayerBox->setPlayer(nullptr);
+ }
+ if (needShow != mShowAvatar)
+ {
+ mShowAvatar = needShow;
+ buildLayout();
+ }
+ else
+ {
+ mShowAvatar = needShow;
+ }
+}
+
+void NpcDialog::setAvatarDirection(uint8_t direction)
+{
+ Being *being = mPlayerBox->getBeing();
+ if (being)
+ being->setDirection(direction);
+}
+
+void NpcDialog::setAvatarAction(int actionId)
+{
+ Being *being = mPlayerBox->getBeing();
+ if (being)
+ being->setAction((Being::Action)actionId);
+}
+
+void NpcDialog::logic()
+{
+ Window::logic();
+ if (mShowAvatar && mAvatarBeing)
+ {
+ mAvatarBeing->logic();
+ if (mPlayerBox->getWidth() < (signed)(3 * getPadding()))
+ {
+ Sprite *sprite = mAvatarBeing->getSprite(0);
+ if (sprite)
+ {
+ mPlayerBox->setWidth(sprite->getWidth() + 2 * getPadding());
+ mPlayerBox->setHeight(sprite->getHeight() + 2 * getPadding());
+ buildLayout();
+ }
+ }
+ }
+}
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index f56af664e..68ee17e33 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -34,10 +34,12 @@
#include <list>
+class Being;
class BrowserBox;
class ItemLinkHandler;
class IntTextField;
class ListBox;
+class PlayerBox;
class TextBox;
class TextField;
class Button;
@@ -184,12 +186,28 @@ class NpcDialog : public Window, public gcn::ActionListener,
void refocus();
+ void showAvatar(int avatarId);
+
+ void setAvatarDirection(uint8_t direction);
+
+ void setAvatarAction(int actionId);
+
+ void logic();
+
private:
typedef std::list<NpcDialog*> DialogList;
static DialogList instances;
void buildLayout();
+ void placeNormalControls();
+
+ void placeMenuControls();
+
+ void placeTextInputControls();
+
+ void placeIntInputControls();
+
int mNpcId;
bool mLogInteraction;
@@ -245,6 +263,9 @@ class NpcDialog : public Window, public gcn::ActionListener,
int mCameraMode;
int mCameraX;
int mCameraY;
+ PlayerBox *mPlayerBox;
+ Being *mAvatarBeing;
+ bool mShowAvatar;
};
#endif // NPCDIALOG_H
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 5e2412d3b..90a9c9409 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -40,7 +40,7 @@ int PlayerBox::instances = 0;
float PlayerBox::mAlpha = 1.0;
ImageRect PlayerBox::background;
-PlayerBox::PlayerBox(const Being *being):
+PlayerBox::PlayerBox(Being *being):
mBeing(being)
{
setFrameSize(2);
diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h
index d2393ca08..9e5a761b4 100644
--- a/src/gui/widgets/playerbox.h
+++ b/src/gui/widgets/playerbox.h
@@ -42,7 +42,7 @@ class PlayerBox : public gcn::ScrollArea
* Constructor. Takes the initial player character that this box should
* display, which defaults to <code>NULL</code>.
*/
- PlayerBox(const Being *being = nullptr);
+ PlayerBox(Being *being = nullptr);
/**
* Destructor.
@@ -54,7 +54,7 @@ class PlayerBox : public gcn::ScrollArea
* player to <code>NULL</code> causes the box not to draw any
* character.
*/
- void setPlayer(const Being *being)
+ void setPlayer(Being *being)
{ mBeing = being; }
/**
@@ -67,8 +67,11 @@ class PlayerBox : public gcn::ScrollArea
*/
void drawFrame(gcn::Graphics *graphics);
+ Being *getBeing()
+ { return mBeing; }
+
private:
- const Being *mBeing; /**< The character used for display */
+ Being *mBeing; /**< The character used for display */
static float mAlpha;
static int instances;