summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/game.cpp22
-rw-r--r--src/gui/inttextfield.cpp (renamed from src/gui/inttextbox.cpp)32
-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/net/npchandler.cpp2
-rw-r--r--tmw.cbp4
12 files changed, 107 insertions, 85 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d7127801..70a58272 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -95,8 +95,8 @@ SET(SRCS
gui/gui.h
gui/help.cpp
gui/help.h
- gui/inttextbox.cpp
- gui/inttextbox.h
+ gui/inttextfield.cpp
+ gui/inttextfield.h
gui/inventorywindow.cpp
gui/inventorywindow.h
gui/itemcontainer.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 97b62dd9..358b0b61 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,8 +47,8 @@ tmw_SOURCES = gui/widgets/layout.cpp \
gui/gui.h \
gui/help.cpp \
gui/help.h \
- gui/inttextbox.h \
- gui/inttextbox.cpp \
+ gui/inttextfield.h \
+ gui/inttextfield.cpp \
gui/inventorywindow.cpp \
gui/inventorywindow.h \
gui/itemcontainer.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 1b6f2d5c..6cd94760 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -627,6 +627,26 @@ void Game::handleInput()
{
setupWindow->action(gcn::ActionEvent(NULL, "cancel"));
}
+ // Submits the text and proceeds to the next dialog
+ else if (npcStringDialog->isVisible())
+ {
+ npcStringDialog->action(gcn::ActionEvent(NULL, "ok"));
+ }
+ // Proceed to the next dialog option, or close the window
+ else if (npcTextDialog->isVisible())
+ {
+ npcTextDialog->action(gcn::ActionEvent(NULL, "ok"));
+ }
+ // Choose the currently highlighted dialogue option
+ else if (npcListDialog->isVisible())
+ {
+ npcListDialog->action(gcn::ActionEvent(NULL, "ok"));
+ }
+ // Submits the text and proceeds to the next dialog
+ else if (npcIntegerDialog->isVisible())
+ {
+ npcIntegerDialog->action(gcn::ActionEvent(NULL, "ok"));
+ }
// Else, open the chat edit box
else
{
@@ -634,7 +654,7 @@ void Game::handleInput()
used = true;
}
break;
- // Quitting confirmation dialog
+ // Quitting confirmation dialog
case SDLK_ESCAPE:
if (!exitConfirm) {
exitConfirm = new ConfirmDialog(
diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextfield.cpp
index a995f084..5d668ccc 100644
--- a/src/gui/inttextbox.cpp
+++ b/src/gui/inttextfield.cpp
@@ -19,19 +19,20 @@
* 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();
@@ -42,32 +43,43 @@ 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 8dad0c39..ab301141 100644
--- a/src/gui/inttextbox.h
+++ b/src/gui/inttextfield.h
@@ -19,21 +19,21 @@
* 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"
/**
* 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.
@@ -43,12 +43,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.
@@ -59,6 +64,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 17c3243a..cd6c6937 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -22,7 +22,7 @@
#include "item_amount.h"
#include "button.h"
-#include "inttextbox.h"
+#include "inttextfield.h"
#include "slider.h"
#include "trade.h"
@@ -40,11 +40,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);
@@ -62,7 +62,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);
@@ -90,12 +90,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")
{
@@ -115,14 +115,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/net/npchandler.cpp b/src/net/npchandler.cpp
index d8763f43..6355df7a 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -89,7 +89,7 @@ void NPCHandler::handleMessage(MessageIn *msg)
// Request for an integer
id = msg->readInt32();
current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id));
- npcIntegerDialog->prepDialog(0, 0, 2147483647);
+ npcIntegerDialog->setRange(0, 2147483647);
npcIntegerDialog->setVisible(true);
break;
diff --git a/tmw.cbp b/tmw.cbp
index c7d37951..7275627b 100644
--- a/tmw.cbp
+++ b/tmw.cbp
@@ -136,8 +136,8 @@
<Unit filename="src\gui\gui.h" />
<Unit filename="src\gui\help.cpp" />
<Unit filename="src\gui\help.h" />
- <Unit filename="src\gui\inttextbox.cpp" />
- <Unit filename="src\gui\inttextbox.h" />
+ <Unit filename="src\gui\inttextfield.cpp" />
+ <Unit filename="src\gui\inttextfield.h" />
<Unit filename="src\gui\inventorywindow.cpp" />
<Unit filename="src\gui\inventorywindow.h" />
<Unit filename="src\gui\item_amount.cpp" />