From 0a4ee3a9df73daf0350080b9e147f7b4bd535429 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 19 Aug 2016 22:59:49 +0300 Subject: Add chat command for show/change share experience in party. --- src/actions/commands.cpp | 66 ++++++++++++++++++++++++++++++++++ src/actions/commands.h | 1 + src/dyetool/actions/commands.cpp | 1 + src/enums/input/inputaction.h | 1 + src/gui/widgets/tabs/chat/partytab.cpp | 53 +++------------------------ src/input/inputactionmap.h | 6 ++++ 6 files changed, 79 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 7ec1d8bf8..e01e9e904 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -1756,4 +1756,70 @@ impHandler(partyItemShare) return true; } +impHandler(partyExpShare) +{ + if (!localPlayer) + return false; + + if (localPlayer->isInParty() == false) + return true; + + ChatTab *tab = event.tab; + if (tab == nullptr) + tab = localChatTab; + if (tab == nullptr) + return true; + + const std::string args = event.args; + if (args.empty()) + { + switch (partyHandler->getShareExperience()) + { + case PartyShare::YES: + // TRANSLATORS: chat message + tab->chatLog(_("Experience sharing enabled."), + ChatMsgType::BY_SERVER); + return true; + case PartyShare::NO: + // TRANSLATORS: chat message + tab->chatLog(_("Experience sharing disabled."), + ChatMsgType::BY_SERVER); + return true; + case PartyShare::NOT_POSSIBLE: + // TRANSLATORS: chat message + tab->chatLog(_("Experience sharing not possible."), + ChatMsgType::BY_SERVER); + return true; + case PartyShare::UNKNOWN: + // TRANSLATORS: chat message + tab->chatLog(_("Experience sharing unknown."), + ChatMsgType::BY_SERVER); + return true; + default: + break; + } + } + + const signed char opt = parseBoolean(args); + + switch (opt) + { + case 1: + partyHandler->setShareExperience( + PartyShare::YES); + break; + case 0: + partyHandler->setShareExperience( + PartyShare::NO); + break; + case -1: + tab->chatLog(strprintf(BOOLEAN_OPTIONS, "exp"), + ChatMsgType::BY_SERVER); + break; + default: + break; + } + return true; +} + } // namespace Actions diff --git a/src/actions/commands.h b/src/actions/commands.h index e0892f384..72d5f5c5b 100644 --- a/src/actions/commands.h +++ b/src/actions/commands.h @@ -150,6 +150,7 @@ namespace Actions decHandler(setSkillOffsetX); decHandler(setSkillOffsetY); decHandler(partyItemShare); + decHandler(partyExpShare); } // namespace Actions #undef decHandler diff --git a/src/dyetool/actions/commands.cpp b/src/dyetool/actions/commands.cpp index 210704fcd..2b9ef0ad3 100644 --- a/src/dyetool/actions/commands.cpp +++ b/src/dyetool/actions/commands.cpp @@ -150,5 +150,6 @@ impHandlerVoid(showSkillOffsetY) impHandlerVoid(setSkillOffsetX) impHandlerVoid(setSkillOffsetY) impHandlerVoid(partyItemShare) +impHandlerVoid(partyExpShare) } // namespace Actions diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h index d76c6f1bc..31bd6d436 100644 --- a/src/enums/input/inputaction.h +++ b/src/enums/input/inputaction.h @@ -682,6 +682,7 @@ enumStart(InputAction) LEAVE_GUILD, GUILD_NOTICE, PARTY_ITEM_SHARE, + PARTY_EXP_SHARE, TOTAL } enumEnd(InputAction); diff --git a/src/gui/widgets/tabs/chat/partytab.cpp b/src/gui/widgets/tabs/chat/partytab.cpp index 530b0eca8..6a52dc634 100644 --- a/src/gui/widgets/tabs/chat/partytab.cpp +++ b/src/gui/widgets/tabs/chat/partytab.cpp @@ -37,7 +37,7 @@ #include "net/partyhandler.h" #include "net/serverfeatures.h" -#include "utils/booleanoptions.h" +#include "utils/gettext.h" #include "debug.h" @@ -90,54 +90,9 @@ bool PartyTab::handleCommand(const std::string &restrict type, } else if (type == "exp") { - if (args.empty()) - { - switch (partyHandler->getShareExperience()) - { - case PartyShare::YES: - // TRANSLATORS: chat message - chatLog(_("Experience sharing enabled."), - ChatMsgType::BY_SERVER); - return true; - case PartyShare::NO: - // TRANSLATORS: chat message - chatLog(_("Experience sharing disabled."), - ChatMsgType::BY_SERVER); - return true; - case PartyShare::NOT_POSSIBLE: - // TRANSLATORS: chat message - chatLog(_("Experience sharing not possible."), - ChatMsgType::BY_SERVER); - return true; - case PartyShare::UNKNOWN: - // TRANSLATORS: chat message - chatLog(_("Experience sharing unknown."), - ChatMsgType::BY_SERVER); - return true; - default: - break; - } - } - - const signed char opt = parseBoolean(args); - - switch (opt) - { - case 1: - partyHandler->setShareExperience( - PartyShare::YES); - break; - case 0: - partyHandler->setShareExperience( - PartyShare::NO); - break; - case -1: - chatLog(strprintf(BOOLEAN_OPTIONS, "exp"), - ChatMsgType::BY_SERVER); - break; - default: - break; - } + inputManager.executeChatCommand(InputAction::PARTY_EXP_SHARE, + args, + this); } else if (type == "setleader" && serverFeatures->haveChangePartyLeader()) diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 99ff49779..332138ed5 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -5582,6 +5582,12 @@ static const InputActionData inputActionData "itemshare|shareitem", UseArgs_true, Protected_true}, + {"keyPartyExpShare", + defaultAction(&Actions::partyExpShare), + InputCondition::INGAME, + "expshare|shareexp", + UseArgs_true, + Protected_true}, }; #undef defaultAction -- cgit v1.2.3-70-g09d2