summaryrefslogtreecommitdiff
path: root/src/gui/npcintegerdialog.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-18 19:04:02 -0700
committerIra Rice <irarice@gmail.com>2009-01-18 19:04:02 -0700
commitd2b804c1a817ccdd85b4b1220bf929e9d370d774 (patch)
tree35f82a41b5107802fab3bbca7b2a59f7a3271e18 /src/gui/npcintegerdialog.cpp
parentd975741a095ae0dee82ff1dfdaa8e03439d7cf2b (diff)
downloadmana-d2b804c1a817ccdd85b4b1220bf929e9d370d774.tar.gz
mana-d2b804c1a817ccdd85b4b1220bf929e9d370d774.tar.bz2
mana-d2b804c1a817ccdd85b4b1220bf929e9d370d774.tar.xz
mana-d2b804c1a817ccdd85b4b1220bf929e9d370d774.zip
Fixed the NPC Integer input field, as well as cut some bull from the
NPC String class. The Integer input field was rather horribly broken to the point where it could send invalid data, the increment and decrement buttons didn't work, and overall it was tripping over itself. As for the NPC String, "The Mana World" as a string is not needed to set the field to that length, but instead fills the text field with that text for starting. This is completely inappropriate for a text entry field, and a more sensible default would be to leave it empty, so that people can type in what they want without having to delete it. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/npcintegerdialog.cpp')
-rw-r--r--src/gui/npcintegerdialog.cpp62
1 files changed, 24 insertions, 38 deletions
diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp
index f5b6ac5b..75dd52c8 100644
--- a/src/gui/npcintegerdialog.cpp
+++ b/src/gui/npcintegerdialog.cpp
@@ -25,7 +25,7 @@
#include <sstream>
#include "button.h"
-#include "textfield.h"
+#include "inttextfield.h"
#include "../npc.h"
@@ -39,18 +39,25 @@ NpcIntegerDialog::NpcIntegerDialog():
{
mDecButton = new Button("-", "decvalue", this);
mIncButton = new Button("+", "incvalue", this);
- mValueField = new TextField();
+ mValueField = new IntTextField();
okButton = new Button(_("OK"), "ok", this);
cancelButton = new Button(_("Cancel"), "cancel", this);
+ resetButton = new Button(_("Reset"), "reset", this);
mDecButton->setSize(20, 20);
mIncButton->setSize(20, 20);
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
+
place(0, 0, mDecButton);
place(1, 0, mValueField, 3);
place(4, 0, mIncButton);
- place(2, 1, okButton);
- place(3, 1, cancelButton, 2);
+ place.getCell().matchColWidth(1, 0);
+ place = getPlacer(0, 1);
+ place(0, 0, resetButton);
+ place(2, 0, cancelButton);
+ place(3, 0, okButton);
reflowLayout(175, 0);
setLocationRelativeTo(getParent());
@@ -59,19 +66,14 @@ NpcIntegerDialog::NpcIntegerDialog():
mValueField->addKeyListener(this);
}
-void NpcIntegerDialog::prepDialog(const int min, const int def, const int max)
+void NpcIntegerDialog::setRange(const int min, const int max)
{
- mMin = min;
- mMax = max;
- mDefault = def;
- mValue = def;
-
- mValueField->setText(toString(mValue));
+ mValueField->setRange(min, max);
}
int NpcIntegerDialog::getValue()
{
- return mValue;
+ return mValueField->getValue();
}
void NpcIntegerDialog::action(const gcn::ActionEvent &event)
@@ -85,41 +87,25 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event)
else if (event.getId() == "cancel")
{
finish = 1;
- mValue = mDefault;
+ mValueField->reset();
}
- else if (event.getId() == "decvalue" && mValue < mMin)
+ else if (event.getId() == "decvalue")
{
- mValue--;
+ mValueField->setValue(mValueField->getValue() - 1);
}
- else if (event.getId() == "incvalue" && mValue > mMax)
+ else if (event.getId() == "incvalue")
{
- mValue++;
+ mValueField->setValue(mValueField->getValue() + 1);
+ }
+ else if (event.getId() == "reset")
+ {
+ mValueField->reset();
}
-
- mValueField->setText(toString(mValue));
if (finish)
{
setVisible(false);
- current_npc->integerInput(mValue);
+ current_npc->integerInput(mValueField->getValue());
current_npc = 0;
}
}
-
-void NpcIntegerDialog::keyPressed(gcn::KeyEvent &event)
-{
- std::stringstream tempValue(mValueField->getText());
- int value;
- tempValue >> value;
- if (value < mMin)
- {
- value = mMin;
- }
- if (value > mMax)
- {
- value = mMax;
- }
-
- mValue = value;
- mValueField->setText(toString(value));
-}