summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp44
-rw-r--r--src/gui/npc_text.cpp7
-rw-r--r--src/gui/npc_text.h2
-rw-r--r--src/gui/npcintegerdialog.h2
-rw-r--r--src/gui/npclistdialog.h2
-rw-r--r--src/gui/npcstringdialog.h2
-rw-r--r--src/gui/textbox.cpp32
-rw-r--r--src/gui/viewport.cpp29
-rw-r--r--src/net/npchandler.cpp7
-rw-r--r--src/net/playerhandler.cpp9
-rw-r--r--src/npc.cpp12
-rw-r--r--src/npc.h2
12 files changed, 89 insertions, 61 deletions
diff --git a/src/game.cpp b/src/game.cpp
index e4b6e54d..e5f7b22b 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -145,9 +145,9 @@ namespace {
{
void action(const gcn::ActionEvent &event)
{
- if (event.getId() == "yes" || event.getId() == "ok") {
+ if (event.getId() == "yes" || event.getId() == "ok")
done = true;
- }
+
exitConfirm = NULL;
disconnectedDialog = NULL;
}
@@ -178,13 +178,9 @@ Uint32 nextSecond(Uint32 interval, void *param)
int get_elapsed_time(int start_time)
{
if (start_time <= tick_time)
- {
return (tick_time - start_time) * 10;
- }
else
- {
return (tick_time + (MAX_TIME - start_time)) * 10;
- }
}
/**
@@ -213,8 +209,10 @@ void createGuiWindows(Network *network)
tradeWindow = new TradeWindow(network);
helpWindow = new HelpWindow();
debugWindow = new DebugWindow();
- itemShortcutWindow = new ShortcutWindow("ItemShortcut",new ItemShortcutContainer);
- emoteShortcutWindow = new ShortcutWindow("emoteShortcut",new EmoteShortcutContainer);
+ itemShortcutWindow = new ShortcutWindow("ItemShortcut",
+ new ItemShortcutContainer);
+ emoteShortcutWindow = new ShortcutWindow("emoteShortcut",
+ new EmoteShortcutContainer);
// Set initial window visibility
chatWindow->setVisible((bool) config.getValue(
@@ -465,7 +463,9 @@ void Game::logic()
if (!disconnectedDialog)
{
disconnectedDialog = new OkDialog(_("Network Error"),
- _("The connection to the server was lost, the program will now quit"));
+ _("The connection to the "
+ "server was lost, the "
+ "program will now quit"));
disconnectedDialog->addActionListener(&exitListener);
disconnectedDialog->requestMoveToTop();
}
@@ -853,9 +853,11 @@ void Game::handleInput()
}
// Attack priorioty is: Monster, Player, auto target
- target = beingManager->findBeing(targetX, targetY, Being::MONSTER);
+ target = beingManager->findBeing(targetX, targetY,
+ Being::MONSTER);
if (!target)
- target = beingManager->findBeing(targetX, targetY, Being::PLAYER);
+ target = beingManager->findBeing(targetX, targetY,
+ Being::PLAYER);
}
player_node->attack(target, newTarget);
@@ -863,30 +865,31 @@ void Game::handleInput()
// Target the nearest player if 'q' is pressed
if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) &&
- !keyboard.isKeyActive(keyboard.KEY_TARGET) )
+ !keyboard.isKeyActive(keyboard.KEY_TARGET) )
{
- Being *target = beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER);
+ Being *target = beingManager->findNearestLivingBeing(player_node,
+ 20, Being::PLAYER);
player_node->setTarget(target);
}
// Target the nearest monster if 'a' pressed
if ((keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) ||
- (joystick && joystick->buttonPressed(3))) &&
- !keyboard.isKeyActive(keyboard.KEY_TARGET))
+ (joystick && joystick->buttonPressed(3))) &&
+ !keyboard.isKeyActive(keyboard.KEY_TARGET))
{
Being *target = beingManager->findNearestLivingBeing(
- x, y, 20, Being::MONSTER);
+ x, y, 20, Being::MONSTER);
player_node->setTarget(target);
}
// Target the nearest npc if 'n' pressed
if ( keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) &&
- !keyboard.isKeyActive(keyboard.KEY_TARGET) )
+ !keyboard.isKeyActive(keyboard.KEY_TARGET) )
{
Being *target = beingManager->findNearestLivingBeing(
- x, y, 20, Being::NPC);
+ x, y, 20, Being::NPC);
player_node->setTarget(target);
}
@@ -894,14 +897,15 @@ void Game::handleInput()
// Talk to the nearest NPC if 't' pressed
if ( keyboard.isKeyActive(keyboard.KEY_TALK) )
{
- if (!npcTextDialog->isVisible() && !npcListDialog->isVisible())
+ if (!npcTextDialog->isVisible() && !npcListDialog->isVisible() &&
+ !npcStringDialog->isVisible() && !npcIntegerDialog->isVisible())
{
Being *target = player_node->getTarget();
if (!target)
{
target = beingManager->findNearestLivingBeing(
- x, y, 20, Being::NPC);
+ x, y, 20, Being::NPC);
}
if (target)
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index ed75b76e..0b7592c7 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -73,11 +73,16 @@ void NpcTextDialog::addText(const std::string &text)
setText(mText + text + "\n");
}
+void NpcTextDialog::clearText()
+{
+ setText("");
+}
+
void NpcTextDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
- setText("");
+ clearText();
setVisible(false);
if (current_npc)
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 5e2ff118..63d41cd6 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -87,4 +87,6 @@ class NpcTextDialog : public Window, public gcn::ActionListener
std::string mText;
};
+extern NpcTextDialog *npcTextDialog;
+
#endif // NPC_TEXT_H
diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h
index 858bce5b..a4ca33cf 100644
--- a/src/gui/npcintegerdialog.h
+++ b/src/gui/npcintegerdialog.h
@@ -81,4 +81,6 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener
gcn::Button *resetButton;
};
+extern NpcIntegerDialog *npcIntegerDialog;
+
#endif // GUI_NPCINTEGERDIALOG_H
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index 8d8b6545..a30bec28 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -82,4 +82,6 @@ class NpcListDialog : public Window, public gcn::ActionListener,
std::vector<std::string> 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<NPC*>(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();