From 7cf5cb58865bc5f3951a6f4e40cf892ede96fc5a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 5 Jan 2012 18:35:21 +0300 Subject: Update copyrights year. --- src/gui/viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index b6c55f2c4..aedfbe219 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * -- cgit v1.2.3-70-g09d2 From eaa6f58f960f2ef5826de4fd2ea6ff0e383fac8b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 19 Jan 2012 01:04:45 +0300 Subject: Allow pickup item with mouse under player. --- src/gui/viewport.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index aedfbe219..1407415fd 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -481,6 +481,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (mHoverBeing->canTalk()) { mHoverBeing->talkTo(); + return; } else { @@ -490,6 +491,9 @@ void Viewport::mousePressed(gcn::MouseEvent &event) { if (player_node != mHoverBeing || mSelfMouseHeal) actorSpriteManager->heal(mHoverBeing); + if (player_node == mHoverBeing && mHoverItem) + player_node->pickUp(mHoverItem); + return; } } else if (player_node->withinAttackRange(mHoverBeing) || @@ -499,17 +503,21 @@ void Viewport::mousePressed(gcn::MouseEvent &event) { player_node->attack(mHoverBeing, !keyboard.isKeyActive(keyboard.KEY_TARGET)); + return; } } else if (!keyboard.isKeyActive(keyboard.KEY_ATTACK)) { if (player_node != mHoverBeing) + { player_node->setGotoTarget(mHoverBeing); + return; + } } } - // Picks up a item if we clicked on one } - else if (mHoverItem) + // Picks up a item if we clicked on one + if (mHoverItem) { player_node->pickUp(mHoverItem); } @@ -739,7 +747,7 @@ void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED) } mHoverItem = nullptr; - if (!mHoverBeing && actorSpriteManager) + if (actorSpriteManager) { mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(), y / mMap->getTileHeight()); -- cgit v1.2.3-70-g09d2 From bac1df3b9ac0e3327e8de812793d0a18cfd64cba Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 23 Jan 2012 20:41:50 +0300 Subject: Add moving camera commands from npc. --- src/gui/viewport.cpp | 41 +++++++++++++++++++++++++++++++++++ src/gui/viewport.h | 8 +++++++ src/net/tmwa/network.cpp | 2 +- src/net/tmwa/npchandler.cpp | 52 +++++++++++++++++++++++++++++++++++++++------ src/net/tmwa/npchandler.h | 2 +- 5 files changed, 97 insertions(+), 8 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1407415fd..f4c6c315f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -875,3 +875,44 @@ bool Viewport::isPopupMenuVisible() { return mPopupMenu ? mPopupMenu->isVisible() : false; } + +void Viewport::moveCameraToActor(int actorId, int x, int y) +{ + if (!player_node) + return; + + Actor *actor = actorSpriteManager->findBeing(actorId); + if (!actor) + return; + Vector actorPos = actor->getPosition(); + Vector playerPos = player_node->getPosition(); + mCameraMode = 1; + mCameraRelativeX = actorPos.x - playerPos.x + x; + mCameraRelativeY = actorPos.y - playerPos.y + y; +} + +void Viewport::moveCameraToPosition(int x, int y) +{ + if (!player_node) + return; + + Vector playerPos = player_node->getPosition(); + mCameraMode = 1; + + mCameraRelativeX = x - playerPos.x; + mCameraRelativeY = y - playerPos.y; +} + +void Viewport::moveCameraRelative(int x, int y) +{ + mCameraMode = 1; + mCameraRelativeX += x; + mCameraRelativeY += y; +} + +void Viewport::returnCamera() +{ + mCameraMode = 0; + mCameraRelativeX = 0; + mCameraRelativeY = 0; +} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index b25f51242..0f56e9426 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -250,6 +250,14 @@ class Viewport : public WindowContainer, public gcn::MouseListener, bool isPopupMenuVisible(); + void moveCameraToActor(int actorId, int x = 0, int y = 0); + + void moveCameraToPosition(int x, int y); + + void moveCameraRelative(int x, int y); + + void returnCamera(); + protected: friend class ActorSpriteManager; diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 08ba1db10..31329eafb 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -83,7 +83,7 @@ short packet_lengths[] = -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, // #0x0200 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, - 2, -1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, -1, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 5e305070e..c395eb1b8 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -25,6 +25,7 @@ #include "localplayer.h" #include "gui/npcdialog.h" +#include "gui/viewport.h" #include "net/messagein.h" #include "net/net.h" @@ -97,7 +98,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_NPC_COMMAND: - processNpcCommand(msg); + processNpcCommand(msg, npcId); break; default: @@ -239,13 +240,52 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) return npcId; } -void NpcHandler::processNpcCommand(Net::MessageIn &msg) +void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId) { const int cmd = msg.readInt16(); - if (cmd == 0) - mRequestLang = true; - else - logger->log("unknown npc command: %d", cmd); + switch (cmd) + { + case 0: + mRequestLang = true; + break; + + case 1: + if (viewport) + viewport->moveCameraToActor(npcId); + break; + + case 2: + if (viewport) + { + const int id = msg.readInt32(); + const int x = msg.readInt16(); + const int y = msg.readInt16(); + if (!id) + viewport->moveCameraToPosition(x, y); + else + viewport->moveCameraToActor(id, x, y); + } + break; + + case 3: + if (viewport) + viewport->returnCamera(); + break; + + case 4: + if (viewport) + { + msg.readInt32(); // id + const int x = msg.readInt16(); + const int y = msg.readInt16(); + viewport->moveCameraRelative(x, y); + } + break; + + default: + logger->log("unknown npc command: %d", cmd); + break; + } } void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, int npcId) diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 648b1e5d9..1cfcacb20 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -66,7 +66,7 @@ class NpcHandler : public MessageHandler, public Ea::NpcHandler int getNpc(Net::MessageIn &msg, bool haveLength); - void processNpcCommand(Net::MessageIn &msg); + void processNpcCommand(Net::MessageIn &msg, int npcId); void processLangReuqest(Net::MessageIn &msg, int npcId); -- cgit v1.2.3-70-g09d2