From 3cca6548aefcfe0751ab7b4d70ac71ace486e12e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 27 Apr 2009 23:43:24 +0200 Subject: Removed underscores from some non-conforming filenames We don't use underscores in the filenames generally, and let's be consistent on that matter. --- src/CMakeLists.txt | 32 +-- src/Makefile.am | 32 +-- src/channel.cpp | 2 + src/channel.h | 8 +- src/floor_item.cpp | 69 ------- src/floor_item.h | 104 ---------- src/flooritem.cpp | 70 +++++++ src/flooritem.h | 104 ++++++++++ src/flooritemmanager.cpp | 2 +- src/game.cpp | 8 +- src/gui/changeemaildialog.cpp | 2 +- src/gui/changepassworddialog.cpp | 2 +- src/gui/char_select.cpp | 379 ---------------------------------- src/gui/char_select.h | 112 ---------- src/gui/charcreatedialog.cpp | 6 +- src/gui/charselectdialog.cpp | 379 ++++++++++++++++++++++++++++++++++ src/gui/charselectdialog.h | 112 ++++++++++ src/gui/confirm_dialog.cpp | 92 --------- src/gui/confirm_dialog.h | 56 ----- src/gui/confirmdialog.cpp | 92 +++++++++ src/gui/confirmdialog.h | 56 +++++ src/gui/guildwindow.cpp | 2 +- src/gui/inventorywindow.cpp | 2 +- src/gui/item_amount.cpp | 178 ---------------- src/gui/item_amount.h | 81 -------- src/gui/itemamount.cpp | 178 ++++++++++++++++ src/gui/itemamount.h | 81 ++++++++ src/gui/login.cpp | 2 +- src/gui/npc_text.cpp | 138 ------------- src/gui/npc_text.h | 113 ---------- src/gui/npcintegerdialog.cpp | 2 +- src/gui/npclistdialog.cpp | 2 +- src/gui/npcstringdialog.cpp | 2 +- src/gui/npctextdialog.cpp | 138 +++++++++++++ src/gui/npctextdialog.h | 113 ++++++++++ src/gui/ok_dialog.cpp | 82 -------- src/gui/ok_dialog.h | 56 ----- src/gui/okdialog.cpp | 82 ++++++++ src/gui/okdialog.h | 56 +++++ src/gui/partywindow.h | 2 +- src/gui/popupmenu.cpp | 6 +- src/gui/register.cpp | 2 +- src/gui/serverdialog.cpp | 2 +- src/gui/setup_audio.cpp | 2 +- src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_players.cpp | 2 +- src/gui/setup_players.h | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/storagewindow.cpp | 3 +- src/gui/table.h | 4 +- src/gui/table_model.cpp | 161 --------------- src/gui/table_model.h | 144 ------------- src/gui/tablemodel.cpp | 161 +++++++++++++++ src/gui/tablemodel.h | 146 +++++++++++++ src/gui/trade.cpp | 2 +- src/gui/unregisterdialog.cpp | 2 +- src/localplayer.cpp | 2 +- src/main.cpp | 6 +- src/net/ea/adminhandler.cpp | 2 +- src/net/ea/beinghandler.cpp | 4 +- src/net/ea/charserverhandler.cpp | 2 +- src/net/ea/chathandler.cpp | 6 +- src/net/ea/npchandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 4 +- src/net/ea/tradehandler.cpp | 4 +- src/net/playerhandler.h | 2 +- src/net/tmwserv/beinghandler.cpp | 2 +- src/net/tmwserv/charserverhandler.cpp | 2 +- src/net/tmwserv/npchandler.cpp | 2 +- src/net/tmwserv/playerhandler.cpp | 4 +- src/net/tmwserv/tradehandler.cpp | 2 +- src/npc.cpp | 2 +- src/player_relations.cpp | 375 --------------------------------- src/player_relations.h | 240 --------------------- src/playerrelations.cpp | 375 +++++++++++++++++++++++++++++++++ src/playerrelations.h | 240 +++++++++++++++++++++ src/position.cpp | 6 +- 77 files changed, 2480 insertions(+), 2476 deletions(-) delete mode 100644 src/floor_item.cpp delete mode 100644 src/floor_item.h create mode 100644 src/flooritem.cpp create mode 100644 src/flooritem.h delete mode 100644 src/gui/char_select.cpp delete mode 100644 src/gui/char_select.h create mode 100644 src/gui/charselectdialog.cpp create mode 100644 src/gui/charselectdialog.h delete mode 100644 src/gui/confirm_dialog.cpp delete mode 100644 src/gui/confirm_dialog.h create mode 100644 src/gui/confirmdialog.cpp create mode 100644 src/gui/confirmdialog.h delete mode 100644 src/gui/item_amount.cpp delete mode 100644 src/gui/item_amount.h create mode 100644 src/gui/itemamount.cpp create mode 100644 src/gui/itemamount.h delete mode 100644 src/gui/npc_text.cpp delete mode 100644 src/gui/npc_text.h create mode 100644 src/gui/npctextdialog.cpp create mode 100644 src/gui/npctextdialog.h delete mode 100644 src/gui/ok_dialog.cpp delete mode 100644 src/gui/ok_dialog.h create mode 100644 src/gui/okdialog.cpp create mode 100644 src/gui/okdialog.h delete mode 100644 src/gui/table_model.cpp delete mode 100644 src/gui/table_model.h create mode 100644 src/gui/tablemodel.cpp create mode 100644 src/gui/tablemodel.h delete mode 100644 src/player_relations.cpp delete mode 100644 src/player_relations.h create mode 100644 src/playerrelations.cpp create mode 100644 src/playerrelations.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd8be3f4..8c59388b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,14 +116,14 @@ SET(SRCS gui/buy.h gui/buysell.cpp gui/buysell.h - gui/char_select.cpp - gui/char_select.h + gui/charselectdialog.cpp + gui/charselectdialog.h gui/charcreatedialog.cpp gui/charcreatedialog.h gui/chat.cpp gui/chat.h - gui/confirm_dialog.cpp - gui/confirm_dialog.h + gui/confirmdialog.cpp + gui/confirmdialog.h gui/debugwindow.cpp gui/debugwindow.h gui/emotecontainer.cpp @@ -150,8 +150,8 @@ SET(SRCS gui/itempopup.h gui/itemshortcutcontainer.cpp gui/itemshortcutcontainer.h - gui/item_amount.cpp - gui/item_amount.h + gui/itemamount.cpp + gui/itemamount.h gui/linkhandler.h gui/login.cpp gui/login.h @@ -169,10 +169,10 @@ SET(SRCS gui/npcpostdialog.h gui/npcstringdialog.cpp gui/npcstringdialog.h - gui/npc_text.cpp - gui/npc_text.h - gui/ok_dialog.cpp - gui/ok_dialog.h + gui/npctextdialog.cpp + gui/npctextdialog.h + gui/okdialog.cpp + gui/okdialog.h gui/palette.cpp gui/palette.h gui/partywindow.cpp @@ -223,8 +223,8 @@ SET(SRCS gui/storagewindow.h gui/table.cpp gui/table.h - gui/table_model.cpp - gui/table_model.h + gui/tablemodel.cpp + gui/tablemodel.h gui/textdialog.cpp gui/textdialog.h gui/textrenderer.h @@ -341,8 +341,8 @@ SET(SRCS engine.h equipment.cpp equipment.h - floor_item.cpp - floor_item.h + flooritem.cpp + flooritem.h flooritemmanager.cpp flooritemmanager.h game.cpp @@ -387,8 +387,8 @@ SET(SRCS particleemitterprop.h player.cpp player.h - player_relations.cpp - player_relations.h + playerrelations.cpp + playerrelations.h position.cpp position.h properties.h diff --git a/src/Makefile.am b/src/Makefile.am index 567843e3..c22fd91d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,14 +69,14 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/buy.h \ gui/buysell.cpp \ gui/buysell.h \ - gui/char_select.cpp \ - gui/char_select.h \ + gui/charselectdialog.cpp \ + gui/charselectdialog.h \ gui/charcreatedialog.cpp \ gui/charcreatedialog.h \ gui/chat.cpp \ gui/chat.h \ - gui/confirm_dialog.cpp \ - gui/confirm_dialog.h \ + gui/confirmdialog.cpp \ + gui/confirmdialog.h \ gui/debugwindow.cpp \ gui/debugwindow.h \ gui/emotecontainer.cpp \ @@ -95,8 +95,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/help.h \ gui/inventorywindow.cpp \ gui/inventorywindow.h \ - gui/item_amount.cpp \ - gui/item_amount.h \ + gui/itemamount.cpp \ + gui/itemamount.h \ gui/itemcontainer.cpp \ gui/itemcontainer.h \ gui/itemlinkhandler.cpp \ @@ -114,8 +114,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/minimap.h \ gui/ministatus.cpp \ gui/ministatus.h \ - gui/npc_text.cpp \ - gui/npc_text.h \ + gui/npctextdialog.cpp \ + gui/npctextdialog.h \ gui/npcintegerdialog.cpp \ gui/npcintegerdialog.h \ gui/npclistdialog.cpp \ @@ -124,8 +124,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/npcpostdialog.h \ gui/npcstringdialog.cpp \ gui/npcstringdialog.h \ - gui/ok_dialog.cpp \ - gui/ok_dialog.h \ + gui/okdialog.cpp \ + gui/okdialog.h \ gui/palette.cpp \ gui/palette.h \ gui/partywindow.cpp \ @@ -176,8 +176,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/storagewindow.h \ gui/table.cpp \ gui/table.h \ - gui/table_model.cpp \ - gui/table_model.h \ + gui/tablemodel.cpp \ + gui/tablemodel.h \ gui/textdialog.cpp \ gui/textdialog.h \ gui/textrenderer.h \ @@ -294,8 +294,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ engine.h \ equipment.cpp \ equipment.h \ - floor_item.cpp \ - floor_item.h \ + flooritem.cpp \ + flooritem.h \ flooritemmanager.cpp \ flooritemmanager.h \ game.cpp \ @@ -340,8 +340,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ particleemitterprop.h \ player.cpp \ player.h \ - player_relations.cpp \ - player_relations.h \ + playerrelations.cpp \ + playerrelations.h \ position.cpp \ position.h \ properties.h \ diff --git a/src/channel.cpp b/src/channel.cpp index a98d315c..154b016d 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -21,6 +21,8 @@ #include "channel.h" +#include "gui/widgets/channeltab.h" + Channel::Channel(short id, const std::string &name, const std::string &announcement) : diff --git a/src/channel.h b/src/channel.h index b2080d4a..230ca915 100644 --- a/src/channel.h +++ b/src/channel.h @@ -24,7 +24,7 @@ #include -#include "gui/widgets/channeltab.h" +class ChannelTab; class Channel { @@ -43,18 +43,18 @@ class Channel ~Channel(); /** - * Get the id associated witht his channel + * Get the id associated witht his channel. */ int getId() const { return mId; } /** - * Get this channel's name + * Get this channel's name. */ const std::string &getName() const { return mName; } /** - * Get the announcement message for this channel + * Get the announcement message for this channel. */ const std::string &getAnnouncement() const { return mAnnouncement; } diff --git a/src/floor_item.cpp b/src/floor_item.cpp deleted file mode 100644 index b8c0ffaf..00000000 --- a/src/floor_item.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "floor_item.h" -#include "graphics.h" -#include "item.h" -#include "map.h" - -#include "resources/image.h" - -FloorItem::FloorItem(int id, - int itemId, - int x, - int y, - Map *map): - mId(id), - mX(x), - mY(y), - mMap(map) -{ - // Create a corresponding item instance - mItem = new Item(itemId); - - // Add ourselves to the map - mSpriteIterator = mMap->addSprite(this); -} - -FloorItem::~FloorItem() -{ - // Remove ourselves from the map - mMap->removeSprite(mSpriteIterator); - - delete mItem; -} - -int FloorItem::getItemId() const -{ - return mItem->getId(); -} - -Item* FloorItem::getItem() const -{ - return mItem; -} - -void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const -{ - graphics->drawImage(mItem->getImage(), - mX * 32 + offsetX, - mY * 32 + offsetY); -} diff --git a/src/floor_item.h b/src/floor_item.h deleted file mode 100644 index 0e269c77..00000000 --- a/src/floor_item.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef FLOORITEM_H -#define FLOORITEM_H - -#include - -#include "sprite.h" - -class Graphics; -class Image; -class Item; -class Map; - -typedef std::list Sprites; - -/** - * An item lying on the floor. - */ -class FloorItem : public Sprite -{ - public: - /** - * Constructor. - */ - FloorItem(int id, - int itemId, - int x, - int y, - Map *map); - - /** - * Destructor. - */ - ~FloorItem(); - - /** - * Returns instance id of this item. - */ - int getId() const { return mId; } - - /** - * Returns the item id. - */ - int getItemId() const; - - /** - * Returns the item object. Useful for adding an item link for the floor - * item to chat. - */ - Item* getItem() const; - - /** - * Returns the x coordinate. - */ - int getX() const { return mX; } - - /** - * Returns the y coordinate. - */ - int getY() const { return mY; } - - /** - * Returns the pixel y coordinate. - * - * @see Sprite::getPixelY() - */ - int getPixelY() const { return mY * 32; } - - /** - * Draws this floor item to the given graphics context. - * - * @see Sprite::draw(Graphics, int, int) - */ - void draw(Graphics *graphics, int offsetX, int offsetY) const; - - private: - int mId; - int mX, mY; - Item *mItem; - Sprites::iterator mSpriteIterator; - Map *mMap; -}; - -#endif diff --git a/src/flooritem.cpp b/src/flooritem.cpp new file mode 100644 index 00000000..b08258c1 --- /dev/null +++ b/src/flooritem.cpp @@ -0,0 +1,70 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "flooritem.h" + +#include "graphics.h" +#include "item.h" +#include "map.h" + +#include "resources/image.h" + +FloorItem::FloorItem(int id, + int itemId, + int x, + int y, + Map *map): + mId(id), + mX(x), + mY(y), + mMap(map) +{ + // Create a corresponding item instance + mItem = new Item(itemId); + + // Add ourselves to the map + mSpriteIterator = mMap->addSprite(this); +} + +FloorItem::~FloorItem() +{ + // Remove ourselves from the map + mMap->removeSprite(mSpriteIterator); + + delete mItem; +} + +int FloorItem::getItemId() const +{ + return mItem->getId(); +} + +Item *FloorItem::getItem() const +{ + return mItem; +} + +void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + graphics->drawImage(mItem->getImage(), + mX * 32 + offsetX, + mY * 32 + offsetY); +} diff --git a/src/flooritem.h b/src/flooritem.h new file mode 100644 index 00000000..9911cd25 --- /dev/null +++ b/src/flooritem.h @@ -0,0 +1,104 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef FLOORITEM_H +#define FLOORITEM_H + +#include + +#include "sprite.h" + +class Graphics; +class Image; +class Item; +class Map; + +typedef std::list Sprites; + +/** + * An item lying on the floor. + */ +class FloorItem : public Sprite +{ + public: + /** + * Constructor. + */ + FloorItem(int id, + int itemId, + int x, + int y, + Map *map); + + /** + * Destructor. + */ + ~FloorItem(); + + /** + * Returns instance id of this item. + */ + int getId() const { return mId; } + + /** + * Returns the item id. + */ + int getItemId() const; + + /** + * Returns the item object. Useful for adding an item link for the + * floor item to chat. + */ + Item *getItem() const; + + /** + * Returns the x coordinate. + */ + int getX() const { return mX; } + + /** + * Returns the y coordinate. + */ + int getY() const { return mY; } + + /** + * Returns the pixel y coordinate. + * + * @see Sprite::getPixelY() + */ + int getPixelY() const { return mY * 32; } + + /** + * Draws this floor item to the given graphics context. + * + * @see Sprite::draw(Graphics, int, int) + */ + void draw(Graphics *graphics, int offsetX, int offsetY) const; + + private: + int mId; + int mX, mY; + Item *mItem; + Sprites::iterator mSpriteIterator; + Map *mMap; +}; + +#endif diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index 5d2799d4..9bfd02ae 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "floor_item.h" #include "flooritemmanager.h" +#include "flooritem.h" #include "utils/dtor.h" diff --git a/src/game.cpp b/src/game.cpp index 47d3b99c..1ccc46e7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -37,13 +37,13 @@ #include "map.h" #include "npc.h" #include "particle.h" -#include "player_relations.h" +#include "playerrelations.h" #include "gui/widgets/chattab.h" #include "gui/buy.h" #include "gui/buysell.h" #include "gui/chat.h" -#include "gui/confirm_dialog.h" +#include "gui/confirmdialog.h" #include "gui/debugwindow.h" #include "gui/emoteshortcutcontainer.h" #include "gui/emotewindow.h" @@ -59,8 +59,8 @@ #include "gui/npcintegerdialog.h" #include "gui/npclistdialog.h" #include "gui/npcstringdialog.h" -#include "gui/npc_text.h" -#include "gui/ok_dialog.h" +#include "gui/npctextdialog.h" +#include "gui/okdialog.h" #include "gui/sdlinput.h" #include "gui/sell.h" #include "gui/setup.h" diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 0955ffca..798c172e 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -26,7 +26,7 @@ #include "logindata.h" #include "gui/register.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 403d9afc..42854896 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -26,7 +26,7 @@ #include "logindata.h" #include "gui/register.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/passwordfield.h" diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp deleted file mode 100644 index ddcc62a5..00000000 --- a/src/gui/char_select.cpp +++ /dev/null @@ -1,379 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/char_select.h" - -#include "gui/charcreatedialog.h" -#include "gui/confirm_dialog.h" -#include "gui/ok_dialog.h" -#include "gui/playerbox.h" - -#ifdef TMWSERV_SUPPORT -#include "gui/widgets/radiobutton.h" -#include "gui/widgets/slider.h" - -#include "gui/unregisterdialog.h" -#include "gui/changepassworddialog.h" -#include "gui/changeemaildialog.h" - -#include "logindata.h" - -#include "net/tmwserv/accountserver/account.h" -#endif - -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/textfield.h" - -#include "game.h" -#include "localplayer.h" -#include "main.h" -#include "units.h" - -#include "net/charhandler.h" -#include "net/messageout.h" -#include "net/net.h" - -#include "resources/colordb.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" -#include "utils/stringutils.h" - -#include - -#include - -/** - * Listener for confirming character deletion. - */ -class CharDeleteConfirm : public ConfirmDialog -{ - public: - CharDeleteConfirm(CharSelectDialog *master); - void action(const gcn::ActionEvent &event); - private: - CharSelectDialog *master; -}; - -CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): - ConfirmDialog(_("Confirm Character Delete"), - _("Are you sure you want to delete this character?"), m), - master(m) -{ -} - -void CharDeleteConfirm::action(const gcn::ActionEvent &event) -{ - //ConfirmDialog::action(event); - if (event.getId() == "yes") - { - master->attemptCharDelete(); - } - ConfirmDialog::action(event); -} - -#ifdef TMWSERV_SUPPORT -CharSelectDialog::CharSelectDialog(LockedArray *charInfo, - LoginData *loginData): - Window(_("Account and Character Management")), - mCharInfo(charInfo), - mCharSelected(false), - mLoginData(loginData) -#else -CharSelectDialog::CharSelectDialog(LockedArray *charInfo, - Gender gender): - Window(_("Select Character")), - mCharInfo(charInfo), - mCharSelected(false), - mGender(gender) -#endif -{ - mSelectButton = new Button(_("Ok"), "ok", this); - mCancelButton = new Button(_("Cancel"), "cancel", this); - mPreviousButton = new Button(_("Previous"), "previous", this); - mNextButton = new Button(_("Next"), "next", this); - mNameLabel = new Label(strprintf(_("Name: %s"), "")); - mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); -#ifdef TMWSERV_SUPPORT - mNewCharButton = new Button(_("New"), "new", this); - mDelCharButton = new Button(_("Delete"), "delete", this); - mUnRegisterButton = new Button(_("Unregister"), "unregister", this); - mChangePasswordButton = new Button(_("Change Password"), "change_password", this); - mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); - - mAccountNameLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); - mNameLabel = new Label(strprintf(_("Name: %s"), "")); - mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); - mMoneyLabel = new Label(strprintf(_("Money: %d"), 0)); - - // Control that shows the Player - mPlayerBox = new PlayerBox; - mPlayerBox->setWidth(74); - - ContainerPlacer place; - place = getPlacer(0, 0); - place(0, 0, mAccountNameLabel); - place(0, 1, mUnRegisterButton); - place(0, 2, mChangePasswordButton); - place(1, 2, mChangeEmailButton); - place = getPlacer(0, 1); - place(0, 0, mPlayerBox, 1, 5).setPadding(3); - place(1, 0, mNameLabel, 3); - place(1, 1, mLevelLabel, 3); - place(1, 2, mMoneyLabel, 3); - place(1, 3, mPreviousButton); - place(2, 3, mNextButton); - place(1, 4, mNewCharButton); - place(2, 4, mDelCharButton); - place.getCell().matchColWidth(1, 2); - place = getPlacer(0, 2); - place(0, 0, mSelectButton); - place(1, 0, mCancelButton); - reflowLayout(265, 0); -#else - mCharInfo->select(0); - LocalPlayer *pi = mCharInfo->getEntry(); - if (pi) - mMoney = Units::formatCurrency(pi->getMoney()); - // Control that shows the Player - mPlayerBox = new PlayerBox; - mPlayerBox->setWidth(74); - - mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0)); - mMoneyLabel = new Label(strprintf(_("Money: %s"), mMoney.c_str())); - - const std::string tempString = getFont()->getWidth(_("New")) < - getFont()->getWidth(_("Delete")) ? - _("Delete") : _("New"); - - mNewDelCharButton = new Button(tempString, "newdel", this); - - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, mPlayerBox, 1, 6).setPadding(3); - place(1, 0, mNewDelCharButton); - place(1, 1, mNameLabel, 5); - place(1, 2, mLevelLabel, 5); - place(1, 3, mJobLevelLabel, 5); - place(1, 4, mMoneyLabel, 5); - place.getCell().matchColWidth(1, 4); - place = getPlacer(0, 2); - place(0, 0, mPreviousButton); - place(1, 0, mNextButton); - place(4, 0, mCancelButton); - place(5, 0, mSelectButton); - - reflowLayout(250, 0); -#endif - - center(); - setVisible(true); - mSelectButton->requestFocus(); - updatePlayerInfo(); -} - -void CharSelectDialog::action(const gcn::ActionEvent &event) -{ -#ifdef TMWSERV_SUPPORT - // The pointers are set to NULL if there is no character stored - if (event.getId() == "ok" && (mCharInfo->getEntry())) -#else - if (event.getId() == "ok" && n_character > 0) -#endif - { - // Start game -#ifdef TMWSERV_SUPPORT - mNewCharButton->setEnabled(false); - mDelCharButton->setEnabled(false); - mUnRegisterButton->setEnabled(false); -#else - mNewDelCharButton->setEnabled(false); -#endif - mSelectButton->setEnabled(false); - mPreviousButton->setEnabled(false); - mNextButton->setEnabled(false); - mCharSelected = true; - attemptCharSelect(); - } - else if (event.getId() == "cancel") - { -#ifdef TMWSERV_SUPPORT - mCharInfo->clear(); - state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT; -#else - state = STATE_EXIT; -#endif - } -#ifdef TMWSERV_SUPPORT - else if (event.getId() == "new") - { - // TODO: Search the first free slot, and start CharCreateDialog - // maybe add that search to the constructor. - if (!(mCharInfo->getEntry())) - { - // Start new character dialog - CharCreateDialog *charCreateDialog = - new CharCreateDialog(this, mCharInfo->getPos()); - Net::getCharHandler()->setCharCreateDialog(charCreateDialog); - } - } - else if (event.getId() == "delete") - { - // Delete character - if (mCharInfo->getEntry()) - { - new CharDeleteConfirm(this); - } - } -#else - else if (event.getId() == "newdel") - { - // Check for a character - if (mCharInfo->getEntry()) - { - new CharDeleteConfirm(this); - } - else if (n_character <= maxSlot) - { - // Start new character dialog - CharCreateDialog *charCreateDialog = - new CharCreateDialog(this, mCharInfo->getPos()); - Net::getCharHandler()->setCharCreateDialog(charCreateDialog); - } - } -#endif - else if (event.getId() == "previous") - { - mCharInfo->prev(); - LocalPlayer *pi = mCharInfo->getEntry(); - if (pi) - mMoney = Units::formatCurrency(pi->getMoney()); - } - else if (event.getId() == "next") - { - mCharInfo->next(); - LocalPlayer *pi = mCharInfo->getEntry(); - if (pi) - mMoney = Units::formatCurrency(pi->getMoney()); - } -#ifdef TMWSERV_SUPPORT - else if (event.getId() == "unregister") - { - new UnRegisterDialog(this, mLoginData); - } - else if (event.getId() == "change_password") - { - new ChangePasswordDialog(this, mLoginData); - } - else if (event.getId() == "change_email") - { - new ChangeEmailDialog(this, mLoginData); - } -#endif -} - -void CharSelectDialog::updatePlayerInfo() -{ - LocalPlayer *pi = mCharInfo->getEntry(); - - if (pi) - { - mNameLabel->setCaption(strprintf(_("Name: %s"), - pi->getName().c_str())); - mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel())); -#ifndef TMWSERV_SUPPORT - mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), - pi->mJobLevel)); -#endif - mMoneyLabel->setCaption(strprintf(_("Money: %s"), mMoney.c_str())); - if (!mCharSelected) - { -#ifdef TMWSERV_SUPPORT - mNewCharButton->setEnabled(false); - mDelCharButton->setEnabled(true); -#else - mNewDelCharButton->setCaption(_("Delete")); -#endif - mSelectButton->setEnabled(true); - } - } - else - { - mNameLabel->setCaption(strprintf(_("Name: %s"), "")); - mLevelLabel->setCaption(strprintf(_("Level: %d"), 0)); -#ifndef TMWSERV_SUPPORT - mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), 0)); -#endif - mMoneyLabel->setCaption(strprintf(_("Money: %s"), "")); -#ifdef TMWSERV_SUPPORT - mNewCharButton->setEnabled(true); - mDelCharButton->setEnabled(false); -#else - mNewDelCharButton->setCaption(_("New")); -#endif - mSelectButton->setEnabled(false); - } - - mPlayerBox->setPlayer(pi); -} - -void CharSelectDialog::attemptCharDelete() -{ - Net::getCharHandler()->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry()); - mCharInfo->lock(); -} - -void CharSelectDialog::attemptCharSelect() -{ - Net::getCharHandler()->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry()); - mCharInfo->lock(); -} - -void CharSelectDialog::logic() -{ - updatePlayerInfo(); -} - -bool CharSelectDialog::selectByName(const std::string &name) -{ - if (mCharInfo->isLocked()) - return false; - - unsigned int oldPos = mCharInfo->getPos(); - - mCharInfo->select(0); - do - { - LocalPlayer *player = mCharInfo->getEntry(); - - if (player && player->getName() == name) - return true; - - mCharInfo->next(); - } while (mCharInfo->getPos()); - - mCharInfo->select(oldPos); - - return false; -} diff --git a/src/gui/char_select.h b/src/gui/char_select.h deleted file mode 100644 index 75a98465..00000000 --- a/src/gui/char_select.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef CHAR_SELECT_H -#define CHAR_SELECT_H - -#include "gui/widgets/window.h" - -#include "being.h" -#include "guichanfwd.h" -#include "lockedarray.h" - -#include - -#ifdef TMWSERV_SUPPORT -#include "../logindata.h" -#endif - -class LocalPlayer; -class Player; -class PlayerBox; - -/** - * Character selection dialog. - * - * \ingroup Interface - */ -class CharSelectDialog : public Window, public gcn::ActionListener -{ - public: - friend class CharDeleteConfirm; - /** - * Constructor. - */ -#ifdef TMWSERV_SUPPORT - CharSelectDialog(LockedArray *charInfo, - LoginData *loginData); -#else - CharSelectDialog(LockedArray *charInfo, - Gender gender); -#endif - - void action(const gcn::ActionEvent &event); - - void updatePlayerInfo(); - - void logic(); - - bool selectByName(const std::string &name); - - private: - LockedArray *mCharInfo; - - gcn::Button *mSelectButton; - gcn::Button *mCancelButton; - gcn::Button *mPreviousButton; - gcn::Button *mNextButton; - - gcn::Label *mNameLabel; - gcn::Label *mLevelLabel; - gcn::Label *mMoneyLabel; - std::string mMoney; - - PlayerBox *mPlayerBox; - - bool mCharSelected; - -#ifdef TMWSERV_SUPPORT - gcn::Button *mNewCharButton; - gcn::Button *mDelCharButton; - gcn::Button *mUnRegisterButton; - gcn::Button *mChangePasswordButton; - gcn::Button *mChangeEmailButton; - gcn::Label *mAccountNameLabel; - - LoginData *mLoginData; -#else - gcn::Button *mNewDelCharButton; - gcn::Label *mJobLevelLabel; - Gender mGender; -#endif - - /** - * Communicate character deletion to the server. - */ - void attemptCharDelete(); - - /** - * Communicate character selection to the server. - */ - void attemptCharSelect(); -}; - -#endif diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index dc982e21..8513d573 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -21,9 +21,9 @@ #include "gui/charcreatedialog.h" -#include "gui/char_select.h" -#include "gui/confirm_dialog.h" -#include "gui/ok_dialog.h" +#include "gui/charselectdialog.h" +#include "gui/confirmdialog.h" +#include "gui/okdialog.h" #include "gui/playerbox.h" #include "gui/widgets/button.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp new file mode 100644 index 00000000..afc349ea --- /dev/null +++ b/src/gui/charselectdialog.cpp @@ -0,0 +1,379 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/charselectdialog.h" + +#include "gui/charcreatedialog.h" +#include "gui/confirmdialog.h" +#include "gui/okdialog.h" +#include "gui/playerbox.h" + +#ifdef TMWSERV_SUPPORT +#include "gui/widgets/radiobutton.h" +#include "gui/widgets/slider.h" + +#include "gui/unregisterdialog.h" +#include "gui/changepassworddialog.h" +#include "gui/changeemaildialog.h" + +#include "logindata.h" + +#include "net/tmwserv/accountserver/account.h" +#endif + +#include "gui/widgets/button.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/textfield.h" + +#include "game.h" +#include "localplayer.h" +#include "main.h" +#include "units.h" + +#include "net/charhandler.h" +#include "net/messageout.h" +#include "net/net.h" + +#include "resources/colordb.h" + +#include "utils/gettext.h" +#include "utils/strprintf.h" +#include "utils/stringutils.h" + +#include + +#include + +/** + * Listener for confirming character deletion. + */ +class CharDeleteConfirm : public ConfirmDialog +{ + public: + CharDeleteConfirm(CharSelectDialog *master); + void action(const gcn::ActionEvent &event); + private: + CharSelectDialog *master; +}; + +CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): + ConfirmDialog(_("Confirm Character Delete"), + _("Are you sure you want to delete this character?"), m), + master(m) +{ +} + +void CharDeleteConfirm::action(const gcn::ActionEvent &event) +{ + //ConfirmDialog::action(event); + if (event.getId() == "yes") + { + master->attemptCharDelete(); + } + ConfirmDialog::action(event); +} + +#ifdef TMWSERV_SUPPORT +CharSelectDialog::CharSelectDialog(LockedArray *charInfo, + LoginData *loginData): + Window(_("Account and Character Management")), + mCharInfo(charInfo), + mCharSelected(false), + mLoginData(loginData) +#else +CharSelectDialog::CharSelectDialog(LockedArray *charInfo, + Gender gender): + Window(_("Select Character")), + mCharInfo(charInfo), + mCharSelected(false), + mGender(gender) +#endif +{ + mSelectButton = new Button(_("Ok"), "ok", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mPreviousButton = new Button(_("Previous"), "previous", this); + mNextButton = new Button(_("Next"), "next", this); + mNameLabel = new Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); +#ifdef TMWSERV_SUPPORT + mNewCharButton = new Button(_("New"), "new", this); + mDelCharButton = new Button(_("Delete"), "delete", this); + mUnRegisterButton = new Button(_("Unregister"), "unregister", this); + mChangePasswordButton = new Button(_("Change Password"), "change_password", this); + mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); + + mAccountNameLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); + mNameLabel = new Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %d"), 0)); + + // Control that shows the Player + mPlayerBox = new PlayerBox; + mPlayerBox->setWidth(74); + + ContainerPlacer place; + place = getPlacer(0, 0); + place(0, 0, mAccountNameLabel); + place(0, 1, mUnRegisterButton); + place(0, 2, mChangePasswordButton); + place(1, 2, mChangeEmailButton); + place = getPlacer(0, 1); + place(0, 0, mPlayerBox, 1, 5).setPadding(3); + place(1, 0, mNameLabel, 3); + place(1, 1, mLevelLabel, 3); + place(1, 2, mMoneyLabel, 3); + place(1, 3, mPreviousButton); + place(2, 3, mNextButton); + place(1, 4, mNewCharButton); + place(2, 4, mDelCharButton); + place.getCell().matchColWidth(1, 2); + place = getPlacer(0, 2); + place(0, 0, mSelectButton); + place(1, 0, mCancelButton); + reflowLayout(265, 0); +#else + mCharInfo->select(0); + LocalPlayer *pi = mCharInfo->getEntry(); + if (pi) + mMoney = Units::formatCurrency(pi->getMoney()); + // Control that shows the Player + mPlayerBox = new PlayerBox; + mPlayerBox->setWidth(74); + + mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %s"), mMoney.c_str())); + + const std::string tempString = getFont()->getWidth(_("New")) < + getFont()->getWidth(_("Delete")) ? + _("Delete") : _("New"); + + mNewDelCharButton = new Button(tempString, "newdel", this); + + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mPlayerBox, 1, 6).setPadding(3); + place(1, 0, mNewDelCharButton); + place(1, 1, mNameLabel, 5); + place(1, 2, mLevelLabel, 5); + place(1, 3, mJobLevelLabel, 5); + place(1, 4, mMoneyLabel, 5); + place.getCell().matchColWidth(1, 4); + place = getPlacer(0, 2); + place(0, 0, mPreviousButton); + place(1, 0, mNextButton); + place(4, 0, mCancelButton); + place(5, 0, mSelectButton); + + reflowLayout(250, 0); +#endif + + center(); + setVisible(true); + mSelectButton->requestFocus(); + updatePlayerInfo(); +} + +void CharSelectDialog::action(const gcn::ActionEvent &event) +{ +#ifdef TMWSERV_SUPPORT + // The pointers are set to NULL if there is no character stored + if (event.getId() == "ok" && (mCharInfo->getEntry())) +#else + if (event.getId() == "ok" && n_character > 0) +#endif + { + // Start game +#ifdef TMWSERV_SUPPORT + mNewCharButton->setEnabled(false); + mDelCharButton->setEnabled(false); + mUnRegisterButton->setEnabled(false); +#else + mNewDelCharButton->setEnabled(false); +#endif + mSelectButton->setEnabled(false); + mPreviousButton->setEnabled(false); + mNextButton->setEnabled(false); + mCharSelected = true; + attemptCharSelect(); + } + else if (event.getId() == "cancel") + { +#ifdef TMWSERV_SUPPORT + mCharInfo->clear(); + state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT; +#else + state = STATE_EXIT; +#endif + } +#ifdef TMWSERV_SUPPORT + else if (event.getId() == "new") + { + // TODO: Search the first free slot, and start CharCreateDialog + // maybe add that search to the constructor. + if (!(mCharInfo->getEntry())) + { + // Start new character dialog + CharCreateDialog *charCreateDialog = + new CharCreateDialog(this, mCharInfo->getPos()); + Net::getCharHandler()->setCharCreateDialog(charCreateDialog); + } + } + else if (event.getId() == "delete") + { + // Delete character + if (mCharInfo->getEntry()) + { + new CharDeleteConfirm(this); + } + } +#else + else if (event.getId() == "newdel") + { + // Check for a character + if (mCharInfo->getEntry()) + { + new CharDeleteConfirm(this); + } + else if (n_character <= maxSlot) + { + // Start new character dialog + CharCreateDialog *charCreateDialog = + new CharCreateDialog(this, mCharInfo->getPos()); + Net::getCharHandler()->setCharCreateDialog(charCreateDialog); + } + } +#endif + else if (event.getId() == "previous") + { + mCharInfo->prev(); + LocalPlayer *pi = mCharInfo->getEntry(); + if (pi) + mMoney = Units::formatCurrency(pi->getMoney()); + } + else if (event.getId() == "next") + { + mCharInfo->next(); + LocalPlayer *pi = mCharInfo->getEntry(); + if (pi) + mMoney = Units::formatCurrency(pi->getMoney()); + } +#ifdef TMWSERV_SUPPORT + else if (event.getId() == "unregister") + { + new UnRegisterDialog(this, mLoginData); + } + else if (event.getId() == "change_password") + { + new ChangePasswordDialog(this, mLoginData); + } + else if (event.getId() == "change_email") + { + new ChangeEmailDialog(this, mLoginData); + } +#endif +} + +void CharSelectDialog::updatePlayerInfo() +{ + LocalPlayer *pi = mCharInfo->getEntry(); + + if (pi) + { + mNameLabel->setCaption(strprintf(_("Name: %s"), + pi->getName().c_str())); + mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel())); +#ifndef TMWSERV_SUPPORT + mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), + pi->mJobLevel)); +#endif + mMoneyLabel->setCaption(strprintf(_("Money: %s"), mMoney.c_str())); + if (!mCharSelected) + { +#ifdef TMWSERV_SUPPORT + mNewCharButton->setEnabled(false); + mDelCharButton->setEnabled(true); +#else + mNewDelCharButton->setCaption(_("Delete")); +#endif + mSelectButton->setEnabled(true); + } + } + else + { + mNameLabel->setCaption(strprintf(_("Name: %s"), "")); + mLevelLabel->setCaption(strprintf(_("Level: %d"), 0)); +#ifndef TMWSERV_SUPPORT + mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), 0)); +#endif + mMoneyLabel->setCaption(strprintf(_("Money: %s"), "")); +#ifdef TMWSERV_SUPPORT + mNewCharButton->setEnabled(true); + mDelCharButton->setEnabled(false); +#else + mNewDelCharButton->setCaption(_("New")); +#endif + mSelectButton->setEnabled(false); + } + + mPlayerBox->setPlayer(pi); +} + +void CharSelectDialog::attemptCharDelete() +{ + Net::getCharHandler()->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry()); + mCharInfo->lock(); +} + +void CharSelectDialog::attemptCharSelect() +{ + Net::getCharHandler()->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry()); + mCharInfo->lock(); +} + +void CharSelectDialog::logic() +{ + updatePlayerInfo(); +} + +bool CharSelectDialog::selectByName(const std::string &name) +{ + if (mCharInfo->isLocked()) + return false; + + unsigned int oldPos = mCharInfo->getPos(); + + mCharInfo->select(0); + do + { + LocalPlayer *player = mCharInfo->getEntry(); + + if (player && player->getName() == name) + return true; + + mCharInfo->next(); + } while (mCharInfo->getPos()); + + mCharInfo->select(oldPos); + + return false; +} diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h new file mode 100644 index 00000000..75a98465 --- /dev/null +++ b/src/gui/charselectdialog.h @@ -0,0 +1,112 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef CHAR_SELECT_H +#define CHAR_SELECT_H + +#include "gui/widgets/window.h" + +#include "being.h" +#include "guichanfwd.h" +#include "lockedarray.h" + +#include + +#ifdef TMWSERV_SUPPORT +#include "../logindata.h" +#endif + +class LocalPlayer; +class Player; +class PlayerBox; + +/** + * Character selection dialog. + * + * \ingroup Interface + */ +class CharSelectDialog : public Window, public gcn::ActionListener +{ + public: + friend class CharDeleteConfirm; + /** + * Constructor. + */ +#ifdef TMWSERV_SUPPORT + CharSelectDialog(LockedArray *charInfo, + LoginData *loginData); +#else + CharSelectDialog(LockedArray *charInfo, + Gender gender); +#endif + + void action(const gcn::ActionEvent &event); + + void updatePlayerInfo(); + + void logic(); + + bool selectByName(const std::string &name); + + private: + LockedArray *mCharInfo; + + gcn::Button *mSelectButton; + gcn::Button *mCancelButton; + gcn::Button *mPreviousButton; + gcn::Button *mNextButton; + + gcn::Label *mNameLabel; + gcn::Label *mLevelLabel; + gcn::Label *mMoneyLabel; + std::string mMoney; + + PlayerBox *mPlayerBox; + + bool mCharSelected; + +#ifdef TMWSERV_SUPPORT + gcn::Button *mNewCharButton; + gcn::Button *mDelCharButton; + gcn::Button *mUnRegisterButton; + gcn::Button *mChangePasswordButton; + gcn::Button *mChangeEmailButton; + gcn::Label *mAccountNameLabel; + + LoginData *mLoginData; +#else + gcn::Button *mNewDelCharButton; + gcn::Label *mJobLevelLabel; + Gender mGender; +#endif + + /** + * Communicate character deletion to the server. + */ + void attemptCharDelete(); + + /** + * Communicate character selection to the server. + */ + void attemptCharSelect(); +}; + +#endif diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp deleted file mode 100644 index 7caa4580..00000000 --- a/src/gui/confirm_dialog.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/confirm_dialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/textbox.h" - -#include "gui/gui.h" - -#include "utils/gettext.h" - -#include - -ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, - Window *parent): - Window(title, true, parent) -{ - mTextBox = new TextBox; - mTextBox->setEditable(false); - mTextBox->setOpaque(false); - mTextBox->setTextWrapped(msg, 260); - - gcn::Button *yesButton = new Button(_("Yes"), "yes", this); - gcn::Button *noButton = new Button(_("No"), "no", this); - - const int numRows = mTextBox->getNumberOfRows(); - const int inWidth = yesButton->getWidth() + noButton->getWidth() + - (2 * getPadding()); - const int fontHeight = getFont()->getHeight(); - const int height = numRows * fontHeight; - int width = getFont()->getWidth(title); - - if (width < mTextBox->getMinWidth()) - width = mTextBox->getMinWidth(); - if (width < inWidth) - width = inWidth; - - setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight + - noButton->getHeight()); - mTextBox->setPosition(getPadding(), getPadding()); - - // 8 is the padding that GUIChan adds to button widgets - // (top and bottom combined) - yesButton->setPosition((width - inWidth) / 2, height + 8); - noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(), - height + 8); - - add(mTextBox); - add(yesButton); - add(noButton); - - if (getParent()) - { - center(); - getParent()->moveToTop(this); - } - setVisible(true); - yesButton->requestFocus(); -} - -void ConfirmDialog::action(const gcn::ActionEvent &event) -{ - // Proxy button events to our listeners - ActionListenerIterator i; - for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) - { - (*i)->action(event); - } - - // Can we receive anything else anyway? - if (event.getId() == "yes" || event.getId() == "no") - scheduleDelete(); -} diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h deleted file mode 100644 index 38ea2abd..00000000 --- a/src/gui/confirm_dialog.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef OPTION_DIALOG_H -#define OPTION_DIALOG_H - -#include "gui/widgets/window.h" - -#include - -class TextBox; - -/** - * An option dialog. - * - * \ingroup GUI - */ -class ConfirmDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - ConfirmDialog(const std::string &title, const std::string &msg, - Window *parent = NULL); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - private: - TextBox *mTextBox; -}; - -#endif diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp new file mode 100644 index 00000000..19c32999 --- /dev/null +++ b/src/gui/confirmdialog.cpp @@ -0,0 +1,92 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/confirmdialog.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/textbox.h" + +#include "gui/gui.h" + +#include "utils/gettext.h" + +#include + +ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, + Window *parent): + Window(title, true, parent) +{ + mTextBox = new TextBox; + mTextBox->setEditable(false); + mTextBox->setOpaque(false); + mTextBox->setTextWrapped(msg, 260); + + gcn::Button *yesButton = new Button(_("Yes"), "yes", this); + gcn::Button *noButton = new Button(_("No"), "no", this); + + const int numRows = mTextBox->getNumberOfRows(); + const int inWidth = yesButton->getWidth() + noButton->getWidth() + + (2 * getPadding()); + const int fontHeight = getFont()->getHeight(); + const int height = numRows * fontHeight; + int width = getFont()->getWidth(title); + + if (width < mTextBox->getMinWidth()) + width = mTextBox->getMinWidth(); + if (width < inWidth) + width = inWidth; + + setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight + + noButton->getHeight()); + mTextBox->setPosition(getPadding(), getPadding()); + + // 8 is the padding that GUIChan adds to button widgets + // (top and bottom combined) + yesButton->setPosition((width - inWidth) / 2, height + 8); + noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(), + height + 8); + + add(mTextBox); + add(yesButton); + add(noButton); + + if (getParent()) + { + center(); + getParent()->moveToTop(this); + } + setVisible(true); + yesButton->requestFocus(); +} + +void ConfirmDialog::action(const gcn::ActionEvent &event) +{ + // Proxy button events to our listeners + ActionListenerIterator i; + for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) + { + (*i)->action(event); + } + + // Can we receive anything else anyway? + if (event.getId() == "yes" || event.getId() == "no") + scheduleDelete(); +} diff --git a/src/gui/confirmdialog.h b/src/gui/confirmdialog.h new file mode 100644 index 00000000..38ea2abd --- /dev/null +++ b/src/gui/confirmdialog.h @@ -0,0 +1,56 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef OPTION_DIALOG_H +#define OPTION_DIALOG_H + +#include "gui/widgets/window.h" + +#include + +class TextBox; + +/** + * An option dialog. + * + * \ingroup GUI + */ +class ConfirmDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + ConfirmDialog(const std::string &title, const std::string &msg, + Window *parent = NULL); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + private: + TextBox *mTextBox; +}; + +#endif diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index a6bcb690..6dc86e13 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -22,7 +22,7 @@ #include "gui/guildwindow.h" -#include "gui/confirm_dialog.h" +#include "gui/confirmdialog.h" #include "gui/guildlistbox.h" #include "gui/textdialog.h" diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 33115f96..2b397ed7 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -21,7 +21,7 @@ #include "gui/inventorywindow.h" -#include "gui/item_amount.h" +#include "gui/itemamount.h" #include "gui/itemcontainer.h" #include "gui/sdlinput.h" #include "gui/viewport.h" diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp deleted file mode 100644 index d259481e..00000000 --- a/src/gui/item_amount.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/item_amount.h" - -#ifdef EATHENA_SUPPORT -#include "gui/storagewindow.h" -#endif -#include "gui/trade.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/slider.h" - -#include "item.h" -#include "localplayer.h" - -#include "utils/gettext.h" -#include "utils/strprintf.h" - -ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, - int maxRange): - Window("", true, parent), - mItem(item), - mMax(maxRange), - mUsage(usage) -{ - if (!mMax) - mMax = mItem->getQuantity(); - - setCloseButton(true); - - // Integer field - - mItemAmountLabel = new Label(strprintf("%d / %d", 1, mMax)); - mItemAmountLabel->setAlignment(gcn::Graphics::CENTER); - - // Slider - mItemAmountSlide = new Slider(1.0, mMax); - mItemAmountSlide->setHeight(10); - mItemAmountSlide->setActionEventId("Slide"); - mItemAmountSlide->addActionListener(this); - - // Buttons - Button *minusButton = new Button("-", "Minus", this); - Button *plusButton = new Button("+", "Plus", this); - Button *okButton = new Button(_("Ok"), "Ok", this); - Button *cancelButton = new Button(_("Cancel"), "Cancel", this); - Button *addAllButton = new Button(_("All"), "All", this); - - minusButton->adjustSize(); - minusButton->setWidth(plusButton->getWidth()); - - // Set positions - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, minusButton); - place(1, 0, mItemAmountSlide, 3); - place(4, 0, plusButton); - place(5, 0, mItemAmountLabel, 2); - place(7, 0, addAllButton); - place = getPlacer(0, 1); - place(4, 0, cancelButton); - place(5, 0, okButton); - reflowLayout(225, 0); - - resetAmount(); - - switch (usage) - { - case TradeAdd: - setCaption(_("Select amount of items to trade.")); - break; - case ItemDrop: - setCaption(_("Select amount of items to drop.")); - break; - case StoreAdd: - setCaption(_("Select amount of items to store.")); - break; - case StoreRemove: - setCaption(_("Select amount of items to retrieve.")); - break; - case ItemSplit: - setCaption(_("Select amount of items to split.")); - break; - } - - setLocationRelativeTo(getParentWindow()); - setVisible(true); -} - -void ItemAmountWindow::resetAmount() -{ - mItemAmountLabel->setCaption(strprintf("%d / %d", 1, mMax)); -} - -void ItemAmountWindow::action(const gcn::ActionEvent &event) -{ - int amount = mItemAmountSlide->getValue(); - - if (event.getId() == "Cancel") - { - close(); - } - else if (event.getId() == "Plus" && amount < mMax) - { - amount++; - } - else if (event.getId() == "Minus" && amount > 1) - { - amount--; - } - else if (event.getId() == "Slide") - { - amount = static_cast(mItemAmountSlide->getValue()); - } - else if (event.getId() == "Ok" || event.getId() == "All") - { - if (event.getId() == "All") - amount = mMax; - - switch (mUsage) - { - case TradeAdd: - tradeWindow->tradeItem(mItem, amount); - break; - case ItemDrop: - player_node->dropItem(mItem, amount); - break; -#ifdef TMWSERV_SUPPORT - case ItemSplit: - player_node->splitItem(mItem, amount); - break; -#else - case StoreAdd: - storageWindow->addStore(mItem, amount); - break; - case StoreRemove: - storageWindow->removeStore(mItem, amount); - break; -#endif - default: - return; - break; - } - - scheduleDelete(); - return; - } - - mItemAmountLabel->setCaption(strprintf("%d / %d", amount, mMax)); - mItemAmountSlide->setValue(amount); -} - -void ItemAmountWindow::close() -{ - scheduleDelete(); -} diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h deleted file mode 100644 index 94ca8dc2..00000000 --- a/src/gui/item_amount.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef ITEM_AMOUNT_WINDOW_H -#define ITEM_AMOUNT_WINDOW_H - -#include "gui/widgets/window.h" - -#include - -class Item; - -/** - * Window used for selecting the amount of items to drop, trade or split. - * - * \ingroup Interface - */ -class ItemAmountWindow : public Window, public gcn::ActionListener -{ - public: - enum Usage { - TradeAdd, - ItemDrop, - StoreAdd, - StoreRemove, - ItemSplit - }; - - /** - * Constructor. - */ - ItemAmountWindow(Usage usage, Window *parent, Item *item, - int maxRange = 0); - - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &event); - - /** - * Sets default amount value. - */ - void resetAmount(); - - /** - * Schedules the Item Amount window for deletion. - */ - void close(); - - private: - gcn::Label *mItemAmountLabel; /**< Item amount caption. */ - Item *mItem; - - int mMax; - Usage mUsage; - - /** - * Item Amount buttons. - */ - gcn::Slider *mItemAmountSlide; -}; - -#endif /* ITEM_AMOUNT_WINDOW_H */ diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp new file mode 100644 index 00000000..518eb761 --- /dev/null +++ b/src/gui/itemamount.cpp @@ -0,0 +1,178 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/itemamount.h" + +#ifdef EATHENA_SUPPORT +#include "gui/storagewindow.h" +#endif +#include "gui/trade.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/slider.h" + +#include "item.h" +#include "localplayer.h" + +#include "utils/gettext.h" +#include "utils/strprintf.h" + +ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange): + Window("", true, parent), + mItem(item), + mMax(maxRange), + mUsage(usage) +{ + if (!mMax) + mMax = mItem->getQuantity(); + + setCloseButton(true); + + // Integer field + + mItemAmountLabel = new Label(strprintf("%d / %d", 1, mMax)); + mItemAmountLabel->setAlignment(gcn::Graphics::CENTER); + + // Slider + mItemAmountSlide = new Slider(1.0, mMax); + mItemAmountSlide->setHeight(10); + mItemAmountSlide->setActionEventId("Slide"); + mItemAmountSlide->addActionListener(this); + + // Buttons + Button *minusButton = new Button("-", "Minus", this); + Button *plusButton = new Button("+", "Plus", this); + Button *okButton = new Button(_("Ok"), "Ok", this); + Button *cancelButton = new Button(_("Cancel"), "Cancel", this); + Button *addAllButton = new Button(_("All"), "All", this); + + minusButton->adjustSize(); + minusButton->setWidth(plusButton->getWidth()); + + // Set positions + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, minusButton); + place(1, 0, mItemAmountSlide, 3); + place(4, 0, plusButton); + place(5, 0, mItemAmountLabel, 2); + place(7, 0, addAllButton); + place = getPlacer(0, 1); + place(4, 0, cancelButton); + place(5, 0, okButton); + reflowLayout(225, 0); + + resetAmount(); + + switch (usage) + { + case TradeAdd: + setCaption(_("Select amount of items to trade.")); + break; + case ItemDrop: + setCaption(_("Select amount of items to drop.")); + break; + case StoreAdd: + setCaption(_("Select amount of items to store.")); + break; + case StoreRemove: + setCaption(_("Select amount of items to retrieve.")); + break; + case ItemSplit: + setCaption(_("Select amount of items to split.")); + break; + } + + setLocationRelativeTo(getParentWindow()); + setVisible(true); +} + +void ItemAmountWindow::resetAmount() +{ + mItemAmountLabel->setCaption(strprintf("%d / %d", 1, mMax)); +} + +void ItemAmountWindow::action(const gcn::ActionEvent &event) +{ + int amount = mItemAmountSlide->getValue(); + + if (event.getId() == "Cancel") + { + close(); + } + else if (event.getId() == "Plus" && amount < mMax) + { + amount++; + } + else if (event.getId() == "Minus" && amount > 1) + { + amount--; + } + else if (event.getId() == "Slide") + { + amount = static_cast(mItemAmountSlide->getValue()); + } + else if (event.getId() == "Ok" || event.getId() == "All") + { + if (event.getId() == "All") + amount = mMax; + + switch (mUsage) + { + case TradeAdd: + tradeWindow->tradeItem(mItem, amount); + break; + case ItemDrop: + player_node->dropItem(mItem, amount); + break; +#ifdef TMWSERV_SUPPORT + case ItemSplit: + player_node->splitItem(mItem, amount); + break; +#else + case StoreAdd: + storageWindow->addStore(mItem, amount); + break; + case StoreRemove: + storageWindow->removeStore(mItem, amount); + break; +#endif + default: + return; + break; + } + + scheduleDelete(); + return; + } + + mItemAmountLabel->setCaption(strprintf("%d / %d", amount, mMax)); + mItemAmountSlide->setValue(amount); +} + +void ItemAmountWindow::close() +{ + scheduleDelete(); +} diff --git a/src/gui/itemamount.h b/src/gui/itemamount.h new file mode 100644 index 00000000..94ca8dc2 --- /dev/null +++ b/src/gui/itemamount.h @@ -0,0 +1,81 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ITEM_AMOUNT_WINDOW_H +#define ITEM_AMOUNT_WINDOW_H + +#include "gui/widgets/window.h" + +#include + +class Item; + +/** + * Window used for selecting the amount of items to drop, trade or split. + * + * \ingroup Interface + */ +class ItemAmountWindow : public Window, public gcn::ActionListener +{ + public: + enum Usage { + TradeAdd, + ItemDrop, + StoreAdd, + StoreRemove, + ItemSplit + }; + + /** + * Constructor. + */ + ItemAmountWindow(Usage usage, Window *parent, Item *item, + int maxRange = 0); + + /** + * Called when receiving actions from widget. + */ + void action(const gcn::ActionEvent &event); + + /** + * Sets default amount value. + */ + void resetAmount(); + + /** + * Schedules the Item Amount window for deletion. + */ + void close(); + + private: + gcn::Label *mItemAmountLabel; /**< Item amount caption. */ + Item *mItem; + + int mMax; + Usage mUsage; + + /** + * Item Amount buttons. + */ + gcn::Slider *mItemAmountSlide; +}; + +#endif /* ITEM_AMOUNT_WINDOW_H */ diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 021f8d4b..8391a5c4 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -21,7 +21,7 @@ #include "gui/login.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp deleted file mode 100644 index 770683eb..00000000 --- a/src/gui/npc_text.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/npc_text.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/textbox.h" - -#include "npc.h" - -#include "net/net.h" -#include "net/npchandler.h" - -#include "utils/gettext.h" - -NpcTextDialog::NpcTextDialog() - : Window(_("NPC")) - , mState(NPC_TEXT_STATE_WAITING) -{ - setWindowName("NPCText"); - setResizable(true); - - setMinWidth(200); - setMinHeight(150); - - setDefaultSize(260, 200, ImageRect::CENTER); - - mTextBox = new TextBox; - mTextBox->setEditable(false); - mTextBox->setOpaque(false); - - mScrollArea = new ScrollArea(mTextBox); - mButton = new Button(_("Waiting for server"), "ok", this); - - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); - - place(0, 0, mScrollArea, 5).setPadding(3); - place(4, 1, mButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - center(); - loadWindowState(); -} - -void NpcTextDialog::clearText() -{ - NPC::isTalking = false; - setText(""); -} - -void NpcTextDialog::setText(const std::string &text) -{ - mText = text; - mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15); -} - -void NpcTextDialog::addText(const std::string &text) -{ - setText(mText + text + "\n"); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); -} - -void NpcTextDialog::showNextButton() -{ - mButton->setCaption(_("Next")); - mState = NPC_TEXT_STATE_NEXT; - mButton->setEnabled(true); -} - -void NpcTextDialog::showCloseButton() -{ - mButton->setCaption(_("Close")); - mState = NPC_TEXT_STATE_CLOSE; - mButton->setEnabled(true); -} - -void NpcTextDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "ok") - { - if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - nextDialog(); - addText("\n> Next\n"); - } else if (mState == NPC_TEXT_STATE_CLOSE || - (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { - setText(""); - if (current_npc) nextDialog(); - setVisible(false); - current_npc = 0; - NPC::isTalking = false; - } else return; - } - else return; - - mButton->setEnabled(false); - mButton->setCaption(_("Waiting for server")); - mState = NPC_TEXT_STATE_WAITING; -} - -void NpcTextDialog::nextDialog(int npcID) -{ - Net::getNpcHandler()->nextDialog(npcID); -} - -void NpcTextDialog::closeDialog(int npcID) -{ - Net::getNpcHandler()->closeDialog(npcID); -} - -void NpcTextDialog::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - setText(mText); -} diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h deleted file mode 100644 index ad32fdf4..00000000 --- a/src/gui/npc_text.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef NPC_TEXT_H -#define NPC_TEXT_H - -#include "gui/widgets/window.h" - -#include "npc.h" - -#include - -#include - -class TextBox; - -/** - * The npc text dialog. - * - * \ingroup Interface - */ -class NpcTextDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - NpcTextDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - /** - * Clears the text shown in the dialog. - */ - void clearText(); - - /** - * Sets the text shows in the dialog. - * - * @param string The new text. - */ - void setText(const std::string &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 std::string &string); - - void showNextButton(); - - void showCloseButton(); - - /** - * Notifies the server that the client has performed a next action. - */ - void nextDialog(int npcID = current_npc); - - /** - * Notifies the server that the client has performed a close action. - */ - void closeDialog(int npcID = current_npc); - - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - - private: - gcn::ScrollArea *mScrollArea; - TextBox *mTextBox; - gcn::Button *mButton; - - std::string mText; - - enum NPCTextState { - NPC_TEXT_STATE_WAITING, - NPC_TEXT_STATE_NEXT, - NPC_TEXT_STATE_CLOSE - }; - NPCTextState mState; -}; - -extern NpcTextDialog *npcTextDialog; - -#endif // NPC_TEXT_H diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 2a04acd2..41b6985c 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,7 +21,7 @@ #include "gui/npcintegerdialog.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/inttextfield.h" diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 97f9fdb7..65e4263e 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -21,7 +21,7 @@ #include "gui/npclistdialog.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/layout.h" diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 446078e8..e5767c5f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -21,7 +21,7 @@ #include "gui/npcstringdialog.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/layout.h" diff --git a/src/gui/npctextdialog.cpp b/src/gui/npctextdialog.cpp new file mode 100644 index 00000000..849c94ec --- /dev/null +++ b/src/gui/npctextdialog.cpp @@ -0,0 +1,138 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/npctextdialog.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/textbox.h" + +#include "npc.h" + +#include "net/net.h" +#include "net/npchandler.h" + +#include "utils/gettext.h" + +NpcTextDialog::NpcTextDialog() + : Window(_("NPC")) + , mState(NPC_TEXT_STATE_WAITING) +{ + setWindowName("NPCText"); + setResizable(true); + + setMinWidth(200); + setMinHeight(150); + + setDefaultSize(260, 200, ImageRect::CENTER); + + mTextBox = new TextBox; + mTextBox->setEditable(false); + mTextBox->setOpaque(false); + + mScrollArea = new ScrollArea(mTextBox); + mButton = new Button(_("Waiting for server"), "ok", this); + + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + + place(0, 0, mScrollArea, 5).setPadding(3); + place(4, 1, mButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + + center(); + loadWindowState(); +} + +void NpcTextDialog::clearText() +{ + NPC::isTalking = false; + setText(""); +} + +void NpcTextDialog::setText(const std::string &text) +{ + mText = text; + mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15); +} + +void NpcTextDialog::addText(const std::string &text) +{ + setText(mText + text + "\n"); + mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); +} + +void NpcTextDialog::showNextButton() +{ + mButton->setCaption(_("Next")); + mState = NPC_TEXT_STATE_NEXT; + mButton->setEnabled(true); +} + +void NpcTextDialog::showCloseButton() +{ + mButton->setCaption(_("Close")); + mState = NPC_TEXT_STATE_CLOSE; + mButton->setEnabled(true); +} + +void NpcTextDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "ok") + { + if (mState == NPC_TEXT_STATE_NEXT && current_npc) { + nextDialog(); + addText("\n> Next\n"); + } else if (mState == NPC_TEXT_STATE_CLOSE || + (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { + setText(""); + if (current_npc) nextDialog(); + setVisible(false); + current_npc = 0; + NPC::isTalking = false; + } else return; + } + else return; + + mButton->setEnabled(false); + mButton->setCaption(_("Waiting for server")); + mState = NPC_TEXT_STATE_WAITING; +} + +void NpcTextDialog::nextDialog(int npcID) +{ + Net::getNpcHandler()->nextDialog(npcID); +} + +void NpcTextDialog::closeDialog(int npcID) +{ + Net::getNpcHandler()->closeDialog(npcID); +} + +void NpcTextDialog::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + + setText(mText); +} diff --git a/src/gui/npctextdialog.h b/src/gui/npctextdialog.h new file mode 100644 index 00000000..ad32fdf4 --- /dev/null +++ b/src/gui/npctextdialog.h @@ -0,0 +1,113 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef NPC_TEXT_H +#define NPC_TEXT_H + +#include "gui/widgets/window.h" + +#include "npc.h" + +#include + +#include + +class TextBox; + +/** + * The npc text dialog. + * + * \ingroup Interface + */ +class NpcTextDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + NpcTextDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Clears the text shown in the dialog. + */ + void clearText(); + + /** + * Sets the text shows in the dialog. + * + * @param string The new text. + */ + void setText(const std::string &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 std::string &string); + + void showNextButton(); + + void showCloseButton(); + + /** + * Notifies the server that the client has performed a next action. + */ + void nextDialog(int npcID = current_npc); + + /** + * Notifies the server that the client has performed a close action. + */ + void closeDialog(int npcID = current_npc); + + /** + * Called when resizing the window. + * + * @param event The calling event + */ + void widgetResized(const gcn::Event &event); + + private: + gcn::ScrollArea *mScrollArea; + TextBox *mTextBox; + gcn::Button *mButton; + + std::string mText; + + enum NPCTextState { + NPC_TEXT_STATE_WAITING, + NPC_TEXT_STATE_NEXT, + NPC_TEXT_STATE_CLOSE + }; + NPCTextState mState; +}; + +extern NpcTextDialog *npcTextDialog; + +#endif // NPC_TEXT_H diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp deleted file mode 100644 index fc8c81db..00000000 --- a/src/gui/ok_dialog.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/ok_dialog.h" - -#include "gui/gui.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/textbox.h" - -#include "utils/gettext.h" - -#include - -OkDialog::OkDialog(const std::string &title, const std::string &msg, - Window *parent): - Window(title, true, parent) -{ - mTextBox = new TextBox; - mTextBox->setEditable(false); - mTextBox->setOpaque(false); - mTextBox->setTextWrapped(msg, 260); - - gcn::Button *okButton = new Button(_("Ok"), "ok", this); - - const int numRows = mTextBox->getNumberOfRows(); - const int fontHeight = getFont()->getHeight(); - const int height = numRows * fontHeight; - int width = getFont()->getWidth(title); - - if (width < mTextBox->getMinWidth()) - width = mTextBox->getMinWidth(); - if (width < okButton->getWidth()) - width = okButton->getWidth(); - - setContentSize(mTextBox->getMinWidth() + fontHeight, height + - fontHeight + okButton->getHeight()); - mTextBox->setPosition(getPadding(), getPadding()); - - // 8 is the padding that GUIChan adds to button widgets - // (top and bottom combined) - okButton->setPosition((width - okButton->getWidth()) / 2, height + 8); - - add(mTextBox); - add(okButton); - - center(); - setVisible(true); - okButton->requestFocus(); -} - -void OkDialog::action(const gcn::ActionEvent &event) -{ - // Proxy button events to our listeners - ActionListenerIterator i; - for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) - { - (*i)->action(event); - } - - // Can we receive anything else anyway? - if (event.getId() == "ok") - scheduleDelete(); -} diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h deleted file mode 100644 index 5df2fb4f..00000000 --- a/src/gui/ok_dialog.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef OK_DIALOG_H -#define OK_DIALOG_H - -#include "gui/widgets/window.h" - -#include - -class TextBox; - -/** - * An 'Ok' button dialog. - * - * \ingroup GUI - */ -class OkDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - * - * @see Window::Window - */ - OkDialog(const std::string &title, const std::string &msg, - Window *parent = NULL); - - /** - * Called when receiving actions from the widgets. - */ - void action(const gcn::ActionEvent &event); - - private: - TextBox *mTextBox; -}; - -#endif diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp new file mode 100644 index 00000000..9da070eb --- /dev/null +++ b/src/gui/okdialog.cpp @@ -0,0 +1,82 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/okdialog.h" + +#include "gui/gui.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/textbox.h" + +#include "utils/gettext.h" + +#include + +OkDialog::OkDialog(const std::string &title, const std::string &msg, + Window *parent): + Window(title, true, parent) +{ + mTextBox = new TextBox; + mTextBox->setEditable(false); + mTextBox->setOpaque(false); + mTextBox->setTextWrapped(msg, 260); + + gcn::Button *okButton = new Button(_("Ok"), "ok", this); + + const int numRows = mTextBox->getNumberOfRows(); + const int fontHeight = getFont()->getHeight(); + const int height = numRows * fontHeight; + int width = getFont()->getWidth(title); + + if (width < mTextBox->getMinWidth()) + width = mTextBox->getMinWidth(); + if (width < okButton->getWidth()) + width = okButton->getWidth(); + + setContentSize(mTextBox->getMinWidth() + fontHeight, height + + fontHeight + okButton->getHeight()); + mTextBox->setPosition(getPadding(), getPadding()); + + // 8 is the padding that GUIChan adds to button widgets + // (top and bottom combined) + okButton->setPosition((width - okButton->getWidth()) / 2, height + 8); + + add(mTextBox); + add(okButton); + + center(); + setVisible(true); + okButton->requestFocus(); +} + +void OkDialog::action(const gcn::ActionEvent &event) +{ + // Proxy button events to our listeners + ActionListenerIterator i; + for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) + { + (*i)->action(event); + } + + // Can we receive anything else anyway? + if (event.getId() == "ok") + scheduleDelete(); +} diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h new file mode 100644 index 00000000..5df2fb4f --- /dev/null +++ b/src/gui/okdialog.h @@ -0,0 +1,56 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef OK_DIALOG_H +#define OK_DIALOG_H + +#include "gui/widgets/window.h" + +#include + +class TextBox; + +/** + * An 'Ok' button dialog. + * + * \ingroup GUI + */ +class OkDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + OkDialog(const std::string &title, const std::string &msg, + Window *parent = NULL); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + private: + TextBox *mTextBox; +}; + +#endif diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h index 63646008..c915d9ce 100644 --- a/src/gui/partywindow.h +++ b/src/gui/partywindow.h @@ -22,7 +22,7 @@ #ifndef PARTYWINDOW_H #define PARTYWINDOW_H -#include "gui/confirm_dialog.h" +#include "gui/confirmdialog.h" #include "gui/widgets/avatar.h" #include "gui/widgets/window.h" diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 2c820bab..c76a9065 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -23,18 +23,18 @@ #include "gui/chat.h" #include "gui/inventorywindow.h" -#include "gui/item_amount.h" +#include "gui/itemamount.h" #include "gui/widgets/browserbox.h" #include "being.h" #include "beingmanager.h" -#include "floor_item.h" +#include "flooritem.h" #include "graphics.h" #include "item.h" #include "localplayer.h" #include "npc.h" -#include "player_relations.h" +#include "playerrelations.h" #include "net/adminhandler.h" #include "net/net.h" diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 04da656b..dabf98fd 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -27,7 +27,7 @@ #include "main.h" #include "gui/login.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 9fb6b6a2..f3b0739a 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -21,7 +21,7 @@ #include "gui/serverdialog.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/dropdown.h" diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 05a9eaa2..9417ad68 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -21,7 +21,7 @@ #include "gui/setup_audio.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 9e43b322..0c15a1ee 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -22,7 +22,7 @@ #include "gui/setup_keyboard.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/button.h" #include "gui/widgets/layouthelper.h" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 367d21a2..01a99567 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -21,7 +21,7 @@ #include "gui/setup_players.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/table.h" #include "gui/widgets/button.h" diff --git a/src/gui/setup_players.h b/src/gui/setup_players.h index c2e6a682..d7507d19 100644 --- a/src/gui/setup_players.h +++ b/src/gui/setup_players.h @@ -26,7 +26,7 @@ #include "gui/setuptab.h" -#include "player_relations.h" +#include "playerrelations.h" #include diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 4cae18ba..bf20658c 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -21,7 +21,7 @@ #include "gui/setup_video.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index df6df65a..aada0bb2 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -20,8 +20,9 @@ */ #include "gui/storagewindow.h" + #include "gui/inventorywindow.h" -#include "gui/item_amount.h" +#include "gui/itemamount.h" #include "gui/itemcontainer.h" #include "gui/viewport.h" diff --git a/src/gui/table.h b/src/gui/table.h index d73cf340..42fbab0e 100644 --- a/src/gui/table.h +++ b/src/gui/table.h @@ -22,13 +22,13 @@ #ifndef TABLE_H #define TABLE_H -#include +#include "tablemodel.h" #include #include #include -#include "table_model.h" +#include class GuiTableActionListener; diff --git a/src/gui/table_model.cpp b/src/gui/table_model.cpp deleted file mode 100644 index 4fa13bae..00000000 --- a/src/gui/table_model.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include "table_model.h" - -#include "../utils/dtor.h" - -void TableModel::installListener(TableModelListener *listener) -{ - listeners.insert(listener); -} - -void TableModel::removeListener(TableModelListener *listener) -{ - listeners.erase(listener); -} - -void TableModel::signalBeforeUpdate() -{ - for (std::set::const_iterator it = listeners.begin(); it != listeners.end(); it++) - (*it)->modelUpdated(false); -} - -void TableModel::signalAfterUpdate() -{ - for (std::set::const_iterator it = listeners.begin(); it != listeners.end(); it++) - (*it)->modelUpdated(true); -} - - -#define WIDGET_AT(row, column) (((row) * mColumns) + (column)) -#define DYN_SIZE(h) ((h) >= 0) // determines whether this size is tagged for auto-detection - -StaticTableModel::StaticTableModel(int row, int column) : - mRows(row), - mColumns(column), - mHeight(1) -{ - mTableModel.resize(row * column, NULL); - mWidths.resize(column, 1); -} - -StaticTableModel::~StaticTableModel() -{ - delete_all(mTableModel); -} - -void StaticTableModel::resize() -{ - mRows = getRows(); - mColumns = getColumns(); - mTableModel.resize(mRows * mColumns, NULL); -} - -void StaticTableModel::set(int row, int column, gcn::Widget *widget) -{ - if (row >= mRows || row < 0 - || column >= mColumns || column < 0) - // raise exn? - return; - - if (DYN_SIZE(mHeight) - && widget->getHeight() > mHeight) - mHeight = widget->getHeight(); - - if (DYN_SIZE(mWidths[column]) - && widget->getWidth() > mWidths[column]) - mWidths[column] = widget->getWidth(); - - signalBeforeUpdate(); - - if (mTableModel[WIDGET_AT(row, column)]) - delete mTableModel[WIDGET_AT(row, column)]; - - mTableModel[WIDGET_AT(row, column)] = widget; - - signalAfterUpdate(); -} - -gcn::Widget *StaticTableModel::getElementAt(int row, int column) -{ - return mTableModel[WIDGET_AT(row, column)]; -} - -void StaticTableModel::fixColumnWidth(int column, int width) -{ - if (width < 0 - || column < 0 || column >= mColumns) - return; - - mWidths[column] = -width; // Negate to tag as fixed -} - -void StaticTableModel::fixRowHeight(int height) -{ - if (height < 0) - return; - - mHeight = -height; -} - -int StaticTableModel::getRowHeight() -{ - return abs(mHeight); -} - -int StaticTableModel::getColumnWidth(int column) -{ - if (column < 0 || column >= mColumns) - return 0; - - return abs(mWidths[column]); -} - -int StaticTableModel::getRows() -{ - return mRows; -} - -int StaticTableModel::getColumns() -{ - return mColumns; -} - -int StaticTableModel::getWidth(void) -{ - int width = 0; - - for (unsigned int i = 0; i < mWidths.size(); i++) - { - width += mWidths[i]; - } - - return width; -} - -int StaticTableModel::getHeight(void) -{ - return (mColumns * mHeight); -} - diff --git a/src/gui/table_model.h b/src/gui/table_model.h deleted file mode 100644 index 9ca36120..00000000 --- a/src/gui/table_model.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TABLE_MODEL_H -#define TABLE_MODEL_H - -#include -#include - -class TableModelListener -{ -public: - /** - * Must be invoked by the TableModel whenever a global change is about to - * occur or has occurred (e.g., when a row or column is being removed or - * added). - * - * This method is triggered twice, once before and once after the update. - * - * \param completed whether we are signalling the end of the update - */ - virtual void modelUpdated(bool completed) = 0; -}; - -/** - * A model for a regular table of widgets. - */ -class TableModel -{ -public: - virtual ~TableModel() { } - - /** - * Determines the number of rows (lines) in the table - */ - virtual int getRows() = 0; - - /** - * Determines the number of columns in each row - */ - virtual int getColumns() = 0; - - /** - * Determines the height for each row - */ - virtual int getRowHeight() = 0; - - /** - * Determines the width of each individual column - */ - virtual int getColumnWidth(int index) = 0; - - /** - * Retrieves the widget stored at the specified location within the table. - */ - virtual gcn::Widget *getElementAt(int row, int column) = 0; - - virtual void installListener(TableModelListener *listener); - - virtual void removeListener(TableModelListener *listener); - -protected: - /** - * Tells all listeners that the table is about to see an update - */ - virtual void signalBeforeUpdate(); - - /** - * Tells all listeners that the table has seen an update - */ - virtual void signalAfterUpdate(); - -private: - std::set listeners; -}; - - -class StaticTableModel : public TableModel -{ -public: - StaticTableModel(int width, int height); - virtual ~StaticTableModel(); - - /** - * Inserts a widget into the table model. - * The model is resized to accomodate the widget's width and height, - * unless column width / row height have been fixed. - */ - virtual void set(int row, int column, gcn::Widget *widget); - - /** - * Fixes the column width for a given column; this overrides dynamic width - * inference. - * - * Semantics are undefined for width 0. - */ - virtual void fixColumnWidth(int column, int width); - - /** - * Fixes the row height; this overrides dynamic height inference. - * - * Semantics are undefined for width 0. - */ - virtual void fixRowHeight(int height); - - /** - * Resizes the table model - */ - virtual void resize(); - - virtual int getRows(); - virtual int getColumns(); - virtual int getRowHeight(); - virtual int getWidth(); - virtual int getHeight(); - virtual int getColumnWidth(int index); - virtual gcn::Widget *getElementAt(int row, int column); - -protected: - int mRows, mColumns; - int mHeight; - std::vector mTableModel; - std::vector mWidths; -}; - -#endif /* !defined(TABLE_MODEL_H) */ diff --git a/src/gui/tablemodel.cpp b/src/gui/tablemodel.cpp new file mode 100644 index 00000000..e362a314 --- /dev/null +++ b/src/gui/tablemodel.cpp @@ -0,0 +1,161 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "tablemodel.h" + +#include "utils/dtor.h" + +#include + +void TableModel::installListener(TableModelListener *listener) +{ + listeners.insert(listener); +} + +void TableModel::removeListener(TableModelListener *listener) +{ + listeners.erase(listener); +} + +void TableModel::signalBeforeUpdate() +{ + for (std::set::const_iterator it = listeners.begin(); it != listeners.end(); it++) + (*it)->modelUpdated(false); +} + +void TableModel::signalAfterUpdate() +{ + for (std::set::const_iterator it = listeners.begin(); it != listeners.end(); it++) + (*it)->modelUpdated(true); +} + + +#define WIDGET_AT(row, column) (((row) * mColumns) + (column)) +#define DYN_SIZE(h) ((h) >= 0) // determines whether this size is tagged for auto-detection + +StaticTableModel::StaticTableModel(int row, int column) : + mRows(row), + mColumns(column), + mHeight(1) +{ + mTableModel.resize(row * column, NULL); + mWidths.resize(column, 1); +} + +StaticTableModel::~StaticTableModel() +{ + delete_all(mTableModel); +} + +void StaticTableModel::resize() +{ + mRows = getRows(); + mColumns = getColumns(); + mTableModel.resize(mRows * mColumns, NULL); +} + +void StaticTableModel::set(int row, int column, gcn::Widget *widget) +{ + if (row >= mRows || row < 0 + || column >= mColumns || column < 0) + // raise exn? + return; + + if (DYN_SIZE(mHeight) + && widget->getHeight() > mHeight) + mHeight = widget->getHeight(); + + if (DYN_SIZE(mWidths[column]) + && widget->getWidth() > mWidths[column]) + mWidths[column] = widget->getWidth(); + + signalBeforeUpdate(); + + if (mTableModel[WIDGET_AT(row, column)]) + delete mTableModel[WIDGET_AT(row, column)]; + + mTableModel[WIDGET_AT(row, column)] = widget; + + signalAfterUpdate(); +} + +gcn::Widget *StaticTableModel::getElementAt(int row, int column) +{ + return mTableModel[WIDGET_AT(row, column)]; +} + +void StaticTableModel::fixColumnWidth(int column, int width) +{ + if (width < 0 + || column < 0 || column >= mColumns) + return; + + mWidths[column] = -width; // Negate to tag as fixed +} + +void StaticTableModel::fixRowHeight(int height) +{ + if (height < 0) + return; + + mHeight = -height; +} + +int StaticTableModel::getRowHeight() +{ + return abs(mHeight); +} + +int StaticTableModel::getColumnWidth(int column) +{ + if (column < 0 || column >= mColumns) + return 0; + + return abs(mWidths[column]); +} + +int StaticTableModel::getRows() +{ + return mRows; +} + +int StaticTableModel::getColumns() +{ + return mColumns; +} + +int StaticTableModel::getWidth(void) +{ + int width = 0; + + for (unsigned int i = 0; i < mWidths.size(); i++) + { + width += mWidths[i]; + } + + return width; +} + +int StaticTableModel::getHeight(void) +{ + return (mColumns * mHeight); +} + diff --git a/src/gui/tablemodel.h b/src/gui/tablemodel.h new file mode 100644 index 00000000..a884932f --- /dev/null +++ b/src/gui/tablemodel.h @@ -0,0 +1,146 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TABLE_MODEL_H +#define TABLE_MODEL_H + +#include + +#include +#include + +class TableModelListener +{ +public: + /** + * Must be invoked by the TableModel whenever a global change is about to + * occur or has occurred (e.g., when a row or column is being removed or + * added). + * + * This method is triggered twice, once before and once after the update. + * + * \param completed whether we are signalling the end of the update + */ + virtual void modelUpdated(bool completed) = 0; +}; + +/** + * A model for a regular table of widgets. + */ +class TableModel +{ +public: + virtual ~TableModel() { } + + /** + * Determines the number of rows (lines) in the table + */ + virtual int getRows() = 0; + + /** + * Determines the number of columns in each row + */ + virtual int getColumns() = 0; + + /** + * Determines the height for each row + */ + virtual int getRowHeight() = 0; + + /** + * Determines the width of each individual column + */ + virtual int getColumnWidth(int index) = 0; + + /** + * Retrieves the widget stored at the specified location within the table. + */ + virtual gcn::Widget *getElementAt(int row, int column) = 0; + + virtual void installListener(TableModelListener *listener); + + virtual void removeListener(TableModelListener *listener); + +protected: + /** + * Tells all listeners that the table is about to see an update + */ + virtual void signalBeforeUpdate(); + + /** + * Tells all listeners that the table has seen an update + */ + virtual void signalAfterUpdate(); + +private: + std::set listeners; +}; + + +class StaticTableModel : public TableModel +{ +public: + StaticTableModel(int width, int height); + virtual ~StaticTableModel(); + + /** + * Inserts a widget into the table model. + * The model is resized to accomodate the widget's width and height, + * unless column width / row height have been fixed. + */ + virtual void set(int row, int column, gcn::Widget *widget); + + /** + * Fixes the column width for a given column; this overrides dynamic width + * inference. + * + * Semantics are undefined for width 0. + */ + virtual void fixColumnWidth(int column, int width); + + /** + * Fixes the row height; this overrides dynamic height inference. + * + * Semantics are undefined for width 0. + */ + virtual void fixRowHeight(int height); + + /** + * Resizes the table model + */ + virtual void resize(); + + virtual int getRows(); + virtual int getColumns(); + virtual int getRowHeight(); + virtual int getWidth(); + virtual int getHeight(); + virtual int getColumnWidth(int index); + virtual gcn::Widget *getElementAt(int row, int column); + +protected: + int mRows, mColumns; + int mHeight; + std::vector mTableModel; + std::vector mWidths; +}; + +#endif /* !defined(TABLE_MODEL_H) */ diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 95e5dc47..9e39645d 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -27,7 +27,7 @@ #include "units.h" #include "gui/inventorywindow.h" -#include "gui/item_amount.h" +#include "gui/itemamount.h" #include "gui/itemcontainer.h" #include "gui/widgets/button.h" diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index b51d199e..c0959cc9 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -25,7 +25,7 @@ #include "log.h" #include "logindata.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/register.h" #include "gui/widgets/button.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 765c9bd2..017668dc 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -23,7 +23,7 @@ #include "configuration.h" #include "equipment.h" -#include "floor_item.h" +#include "flooritem.h" #include "game.h" #include "graphics.h" #include "inventory.h" diff --git a/src/main.cpp b/src/main.cpp index d35fa985..a18a370c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,7 @@ #ifdef USE_OPENGL #include "openglgraphics.h" #endif -#include "player_relations.h" +#include "playerrelations.h" #include "serverinfo.h" #include "sound.h" #include "statuseffect.h" @@ -45,10 +45,10 @@ #include "gui/widgets/label.h" #include "gui/widgets/progressbar.h" -#include "gui/char_select.h" +#include "gui/charselectdialog.h" #include "gui/gui.h" #include "gui/login.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/palette.h" #include "gui/register.h" #include "gui/sdlinput.h" diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp index c84cdea3..c3f960c7 100644 --- a/src/net/ea/adminhandler.cpp +++ b/src/net/ea/adminhandler.cpp @@ -30,7 +30,7 @@ #include "being.h" #include "beingmanager.h" #include "game.h" -#include "player_relations.h" +#include "playerrelations.h" #include "gui/widgets/chattab.h" diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index b6eab2c7..65d19040 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -33,9 +33,9 @@ #include "localplayer.h" #include "log.h" #include "npc.h" -#include "player_relations.h" +#include "playerrelations.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index fab1ffe3..c1d84265 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -33,7 +33,7 @@ #include "main.h" #include "gui/charcreatedialog.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index 26af36dd..db89e316 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -30,7 +30,7 @@ #include "beingmanager.h" #include "game.h" #include "localplayer.h" -#include "player_relations.h" +#include "playerrelations.h" #include "gui/widgets/chattab.h" @@ -40,8 +40,6 @@ #include -#define SERVER_NAME "Server" - Net::ChatHandler *chatHandler; namespace EAthena { @@ -96,7 +94,7 @@ void ChatHandler::handleMessage(MessageIn &msg) chatMsg = msg.readString(chatMsgLength); - if (nick != SERVER_NAME) + if (nick != "Server") { if (player_relations.hasPermission(nick, PlayerRelation::WHISPER)) chatWindow->whisper(nick, chatMsg); diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp index 05313798..5c41c380 100644 --- a/src/net/ea/npchandler.cpp +++ b/src/net/ea/npchandler.cpp @@ -32,7 +32,7 @@ #include "localplayer.h" #include "npc.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/npcintegerdialog.h" #include "gui/npclistdialog.h" #include "gui/npcstringdialog.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 4ff480d6..ef6edc87 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -35,11 +35,11 @@ #include "gui/buy.h" #include "gui/buysell.h" #include "gui/gui.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/npcintegerdialog.h" #include "gui/npclistdialog.h" #include "gui/npcstringdialog.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "gui/sell.h" #include "gui/skill.h" #include "gui/storagewindow.h" diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp index 1bf7e303..ee8e6733 100644 --- a/src/net/ea/tradehandler.cpp +++ b/src/net/ea/tradehandler.cpp @@ -29,9 +29,9 @@ #include "inventory.h" #include "item.h" #include "localplayer.h" -#include "player_relations.h" +#include "playerrelations.h" -#include "gui/confirm_dialog.h" +#include "gui/confirmdialog.h" #include "gui/trade.h" #include "gui/widgets/chattab.h" diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 63a1ea3d..0998da04 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -23,7 +23,7 @@ #define PLAYERHANDLER_H #include "being.h" -#include "floor_item.h" +#include "flooritem.h" #include "localplayer.h" namespace Net { diff --git a/src/net/tmwserv/beinghandler.cpp b/src/net/tmwserv/beinghandler.cpp index 581640db..1ec13800 100644 --- a/src/net/tmwserv/beinghandler.cpp +++ b/src/net/tmwserv/beinghandler.cpp @@ -35,7 +35,7 @@ #include "particle.h" #include "sound.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "utils/gettext.h" diff --git a/src/net/tmwserv/charserverhandler.cpp b/src/net/tmwserv/charserverhandler.cpp index 225c12a8..273c2d8f 100644 --- a/src/net/tmwserv/charserverhandler.cpp +++ b/src/net/tmwserv/charserverhandler.cpp @@ -36,7 +36,7 @@ #include "main.h" #include "gui/charcreatedialog.h" -#include "gui/ok_dialog.h" +#include "gui/okdialog.h" #include "utils/gettext.h" diff --git a/src/net/tmwserv/npchandler.cpp b/src/net/tmwserv/npchandler.cpp index 5670bd69..20a13ec2 100644 --- a/src/net/tmwserv/npchandler.cpp +++ b/src/net/tmwserv/npchandler.cpp @@ -35,7 +35,7 @@ #include "gui/npclistdialog.h" #include "gui/npcpostdialog.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" Net::NpcHandler *npcHandler; diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index 441b5021..e2b5cec4 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -41,8 +41,8 @@ #include "gui/chat.h" #include "gui/gui.h" #include "gui/npclistdialog.h" -#include "gui/npc_text.h" -#include "gui/ok_dialog.h" +#include "gui/npctextdialog.h" +#include "gui/okdialog.h" #include "gui/sell.h" #include "gui/skill.h" #include "gui/viewport.h" diff --git a/src/net/tmwserv/tradehandler.cpp b/src/net/tmwserv/tradehandler.cpp index ae190c96..4c462a3f 100644 --- a/src/net/tmwserv/tradehandler.cpp +++ b/src/net/tmwserv/tradehandler.cpp @@ -35,7 +35,7 @@ #include "item.h" #include "localplayer.h" -#include "gui/confirm_dialog.h" +#include "gui/confirmdialog.h" #include "gui/trade.h" #include "gui/widgets/chattab.h" diff --git a/src/npc.cpp b/src/npc.cpp index 374e7525..40a98ca0 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -25,7 +25,7 @@ #include "particle.h" #include "text.h" -#include "gui/npc_text.h" +#include "gui/npctextdialog.h" #include "gui/palette.h" #include "net/net.h" diff --git a/src/player_relations.cpp b/src/player_relations.cpp deleted file mode 100644 index 898996fa..00000000 --- a/src/player_relations.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include "being.h" -#include "beingmanager.h" -#include "configuration.h" -#include "graphics.h" -#include "player.h" -#include "player_relations.h" - -#include "utils/dtor.h" - -#define PLAYER_IGNORE_STRATEGY_NOP "nop" -#define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" -#define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 - -#define NAME "name" // constant for xml serialisation -#define RELATION "relation" // constant for xml serialisation - -#define IGNORE_EMOTE_TIME 100 - -// (De)serialisation class -class PlayerConfSerialiser : public ConfigurationListManager, - std::map *> -{ - virtual ConfigurationObject *writeConfigItem(std::pair value, - ConfigurationObject *cobj) - { - if (!value.second) - return NULL; - cobj->setValue(NAME, value.first); - cobj->setValue(RELATION, toString(value.second->mRelation)); - - return cobj; - } - - virtual std::map * - readConfigItem(ConfigurationObject *cobj, - std::map *container) - { - std::string name = cobj->getValue(NAME, ""); - if (name.empty()) - return container; - - if (!(*container)[name]) { - int v = (int)cobj->getValue(RELATION, PlayerRelation::NEUTRAL); - (*container)[name] = new PlayerRelation(static_cast(v)); - } - // otherwise ignore the duplicate entry - - return container; - } -}; - -static PlayerConfSerialiser player_conf_serialiser; // stateless singleton - -const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = { - /* NEUTRAL */ 0, // we always fall back to the defaults anyway - /* FRIEND */ EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE, - /* DISREGARDED*/ EMOTE | SPEECH_FLOAT, - /* IGNORED */ 0 -}; - -PlayerRelation::PlayerRelation(Relation relation) -{ - mRelation = relation; -} - -PlayerRelationsManager::PlayerRelationsManager() : - mPersistIgnores(false), - mDefaultPermissions(PlayerRelation::DEFAULT), - mIgnoreStrategy(NULL) -{ -} - -PlayerRelationsManager::~PlayerRelationsManager() -{ - delete_all(mIgnoreStrategies); -} - -void PlayerRelationsManager::clear() -{ - std::vector *names = getPlayers(); - for (std::vector::const_iterator - it = names->begin(); it != names->end(); it++) - removePlayer(*it); - delete names; -} - -#define PERSIST_IGNORE_LIST "persist-player-list" -#define PLAYER_IGNORE_STRATEGY "player-ignore-strategy" -#define DEFAULT_PERMISSIONS "default-player-permissions" - -int PlayerRelationsManager::getPlayerIgnoreStrategyIndex(const std::string &name) -{ - std::vector *strategies = getPlayerIgnoreStrategies(); - for (unsigned int i = 0; i < strategies->size(); i++) - if ((*strategies)[i]->mShortName == name) - return i; - - return -1; -} - -void PlayerRelationsManager::load() -{ - clear(); - - mPersistIgnores = config.getValue(PERSIST_IGNORE_LIST, 0); - mDefaultPermissions = (int) config.getValue(DEFAULT_PERMISSIONS, mDefaultPermissions); - std::string ignore_strategy_name = config.getValue(PLAYER_IGNORE_STRATEGY, DEFAULT_IGNORE_STRATEGY); - int ignore_strategy_index = getPlayerIgnoreStrategyIndex(ignore_strategy_name); - if (ignore_strategy_index >= 0) - setPlayerIgnoreStrategy((*getPlayerIgnoreStrategies())[ignore_strategy_index]); - - config.getList, - std::map *> - ("player", &(mRelations), &player_conf_serialiser); -} - - -void PlayerRelationsManager::init() -{ - load(); - - if (!mPersistIgnores) - clear(); // Yes, we still keep them around in the config file until the next update. -} - -void PlayerRelationsManager::store() -{ - config.setList::const_iterator, - std::pair, - std::map *> - ("player", - mRelations.begin(), mRelations.end(), - &player_conf_serialiser); - - config.setValue(DEFAULT_PERMISSIONS, mDefaultPermissions); - config.setValue(PERSIST_IGNORE_LIST, mPersistIgnores); - config.setValue(PLAYER_IGNORE_STRATEGY, - (mIgnoreStrategy)? mIgnoreStrategy->mShortName : DEFAULT_IGNORE_STRATEGY); - - config.write(); -} - -void PlayerRelationsManager::signalUpdate(const std::string &name) -{ - store(); - - for (std::list::const_iterator it = mListeners.begin(); it != mListeners.end(); it++) - (*it)->updatedPlayer(name); -} - -unsigned int PlayerRelationsManager::checkPermissionSilently(const std::string &player_name, unsigned int flags) -{ - PlayerRelation *r = mRelations[player_name]; - if (!r) - return mDefaultPermissions & flags; - else { - unsigned int permissions = PlayerRelation::RELATION_PERMISSIONS[r->mRelation]; - - switch (r->mRelation) { - case PlayerRelation::NEUTRAL: - permissions = mDefaultPermissions; - break; - - case PlayerRelation::FRIEND: - permissions |= mDefaultPermissions; // widen - break; - - default: - permissions &= mDefaultPermissions; // narrow - } - - return permissions & flags; - } -} - -bool PlayerRelationsManager::hasPermission(Being *being, unsigned int flags) -{ - if (being->getType() == Being::PLAYER) - return hasPermission(being->getName(), flags) == flags; - return true; -} - -bool PlayerRelationsManager::hasPermission(const std::string &name, unsigned int flags) -{ - unsigned int rejections = flags & ~checkPermissionSilently(name, flags); - bool permitted = rejections == 0; - - if (!permitted) { - // execute `ignore' strategy, if possible - if (mIgnoreStrategy) { - Player *to_ignore = dynamic_cast(beingManager->findBeingByName(name, Being::PLAYER)); - - if (to_ignore) - mIgnoreStrategy->ignore(to_ignore, - rejections); - } - } - - return permitted; -} - -void PlayerRelationsManager::setRelation(const std::string &player_name, - PlayerRelation::Relation relation) -{ - PlayerRelation *r = mRelations[player_name]; - if (r == NULL) - mRelations[player_name] = new PlayerRelation(relation); - else - r->mRelation = relation; - - signalUpdate(player_name); -} - -std::vector * PlayerRelationsManager::getPlayers() -{ - std::vector *retval = new std::vector(); - - for (std::map::const_iterator it = mRelations.begin(); it != mRelations.end(); it++) - if (it->second) - retval->push_back(it->first); - - sort(retval->begin(), retval->end()); - - return retval; -} - -void PlayerRelationsManager::removePlayer(const std::string &name) -{ - if (mRelations[name]) - delete mRelations[name]; - - mRelations.erase(name); - - signalUpdate(name); -} - - -PlayerRelation::Relation PlayerRelationsManager::getRelation(const std::string &name) -{ - if (mRelations[name]) - return mRelations[name]->mRelation; - - return PlayerRelation::NEUTRAL; -} - -//////////////////////////////////////// -// defaults - -unsigned int PlayerRelationsManager::getDefault() const -{ - return mDefaultPermissions; -} - -void PlayerRelationsManager::setDefault(unsigned int permissions) -{ - mDefaultPermissions = permissions; - - store(); - signalUpdate(""); -} - - -//////////////////////////////////////// -// ignore strategies - - -class PIS_nothing : public PlayerIgnoreStrategy -{ -public: - PIS_nothing() - { - mDescription = "completely ignore"; - mShortName = PLAYER_IGNORE_STRATEGY_NOP; - } - - virtual void ignore(Player *player, unsigned int flags) - { - } -}; - -class PIS_dotdotdot : public PlayerIgnoreStrategy -{ -public: - PIS_dotdotdot() - { - mDescription = "print '...'"; - mShortName = "dotdotdot"; - } - - virtual void ignore(Player *player, unsigned int flags) - { - player->setSpeech("...", 500); - } -}; - - -class PIS_blinkname : public PlayerIgnoreStrategy -{ -public: - PIS_blinkname() - { - mDescription = "blink name"; - mShortName = "blinkname"; - } - - virtual void ignore(Player *player, unsigned int flags) - { - player->flash(200); - } -}; - -class PIS_emote : public PlayerIgnoreStrategy -{ -public: - PIS_emote(int emote_nr, const std::string &description, const std::string &shortname) : - mEmotion(emote_nr) - { - mDescription = description; - mShortName = shortname; - } - - virtual void ignore(Player *player, unsigned int flags) - { - player->setEmote(mEmotion, IGNORE_EMOTE_TIME); - } -private: - int mEmotion; -}; - - - -std::vector * -PlayerRelationsManager::getPlayerIgnoreStrategies() -{ - if (mIgnoreStrategies.size() == 0) - { - // not initialised yet? - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, - "floating '...' bubble", - PLAYER_IGNORE_STRATEGY_EMOTE0)); - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, - "floating bubble", - "emote1")); - mIgnoreStrategies.push_back(new PIS_nothing()); - mIgnoreStrategies.push_back(new PIS_dotdotdot()); - mIgnoreStrategies.push_back(new PIS_blinkname()); - } - return &mIgnoreStrategies; -} - - -PlayerRelationsManager player_relations; diff --git a/src/player_relations.h b/src/player_relations.h deleted file mode 100644 index adc6a95f..00000000 --- a/src/player_relations.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2008 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PLAYER_RELATIONS_H -#define PLAYER_RELATIONS_H - -#include -#include -#include -#include - -class Being; -class Player; - -struct PlayerRelation -{ - static const unsigned int EMOTE = (1 << 0); - static const unsigned int SPEECH_FLOAT = (1 << 1); - static const unsigned int SPEECH_LOG = (1 << 2); - static const unsigned int WHISPER = (1 << 3); - static const unsigned int TRADE = (1 << 4); - - static const unsigned int RELATIONS_NR = 4; - static const unsigned int RELATION_PERMISSIONS[RELATIONS_NR]; - - static const unsigned int DEFAULT = EMOTE - | SPEECH_FLOAT - | SPEECH_LOG - | WHISPER - | TRADE; - enum Relation { - NEUTRAL = 0, - FRIEND = 1, - DISREGARDED = 2, - IGNORED = 3 - }; - - PlayerRelation(Relation relation); - - Relation mRelation; // bitmask for all of the above -}; - - -/** - * Ignore strategy: describes how we should handle ignores. - */ -class PlayerIgnoreStrategy -{ -public: - std::string mDescription; - std::string mShortName; - - virtual ~PlayerIgnoreStrategy() {} - - /** - * Handle the ignoring of the indicated action by the indicated player. - */ - virtual void ignore(Player *player, unsigned int flags) = 0; -}; - -class PlayerRelationsListener -{ -public: - PlayerRelationsListener() { } - virtual ~PlayerRelationsListener() { } - - virtual void updatedPlayer(const std::string &name) = 0; -}; - -/** - * Player relations class, represents any particular relations and/or - * preferences the user of the local client has wrt other players (identified - * by std::string). - */ -class PlayerRelationsManager -{ -public: - PlayerRelationsManager(); - ~PlayerRelationsManager(); - - /** - * Initialise player relations manager (load config file etc.) - */ - void init(); - - /** - * Load configuration from our config file, or substitute defaults. - */ - void load(); - - /** - * Save configuration to our config file. - */ - void store(); - - /** - * Determines whether the player in question is being ignored, filtered by - * the specified flags. - */ - unsigned int checkPermissionSilently(const std::string &player_name, - unsigned int flags); - - /** - * Tests whether the player in question is being ignored for any of the - * actions in the specified flags. If so, trigger appropriate side effects - * if requested by the player. - */ - bool hasPermission(Being *being, unsigned int flags); - - bool hasPermission(const std::string &being, unsigned int flags); - - /** - * Updates the relationship with this player. - */ - void setRelation(const std::string &name, - PlayerRelation::Relation relation); - - /** - * Updates the relationship with this player. - */ - PlayerRelation::Relation getRelation(const std::string &name); - - /** - * Deletes the information recorded for a player. - */ - void removePlayer(const std::string &name); - - /** - * Retrieves the default permissions. - */ - unsigned int getDefault() const; - - /** - * Sets the default permissions. - */ - void setDefault(unsigned int permissions); - - /** - * Retrieves all known player ignore strategies. - * - * The player ignore strategies are allocated statically and must not be - * deleted. - */ - std::vector *getPlayerIgnoreStrategies(); - - /** - * Return the current player ignore strategy. - * - * \return A player ignore strategy, or NULL - */ - PlayerIgnoreStrategy *getPlayerIgnoreStrategy() const - { - return mIgnoreStrategy; - } - - /** - * Sets the strategy to call when ignoring players. - */ - void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *strategy) - { - mIgnoreStrategy = strategy; - } - - /** - * For a given ignore strategy short name, find the appropriate index in - * the ignore strategies vector. - * - * \param The short name of the ignore strategy to look up - * \return The appropriate index, or -1 - */ - int getPlayerIgnoreStrategyIndex(const std::string &shortname); - - /** - * Retrieves a sorted vector of all players for which we have any relations - * recorded. - */ - std::vector *getPlayers(); - - /** - * Removes all recorded player info. - */ - void clear(); - - /** - * Do we persist our `ignore' setup? - */ - bool getPersistIgnores() const { return mPersistIgnores; } - - /** - * Change the `ignore persist' flag. - * - * @param value Whether to persist ignores - */ - void setPersistIgnores(bool value) { mPersistIgnores = value; } - - void addListener(PlayerRelationsListener *listener) - { - mListeners.push_back(listener); - } - - void removeListener(PlayerRelationsListener *listener) - { - mListeners.remove(listener); - } - -private: - void signalUpdate(const std::string &name); - - bool mPersistIgnores; // If NOT set, we delete the ignored data upon reloading - unsigned int mDefaultPermissions; - - PlayerIgnoreStrategy *mIgnoreStrategy; - std::map mRelations; - std::list mListeners; - std::vector mIgnoreStrategies; -}; - - -extern PlayerRelationsManager player_relations; // singleton representation of player relations - - -#endif /* !defined(PLAYER_RELATIONS_H) */ diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp new file mode 100644 index 00000000..4a431e2a --- /dev/null +++ b/src/playerrelations.cpp @@ -0,0 +1,375 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "being.h" +#include "beingmanager.h" +#include "configuration.h" +#include "graphics.h" +#include "player.h" +#include "playerrelations.h" + +#include "utils/dtor.h" + +#define PLAYER_IGNORE_STRATEGY_NOP "nop" +#define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" +#define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 + +#define NAME "name" // constant for xml serialisation +#define RELATION "relation" // constant for xml serialisation + +#define IGNORE_EMOTE_TIME 100 + +// (De)serialisation class +class PlayerConfSerialiser : public ConfigurationListManager, + std::map *> +{ + virtual ConfigurationObject *writeConfigItem(std::pair value, + ConfigurationObject *cobj) + { + if (!value.second) + return NULL; + cobj->setValue(NAME, value.first); + cobj->setValue(RELATION, toString(value.second->mRelation)); + + return cobj; + } + + virtual std::map * + readConfigItem(ConfigurationObject *cobj, + std::map *container) + { + std::string name = cobj->getValue(NAME, ""); + if (name.empty()) + return container; + + if (!(*container)[name]) { + int v = (int)cobj->getValue(RELATION, PlayerRelation::NEUTRAL); + (*container)[name] = new PlayerRelation(static_cast(v)); + } + // otherwise ignore the duplicate entry + + return container; + } +}; + +static PlayerConfSerialiser player_conf_serialiser; // stateless singleton + +const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = { + /* NEUTRAL */ 0, // we always fall back to the defaults anyway + /* FRIEND */ EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE, + /* DISREGARDED*/ EMOTE | SPEECH_FLOAT, + /* IGNORED */ 0 +}; + +PlayerRelation::PlayerRelation(Relation relation) +{ + mRelation = relation; +} + +PlayerRelationsManager::PlayerRelationsManager() : + mPersistIgnores(false), + mDefaultPermissions(PlayerRelation::DEFAULT), + mIgnoreStrategy(NULL) +{ +} + +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + +void PlayerRelationsManager::clear() +{ + std::vector *names = getPlayers(); + for (std::vector::const_iterator + it = names->begin(); it != names->end(); it++) + removePlayer(*it); + delete names; +} + +#define PERSIST_IGNORE_LIST "persist-player-list" +#define PLAYER_IGNORE_STRATEGY "player-ignore-strategy" +#define DEFAULT_PERMISSIONS "default-player-permissions" + +int PlayerRelationsManager::getPlayerIgnoreStrategyIndex(const std::string &name) +{ + std::vector *strategies = getPlayerIgnoreStrategies(); + for (unsigned int i = 0; i < strategies->size(); i++) + if ((*strategies)[i]->mShortName == name) + return i; + + return -1; +} + +void PlayerRelationsManager::load() +{ + clear(); + + mPersistIgnores = config.getValue(PERSIST_IGNORE_LIST, 0); + mDefaultPermissions = (int) config.getValue(DEFAULT_PERMISSIONS, mDefaultPermissions); + std::string ignore_strategy_name = config.getValue(PLAYER_IGNORE_STRATEGY, DEFAULT_IGNORE_STRATEGY); + int ignore_strategy_index = getPlayerIgnoreStrategyIndex(ignore_strategy_name); + if (ignore_strategy_index >= 0) + setPlayerIgnoreStrategy((*getPlayerIgnoreStrategies())[ignore_strategy_index]); + + config.getList, + std::map *> + ("player", &(mRelations), &player_conf_serialiser); +} + + +void PlayerRelationsManager::init() +{ + load(); + + if (!mPersistIgnores) + clear(); // Yes, we still keep them around in the config file until the next update. +} + +void PlayerRelationsManager::store() +{ + config.setList::const_iterator, + std::pair, + std::map *> + ("player", + mRelations.begin(), mRelations.end(), + &player_conf_serialiser); + + config.setValue(DEFAULT_PERMISSIONS, mDefaultPermissions); + config.setValue(PERSIST_IGNORE_LIST, mPersistIgnores); + config.setValue(PLAYER_IGNORE_STRATEGY, + (mIgnoreStrategy)? mIgnoreStrategy->mShortName : DEFAULT_IGNORE_STRATEGY); + + config.write(); +} + +void PlayerRelationsManager::signalUpdate(const std::string &name) +{ + store(); + + for (std::list::const_iterator it = mListeners.begin(); it != mListeners.end(); it++) + (*it)->updatedPlayer(name); +} + +unsigned int PlayerRelationsManager::checkPermissionSilently(const std::string &player_name, unsigned int flags) +{ + PlayerRelation *r = mRelations[player_name]; + if (!r) + return mDefaultPermissions & flags; + else { + unsigned int permissions = PlayerRelation::RELATION_PERMISSIONS[r->mRelation]; + + switch (r->mRelation) { + case PlayerRelation::NEUTRAL: + permissions = mDefaultPermissions; + break; + + case PlayerRelation::FRIEND: + permissions |= mDefaultPermissions; // widen + break; + + default: + permissions &= mDefaultPermissions; // narrow + } + + return permissions & flags; + } +} + +bool PlayerRelationsManager::hasPermission(Being *being, unsigned int flags) +{ + if (being->getType() == Being::PLAYER) + return hasPermission(being->getName(), flags) == flags; + return true; +} + +bool PlayerRelationsManager::hasPermission(const std::string &name, unsigned int flags) +{ + unsigned int rejections = flags & ~checkPermissionSilently(name, flags); + bool permitted = rejections == 0; + + if (!permitted) { + // execute `ignore' strategy, if possible + if (mIgnoreStrategy) { + Player *to_ignore = dynamic_cast(beingManager->findBeingByName(name, Being::PLAYER)); + + if (to_ignore) + mIgnoreStrategy->ignore(to_ignore, + rejections); + } + } + + return permitted; +} + +void PlayerRelationsManager::setRelation(const std::string &player_name, + PlayerRelation::Relation relation) +{ + PlayerRelation *r = mRelations[player_name]; + if (r == NULL) + mRelations[player_name] = new PlayerRelation(relation); + else + r->mRelation = relation; + + signalUpdate(player_name); +} + +std::vector * PlayerRelationsManager::getPlayers() +{ + std::vector *retval = new std::vector(); + + for (std::map::const_iterator it = mRelations.begin(); it != mRelations.end(); it++) + if (it->second) + retval->push_back(it->first); + + sort(retval->begin(), retval->end()); + + return retval; +} + +void PlayerRelationsManager::removePlayer(const std::string &name) +{ + if (mRelations[name]) + delete mRelations[name]; + + mRelations.erase(name); + + signalUpdate(name); +} + + +PlayerRelation::Relation PlayerRelationsManager::getRelation(const std::string &name) +{ + if (mRelations[name]) + return mRelations[name]->mRelation; + + return PlayerRelation::NEUTRAL; +} + +//////////////////////////////////////// +// defaults + +unsigned int PlayerRelationsManager::getDefault() const +{ + return mDefaultPermissions; +} + +void PlayerRelationsManager::setDefault(unsigned int permissions) +{ + mDefaultPermissions = permissions; + + store(); + signalUpdate(""); +} + + +//////////////////////////////////////// +// ignore strategies + + +class PIS_nothing : public PlayerIgnoreStrategy +{ +public: + PIS_nothing() + { + mDescription = "completely ignore"; + mShortName = PLAYER_IGNORE_STRATEGY_NOP; + } + + virtual void ignore(Player *player, unsigned int flags) + { + } +}; + +class PIS_dotdotdot : public PlayerIgnoreStrategy +{ +public: + PIS_dotdotdot() + { + mDescription = "print '...'"; + mShortName = "dotdotdot"; + } + + virtual void ignore(Player *player, unsigned int flags) + { + player->setSpeech("...", 500); + } +}; + + +class PIS_blinkname : public PlayerIgnoreStrategy +{ +public: + PIS_blinkname() + { + mDescription = "blink name"; + mShortName = "blinkname"; + } + + virtual void ignore(Player *player, unsigned int flags) + { + player->flash(200); + } +}; + +class PIS_emote : public PlayerIgnoreStrategy +{ +public: + PIS_emote(int emote_nr, const std::string &description, const std::string &shortname) : + mEmotion(emote_nr) + { + mDescription = description; + mShortName = shortname; + } + + virtual void ignore(Player *player, unsigned int flags) + { + player->setEmote(mEmotion, IGNORE_EMOTE_TIME); + } +private: + int mEmotion; +}; + + + +std::vector * +PlayerRelationsManager::getPlayerIgnoreStrategies() +{ + if (mIgnoreStrategies.size() == 0) + { + // not initialised yet? + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + "floating '...' bubble", + PLAYER_IGNORE_STRATEGY_EMOTE0)); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + "floating bubble", + "emote1")); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); + } + return &mIgnoreStrategies; +} + + +PlayerRelationsManager player_relations; diff --git a/src/playerrelations.h b/src/playerrelations.h new file mode 100644 index 00000000..adc6a95f --- /dev/null +++ b/src/playerrelations.h @@ -0,0 +1,240 @@ +/* + * The Mana World + * Copyright (C) 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PLAYER_RELATIONS_H +#define PLAYER_RELATIONS_H + +#include +#include +#include +#include + +class Being; +class Player; + +struct PlayerRelation +{ + static const unsigned int EMOTE = (1 << 0); + static const unsigned int SPEECH_FLOAT = (1 << 1); + static const unsigned int SPEECH_LOG = (1 << 2); + static const unsigned int WHISPER = (1 << 3); + static const unsigned int TRADE = (1 << 4); + + static const unsigned int RELATIONS_NR = 4; + static const unsigned int RELATION_PERMISSIONS[RELATIONS_NR]; + + static const unsigned int DEFAULT = EMOTE + | SPEECH_FLOAT + | SPEECH_LOG + | WHISPER + | TRADE; + enum Relation { + NEUTRAL = 0, + FRIEND = 1, + DISREGARDED = 2, + IGNORED = 3 + }; + + PlayerRelation(Relation relation); + + Relation mRelation; // bitmask for all of the above +}; + + +/** + * Ignore strategy: describes how we should handle ignores. + */ +class PlayerIgnoreStrategy +{ +public: + std::string mDescription; + std::string mShortName; + + virtual ~PlayerIgnoreStrategy() {} + + /** + * Handle the ignoring of the indicated action by the indicated player. + */ + virtual void ignore(Player *player, unsigned int flags) = 0; +}; + +class PlayerRelationsListener +{ +public: + PlayerRelationsListener() { } + virtual ~PlayerRelationsListener() { } + + virtual void updatedPlayer(const std::string &name) = 0; +}; + +/** + * Player relations class, represents any particular relations and/or + * preferences the user of the local client has wrt other players (identified + * by std::string). + */ +class PlayerRelationsManager +{ +public: + PlayerRelationsManager(); + ~PlayerRelationsManager(); + + /** + * Initialise player relations manager (load config file etc.) + */ + void init(); + + /** + * Load configuration from our config file, or substitute defaults. + */ + void load(); + + /** + * Save configuration to our config file. + */ + void store(); + + /** + * Determines whether the player in question is being ignored, filtered by + * the specified flags. + */ + unsigned int checkPermissionSilently(const std::string &player_name, + unsigned int flags); + + /** + * Tests whether the player in question is being ignored for any of the + * actions in the specified flags. If so, trigger appropriate side effects + * if requested by the player. + */ + bool hasPermission(Being *being, unsigned int flags); + + bool hasPermission(const std::string &being, unsigned int flags); + + /** + * Updates the relationship with this player. + */ + void setRelation(const std::string &name, + PlayerRelation::Relation relation); + + /** + * Updates the relationship with this player. + */ + PlayerRelation::Relation getRelation(const std::string &name); + + /** + * Deletes the information recorded for a player. + */ + void removePlayer(const std::string &name); + + /** + * Retrieves the default permissions. + */ + unsigned int getDefault() const; + + /** + * Sets the default permissions. + */ + void setDefault(unsigned int permissions); + + /** + * Retrieves all known player ignore strategies. + * + * The player ignore strategies are allocated statically and must not be + * deleted. + */ + std::vector *getPlayerIgnoreStrategies(); + + /** + * Return the current player ignore strategy. + * + * \return A player ignore strategy, or NULL + */ + PlayerIgnoreStrategy *getPlayerIgnoreStrategy() const + { + return mIgnoreStrategy; + } + + /** + * Sets the strategy to call when ignoring players. + */ + void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *strategy) + { + mIgnoreStrategy = strategy; + } + + /** + * For a given ignore strategy short name, find the appropriate index in + * the ignore strategies vector. + * + * \param The short name of the ignore strategy to look up + * \return The appropriate index, or -1 + */ + int getPlayerIgnoreStrategyIndex(const std::string &shortname); + + /** + * Retrieves a sorted vector of all players for which we have any relations + * recorded. + */ + std::vector *getPlayers(); + + /** + * Removes all recorded player info. + */ + void clear(); + + /** + * Do we persist our `ignore' setup? + */ + bool getPersistIgnores() const { return mPersistIgnores; } + + /** + * Change the `ignore persist' flag. + * + * @param value Whether to persist ignores + */ + void setPersistIgnores(bool value) { mPersistIgnores = value; } + + void addListener(PlayerRelationsListener *listener) + { + mListeners.push_back(listener); + } + + void removeListener(PlayerRelationsListener *listener) + { + mListeners.remove(listener); + } + +private: + void signalUpdate(const std::string &name); + + bool mPersistIgnores; // If NOT set, we delete the ignored data upon reloading + unsigned int mDefaultPermissions; + + PlayerIgnoreStrategy *mIgnoreStrategy; + std::map mRelations; + std::list mListeners; + std::vector mIgnoreStrategies; +}; + + +extern PlayerRelationsManager player_relations; // singleton representation of player relations + + +#endif /* !defined(PLAYER_RELATIONS_H) */ diff --git a/src/position.cpp b/src/position.cpp index 69d50476..33859327 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -29,14 +29,14 @@ std::ostream& operator <<(std::ostream &os, const Position &p) std::ostream& operator <<(std::ostream &os, const Path &path) { - Path::const_iterator i = path.begin(); + Path::const_iterator i = path.begin(), i_end = path.end(); os << "("; - while (i != path.end()) + while (i != i_end) { os << *i; ++i; - if (i != path.end()) + if (i != i_end) os << ", "; } os << ")"; -- cgit v1.2.3-70-g09d2