summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-08-12 01:53:54 +0300
committerAndrei Karas <akaras@inbox.ru>2011-08-12 01:53:54 +0300
commitfca4273667f15afba055d3c296094f2f41c7ae91 (patch)
treed2a24602a4a60814a5927384570d2873bed83225 /src
parent44e80c70513022b6c378f64d6bf5d25dda7b0e7f (diff)
downloadmanaplus-fca4273667f15afba055d3c296094f2f41c7ae91.tar.gz
manaplus-fca4273667f15afba055d3c296094f2f41c7ae91.tar.bz2
manaplus-fca4273667f15afba055d3c296094f2f41c7ae91.tar.xz
manaplus-fca4273667f15afba055d3c296094f2f41c7ae91.zip
Add ability to add comments to npcs.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp41
-rw-r--r--src/being.h4
-rw-r--r--src/client.cpp13
-rw-r--r--src/client.h3
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/beingpopup.cpp6
-rw-r--r--src/gui/popupmenu.cpp24
-rw-r--r--src/gui/popupmenu.h5
-rw-r--r--src/gui/viewport.cpp3
9 files changed, 84 insertions, 17 deletions
diff --git a/src/being.cpp b/src/being.cpp
index cd616fc67..b6f06a75a 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -263,7 +263,7 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map):
if (mType == PLAYER)
mShowName = config.getBoolValue("visiblenames");
- else
+ else if (mType != NPC)
mGotComment = true;
config.addListener("visiblenames", this);
@@ -2363,13 +2363,26 @@ void Being::updateComment()
return;
mGotComment = true;
- mComment = loadComment(mName);
+ mComment = loadComment(mName, mType);
}
-std::string Being::loadComment(const std::string &name)
+std::string Being::loadComment(const std::string &name, int type)
{
- std::string str = Client::getUsersDirectory()
- + stringToHexPath(name) + "/comment.txt";
+ std::string str;
+ switch (type)
+ {
+ case PLAYER:
+ str = Client::getUsersDirectory();
+ break;
+ case NPC:
+ str = Client::getNpcsDirectory();
+ break;
+ default:
+ return "";
+ }
+
+ str += stringToHexPath(name) + "/comment.txt";
+ logger->log("load from: %s", str.c_str());
std::vector<std::string> lines;
ResourceManager *resman = ResourceManager::getInstance();
@@ -2383,10 +2396,22 @@ std::string Being::loadComment(const std::string &name)
}
void Being::saveComment(const std::string &name,
- const std::string &comment)
+ const std::string &comment, int type)
{
- std::string dir = Client::getUsersDirectory()
- + stringToHexPath(name);
+ std::string dir;
+ switch (type)
+ {
+ case PLAYER:
+ dir = Client::getUsersDirectory();
+ break;
+ case NPC:
+ dir = Client::getNpcsDirectory();
+ break;
+ default:
+ return;
+ }
+ dir += stringToHexPath(name);
+ logger->log("save to: %s", dir.c_str());
ResourceManager *resman = ResourceManager::getInstance();
resman->saveTextFile(dir, "comment.txt", name + "\n" + comment);
}
diff --git a/src/being.h b/src/being.h
index 76c968451..2c37ffeb5 100644
--- a/src/being.h
+++ b/src/being.h
@@ -741,10 +741,10 @@ class Being : public ActorSprite, public ConfigListener
static void clearCache();
- static std::string loadComment(const std::string &name);
+ static std::string loadComment(const std::string &name, int type);
static void saveComment(const std::string &name,
- const std::string &comment);
+ const std::string &comment, int type);
bool isAdvanced()
{ return mAdvanced; }
diff --git a/src/client.cpp b/src/client.cpp
index 092f81a93..022bc07d5 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -240,6 +240,7 @@ Client::Client(const Options &options):
mOptions(options),
mServerConfigDir(""),
mUsersDir(""),
+ mNpcsDir(""),
mRootDir(""),
mCurrentDialog(0),
mQuitDialog(0),
@@ -1917,6 +1918,13 @@ void Client::initUsersDir()
logger->error(strprintf(_("%s doesn't exist and can't be created! "
"Exiting."), mUsersDir.c_str()));
}
+
+ mNpcsDir = Client::getServerConfigDirectory() + "/npcs/";
+ if (mkdir_r(mNpcsDir.c_str()))
+ {
+ logger->error(strprintf(_("%s doesn't exist and can't be created! "
+ "Exiting."), mNpcsDir.c_str()));
+ }
}
void Client::initPacketLimiter()
@@ -2137,6 +2145,11 @@ const std::string Client::getUsersDirectory()
return instance()->mUsersDir;
}
+const std::string Client::getNpcsDirectory()
+{
+ return instance()->mNpcsDir;
+}
+
void Client::setGuiAlpha(float n)
{
instance()->mGuiAlpha = n;
diff --git a/src/client.h b/src/client.h
index 75b3c03fe..986e06cfb 100644
--- a/src/client.h
+++ b/src/client.h
@@ -226,6 +226,8 @@ public:
static const std::string getUsersDirectory();
+ static const std::string getNpcsDirectory();
+
static bool getIsMinimized()
{ return instance()->mIsMinimized; }
@@ -303,6 +305,7 @@ private:
std::string mScreenshotDir;
std::string mServerConfigDir;
std::string mUsersDir;
+ std::string mNpcsDir;
std::string mRootDir;
std::string mServerName;
diff --git a/src/game.cpp b/src/game.cpp
index 40b6896b7..05fb88048 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -556,7 +556,7 @@ void Game::adjustPerfomance()
{
mNextAdjustTime = cur_time + adjustDelay;
}
- else if (mNextAdjustTime < cur_time)
+ else if (mNextAdjustTime < (unsigned)cur_time)
{
mNextAdjustTime = cur_time + adjustDelay;
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp
index e5dc602a0..8d7b26c1b 100644
--- a/src/gui/beingpopup.cpp
+++ b/src/gui/beingpopup.cpp
@@ -89,6 +89,12 @@ void BeingPopup::show(int x, int y, Being *b)
b->updateComment();
+ if (b->getType() == Being::NPC && b->getComment().empty())
+ {
+ setVisible(false);
+ return;
+ }
+
mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace());
if (gui)
{
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 9cf9e536e..14a326e41 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -22,6 +22,7 @@
#include "gui/popupmenu.h"
+#include "actorsprite.h"
#include "actorspritemanager.h"
#include "being.h"
#include "dropshortcut.h"
@@ -94,7 +95,8 @@ PopupMenu::PopupMenu():
mSpell(0),
mDialog(0),
mButton(0),
- mNick("")
+ mNick(""),
+ mType(Being::UNKNOWN)
{
mBrowserBox = new BrowserBox;
mBrowserBox->setPosition(4, 4);
@@ -105,6 +107,7 @@ PopupMenu::PopupMenu():
mRenameListener.setDialog(0);
mPlayerListener.setNick("");
mPlayerListener.setDialog(0);
+ mPlayerListener.setType(Being::UNKNOWN);
add(mBrowserBox);
}
@@ -116,6 +119,7 @@ void PopupMenu::showPopup(int x, int y, Being *being)
mBeingId = being->getId();
mNick = being->getName();
+ mType = being->getType();
mBrowserBox->clearRows();
const std::string &name = mNick;
@@ -278,6 +282,8 @@ void PopupMenu::showPopup(int x, int y, Being *being)
mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell")));
mBrowserBox->addRow("##3---");
mBrowserBox->addRow(strprintf("@@move|%s@@", _("Move")));
+ mBrowserBox->addRow(strprintf("@@addcomment|%s@@",
+ _("Add comment")));
break;
case ActorSprite::MONSTER:
@@ -359,6 +365,7 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick)
mNick = nick;
mBeingId = 0;
+ mType = Being::PLAYER;
mBrowserBox->clearRows();
const std::string &name = mNick;
@@ -599,6 +606,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab)
{
mBeingId = being->getId();
mNick = being->getName();
+ mType = being->getType();
mBrowserBox->addRow(strprintf("@@trade|%s@@", _("Trade")));
mBrowserBox->addRow(strprintf("@@attack|%s@@", _("Attack")));
@@ -728,6 +736,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab)
else
{
mNick = name;
+ mType = Being::PLAYER;
mBrowserBox->addRow(strprintf(
"@@addcomment|%s@@", _("Add comment")));
mBrowserBox->addRow("##3---");
@@ -768,6 +777,7 @@ void PopupMenu::showChangePos(int x, int y)
mItem = 0;
mMapItem = 0;
mNick = "";
+ mType = Being::UNKNOWN;
setVisible(false);
}
}
@@ -1220,6 +1230,7 @@ void PopupMenu::handleLink(const std::string &link,
_("Comment: "));
mPlayerListener.setDialog(dialog);
mPlayerListener.setNick(mNick);
+ mPlayerListener.setType(mType);
if (being)
{
@@ -1228,7 +1239,7 @@ void PopupMenu::handleLink(const std::string &link,
}
else
{
- dialog->setText(Being::loadComment(mNick));
+ dialog->setText(Being::loadComment(mNick, mType));
}
dialog->setActionEventId("ok");
dialog->addActionListener(&mPlayerListener);
@@ -1560,6 +1571,7 @@ void PopupMenu::handleLink(const std::string &link,
mItemColor = 1;
mMapItem = 0;
mNick = "";
+ mType = Being::UNKNOWN;
}
void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
@@ -1870,6 +1882,7 @@ void PopupMenu::showAttackMonsterPopup(int x, int y, std::string name,
return;
mNick = name;
+ mType = Being::MONSTER;
mBrowserBox->clearRows();
@@ -2001,7 +2014,8 @@ void RenameListener::action(const gcn::ActionEvent &event)
PlayerListener::PlayerListener() :
mNick(""),
- mDialog(0)
+ mDialog(0),
+ mType(Being::UNKNOWN)
{
}
@@ -2011,10 +2025,10 @@ void PlayerListener::action(const gcn::ActionEvent &event)
{
std::string comment = mDialog->getText();
Being* being = actorSpriteManager->findBeingByName(
- mNick, Being::PLAYER);
+ mNick, (ActorSprite::Type)mType);
if (being)
being->setComment(comment);
- Being::saveComment(mNick, comment);
+ Being::saveComment(mNick, comment, mType);
}
mDialog = 0;
}
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index afa4bdfa2..3a7f27d4b 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -78,9 +78,13 @@ class PlayerListener : public gcn::ActionListener
void setDialog(TextDialog *dialog)
{ mDialog = dialog; }
+ void setType(int type)
+ { mType = type; }
+
private:
std::string mNick;
TextDialog *mDialog;
+ int mType;
};
/**
@@ -171,6 +175,7 @@ class PopupMenu : public Popup, public LinkHandler
TextDialog *mDialog;
Button *mButton;
std::string mNick;
+ int mType;
/**
* Shared code for the various showPopup functions.
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index ba8414699..2ca59f524 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -684,7 +684,8 @@ void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED)
const int y = getMouseY() + static_cast<int>(mPixelViewY);
mHoverBeing = actorSpriteManager->findBeingByPixel(x, y, true);
- if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER)
+ if (mHoverBeing && (mHoverBeing->getType() == Being::PLAYER
+ || mHoverBeing->getType() == Being::NPC))
{
mTextPopup->setVisible(false);
if (mShowBeingPopup)