summaryrefslogtreecommitdiff
path: root/src/gui/npcdialog.cpp
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/npcdialog.cpp
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/npcdialog.cpp')
-rw-r--r--src/gui/npcdialog.cpp198
1 files changed, 173 insertions, 25 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();
+ }
+ }
+ }
+}