diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/npc.cpp | 8 | ||||
-rw-r--r-- | src/gui/npc.h | 9 | ||||
-rw-r--r-- | src/gui/npc_text.cpp | 75 | ||||
-rw-r--r-- | src/gui/npc_text.h | 78 | ||||
-rw-r--r-- | src/gui/passwordfield.cpp | 2 | ||||
-rw-r--r-- | src/gui/slider.cpp | 1 | ||||
-rw-r--r-- | src/gui/textfield.cpp | 2 | ||||
-rw-r--r-- | src/gui/window.cpp | 27 |
8 files changed, 178 insertions, 24 deletions
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp index d206010e..80d55c73 100644 --- a/src/gui/npc.cpp +++ b/src/gui/npc.cpp @@ -54,6 +54,14 @@ NpcListDialog::NpcListDialog(gcn::Container *parent): setLocationRelativeTo(getParent()); } +NpcListDialog::~NpcListDialog() +{ + delete okButton; + delete cancelButton; + delete itemList; + delete scrollArea; +} + int NpcListDialog::getNumberOfElements() { return items.size(); diff --git a/src/gui/npc.h b/src/gui/npc.h index acc91173..d0810201 100644 --- a/src/gui/npc.h +++ b/src/gui/npc.h @@ -21,8 +21,8 @@ * $Id$ */ -#ifndef _NPC_H -#define _NPC_H +#ifndef _TMW_NPC_H +#define _TMW_NPC_H #include <guichan.hpp> #include <vector> @@ -46,6 +46,11 @@ class NpcListDialog : public Window, public gcn::ActionListener, NpcListDialog(gcn::Container *parent); /** + * Destructor. + */ + ~NpcListDialog(); + + /** * Called when receiving actions from the widgets. */ void action(const std::string& eventId); diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp new file mode 100644 index 00000000..38c29688 --- /dev/null +++ b/src/gui/npc_text.cpp @@ -0,0 +1,75 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "npc_text.h" +#include "scrollarea.h" +#include "button.h" +#include "../game.h" + +NpcTextDialog::NpcTextDialog(gcn::Container *parent): + Window(parent, "NPC") +{ + textBox = new gcn::TextBox(); + textBox->setEditable(false); + scrollArea = new ScrollArea(textBox); + okButton = new Button("OK"); + + setSize(260, 175); + scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 130)); + okButton->setPosition(260 - 10 - okButton->getWidth(), 145); + + okButton->setEventId("ok"); + okButton->addActionListener(this); + + add(scrollArea); + add(okButton); + + setLocationRelativeTo(getParent()); +} + +NpcTextDialog::~NpcTextDialog() +{ + delete okButton; + delete textBox; + delete scrollArea; +} + +void NpcTextDialog::setText(const char *text) +{ + textBox->setText(std::string(text)); +} + +void NpcTextDialog::addText(const char *text) +{ + textBox->setText( + textBox->getText() + std::string(text) + std::string("\n")); +} + +void NpcTextDialog::action(const std::string& eventId) +{ + WFIFOW(0) = net_w_value(0x00b9); + WFIFOL(2) = net_l_value(current_npc); + WFIFOSET(6); + setText(""); + setVisible(false); +} diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h new file mode 100644 index 00000000..6bb7d943 --- /dev/null +++ b/src/gui/npc_text.h @@ -0,0 +1,78 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_NPC_TEXT_H +#define _TMW_NPC_TEXT_H + +#include <guichan.hpp> +#include <vector> +#include <string> +#include "window.h" + +/** + * The npc text dialog. + * + * \ingroup GUI + */ +class NpcTextDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + NpcTextDialog(gcn::Container *parent); + + /** + * Destructor. + */ + ~NpcTextDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const std::string& eventId); + + /** + * Sets the text shows in the dialog. + * + * @param string The new text. + */ + void setText(const char *string); + + /** + * Adds the text to the text shows in the dialog. Also adds a newline + * to the end. + * + * @param string The text to add. + */ + void addText(const char *string); + + private: + gcn::Button *okButton; + gcn::TextBox *textBox; + gcn::ScrollArea *scrollArea; +}; + +#endif diff --git a/src/gui/passwordfield.cpp b/src/gui/passwordfield.cpp index ee849c45..aa5c3141 100644 --- a/src/gui/passwordfield.cpp +++ b/src/gui/passwordfield.cpp @@ -32,7 +32,7 @@ PasswordField::PasswordField(const std::string& text): void PasswordField::draw(gcn::Graphics *graphics) { - int x, y, w, h, col; + int x, y, w, h; getAbsolutePosition(x, y); w = getWidth(); h = getHeight(); diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index 612d2e2e..11254f09 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -65,7 +65,6 @@ void Slider::draw(gcn::Graphics *graphics) void Slider::drawMarker(gcn::Graphics *graphics) { - int w = getWidth(); int h = getHeight(); int x, y; getAbsolutePosition(x, y); diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 3479355d..4022ca2d 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -33,7 +33,7 @@ TextField::TextField(const std::string& text): void TextField::draw(gcn::Graphics *graphics) { - int x, y, w, h, col; + int x, y, w, h; getAbsolutePosition(x, y); w = getWidth(); h = getHeight(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 4d386071..632ad303 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -172,9 +172,6 @@ void Window::add(Widget *w, int x, int y) void Window::mousePress(int mx, int my, int button) { - int x = this->getDimension().x; - int y = this->getDimension().y; - mouseDown = true; mousePX = mx; @@ -199,24 +196,16 @@ void Window::mouseMotion(int mx, int my) y = y - (mousePY - my); // Keep guichan window inside window - if (x < 0) - x = 0; - if (y < 0) - y = 0; - if (x + winWidth > 799) - x = 799 - winWidth; - if (y + winHeight > 599) - y = 599 - winHeight; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (x + winWidth > 799) x = 799 - winWidth; + if (y + winHeight > 599) y = 599 - winHeight; // Snap window to edges - if (x < snapSize) - x = 0; - if (y < snapSize) - y = 0; - if (x + winWidth + snapSize > 799) - x = 799 - winWidth; - if (y + winHeight + snapSize > 599) - y = 599 - winHeight; + if (x < snapSize) x = 0; + if (y < snapSize) y = 0; + if (x + winWidth + snapSize > 799) x = 799 - winWidth; + if (y + winHeight + snapSize > 599) y = 599 - winHeight; this->setPosition(x, y); } |