summaryrefslogtreecommitdiff
path: root/src/gui
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/gui
parent5a3724fea17bb1d1059207eb6c1d1e18dac20aa3 (diff)
downloadmanaverse-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.gz
manaverse-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.bz2
manaverse-46dd47b2652d0928bc414b12685a89effe41e9ef.tar.xz
manaverse-46dd47b2652d0928bc414b12685a89effe41e9ef.zip
improve npcdialog class.
allow set avatar size in avatars.xml.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npcdialog.cpp47
-rw-r--r--src/gui/npcdialog.h10
2 files changed, 27 insertions, 30 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