summaryrefslogtreecommitdiff
path: root/src/gui
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
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')
-rw-r--r--src/gui/inttextfield.cpp (renamed from src/gui/inttextbox.cpp)31
-rw-r--r--src/gui/inttextfield.h (renamed from src/gui/inttextbox.h)20
-rw-r--r--src/gui/item_amount.cpp24
-rw-r--r--src/gui/item_amount.h4
-rw-r--r--src/gui/npcintegerdialog.cpp62
-rw-r--r--src/gui/npcintegerdialog.h12
-rw-r--r--src/gui/npcstringdialog.cpp2
-rw-r--r--src/gui/textfield.cpp2
-rw-r--r--src/gui/textfield.h1
9 files changed, 79 insertions, 79 deletions
diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextfield.cpp
index 4cb885c3..e8e6e69b 100644
--- a/src/gui/inttextbox.cpp
+++ b/src/gui/inttextfield.cpp
@@ -19,17 +19,19 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "inttextbox.h"
+#include "inttextfield.h"
#include "sdlinput.h"
#include "../utils/tostring.h"
-IntTextBox::IntTextBox(int i):
- mValue(i)
+IntTextField::IntTextField(int def):
+ TextField(toString(def)),
+ mDefault(def),
+ mValue(def)
{
}
-void IntTextBox::keyPressed(gcn::KeyEvent &event)
+void IntTextField::keyPressed(gcn::KeyEvent &event)
{
const gcn::Key &key = event.getKey();
@@ -40,32 +42,43 @@ void IntTextBox::keyPressed(gcn::KeyEvent &event)
event.consume();
}
- if (!key.isNumber()) return;
+ if (!key.isNumber())
+ return;
+
TextField::keyPressed(event);
std::istringstream s(getText());
int i;
s >> i;
- setInt(i);
+ setValue(i);
}
-void IntTextBox::setRange(int min, int max)
+void IntTextField::setRange(int min, int max)
{
mMin = min;
mMax = max;
}
-int IntTextBox::getInt()
+int IntTextField::getValue()
{
return getText().empty() ? mMin : mValue;
}
-void IntTextBox::setInt(int i)
+void IntTextField::setValue(int i)
{
if (i >= mMin && i <= mMax)
mValue = i;
+ else if (i < mMin)
+ mValue = mMin;
+ else if (i > mMax)
+ mValue = mMax;
const std::string valStr = toString(mValue);
setText(valStr);
setCaretPosition(valStr.length() + 1);
}
+
+void IntTextField::reset()
+{
+ setValue(mDefault);
+}
diff --git a/src/gui/inttextbox.h b/src/gui/inttextfield.h
index d134fcd7..3f9cd7ad 100644
--- a/src/gui/inttextbox.h
+++ b/src/gui/inttextfield.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef INTTEXTBOX_H
-#define INTTEXTBOX_H
+#ifndef INTTEXTFIELD_H
+#define INTTEXTFIELD_H
#include "textfield.h"
@@ -29,13 +29,13 @@
/**
* TextBox which only accepts numbers as input.
*/
-class IntTextBox : public TextField
+class IntTextField : public TextField
{
public:
/**
- * Constructor, sets initial value.
+ * Constructor, sets default value.
*/
- IntTextBox(int value=0);
+ IntTextField(int def = 0);
/**
* Sets the minimum and maximum values of the text box.
@@ -45,12 +45,17 @@ class IntTextBox : public TextField
/**
* Returns the value in the text box.
*/
- int getInt();
+ int getValue();
+
+ /**
+ * Reset the field to the default value.
+ */
+ void reset();
/**
* Set the value of the text box to the specified value.
*/
- void setInt(int value);
+ void setValue(int value);
/**
* Responds to key presses.
@@ -60,6 +65,7 @@ class IntTextBox : public TextField
private:
int mMin; /**< Minimum value */
int mMax; /**< Maximum value */
+ int mDefault; /**< Default value */
int mValue; /**< Current value */
};
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 48b0e601..03b22fa9 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -20,7 +20,7 @@
*/
#include "button.h"
-#include "inttextbox.h"
+#include "inttextfield.h"
#include "item_amount.h"
#include "slider.h"
#include "trade.h"
@@ -39,11 +39,11 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
const int maxRange = mItem->getQuantity();
// Integer field
- mItemAmountTextBox = new IntTextBox(1);
- mItemAmountTextBox->setRange(1, maxRange);
- mItemAmountTextBox->setWidth(30);
- mItemAmountTextBox->setActionEventId("Dummy");
- mItemAmountTextBox->addActionListener(this);
+ mItemAmountTextField = new IntTextField(1);
+ mItemAmountTextField->setRange(1, maxRange);
+ mItemAmountTextField->setWidth(30);
+ mItemAmountTextField->setActionEventId("Dummy");
+ mItemAmountTextField->addActionListener(this);
// Slider
mItemAmountSlide = new Slider(1.0, maxRange);
@@ -61,7 +61,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
// Set positions
place(0, 0, minusButton);
- place(1, 0, mItemAmountTextBox).setPadding(2);
+ place(1, 0, mItemAmountTextField).setPadding(2);
place(2, 0, plusButton);
place(0, 1, mItemAmountSlide, 6);
place(4, 2, okButton);
@@ -89,12 +89,12 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
void ItemAmountWindow::resetAmount()
{
- mItemAmountTextBox->setInt(1);
+ mItemAmountTextField->setValue(1);
}
void ItemAmountWindow::action(const gcn::ActionEvent &event)
{
- int amount = mItemAmountTextBox->getInt();
+ int amount = mItemAmountTextField->getValue();
if (event.getId() == "Cancel")
{
@@ -114,14 +114,14 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "Drop")
{
- player_node->dropItem(mItem, mItemAmountTextBox->getInt());
+ player_node->dropItem(mItem, mItemAmountTextField->getValue());
scheduleDelete();
}
else if (event.getId() == "AddTrade")
{
- tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt());
+ tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue());
scheduleDelete();
}
- mItemAmountTextBox->setInt(amount);
+ mItemAmountTextField->setValue(amount);
mItemAmountSlide->setValue(amount);
}
diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h
index 2005094d..08852c8f 100644
--- a/src/gui/item_amount.h
+++ b/src/gui/item_amount.h
@@ -30,7 +30,7 @@
#include "../guichanfwd.h"
-class IntTextBox;
+class IntTextField;
class Item;
#define AMOUNT_TRADE_ADD 1
@@ -60,7 +60,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener
void resetAmount();
private:
- IntTextBox *mItemAmountTextBox; /**< Item amount caption. */
+ IntTextField *mItemAmountTextField; /**< Item amount caption. */
Item *mItem;
/**
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));
-}
diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h
index a45d57c4..c1bdffe1 100644
--- a/src/gui/npcintegerdialog.h
+++ b/src/gui/npcintegerdialog.h
@@ -32,6 +32,8 @@
#include "../guichanfwd.h"
+class IntTextField;
+
/**
* The npc integer input dialog.
*
@@ -53,9 +55,6 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener,
*/
void action(const gcn::ActionEvent &event);
- /** Called when key is pressed */
- void keyPressed(gcn::KeyEvent &event);
-
/**
* Returns the current value.
*/
@@ -65,18 +64,17 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener,
* Prepares the NPC dialog.
*
* @param min The minimum value to allow
- * @param def The default value
* @param max The maximum value to allow
*/
- void prepDialog(const int min, const int def, const int max);
+ void setRange(const int min, const int max);
private:
- int mMin, mMax, mDefault, mValue;
gcn::Button *mDecButton;
gcn::Button *mIncButton;
- gcn::TextField *mValueField;
+ IntTextField *mValueField;
gcn::Button *okButton;
gcn::Button *cancelButton;
+ gcn::Button *resetButton;
};
#endif // _TMW_GUI_NPCINTEGERDIALOG_H
diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp
index 6bca961c..53f200b0 100644
--- a/src/gui/npcstringdialog.cpp
+++ b/src/gui/npcstringdialog.cpp
@@ -37,7 +37,7 @@
NpcStringDialog::NpcStringDialog():
Window(_("NPC Text Request"))
{
- mValueField = new TextField("The Mana World"); // Just a sizing value :)
+ mValueField = new TextField("");
okButton = new Button(_("OK"), "ok", this);
cancelButton = new Button(_("Cancel"), "cancel", this);
diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp
index 0146fd4a..80e3bbcf 100644
--- a/src/gui/textfield.cpp
+++ b/src/gui/textfield.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "textfield.h"
-
#include <algorithm>
#include <guichan/font.hpp>
diff --git a/src/gui/textfield.h b/src/gui/textfield.h
index 38150b83..3235e3f6 100644
--- a/src/gui/textfield.h
+++ b/src/gui/textfield.h
@@ -27,7 +27,6 @@
#include "../guichanfwd.h"
class ImageRect;
-
class TextField;
class TextFieldListener