00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/npcintegerdialog.h"
00023
00024 #include "gui/npc_text.h"
00025
00026 #include "gui/widgets/button.h"
00027 #include "gui/widgets/inttextfield.h"
00028 #include "gui/widgets/layout.h"
00029
00030 #include "npc.h"
00031
00032 #include "net/net.h"
00033 #include "net/npchandler.h"
00034
00035 #include "utils/gettext.h"
00036 #include "utils/strprintf.h"
00037
00038 NpcIntegerDialog::NpcIntegerDialog()
00039 : Window(_("NPC Number Request"))
00040 {
00041 setWindowName("NPCInteger");
00042 mValueField = new IntTextField;
00043
00044 setDefaultSize(175, 75, ImageRect::CENTER);
00045
00046 mDecButton = new Button("-", "decvalue", this);
00047 mIncButton = new Button("+", "incvalue", this);
00048 gcn::Button *okButton = new Button(_("OK"), "ok", this);
00049 gcn::Button *cancelButton = new Button(_("Cancel"), "cancel", this);
00050 gcn::Button *resetButton = new Button(_("Reset"), "reset", this);
00051
00052 mDecButton->adjustSize();
00053 mDecButton->setWidth(mIncButton->getWidth());
00054
00055 ContainerPlacer place;
00056 place = getPlacer(0, 0);
00057
00058 place(0, 0, mDecButton);
00059 place(1, 0, mValueField, 3);
00060 place(4, 0, mIncButton);
00061 place.getCell().matchColWidth(1, 0);
00062 place = getPlacer(0, 1);
00063 place(0, 0, resetButton);
00064 place(2, 0, cancelButton);
00065 place(3, 0, okButton);
00066 reflowLayout(175, 0);
00067
00068 center();
00069 setDefaultSize();
00070 loadWindowState();
00071 }
00072
00073 void NpcIntegerDialog::setRange(int min, int max)
00074 {
00075 mValueField->setRange(min, max);
00076 }
00077
00078 int NpcIntegerDialog::getValue()
00079 {
00080 return mValueField->getValue();
00081 }
00082
00083 void NpcIntegerDialog::reset()
00084 {
00085 mValueField->reset();
00086 }
00087
00088 void NpcIntegerDialog::action(const gcn::ActionEvent &event)
00089 {
00090 bool finish = false;
00091
00092 if (event.getId() == "ok")
00093 {
00094 finish = true;
00095 npcTextDialog->addText(strprintf("\n> %d\n", mValueField->getValue()));
00096 }
00097 else if (event.getId() == "cancel")
00098 {
00099 finish = true;
00100 mValueField->reset();
00101 npcTextDialog->addText(_("\n> Cancel\n"));
00102 }
00103 else if (event.getId() == "decvalue")
00104 {
00105 mValueField->setValue(mValueField->getValue() - 1);
00106 }
00107 else if (event.getId() == "incvalue")
00108 {
00109 mValueField->setValue(mValueField->getValue() + 1);
00110 }
00111 else if (event.getId() == "reset")
00112 {
00113 mValueField->reset();
00114 }
00115
00116 if (finish)
00117 {
00118 setVisible(false);
00119 NPC::isTalking = false;
00120
00121 Net::getNpcHandler()->integerInput(current_npc, mValueField->getValue());
00122
00123 mValueField->reset();
00124 }
00125 }
00126
00127 void NpcIntegerDialog::setDefaultValue(int value)
00128 {
00129 mValueField->setDefaultValue(value);
00130 }
00131
00132 bool NpcIntegerDialog::isInputFocused()
00133 {
00134 return mValueField->isFocused();
00135 }
00136
00137 void NpcIntegerDialog::requestFocus()
00138 {
00139 mValueField->requestFocus();
00140 }
00141
00142 void NpcIntegerDialog::setVisible(bool visible)
00143 {
00144 if (visible) {
00145 npcTextDialog->setVisible(true);
00146 requestFocus();
00147 }
00148
00149 Window::setVisible(visible);
00150 }