[947] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[947] | 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 | |
---|
[1062] | 32 | #include "CorePrereqs.h" |
---|
| 33 | |
---|
[947] | 34 | #include "Executor.h" |
---|
| 35 | #include "ClassManager.h" |
---|
| 36 | #include "CommandExecutor.h" |
---|
[1390] | 37 | #include "ArgumentCompletionFunctions.h" |
---|
[947] | 38 | |
---|
| 39 | |
---|
[1341] | 40 | #define SetConsoleCommand(classname, function, bCreateShortcut) \ |
---|
| 41 | SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut) |
---|
[947] | 42 | |
---|
[1416] | 43 | #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ |
---|
[1430] | 44 | ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut) |
---|
[947] | 45 | |
---|
| 46 | |
---|
[1341] | 47 | #define SetConsoleCommandShortcut(classname, function) \ |
---|
| 48 | SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function)) |
---|
[947] | 49 | |
---|
[1341] | 50 | #define SetConsoleCommandShortcutExtern(function) \ |
---|
| 51 | SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function)) |
---|
[947] | 52 | |
---|
[1416] | 53 | #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ |
---|
[1430] | 54 | ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command) |
---|
[993] | 55 | |
---|
[947] | 56 | |
---|
[1341] | 57 | namespace orxonox |
---|
| 58 | { |
---|
| 59 | namespace AccessLevel |
---|
| 60 | { |
---|
| 61 | enum Level |
---|
| 62 | { |
---|
| 63 | None, |
---|
| 64 | User, |
---|
| 65 | Admin, |
---|
| 66 | Offline, |
---|
| 67 | Debug, |
---|
| 68 | Disabled |
---|
| 69 | }; |
---|
| 70 | } |
---|
[947] | 71 | |
---|
[1341] | 72 | class _CoreExport ConsoleCommand : public ExecutorStatic |
---|
| 73 | { |
---|
| 74 | public: |
---|
[1390] | 75 | ConsoleCommand(FunctorStatic* functor, const std::string& name = ""); |
---|
[1341] | 76 | |
---|
| 77 | inline ConsoleCommand& setDescription(const std::string& description) |
---|
| 78 | { this->ExecutorStatic::setDescription(description); return (*this); } |
---|
| 79 | inline ConsoleCommand& setDescriptionParam(int param, const std::string& description) |
---|
| 80 | { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); } |
---|
| 81 | inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description) |
---|
| 82 | { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); } |
---|
| 83 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1) |
---|
| 84 | { this->ExecutorStatic::setDefaultValues(param1); return (*this); } |
---|
| 85 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) |
---|
| 86 | { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); } |
---|
| 87 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) |
---|
| 88 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); } |
---|
| 89 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) |
---|
| 90 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); } |
---|
| 91 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) |
---|
| 92 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); } |
---|
| 93 | inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param) |
---|
| 94 | { this->ExecutorStatic::setDefaultValue(index, param); return (*this); } |
---|
| 95 | |
---|
| 96 | inline ConsoleCommand& setAccessLevel(AccessLevel::Level level) |
---|
| 97 | { this->accessLevel_ = level; return (*this); } |
---|
| 98 | inline AccessLevel::Level getAccessLevel() const |
---|
| 99 | { return this->accessLevel_; } |
---|
| 100 | |
---|
[1434] | 101 | ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer); |
---|
| 102 | ArgumentCompleter* getArgumentCompleter(unsigned int param) const; |
---|
| 103 | |
---|
[1430] | 104 | 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 = ""); |
---|
[1441] | 105 | const ArgumentCompletionList& getArgumentCompletionList() const |
---|
[1430] | 106 | { return this->argumentList_; } |
---|
[1441] | 107 | ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const |
---|
[1430] | 108 | { return this->argumentList_.begin(); } |
---|
[1441] | 109 | ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const |
---|
[1430] | 110 | { return this->argumentList_.end(); } |
---|
[1390] | 111 | |
---|
[1341] | 112 | private: |
---|
| 113 | AccessLevel::Level accessLevel_; |
---|
[1430] | 114 | ArgumentCompleter* argumentCompleter_[5]; |
---|
[1441] | 115 | ArgumentCompletionList argumentList_; |
---|
[1341] | 116 | }; |
---|
| 117 | |
---|
| 118 | inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "") |
---|
| 119 | { |
---|
| 120 | return new ConsoleCommand(functor, name); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
[947] | 124 | #endif /* _ConsoleCommand_H__ */ |
---|