summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-02-15 03:32:36 +0200
committerAndrei Karas <akaras@inbox.ru>2011-02-15 03:32:36 +0200
commit94f11a223e03c6845e7ce6e9fe67c0e9fa7061f4 (patch)
treef928dbd50f5f81db1935be1734d9903680798c48 /src/gui
parent3805d1384894a33ecb09e4852d47afb04ddb0687 (diff)
downloadmv-94f11a223e03c6845e7ce6e9fe67c0e9fa7061f4.tar.gz
mv-94f11a223e03c6845e7ce6e9fe67c0e9fa7061f4.tar.bz2
mv-94f11a223e03c6845e7ce6e9fe67c0e9fa7061f4.tar.xz
mv-94f11a223e03c6845e7ce6e9fe67c0e9fa7061f4.zip
Replace in npc dialogs textbox to browserbox. This allow use links, colors, etc.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npcdialog.cpp32
-rw-r--r--src/gui/npcdialog.h12
-rw-r--r--src/gui/widgets/browserbox.cpp1
3 files changed, 30 insertions, 15 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 4fe5bf8ab..1859329ab 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -26,9 +26,11 @@
#include "gui/setup.h"
+#include "gui/widgets/browserbox.h"
#include "gui/widgets/button.h"
#include "gui/widgets/chattab.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"
@@ -70,10 +72,11 @@ NpcDialog::NpcDialog(int npcId)
setDefaultSize(260, 200, ImageRect::CENTER);
+ mItemLinkHandler = new ItemLinkHandler;
// Setup output text box
- mTextBox = new TextBox;
- mTextBox->setEditable(false);
+ mTextBox = new BrowserBox;
mTextBox->setOpaque(false);
+ mTextBox->setLinkHandler(mItemLinkHandler);
mScrollArea = new ScrollArea(mTextBox);
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -147,16 +150,20 @@ NpcDialog::~NpcDialog()
mPlusButton = 0;
delete mMinusButton;
mMinusButton = 0;
+ delete mItemLinkHandler;
+ mItemLinkHandler = 0;
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, bool save)
{
@@ -165,8 +172,9 @@ void NpcDialog::addText(const std::string &text, bool save)
if (mText.size() > 5000)
mText = "";
- mNewText += text + "\n";
- setText(mText + text + "\n");
+ mNewText += text;
+ mTextBox->addRow(text);
+// setText(mText + text + "\n");
}
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
mActionState = NPC_ACTION_WAIT;
@@ -196,7 +204,7 @@ void NpcDialog::action(const gcn::ActionEvent &event)
nextDialog();
// TRANSLATORS: Please leave the \n sequences intact.
- addText(_("\n> Next\n"), false);
+ addText(_("> Next"), false);
}
else if (mActionState == NPC_ACTION_CLOSE)
{
@@ -239,13 +247,13 @@ void NpcDialog::action(const gcn::ActionEvent &event)
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);
mNewText.clear();
}
if (!mLogInteraction)
- setText("");
+ mTextBox->clearRows();
}
else if (event.getId() == "reset")
{
@@ -264,7 +272,9 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "clear")
{
- setText(mNewText);
+ mTextBox->clearRows();
+// mTextBox->addRow(mNewText);
+// setText(mNewText);
}
}
@@ -377,7 +387,7 @@ void NpcDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
- setText(mText);
+// setText(mText);
}
void NpcDialog::setVisible(bool visible)
@@ -441,8 +451,8 @@ void NpcDialog::buildLayout()
}
else if (mInputState != NPC_INPUT_NONE)
{
- if (!mLogInteraction)
- setText(mNewText);
+// if (!mLogInteraction)
+// setText(mNewText);
mButton->setCaption(CAPTION_SUBMIT);
if (mInputState == NPC_INPUT_LIST)
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index c4a567c06..35015f3ce 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -33,10 +33,12 @@
#include <string>
#include <vector>
-class TextBox;
+class BrowserBox;
+class ItemLinkHandler;
+class IntTextField;
class ListBox;
+class TextBox;
class TextField;
-class IntTextField;
class Button;
/**
@@ -67,7 +69,7 @@ class NpcDialog : public Window, public gcn::ActionListener,
*
* @param string The new text.
*/
- void setText(const std::string &string);
+// void setText(const std::string &string);
/**
* Adds the text to the text shows in the dialog. Also adds a newline
@@ -190,7 +192,8 @@ class NpcDialog : public Window, public gcn::ActionListener,
// Used for the main input area
gcn::ScrollArea *mScrollArea;
- TextBox *mTextBox;
+ BrowserBox *mTextBox;
+ //TextBox *mTextBox;
std::string mText;
std::string mNewText;
@@ -198,6 +201,7 @@ class NpcDialog : public Window, public gcn::ActionListener,
ListBox *mItemList;
gcn::ScrollArea *mListScrollArea;
std::vector<std::string> mItems;
+ ItemLinkHandler *mItemLinkHandler;
// Used for string and integer input
TextField *mTextField;
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 3e3b9f07f..4a384d28a 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -40,6 +40,7 @@
BrowserBox::BrowserBox(unsigned int mode, bool opaque):
gcn::Widget(),
+ mLinkHandler(0),
mMode(mode), mHighMode(UNDERLINE | BACKGROUND),
mOpaque(opaque),
mUseLinksAndUserColors(true),