summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/windows/npcdialog.cpp34
-rw-r--r--src/gui/windows/npcdialog.h3
2 files changed, 25 insertions, 12 deletions
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 21c8fd577..51edbaf3b 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -132,6 +132,7 @@ NpcDialog::NpcDialog(const BeingId npcId) :
mSkinName(),
mPlayerBox(new PlayerBox(nullptr)),
mAvatarBeing(nullptr),
+ mDialogInfo(nullptr),
mLastNextTime(0),
mCameraMode(-1),
mCameraX(0),
@@ -321,7 +322,7 @@ void NpcDialog::action(const ActionEvent &event)
{
case NPC_INPUT_LIST:
{
- if (!mSkinName.empty())
+ if (mDialogInfo)
return;
if (gui)
gui->resetClickCount();
@@ -952,7 +953,7 @@ void NpcDialog::buildLayout()
switch (mInputState)
{
case NPC_INPUT_LIST:
- if (mSkinName.empty())
+ if (!mDialogInfo)
placeMenuControls();
else
placeSkinControls();
@@ -1141,7 +1142,21 @@ void NpcDialog::copyToClipboard(const BeingId npcId,
void NpcDialog::setSkin(const std::string &skin)
{
+ if (skin.empty())
+ {
+ mSkinName = skin;
+ mDialogInfo = nullptr;
+ return;
+ }
+ const NpcDialogInfo *const dialog = NpcDialogDB::getDialog(skin);
+ if (!dialog)
+ {
+ logger->log("Error: creating controls for not existing npc dialog %s",
+ skin.c_str());
+ return;
+ }
mSkinName = skin;
+ mDialogInfo = dialog;
}
void NpcDialog::deleteSkinControls()
@@ -1153,18 +1168,13 @@ void NpcDialog::createSkinControls()
{
deleteSkinControls();
- const NpcDialogInfo *const dialog = NpcDialogDB::getDialog(mSkinName);
- if (!dialog)
- {
- logger->log("Error: creating controls for not existing npc dialog %s",
- mSkinName.c_str());
+ if (!mDialogInfo)
return;
- }
- mHideText = dialog->hideText;
+ mHideText = mDialogInfo->hideText;
FOR_EACH (std::vector<NpcImageInfo*>::const_iterator,
it,
- dialog->menu.images)
+ mDialogInfo->menu.images)
{
const NpcImageInfo *const info = *it;
Image *const image = Theme::getImageFromTheme(info->name);
@@ -1177,7 +1187,7 @@ void NpcDialog::createSkinControls()
}
FOR_EACH (std::vector<NpcTextInfo*>::const_iterator,
it,
- dialog->menu.texts)
+ mDialogInfo->menu.texts)
{
const NpcTextInfo *const info = *it;
BrowserBox *box = new BrowserBox(this,
@@ -1204,7 +1214,7 @@ void NpcDialog::createSkinControls()
}
FOR_EACH (std::vector<NpcButtonInfo*>::const_iterator,
it,
- dialog->menu.buttons)
+ mDialogInfo->menu.buttons)
{
const NpcButtonInfo *const info = *it;
Button *const button = new Button(this);
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index 445cb03ba..997f97e8a 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -46,6 +46,8 @@ class PlayerBox;
class ScrollArea;
class TextField;
+struct NpcDialogInfo;
+
typedef std::map<BeingId, NpcDialog*> NpcDialogs;
/**
@@ -309,6 +311,7 @@ class NpcDialog final : public Window,
std::string mSkinName;
PlayerBox *mPlayerBox A_NONNULLPOINTER;
Being *mAvatarBeing;
+ const NpcDialogInfo *mDialogInfo;
int mLastNextTime;
int mCameraMode;
int mCameraX;