summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-04-16 21:02:23 -0600
committerJared Adams <jaxad0127@gmail.com>2010-04-21 01:36:54 +0000
commit3c6fac14b67b86e2af9bbcac9e017f4b485e8149 (patch)
treeed0016d841a35ac0288ceeba7cc1dd4e1717dfd7 /src
parent959708c60c119e03183ba97177f13e92d61e342c (diff)
downloadmana-3c6fac14b67b86e2af9bbcac9e017f4b485e8149.tar.gz
mana-3c6fac14b67b86e2af9bbcac9e017f4b485e8149.tar.bz2
mana-3c6fac14b67b86e2af9bbcac9e017f4b485e8149.tar.xz
mana-3c6fac14b67b86e2af9bbcac9e017f4b485e8149.zip
Add a clear button to the NPC dialog
Reviewed-by: Bertram
Diffstat (limited to 'src')
-rw-r--r--src/gui/npcdialog.cpp64
-rw-r--r--src/gui/npcdialog.h11
-rw-r--r--src/gui/setup_video.cpp12
-rw-r--r--src/gui/setup_video.h2
4 files changed, 73 insertions, 16 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 16b584f3..6d3995a7 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -21,6 +21,7 @@
#include "gui/npcdialog.h"
+#include "configuration.h"
#include "npc.h"
#include "gui/setup.h"
@@ -51,6 +52,7 @@ NpcDialog::DialogList NpcDialog::instances;
NpcDialog::NpcDialog(int npcId)
: Window(_("NPC")),
mNpcId(npcId),
+ mLogInteraction(config.getValue("logNpcInGui", true)),
mDefaultInt(0),
mInputState(NPC_INPUT_NONE),
mActionState(NPC_ACTION_WAIT)
@@ -93,6 +95,8 @@ NpcDialog::NpcDialog(int npcId)
mIntField = new IntTextField;
mIntField->setVisible(true);
+ mClearButton = new Button(_("Clear log"), "clear", this);
+
// Setup button
mButton = new Button("", "ok", this);
@@ -118,6 +122,8 @@ NpcDialog::NpcDialog(int npcId)
instances.push_back(this);
setVisible(true);
requestFocus();
+
+ config.addListener("logNpcInGui", this);
}
NpcDialog::~NpcDialog()
@@ -132,6 +138,8 @@ NpcDialog::~NpcDialog()
delete mMinusButton;
instances.remove(this);
+
+ config.removeListener("logNpcInGui", this);
}
void NpcDialog::setText(const std::string &text)
@@ -140,9 +148,13 @@ void NpcDialog::setText(const std::string &text)
mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15);
}
-void NpcDialog::addText(const std::string &text)
+void NpcDialog::addText(const std::string &text, bool save)
{
- setText(mText + text + "\n");
+ if (save || mLogInteraction)
+ {
+ mNewText += text + "\n";
+ setText(mText + text + "\n");
+ }
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
mActionState = NPC_ACTION_WAIT;
buildLayout();
@@ -168,7 +180,7 @@ void NpcDialog::action(const gcn::ActionEvent &event)
{
nextDialog();
// TRANSLATORS: Please leave the \n sequences intact.
- addText(_("\n> Next\n"));
+ addText(_("\n> Next\n"), false);
}
else if (mActionState == NPC_ACTION_CLOSE)
{
@@ -203,8 +215,13 @@ 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()) );
+ addText(strprintf("\n> \"%s\"\n", printText.c_str()), false);
+
+ mNewText.clear();
}
+
+ if (!mLogInteraction)
+ setText("");
}
else if (event.getId() == "reset")
{
@@ -225,6 +242,10 @@ void NpcDialog::action(const gcn::ActionEvent &event)
{
mIntField->setValue(mIntField->getValue() - 1);
}
+ else if (event.getId() == "clear")
+ {
+ setText(mNewText);
+ }
}
void NpcDialog::nextDialog()
@@ -345,6 +366,14 @@ void NpcDialog::setVisible(bool visible)
}
}
+void NpcDialog::optionChanged(const std::string &name)
+{
+ if (name == "logNpcInGui")
+ {
+ mLogInteraction = config.getValue("logNpcInGui", true);
+ }
+}
+
NpcDialog *NpcDialog::getActive()
{
if (instances.size() == 1)
@@ -394,34 +423,41 @@ void NpcDialog::buildLayout()
mButton->setCaption(CAPTION_CLOSE);
}
place(0, 0, mScrollArea, 5, 3);
+ place(3, 3, mClearButton);
place(4, 3, mButton);
}
else if (mInputState != NPC_INPUT_NONE)
{
+ if (!mLogInteraction)
+ setText(mNewText);
+
mButton->setCaption(CAPTION_SUBMIT);
if (mInputState == NPC_INPUT_LIST)
{
- place(0, 0, mScrollArea, 5, 3);
- place(0, 3, mListScrollArea, 5, 3);
- place(3, 6, mButton, 2);
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mListScrollArea, 6, 3);
+ place(2, 6, mClearButton, 2);
+ place(4, 6, mButton, 2);
mItemList->setSelected(-1);
}
else if (mInputState == NPC_INPUT_STRING)
{
- place(0, 0, mScrollArea, 5, 3);
- place(0, 3, mTextField, 5);
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mTextField, 6);
place(0, 4, mResetButton, 2);
- place(3, 4, mButton, 2);
+ place(2, 4, mClearButton, 2);
+ place(4, 4, mButton, 2);
}
else if (mInputState == NPC_INPUT_INTEGER)
{
- place(0, 0, mScrollArea, 5, 3);
+ place(0, 0, mScrollArea, 6, 3);
place(0, 3, mMinusButton, 1);
- place(1, 3, mIntField, 3);
- place(4, 3, mPlusButton, 1);
+ place(1, 3, mIntField, 4);
+ place(5, 3, mPlusButton, 1);
place(0, 4, mResetButton, 2);
- place(3, 4, mButton, 2);
+ place(2, 4, mClearButton, 2);
+ place(4, 4, mButton, 2);
}
}
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index 50e9e2cc..a8521ce9 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -22,6 +22,7 @@
#ifndef NPCDIALOG_H
#define NPCDIALOG_H
+#include "configlistener.h"
#include "npc.h"
#include "gui/widgets/window.h"
@@ -45,7 +46,7 @@ class Button;
* \ingroup Interface
*/
class NpcDialog : public Window, public gcn::ActionListener,
- public gcn::ListModel
+ public gcn::ListModel, public ConfigListener
{
public:
/**
@@ -75,7 +76,7 @@ class NpcDialog : public Window, public gcn::ActionListener,
*
* @param string The text to add.
*/
- void addText(const std::string &string);
+ void addText(const std::string &string, bool save = true);
/**
* When called, the widget will show a "Next" button.
@@ -151,6 +152,8 @@ class NpcDialog : public Window, public gcn::ActionListener,
void setVisible(bool visible);
+ void optionChanged(const std::string &name);
+
/**
* Returns true if any instances exist.
*/
@@ -174,6 +177,7 @@ class NpcDialog : public Window, public gcn::ActionListener,
void buildLayout();
int mNpcId;
+ bool mLogInteraction;
int mDefaultInt;
std::string mDefaultString;
@@ -182,6 +186,7 @@ class NpcDialog : public Window, public gcn::ActionListener,
gcn::ScrollArea *mScrollArea;
TextBox *mTextBox;
std::string mText;
+ std::string mNewText;
// Used for choice input
ListBox *mItemList;
@@ -194,6 +199,8 @@ class NpcDialog : public Window, public gcn::ActionListener,
Button *mPlusButton;
Button *mMinusButton;
+ Button *mClearButton;
+
// Used for the button
Button *mButton;
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 926703b6..8ce6eebd 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -185,6 +185,7 @@ Setup_Video::Setup_Video():
mVisibleNamesEnabled(config.getValue("visiblenames", true)),
mParticleEffectsEnabled(config.getValue("particleeffects", true)),
mNameEnabled(config.getValue("showownname", false)),
+ mNPCLogEnabled(config.getValue("logNpcInGui", true)),
mPickupChatEnabled(config.getValue("showpickupchat", true)),
mPickupParticleEnabled(config.getValue("showpickupparticle", false)),
mOpacity(config.getValue("guialpha", 0.8)),
@@ -202,6 +203,7 @@ Setup_Video::Setup_Video():
mParticleEffectsCheckBox(new CheckBox(_("Particle effects"),
mParticleEffectsEnabled)),
mNameCheckBox(new CheckBox(_("Show own name"), mNameEnabled)),
+ mNPCLogCheckBox(new CheckBox(_("Log NPC interations"), mNPCLogEnabled)),
mPickupNotifyLabel(new Label(_("Show pickup notification"))),
// TRANSLATORS: Refers to "Show own name"
mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)),
@@ -262,6 +264,7 @@ Setup_Video::Setup_Video():
mPickupChatCheckBox->setActionEventId("pickupchat");
mPickupParticleCheckBox->setActionEventId("pickupparticle");
mNameCheckBox->setActionEventId("showownname");
+ mNPCLogCheckBox->setActionEventId("lognpc");
mAlphaSlider->setActionEventId("guialpha");
mFpsCheckBox->setActionEventId("fpslimitcheckbox");
mSpeechSlider->setActionEventId("speech");
@@ -279,6 +282,7 @@ Setup_Video::Setup_Video():
mPickupChatCheckBox->addActionListener(this);
mPickupParticleCheckBox->addActionListener(this);
mNameCheckBox->addActionListener(this);
+ mNPCLogCheckBox->addActionListener(this);
mAlphaSlider->addActionListener(this);
mFpsCheckBox->addActionListener(this);
mSpeechSlider->addActionListener(this);
@@ -315,6 +319,7 @@ Setup_Video::Setup_Video():
place(3, 2, mNameCheckBox, 1);
place(1, 3, mParticleEffectsCheckBox, 3);
+ place(3, 3, mNPCLogCheckBox, 1);
place(1, 4, mPickupNotifyLabel, 4);
@@ -426,6 +431,7 @@ void Setup_Video::apply()
mVisibleNamesEnabled = config.getValue("visiblenames", true);
mParticleEffectsEnabled = config.getValue("particleeffects", true);
mNameEnabled = config.getValue("showownname", false);
+ mNPCLogEnabled = config.getValue("logNpcInGui", true);
mSpeechMode = static_cast<Being::Speech>(
config.getValue("speech", Being::TEXT_OVERHEAD));
mOpacity = config.getValue("guialpha", 0.8);
@@ -448,6 +454,7 @@ void Setup_Video::cancel()
mFpsSlider->setEnabled(mFps > 0);
mSpeechSlider->setValue(mSpeechMode);
mNameCheckBox->setSelected(mNameEnabled);
+ mNPCLogCheckBox->setSelected(mNPCLogEnabled);
mAlphaSlider->setValue(mOpacity);
mOverlayDetailSlider->setValue(mOverlayDetail);
mParticleDetailSlider->setValue(mParticleDetail);
@@ -463,6 +470,7 @@ void Setup_Video::cancel()
config.setValue("showownname", mNameEnabled);
if (player_node)
player_node->setCheckNameSetting(true);
+ config.setValue("logNpcInGui", mNPCLogEnabled);
config.setValue("guialpha", mOpacity);
config.setValue("opengl", mOpenGLEnabled);
config.setValue("showpickupchat", mPickupChatEnabled);
@@ -547,6 +555,10 @@ void Setup_Video::action(const gcn::ActionEvent &event)
player_node->setCheckNameSetting(true);
config.setValue("showownname", mNameCheckBox->isSelected());
}
+ else if (id == "lognpc")
+ {
+ config.setValue("logNpcInGui", mNPCLogCheckBox->isSelected());
+ }
else if (id == "overlaydetailslider")
{
int val = (int) mOverlayDetailSlider->getValue();
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index f0984c49..ae0786b1 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -57,6 +57,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
bool mVisibleNamesEnabled;
bool mParticleEffectsEnabled;
bool mNameEnabled;
+ bool mNPCLogEnabled;
bool mPickupChatEnabled;
bool mPickupParticleEnabled;
double mOpacity;
@@ -82,6 +83,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
gcn::CheckBox *mVisibleNamesCheckBox;
gcn::CheckBox *mParticleEffectsCheckBox;
gcn::CheckBox *mNameCheckBox;
+ gcn::CheckBox *mNPCLogCheckBox;
gcn::Label *mPickupNotifyLabel;
gcn::CheckBox *mPickupChatCheckBox;