summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/npcdialog.cpp43
-rw-r--r--src/gui/npcdialog.h20
2 files changed, 27 insertions, 36 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 90d3e37e..376813f7 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -28,14 +28,14 @@
#include "playerinfo.h"
#include "gui/npcpostdialog.h"
-#include "gui/setup.h"
+#include "gui/widgets/browserbox.h"
#include "gui/widgets/button.h"
#include "gui/widgets/inttextfield.h"
+#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/textbox.h"
#include "gui/widgets/textfield.h"
#include "net/net.h"
@@ -69,9 +69,10 @@ static NpcEventListener *npcListener = nullptr;
NpcDialog::DialogList NpcDialog::instances;
NpcDialog::NpcDialog(int npcId)
- : Window(_("NPC")),
- mNpcId(npcId),
- mLogInteraction(config.getBoolValue("logNpcInGui"))
+ : Window(_("NPC"))
+ , mNpcId(npcId)
+ , mLogInteraction(config.getBoolValue("logNpcInGui"))
+ , mItemLinkHandler(std::make_unique<ItemLinkHandler>(this))
{
// Basic Window Setup
setWindowName("NpcText");
@@ -85,9 +86,8 @@ NpcDialog::NpcDialog(int npcId)
setDefaultSize(260, 200, ImageRect::CENTER);
// Setup output text box
- mTextBox = new TextBox;
- mTextBox->setEditable(false);
- mTextBox->setOpaque(false);
+ mTextBox = new BrowserBox(BrowserBox::AUTO_WRAP);
+ mTextBox->setLinkHandler(mItemLinkHandler.get());
mScrollArea = new ScrollArea(mTextBox);
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -104,7 +104,7 @@ NpcDialog::NpcDialog(int npcId)
mItemList->setVisible(true);
// Setup string input box
- mTextField = new TextField(std::string());
+ mTextField = new TextField;
mTextField->setVisible(true);
// Setup int input box
@@ -164,18 +164,19 @@ NpcDialog::~NpcDialog()
npcListener->removeDialog(mNpcId);
}
-void NpcDialog::setText(const std::string &text)
+void NpcDialog::setText(const std::vector<std::string> &text)
{
- mText = text;
- mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15);
+ mTextBox->clearRows();
+ for (const std::string &row : text)
+ mTextBox->addRow(row);
}
void NpcDialog::addText(const std::string &text, bool save)
{
if (save || mLogInteraction)
{
- mNewText += text + "\n";
- setText(mText + text + "\n");
+ mNewText.push_back(text);
+ mTextBox->addRow(text);
}
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
mActionState = NPC_ACTION_WAIT;
@@ -235,13 +236,14 @@ void NpcDialog::action(const gcn::ActionEvent &event)
Net::getNpcHandler()->integerInput(mNpcId, mIntField->getValue());
}
// addText will auto remove the input layout
- addText(strprintf("\n> \"%s\"\n", printText.c_str()), false);
+ addText(strprintf("> \"%s\"", printText.c_str()), false);
+ addText(std::string(), false);
mNewText.clear();
}
if (!mLogInteraction)
- setText(std::string());
+ setText({});
}
else if (event.getId() == "reset")
{
@@ -371,13 +373,6 @@ void NpcDialog::move(int amount)
}
}
-void NpcDialog::widgetResized(const gcn::Event &event)
-{
- Window::widgetResized(event);
-
- setText(mText);
-}
-
void NpcDialog::setVisible(bool visible)
{
Window::setVisible(visible);
@@ -587,7 +582,7 @@ void NpcEventListener::event(Event::Channel channel,
else if (event.getType() == Event::ClearDialog)
{
if (NpcDialog *dialog = getDialog(event.getInt("id"), false))
- dialog->setText(std::string());
+ dialog->setText({});
}
else if (event.getType() == Event::Close)
{
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index 36fda2b1..b902f044 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -30,13 +30,15 @@
#include <guichan/listmodel.hpp>
#include <list>
+#include <memory>
#include <string>
#include <vector>
-class TextBox;
+class BrowserBox;
class ListBox;
class TextField;
class IntTextField;
+class ItemLinkHandler;
class Button;
/**
@@ -64,7 +66,7 @@ class NpcDialog : public Window,
*
* @param string The new text.
*/
- void setText(const std::string &string);
+ void setText(const std::vector<std::string> &string);
/**
* Adds the text to the text shows in the dialog. Also adds a newline
@@ -139,13 +141,6 @@ class NpcDialog : public Window,
void move(int amount);
- /**
- * Called when resizing the window.
- *
- * @param event The calling event
- */
- void widgetResized(const gcn::Event &event) override;
-
void setVisible(bool visible) override;
void event(Event::Channel channel, const Event &event) override;
@@ -182,9 +177,10 @@ class NpcDialog : public Window,
// Used for the main input area
gcn::ScrollArea *mScrollArea;
- TextBox *mTextBox;
- std::string mText;
- std::string mNewText;
+ BrowserBox *mTextBox;
+ std::vector<std::string> mNewText;
+
+ std::unique_ptr<ItemLinkHandler> mItemLinkHandler;
// Used for choice input
ListBox *mItemList;