From b8f0e1755ae8c6acf9bc681a83f18ef6ff0a1172 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Feb 2009 19:37:43 +0000 Subject: Move check to a more appropriate place It shouldn't have been moved to where it was in the first place, as it doesn't have any effecxt on that code, but was originally on the other code (where it is now). --- src/gui/char_select.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index ae78b384..bad6d8de 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -148,11 +148,11 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "newdel") { // Check for a character - if (mCharInfo->getEntry() && n_character <= MAX_SLOT + 1) + if (mCharInfo->getEntry()) { new CharDeleteConfirm(this); } - else + else if (n_character <= MAX_SLOT) { // Start new character dialog CharCreateDialog *charCreateDialog = -- cgit v1.2.3-70-g09d2 From c3f7f72f37adad5103587069ff549798fc9d652d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 18 Feb 2009 20:14:23 +0100 Subject: Introduced a toLower method and grouped string utils The string utility methods are now grouped together in the stringutils.h header. Also, a toLower method was added for convenience. --- aethyra.cbp | 4 +-- src/CMakeLists.txt | 4 +-- src/Makefile.am | 4 +-- src/being.cpp | 5 ++- src/configuration.cpp | 2 +- src/emoteshortcut.cpp | 2 +- src/engine.cpp | 4 +-- src/gui/char_select.cpp | 2 +- src/gui/char_server.cpp | 4 +-- src/gui/chat.cpp | 23 +++---------- src/gui/color.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotecontainer.cpp | 2 +- src/gui/emoteshortcutcontainer.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inttextfield.cpp | 2 +- src/gui/inventorywindow.cpp | 2 +- src/gui/itemcontainer.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/itemshortcutcontainer.cpp | 2 +- src/gui/login.cpp | 2 +- src/gui/ministatus.cpp | 2 +- src/gui/recorder.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/setup_colors.cpp | 2 +- src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/shortcutcontainer.cpp | 2 +- src/gui/status.cpp | 2 +- src/gui/trade.cpp | 2 +- src/gui/updatewindow.cpp | 2 +- src/gui/viewport.cpp | 2 +- src/itemshortcut.cpp | 2 +- src/localplayer.cpp | 2 +- src/main.cpp | 4 +-- src/map.cpp | 2 +- src/net/charserverhandler.cpp | 4 +-- src/net/chathandler.cpp | 3 +- src/net/inventoryhandler.cpp | 2 +- src/net/loginhandler.cpp | 4 +-- src/net/network.cpp | 4 +-- src/net/playerhandler.cpp | 2 +- src/resources/itemdb.cpp | 9 ++--- src/resources/mapreader.cpp | 2 +- src/utils/stringutils.cpp | 64 +++++++++++++++++++++++++++++++++++ src/utils/stringutils.h | 69 ++++++++++++++++++++++++++++++++++++++ src/utils/trim.h | 52 ---------------------------- 48 files changed, 192 insertions(+), 133 deletions(-) create mode 100644 src/utils/stringutils.cpp create mode 100644 src/utils/stringutils.h delete mode 100644 src/utils/trim.h diff --git a/aethyra.cbp b/aethyra.cbp index 08ec74fd..29bc7227 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -420,10 +420,10 @@ + + - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25bcbfb0..51d6b937 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -296,10 +296,10 @@ SET(SRCS utils/dtor.h utils/fastsqrt.h utils/gettext.h + utils/stringutils.cpp + utils/stringutils.h utils/strprintf.cpp utils/strprintf.h - utils/tostring.h - utils/trim.h utils/xml.cpp utils/xml.h animatedsprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 71862994..6b5dda8b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -246,10 +246,10 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ utils/dtor.h \ utils/fastsqrt.h \ utils/gettext.h \ + utils/stringutils.cpp \ + utils/stringutils.h \ utils/strprintf.cpp \ utils/strprintf.h \ - utils/tostring.h \ - utils/trim.h \ utils/mutex.h \ utils/xml.cpp \ utils/xml.h \ diff --git a/src/being.cpp b/src/being.cpp index 34b042e8..3f34948e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -50,9 +50,8 @@ #include "gui/speechbubble.h" #include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/tostring.h" -#include "utils/trim.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" #include "utils/xml.h" int Being::instances = 0; diff --git a/src/configuration.cpp b/src/configuration.cpp index 2224a6c7..0df666ab 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "log.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" #include "utils/xml.h" void ConfigurationObject::setValue(const std::string &key, std::string value) diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp index c1ca3c2c..b229ec70 100644 --- a/src/emoteshortcut.cpp +++ b/src/emoteshortcut.cpp @@ -25,7 +25,7 @@ #include "configuration.h" #include "localplayer.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" EmoteShortcut::EmoteShortcut *emoteShortcut; diff --git a/src/engine.cpp b/src/engine.cpp index d491b3ff..cc19bd72 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -40,9 +40,7 @@ #include "resources/mapreader.h" #include "resources/resourcemanager.h" -#include "utils/tostring.h" - -char itemCurrenyQ[10] = "0"; +#include "utils/stringutils.h" Engine::Engine(Network *network): mCurrentMap(NULL), diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index bad6d8de..fa0594d6 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -46,7 +46,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" // Defined in main.cpp, used here for setting the char create dialog extern CharServerHandler charServerHandler; diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 60f8f5dd..6977a104 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -30,7 +30,7 @@ #include "../serverinfo.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern SERVER_INFO **server_info; @@ -102,7 +102,7 @@ void ServerSelectDialog::action(const gcn::ActionEvent &event) { mOkButton->setEnabled(false); const SERVER_INFO *si = server_info[mServerList->getSelected()]; - mLoginData->hostname = iptostring(si->address); + mLoginData->hostname = ipToString(si->address); mLoginData->port = si->port; mLoginData->updateHost = si->updateHost; state = mNextState; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 0e8810ac..91e410ce 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -47,8 +47,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" ChatWindow::ChatWindow(Network * network): Window(""), mNetwork(network), mTmpVisible(false) @@ -336,15 +335,8 @@ void ChatWindow::whisper(const std::string &nick, std::string msg) std::string playerName = player_node->getName(); std::string tempNick = recvnick; - for (unsigned int i = 0; i < playerName.size(); i++) - { - playerName[i] = (char) tolower(playerName[i]); - } - - for (unsigned int i = 0; i < tempNick.size(); i++) - { - tempNick[i] = (char) tolower(tempNick[i]); - } + toLower(playerName); + toLower(tempNick); if (tempNick.compare(playerName) == 0 || msg.empty()) return; @@ -405,14 +397,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) start = msg.find('[', start + 1); } - std::string temp = msg.substr(start+1, end - start - 1); - - trim(temp); + std::string temp = msg.substr(start + 1, end - start - 1); - for (unsigned int i = 0; i < temp.size(); i++) - { - temp[i] = (char) tolower(temp[i]); - } + toLower(trim(temp)); const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) diff --git a/src/gui/color.cpp b/src/gui/color.cpp index aa249077..b68bf68b 100644 --- a/src/gui/color.cpp +++ b/src/gui/color.cpp @@ -24,7 +24,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" Color::Color() { diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 2d8bb826..c41e0a5e 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -34,7 +34,7 @@ #include "../particle.h" #include "../map.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" DebugWindow::DebugWindow(): Window("Debug") diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index 721a0ebd..c4cace55 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -39,7 +39,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" const int EmoteContainer::gridWidth = 34; // emote icon width + 4 const int EmoteContainer::gridHeight = 36; // emote icon height + 4 diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index af83a743..e828df8b 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -39,7 +39,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" static const int MAX_ITEMS = 12; diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 8cf1d730..30129941 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -30,7 +30,7 @@ #include "../localplayer.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" EmoteWindow::EmoteWindow(): Window(_("Emote")) diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index fae517a9..6be55e1c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -41,7 +41,7 @@ #include "../resources/resourcemanager.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" // Positions of the boxes, 2nd dimension is X and Y respectively. static const int boxPosition[][2] = { diff --git a/src/gui/inttextfield.cpp b/src/gui/inttextfield.cpp index adade3b9..40bbd887 100644 --- a/src/gui/inttextfield.cpp +++ b/src/gui/inttextfield.cpp @@ -22,7 +22,7 @@ #include "inttextfield.h" #include "sdlinput.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" IntTextField::IntTextField(int def): TextField(toString(def)), diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index ec825ae3..e8457337 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -44,7 +44,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" InventoryWindow::InventoryWindow(int invSize): Window(_("Inventory")), diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index e84c79ca..79aeb227 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -38,7 +38,7 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" const int ItemContainer::gridWidth = 36; // item icon width + 4 const int ItemContainer::gridHeight = 42; // item icon height + 10 diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index d13cd1c2..88afcd5b 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -36,7 +36,7 @@ #include "../resources/iteminfo.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" ItemPopup::ItemPopup(): Window() diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 324e1b6c..10ced157 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -36,7 +36,7 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" ItemShortcutContainer::ItemShortcutContainer(): ShortcutContainer(), diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 159b7f6f..cd331322 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -39,7 +39,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" static const int MAX_SERVER_LIST_SIZE = 5; static const int LOGIN_DIALOG_WIDTH = 220; diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 629cf45c..6537b48e 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -28,7 +28,7 @@ #include "../graphics.h" #include "../localplayer.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" MiniStatusWindow::MiniStatusWindow(): Window("") diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 982d808d..ff8825ef 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -28,7 +28,7 @@ #include "widgets/layout.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" Recorder::Recorder(ChatWindow *chat, const std::string &title, const std::string &buttonTxt) : diff --git a/src/gui/register.cpp b/src/gui/register.cpp index fd7df18d..13928e41 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -40,7 +40,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * Listener used while dealing with wrong data. It is used to direct the focus diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index f3fa3c65..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -40,7 +40,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" Setup_Colors::Setup_Colors() : mSelected(-1) diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 1fb0b443..0f79e3c6 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -36,7 +36,7 @@ #include "../keyboardconfig.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * The list model for key function list. diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 34dfde0f..8b21582e 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -47,7 +47,7 @@ #include "../particle.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern Graphics *graphics; diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index cc559def..13ff042d 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -26,7 +26,7 @@ #include "../resources/image.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" float ShortcutContainer::mAlpha = config.getValue("guialpha", 0.8); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 42a48b2f..49af3ae2 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -33,7 +33,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" StatusWindow::StatusWindow(LocalPlayer *player): Window(player->getName()), diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index c57cac59..ba2e2462 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -44,7 +44,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" TradeWindow::TradeWindow(Network *network): Window(_("Trade: You")), diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index a25d57d4..81dcb047 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -45,7 +45,7 @@ #include "../resources/resourcemanager.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * Calculates the Alder-32 checksum for the given file. diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 79a37227..9a7f6173 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -37,7 +37,7 @@ #include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern volatile int tick_time; diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index fd32c4f5..0627ccda 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -26,7 +26,7 @@ #include "itemshortcut.h" #include "localplayer.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" ItemShortcut::ItemShortcut *itemShortcut; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0470fefc..608c25b8 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -45,7 +45,7 @@ #include "resources/imageset.h" #include "resources/resourcemanager.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" LocalPlayer *player_node = NULL; diff --git a/src/main.cpp b/src/main.cpp index a6ddd597..06ec2f75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ #include "resources/resourcemanager.h" #include "utils/gettext.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" #ifdef __APPLE__ #include @@ -964,7 +964,7 @@ int main(int argc, char *argv[]) if (n_server == 1) { SERVER_INFO *si = *server_info; - loginData.hostname = iptostring(si->address); + loginData.hostname = ipToString(si->address); loginData.port = si->port; loginData.updateHost = si->updateHost; state = UPDATE_STATE; diff --git a/src/map.cpp b/src/map.cpp index 5e38aee2..b780b5cc 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -37,7 +37,7 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" extern volatile int tick_time; diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 5bf45bb4..95555300 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -34,7 +34,7 @@ #include "../gui/ok_dialog.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" CharServerHandler::CharServerHandler(): mCharCreateDialog(0) @@ -166,7 +166,7 @@ void CharServerHandler::handleMessage(MessageIn *msg) slot = mCharInfo->getPos(); msg->skip(4); // CharID, must be the same as player_node->charID map_path = msg->readString(16); - mLoginData->hostname = iptostring(msg->readInt32()); + mLoginData->hostname = ipToString(msg->readInt32()); mLoginData->port = msg->readInt16(); mCharInfo->unlock(); mCharInfo->select(0); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 14566b39..6717f515 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -35,8 +35,7 @@ #include "../gui/chat.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" extern Being *player_node; diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index ac5f94d3..8ea0071d 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -38,7 +38,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" InventoryHandler::InventoryHandler() { diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index e173252f..cf45dbd4 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -31,7 +31,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern SERVER_INFO **server_info; @@ -111,7 +111,7 @@ void LoginHandler::handleMessage(MessageIn *msg) logger->log("Network: Server: %s (%s:%d)", server_info[i]->name.c_str(), - iptostring(server_info[i]->address), + ipToString(server_info[i]->address), server_info[i]->port); } state = CHAR_SERVER_STATE; diff --git a/src/net/network.cpp b/src/net/network.cpp index 02d8bf4f..0126ad6d 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -27,7 +27,7 @@ #include "network.h" #include "../log.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** Warning: buffers and other variables are shared, so there can be only one connection active at a time */ @@ -327,7 +327,7 @@ bool Network::realConnect() } logger->log("Network::Started session with %s:%i", - iptostring(ipAddress.host), ipAddress.port); + ipToString(ipAddress.host), ipAddress.port); mState = CONNECTED; diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 9c34cec6..bce53ae9 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -39,7 +39,7 @@ #include "../gui/skill.h" #include "../gui/viewport.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" #include "../utils/gettext.h" // TODO Move somewhere else diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index ceaf0395..0031bbd0 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -30,7 +30,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" #include "../utils/xml.h" namespace @@ -125,12 +125,7 @@ void ItemDB::load() if (itr == mNamedItemInfos.end()) { std::string temp = name; - trim(temp); - - for (unsigned int i = 0; i < temp.size(); i++) - { - temp[i] = (char) tolower(temp[i]); - } + toLower(trim(temp)); mNamedItemInfos[temp] = itemInfo; } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 840f0677..901a2561 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -34,7 +34,7 @@ #include "../tileset.h" #include "../utils/base64.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" #include "../utils/xml.h" const unsigned int DEFAULT_TILE_WIDTH = 32; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp new file mode 100644 index 00000000..d414d665 --- /dev/null +++ b/src/utils/stringutils.cpp @@ -0,0 +1,64 @@ +/* + * Aethyra + * Copyright (C) 2007 The Mana World Development Team + * + * This file is part of Aethyra based on original code + * from 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 "stringutils.h" + +#include + +std::string &trim(std::string &str) +{ + std::string::size_type pos = str.find_last_not_of(' '); + if (pos != std::string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(' '); + if (pos != std::string::npos) + { + str.erase(0, pos); + } + } + else + { + // There is nothing else but whitespace in the string + str.clear(); + } + return str; +} + +std::string &toLower(std::string &str) +{ + std::transform(str.begin(), str.end(), str.begin(), tolower); + return str; +} + +const char *ipToString(int address) +{ + static char asciiIP[16]; + + sprintf(asciiIP, "%i.%i.%i.%i", + (unsigned char)(address), + (unsigned char)(address >> 8), + (unsigned char)(address >> 16), + (unsigned char)(address >> 24)); + + return asciiIP; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h new file mode 100644 index 00000000..7d8df748 --- /dev/null +++ b/src/utils/stringutils.h @@ -0,0 +1,69 @@ +/* + * Aethyra + * Copyright (C) 2007 The Mana World Development Team + * + * This file is part of Aethyra based on original code + * from 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 UTILS_STRINGUTILS_H +#define UTILS_STRINGUTILS_H + +#include +#include + +/** + * Trims spaces off the end and the beginning of the given string. + * + * @param str the string to trim spaces off + * @return a reference to the trimmed string + */ +std::string &trim(std::string &str); + +/** + * Converts the given string to lower case. + * + * @param str the string to convert to lower case + * @return a reference to the given string converted to lower case + */ +std::string &toLower(std::string &str); + +/** + * Converts the given value to a string using std::stringstream. + * + * @param arg the value to convert to a string + * @return the string representation of arg + */ +template std::string toString(const T &arg) +{ + std::stringstream ss; + ss << arg; + return ss.str(); +} + +/** + * Converts the given IP address to a string. + * + * The returned string is statically allocated, and shouldn't be freed. It is + * changed upon the next use of this method. + * + * @param address the address to convert to a string + * @return the string representation of the address + */ +const char *ipToString(int address); + +#endif // UTILS_STRINGUTILS_H diff --git a/src/utils/trim.h b/src/utils/trim.h deleted file mode 100644 index 0602842f..00000000 --- a/src/utils/trim.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Aethyra - * Copyright (C) 2007 The Mana World Development Team - * - * This file is part of Aethyra based on original code - * from 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 UTILS_TRIM_H -#define UTILS_TRIM_H - -#include - -/** - * Trims spaces off the end and the beginning of the given string. - * - * @param str the string to trim spaces off - */ -inline void trim(std::string &str) -{ - std::string::size_type pos = str.find_last_not_of(' '); - if (pos != std::string::npos) - { - str.erase(pos + 1); - pos = str.find_first_not_of(' '); - if (pos != std::string::npos) - { - str.erase(0, pos); - } - } - else - { - // There is nothing else but whitespace in the string - str.clear(); - } -} - -#endif -- cgit v1.2.3-70-g09d2 From b2540f391dddc296bcafe26cd8d1e98df38c5171 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 18 Feb 2009 13:24:55 -0700 Subject: Deleted a file which didn't manage to get deleted in the last commit. Signed-off-by: Ira Rice --- src/shopitem.cpp | 2 +- src/utils/tostring.h | 49 ------------------------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 src/utils/tostring.h diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 70a68719..8fbb7400 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -22,7 +22,7 @@ #include "shopitem.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" ShopItem::ShopItem(int id, int quantity, int price): Item(id, quantity), diff --git a/src/utils/tostring.h b/src/utils/tostring.h deleted file mode 100644 index 131d559d..00000000 --- a/src/utils/tostring.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Aethyra - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of Aethyra based on original code - * from 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 UTILS_TOSTRING_H -#define UTILS_TOSTRING_H - -#include - -template -std::string toString(const T &arg) -{ - std::stringstream ss; - ss << arg; - return ss.str(); -} - -inline char *iptostring(int address) -{ - static char asciiIP[16]; - - sprintf(asciiIP, "%i.%i.%i.%i", - (unsigned char)(address), - (unsigned char)(address >> 8), - (unsigned char)(address >> 16), - (unsigned char)(address >> 24)); - - return asciiIP; -} - -#endif -- cgit v1.2.3-70-g09d2 From 00bbc2186302fe4365f08903a209e03bb8feb4c5 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 18 Feb 2009 14:23:56 -0700 Subject: Changed shopitem to use the stringutils class instead of tostring, as the two have been merged. Signed-off-by: Ira Rice --- src/shopitem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 8fbb7400..c8015e45 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -30,3 +30,4 @@ ShopItem::ShopItem(int id, int quantity, int price): { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; } + -- cgit v1.2.3-70-g09d2 From b2eb8daa8c39bcfd5fbd3a76dbbc432b43c561a9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Fri, 20 Feb 2009 00:19:52 +0100 Subject: Added a pickup notification as particle effect. Also make a ui option to enable/disable this effect (default is off) and another option to disable the pickup notification in the chat log (default is on). --- src/gui/gui.cpp | 1 + src/gui/gui.h | 8 ++++++++ src/gui/setup_video.cpp | 41 +++++++++++++++++++++++++++++++++++------ src/gui/setup_video.h | 6 ++++++ src/gui/truetypefont.cpp | 3 ++- src/gui/truetypefont.h | 2 +- src/localplayer.cpp | 12 ++++++++++++ src/localplayer.h | 5 +++++ src/net/inventoryhandler.cpp | 15 ++++++++++++--- src/particle.cpp | 11 +++++++---- src/particle.h | 8 +++++--- src/textparticle.cpp | 23 +++++++++++++++++++++-- src/textparticle.h | 4 +++- 13 files changed, 118 insertions(+), 21 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4b5c375d..ed85fa8f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -113,6 +113,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); + mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 0c6529bd..e19a0a87 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,13 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return the Font used for "Info Particles", i.e. ones showing, what + * you picked up, etc. + */ + gcn::Font* getInfoParticleFont() const + { return mInfoParicleFont; } + /** * Sets whether a custom cursor should be rendered. */ @@ -108,6 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ + gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 8b21582e..35c58ecd 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -110,6 +110,8 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", true)), mParticleEffectsEnabled(config.getValue("particleeffects", true)), mNameEnabled(config.getValue("showownname", false)), + mPickupChatEnabled(config.getValue("showpickupchat", true)), + mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 0)), mSpeechMode((int) config.getValue("speech", 3)), @@ -137,7 +139,11 @@ Setup_Video::Setup_Video(): mOverlayDetailField(new gcn::Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")) + mParticleDetailField(new gcn::Label("")), + mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + mPickupParticleCheckBox(new CheckBox(_("as particle"), + mPickupParticleEnabled)) { setOpaque(false); @@ -170,6 +176,8 @@ Setup_Video::Setup_Video(): mModeList->setActionEventId("videomode"); mCustomCursorCheckBox->setActionEventId("customcursor"); mParticleEffectsCheckBox->setActionEventId("particleeffects"); + mPickupChatCheckBox->setActionEventId("pickupchat"); + mPickupParticleCheckBox->setActionEventId("pickupparticle"); mNameCheckBox->setActionEventId("showownname"); mAlphaSlider->setActionEventId("guialpha"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); @@ -187,6 +195,8 @@ Setup_Video::Setup_Video(): mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); + mPickupChatCheckBox->addActionListener(this); + mPickupParticleCheckBox->addActionListener(this); mNameCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); @@ -261,11 +271,14 @@ Setup_Video::Setup_Video(): ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, scrollArea, 1, 6).setPadding(2); - place(1, 0, mFsCheckBox, 3); - place(1, 1, mOpenGLCheckBox, 3); - place(1, 2, mCustomCursorCheckBox, 3); - place(1, 3, mNameCheckBox, 3); - place(1, 4, mParticleEffectsCheckBox, 3); + place(1, 0, mFsCheckBox, 2); + place(3, 0, mOpenGLCheckBox, 1); + place(1, 1, mCustomCursorCheckBox, 3); + place(1, 2, mNameCheckBox, 3); + place(1, 3, mParticleEffectsCheckBox, 3); + place(1, 4, mPickupNotifyLabel, 3); + place(1, 5, mPickupChatCheckBox, 1); + place(2, 5, mPickupParticleCheckBox, 2); place(0, 6, mAlphaSlider); place(0, 7, mFpsSlider); @@ -355,6 +368,8 @@ void Setup_Video::apply() mOpacity = config.getValue("guialpha", 0.8); mOverlayDetail = (int) config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", false); + mPickupChatEnabled = config.getValue("showpickupchat", true); + mPickupParticleEnabled = config.getValue("showpickupparticle", false); } int Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, @@ -401,6 +416,9 @@ void Setup_Video::cancel() config.setValue("showownname", mNameEnabled ? true : false); config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); + config.setValue("showpickupchat", mPickupChatEnabled ? true : false); + config.setValue("showpickupparticle", mPickupParticleEnabled ? + true : false); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -434,6 +452,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) new OkDialog(_("Particle effect settings changed"), _("Restart your client or change maps for the change to take effect.")); } + else if (event.getId() == "pickupchat") + { + config.setValue("showpickupchat", mPickupChatCheckBox->isSelected() + ? true : false); + } + else if (event.getId() == "pickupparticle") + { + config.setValue("showpickupparticle", + mPickupParticleCheckBox->isSelected() + ? true : false); + } else if (event.getId() == "speech") { int val = (int) mSpeechSlider->getValue(); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 525e8941..b491cf23 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -53,6 +53,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mNameEnabled; + bool mPickupChatEnabled; + bool mPickupParticleEnabled; double mOpacity; int mFps; int mSpeechMode; @@ -95,6 +97,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, int mParticleDetail; gcn::Slider *mParticleDetailSlider; gcn::Label *mParticleDetailField; + + gcn::Label *mPickupNotifyLabel; + gcn::CheckBox *mPickupChatCheckBox; + gcn::CheckBox *mPickupParticleCheckBox; }; #endif diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 24c60caf..e50fb457 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -78,7 +78,7 @@ typedef std::list::iterator CacheIterator; static int fontCounter; -TrueTypeFont::TrueTypeFont(const std::string& filename, int size) +TrueTypeFont::TrueTypeFont(const std::string &filename, int size, int style) { if (fontCounter == 0 && TTF_Init() == -1) { @@ -88,6 +88,7 @@ TrueTypeFont::TrueTypeFont(const std::string& filename, int size) ++fontCounter; mFont = TTF_OpenFont(filename.c_str(), size); + TTF_SetFontStyle (mFont, style); if (!mFont) { diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 35e8270f..085aa226 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -49,7 +49,7 @@ class TrueTypeFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - TrueTypeFont(const std::string& filename, int size); + TrueTypeFont(const std::string &filename, int size, int style = 0); /** * Destructor. diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 608c25b8..cbc2ec7a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -589,6 +589,18 @@ void LocalPlayer::setXp(int xp) mXp = xp; } +void LocalPlayer::pickedUp(std::string item) +{ + if (mMap) + { + // Show pickup notification + particleEngine->addTextRiseFadeOutEffect(item, + gui->getInfoParticleFont (), + mPx + 16, mPy - 16, + 40, 220, 40, true); + } +} + bool LocalPlayer::withinAttackRange(Being *target) { int dist_x = abs(target->mX - mX); diff --git a/src/localplayer.h b/src/localplayer.h index b368d7c1..0ae99bb0 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -202,6 +202,11 @@ class LocalPlayer : public Player */ void setXp(int xp); + /** + * Shows item pickup effect if the player is on a map. + */ + void pickedUp(std::string item); + /** * Returns the amount of experience points. */ diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 8ea0071d..be128609 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -26,6 +26,7 @@ #include "messagein.h" #include "protocol.h" +#include "../configuration.h" #include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" @@ -142,13 +143,21 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemType = msg->readInt8(); if (msg->readInt8() > 0) { - chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + } } else { const ItemInfo &itemInfo = ItemDB::get(itemId); const std::string amountStr = (amount > 1) ? toString(amount) : "a"; - chatWindow->chatLog(strprintf(_("You picked up %s %s"), - amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(strprintf(_("You picked up %s %s"), + amountStr.c_str(), itemInfo.getName().c_str()), + BY_SERVER); + } + if (config.getValue("showpickupparticle", false)) { + player_node->pickedUp(itemInfo.getName()); + } if (Item *item = inventory->getItem(index)) { item->setId(itemId); diff --git a/src/particle.cpp b/src/particle.cpp index 9510573f..8bc764ba 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -327,10 +327,10 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, Particle *Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y) + gcn::Font *font, int x, int y, bool outline) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font); + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -347,9 +347,12 @@ Particle *Particle::addTextSplashEffect(const std::string &text, Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y) + int x, int y, + int colorR, int colorG, + int colorB, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index 9c01bcdf..f03f081d 100644 --- a/src/particle.h +++ b/src/particle.h @@ -108,15 +108,17 @@ class Particle : public Sprite */ Particle *addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y); + gcn::Font *font, int x, int y, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y); - + int x, int y, int colorR = 255, + int colorG = 255, int colorB = 255, + bool outline = false); /** * Adds an emitter to the particle. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 3283f9fd..8a8948f4 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -24,16 +24,18 @@ #include "graphics.h" #include "textparticle.h" +#include TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font): + gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), mColorR(colorR), mColorG(colorG), - mColorB(colorB) + mColorB(colorB), + mOutline(outline) { } @@ -60,6 +62,23 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); + if (mOutline) + { + graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); + // Text outline + graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); + graphics->drawText(mText, screenX + 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX - 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY + 1, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY - 1, + gcn::Graphics::CENTER); + } graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index d847eb00..26b92a50 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -34,7 +34,7 @@ class TextParticle : public Particle */ TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font); + gcn::Font *font, bool outline = false); /** * Draws the particle image. @@ -49,6 +49,8 @@ class TextParticle : public Particle std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text readable - draw it the way + a Text is usually drawn: with outline */ }; #endif -- cgit v1.2.3-70-g09d2 From 6635294efc3d94dd468c7a4a723e7169402c018c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 20 Feb 2009 08:57:42 -0700 Subject: Removed the last of the image particle guichan fonts. Signed-off-by: Ira Rice --- data/graphics/gui/CMakeLists.txt | 3 --- data/graphics/gui/Makefile.am | 3 --- data/graphics/gui/hits_blue.png | Bin 884 -> 0 bytes data/graphics/gui/hits_red.png | Bin 813 -> 0 bytes data/graphics/gui/hits_yellow.png | Bin 907 -> 0 bytes src/being.cpp | 46 ++++++++++++++++++++++++++++++-------- src/gui/gui.cpp | 24 ++------------------ src/gui/gui.h | 11 ++------- src/localplayer.cpp | 6 +++-- 9 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 data/graphics/gui/hits_blue.png delete mode 100644 data/graphics/gui/hits_red.png delete mode 100644 data/graphics/gui/hits_yellow.png diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index c5961f7a..a562b8f1 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -9,9 +9,6 @@ SET (FILES deepbox.png default.png gui.xml - hits_blue.png - hits_red.png - hits_yellow.png hscroll_left_default.png hscroll_left_highlight.png hscroll_left_pressed.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 921469a1..f2b62698 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -12,9 +12,6 @@ gui_DATA = \ deepbox.png \ default.png \ gui.xml \ - hits_blue.png \ - hits_red.png \ - hits_yellow.png \ hscroll_left_default.png \ hscroll_left_highlight.png \ hscroll_left_pressed.png \ diff --git a/data/graphics/gui/hits_blue.png b/data/graphics/gui/hits_blue.png deleted file mode 100644 index cfb04ab8..00000000 Binary files a/data/graphics/gui/hits_blue.png and /dev/null differ diff --git a/data/graphics/gui/hits_red.png b/data/graphics/gui/hits_red.png deleted file mode 100644 index 150f1c1e..00000000 Binary files a/data/graphics/gui/hits_red.png and /dev/null differ diff --git a/data/graphics/gui/hits_yellow.png b/data/graphics/gui/hits_yellow.png deleted file mode 100644 index 6975dfd5..00000000 Binary files a/data/graphics/gui/hits_yellow.png and /dev/null differ diff --git a/src/being.cpp b/src/being.cpp index 3f34948e..cebf6d1c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -226,20 +226,36 @@ void Being::takeDamage(int amount) gcn::Font *font; std::string damage = amount ? toString(amount) : "miss"; + int red, green, blue; + + font = gui->getInfoParticleFont(); + // Selecting the right color if (damage == "miss") - font = hitYellowFont; + { + red = 255; + green = 255; + blue = 0; + } else { if (getType() == MONSTER) - font = hitBlueFont; + { + red = 0; + green = 100; + blue = 255; + } else - font = hitRedFont; + { + red = 255; + green = 50; + blue = 50; + } } // Show damage number - particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, - mPx + 16, mPy + 16); + particleEngine->addTextSplashEffect(damage, red, green, blue, font, + mPx + 16, mPy + 16, true); } void Being::showCrit() @@ -247,15 +263,27 @@ void Being::showCrit() gcn::Font *font; std::string text = "crit!"; + int red, green, blue; + + font = gui->getInfoParticleFont(); + // Selecting the right color if (getType() == MONSTER) - font = hitBlueFont; + { + red = 0; + green = 100; + blue = 255; + } else - font = hitRedFont; + { + red = 255; + green = 50; + blue = 50; + } // Show crit notice - particleEngine->addTextSplashEffect(text, 255, 255, 255, font, - mPx + 16, mPy + 16); + particleEngine->addTextSplashEffect(text, red, green, blue, font, + mPx + 16, mPy + 16, true); } void Being::handleAttack(Being *victim, int damage) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ed85fa8f..85a33218 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -113,7 +113,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); - mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); + mInfoParticleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { @@ -136,22 +136,6 @@ Gui::Gui(Graphics *graphics): gcn::Widget::setGlobalFont(mGuiFont); - // Load hits' colorful fonts - try - { - hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png", - "0123456789crit! "); - hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png", - "0123456789crit! "); - hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png", - "0123456789misxp "); - } - catch (gcn::Exception e) - { - logger->error(std::string("Unable to load colored hits' fonts: ") - + e.getMessage()); - } - // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getValue("customcursor", 1) == 1); mConfigListener = new GuiConfigListener(this); @@ -169,16 +153,12 @@ Gui::~Gui() config.removeListener("customcursor", mConfigListener); delete mConfigListener; - // Fonts used in showing hits - delete hitRedFont; - delete hitBlueFont; - delete hitYellowFont; - if (mMouseCursors) mMouseCursors->decRef(); delete mGuiFont; delete boldFont; + delete mInfoParticleFont; delete viewport; delete getTop(); diff --git a/src/gui/gui.h b/src/gui/gui.h index e19a0a87..295bc595 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -82,7 +82,7 @@ class Gui : public gcn::Gui * you picked up, etc. */ gcn::Font* getInfoParticleFont() const - { return mInfoParicleFont; } + { return mInfoParticleFont; } /** * Sets whether a custom cursor should be rendered. @@ -115,7 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; @@ -126,13 +126,6 @@ class Gui : public gcn::Gui extern Gui *gui; /**< The GUI system */ extern SDLInput *guiInput; /**< GUI input */ -/** - * Fonts used in showing hits - */ -extern gcn::Font *hitRedFont; -extern gcn::Font *hitBlueFont; -extern gcn::Font *hitYellowFont; - /** * Bolded text font */ diff --git a/src/localplayer.cpp b/src/localplayer.cpp index cbc2ec7a..9bf5d990 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -583,8 +583,10 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, hitYellowFont, - mPx + 16, mPy - 16); + particleEngine->addTextRiseFadeOutEffect(text, + gui->getInfoParticleFont(), + mPx + 16, mPy - 16, + 255, 255, 0, true); } mXp = xp; } -- cgit v1.2.3-70-g09d2 From 8c1e0d01cdd4ec664aa7a6d11a129263a353a61b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 20 Feb 2009 19:56:56 -0700 Subject: Fixed some lines from cutting off in English (which would carry over to other languages as well). Signed-off-by: Ira Rice --- src/gui/setup_video.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 35c58ecd..7e3d483c 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -288,7 +288,7 @@ Setup_Video::Setup_Video(): place(0, 11, mOverlayDetailSlider); place(0, 12, mParticleDetailSlider); - place(1, 6, alphaLabel, 2); + place(1, 6, alphaLabel, 3); place(1, 7, mFpsCheckBox).setPadding(3); place(1, 8, scrollRadiusLabel); place(1, 9, scrollLazinessLabel); @@ -299,9 +299,9 @@ Setup_Video::Setup_Video(): place(2, 7, mFpsField).setPadding(1); place(2, 8, mScrollRadiusField).setPadding(1); place(2, 9, mScrollLazinessField).setPadding(1); - place(2, 10, mSpeechLabel, 2).setPadding(2); - place(2, 11, mOverlayDetailField, 2).setPadding(2); - place(2, 12, mParticleDetailField, 2).setPadding(2); + place(2, 10, mSpeechLabel, 3).setPadding(2); + place(2, 11, mOverlayDetailField, 3).setPadding(2); + place(2, 12, mParticleDetailField, 3).setPadding(2); setDimension(gcn::Rectangle(0, 0, 325, 280)); } -- cgit v1.2.3-70-g09d2 From 1bb480c85d255dc53654dd7b86495583f7875217 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 20 Feb 2009 22:49:45 -0700 Subject: Fix debug window to show correct mouse coordinates --- src/gui/debugwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index c41e0a5e..68b70817 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -68,8 +68,8 @@ void DebugWindow::logic() // Get the current mouse position int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = mouseX / 32 + viewport->getCameraX(); - int mouseTileY = mouseY / 32 + viewport->getCameraY(); + int mouseTileX = (mouseX + viewport->getCameraX()) / 32; + int mouseTileY = (mouseY + viewport->getCameraY()) / 32; mFPSLabel->setCaption(toString(fps) + " FPS"); mFPSLabel->adjustSize(); -- cgit v1.2.3-70-g09d2 From d27772e75e53731a39df96e5256b089a9aa3075d Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 22 Feb 2009 18:00:14 +0100 Subject: Fixed another Particle/Paricle mismatch in a comment --- src/gui/gui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/gui.h b/src/gui/gui.h index 295bc595..afa358be 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -115,7 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; -- cgit v1.2.3-70-g09d2 From 48fb40dba78a5b748b53abfa79f8c0442a72a9c7 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 23 Feb 2009 08:56:25 -0700 Subject: Clean up of Aethyra logo on 800x600 wallpaper by Taz2781. Signed-off-by: Ira Rice --- data/graphics/images/login_wallpaper.png | Bin 187106 -> 476965 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/graphics/images/login_wallpaper.png b/data/graphics/images/login_wallpaper.png index 06a9e94f..96389618 100644 Binary files a/data/graphics/images/login_wallpaper.png and b/data/graphics/images/login_wallpaper.png differ -- cgit v1.2.3-70-g09d2 From f65c1e48107fa2cc615c86d8f6829b50c05baa3f Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:19:55 +0100 Subject: Allow to sell non-stackable items like stackables Make it possible to sell non-stackable items all at once by introducing "Duplicate Items" and a Shop that can handle them. Also fix a trivial bug to correctly preview you money while selling. --- src/gui/sell.cpp | 33 ++++++++++++++------- src/gui/shop.cpp | 51 +++++++++++++++++++++++++++----- src/gui/shop.h | 59 ++++++++++++++++++++++++++++++++----- src/shopitem.cpp | 58 ++++++++++++++++++++++++++++++++++-- src/shopitem.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 259 insertions(+), 32 deletions(-) diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index fd271c63..f974f247 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -50,7 +50,8 @@ SellDialog::SellDialog(Network *network): setMinHeight(230); setDefaultSize(0, 0, 260, 230); - mShopItems = new ShopItems(); + // Create a ShopItems instance, that is aware of duplicate entries. + mShopItems = new ShopItems(true); mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); @@ -115,10 +116,11 @@ void SellDialog::reset() void SellDialog::addItem(const Item *item, int price) { if (!item) + { return; + } - mShopItems->addItem( - item->getInvIndex(), item->getId(), + mShopItems->addItem(item->getInvIndex(), item->getId(), item->getQuantity(), price); mShopItemList->adjustSize(); @@ -164,23 +166,34 @@ void SellDialog::action(const gcn::ActionEvent &event) { // Attempt sell MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mShopItems->at(selectedItem)->getInvIndex()); - outMsg.writeInt16(mAmountItems); + ShopItem* item = mShopItems->at(selectedItem); + int sellCount; + mPlayerMoney += + mAmountItems * mShopItems->at(selectedItem)->getPrice(); mMaxItems -= mAmountItems; - mShopItems->getShop()->at(selectedItem)->setQuantity(mMaxItems); + while (mAmountItems > 0) { + outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); + outMsg.writeInt16(8); + outMsg.writeInt16(item->getCurrentInvIndex()); + // This order is important, item->getCurrentInvIndex() would return + // the inventory index of the next Duplicate otherwise. + sellCount = item->sellCurrentDuplicate(mAmountItems); + mAmountItems -= sellCount; + outMsg.writeInt16(sellCount); + } + mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); mAmountItems = 1; + mSlider->setValue(0); if (!mMaxItems) { // All were sold mShopItemList->setSelected(-1); - mShopItems->getShop()->erase( - mShopItems->getShop()->begin() + selectedItem); + delete mShopItems->at(selectedItem); + mShopItems->erase(selectedItem); gcn::Rectangle scroll; scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1); diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index a56116d3..da68cf28 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -24,6 +24,11 @@ #include "../utils/dtor.h" +ShopItems::ShopItems(bool mergeDuplicates) : + mMergeDuplicates(mergeDuplicates) +{ +} + ShopItems::~ShopItems() { clear(); @@ -39,16 +44,29 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int inventoryIndex, short id, int amount, int price) +void ShopItems::addItem(int inventoryIndex, int id, int quantity, + int price) { - ShopItem *item = new ShopItem(id, amount, price); - item->setInvIndex(inventoryIndex); - mShopItems.push_back(item); + ShopItem* item = 0; + if (mMergeDuplicates) + { + item = findItem(id); + } + + if (item) + { + item->addDuplicate (inventoryIndex, quantity); + } + else + { + item = new ShopItem(inventoryIndex, id, quantity, price); + mShopItems.push_back(item); + } } -void ShopItems::addItem(short id, int price) +void ShopItems::addItem(int id, int price) { - mShopItems.push_back(new ShopItem(id, 0, price)); + addItem(-1, id, 0, price); } ShopItem* ShopItems::at(int i) const @@ -56,13 +74,30 @@ ShopItem* ShopItems::at(int i) const return mShopItems.at(i); } +void ShopItems::erase(int i) +{ + mShopItems.erase(mShopItems.begin() + i); +} + void ShopItems::clear() { delete_all(mShopItems); mShopItems.clear(); } -std::vector* ShopItems::getShop() +ShopItem* ShopItems::findItem(int id) { - return &mShopItems; + ShopItem *item; + + std::vector::iterator it; + for(it = mShopItems.begin(); it != mShopItems.end(); it++) + { + item = *(it); + if (item->getId() == id) + { + return item; + } + } + + return 0; } diff --git a/src/gui/shop.h b/src/gui/shop.h index 166eb00b..26a9429d 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -32,31 +32,62 @@ class ShopItem; +/** + * This class handles the list of items available in a shop. + * + * The addItem routine can automatically check, if an item already exists and + * only adds duplicates to the old item, if one is found. The original + * distribution of the duplicates can be retrieved from the item. + * + * This functionality can be enabled in the constructor. + */ class ShopItems : public gcn::ListModel { public: + /** + * Constructor. Creates a new ShopItems instance. + * + * @param mergeDuplicates lets the Shop look for duplicate entries and + * merges them to one item. + */ + ShopItems(bool mergeDuplicates = false); + /** * Destructor. */ ~ShopItems(); /** - * Adds an item to the list (used by sell dialog). + * Adds an item to the list (used by sell dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item */ - void addItem(int inventoryIndex, short id, int amount, int price); + void addItem(int inventoryIndex, int id, int amount, int price); /** - * Adds an item to the list (used by buy dialog). + * Adds an item to the list (used by buy dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param id the id of the item + * @param price price of the item */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Returns the number of items in the shop. + * + * @return the number of items in the shop */ int getNumberOfElements(); /** * Returns the name of item number i in the shop. + * + * @param i the index to retrieve */ std::string getElementAt(int i); @@ -65,18 +96,32 @@ class ShopItems : public gcn::ListModel */ ShopItem* at(int i) const; + /** + * Removes an element from the shop. + * + * @param i index to remove + */ + void erase(int i); + /** * Clear the vector. */ void clear(); + private: /** - * Direct access to the vector. + * Searches the current items in the shop for the specified + * id and returns the item if found, or 0 else. + * + * @return the item found or 0 */ - std::vector* getShop(); + ShopItem* findItem(int id); - private: + /** the shop storage */ std::vector mShopItems; + + /** Look for duplicate entries on addition */ + bool mMergeDuplicates; }; #endif diff --git a/src/shopitem.cpp b/src/shopitem.cpp index c8015e45..5573eb37 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -24,10 +24,62 @@ #include "utils/stringutils.h" -ShopItem::ShopItem(int id, int quantity, int price): - Item(id, quantity), - mPrice(price) +ShopItem::ShopItem (int inventoryIndex, int id, + int quantity, int price) : + Item (id, 0), mPrice(price) { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; + setInvIndex(inventoryIndex); + addDuplicate(inventoryIndex, quantity); +} + +ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price) +{ + mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; + setInvIndex(-1); + addDuplicate(-1, 0); +} + +ShopItem::~ShopItem() +{ + /** Clear all remaining duplicates on Object destruction. */ + while (!mDuplicates.empty()) + { + delete mDuplicates.top(); + mDuplicates.pop(); + } +} + +void ShopItem::addDuplicate(int inventoryIndex, + int quantity) +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = inventoryIndex; + di->quantity = quantity; + mDuplicates.push(di); + mQuantity += quantity; +} + + +void ShopItem::addDuplicate() +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = -1; + di->quantity = 0; + mDuplicates.push(di); +} + +int ShopItem::sellCurrentDuplicate(int quantity) +{ + DuplicateItem* dupl = mDuplicates.top(); + int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity; + dupl->quantity -= sellCount; + mQuantity -= sellCount; + if (dupl->quantity == 0) + { + delete dupl; + mDuplicates.pop(); + } + return sellCount; } diff --git a/src/shopitem.h b/src/shopitem.h index 8b1ba4b2..d6226732 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -23,27 +23,100 @@ #ifndef _SHOPITEM_H #define _SHOPITEM_H +#include + #include "item.h" /** - * Represents an item in a shop inventory. + * Represents an item in a shop inventory. It can store quantity and inventory + * indices of duplicate entries in the shop as well. */ class ShopItem : public Item { public: /** - * Constructor. + * Constructor. Creates a new ShopItem. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item + */ + ShopItem(int inventoryIndex, int id, int quantity, int price); + + /** + * Constructor. Creates a new ShopItem. Inventory index will be set to + * -1 and quantity to 0. + * + * @param id the id of the item + * @param price price of the item + */ + ShopItem(int id, int price); + + /** + * Destructor. + */ + ~ShopItem(); + + /** + * Add a duplicate. Id and price will be taken from this item. + * + * @param inventoryIndex the inventory index of the item + * @param quantity number of available copies of the item + */ + void addDuplicate (int inventoryIndex, int quantity); + + /** + * Add a duplicate. Id and price will be taken from this item. + * Needed for compatibility with ShopDuplicateItems (see) class + * documentation). */ - ShopItem(int id, int quantity, int price); + void addDuplicate (); + + /** + * Gets the quantity of the currently topmost duplicate. + * + * @return the quantity of the currently topmost duplicate + */ + int getCurrentQuantity() { + return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity; + } + + /** + * Gets the inventory index of the currently topmost duplicate. + * + * @return the inventory index of the currently topmost duplicate + */ + int getCurrentInvIndex() { + return mDuplicates.empty() ? mInvIndex : + mDuplicates.top()->inventoryIndex; + } + + /** + * Reduces the quantity of the topmost duplicate by the specified + * amount. Also reduces the total quantity of this DuplicateItem. + * Empty duplicates are automatically removed. + * + * If the amount is bigger than the quantity of the current topmost, + * only sell as much as possible. Returns the amount actually sold (do + * not ignore the return value!) + * + * @return the amount, that actually was sold. + */ + int sellCurrentDuplicate(int quantity); /** * Gets the price of the item. + * + * @return the price of the item */ int getPrice() const { return mPrice; } /** - * Gets the display name for in the shop list. + * Gets the display name for the item in the shop list. + * + * @return the display name for the item in the shop list */ const std::string& getDisplayName() const { return mDisplayName; } @@ -52,6 +125,15 @@ class ShopItem : public Item int mPrice; int mIndex; std::string mDisplayName; + + /** + * Struct to keep track of duplicates. + */ + typedef struct { + int inventoryIndex; + int quantity; + } DuplicateItem; + std::stack mDuplicates; /** <-- Stores duplicates */ }; #endif -- cgit v1.2.3-70-g09d2 From 95c7c2fb3468a96415736d1f4d1faf28e6c81aa2 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 10:33:22 -0700 Subject: Fix update handling THis will prevent loading updates when -u is used, and prevent error messages in the log when -u is used. --- src/main.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 06ec2f75..f7468d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -586,6 +586,7 @@ void parseOptions(int argc, char *argv[], Options &options) */ void loadUpdates() { + if (updatesDir.empty()) return; const std::string updatesFile = "/" + updatesDir + "/resources2.txt"; ResourceManager *resman = ResourceManager::getInstance(); std::vector lines = resman->loadTextFile(updatesFile); @@ -971,8 +972,7 @@ int main(int argc, char *argv[]) } else { - int nextState = (options.skipUpdate) ? - LOADDATA_STATE : UPDATE_STATE; + int nextState = UPDATE_STATE; currentDialog = new ServerSelectDialog(&loginData, nextState); positionDialog(currentDialog, screenWidth, @@ -1032,18 +1032,18 @@ int main(int argc, char *argv[]) break; case UPDATE_STATE: - // Determine which source to use for the update host - if (!options.updateHost.empty()) - updateHost = options.updateHost; - else - updateHost = loginData.updateHost; - - setUpdatesDir(); - logger->log("State: UPDATE"); - if (options.skipUpdate) { state = LOADDATA_STATE; } else { + // Determine which source to use for the update host + if (!options.updateHost.empty()) + updateHost = options.updateHost; + else + updateHost = loginData.updateHost; + + setUpdatesDir(); + logger->log("State: UPDATE"); + currentDialog = new UpdaterWindow(updateHost, homeDir + "/" + updatesDir); positionDialog(currentDialog, screenWidth, -- cgit v1.2.3-70-g09d2 From e85269ffe1fe91f5cf44ccfec01252343643ef1d Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 20:44:21 -0700 Subject: Don't set current_npc when initiating interraction Let it be set by the netcode if the NPC responds. This caused a movement bug if they didn't. --- src/npc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/npc.cpp b/src/npc.cpp index 5540350a..dbd7a990 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -107,7 +107,6 @@ void NPC::talk() outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); outMsg.writeInt8(0); - current_npc = this; } void NPC::nextDialog() -- cgit v1.2.3-70-g09d2 From a1e483913672e55704e8fbafeff5ea0ccc0c9b07 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 24 Feb 2009 23:03:31 -0700 Subject: Cleaned up some code, as well as removed redundant talk client requesting (which would happen from using the keyboard instead of the mouse). Signed-off-by: Ira Rice --- src/game.cpp | 44 ++++++++++++++++++++++++-------------------- src/gui/npc_text.cpp | 7 ++++++- src/gui/npc_text.h | 2 ++ src/gui/npcintegerdialog.h | 2 ++ src/gui/npclistdialog.h | 2 ++ src/gui/npcstringdialog.h | 2 ++ src/gui/textbox.cpp | 32 +++++++++++++------------------- src/gui/viewport.cpp | 29 +++++++++++++++++++---------- src/net/npchandler.cpp | 7 ++----- src/net/playerhandler.cpp | 9 ++++++--- src/npc.cpp | 12 +++++++++--- src/npc.h | 2 ++ 12 files changed, 89 insertions(+), 61 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index e4b6e54d..e5f7b22b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -145,9 +145,9 @@ namespace { { void action(const gcn::ActionEvent &event) { - if (event.getId() == "yes" || event.getId() == "ok") { + if (event.getId() == "yes" || event.getId() == "ok") done = true; - } + exitConfirm = NULL; disconnectedDialog = NULL; } @@ -178,13 +178,9 @@ Uint32 nextSecond(Uint32 interval, void *param) int get_elapsed_time(int start_time) { if (start_time <= tick_time) - { return (tick_time - start_time) * 10; - } else - { return (tick_time + (MAX_TIME - start_time)) * 10; - } } /** @@ -213,8 +209,10 @@ void createGuiWindows(Network *network) tradeWindow = new TradeWindow(network); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); - itemShortcutWindow = new ShortcutWindow("ItemShortcut",new ItemShortcutContainer); - emoteShortcutWindow = new ShortcutWindow("emoteShortcut",new EmoteShortcutContainer); + itemShortcutWindow = new ShortcutWindow("ItemShortcut", + new ItemShortcutContainer); + emoteShortcutWindow = new ShortcutWindow("emoteShortcut", + new EmoteShortcutContainer); // Set initial window visibility chatWindow->setVisible((bool) config.getValue( @@ -465,7 +463,9 @@ void Game::logic() if (!disconnectedDialog) { disconnectedDialog = new OkDialog(_("Network Error"), - _("The connection to the server was lost, the program will now quit")); + _("The connection to the " + "server was lost, the " + "program will now quit")); disconnectedDialog->addActionListener(&exitListener); disconnectedDialog->requestMoveToTop(); } @@ -853,9 +853,11 @@ void Game::handleInput() } // Attack priorioty is: Monster, Player, auto target - target = beingManager->findBeing(targetX, targetY, Being::MONSTER); + target = beingManager->findBeing(targetX, targetY, + Being::MONSTER); if (!target) - target = beingManager->findBeing(targetX, targetY, Being::PLAYER); + target = beingManager->findBeing(targetX, targetY, + Being::PLAYER); } player_node->attack(target, newTarget); @@ -863,30 +865,31 @@ void Game::handleInput() // Target the nearest player if 'q' is pressed if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) + !keyboard.isKeyActive(keyboard.KEY_TARGET) ) { - Being *target = beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); + Being *target = beingManager->findNearestLivingBeing(player_node, + 20, Being::PLAYER); player_node->setTarget(target); } // Target the nearest monster if 'a' pressed if ((keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || - (joystick && joystick->buttonPressed(3))) && - !keyboard.isKeyActive(keyboard.KEY_TARGET)) + (joystick && joystick->buttonPressed(3))) && + !keyboard.isKeyActive(keyboard.KEY_TARGET)) { Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::MONSTER); + x, y, 20, Being::MONSTER); player_node->setTarget(target); } // Target the nearest npc if 'n' pressed if ( keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) + !keyboard.isKeyActive(keyboard.KEY_TARGET) ) { Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); + x, y, 20, Being::NPC); player_node->setTarget(target); } @@ -894,14 +897,15 @@ void Game::handleInput() // Talk to the nearest NPC if 't' pressed if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) { - if (!npcTextDialog->isVisible() && !npcListDialog->isVisible()) + if (!npcTextDialog->isVisible() && !npcListDialog->isVisible() && + !npcStringDialog->isVisible() && !npcIntegerDialog->isVisible()) { Being *target = player_node->getTarget(); if (!target) { target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); + x, y, 20, Being::NPC); } if (target) diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ed75b76e..0b7592c7 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -73,11 +73,16 @@ void NpcTextDialog::addText(const std::string &text) setText(mText + text + "\n"); } +void NpcTextDialog::clearText() +{ + setText(""); +} + void NpcTextDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { - setText(""); + clearText(); setVisible(false); if (current_npc) diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 5e2ff118..63d41cd6 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -87,4 +87,6 @@ class NpcTextDialog : public Window, public gcn::ActionListener std::string mText; }; +extern NpcTextDialog *npcTextDialog; + #endif // NPC_TEXT_H diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 858bce5b..a4ca33cf 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -81,4 +81,6 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener gcn::Button *resetButton; }; +extern NpcIntegerDialog *npcIntegerDialog; + #endif // GUI_NPCINTEGERDIALOG_H diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 8d8b6545..a30bec28 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -82,4 +82,6 @@ class NpcListDialog : public Window, public gcn::ActionListener, std::vector mItems; }; +extern NpcListDialog *npcListDialog; + #endif // GUI_NPCLISTDIALOG_H diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 71d1f15c..c8871184 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -75,4 +75,6 @@ class NpcStringDialog : public Window, public gcn::ActionListener gcn::Button *cancelButton; }; +extern NpcStringDialog *npcStringDialog; + #endif // GUI_NPCSTRINGDIALOG_H diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index dc94ead2..589986cd 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -38,52 +38,46 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) { // Make sure parent scroll area sets width of this widget if (getParent()) - { getParent()->logic(); - } // Take the supplied minimum dimension as a starting point and try to beat it mMinWidth = minDimension; std::stringstream wrappedStream; - std::string::size_type newlinePos, lastNewlinePos = 0; + std::string::size_type spacePos, newlinePos, lastNewlinePos = 0; int minWidth = 0; int xpos; + spacePos = text.rfind(" ", text.size()); + + if (spacePos != std::string::npos) + { + const std::string word = text.substr(spacePos + 1); + const int length = getFont()->getWidth(word); + + if (length > mMinWidth) + mMinWidth = length; + } + do { // Determine next piece of string to wrap newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) - { newlinePos = text.size(); - } std::string line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); - std::string::size_type spacePos, lastSpacePos = 0; + std::string::size_type lastSpacePos = 0; xpos = 0; - spacePos = text.rfind(" ", text.size()); - - if (spacePos != std::string::npos) - { - const std::string word = text.substr(spacePos + 1); - const int length = getFont()->getWidth(word); - - if (length > mMinWidth) - mMinWidth = length; - } - do { spacePos = line.find(" ", lastSpacePos); if (spacePos == std::string::npos) - { spacePos = line.size(); - } std::string word = line.substr(lastSpacePos, spacePos - lastSpacePos); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 9a7f6173..f655888c 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -111,19 +111,23 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { if (player_x > mPixelViewX + mScrollRadius) { - mPixelViewX += (player_x - mPixelViewX - mScrollRadius) / mScrollLaziness; + mPixelViewX += (player_x - mPixelViewX - mScrollRadius) / + mScrollLaziness; } if (player_x < mPixelViewX - mScrollRadius) { - mPixelViewX += (player_x - mPixelViewX + mScrollRadius) / mScrollLaziness; + mPixelViewX += (player_x - mPixelViewX + mScrollRadius) / + mScrollLaziness; } if (player_y > mPixelViewY + mScrollRadius) { - mPixelViewY += (player_y - mPixelViewY - mScrollRadius) / mScrollLaziness; + mPixelViewY += (player_y - mPixelViewY - mScrollRadius) / + mScrollLaziness; } if (player_y < mPixelViewY - mScrollRadius) { - mPixelViewY += (player_y - mPixelViewY + mScrollRadius) / mScrollLaziness; + mPixelViewY += (player_y - mPixelViewY + mScrollRadius) / + mScrollLaziness; } lastTick++; } @@ -166,8 +170,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); - // Find a path from the player to the mouse, and draw it. This is for debug - // purposes. + // Find a path from the player to the mouse, and draw it. This is for + // debug purposes. if (mShowDebugPath) { // Get the current mouse position @@ -177,7 +181,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int mouseTileX = mouseX / 32 + mTileViewX; int mouseTileY = mouseY / 32 + mTileViewY; - Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY); + Path debugPath = mMap->findPath(player_node->mX, player_node->mY, + mouseTileX, mouseTileY); graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) @@ -186,7 +191,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int squareY = i->y * 32 - (int) mPixelViewY + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); - graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), squareX + 4, squareY + 12, gcn::Graphics::CENTER); + graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), + squareX + 4, squareY + 12, + gcn::Graphics::CENTER); } } } @@ -300,10 +307,12 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (being->mAction == Being::DEAD) break; - if (player_node->withinAttackRange(being) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) + if (player_node->withinAttackRange(being) || + keyboard.isKeyActive(keyboard.KEY_ATTACK)) { player_node->setGotoTarget(being); - player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET)); + player_node->attack(being, + !keyboard.isKeyActive(keyboard.KEY_TARGET)); } else { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 8425a215..94e145b4 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -33,11 +33,6 @@ #include "../gui/npclistdialog.h" #include "../gui/npcstringdialog.h" -extern NpcIntegerDialog *npcIntegerDialog; -extern NpcListDialog *npcListDialog; -extern NpcTextDialog *npcTextDialog; -extern NpcStringDialog *npcStringDialog; - NPCHandler::NPCHandler() { static const Uint16 _messages[] = { @@ -81,10 +76,12 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == dynamic_cast(beingManager->findBeing(id))) current_npc = NULL; + NPC::mTalking = false; break; case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused + NPC::mTalking = false; break; case SMSG_NPC_INT_INPUT: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index bce53ae9..c1e0d033 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -32,8 +32,10 @@ #include "../gui/buy.h" #include "../gui/chat.h" #include "../gui/gui.h" -#include "../gui/npclistdialog.h" #include "../gui/npc_text.h" +#include "../gui/npcintegerdialog.h" +#include "../gui/npclistdialog.h" +#include "../gui/npcstringdialog.h" #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" @@ -46,8 +48,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern NpcListDialog *npcListDialog; -extern NpcTextDialog *npcTextDialog; extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; @@ -81,7 +81,10 @@ namespace { { player_node->revive(); deathNotice = NULL; + npcIntegerDialog->setVisible(false); npcListDialog->setVisible(false); + npcStringDialog->setVisible(false); + npcTextDialog->clearText(); npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); diff --git a/src/npc.cpp b/src/npc.cpp index dbd7a990..eaf6b78b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -25,12 +25,15 @@ #include "particle.h" #include "text.h" +#include "gui/npc_text.h" + #include "net/messageout.h" #include "net/protocol.h" #include "resources/npcdb.h" NPC *current_npc = 0; +bool NPC::mTalking = false; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -46,7 +49,8 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): i != info.sprites.end(); i++) { - if (c == VECTOREND_SPRITE) break; + if (c == VECTOREND_SPRITE) + break; std::string file = "graphics/sprites/" + (*i)->sprite; int variant = (*i)->variant; @@ -103,6 +107,10 @@ Being::Type NPC::getType() const void NPC::talk() { + if (mTalking) + return; + + mTalking = true; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); @@ -165,7 +173,5 @@ void NPC::sell() void NPC::updateCoords() { if (mName) - { mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); - } } diff --git a/src/npc.h b/src/npc.h index f8aaad7f..0dc9c742 100644 --- a/src/npc.h +++ b/src/npc.h @@ -51,6 +51,8 @@ class NPC : public Player void buy(); void sell(); + static bool mTalking; + protected: Network *mNetwork; void updateCoords(); -- cgit v1.2.3-70-g09d2 From d8bc3a6418c5027d7f6c42ce8f8dceca8dee8971 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 00:50:33 -0700 Subject: Fixed up NPC list dialogs to be navigatable by keyboard (scrolling through the list requires the use of the mouse wheel at the moment), fixed wrapping behavior for wrapping around lists to actually wrap around lists properly, and placed a few checks for current_npc where they were assumed before which could cause the client to hang or crash in case the NPC is no longer around. Signed-off-by: Ira Rice --- src/game.cpp | 2 +- src/gui/listbox.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/listbox.h | 19 ++++++++++ src/gui/npcintegerdialog.cpp | 11 +++--- src/gui/npclistdialog.cpp | 16 +++++++-- src/gui/npclistdialog.h | 5 +++ src/gui/npcstringdialog.cpp | 5 ++- src/gui/table.cpp | 6 +--- src/net/npchandler.cpp | 2 +- 9 files changed, 136 insertions(+), 15 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index e5f7b22b..16790cac 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -490,7 +490,7 @@ void Game::handleInput() gcn::Window *requestedWindow = NULL; if (setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) { keyboard.setNewKey((int) event.key.keysym.sym); keyboard.callbackNewKey(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index f16857ce..8ae68e09 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include "color.h" @@ -69,6 +70,90 @@ void ListBox::draw(gcn::Graphics *graphics) } } +void ListBox::setSelected(int selected) +{ + if (!mListModel) + { + mSelected = -1; + } + else + { + if (selected < 0 && !mWrappingEnabled) + { + mSelected = -1; + } + else if (selected >= mListModel->getNumberOfElements() && + mWrappingEnabled) + { + mSelected = 0; + } + else if ((selected >= mListModel->getNumberOfElements() && + !mWrappingEnabled) || (selected < 0 && mWrappingEnabled)) + { + mSelected = mListModel->getNumberOfElements() - 1; + } + else + { + mSelected = selected; + } + } +} + +// -- KeyListener notifications +void ListBox::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == gcn::Key::ENTER || key.getValue() == gcn::Key::SPACE) + { + distributeActionEvent(); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::UP) + { + setSelected(mSelected - 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::DOWN) + { + setSelected(mSelected + 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::END) + { + setSelected(getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } +} + +void ListBox::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + if (getSelected() > 0 || (getSelected() == 0 && mWrappingEnabled)) + { + setSelected(getSelected() - 1); + } + + mouseEvent.consume(); + } +} + +void ListBox::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + setSelected(getSelected() + 1); + + mouseEvent.consume(); + } +} + void ListBox::mouseDragged(gcn::MouseEvent &event) { // Pretend mouse is pressed continuously while dragged. Causes list diff --git a/src/gui/listbox.h b/src/gui/listbox.h index e783083f..a6392a94 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -49,6 +49,25 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); + // Inherited from KeyListener + + virtual void keyPressed(gcn::KeyEvent& keyEvent); + + // Inherited from MouseListener + + virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); + private: static float mAlpha; }; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index ea3398c9..d0a7c7be 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -72,15 +72,15 @@ int NpcIntegerDialog::getValue() void NpcIntegerDialog::action(const gcn::ActionEvent &event) { - int finish = 0; + bool finish = false; if (event.getId() == "ok") { - finish = 1; + finish = true; } else if (event.getId() == "cancel") { - finish = 1; + finish = true; mValueField->reset(); } else if (event.getId() == "decvalue") @@ -99,7 +99,10 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + if (current_npc) + current_npc->integerInput(mValueField->getValue()); + current_npc = NULL; mValueField->reset(); } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 81c33049..f3bb949a 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,9 @@ NpcListDialog::NpcListDialog(): mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); + scrollArea = new ScrollArea(mItemList); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); @@ -95,10 +97,9 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { // Send the selected index back to the server int selectedIndex = mItemList->getSelected(); + if (selectedIndex > -1) - { choice = selectedIndex + 1; - } } else if (event.getId() == "cancel") { @@ -109,7 +110,16 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + + if (current_npc) + current_npc->dialogChoice(choice); + current_npc = NULL; } } + +void NpcListDialog::requestFocus() +{ + mItemList->requestFocus(); + mItemList->setSelected(0); +} diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index a30bec28..de3a7a77 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -73,6 +73,11 @@ class NpcListDialog : public Window, public gcn::ActionListener, */ void reset(); + /** + * Requests the listbox to take focus for input. + */ + void requestFocus(); + private: gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index ef2de73a..140ca40f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,7 +64,10 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + + if (current_npc) + current_npc->stringInput(mValueField->getText()); + current_npc = NULL; mValueField->setText(""); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 8acbc4f4..29a33b7a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -402,25 +402,21 @@ void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) else if (key.getValue() == gcn::Key::UP) { setSelectedRow(mSelectedRow - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) { setSelectedRow(mSelectedRow + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::LEFT) { setSelectedColumn(mSelectedColumn - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::RIGHT) { setSelectedColumn(mSelectedColumn + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::HOME) @@ -460,7 +456,7 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) { if (isFocused()) { - if (getSelectedRow() >= 0 ) + if (getSelectedRow() > 0 || (getSelectedRow() == 0 && mWrappingEnabled)) { setSelectedRow(getSelectedRow() - 1); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 94e145b4..26250d9e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,6 +60,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); + npcListDialog->requestFocus(); break; case SMSG_NPC_MESSAGE: @@ -68,7 +69,6 @@ void NPCHandler::handleMessage(MessageIn *msg) player_node->setAction(LocalPlayer::STAND); current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(false); npcTextDialog->setVisible(true); break; -- cgit v1.2.3-70-g09d2 From 0aaf301660a504d94f758ac8a4d50dc33c189fa7 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 08:03:00 -0700 Subject: If no network is set, then don't continue Based on TMW commit a996d4bff3cc5a35ee5cdb6cb5bdef920cf44120 Signed-off-by: Ira Rice --- src/npc.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/npc.cpp b/src/npc.cpp index eaf6b78b..832e6926 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -107,7 +107,7 @@ Being::Type NPC::getType() const void NPC::talk() { - if (mTalking) + if (mTalking || !mNetwork) return; mTalking = true; @@ -119,6 +119,9 @@ void NPC::talk() void NPC::nextDialog() { + if (!mNetwork) + return; + MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(mId); @@ -156,6 +159,9 @@ void NPC::stringInput(const std::string &value) */ void NPC::buy() { + if (!mNetwork) + return; + MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeInt32(mId); @@ -164,6 +170,9 @@ void NPC::buy() void NPC::sell() { + if (!mNetwork) + return; + MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeInt32(mId); -- cgit v1.2.3-70-g09d2 From 543166b9d50ebf06bfc83a32fb2bab3b366eb871 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 10:29:34 -0700 Subject: Make sure that all dialogs are cleared on player death, not just the NPC text dialog. Signed-off-by: Ira Rice --- src/gui/npc_text.cpp | 1 + src/gui/npcintegerdialog.cpp | 5 +++++ src/gui/npcintegerdialog.h | 5 +++++ src/gui/npclistdialog.cpp | 1 + src/net/npchandler.cpp | 2 -- src/net/playerhandler.cpp | 4 +++- 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 0b7592c7..c28f1403 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -75,6 +75,7 @@ void NpcTextDialog::addText(const std::string &text) void NpcTextDialog::clearText() { + NPC::mTalking = false; setText(""); } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index d0a7c7be..9c49a630 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -70,6 +70,11 @@ int NpcIntegerDialog::getValue() return mValueField->getValue(); } +void NpcIntegerDialog::reset() +{ + mValueField->reset(); +} + void NpcIntegerDialog::action(const gcn::ActionEvent &event) { bool finish = false; diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index a4ca33cf..cca8cb32 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -54,6 +54,11 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener */ int getValue(); + /** + * Resets the integer input field. + */ + void reset(); + /** * Prepares the NPC dialog. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f3bb949a..2c4dfc04 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -86,6 +86,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + mItemList->setSelected(-1); mItems.clear(); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 26250d9e..a59ee814 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -76,12 +76,10 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == dynamic_cast(beingManager->findBeing(id))) current_npc = NULL; - NPC::mTalking = false; break; case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused - NPC::mTalking = false; break; case SMSG_NPC_INT_INPUT: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index c1e0d033..0637d784 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -82,14 +82,16 @@ namespace { player_node->revive(); deathNotice = NULL; npcIntegerDialog->setVisible(false); + npcListDialog->reset(); npcListDialog->setVisible(false); + npcStringDialog->setValue(""); npcStringDialog->setVisible(false); npcTextDialog->clearText(); npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = 0; + current_npc = NULL; } } deathListener; } -- cgit v1.2.3-70-g09d2 From 6cd131052c78af04e794409189a0d7e16dcc0c51 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 10:32:49 -0700 Subject: Added method for resetting npc integer dialogs in the last commit, but forgot to use it. Signed-off-by: Ira Rice --- src/net/playerhandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 0637d784..f18c5d82 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -81,6 +81,7 @@ namespace { { player_node->revive(); deathNotice = NULL; + npcIntegerDialog->reset(); npcIntegerDialog->setVisible(false); npcListDialog->reset(); npcListDialog->setVisible(false); -- cgit v1.2.3-70-g09d2 From 0dde31c3db09113639fa443142995b6efcff6646 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 19:04:39 -0700 Subject: Fix NPC handling to not need a handle on the NPC Loosely based on TMW commit f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Signed-off-by: Ira Rice --- src/beingmanager.cpp | 10 +++++++ src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buysell.cpp | 34 +++++++++++++++++------ src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 18 +++++++++--- src/gui/npc_text.h | 9 ++++-- src/gui/npcintegerdialog.cpp | 16 +++++++---- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 16 +++++++---- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 22 +++++++++++---- src/gui/npcstringdialog.h | 5 +++- src/net/beinghandler.cpp | 13 ++++----- src/net/buysellhandler.cpp | 25 ++++++++++------- src/net/npchandler.cpp | 22 +++++++-------- src/net/playerhandler.cpp | 2 +- src/npc.cpp | 65 ++------------------------------------------ src/npc.h | 13 +++------ 19 files changed, 165 insertions(+), 141 deletions(-) diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index b4ffa76c..d63e0dc5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -253,3 +253,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 59a7c76a..32ba6242 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -99,13 +99,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 16790cac..110b75cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -195,13 +195,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow(); buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog(); + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow(); emoteWindow = new EmoteWindow(); - npcTextDialog = new NpcTextDialog(); - npcIntegerDialog = new NpcIntegerDialog(); - npcListDialog = new NpcListDialog(); - npcStringDialog = new NpcStringDialog(); + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); setupWindow = new Setup(); minimap = new Minimap(); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 7d63f184..dc7deef6 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -25,10 +25,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -54,12 +57,27 @@ BuySellDialog::BuySellDialog(): void BuySellDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "Buy") { - current_npc->buy(); - } else if (event.getId() == "Sell") { - current_npc->sell(); - } else if (event.getId() == "Cancel") { + setVisible(false); + int action = 0; + + NPC::mTalking = false; + + if (event.getId() == "Buy") + { + action = 0; + } + else if (event.getId() == "Sell") + { + action = 1; + } + else if (event.getId() == "Cancel") + { current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index c12e3c9b..747066a7 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -41,12 +43,15 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index c28f1403..b94e8aa4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -29,10 +29,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")) +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -87,12 +90,19 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) setVisible(false); if (current_npc) - current_npc->nextDialog(); + nextDialog(); - current_npc = NULL; + current_npc = 0; } } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 63d41cd6..a72de5d0 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -29,6 +29,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -44,7 +47,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +74,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -79,7 +84,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: - gcn::Button *okButton; + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9c49a630..132a7608 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); @@ -104,11 +107,14 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->integerInput(mValueField->getValue()); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); - current_npc = NULL; + current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index cca8cb32..15bdee48 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -27,6 +27,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -42,7 +43,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -78,6 +79,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2c4dfc04..73b00239 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,10 +31,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -86,6 +89,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + NPC::mTalking = false; mItemList->setSelected(-1); mItems.clear(); } @@ -112,10 +116,12 @@ void NpcListDialog::action(const gcn::ActionEvent &event) setVisible(false); reset(); - if (current_npc) - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); - current_npc = NULL; + current_npc = 0; } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index de3a7a77..0a0e9813 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -30,6 +30,8 @@ #include "window.h" +class Network; + /** * The npc list dialog. * @@ -44,7 +46,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -79,6 +81,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void requestFocus(); private: + Network *mNetwork; gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; gcn::Button *okButton; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 140ca40f..f2c7434c 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -64,12 +67,19 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->stringInput(mValueField->getText()); - - current_npc = NULL; + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); + + current_npc = 0; } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index c8871184..ee620daf 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * The npc integer input dialog. * @@ -40,7 +42,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -70,6 +72,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::TextField *mValueField; gcn::Button *okButton; gcn::Button *cancelButton; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index c11d22e7..bae14a05 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -196,7 +196,11 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + dstBeing = beingManager->findBeing(id); + + if (id == current_npc) + current_npc = 0; if (!dstBeing) break; @@ -205,12 +209,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc = NULL; - - if (msg->readInt8() == 1) - dstBeing->setAction(Being::DEAD); - else + if (!(msg->readInt8() == 1)) beingManager->destroyBeing(dstBeing); break; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 245b8a50..e9255540 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -66,7 +66,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -89,7 +89,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) case SMSG_NPC_SELL: msg->readInt16(); // length n_items = (msg->getLength() - 4) / 10; - if (n_items > 0) { + if (n_items > 0) + { sellDialog->setMoney(player_node->mGp); sellDialog->reset(); sellDialog->setVisible(true); @@ -101,21 +102,25 @@ void BuySellHandler::handleMessage(MessageIn *msg) msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); - if (item && !(item->isEquipped())) { + + if (item && !(item->isEquipped())) sellDialog->addItem(item, value); - } } } - else { + else + { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); current_npc = 0; } break; case SMSG_NPC_BUY_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) + { chatWindow->chatLog(_("Thanks for buying"), BY_SERVER); - } else { + } + else + { // Reset player money since buy dialog already assumed purchase // would go fine buyDialog->setMoney(player_node->mGp); @@ -124,11 +129,11 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_SELL_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) chatWindow->chatLog(_("Thanks for selling"), BY_SERVER); - } else { + else chatWindow->chatLog(_("Unable to sell"), BY_SERVER); - } + break; } } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index a59ee814..1067a57e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "messagein.h" #include "npchandler.h" #include "protocol.h" @@ -49,15 +51,14 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - int id; + Uint32 id; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); npcListDialog->requestFocus(); @@ -65,17 +66,16 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcTextDialog->setVisible(true); break; case SMSG_NPC_CLOSE: id = msg->readInt32(); - if (current_npc == dynamic_cast(beingManager->findBeing(id))) - current_npc = NULL; + if (current_npc == id) + current_npc = 0; break; case SMSG_NPC_NEXT: @@ -84,8 +84,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); npcIntegerDialog->requestFocus(); @@ -93,8 +93,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index f18c5d82..ffeb3fab 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -92,7 +92,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = NULL; + current_npc = 0; } } deathListener; } diff --git a/src/npc.cpp b/src/npc.cpp index 832e6926..92ef4d82 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -21,6 +21,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -32,8 +33,8 @@ #include "resources/npcdb.h" -NPC *current_npc = 0; bool NPC::mTalking = false; +Uint32 current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -117,68 +118,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) diff --git a/src/npc.h b/src/npc.h index 0dc9c742..e1bf9737 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,6 +23,8 @@ #ifndef NPC_H #define NPC_H +#include + #include "player.h" class Network; @@ -42,14 +44,7 @@ class NPC : public Player virtual Type getType() const; - void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); + void talk();; static bool mTalking; @@ -60,6 +55,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern Uint32 current_npc; #endif -- cgit v1.2.3-70-g09d2 From 0ffbbaa33f633bccf3b2a49713eb1cb117ff8a5a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 08:24:01 -0700 Subject: Fixed an error in shoplistboxes as identified by Octalot. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 2 +- src/gui/buy.h | 2 +- src/gui/listbox.cpp | 3 ++- src/gui/listbox.h | 10 +++++----- src/gui/sell.cpp | 2 +- src/gui/shop.cpp | 3 +-- src/gui/shoplistbox.cpp | 9 --------- src/gui/shoplistbox.h | 2 -- src/shopitem.cpp | 6 ++---- src/shopitem.h | 2 +- 10 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a2485ca1..5a57dcc6 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -118,7 +118,7 @@ void BuyDialog::reset() setMoney(0); } -void BuyDialog::addItem(short id, int price) +void BuyDialog::addItem(int id, int price) { mShopItems->addItem(id, price); mShopItemList->adjustSize(); diff --git a/src/gui/buy.h b/src/gui/buy.h index b05608c0..9029fe9d 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -69,7 +69,7 @@ class BuyDialog : public Window, public gcn::ActionListener, /** * Adds an item to the shop inventory. */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 8ae68e09..45d14884 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -56,7 +56,7 @@ void ListBox::draw(gcn::Graphics *graphics) const int fontHeight = getFont()->getHeight(); - // Draw rectangle below the selected list element + // Draw filled rectangle around the selected list element if (mSelected >= 0) graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, getWidth(), fontHeight)); @@ -97,6 +97,7 @@ void ListBox::setSelected(int selected) mSelected = selected; } } + gcn::ListBox::setSelected(mSelected); } // -- KeyListener notifications diff --git a/src/gui/listbox.h b/src/gui/listbox.h index a6392a94..09f00cdf 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -47,17 +47,17 @@ class ListBox : public gcn::ListBox */ void draw(gcn::Graphics *graphics); - void mouseDragged(gcn::MouseEvent &event); - // Inherited from KeyListener - virtual void keyPressed(gcn::KeyEvent& keyEvent); + void keyPressed(gcn::KeyEvent& keyEvent); // Inherited from MouseListener - virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); - virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + void mouseDragged(gcn::MouseEvent &event); /** * Sets the selected item. The selected item is represented by diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index f974f247..154d1a57 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -121,7 +121,7 @@ void SellDialog::addItem(const Item *item, int price) } mShopItems->addItem(item->getInvIndex(), item->getId(), - item->getQuantity(), price); + item->getQuantity(), price); mShopItemList->adjustSize(); } diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index da68cf28..bd676bc0 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -44,8 +44,7 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int inventoryIndex, int id, int quantity, - int price) +void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price) { ShopItem* item = 0; if (mMergeDuplicates) diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 6d3d9464..6e70e022 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -108,15 +108,6 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) } } -void ShopListBox::mousePressed(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::LEFT) - { - setSelected(event.getY() / mRowHeight); - distributeActionEvent(); - } -} - void ShopListBox::adjustSize() { if (mListModel) diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h index 8542a7b8..bed9902b 100644 --- a/src/gui/shoplistbox.h +++ b/src/gui/shoplistbox.h @@ -57,8 +57,6 @@ class ShopListBox : public ListBox */ unsigned int getRowHeight() const { return mRowHeight; } - void mousePressed(gcn::MouseEvent &event); - /** * gives information about the current player's money */ diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 5573eb37..00875a2d 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -24,8 +24,7 @@ #include "utils/stringutils.h" -ShopItem::ShopItem (int inventoryIndex, int id, - int quantity, int price) : +ShopItem::ShopItem (int inventoryIndex, int id, int quantity, int price) : Item (id, 0), mPrice(price) { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; @@ -50,8 +49,7 @@ ShopItem::~ShopItem() } } -void ShopItem::addDuplicate(int inventoryIndex, - int quantity) +void ShopItem::addDuplicate(int inventoryIndex, int quantity) { DuplicateItem* di = new DuplicateItem; di->inventoryIndex = inventoryIndex; diff --git a/src/shopitem.h b/src/shopitem.h index d6226732..18608a94 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -89,7 +89,7 @@ class ShopItem : public Item */ int getCurrentInvIndex() { return mDuplicates.empty() ? mInvIndex : - mDuplicates.top()->inventoryIndex; + mDuplicates.top()->inventoryIndex; } /** -- cgit v1.2.3-70-g09d2 From 4c0259fc06f9147fa1c7e55db26659d1dade0f45 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 09:24:51 -0700 Subject: Fixed showing being deaths. I removed the wrong pointless death animation (case 1 is NOT death, but actually idle in SMSG_PLAYER_UPDATE_1) Signed-off-by: Ira Rice --- src/net/beinghandler.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index bae14a05..71369031 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -209,7 +209,9 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (!(msg->readInt8() == 1)) + if (msg->readInt8() == 1) + dstBeing->setAction(Being::DEAD); + else beingManager->destroyBeing(dstBeing); break; @@ -443,11 +445,6 @@ void BeingHandler::handleMessage(MessageIn *msg) { switch (msg->readInt8()) { - case 1: - if (dstBeing->getType() != Being::NPC) - dstBeing->setAction(Being::DEAD); - break; - case 2: dstBeing->setAction(Being::SIT); break; -- cgit v1.2.3-70-g09d2 From 5dd5ed1987bdafa8d32edf10317a3f80dd8b2708 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 10:51:37 -0700 Subject: Extended job numbers based on what's actually used for Ragnarok's server. TODO: Make this externally configurable, so that specific servers can specify what they use specific sprite IDs for, as well as specifying good defaults as well, in case that configuration file isn't found. Signed-off-by: Ira Rice --- src/beingmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d63e0dc5..a2d39150 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -69,11 +69,11 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) { Being *being; - if (job < 10) + if (job <= 25 || (job >= 4001 && job <= 4049)) being = new Player(id, job, mMap); - else if (job >= 100 && job < 200) + else if (job >= 46 && job <= 1000) being = new NPC(id, job, mMap, mNetwork); - else if (job >= 1000 && job < 1200) + else if (job > 1000 && job <= 2000) being = new Monster(id, job, mMap); else being = new Being(id, job, mMap); -- cgit v1.2.3-70-g09d2 From 6b0cff837b7adae56dc90d12e9c0e256e6aab134 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 10:55:08 -0700 Subject: Forgot to extend the player or NPC specifying fields as well. Signed-off-by: Ira Rice --- src/beingmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a2d39150..d6d71a91 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -79,7 +79,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) being = new Being(id, job, mMap); // Player or NPC - if (job < 200) + if (job <= 1000 || (job >= 4001 && job <= 4049)) { MessageOut outMsg(mNetwork); outMsg.writeInt16(0x0094); -- cgit v1.2.3-70-g09d2