summaryrefslogtreecommitdiff
path: root/src/gui/npc.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 11:33:17 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 11:33:17 +0000
commitce2813cb1f4988669422c6af3e8c4442776e45c8 (patch)
tree098177c279f5376bd27d4db30f913f6e61471537 /src/gui/npc.cpp
parent5acb9213cc2ee949a252a5c08a9a9a13542b94d5 (diff)
downloadmana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.gz
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.bz2
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.xz
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.zip
Added garbage collection to the ScrollArea class. Fixed slider not being updated in the item amount box when the buttons are used.
Diffstat (limited to 'src/gui/npc.cpp')
-rw-r--r--src/gui/npc.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index 2729d816..de491b73 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -23,6 +23,8 @@
#include "npc.h"
+#include <sstream>
+
#include "button.h"
#include "scrollarea.h"
#include "listbox.h"
@@ -35,10 +37,10 @@
NpcListDialog::NpcListDialog():
Window("NPC")
{
- itemList = new ListBox(this);
- scrollArea = new ScrollArea(itemList);
- okButton = new Button("OK");
- cancelButton = new Button("Cancel");
+ mItemList = new ListBox(this);
+ ScrollArea *scrollArea = new ScrollArea(mItemList);
+ Button *okButton = new Button("OK");
+ Button *cancelButton = new Button("Cancel");
setContentSize(260, 175);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -51,11 +53,11 @@ NpcListDialog::NpcListDialog():
cancelButton->getX() - 5 - okButton->getWidth(),
cancelButton->getY());
- itemList->setEventId("item");
+ mItemList->setEventId("item");
okButton->setEventId("ok");
cancelButton->setEventId("cancel");
- itemList->addActionListener(this);
+ mItemList->addActionListener(this);
okButton->addActionListener(this);
cancelButton->addActionListener(this);
@@ -66,11 +68,6 @@ NpcListDialog::NpcListDialog():
setLocationRelativeTo(getParent());
}
-NpcListDialog::~NpcListDialog()
-{
- delete itemList;
-}
-
int
NpcListDialog::getNumberOfElements()
{
@@ -86,16 +83,12 @@ NpcListDialog::getElementAt(int i)
void
NpcListDialog::parseItems(const std::string &itemString)
{
- char *copy = new char[itemString.length() + 1];
- strcpy(copy, itemString.c_str());
+ std::istringstream iss(itemString);
- char *token = strtok(copy, ":");
- while (token) {
- items.push_back(token);
- token = strtok(NULL, ":");
+ std::string tmp;
+ while(getline(iss, tmp, ':')) {
+ items.push_back(tmp);
}
-
- delete[] copy;
}
void
@@ -108,11 +101,11 @@ void
NpcListDialog::action(const std::string& eventId)
{
int choice = 0;
-
+
if (eventId == "ok")
{
// Send the selected index back to the server
- int selectedIndex = itemList->getSelected();
+ int selectedIndex = mItemList->getSelected();
if (selectedIndex > -1)
{
choice = selectedIndex + 1;
@@ -122,7 +115,7 @@ NpcListDialog::action(const std::string& eventId)
{
choice = 0xff; // 0xff means cancel
}
-
+
if (choice)
{
MessageOut outMsg;