diff options
author | David Athay <ko2fan@gmail.com> | 2009-01-18 19:41:16 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2009-01-18 19:41:16 +0000 |
commit | 93f60007c1b5c203b71d32551278351385ea2bee (patch) | |
tree | 1983f0da9de01b94e7c616e1efd530360c650729 | |
parent | 224da21ea258450fcc78dd7635de84aba1d1df5e (diff) | |
parent | ccef6c4284a9cc250da72c5835501ae03c2c513f (diff) | |
download | mana-93f60007c1b5c203b71d32551278351385ea2bee.tar.gz mana-93f60007c1b5c203b71d32551278351385ea2bee.tar.bz2 mana-93f60007c1b5c203b71d32551278351385ea2bee.tar.xz mana-93f60007c1b5c203b71d32551278351385ea2bee.zip |
Merge branch 'master' of git://gitorious.org/tmw/eathena
27 files changed, 863 insertions, 174 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 1ca4ee72..4065e939 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -29,6 +29,8 @@ SET (FILES rpgfont_wider.png selection.png slider.png + tab.png + tabselected.png target-cursor-blue-l.png target-cursor-blue-m.png target-cursor-blue-s.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 0b7824c9..4cc5b569 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -33,6 +33,8 @@ gui_DATA = \ rpgfont_wider.png \ selection.png \ slider.png \ + tab.png \ + tabselected.png \ target-cursor-blue-l.png \ target-cursor-blue-m.png \ target-cursor-blue-s.png \ diff --git a/data/graphics/gui/tab.png b/data/graphics/gui/tab.png Binary files differnew file mode 100644 index 00000000..91eadf08 --- /dev/null +++ b/data/graphics/gui/tab.png diff --git a/data/graphics/gui/tabselected.png b/data/graphics/gui/tabselected.png Binary files differnew file mode 100644 index 00000000..e2983060 --- /dev/null +++ b/data/graphics/gui/tabselected.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27d1e1d8..f87b6c8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,10 @@ SET(SRCS gui/widgets/resizegrip.h gui/widgets/layout.cpp gui/widgets/layout.h + gui/widgets/tab.cpp + gui/widgets/tab.h + gui/widgets/tabbedarea.cpp + gui/widgets/tabbedarea.h gui/browserbox.cpp gui/browserbox.h gui/buddywindow.cpp @@ -112,8 +116,12 @@ SET(SRCS gui/minimap.h gui/ministatus.cpp gui/ministatus.h + gui/npcintegerdialog.cpp + gui/npcintegerdialog.h gui/npclistdialog.cpp gui/npclistdialog.h + gui/npcstringdialog.cpp + gui/npcstringdialog.h gui/npc_text.cpp gui/npc_text.h gui/ok_dialog.cpp @@ -159,8 +167,6 @@ SET(SRCS gui/slider.h gui/status.cpp gui/status.h - gui/tabbedcontainer.cpp - gui/tabbedcontainer.h gui/table.cpp gui/table.h gui/table_model.cpp diff --git a/src/Makefile.am b/src/Makefile.am index d882f426..2936849a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,10 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/widgets/tab.cpp \ + gui/widgets/tab.h \ + gui/widgets/tabbedarea.cpp \ + gui/widgets/tabbedarea.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -64,8 +68,12 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/minimap.h \ gui/ministatus.cpp \ gui/ministatus.h \ + gui/npcintegerdialog.cpp \ + gui/npcintegerdialog.h \ gui/npclistdialog.cpp \ gui/npclistdialog.h \ + gui/npcstringdialog.cpp \ + gui/npcstringdialog.h \ gui/npc_text.cpp \ gui/npc_text.h \ gui/ok_dialog.cpp \ @@ -113,8 +121,6 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/slider.h \ gui/status.cpp \ gui/status.h \ - gui/tabbedcontainer.cpp \ - gui/tabbedcontainer.h \ gui/table.h \ gui/table.cpp \ gui/table_model.h \ diff --git a/src/game.cpp b/src/game.cpp index a788c51a..1b6f2d5c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -55,7 +55,9 @@ #include "gui/menuwindow.h" #include "gui/minimap.h" #include "gui/ministatus.h" +#include "gui/npcintegerdialog.h" #include "gui/npclistdialog.h" +#include "gui/npcstringdialog.h" #include "gui/npc_text.h" #include "gui/ok_dialog.h" #include "gui/sdlinput.h" @@ -107,8 +109,10 @@ BuyDialog *buyDialog; SellDialog *sellDialog; BuySellDialog *buySellDialog; InventoryWindow *inventoryWindow; +NpcIntegerDialog *npcIntegerDialog; NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; +NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; Setup* setupWindow; Minimap *minimap; @@ -187,7 +191,9 @@ void createGuiWindows(Network *network) buySellDialog = new BuySellDialog(); inventoryWindow = new InventoryWindow(); npcTextDialog = new NpcTextDialog(); + npcIntegerDialog = new NpcIntegerDialog(); npcListDialog = new NpcListDialog(); + npcStringDialog = new NpcStringDialog(); skillDialog = new SkillDialog(); setupWindow = new Setup(); minimap = new Minimap(); @@ -237,8 +243,10 @@ void destroyGuiWindows() delete sellDialog; delete buySellDialog; delete inventoryWindow; + delete npcIntegerDialog; delete npcListDialog; delete npcTextDialog; + delete npcStringDialog; delete skillDialog; delete setupWindow; delete minimap; @@ -643,7 +651,8 @@ void Game::handleInput() default: break; } - if (keyboard.isEnabled() && !chatWindow->isInputFocused()) + if (keyboard.isEnabled() && !chatWindow->isInputFocused() + && !npcStringDialog->isInputFocused()) { const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); // Do not activate shortcuts if tradewindow is visible diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp new file mode 100644 index 00000000..f5b6ac5b --- /dev/null +++ b/src/gui/npcintegerdialog.cpp @@ -0,0 +1,125 @@ +/* + * 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 + */ + +#include "npcintegerdialog.h" + +#include <limits> +#include <sstream> + +#include "button.h" +#include "textfield.h" + +#include "../npc.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" + +#include "widgets/layout.h" + +NpcIntegerDialog::NpcIntegerDialog(): + Window(_("NPC Number Request")) +{ + mDecButton = new Button("-", "decvalue", this); + mIncButton = new Button("+", "incvalue", this); + mValueField = new TextField(); + okButton = new Button(_("OK"), "ok", this); + cancelButton = new Button(_("Cancel"), "cancel", this); + + mDecButton->setSize(20, 20); + mIncButton->setSize(20, 20); + + place(0, 0, mDecButton); + place(1, 0, mValueField, 3); + place(4, 0, mIncButton); + place(2, 1, okButton); + place(3, 1, cancelButton, 2); + reflowLayout(175, 0); + + setLocationRelativeTo(getParent()); + + mValueField->setActionEventId("valuefield"); + mValueField->addKeyListener(this); +} + +void NpcIntegerDialog::prepDialog(const int min, const int def, const int max) +{ + mMin = min; + mMax = max; + mDefault = def; + mValue = def; + + mValueField->setText(toString(mValue)); +} + +int NpcIntegerDialog::getValue() +{ + return mValue; +} + +void NpcIntegerDialog::action(const gcn::ActionEvent &event) +{ + int finish = 0; + + if (event.getId() == "ok") + { + finish = 1; + } + else if (event.getId() == "cancel") + { + finish = 1; + mValue = mDefault; + } + else if (event.getId() == "decvalue" && mValue < mMin) + { + mValue--; + } + else if (event.getId() == "incvalue" && mValue > mMax) + { + mValue++; + } + + mValueField->setText(toString(mValue)); + + if (finish) + { + setVisible(false); + current_npc->integerInput(mValue); + 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 new file mode 100644 index 00000000..a45d57c4 --- /dev/null +++ b/src/gui/npcintegerdialog.h @@ -0,0 +1,82 @@ +/* + * 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 + */ + +#ifndef _TMW_GUI_NPCINTEGERDIALOG_H +#define _TMW_GUI_NPCINTEGERDIALOG_H + +#include <iosfwd> +#include <vector> + +#include <guichan/actionlistener.hpp> +#include <guichan/keylistener.hpp> + +#include "window.h" + +#include "../guichanfwd.h" + +/** + * The npc integer input dialog. + * + * \ingroup Interface + */ +class NpcIntegerDialog : public Window, public gcn::ActionListener, + public gcn::KeyListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + NpcIntegerDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** Called when key is pressed */ + void keyPressed(gcn::KeyEvent &event); + + /** + * Returns the current value. + */ + int getValue(); + + /** + * 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); + + private: + int mMin, mMax, mDefault, mValue; + gcn::Button *mDecButton; + gcn::Button *mIncButton; + gcn::TextField *mValueField; + gcn::Button *okButton; + gcn::Button *cancelButton; +}; + +#endif // _TMW_GUI_NPCINTEGERDIALOG_H diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp new file mode 100644 index 00000000..6bca961c --- /dev/null +++ b/src/gui/npcstringdialog.cpp @@ -0,0 +1,77 @@ +/* + * 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 + */ + +#include "npcstringdialog.h" + +#include <limits> +#include <sstream> + +#include "button.h" +#include "textfield.h" + +#include "../npc.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" + +#include "widgets/layout.h" + +NpcStringDialog::NpcStringDialog(): + Window(_("NPC Text Request")) +{ + mValueField = new TextField("The Mana World"); // Just a sizing value :) + okButton = new Button(_("OK"), "ok", this); + cancelButton = new Button(_("Cancel"), "cancel", this); + + place(0, 0, mValueField, 3); + place(1, 1, okButton); + place(2, 1, cancelButton); + reflowLayout(175, 0); + + setLocationRelativeTo(getParent()); +} + +std::string NpcStringDialog::getValue() +{ + return mValueField->getText(); +} + +void NpcStringDialog::setValue(const std::string &value) +{ + mValueField->setText(value); +} + +void NpcStringDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "cancel") + { + mValueField->setText(""); + } + + setVisible(false); + current_npc->stringInput(mValueField->getText()); + current_npc = 0; +} + +bool NpcStringDialog::isInputFocused() +{ + return mValueField->isFocused(); +} diff --git a/src/gui/tabbedcontainer.h b/src/gui/npcstringdialog.h index babf68a2..22054994 100644 --- a/src/gui/tabbedcontainer.h +++ b/src/gui/npcstringdialog.h @@ -19,47 +19,60 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _TMW_TABPANE_H -#define _TMW_TABPANE_H +#ifndef _TMW_GUI_NPCSTRINGDIALOG_H +#define _TMW_GUI_NPCSTRINGDIALOG_H #include <iosfwd> #include <vector> -#include <map> #include <guichan/actionlistener.hpp> +#include <guichan/keylistener.hpp> -#include <guichan/widgets/container.hpp> +#include "window.h" #include "../guichanfwd.h" -class TabbedContainer : public gcn::Container, public gcn::ActionListener +/** + * The npc integer input dialog. + * + * \ingroup Interface + */ +class NpcStringDialog : public Window, public gcn::ActionListener { public: - TabbedContainer(); - ~TabbedContainer(); - - void addTab(gcn::Widget *widget, const std::string &caption); - - void removeTab(const std::string &caption); - - void logic(); - + /** + * Constructor. + * + * @see Window::Window + */ + NpcStringDialog(); + + /** + * Called when receiving actions from the widgets. + */ void action(const gcn::ActionEvent &event); - void setOpaque(bool opaque); + /** + * Returns the current value. + */ + std::string getValue(); - short getNumberOfTabs(); + /** + * Chnages the current value. + * + * @param value The new value + */ + void setValue(const std::string &value); - std::string getActiveWidget(); + /** + * Checks whether NpcStringDialog is Focused or not. + */ + bool isInputFocused(); private: - typedef std::vector<gcn::Widget*> Widgets; - typedef Widgets::iterator WidgetIterator; - std::map<std::string, gcn::Widget*> mTabs; // tabs mapped to their channel name - Widgets mContents; // The contents of the tabs - - std::map<gcn::Widget*, std::string> mWidgets; - gcn::Widget *mActiveContent; + gcn::TextField *mValueField; + gcn::Button *okButton; + gcn::Button *cancelButton; }; -#endif +#endif // _TMW_GUI_NPCSTRINGDIALOG_H diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 067d8d64..80da120a 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -29,7 +29,8 @@ #include "setup_video.h" #include "setup_keyboard.h" #include "setup_players.h" -#include "tabbedcontainer.h" + +#include "widgets/tabbedarea.h" #include "../utils/dtor.h" #include "../utils/gettext.h" @@ -47,7 +48,7 @@ extern Window *itemShortcutWindow; extern Window *tradeWindow; Setup::Setup(): - Window("Setup") + Window(_("Setup")) { setCloseButton(true); int width = 310; @@ -69,30 +70,29 @@ Setup::Setup(): btn->setEnabled(statusWindow != NULL); } - TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, width, height - 40)); - panel->setOpaque(false); + TabbedArea *panel = new TabbedArea(); + panel->setDimension(gcn::Rectangle(5, 5, 260, 225)); SetupTab *tab; tab = new Setup_Video(); - panel->addTab(tab, _("Video")); + panel->addTab(_("Video"), tab); mTabs.push_back(tab); tab = new Setup_Audio(); - panel->addTab(tab, _("Audio")); + panel->addTab(_("Audio"), tab); mTabs.push_back(tab); tab = new Setup_Joystick(); - panel->addTab(tab, _("Joystick")); + panel->addTab(_("Joystick"), tab); mTabs.push_back(tab); tab = new Setup_Keyboard(); - panel->addTab(tab, _("Keyboard")); + panel->addTab(_("Keyboard"), tab); mTabs.push_back(tab); tab = new Setup_Players(); - panel->addTab(tab, _("Players")); + panel->addTab(_("Players"), tab); mTabs.push_back(tab); add(panel); diff --git a/src/gui/setup.h b/src/gui/setup.h index 5268f725..2142a67d 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -46,7 +46,7 @@ class Setup : public Window, public gcn::ActionListener /** * Destructor. */ - virtual ~Setup(); + ~Setup(); /** * Event handling method. diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index c595edc9..4f09cde0 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -42,6 +42,7 @@ Setup_Audio::Setup_Audio(): mMusicSlider(new Slider(0, 128)) { setOpaque(false); + setDimension(gcn::Rectangle(0, 0, 250, 200)); gcn::Label *sfxLabel = new gcn::Label(_("Sfx volume")); gcn::Label *musicLabel = new gcn::Label(_("Music volume")); diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index a718f87e..9de5be9f 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -38,6 +38,8 @@ Setup_Joystick::Setup_Joystick(): mJoystickEnabled(new CheckBox(_("Enable joystick"))) { setOpaque(false); + setDimension(gcn::Rectangle(0, 0, 250, 200)); + mJoystickEnabled->setPosition(10, 10); mCalibrateLabel->setPosition(10, 25); mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight()); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index de3c0ce1..e4d1af0c 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -74,6 +74,7 @@ Setup_Keyboard::Setup_Keyboard(): { keyboard.setSetupKeyboard(this); setOpaque(false); + setDimension(gcn::Rectangle(0, 0, 250, 200)); refreshKeys(); diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 122f54e1..0f7ba03b 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -221,6 +221,7 @@ Setup_Players::Setup_Players(): mIgnoreActionChoicesBox(new gcn::DropDown(new IgnoreChoicesListModel())) { setOpaque(false); + setDimension(gcn::Rectangle(0, 0, 250, 200)); int table_width = NAME_COLUMN_WIDTH + RELATION_CHOICE_COLUMN_WIDTH; mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index cc39caed..9fb38f13 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -130,6 +130,7 @@ Setup_Video::Setup_Video(): mParticleDetailField(new gcn::Label("")) { setOpaque(false); + setDimension(gcn::Rectangle(0, 0, 250, 200)); ScrollArea *scrollArea = new ScrollArea(mModeList); gcn::Label *alphaLabel = new gcn::Label(_("Gui opacity")); diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp deleted file mode 100644 index 8c23f76f..00000000 --- a/src/gui/tabbedcontainer.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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 - */ - -#include "tabbedcontainer.h" - -#include "button.h" - -#include "../utils/tostring.h" -#include "../utils/dtor.h" - -#define TABWIDTH 60 -#define TABHEIGHT 20 - -TabbedContainer::TabbedContainer(): - mActiveContent(0) -{ -} - -TabbedContainer::~TabbedContainer() -{ - delete_all(mTabs); - mTabs.clear(); - mContents.clear(); -} - -void TabbedContainer::addTab(gcn::Widget *widget, const std::string &caption) -{ - int tabNumber = mTabs.size(); - - Button *tab = new Button(caption, toString(tabNumber), this); - - tab->setSize(TABWIDTH, TABHEIGHT); - add(tab, TABWIDTH * tabNumber, 0); - - mTabs[caption] = tab; - - mContents.push_back(widget); - widget->setPosition(0, TABHEIGHT); - - // If this is the first tab in this container, make it visible - if (!mActiveContent) { - mActiveContent = widget; - add(mActiveContent); - tab->setLogged(true); - } - - mWidgets[widget] = caption; -} - -void TabbedContainer::removeTab(const std::string &caption) -{ - gcn::ActionEvent actionEvent(this, "0"); - action(actionEvent); - remove(mTabs[caption]); - mTabs.erase(caption); -} - -void TabbedContainer::logic() -{ - if (mActiveContent) { - mActiveContent->setSize( - getWidth() - 2 * mActiveContent->getFrameSize(), - getHeight() - TABHEIGHT - 2 * mActiveContent->getFrameSize()); - } - - Container::logic(); -} - -void TabbedContainer::action(const gcn::ActionEvent &event) -{ - int tabNo; - std::stringstream ss(event.getId()); - ss >> tabNo; - - gcn::Widget *newContent = mContents[tabNo]; - - if (newContent) { - if (mActiveContent) { - // Unhighlight old tab - ((Button*)mTabs[mWidgets[mActiveContent]])->setLogged(false); - remove(mActiveContent); - } - mActiveContent = newContent; - // Highlight new tab - ((Button*)mTabs[mWidgets[mActiveContent]])->setLogged(true); - add(newContent); - } -} - -void TabbedContainer::setOpaque(bool opaque) -{ - Container::setOpaque(opaque); -} - -short TabbedContainer::getNumberOfTabs() -{ - return mTabs.size(); -} - -std::string TabbedContainer::getActiveWidget() -{ - return mWidgets[mActiveContent]; -} diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp new file mode 100644 index 00000000..c53ac85c --- /dev/null +++ b/src/gui/widgets/tab.cpp @@ -0,0 +1,130 @@ +/* + * The Mana World + * Copyright 2008 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 + */ + +#include <algorithm> + +#include "tab.h" + +#include "tabbedarea.h" + +#include "../../graphics.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +#include "../../utils/dtor.h" + +int Tab::mInstances = 0; + +enum{ + TAB_STANDARD, // 0 + TAB_HIGHLIGHTED, // 1 + TAB_SELECTED, // 2 + TAB_UNUSED, // 3 + TAB_COUNT // 4 - Must be last. +}; + +struct TabData +{ + char const *file; + int gridX; + int gridY; +}; + +static TabData const data[TAB_COUNT] = { + {"graphics/gui/tab.png", 0, 0}, + {"graphics/gui/tab.png", 9, 4}, + {"graphics/gui/tabselected.png", 16, 19}, + {"graphics/gui/tab.png", 25, 23} +}; + +ImageRect Tab::tabImg[TAB_COUNT]; + +Tab::Tab() : gcn::Tab() +{ + init(); +} + +Tab::~Tab() +{ + mInstances--; + + if (mInstances == 0) + { + for (int mode = 0; mode < TAB_COUNT; mode++) + { + for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>()); + } + } +} + +void Tab::init() +{ + setFrameSize(0); + + if (mInstances == 0) + { + // Load the skin + ResourceManager *resman = ResourceManager::getInstance(); + Image *tab[TAB_COUNT]; + + int a, x, y, mode; + + for (mode = 0; mode < TAB_COUNT; mode++) + { + tab[mode] = resman->getImage(data[mode].file); + a = 0; + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + tabImg[mode].grid[a] = tab[mode]->getSubImage( + data[x].gridX, data[y].gridY, + data[x + 1].gridX - data[x].gridX + 1, + data[y + 1].gridY - data[y].gridY + 1); + a++; + } + } + tab[mode]->decRef(); + } + } + mInstances++; +} + +void Tab::draw(gcn::Graphics *graphics) +{ + int mode; + + // check which type of tab to draw + if (mTabbedArea && mTabbedArea->isTabSelected(this)) + { + mode = TAB_SELECTED; + } + else + { + mode = TAB_STANDARD; + } + + // draw tab + static_cast<Graphics*>(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), tabImg[mode]); + + // draw label + drawChildren(graphics); +} diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h new file mode 100644 index 00000000..42964b0f --- /dev/null +++ b/src/gui/widgets/tab.h @@ -0,0 +1,60 @@ +/* + * The Mana World + * Copyright 2008 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 + */ + +#ifndef _TMW_TAB_H +#define _TMW_TAB_H + +#include <guichan/widgets/tab.hpp> + +class ImageRect; + +/** + * A tab, the same as the guichan tab in 0.8, but extended to allow transparancy + */ +class Tab : public gcn::Tab +{ + public: + /** + * Constructor. + */ + Tab(); + + /** + * Destructor. + */ + ~Tab(); + + /** + * Draw the tabbed area. + */ + void draw(gcn::Graphics *graphics); + + private: + /** Load images if no other instances exist yet */ + void init(); + + static ImageRect tabImg[4]; /**< Tab state graphics */ + static int mInstances; /**< Number of tab instances */ +}; + +#endif + + diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp new file mode 100644 index 00000000..205fdc99 --- /dev/null +++ b/src/gui/widgets/tabbedarea.cpp @@ -0,0 +1,160 @@ +/* + * The Mana World + * Copyright 2008 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 + */ + +#include "tabbedarea.h" +#include "tab.h" + +#include <guichan/widgets/container.hpp> + +TabbedArea::TabbedArea() : gcn::TabbedArea() +{ + mWidgetContainer->setOpaque(false); +} + +int TabbedArea::getNumberOfTabs() +{ + return mTabs.size(); +} + +Tab* TabbedArea::getTab(const std::string &name) +{ + TabContainer::iterator itr = mTabs.begin(), itr_end = mTabs.end(); + while (itr != itr_end) + { + if ((*itr).first->getCaption() == name) + { + return static_cast<Tab*>((*itr).first); + } + ++itr; + } + return NULL; +} + +void TabbedArea::draw(gcn::Graphics *graphics) +{ + if (mTabs.empty()) + { + return; + } + + drawChildren(graphics); +} + +gcn::Widget* TabbedArea::getWidget(const std::string &name) +{ + TabContainer::iterator itr = mTabs.begin(), itr_end = mTabs.end(); + while (itr != itr_end) + { + if ((*itr).first->getCaption() == name) + { + return (*itr).second; + } + ++itr; + } + + return NULL; +} + +void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget) +{ + Tab* tab = new Tab(); + tab->setCaption(caption); + mTabsToDelete.push_back(tab); + + addTab(tab, widget); +} + +void TabbedArea::addTab(Tab *tab, gcn::Widget *widget) +{ + tab->setTabbedArea(this); + tab->addActionListener(this); + + mTabContainer->add(tab); + mTabs.push_back(std::pair<Tab*, gcn::Widget*>(tab, widget)); + + if (mSelectedTab == NULL) + { + setSelectedTab(tab); + } + + adjustTabPositions(); + adjustSize(); +} + +void TabbedArea::removeTab(Tab *tab) +{ + int tabIndexToBeSelected = 0; + + if (tab == mSelectedTab) + { + int index = getSelectedTabIndex(); + + if (index == (int)mTabs.size() - 1 + && mTabs.size() == 1) + { + tabIndexToBeSelected = -1; + } + else + { + tabIndexToBeSelected = index - 1; + } + } + + TabContainer::iterator iter; + for (iter = mTabs.begin(); iter != mTabs.end(); iter++) + { + if (iter->first == tab) + { + mTabContainer->remove(tab); + mTabs.erase(iter); + break; + } + } + + std::vector<gcn::Tab*>::iterator iter2; + for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) + { + if (*iter2 == tab) + { + mTabsToDelete.erase(iter2); + delete tab; + break; + } + } + + if (tabIndexToBeSelected == -1) + { + mSelectedTab = NULL; + mWidgetContainer->clear(); + } + else + { + setSelectedTab(tabIndexToBeSelected); + } + + adjustSize(); + adjustTabPositions(); +} + +void TabbedArea::logic() +{ + logicChildren(); +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h new file mode 100644 index 00000000..2199264b --- /dev/null +++ b/src/gui/widgets/tabbedarea.h @@ -0,0 +1,92 @@ +/* + * The Mana World + * Copyright 2008 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 + */ + +#ifndef _TMW_TABBEDAREA_H +#define _TMW_TABBEDAREA_H + +#include <guichan/widget.hpp> +#include <guichan/widgets/tabbedarea.hpp> + +#include <string> + +class Tab; + +/** + * A tabbed area, the same as the guichan tabbed area in 0.8, but extended + */ +class TabbedArea : public gcn::TabbedArea +{ + public: + /** + * Constructor. + */ + TabbedArea(); + + /** + * Draw the tabbed area. + */ + void draw(gcn::Graphics *graphics); + + /** + * Return how many tabs have been created + */ + int getNumberOfTabs(); + + /** + * Return tab with specified name as caption + */ + Tab* getTab(const std::string &name); + + /** + * Returns the widget with the tab that has specified caption + */ + gcn::Widget* getWidget(const std::string &name); + + /** + * Add a tab + * @param caption The Caption to display + * @param widget The widget to show when tab is selected + */ + void addTab(const std::string &caption, gcn::Widget *widget); + + /** + * Add a tab + * @param tab The tab + * @param widget The widget to display + */ + void addTab(Tab *tab, gcn::Widget *widget); + + /** + * Overload the remove tab function as its broken in guichan 0.8 + */ + void removeTab(Tab *tab); + + /** + * Overload the logic function since it's broken in guichan 0.8 + */ + void logic(); + + private: + typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer; +}; + +#endif + diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index b633835c..d8763f43 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -27,11 +27,15 @@ #include "../beingmanager.h" #include "../npc.h" +#include "../gui/npcintegerdialog.h" #include "../gui/npclistdialog.h" +#include "../gui/npcstringdialog.h" #include "../gui/npc_text.h" +extern NpcIntegerDialog *npcIntegerDialog; extern NpcListDialog *npcListDialog; extern NpcTextDialog *npcTextDialog; +extern NpcStringDialog *npcStringDialog; NPCHandler::NPCHandler() { @@ -40,6 +44,8 @@ NPCHandler::NPCHandler() SMSG_NPC_MESSAGE, SMSG_NPC_NEXT, SMSG_NPC_CLOSE, + SMSG_NPC_INT_INPUT, + SMSG_NPC_STR_INPUT, 0 }; handledMessages = _messages; @@ -78,5 +84,21 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused break; + + case SMSG_NPC_INT_INPUT: + // Request for an integer + id = msg->readInt32(); + current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + npcIntegerDialog->prepDialog(0, 0, 2147483647); + npcIntegerDialog->setVisible(true); + break; + + case SMSG_NPC_STR_INPUT: + // Request for a string + id = msg->readInt32(); + current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + npcStringDialog->setValue(""); + npcStringDialog->setVisible(true); + break; } } diff --git a/src/net/protocol.h b/src/net/protocol.h index d7bdd041..f52aa794 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -75,6 +75,8 @@ #define SMSG_NPC_SELL 0x00c7 #define SMSG_NPC_BUY_RESPONSE 0x00ca #define SMSG_NPC_SELL_RESPONSE 0x00cb +#define SMSG_NPC_INT_INPUT 0x0142 /**< Integer input */ +#define SMSG_NPC_STR_INPUT 0x01d4 /**< String input */ #define SMSG_PLAYER_CHAT 0x008e /**< Player talks */ #define SMSG_WHISPER 0x0097 /**< Whisper Recieved */ #define SMSG_WHISPER_RESPONSE 0x0098 @@ -100,6 +102,8 @@ #define CMSG_NPC_LIST_CHOICE 0x00b8 #define CMSG_NPC_NEXT_REQUEST 0x00b9 #define CMSG_NPC_SELL_REQUEST 0x00c9 +#define CMSG_NPC_INT_RESPONSE 0x0143 +#define CMSG_NPC_STR_RESPONSE 0x01d5 #define CMSG_SKILL_LEVELUP_REQUEST 0x0112 #define CMSG_STAT_UPDATE_REQUEST 0x00bb #define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 diff --git a/src/npc.cpp b/src/npc.cpp index 66048005..b107445a 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -80,14 +80,12 @@ void NPC::setName(const std::string &name) gcn::Color(200, 200, 255)); } -Being::Type -NPC::getType() const +Being::Type NPC::getType() const { return Being::NPC; } -void -NPC::talk() +void NPC::talk() { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); @@ -96,16 +94,14 @@ NPC::talk() current_npc = this; } -void -NPC::nextDialog() +void NPC::nextDialog() { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(mId); } -void -NPC::dialogChoice(char choice) +void NPC::dialogChoice(char choice) { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); @@ -113,12 +109,29 @@ NPC::dialogChoice(char choice) outMsg.writeInt8(choice); } +void NPC::integerInput(int value) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(mId); + outMsg.writeInt32(value); +} + +void NPC::stringInput(const std::string &value) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(value.length() + 8); + outMsg.writeInt32(mId); + outMsg.writeString(value, value.length()); + outMsg.writeInt8(0); // Just to be safe +} + /* * TODO Unify the buy() and sell() methods, without sacrificing readability of * the code calling the method. buy(bool buySell) would be bad... */ -void -NPC::buy() +void NPC::buy() { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); @@ -126,8 +139,7 @@ NPC::buy() outMsg.writeInt8(0); } -void -NPC::sell() +void NPC::sell() { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); @@ -43,6 +43,8 @@ class NPC : public Being void talk(); void nextDialog(); void dialogChoice(char choice); + void integerInput(int value); + void stringInput(const std::string &value); void buy(); void sell(); |