[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _ConsoleCommand_H__ |
---|
| 30 | #define _ConsoleCommand_H__ |
---|
| 31 | |
---|
| 32 | #include "CorePrereqs.h" |
---|
| 33 | |
---|
[3304] | 34 | #include <boost/preprocessor/cat.hpp> |
---|
| 35 | |
---|
[3196] | 36 | #include "ArgumentCompletionFunctions.h" |
---|
| 37 | #include "CommandExecutor.h" |
---|
[1505] | 38 | #include "Executor.h" |
---|
[1549] | 39 | #include "Identifier.h" |
---|
[1505] | 40 | |
---|
| 41 | |
---|
[1747] | 42 | #define SetConsoleCommand(classname, function, bCreateShortcut) \ |
---|
[3304] | 43 | SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut) |
---|
[1747] | 44 | #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \ |
---|
[3304] | 45 | SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) |
---|
[1505] | 46 | |
---|
[3304] | 47 | #define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \ |
---|
| 48 | orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut) |
---|
[1505] | 49 | |
---|
| 50 | |
---|
| 51 | #define SetConsoleCommandShortcut(classname, function) \ |
---|
[3304] | 52 | SetConsoleCommandShortcutAliasGeneric(classname, function, #function) |
---|
[1747] | 53 | #define SetConsoleCommandShortcutAlias(classname, function, name) \ |
---|
[3304] | 54 | SetConsoleCommandShortcutAliasGeneric(classname, function, name) |
---|
| 55 | #define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \ |
---|
| 56 | SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name)) |
---|
[1505] | 57 | |
---|
| 58 | #define SetConsoleCommandShortcutExtern(function) \ |
---|
[3304] | 59 | SetConsoleCommandShortcutExternAliasGeneric(function, #function) |
---|
[1747] | 60 | #define SetConsoleCommandShortcutExternAlias(function, name) \ |
---|
[3304] | 61 | SetConsoleCommandShortcutExternAliasGeneric(function, name) |
---|
| 62 | #define SetConsoleCommandShortcutExternAliasGeneric(function, name) \ |
---|
| 63 | SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name)) |
---|
[1505] | 64 | |
---|
| 65 | #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ |
---|
[2662] | 66 | orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true) |
---|
[1505] | 67 | |
---|
| 68 | |
---|
| 69 | namespace orxonox |
---|
| 70 | { |
---|
| 71 | namespace AccessLevel |
---|
| 72 | { |
---|
[3280] | 73 | enum Value |
---|
[1505] | 74 | { |
---|
| 75 | None, |
---|
| 76 | User, |
---|
| 77 | Admin, |
---|
| 78 | Offline, |
---|
| 79 | Debug, |
---|
| 80 | Disabled |
---|
| 81 | }; |
---|
| 82 | } |
---|
| 83 | |
---|
[1755] | 84 | class _CoreExport ConsoleCommand : public Executor |
---|
[1505] | 85 | { |
---|
| 86 | public: |
---|
[1755] | 87 | ConsoleCommand(Functor* functor, const std::string& name = ""); |
---|
[1505] | 88 | |
---|
[1747] | 89 | inline ConsoleCommand& description(const std::string& description) |
---|
[1755] | 90 | { this->Executor::setDescription(description); return (*this); } |
---|
[1747] | 91 | inline ConsoleCommand& descriptionParam(int param, const std::string& description) |
---|
[1755] | 92 | { this->Executor::setDescriptionParam(param, description); return (*this); } |
---|
[1747] | 93 | inline ConsoleCommand& descriptionReturnvalue(const std::string& description) |
---|
[1755] | 94 | { this->Executor::setDescriptionReturnvalue(description); return (*this); } |
---|
[1747] | 95 | inline ConsoleCommand& defaultValues(const MultiType& param1) |
---|
[1755] | 96 | { this->Executor::setDefaultValues(param1); return (*this); } |
---|
[1747] | 97 | inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2) |
---|
[1755] | 98 | { this->Executor::setDefaultValues(param1, param2); return (*this); } |
---|
[1747] | 99 | inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3) |
---|
[1755] | 100 | { this->Executor::setDefaultValues(param1, param2, param3); return (*this); } |
---|
[1747] | 101 | inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) |
---|
[1755] | 102 | { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); } |
---|
[1747] | 103 | inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) |
---|
[1755] | 104 | { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); } |
---|
[1747] | 105 | inline ConsoleCommand& defaultValue(unsigned int index, const MultiType& param) |
---|
[1755] | 106 | { this->Executor::setDefaultValue(index, param); return (*this); } |
---|
[1505] | 107 | |
---|
[3280] | 108 | inline ConsoleCommand& accessLevel(AccessLevel::Value level) |
---|
[1505] | 109 | { this->accessLevel_ = level; return (*this); } |
---|
[3280] | 110 | inline AccessLevel::Value getAccessLevel() const |
---|
[1505] | 111 | { return this->accessLevel_; } |
---|
| 112 | |
---|
[1747] | 113 | ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer); |
---|
[1505] | 114 | ArgumentCompleter* getArgumentCompleter(unsigned int param) const; |
---|
| 115 | |
---|
| 116 | void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = ""); |
---|
| 117 | const ArgumentCompletionList& getArgumentCompletionList() const |
---|
| 118 | { return this->argumentList_; } |
---|
| 119 | ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const |
---|
| 120 | { return this->argumentList_.begin(); } |
---|
| 121 | ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const |
---|
| 122 | { return this->argumentList_.end(); } |
---|
| 123 | |
---|
[2087] | 124 | inline ConsoleCommand& setAsInputCommand() |
---|
| 125 | { |
---|
| 126 | this->keybindMode(KeybindMode::OnHold); |
---|
| 127 | this->defaultValue(0, Vector2(0.0f, 0.0f)); |
---|
| 128 | this->inputConfiguredParam(0); |
---|
| 129 | return *this; |
---|
| 130 | } |
---|
| 131 | |
---|
[3280] | 132 | inline ConsoleCommand& keybindMode(KeybindMode::Value mode) |
---|
[1505] | 133 | { this->keybindMode_ = mode; return *this; } |
---|
[3280] | 134 | inline KeybindMode::Value getKeybindMode() const |
---|
[1505] | 135 | { return this->keybindMode_; } |
---|
| 136 | |
---|
[2087] | 137 | inline ConsoleCommand& inputConfiguredParam(int index) |
---|
| 138 | { this->inputConfiguredParam_ = index; return *this; } |
---|
| 139 | inline int getInputConfiguredParam_() const |
---|
| 140 | { return this->inputConfiguredParam_; } |
---|
[1505] | 141 | |
---|
| 142 | private: |
---|
[3280] | 143 | AccessLevel::Value accessLevel_; |
---|
[1505] | 144 | ArgumentCompleter* argumentCompleter_[5]; |
---|
| 145 | ArgumentCompletionList argumentList_; |
---|
| 146 | |
---|
[3280] | 147 | KeybindMode::Value keybindMode_; |
---|
[2087] | 148 | int inputConfiguredParam_; |
---|
[1505] | 149 | }; |
---|
| 150 | |
---|
[1755] | 151 | inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "") |
---|
[1505] | 152 | { |
---|
| 153 | return new ConsoleCommand(functor, name); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | #endif /* _ConsoleCommand_H__ */ |
---|