From 8155f5673970015d21fcd80f078c4df01e06d9c9 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 20:28:22 -0700 Subject: Remove debug statement that should've been removed It was for testing and shouldn't have been committed --- src/npc.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/npc.cpp') diff --git a/src/npc.cpp b/src/npc.cpp index 92db9373..246fb205 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -178,7 +178,6 @@ void NPC::updateCoords() void NPC::handleDeath() { - printf("NPC::handleDeath\n"); if (this != current_npc) return; if (npcTextDialog->isVisible()) -- cgit v1.2.3-60-g2f50 From a41c61706b29b0fadf1271946a76c3b3b51239f0 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(-) (limited to 'src/npc.cpp') diff --git a/src/npc.cpp b/src/npc.cpp index 246fb205..dff1e299 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -112,7 +112,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-60-g2f50 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(-) (limited to 'src/npc.cpp') 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-60-g2f50 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(-) (limited to 'src/npc.cpp') 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-60-g2f50 From e116e2a34ec507ab0f2ab65662a7c4ae8f587341 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 07:01:04 -0700 Subject: Don't delete the current NPC too early --- src/npc.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/npc.cpp b/src/npc.cpp index dff1e299..0d568309 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -75,9 +75,13 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): NPC::~NPC() { - delete mName; + if (current_npc == this) // Don't delete if current NPC + { + handleDeath(); + return; + } - if (current_npc == this) handleDeath(); + delete mName; } void NPC::setName(const std::string &name) @@ -181,5 +185,9 @@ void NPC::handleDeath() if (npcTextDialog->isVisible()) npcTextDialog->showCloseButton(); - else current_npc = NULL; + else { + NPC *temp = current_npc; + current_npc = NULL; + delete temp; + } } -- cgit v1.2.3-60-g2f50 From a996d4bff3cc5a35ee5cdb6cb5bdef920cf44120 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 07:03:38 -0700 Subject: If no network is set, then don't continue Only checks in these two palces for now, as missing network in the others would indicate a design flaw. --- src/npc.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/npc.cpp') diff --git a/src/npc.cpp b/src/npc.cpp index 0d568309..701e280b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -112,6 +112,7 @@ Being::Type NPC::getType() const void NPC::talk() { + if (!mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); @@ -120,6 +121,7 @@ void NPC::talk() void NPC::nextDialog() { + if (!mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(mId); -- cgit v1.2.3-60-g2f50 From 7a65eb17a322cb22e7940504797844114fb77d79 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 07:54:38 -0700 Subject: Fix some problems with deleting NPCs early --- src/beingmanager.cpp | 11 ++++++++++- src/net/npchandler.cpp | 2 +- src/npc.cpp | 12 +++--------- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3c8edf86..3b73d29f 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,7 +96,10 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - delete being; + if (being == current_npc) + current_npc->handleDeath(); + else + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -193,6 +196,12 @@ void BeingManager::clear() mBeings.remove(player_node); } + if (current_npc) + { + mBeings.remove(current_npc); + current_npc->handleDeath(); + } + delete_all(mBeings); mBeings.clear(); diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 5ae2ac2e..ae521bd5 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -94,7 +94,7 @@ void NPCHandler::handleMessage(MessageIn *msg) // If we're talking to that NPC, show the next button if (temporaryNPC == current_npc) npcTextDialog->showNextButton(); - else + else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help temporaryNPC->nextDialog(); break; diff --git a/src/npc.cpp b/src/npc.cpp index 701e280b..658334bc 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -75,12 +75,6 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): NPC::~NPC() { - if (current_npc == this) // Don't delete if current NPC - { - handleDeath(); - return; - } - delete mName; } @@ -112,7 +106,7 @@ Being::Type NPC::getType() const void NPC::talk() { - if (!mNetwork) return; + if (!this || !mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); @@ -121,7 +115,7 @@ void NPC::talk() void NPC::nextDialog() { - if (!mNetwork) return; + if (!this || !mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(mId); @@ -187,7 +181,7 @@ void NPC::handleDeath() if (npcTextDialog->isVisible()) npcTextDialog->showCloseButton(); - else { + else if (current_npc) { NPC *temp = current_npc; current_npc = NULL; delete temp; -- cgit v1.2.3-60-g2f50 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(-) (limited to 'src/npc.cpp') 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-60-g2f50 From 9673149ea3c28f42f38fc9989faf76d68e72bd20 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 11:25:56 -0700 Subject: Don't delete the Being in the NPC class The BeingManager will clean it up when it's next cleared. One hanging Being isn't too much. A reference count system like resources use might be a better way to handle Beings. --- src/npc.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/npc.cpp b/src/npc.cpp index 658334bc..ecac2509 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -181,9 +181,6 @@ void NPC::handleDeath() if (npcTextDialog->isVisible()) npcTextDialog->showCloseButton(); - else if (current_npc) { - NPC *temp = current_npc; + else current_npc = NULL; - delete temp; - } } -- cgit v1.2.3-60-g2f50 From f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:38:55 -0700 Subject: Fix NPC handling to not need a handle on the NPC The Being ID is used instead, as that is all that was ever really needed. --- src/beingmanager.cpp | 21 +++++++------- src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buy.cpp | 2 +- src/gui/buysell.cpp | 22 +++++++++++---- src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 21 ++++++++++---- src/gui/npc_text.h | 8 +++++- src/gui/npcintegerdialog.cpp | 14 +++++++-- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 12 ++++++-- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 16 +++++++++-- src/gui/npcstringdialog.h | 5 +++- src/gui/sell.cpp | 2 +- src/net/beinghandler.cpp | 14 ++++++--- src/net/buysellhandler.cpp | 4 +-- src/net/npchandler.cpp | 27 ++++++++---------- src/net/playerhandler.cpp | 4 +-- src/npc.cpp | 67 ++------------------------------------------ src/npc.h | 15 +--------- 21 files changed, 142 insertions(+), 148 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3b73d29f..273436bf 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,10 +96,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - if (being == current_npc) - current_npc->handleDeath(); - else - delete being; + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -196,12 +193,6 @@ void BeingManager::clear() mBeings.remove(player_node); } - if (current_npc) - { - mBeings.remove(current_npc); - current_npc->handleDeath(); - } - delete_all(mBeings); mBeings.clear(); @@ -264,3 +255,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 11721709..02c83725 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -98,13 +98,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 cb85fc5c..6f9dbb88 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -198,13 +198,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/buy.cpp b/src/gui/buy.cpp index c084c7c2..cad21ab5 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -132,7 +132,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 8bf5f1f4..c1c934d1 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -24,10 +24,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[] = { @@ -60,12 +63,19 @@ void BuySellDialog::logic() void BuySellDialog::action(const gcn::ActionEvent &event) { + setVisible(false); + int action; if (event.getId() == "Buy") { - current_npc->buy(); + action = 0; } else if (event.getId() == "Sell") { - current_npc->sell(); + action = 1; } else if (event.getId() == "Cancel") { - if (current_npc) current_npc->handleDeath(); + 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 754bb551..197c1a2b 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -26,6 +26,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -40,7 +42,7 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Check for current NPC @@ -51,6 +53,9 @@ class BuySellDialog : public Window, public gcn::ActionListener * 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 1750cbd4..db0015e9 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -28,10 +28,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), mState(NPC_TEXT_STATE_WAITING) { setResizable(true); @@ -97,14 +100,14 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok") { if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - current_npc->nextDialog(); + nextDialog(); addText("\n> Next\n"); } else if (mState == NPC_TEXT_STATE_CLOSE || (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); - if (current_npc) current_npc->nextDialog(); + if (current_npc) nextDialog(); setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } else return; } else return; @@ -114,10 +117,16 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) mState = NPC_TEXT_STATE_WAITING; } +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); setText(mText); } - diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 00b11b3c..62486fff 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -28,6 +28,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -43,7 +46,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -74,6 +77,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void showCloseButton(); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -82,6 +87,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index f91b42da..f6d788df 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField; @@ -104,7 +107,12 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); + mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 6083338c..80a21848 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -26,6 +26,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -41,7 +42,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -81,6 +82,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 8349cb4a..fc7d2979 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,13 +31,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -115,7 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index e7e2f9a9..a7b49506 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -29,6 +29,8 @@ #include +class Network; + /** * The npc list dialog. * @@ -43,7 +45,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -75,6 +77,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); private: + Network *mNetwork; gcn::ListBox *mItemList; std::vector mItems; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 679c93e5..7ed05288 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -74,8 +77,15 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + 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); } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 31f9c9a0..43283219 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -26,6 +26,8 @@ #include +class Network; + /** * The npc integer input dialog. * @@ -39,7 +41,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +73,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::TextField *mValueField; std::string mDefault; }; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 14620aa6..51fc8f9f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -133,7 +133,7 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 3e746eb5..982667d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -35,6 +35,10 @@ #include "../npc.h" #include "../player_relations.h" +#include "../gui/npc_text.h" + +extern NpcTextDialog *npcTextDialog; + const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler(bool enableSync): @@ -204,7 +208,12 @@ 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(); + + if (id == current_npc) + npcTextDialog->showCloseButton(); + + dstBeing = beingManager->findBeing(id); if (!dstBeing) break; @@ -213,9 +222,6 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc->handleDeath(); - if (msg->readInt8() == 1) dstBeing->setAction(Being::DEAD); else diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index a2442d70..714bc0ea 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -65,7 +65,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: @@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) } else { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } break; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ae521bd5..405217bb 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -54,24 +54,21 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { int id; - NPC *temporaryNPC; 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); break; 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)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); @@ -79,30 +76,28 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the close button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - temporaryNPC->nextDialog(); + npcTextDialog->nextDialog(id); break; case SMSG_NPC_NEXT: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the next button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showNextButton(); - else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help - temporaryNPC->nextDialog(); + else + npcTextDialog->nextDialog(id); break; 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->setDefaultValue(0); npcIntegerDialog->setVisible(true); @@ -111,8 +106,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 ee1b2fd9..550753b7 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -93,7 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } } deathListener; } @@ -147,8 +147,6 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); - if (current_npc) current_npc->handleDeath(); - float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; diff --git a/src/npc.cpp b/src/npc.cpp index ecac2509..8fd8a86b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -20,6 +20,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -33,7 +34,7 @@ extern NpcTextDialog *npcTextDialog; -NPC *current_npc = NULL; +int current_npc = NULL; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -113,60 +114,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!this || !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() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) @@ -174,13 +121,3 @@ void NPC::updateCoords() mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); } } - -void NPC::handleDeath() -{ - if (this != current_npc) return; - - if (npcTextDialog->isVisible()) - npcTextDialog->showCloseButton(); - else - current_npc = NULL; -} diff --git a/src/npc.h b/src/npc.h index 81b6d51e..ef9fdc7d 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,19 +42,6 @@ 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(); - - /** - * Call this to ease clean up of the current NPC, without causing - * interface problems - */ - void handleDeath(); protected: Network *mNetwork; void updateCoords(); @@ -62,6 +49,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern int current_npc; #endif -- cgit v1.2.3-60-g2f50 From 3ad6ac47d4967870a54fddd66aa9996724115b94 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:50:47 -0700 Subject: Prevent duplicate NPC talking when using keyboard Based on commit a1e483913672e55704e8fbafeff5ea0ccc0c9b07 from Aethyra. --- src/gui/npc_text.cpp | 1 + src/npc.cpp | 7 +++++-- src/npc.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index db0015e9..520efad4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -108,6 +108,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (current_npc) nextDialog(); setVisible(false); current_npc = 0; + NPC::isTalking = false; } else return; } else return; diff --git a/src/npc.cpp b/src/npc.cpp index 8fd8a86b..5132e0dc 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -34,7 +34,8 @@ extern NpcTextDialog *npcTextDialog; -int current_npc = NULL; +int current_npc = 0; +bool NPC::isTalking = false; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -107,7 +108,9 @@ Being::Type NPC::getType() const void NPC::talk() { - if (!this || !mNetwork) return; + if (isTalking || !this || !mNetwork) return; + + isTalking = true; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); diff --git a/src/npc.h b/src/npc.h index ef9fdc7d..182da3e5 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,6 +42,8 @@ class NPC : public Player virtual Type getType() const; void talk(); + + static bool isTalking; protected: Network *mNetwork; void updateCoords(); -- cgit v1.2.3-60-g2f50 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(-) (limited to 'src/npc.cpp') 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-60-g2f50 From c75511fffc77d517fbf854ec8bef791f055de44c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 26 Feb 2009 22:22:22 +0100 Subject: Got rid of Sint{8,16,32} and Uint32 for being ID Using unsigned rarely makes sense, especially when the server doesn't use it either. Other uses of unsigned should be reviewed. In all other cases, int is the fastest integer type on any architecture. Using 8 or 16 bits can basically only be a memory optimization. --- src/being.cpp | 2 +- src/being.h | 12 ++++++------ src/beingmanager.cpp | 16 ++++++++-------- src/beingmanager.h | 14 +++++++------- src/floor_item.cpp | 10 +++++----- src/floor_item.h | 20 ++++++++++---------- src/flooritemmanager.cpp | 9 ++++----- src/flooritemmanager.h | 7 +++---- src/gui/popupmenu.h | 4 +--- src/localplayer.cpp | 2 +- src/localplayer.h | 4 ++-- src/monster.cpp | 2 +- src/monster.h | 2 +- src/net/beinghandler.cpp | 6 +++--- src/net/buysellhandler.cpp | 8 ++++---- src/net/chathandler.cpp | 2 +- src/net/equipmenthandler.cpp | 6 +++--- src/net/inventoryhandler.cpp | 6 +++--- src/net/itemhandler.cpp | 2 +- src/net/npchandler.cpp | 2 +- src/net/playerhandler.cpp | 22 +++++++++++----------- src/net/skillhandler.cpp | 8 ++++---- src/net/tradehandler.cpp | 6 +++--- src/npc.cpp | 2 +- src/npc.h | 2 +- 25 files changed, 86 insertions(+), 90 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/being.cpp b/src/being.cpp index 902bd4e1..45019bf2 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -185,7 +185,7 @@ void Being::setSprite(int slot, int id, std::string color) mSpriteColors[slot] = color; } -void Being::setSpeech(const std::string &text, Uint32 time) +void Being::setSpeech(const std::string &text, int time) { mSpeech = text; diff --git a/src/being.h b/src/being.h index ef830e3a..8b2a1e7e 100644 --- a/src/being.h +++ b/src/being.h @@ -166,7 +166,7 @@ class Being : public Sprite * @param text The text that should appear. * @param time The amount of time the text should stay in milliseconds. */ - void setSpeech(const std::string &text, Uint32 time = 500); + void setSpeech(const std::string &text, int time = 500); /** * Puts a damage bubble above this being. @@ -285,12 +285,12 @@ class Being : public Sprite /** * Gets the sprite id. */ - Uint32 getId() const { return mId; } + int getId() const { return mId; } /** * Sets the sprite id. */ - void setId(Uint32 id) { mId = id; } + void setId(int id) { mId = id; } /** * Sets the map the being is on @@ -477,7 +477,7 @@ class Being : public Sprite */ virtual void handleStatusEffect(StatusEffect *effect, int effectId); - Uint32 mId; /**< Unique sprite id */ + int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ @@ -496,8 +496,8 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - Uint32 mSpeechTime; - Sint32 mPx, mPy; /**< Pixel coordinates */ + int mSpeechTime; + int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 15f683af..83e16f4c 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -67,7 +67,7 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint32 id, Uint16 job) +Being *BeingManager::createBeing(int id, Uint16 job) { Being *being; @@ -99,7 +99,7 @@ void BeingManager::destroyBeing(Being *being) delete being; } -Being* BeingManager::findBeing(Uint32 id) +Being *BeingManager::findBeing(int id) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -111,7 +111,7 @@ Being* BeingManager::findBeing(Uint32 id) return NULL; } -Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) +Being *BeingManager::findBeing(int x, int y, Being::Type type) { beingFinder.x = x; beingFinder.y = y; @@ -122,7 +122,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +Being *BeingManager::findBeingByPixel(int x, int y) { BeingIterator itr = mBeings.begin(); BeingIterator itr_end = mBeings.end(); @@ -148,7 +148,7 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) return NULL; } -Being* BeingManager::findBeingByName(std::string name, Being::Type type) +Being *BeingManager::findBeingByName(std::string name, Being::Type type) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -161,7 +161,7 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type) return NULL; } -Beings& BeingManager::getAll() +Beings &BeingManager::getAll() { return mBeings; } @@ -202,7 +202,7 @@ void BeingManager::clear() } } -Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, +Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, Being::Type type) { Being *closestBeing = NULL; @@ -229,7 +229,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } -Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, +Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type) { Being *closestBeing = NULL; diff --git a/src/beingmanager.h b/src/beingmanager.h index 02c83725..6c0e0fda 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -49,7 +49,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being *createBeing(Uint32 id, Uint16 job); + Being *createBeing(int id, Uint16 job); /** * Remove a Being. @@ -59,13 +59,13 @@ class BeingManager /** * Return a specific id Being. */ - Being* findBeing(Uint32 id); - Being* findBeingByPixel(Uint16 x, Uint16 y); + Being *findBeing(int id); + Being *findBeingByPixel(int x, int y); /** * Returns a being at specific coordinates. */ - Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to specific coordinates. @@ -76,13 +76,13 @@ class BeingManager * no being is returned. * @param type The type of being to look for. */ - Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being *findNearestLivingBeing(int x, int y, int maxdist, Being::Type type = Being::UNKNOWN); /** * Finds a being by name and (optionally) by type. */ - Being* findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); + Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to another being. @@ -90,7 +90,7 @@ class BeingManager * \param maxdist maximal distance. If minimal distance is larger, * no being is returned */ - Being* findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type = Being::UNKNOWN); /** diff --git a/src/floor_item.cpp b/src/floor_item.cpp index fbe606b4..000835ad 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -26,10 +26,10 @@ #include "resources/image.h" -FloorItem::FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, +FloorItem::FloorItem(int id, + int itemId, + int x, + int y, Map *map): mId(id), mX(x), @@ -51,7 +51,7 @@ FloorItem::~FloorItem() delete mItem; } -unsigned int FloorItem::getItemId() const +int FloorItem::getItemId() const { return mItem->getId(); } diff --git a/src/floor_item.h b/src/floor_item.h index 444c756a..7ca0f5a3 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -42,10 +42,10 @@ class FloorItem : public Sprite /** * Constructor. */ - FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, + FloorItem(int id, + int itemId, + int x, + int y, Map *map); /** @@ -56,22 +56,22 @@ class FloorItem : public Sprite /** * Returns instance id of this item. */ - unsigned int getId() const { return mId; } + int getId() const { return mId; } /** * Returns the item id. */ - unsigned int getItemId() const; + int getItemId() const; /** * Returns the x coordinate. */ - unsigned short getX() const { return mX; } + int getX() const { return mX; } /** * Returns the y coordinate. */ - unsigned short getY() const { return mY; } + int getY() const { return mY; } /** * Returns the pixel y coordinate. @@ -88,8 +88,8 @@ class FloorItem : public Sprite void draw(Graphics *graphics, int offsetX, int offsetY) const; private: - unsigned int mId; - unsigned short mX, mY; + int mId; + int mX, mY; Item *mItem; Sprites::iterator mSpriteIterator; Map *mMap; diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index 65556abb..65fb2146 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -29,8 +29,8 @@ FloorItemManager::~FloorItemManager() clear(); } -FloorItem* FloorItemManager::create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map) +FloorItem* FloorItemManager::create(int id, int itemId, + int x, int y, Map *map) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, map); mFloorItems.push_back(floorItem); @@ -49,7 +49,7 @@ void FloorItemManager::clear() mFloorItems.clear(); } -FloorItem* FloorItemManager::findById(unsigned int id) +FloorItem *FloorItemManager::findById(int id) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) @@ -63,8 +63,7 @@ FloorItem* FloorItemManager::findById(unsigned int id) return NULL; } -FloorItem* FloorItemManager::findByCoordinates(unsigned short x, - unsigned short y) +FloorItem *FloorItemManager::findByCoordinates(int x, int y) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h index 3f96b587..704b39fd 100644 --- a/src/flooritemmanager.h +++ b/src/flooritemmanager.h @@ -32,15 +32,14 @@ class FloorItemManager public: ~FloorItemManager(); - FloorItem* create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map); + FloorItem* create(int id, int itemId, int x, int y, Map *map); void destroy(FloorItem *item); void clear(); - FloorItem* findById(unsigned int id); - FloorItem* findByCoordinates(unsigned short x, unsigned short y); + FloorItem* findById(int id); + FloorItem* findByCoordinates(int x, int y); private: typedef std::list FloorItems; diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 2694abd8..0a6877d9 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -22,8 +22,6 @@ #ifndef POPUP_MENU_H #define POPUP_MENU_H -#include // for Uint32 - #include "linkhandler.h" #include "window.h" @@ -68,7 +66,7 @@ class PopupMenu : public Window, public LinkHandler private: BrowserBox* mBrowserBox; - Uint32 mBeingId; + int mBeingId; FloorItem* mFloorItem; Item *mItem; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5b1500ff..18f25257 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -295,7 +295,7 @@ void LocalPlayer::walk(unsigned char dir) return; } - Sint16 dx = 0, dy = 0; + int dx = 0, dy = 0; if (dir & UP) dy--; if (dir & DOWN) diff --git a/src/localplayer.h b/src/localplayer.h index 2226671b..ba6e7670 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -228,8 +228,8 @@ class LocalPlayer : public Player Uint8 mAttr[6]; Uint8 mAttrUp[6]; - Sint16 ATK, MATK, DEF, MDEF, HIT, FLEE; - Sint16 ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; + int ATK, MATK, DEF, MDEF, HIT, FLEE; + int ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; diff --git a/src/monster.cpp b/src/monster.cpp index 610da492..2979e9fd 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -33,7 +33,7 @@ static const int NAME_X_OFFSET = 16; static const int NAME_Y_OFFSET = 16; -Monster::Monster(Uint32 id, Uint16 job, Map *map): +Monster::Monster(int id, Uint16 job, Map *map): Being(id, job, map), mText(0) { diff --git a/src/monster.h b/src/monster.h index 8d7f8ae7..ab6f85df 100644 --- a/src/monster.h +++ b/src/monster.h @@ -30,7 +30,7 @@ class Text; class Monster : public Being { public: - Monster(Uint32 id, Uint16 job, Map *map); + Monster(int id, Uint16 job, Map *map); ~Monster(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b706b088..356d9509 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -69,16 +69,16 @@ BeingHandler::BeingHandler(bool enableSync): void BeingHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; Uint16 job, speed; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves; Uint16 weapon, shield; Uint16 gmstatus; - Sint16 param1; + int param1; int stunMode; Uint32 statusEffects; - Sint8 type; + int type; Uint16 status; Being *srcBeing, *dstBeing; int hairStyle, hairColor, flag; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 65f8498a..520a1fe6 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -77,10 +77,10 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readInt32(); + int value = msg->readInt32(); msg->readInt32(); // DCvalue msg->readInt8(); // type - Sint16 itemId = msg->readInt16(); + int itemId = msg->readInt16(); buyDialog->addItem(itemId, value); } break; @@ -96,8 +96,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readInt16(); - Sint32 value = msg->readInt32(); + int index = msg->readInt16(); + int value = msg->readInt32(); msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index a3ccc4fb..8e108142 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -60,7 +60,7 @@ void ChatHandler::handleMessage(MessageIn *msg) Being *being; std::string chatMsg; std::string nick; - Sint16 chatMsgLength; + int chatMsgLength; switch (msg->getId()) { diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index 9a3c396a..a31da38e 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -48,9 +48,9 @@ EquipmentHandler::EquipmentHandler() void EquipmentHandler::handleMessage(MessageIn *msg) { - Sint32 itemCount; - Sint16 index, equipPoint, itemId; - Sint8 type; + int itemCount; + int index, equipPoint, itemId; + int type; int mask, position; Item *item; Inventory *inventory = player_node->getInventory(); diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index a227701e..d78a7a45 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -61,9 +61,9 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { - Sint32 number; - Sint16 index, amount, itemId, equipType, arrow; - Sint16 identified, cards[4], itemType; + int number; + int index, amount, itemId, equipType, arrow; + int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); Inventory *storage = player_node->getStorage(); diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index 8c4af4e4..b7ac23a8 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -41,7 +41,7 @@ void ItemHandler::handleMessage(MessageIn *msg) { Uint32 id; Uint16 x, y; - Sint16 itemId; + int itemId; switch (msg->getId()) { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 2ecd4726..487b358f 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -50,7 +50,7 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; switch (msg->getId()) { diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 7790cdd0..d99a97a5 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -164,8 +164,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mY = y; logger->log("Adjust scrolling by %d:%d", - (int)scrollOffsetX, - (int)scrollOffsetY); + (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -173,7 +173,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); Uint32 value = msg->readInt32(); switch (type) @@ -301,10 +301,10 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readInt32(); - Sint32 base = msg->readInt32(); - Sint32 bonus = msg->readInt32(); - Sint32 total = base + bonus; + int type = msg->readInt32(); + int base = msg->readInt32(); + int bonus = msg->readInt32(); + int total = base + bonus; switch (type) { case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; @@ -325,9 +325,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readInt16(); - Sint8 fail = msg->readInt8(); - Sint8 value = msg->readInt8(); + int type = msg->readInt16(); + int fail = msg->readInt8(); + int value = msg->readInt8(); if (fail != 1) break; @@ -404,7 +404,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); switch (type) { case 0: diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index e2185524..526698f4 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -51,14 +51,14 @@ void SkillHandler::handleMessage(MessageIn *msg) for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readInt16(); + int skillId = msg->readInt16(); msg->readInt16(); // target type msg->readInt16(); // unknown - Sint16 level = msg->readInt16(); - Sint16 sp = msg->readInt16(); + int level = msg->readInt16(); + int sp = msg->readInt16(); msg->readInt16(); // range std::string skillName = msg->readString(24); - Sint8 up = msg->readInt8(); + int up = msg->readInt8(); if (level != 0 || up != 0) { diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index c5465835..ab2eba31 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -140,8 +140,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readInt32(); - Sint16 type = msg->readInt16(); + int amount = msg->readInt32(); + int type = msg->readInt16(); msg->readInt8(); // identified flag msg->readInt8(); // attribute msg->readInt8(); // refine @@ -166,7 +166,7 @@ void TradeHandler::handleMessage(MessageIn *msg) tradeWindow->receivedOk(true); return; } - Sint16 quantity = msg->readInt16(); + int quantity = msg->readInt16(); switch (msg->readInt8()) { diff --git a/src/npc.cpp b/src/npc.cpp index 7ba25c08..5a4f9507 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -38,7 +38,7 @@ int current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): +NPC::NPC(int id, Uint16 job, Map *map, Network *network): Player(id, job, map), mNetwork(network) { NPCInfo info = NPCDB::get(job); diff --git a/src/npc.h b/src/npc.h index 216fb2fe..63a0b953 100644 --- a/src/npc.h +++ b/src/npc.h @@ -33,7 +33,7 @@ class Text; class NPC : public Player { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(int id, Uint16 job, Map *map, Network *network); ~NPC(); -- cgit v1.2.3-60-g2f50 From 3b1fbbe072e4da86be4c8f8f22655d04565379d2 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 22:42:42 +0100 Subject: Make use of the new available colors This patch lets all being derivatives use the palette to set their name's colors. Text Particle Effects all respect the new settings. Some widgets were updated to use the colors. --- src/being.cpp | 37 ++++++++++++++----------------------- src/being.h | 2 +- src/gui/gui.cpp | 5 ----- src/gui/listbox.cpp | 2 +- src/gui/shoplistbox.cpp | 2 +- src/gui/speechbubble.cpp | 5 +++-- src/gui/speechbubble.h | 4 +++- src/gui/table.cpp | 2 ++ src/gui/textbox.cpp | 5 +++-- src/gui/textbox.h | 15 +++++++++++++++ src/gui/widgets/dropdown.cpp | 16 ++++++---------- src/gui/widgets/textpreview.cpp | 2 ++ src/localplayer.cpp | 19 ++++++++++--------- src/monster.cpp | 7 +++++-- src/npc.cpp | 6 ++++-- src/particle.cpp | 17 +++++------------ src/particle.h | 14 ++++++-------- src/player.cpp | 13 +++++++++---- src/text.cpp | 6 +++--- src/text.h | 6 +++--- src/textparticle.cpp | 11 +++-------- src/textparticle.h | 7 +++---- 22 files changed, 102 insertions(+), 101 deletions(-) (limited to 'src/npc.cpp') diff --git a/src/being.cpp b/src/being.cpp index 60fb8d13..66273710 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -45,6 +45,7 @@ #include "resources/resourcemanager.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/speechbubble.h" #include "utils/dtor.h" @@ -101,7 +102,7 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble; mSpeech = ""; - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::CHAT); mText = 0; } @@ -202,17 +203,14 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font; std::string damage = amount ? toString(amount) : type == FLEE ? "dodge" : "miss"; - - int red, green, blue; + const gcn::Color* color; font = gui->getInfoParticleFont(); // Selecting the right color if (type == CRITICAL || type == FLEE) { - red = 255; - green = 128; - blue = 0; + color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) { @@ -220,33 +218,25 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } else { - red = 255; - green = 255; - blue = 0; - } - } + color = &guiPalette->getColor(Palette::MISS); + } + } else if (getType() == MONSTER) { - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER); } else { - red = 255; - green = 50; - blue = 50; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect(damage, mPx + 16, mPy + 16, + color, font, true); if (amount > 0) { @@ -531,7 +521,8 @@ void Being::drawSpeech(int offsetX, int offsetY) delete mText; mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, gcn::Color(255, 255, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::PARTICLE)); } else if (speech == NO_SPEECH) { diff --git a/src/being.h b/src/being.h index b9b57a0d..ec6f1c44 100644 --- a/src/being.h +++ b/src/being.h @@ -510,7 +510,7 @@ class Being : public Sprite Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ - gcn::Color mNameColor; + const gcn::Color* mNameColor; std::vector mSprites; std::vector mSpriteIDs; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e14642dd..4081eeac 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -46,11 +46,6 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; -/* -// Fonts used in showing hits -gcn::Font *hitRedFont = 0; -gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0;*/ // Bolded font gcn::Font *boldFont = 0; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 23d43066..7ba84ee7 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -56,7 +56,7 @@ void ListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); // Draw the list elements - graphics->setColor(gcn::Color(0, 0, 0, 255)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 19c8a7b4..aa42c294 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -78,7 +78,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color temp; const gcn::Color* backgroundColor = - &guiPalette->getColor(Palette::BACKGROUND, alpha); + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 9ee91166..5f05971d 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -45,6 +45,7 @@ SpeechBubble::SpeechBubble(): mSpeechBox = new TextBox; mSpeechBox->setEditable(false); mSpeechBox->setOpaque(false); + mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); mSpeechArea = new ScrollArea(mSpeechBox); @@ -60,11 +61,11 @@ SpeechBubble::SpeechBubble(): setLocationRelativeTo(getParent()); } -void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) +void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) { mCaption->setCaption(name); mCaption->adjustSize(); - mCaption->setForegroundColor(color); + mCaption->setForegroundColor(*color); } void SpeechBubble::setText(std::string text, bool showName) diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index 573e61f0..34e00722 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -22,6 +22,7 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H +#include "palette.h" #include "window.h" class ScrollArea; @@ -33,7 +34,8 @@ class SpeechBubble : public Window SpeechBubble(); void setCaption(const std::string &name, - const gcn::Color &color = 0x000000); + const gcn::Color *color = + &guiPalette->getColor(Palette::TEXT)); void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); diff --git a/src/gui/table.cpp b/src/gui/table.cpp index ece470b1..5fc96dbd 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -338,6 +338,8 @@ void GuiTable::draw(gcn::Graphics* graphics) { graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, (int)(mAlpha * 127.0f))); + graphics->fillRectangle(gcn::Rectangle(0, y_offset, + x_offset, height)); } y_offset += height; diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index a4024de3..10f727e3 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -23,10 +23,11 @@ #include +#include "palette.h" #include "textbox.h" -TextBox::TextBox(): - gcn::TextBox() +TextBox::TextBox() : + gcn::TextBox(), mTextColor(&guiPalette->getColor(Palette::TEXT)) { setOpaque(false); setFrameSize(0); diff --git a/src/gui/textbox.h b/src/gui/textbox.h index 10a81fc0..5884e11c 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -39,6 +39,11 @@ class TextBox : public gcn::TextBox */ TextBox(); + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + /** * Sets the text after wrapping it to the current width of the widget. */ @@ -49,8 +54,18 @@ class TextBox : public gcn::TextBox */ int getMinWidth() { return mMinWidth; } + /** + * Draws the text. + */ + inline void draw(gcn::Graphics *graphics) + { + setForegroundColor(*mTextColor); + gcn::TextBox::draw(graphics); + } + private: int mMinWidth; + const gcn::Color* mTextColor; }; #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 022da0f0..b736591c 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -139,24 +139,20 @@ void DropDown::draw(gcn::Graphics* graphics) } } -// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); + const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, + alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - gcn::Color col = getBackgroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - col = getForegroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); } graphics->setFont(getFont()); @@ -168,7 +164,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (isFocused()) { - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -180,7 +176,7 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawLine(0, h, getWidth(), h); graphics->setColor(shadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 28d7fd35..4fcaa4a7 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "textpreview.h" #include "../gui.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 296bc28c..30ff9c35 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -38,6 +38,7 @@ #include "gui/gui.h" #include "gui/ministatus.h" +#include "gui/palette.h" #include "gui/storagewindow.h" #include "net/messageout.h" @@ -212,7 +213,9 @@ void LocalPlayer::logic() void LocalPlayer::setGM() { mIsGM = !mIsGM; - mNameColor = mIsGM ? 0x009000: 0x202020; + mNameColor = mIsGM ? + &guiPalette->getColor(Palette::GM) : + &guiPalette->getColor(Palette::PLAYER); setName(getName()); config.setValue(getName() + "GMassert", mIsGM); } @@ -614,10 +617,9 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, - gui->getInfoParticleFont(), - mPx + 16, mPy - 16, - 255, 255, 0, true); + particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::EXP_INFO), + gui->getInfoParticleFont(), true); } mXp = xp; } @@ -627,10 +629,9 @@ void LocalPlayer::pickedUp(std::string item) if (mMap) { // Show pickup notification - particleEngine->addTextRiseFadeOutEffect(item, - gui->getInfoParticleFont (), - mPx + 16, mPy - 16, - 40, 220, 40, true); + particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::PICKUP_INFO), + gui->getInfoParticleFont (), true); } } diff --git a/src/monster.cpp b/src/monster.cpp index 89d0953d..7dc08238 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -27,6 +27,8 @@ #include "sound.h" #include "text.h" +#include "gui/palette.h" + #include "resources/monsterdb.h" #include "resources/monsterinfo.h" @@ -71,7 +73,7 @@ Monster::Monster(int id, Uint16 job, Map *map): } } - mNameColor = 0xff2020; + mNameColor = &guiPalette->getColor(Palette::MONSTER); } Monster::~Monster() @@ -195,7 +197,8 @@ void Monster::showName(bool show) { mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), - gcn::Graphics::CENTER, gcn::Color(255, 64, 64)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::MONSTER)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index 5a4f9507..630316e0 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -26,6 +26,7 @@ #include "text.h" #include "gui/npc_text.h" +#include "gui/palette.h" #include "net/messageout.h" #include "net/protocol.h" @@ -71,7 +72,7 @@ NPC::NPC(int id, Uint16 job, Map *map, Network *network): } mName = 0; - mNameColor = 0x21bbbb; + mNameColor = &guiPalette->getColor(Palette::NPC); } NPC::~NPC() @@ -85,7 +86,8 @@ void NPC::setName(const std::string &name) delete mName; mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::NPC)); Being::setName(displayName + " (NPC)"); } diff --git a/src/particle.cpp b/src/particle.cpp index 6dc45a08..82c163c6 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -324,12 +324,10 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -345,13 +343,8 @@ Particle *Particle::addTextSplashEffect(const std::string &text, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, - int colorR, int colorG, - int colorB, bool outline) -{ - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + Particle *newParticle = new TextParticle(mMap, text, color, 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 b4c80194..3584c4fc 100644 --- a/src/particle.h +++ b/src/particle.h @@ -105,19 +105,17 @@ class Particle : public Sprite /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, int colorR = 255, - int colorG = 255, int colorB = 255, - bool outline = false); + int x, int y, const gcn::Color *color, gcn::Font *font, + bool outline = false); + /** * Adds an emitter to the particle. */ diff --git a/src/player.cpp b/src/player.cpp index e1928280..8668ac58 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -21,10 +21,13 @@ #include "animatedsprite.h" #include "game.h" +#include "localplayer.h" #include "particle.h" #include "player.h" #include "text.h" +#include "gui/palette.h" + #include "resources/colordb.h" #include "resources/itemdb.h" @@ -50,17 +53,19 @@ void Player::setName(const std::string &name) { if (mIsGM) { - mNameColor = 0x009000; + mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(0, 255, 0)); + &guiPalette->getColor(Palette::GM)); } else { - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::PLAYER); mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(255, 255, 255)); + (this == player_node) ? + &guiPalette->getColor(Palette::SELF) : + &guiPalette->getColor(Palette::PC)); } Being::setName(name); } diff --git a/src/text.cpp b/src/text.cpp index 5a912d17..b0be25bf 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -39,7 +39,7 @@ Image *Text::mBubbleArrow; Text::Text(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color, bool isSpeech) : + const gcn::Color* color, bool isSpeech) : mText(text), mColor(color), mIsSpeech(isSpeech) @@ -133,12 +133,12 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, !mIsSpeech, true); + mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color) : + const gcn::Color *color) : Text(text, x, y, alignment, color), mTime(0) { diff --git a/src/text.h b/src/text.h index 6e121da7..a96096cc 100644 --- a/src/text.h +++ b/src/text.h @@ -40,7 +40,7 @@ class Text */ Text(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color, bool isSpeech = false); + const gcn::Color *color, bool isSpeech = false); /** * Destructor. The text is removed from the screen. @@ -65,7 +65,7 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColor; /**< The color of the text. */ + const gcn::Color *mColor; /**< The color of the text. */ bool mIsSpeech; /**< Is this text a speech bubble? */ protected: @@ -78,7 +78,7 @@ class FlashText : public Text public: FlashText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color); + const gcn::Color* color); /** * Remove the text from the screen diff --git a/src/textparticle.cpp b/src/textparticle.cpp index ed8609e9..792b6bea 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -21,21 +21,17 @@ #include -#include - #include "textparticle.h" #include "gui/textrenderer.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), - mColorR(colorR), - mColorG(colorG), - mColorB(colorB), + mColor(color), mOutline(outline) { } @@ -64,6 +60,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, - (int)alpha); + mColor, mTextFont, mOutline, false, (int)alpha); } diff --git a/src/textparticle.h b/src/textparticle.h index d72df138..8b7d3e01 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -32,7 +32,7 @@ class TextParticle : public Particle * Constructor. */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline = false); /** @@ -47,9 +47,8 @@ class TextParticle : public Particle private: 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 */ + const gcn::Color* mColor; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text better readable */ }; #endif -- cgit v1.2.3-60-g2f50