From a1e54a22abd85e1913a25ef63c947210c2dd8ddc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Dec 2014 18:13:32 +0300 Subject: Add chat command for add item name to chat. New chat command: /addchat ID Alias: /chatadd ID --- src/actions/commands.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/actions/commands.h | 1 + src/input/inputaction.h | 1 + src/input/inputactionmap.h | 9 +++++++++ 4 files changed, 54 insertions(+) (limited to 'src') diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 6708567cf..151e54474 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -22,10 +22,14 @@ #include "actormanager.h" #include "configuration.h" +#include "flooritem.h" +#include "inventory.h" +#include "item.h" #include "actions/actiondef.h" #include "being/localplayer.h" +#include "being/playerinfo.h" #include "being/playerrelations.h" #include "gui/chatconsts.h" @@ -43,6 +47,8 @@ #include "net/pethandler.h" #include "net/serverfeatures.h" +#include "resources/iteminfo.h" + #include "utils/chatutils.h" #include "utils/gettext.h" #include "utils/process.h" @@ -245,6 +251,43 @@ impHandler(chatNuke) return true; } +impHandler(chatAdd) +{ + if (!chatWindow) + return false; + + if (event.args.empty()) + return true; + + const int id = atoi(event.args.c_str()); + if (!id) + return true; + + Inventory *const inv = PlayerInfo::getInventory(); + const Item *item = nullptr; + if (inv) + { + // +++ need add also color here + item = inv->findItem(id, 1); + } + + if (item) + { + // +++ need add also color here + chatWindow->addItemText(item->getInfo().getName()); + return true; + } + + const FloorItem *const floorItem = actorManager->findItem(id); + + if (floorItem) + { + // +++ need add also color here + chatWindow->addItemText(floorItem->getInfo().getName()); + } + return true; +} + impHandler0(present) { if (chatWindow) diff --git a/src/actions/commands.h b/src/actions/commands.h index 160737572..34dcf0c44 100644 --- a/src/actions/commands.h +++ b/src/actions/commands.h @@ -37,6 +37,7 @@ namespace Actions decHandler(chatEnemy); decHandler(chatErase); decHandler(chatNuke); + decHandler(chatAdd); decHandler(present); decHandler(printAll); decHandler(move); diff --git a/src/input/inputaction.h b/src/input/inputaction.h index c020b3b5b..28bb44fd8 100644 --- a/src/input/inputaction.h +++ b/src/input/inputaction.h @@ -496,6 +496,7 @@ namespace InputAction GUILD, NUKE, USE, + CHAT_ADD, TOTAL }; } // namespace InputAction diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index f51f5f6f5..b25dfe848 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -4207,6 +4207,15 @@ static const InputActionData inputActionData[InputAction::TOTAL] = { InputCondition::INGAME, "use|useitem", true}, + {"keyChatAdd", + InputType::UNKNOWN, InputAction::NO_VALUE, + InputType::UNKNOWN, InputAction::NO_VALUE, + Input::GRP_DEFAULT, + &Actions::chatAdd, + InputAction::NO_VALUE, 50, + InputCondition::INGAME, + "addchat|chatadd", + true}, }; #endif // INPUT_INPUTACTIONMAP_H -- cgit v1.2.3-60-g2f50