summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-11 11:40:12 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-11 15:02:25 +0300
commit5001fa194c820422dd5de2dd655c17bde131e1cb (patch)
tree0f8b0ad59277055c0f94591f64a1367bba558cca /src/gui
parent51a4bf586930fee4df788bef5b6cc350e10cc005 (diff)
downloadmanaplus-5001fa194c820422dd5de2dd655c17bde131e1cb.tar.gz
manaplus-5001fa194c820422dd5de2dd655c17bde131e1cb.tar.bz2
manaplus-5001fa194c820422dd5de2dd655c17bde131e1cb.tar.xz
manaplus-5001fa194c820422dd5de2dd655c17bde131e1cb.zip
add support for giving item to npc (evol only)
chancge network version to 9.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npcdialog.cpp219
-rw-r--r--src/gui/npcdialog.h14
-rw-r--r--src/gui/widgets/itemcontainer.cpp22
3 files changed, 209 insertions, 46 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index dd2243310..3d8da6d58 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -26,10 +26,13 @@
#include "being.h"
#include "configuration.h"
#include "client.h"
+#include "inventory.h"
+#include "item.h"
#include "soundconsts.h"
#include "soundmanager.h"
#include "gui/gui.h"
+#include "gui/inventorywindow.h"
#include "gui/sdlfont.h"
#include "gui/setup.h"
#include "gui/viewport.h"
@@ -37,6 +40,7 @@
#include "gui/widgets/browserbox.h"
#include "gui/widgets/chattab.h"
#include "gui/widgets/inttextfield.h"
+#include "gui/widgets/itemcontainer.h"
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/extendedlistbox.h"
@@ -102,7 +106,13 @@ NpcDialog::NpcDialog(const int npcId) :
// TRANSLATORS: npc dialog button
mButton2(new Button(this, _("Close"), "close", this)),
// TRANSLATORS: npc dialog button
+ mButton3(new Button(this, _("Add"), "add", this)),
+ // TRANSLATORS: npc dialog button
mResetButton(new Button(this, _("Reset"), "reset", this)),
+ mInventory(new Inventory(Inventory::NPC, 1)),
+ mItemContainer(new ItemContainer(this, mInventory)),
+ mItemScrollArea(new ScrollArea(mItemContainer,
+ getOptionBool("showitemsbackground"), "npc_listbackground.xml")),
mInputState(NPC_INPUT_NONE),
mActionState(NPC_ACTION_WAIT),
mLastNextTime(0),
@@ -152,6 +162,7 @@ NpcDialog::NpcDialog(const int npcId) :
setContentSize(260, 175);
mListScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mItemScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mItemList->setVisible(true);
mTextField->setVisible(true);
mIntField->setVisible(true);
@@ -204,6 +215,8 @@ NpcDialog::~NpcDialog()
mButton = nullptr;
delete mButton2;
mButton2 = nullptr;
+ delete mButton3;
+ mButton3 = nullptr;
// These might not actually be in the layout, so lets be safe
delete mScrollArea;
@@ -223,6 +236,13 @@ NpcDialog::~NpcDialog()
delete mItemLinkHandler;
mItemLinkHandler = nullptr;
+ delete mItemContainer;
+ mItemContainer = nullptr;
+ delete mInventory;
+ mInventory = nullptr;
+ delete mItemScrollArea;
+ mItemScrollArea = nullptr;
+
delete mListScrollArea;
mListScrollArea = nullptr;
@@ -287,38 +307,68 @@ void NpcDialog::action(const gcn::ActionEvent &event)
std::string printText; // Text that will get printed
// in the textbox
- if (mInputState == NPC_INPUT_LIST)
+ switch(mInputState)
{
- if (gui)
- gui->resetClickCount();
- const int selectedIndex = mItemList->getSelected();
-
- if (selectedIndex >= static_cast<int>(mItems.size())
- || selectedIndex < 0
- || !Client::limitPackets(PACKET_NPC_INPUT))
+ case NPC_INPUT_LIST:
+ {
+ if (gui)
+ gui->resetClickCount();
+ const int selectedIndex = mItemList->getSelected();
+
+ if (selectedIndex >= static_cast<int>(mItems.size())
+ || selectedIndex < 0
+ || !Client::limitPackets(PACKET_NPC_INPUT))
+ {
+ return;
+ }
+ unsigned char choice = static_cast<unsigned char>(
+ selectedIndex + 1);
+ printText = mItems[selectedIndex];
+
+ Net::getNpcHandler()->listInput(mNpcId, choice);
+ break;
+ }
+ case NPC_INPUT_STRING:
+ {
+ if (!Client::limitPackets(PACKET_NPC_INPUT))
+ return;
+ printText = mTextField->getText();
+ Net::getNpcHandler()->stringInput(mNpcId, printText);
+ }
+ case NPC_INPUT_INTEGER:
{
- return;
+ if (!Client::limitPackets(PACKET_NPC_INPUT))
+ return;
+ printText = strprintf("%d", mIntField->getValue());
+ Net::getNpcHandler()->integerInput(
+ mNpcId, mIntField->getValue());
+ }
+ case NPC_INPUT_ITEM:
+ {
+ if (!Client::limitPackets(PACKET_NPC_INPUT))
+ return;
+
+ const Item *const item = mInventory->getItem(0);
+ std::string str;
+ int color = 1;
+ if (item)
+ {
+ str = strprintf("%d,%d", item->getId(),
+ item->getColor());
+ }
+ else
+ {
+ str = "0,0";
+ }
+
+ // need send selected item
+ Net::getNpcHandler()->stringInput(mNpcId, str);
+ mInventory->clear();
+ break;
}
- unsigned char choice = static_cast<unsigned char>(
- selectedIndex + 1);
- printText = mItems[selectedIndex];
- Net::getNpcHandler()->listInput(mNpcId, choice);
- }
- else if (mInputState == NPC_INPUT_STRING)
- {
- if (!Client::limitPackets(PACKET_NPC_INPUT))
- return;
- printText = mTextField->getText();
- Net::getNpcHandler()->stringInput(mNpcId, printText);
- }
- else if (mInputState == NPC_INPUT_INTEGER)
- {
- if (!Client::limitPackets(PACKET_NPC_INPUT))
- return;
- printText = strprintf("%d", mIntField->getValue());
- Net::getNpcHandler()->integerInput(
- mNpcId, mIntField->getValue());
+ default:
+ break;
}
// addText will auto remove the input layout
addText(strprintf("> \"%s\"", printText.c_str()), false);
@@ -330,10 +380,20 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
else if (eventId == "reset")
{
- if (mInputState == NPC_INPUT_STRING)
- mTextField->setText(mDefaultString);
- else if (mInputState == NPC_INPUT_INTEGER)
- mIntField->setValue(mDefaultInt);
+ switch (mInputState)
+ {
+ case NPC_INPUT_STRING:
+ mTextField->setText(mDefaultString);
+ break;
+ case NPC_INPUT_INTEGER:
+ mIntField->setValue(mDefaultInt);
+ break;
+ case NPC_INPUT_ITEM:
+ mInventory->clear();
+ break;
+ default:
+ break;
+ }
}
else if (eventId == "inc")
{
@@ -345,16 +405,45 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
else if (eventId == "clear")
{
- clearRows();
+ switch (mInputState)
+ {
+ case NPC_INPUT_ITEM:
+ mInventory->clear();
+ break;
+ case NPC_INPUT_STRING:
+ case NPC_INPUT_INTEGER:
+ default:
+ clearRows();
+ break;
+ }
}
else if (eventId == "close")
{
if (mActionState == NPC_ACTION_INPUT)
{
- Net::getNpcHandler()->listInput(mNpcId, 255);
+ switch (mInputState)
+ {
+ case NPC_INPUT_ITEM:
+ Net::getNpcHandler()->stringInput(mNpcId, "0,0");
+ break;
+ case NPC_INPUT_STRING:
+ case NPC_INPUT_INTEGER:
+ default:
+ Net::getNpcHandler()->listInput(mNpcId, 255);
+ break;
+ }
closeDialog();
}
}
+ else if (eventId == "add")
+ {
+ if (inventoryWindow)
+ {
+ const Item *const item = inventoryWindow->getSelectedItem();
+ if (item)
+ mInventory->addItem(item->getId(), 1, 1, item->getColor());
+ }
+ }
}
void NpcDialog::nextDialog()
@@ -450,6 +539,7 @@ void NpcDialog::textRequest(const std::string &defaultText)
mInputState = NPC_INPUT_STRING;
mDefaultString = defaultText;
mTextField->setText(defaultText);
+
buildLayout();
}
@@ -486,6 +576,14 @@ void NpcDialog::integerRequest(const int defaultValue, const int min,
buildLayout();
}
+void NpcDialog::itemRequest()
+{
+ mActionState = NPC_ACTION_INPUT;
+ mInputState = NPC_INPUT_ITEM;
+
+ buildLayout();
+}
+
void NpcDialog::move(const int amount)
{
if (mActionState != NPC_ACTION_INPUT)
@@ -501,6 +599,7 @@ void NpcDialog::move(const int amount)
break;
case NPC_INPUT_NONE:
case NPC_INPUT_STRING:
+ case NPC_INPUT_ITEM:
default:
break;
}
@@ -627,6 +726,27 @@ void NpcDialog::placeIntInputControls()
}
}
+void NpcDialog::placeItemInputControls()
+{
+ if (mShowAvatar)
+ {
+ place(0, 0, mPlayerBox);
+ place(1, 0, mScrollArea, 6, 3);
+ place(0, 3, mItemScrollArea, 7, 3);
+ place(1, 6, mButton3, 2);
+ place(3, 6, mClearButton, 2);
+ place(5, 6, mButton, 2);
+ }
+ else
+ {
+ place(0, 0, mScrollArea, 6, 3);
+ place(0, 3, mItemScrollArea, 6, 3);
+ place(0, 6, mButton3, 2);
+ place(2, 6, mClearButton, 2);
+ place(4, 6, mButton, 2);
+ }
+}
+
void NpcDialog::buildLayout()
{
clearLayout();
@@ -644,18 +764,27 @@ void NpcDialog::buildLayout()
else if (mInputState != NPC_INPUT_NONE)
{
mButton->setCaption(CAPTION_SUBMIT);
- if (mInputState == NPC_INPUT_LIST)
- {
- placeMenuControls();
- mItemList->setSelected(-1);
- }
- else if (mInputState == NPC_INPUT_STRING)
+ switch (mInputState)
{
- placeTextInputControls();
- }
- else if (mInputState == NPC_INPUT_INTEGER)
- {
- placeIntInputControls();
+ case NPC_INPUT_LIST:
+ placeMenuControls();
+ mItemList->setSelected(-1);
+ break;
+
+ case NPC_INPUT_STRING:
+ placeTextInputControls();
+ break;
+
+ case NPC_INPUT_INTEGER:
+ placeIntInputControls();
+ break;
+
+ case NPC_INPUT_ITEM:
+ placeItemInputControls();
+ break;
+
+ default:
+ break;
}
}
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index 815bc7564..9e4de0907 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -40,7 +40,9 @@ class Button;
class BrowserBox;
class ExtendedListBox;
class ItemLinkHandler;
+class Inventory;
class IntTextField;
+class ItemContainer;
class NpcDialog;
class PlayerBox;
class ScrollArea;
@@ -161,6 +163,8 @@ class NpcDialog final : public Window,
void integerRequest(const int defaultValue = 0, const int min = 0,
const int max = 2147483647);
+ void itemRequest();
+
void move(const int amount);
void setVisible(bool visible) override;
@@ -227,6 +231,8 @@ class NpcDialog final : public Window,
void placeIntInputControls();
+ void placeItemInputControls();
+
int mNpcId;
int mDefaultInt;
@@ -255,16 +261,22 @@ class NpcDialog final : public Window,
// Used for the button
Button *mButton;
Button *mButton2;
+ Button *mButton3;
// Will reset the text and integer input to the provided default
Button *mResetButton;
+ Inventory *mInventory;
+ ItemContainer *mItemContainer;
+ ScrollArea *mItemScrollArea;
+
enum NpcInputState
{
NPC_INPUT_NONE = 0,
NPC_INPUT_LIST,
NPC_INPUT_STRING,
- NPC_INPUT_INTEGER
+ NPC_INPUT_INTEGER,
+ NPC_INPUT_ITEM
};
enum NpcActionState
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index e815b1541..f3fb21336 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -413,6 +413,8 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
case Inventory::TRADE:
src = DRAGDROP_SOURCE_TRADE;
break;
+ case Inventory::NPC:
+ src = DRAGDROP_SOURCE_NPC;
default:
break;
}
@@ -505,6 +507,9 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
case Inventory::TRADE:
dst = DRAGDROP_SOURCE_TRADE;
break;
+ case Inventory::NPC:
+ dst = DRAGDROP_SOURCE_NPC;
+ break;
default:
break;
}
@@ -530,6 +535,23 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
{
inventory = PlayerInfo::getInventory();
}
+ else if (src == DRAGDROP_SOURCE_INVENTORY
+ && dst == DRAGDROP_SOURCE_NPC)
+ {
+ inventory = PlayerInfo::getInventory();
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item)
+ mInventory->addItem(item->getId(), 1, 1, item->getColor());
+ return;
+ }
+ else if (src == DRAGDROP_SOURCE_NPC)
+ {
+ inventory = PlayerInfo::getInventory();
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item)
+ mInventory->removeItemAt(dragDrop.getTag());
+ return;
+ }
if (inventory)
{