summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-16 23:26:43 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-17 01:10:09 +0300
commit46dd47b2652d0928bc414b12685a89effe41e9ef (patch)
tree3bacd592cf08ff3eab1a3fae41688e8f4410047f /src
parent5a3724fea17bb1d1059207eb6c1d1e18dac20aa3 (diff)
downloadmv-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.gz
mv-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.bz2
mv-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.xz
mv-46dd47b2652d0928bc414b12685a89effe41e9ef.zip
improve npcdialog class.
allow set avatar size in avatars.xml.
Diffstat (limited to 'src')
-rw-r--r--src/gui/npcdialog.cpp47
-rw-r--r--src/gui/npcdialog.h10
-rw-r--r--src/resources/avatardb.cpp5
-rw-r--r--src/resources/beinginfo.cpp8
-rw-r--r--src/resources/beinginfo.h18
5 files changed, 53 insertions, 35 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 598926546..f4d99cc79 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -43,6 +43,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textbox.h"
+#include "resources/avatardb.h"
#include "resources/npcdb.h"
#include "resources/resourcemanager.h"
@@ -73,7 +74,6 @@ NpcDialog::NpcDialog(const int npcId) :
Window(_("NPC"), false, nullptr, "npc.xml"),
gcn::ActionListener(),
mNpcId(npcId),
- mLogInteraction(config.getBoolValue("logNpcInGui")),
mDefaultInt(0),
mDefaultString(),
mTextBox(new BrowserBox(this, BrowserBox::AUTO_WRAP)),
@@ -108,7 +108,8 @@ NpcDialog::NpcDialog(const int npcId) :
mCameraY(0),
mPlayerBox(new PlayerBox(nullptr)),
mAvatarBeing(nullptr),
- mShowAvatar(false)
+ mShowAvatar(false),
+ mLogInteraction(config.getBoolValue("logNpcInGui"))
{
// Basic Window Setup
setWindowName("NpcText");
@@ -155,7 +156,6 @@ NpcDialog::NpcDialog(const int npcId) :
fnt->getWidth(CAPTION_NEXT));
width = std::max(width, fnt->getWidth(CAPTION_CLOSE));
width = std::max(width, fnt->getWidth(CAPTION_SUBMIT));
-
mButton->setWidth(8 + width);
// Place widgets
@@ -182,8 +182,7 @@ NpcDialog::NpcDialog(const int npcId) :
NpcDialog::~NpcDialog()
{
- config.removeListener("logNpcInGui", this);
-
+ config.removeListeners(this);
clearLayout();
if (mPlayerBox)
@@ -233,15 +232,6 @@ NpcDialog::~NpcDialog()
instances.remove(this);
}
-/*
-void NpcDialog::setText(const std::string &text)
-{
- mText = text;
-
- mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15);
-}
-*/
-
void NpcDialog::addText(const std::string &text, const bool save)
{
if (save || mLogInteraction)
@@ -251,7 +241,6 @@ void NpcDialog::addText(const std::string &text, const bool save)
mNewText.append(text);
mTextBox->addRow(text);
-// setText(mText + text + "\n");
}
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
mActionState = NPC_ACTION_WAIT;
@@ -290,8 +279,8 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
else if (mActionState == NPC_ACTION_INPUT)
{
- std::string printText(""); // Text that will get printed
- // in the textbox
+ std::string printText; // Text that will get printed
+ // in the textbox
if (mInputState == NPC_INPUT_LIST)
{
@@ -328,7 +317,6 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
// addText will auto remove the input layout
addText(strprintf("> \"%s\"", printText.c_str()), false);
-
mNewText.clear();
}
@@ -416,6 +404,7 @@ void NpcDialog::parseListItems(const std::string &itemString)
ResourceManager *const resman = ResourceManager::getInstance();
std::string tmp;
+ const std::string path = paths.getStringValue("guiIcons");
while (getline(iss, tmp, ':'))
{
const size_t pos = tmp.find("|");
@@ -427,9 +416,8 @@ void NpcDialog::parseListItems(const std::string &itemString)
else
{
mItems.push_back(tmp.substr(pos + 1));
- Image *const img = resman->getImage(
- paths.getStringValue("guiIcons")
- .append(tmp.substr(0, pos)).append(".png"));
+ Image *const img = resman->getImage(std::string(
+ path).append(tmp.substr(0, pos)).append(".png"));
mImages.push_back(img);
}
}
@@ -668,9 +656,7 @@ void NpcDialog::buildLayout()
Layout &layout = getLayout();
layout.setRowHeight(1, Layout::AUTO_SET);
-
redraw();
-
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
}
@@ -715,11 +701,20 @@ void NpcDialog::showAvatar(const uint16_t avatarId)
if (!mAvatarBeing->empty())
{
mAvatarBeing->logic();
+ const BeingInfo *const info = AvatarDB::get(avatarId);
+ const int pad2 = 2 * mPadding;
+ int width = 0;
+ if (info)
+ {
+ width = info->getWidth();
+ mPlayerBox->setWidth(width + pad2);
+ mPlayerBox->setHeight(info->getHeight() + pad2);
+ }
const Sprite *const sprite = mAvatarBeing->getSprite(0);
- if (sprite)
+ if (sprite && !width)
{
- mPlayerBox->setWidth(sprite->getWidth() + 2 * getPadding());
- mPlayerBox->setHeight(sprite->getHeight() + 2 * getPadding());
+ mPlayerBox->setWidth(sprite->getWidth() + pad2);
+ mPlayerBox->setHeight(sprite->getHeight() + pad2);
}
}
}
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index f8c50ddff..b0208755b 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -51,8 +51,10 @@ class TextField;
*
* \ingroup Interface
*/
-class NpcDialog final : public Window, public gcn::ActionListener,
- public ExtendedListModel, public ConfigListener
+class NpcDialog final : public Window,
+ public gcn::ActionListener,
+ public ExtendedListModel,
+ public ConfigListener
{
public:
/**
@@ -158,7 +160,7 @@ class NpcDialog final : public Window, public gcn::ActionListener,
void move(const int amount);
- void setVisible(bool visible);
+ void setVisible(bool visible) override;
void optionChanged(const std::string &name) override;
@@ -215,7 +217,6 @@ class NpcDialog final : public Window, public gcn::ActionListener,
void placeIntInputControls();
int mNpcId;
- bool mLogInteraction;
int mDefaultInt;
std::string mDefaultString;
@@ -272,6 +273,7 @@ class NpcDialog final : public Window, public gcn::ActionListener,
PlayerBox *mPlayerBox;
Being *mAvatarBeing;
bool mShowAvatar;
+ bool mLogInteraction;
};
#endif // NPCDIALOG_H
diff --git a/src/resources/avatardb.cpp b/src/resources/avatardb.cpp
index e18eff5c2..39b1184fb 100644
--- a/src/resources/avatardb.cpp
+++ b/src/resources/avatardb.cpp
@@ -73,6 +73,11 @@ void AvatarDB::load()
currentInfo->setTargetOffsetY(XML::getProperty(avatarNode,
"targetOffsetY", 0));
+ currentInfo->setWidth(XML::getProperty(avatarNode,
+ "width", 0));
+ currentInfo->setHeight(XML::getProperty(avatarNode,
+ "height", 0));
+
SpriteDisplay display;
// iterate <sprite>s and <sound>s
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index 914a00d1a..b1d6c1d0c 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -49,11 +49,13 @@ BeingInfo::BeingInfo() :
mTargetOffsetX(0),
mTargetOffsetY(0),
mMaxHP(0),
- mStaticMaxHP(false),
- mTargetSelection(true),
mSortOffsetY(0),
mDeadSortOffsetY(31),
- mAvatarId(0)
+ mAvatarId(0),
+ mWidth(0),
+ mHeight(0),
+ mStaticMaxHP(false),
+ mTargetSelection(true)
{
SpriteDisplay display;
display.sprites.push_back(SpriteReference::Empty);
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index 9bf5417fa..36c78f53b 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -195,6 +195,18 @@ class BeingInfo final
void setAvatarId(const uint16_t id)
{ mAvatarId = id; }
+ int getWidth() const
+ { return mWidth; }
+
+ int getHeight() const
+ { return mHeight; }
+
+ void setWidth(const int n)
+ { mWidth = n; }
+
+ void setHeight(const int n)
+ { mHeight = n; }
+
static void init();
static void clear();
@@ -211,11 +223,13 @@ class BeingInfo final
int mTargetOffsetX;
int mTargetOffsetY;
int mMaxHP;
- bool mStaticMaxHP;
- bool mTargetSelection;
int mSortOffsetY;
int mDeadSortOffsetY;
uint16_t mAvatarId;
+ int mWidth;
+ int mHeight;
+ bool mStaticMaxHP;
+ bool mTargetSelection;
};
typedef std::map<int, BeingInfo*> BeingInfos;