[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 | |
---|
[7401] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @ingroup Command ConsoleCommand |
---|
[10624] | 32 | @brief Declaration of the orxonox::ConsoleCommand class. |
---|
[7401] | 33 | */ |
---|
| 34 | |
---|
[1505] | 35 | #ifndef _ConsoleCommand_H__ |
---|
| 36 | #define _ConsoleCommand_H__ |
---|
| 37 | |
---|
[7203] | 38 | #include "core/CorePrereqs.h" |
---|
[1505] | 39 | |
---|
[7185] | 40 | #include <stack> |
---|
[7272] | 41 | #include <vector> |
---|
[3304] | 42 | |
---|
[3196] | 43 | #include "ArgumentCompletionFunctions.h" |
---|
[1505] | 44 | #include "Executor.h" |
---|
| 45 | |
---|
[7179] | 46 | namespace orxonox |
---|
| 47 | { |
---|
[7401] | 48 | /** |
---|
| 49 | @brief A small collection of functions that can be used in DeclareConsoleCommand() if |
---|
| 50 | you don't want to use the real function-pointer. |
---|
| 51 | */ |
---|
[7218] | 52 | namespace prototype |
---|
| 53 | { |
---|
| 54 | inline void void__void(void) {} |
---|
| 55 | inline void void__string(const std::string&) {} |
---|
[8079] | 56 | |
---|
| 57 | inline std::string string__bool(bool) { return ""; } |
---|
| 58 | inline std::string string__string(const std::string&) { return ""; } |
---|
| 59 | inline std::string string__uint_uint_bool(unsigned int, unsigned int, bool) { return ""; } |
---|
[7218] | 60 | } |
---|
| 61 | |
---|
[11071] | 62 | /** |
---|
| 63 | @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level. |
---|
| 64 | */ |
---|
| 65 | enum class AccessLevel |
---|
[7218] | 66 | { |
---|
[11071] | 67 | All, |
---|
| 68 | Standalone, |
---|
| 69 | Master, |
---|
| 70 | Server, |
---|
| 71 | Client, |
---|
| 72 | Online, |
---|
| 73 | Offline, |
---|
| 74 | None |
---|
| 75 | }; |
---|
[7218] | 76 | |
---|
[7401] | 77 | /** |
---|
| 78 | @brief The ConsoleCommand class stores all information about a console command which can be executed by CommandExecutor. |
---|
| 79 | |
---|
| 80 | Console commands can be entered by the user into the shell, called in scripts, or |
---|
| 81 | used for key-bindings. They are simple text strings that can be executed by |
---|
| 82 | CommandExecutor. CommandExecutor will search for a ConsoleCommand with the given |
---|
| 83 | group and name and will execute it's Executor (which again calls the Functor and |
---|
| 84 | this finally calls the command-function). |
---|
| 85 | |
---|
| 86 | @see See @ref ConsoleCommandExample "ConsoleCommand.h" for more information and some examples. |
---|
| 87 | */ |
---|
[7236] | 88 | class _CoreExport ConsoleCommand |
---|
[7179] | 89 | { |
---|
[7236] | 90 | friend struct ConsoleCommandManipulator; |
---|
[7179] | 91 | |
---|
[7401] | 92 | /** |
---|
| 93 | @brief Helper class that is used to put the current state of the ConsoleCommand on a stack. |
---|
| 94 | */ |
---|
[7214] | 95 | struct Command |
---|
| 96 | { |
---|
[7401] | 97 | ExecutorPtr executor_; ///< The executor |
---|
| 98 | FunctorPtr functor_; ///< The function that is used with the executor - has to be stored separatley because the executor is often used with different functors |
---|
| 99 | std::vector<void*> objectStack_; ///< The object stack |
---|
[7214] | 100 | }; |
---|
| 101 | |
---|
[7179] | 102 | public: |
---|
[7401] | 103 | /** |
---|
[10624] | 104 | * @brief Defines the name of a command, consisting of an optional group ("" means no group) and the name itself. |
---|
| 105 | */ |
---|
| 106 | struct CommandName |
---|
| 107 | { |
---|
| 108 | CommandName(const std::string& group, const std::string& name) : group_(group), name_(name) {} |
---|
| 109 | std::string group_; |
---|
| 110 | std::string name_; |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | /** |
---|
[7401] | 114 | @brief Helper class that is used to manipulate console commands. |
---|
| 115 | |
---|
| 116 | An instance of this class is returned if you call the ModifyConsoleCommand macro. |
---|
| 117 | This class provides an interface which wraps some functions of ConsoleCommand. It |
---|
| 118 | allows access to some private functions like setFunction() (that can't be called |
---|
| 119 | right after SetConsoleCommand()) but it also hides some functions that shouln't be |
---|
| 120 | called after the static declaration like addShortcut() or description(). |
---|
| 121 | |
---|
| 122 | @see See @ref ConsoleCommandExample "ConsoleCommand.h" for more information and examples. |
---|
| 123 | */ |
---|
[7236] | 124 | struct ConsoleCommandManipulator |
---|
[7179] | 125 | { |
---|
| 126 | public: |
---|
[7401] | 127 | /// Constructor: Creates a manipulator for a given ConsoleCommand. |
---|
[9348] | 128 | ConsoleCommandManipulator(ConsoleCommand* command) : command_(command) {} |
---|
[7179] | 129 | |
---|
[7401] | 130 | /// Changes the current function of the command. @param function The new function-pointer @param bForce If true, the new function-pointer is always assigned, even if the headers don't match |
---|
[7179] | 131 | template <class F> |
---|
[7236] | 132 | inline ConsoleCommandManipulator& setFunction(F function, bool bForce = false) |
---|
[7214] | 133 | { |
---|
| 134 | if (this->command_) |
---|
| 135 | { |
---|
[7401] | 136 | // check if the headers match. If they do, only change the function-pointer of the current Functor instead of creating a new Functor |
---|
[7215] | 137 | if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F)) |
---|
[7214] | 138 | { |
---|
[7215] | 139 | FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getExecutor()->getFunctor().get()); |
---|
[7214] | 140 | functor->setFunction(function); |
---|
| 141 | return *this; |
---|
| 142 | } |
---|
| 143 | this->command_->setFunction(createFunctor(function), bForce); |
---|
| 144 | } |
---|
| 145 | return *this; |
---|
| 146 | } |
---|
[7401] | 147 | /// Changes the current function of the command. @param function The new function-pointer @param object The new object-pointer (for member-functions) @param bForce If true, the new function-pointer is always assigned, even if the headers don't match |
---|
[7179] | 148 | template <class F, class O> |
---|
[7236] | 149 | inline ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false) |
---|
[7214] | 150 | { |
---|
| 151 | if (this->command_) |
---|
| 152 | { |
---|
[7401] | 153 | // check if the headers match. If they do, only change the function-pointer of the current Functor instead of creating a new Functor |
---|
[7215] | 154 | if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F)) |
---|
[7214] | 155 | { |
---|
[7215] | 156 | FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getExecutor()->getFunctor().get()); |
---|
[7214] | 157 | functor->setFunction(function); |
---|
| 158 | functor->setObject(object); |
---|
| 159 | return *this; |
---|
| 160 | } |
---|
| 161 | this->command_->setFunction(createFunctor(function, object), bForce); |
---|
| 162 | } |
---|
| 163 | return *this; |
---|
| 164 | } |
---|
[7401] | 165 | /// Changes the current Functor of the command. @param functor The new Functor @param bForce If true, the new Functor is always assigned, even if the headers don't match |
---|
[7236] | 166 | inline ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false) |
---|
[7214] | 167 | { if (this->command_) { this->command_->setFunction(functor, bForce); } return *this; } |
---|
[7401] | 168 | /// Changes the current Executor of the command. @param executor The new Executor @param bForce If true, the new Executor is always assigned, even if the headers don't match |
---|
[7236] | 169 | inline ConsoleCommandManipulator& setFunction(const ExecutorPtr& executor, bool bForce = false) |
---|
[7214] | 170 | { if (this->command_) { this->command_->setFunction(executor, bForce); } return *this; } |
---|
[7179] | 171 | |
---|
[7401] | 172 | /// Pushes a copy of the current Executor on the command-stack, that can be altered without changing the old Executor. @details This function is especially useful if you don't wan't to change the function, but only the default values of the executor. |
---|
[7270] | 173 | inline ConsoleCommandManipulator& pushFunction() |
---|
| 174 | { if (this->command_) { this->command_->pushFunction(); } return *this; } |
---|
[7401] | 175 | /// Pushes a new function on the command-stack. @param function The new function-pointer @param bForce If true, the new function-pointer is always assigned, even if the headers don't match |
---|
[7179] | 176 | template <class F> |
---|
[7236] | 177 | inline ConsoleCommandManipulator& pushFunction(F function, bool bForce = false) |
---|
[7214] | 178 | { if (this->command_) { this->command_->pushFunction(createFunctor(function), bForce); } return *this; } |
---|
[7401] | 179 | /// Pushes a new function on the command-stack. @param function The new function-pointer @param object The new object-pointer (for member-functions) @param bForce If true, the new function-pointer is always assigned, even if the headers don't match |
---|
[7179] | 180 | template <class F, class O> |
---|
[7236] | 181 | inline ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false) |
---|
[7214] | 182 | { if (this->command_) { this->command_->pushFunction(createFunctor(function, object), bForce); } return *this; } |
---|
[7401] | 183 | /// Pushes a new Functor on the command-stack. @param functor The new Functor @param bForce If true, the new Functor is always assigned, even if the headers don't match |
---|
[7236] | 184 | inline ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false) |
---|
[7214] | 185 | { if (this->command_) { this->command_->pushFunction(functor, bForce); } return *this; } |
---|
[7401] | 186 | /// Pushes a new Executor on the command-stack. @param executor The new Executor @param bForce If true, the new Executor is always assigned, even if the headers don't match |
---|
[7236] | 187 | inline ConsoleCommandManipulator& pushFunction(const ExecutorPtr& executor, bool bForce = false) |
---|
[7214] | 188 | { if (this->command_) { this->command_->pushFunction(executor, bForce); } return *this; } |
---|
[7179] | 189 | |
---|
[7401] | 190 | /// Removes the current function from the stack and restores the old state. If there's no other function on the stack, the command is deactivated. |
---|
[7236] | 191 | inline ConsoleCommandManipulator& popFunction() |
---|
[7214] | 192 | { if (this->command_) { this->command_->popFunction(); } return *this; } |
---|
[7179] | 193 | |
---|
[11071] | 194 | /// Sets the current function-pointer to nullptr, which also deactivates the command. |
---|
[7236] | 195 | inline ConsoleCommandManipulator& resetFunction() |
---|
[7218] | 196 | { if (this->command_) { this->command_->resetFunction(); } return *this; } |
---|
| 197 | |
---|
[7401] | 198 | /// Changes the current object (used for member-functions). |
---|
[7236] | 199 | inline ConsoleCommandManipulator& setObject(void* object) |
---|
[7179] | 200 | { if (this->command_) { this->command_->setObject(object); } return *this; } |
---|
[7401] | 201 | /// Pushes a new object on the object-stack. |
---|
[7236] | 202 | inline ConsoleCommandManipulator& pushObject(void* object) |
---|
[7185] | 203 | { if (this->command_) { this->command_->pushObject(object); } return *this; } |
---|
[11071] | 204 | /// Removes the current object from the object-stack and restores the old object (or nullptr if there's no object left on the stack). |
---|
[7236] | 205 | inline ConsoleCommandManipulator& popObject() |
---|
[7185] | 206 | { if (this->command_) { this->command_->popObject(); } return *this; } |
---|
[7179] | 207 | |
---|
[7401] | 208 | /// Changes the activity of the command. |
---|
[7236] | 209 | inline ConsoleCommandManipulator& setActive(bool bActive) |
---|
[7179] | 210 | { if (this->command_) { this->command_->setActive(bActive); } return *this; } |
---|
[7401] | 211 | /// Activates the command. |
---|
[7236] | 212 | inline ConsoleCommandManipulator& activate() |
---|
[7214] | 213 | { return this->setActive(true); } |
---|
[7401] | 214 | /// Deactivates the command. |
---|
[7236] | 215 | inline ConsoleCommandManipulator& deactivate() |
---|
[7214] | 216 | { return this->setActive(false); } |
---|
[7179] | 217 | |
---|
[7401] | 218 | /// Changes the visibility of the command. |
---|
[7236] | 219 | inline ConsoleCommandManipulator& setHidden(bool bHidden) |
---|
[7215] | 220 | { if (this->command_) { this->command_->setHidden(bHidden); } return *this; } |
---|
[7401] | 221 | /// Hides the command (can still be executed, but is not visible in the list of available commands). |
---|
[7236] | 222 | inline ConsoleCommandManipulator& hide() |
---|
[7215] | 223 | { return this->setHidden(true); } |
---|
[7401] | 224 | /// Makes the command visible. |
---|
[7236] | 225 | inline ConsoleCommandManipulator& show() |
---|
[7215] | 226 | { return this->setHidden(false); } |
---|
[7214] | 227 | |
---|
[7401] | 228 | /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 229 | inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1) |
---|
| 230 | { if (this->command_) { this->command_->defaultValues(arg1); } return *this; } |
---|
| 231 | /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 232 | inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2) |
---|
| 233 | { if (this->command_) { this->command_->defaultValues(arg1, arg2); } return *this; } |
---|
| 234 | /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 235 | inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) |
---|
| 236 | { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3); } return *this; } |
---|
| 237 | /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 238 | inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) |
---|
| 239 | { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3, arg4); } return *this; } |
---|
| 240 | /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 241 | inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) |
---|
| 242 | { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3, arg4, arg5); } return *this; } |
---|
| 243 | /// Changes the default value of the argument with given index of the current executor (doesn't modify executors on deeper levels of the command-stack). |
---|
| 244 | inline ConsoleCommandManipulator& defaultValue(unsigned int index, const MultiType& arg) |
---|
| 245 | { if (this->command_) { this->command_->defaultValue(index, arg); } return *this; } |
---|
[7215] | 246 | |
---|
[7401] | 247 | /// Changes the access level of the command. |
---|
[11071] | 248 | inline ConsoleCommandManipulator& accessLevel(AccessLevel level) |
---|
[7215] | 249 | { if (this->command_) { this->command_->accessLevel(level); } return *this; } |
---|
| 250 | |
---|
[7401] | 251 | /// Changes the argument completer for the given parameter. |
---|
| 252 | inline ConsoleCommandManipulator& argumentCompleter(unsigned int index, ArgumentCompleter* completer) |
---|
| 253 | { if (this->command_) { this->command_->argumentCompleter(index, completer); } return *this; } |
---|
[7215] | 254 | |
---|
[7401] | 255 | /// Defines the command to be an input command. |
---|
[7236] | 256 | inline ConsoleCommandManipulator& setAsInputCommand() |
---|
[7215] | 257 | { if (this->command_) { this->command_->setAsInputCommand(); } return *this; } |
---|
[7401] | 258 | /// Changes the keybind mode of the command. |
---|
[7236] | 259 | inline ConsoleCommandManipulator& keybindMode(KeybindMode::Value mode) |
---|
[7861] | 260 | { if (this->command_) { this->command_->changeKeybindMode(mode); } return *this; } |
---|
[7401] | 261 | /// Sets the input configured param to the given index. |
---|
[7236] | 262 | inline ConsoleCommandManipulator& inputConfiguredParam(int index) |
---|
[7215] | 263 | { if (this->command_) { this->command_->inputConfiguredParam(index); } return *this; } |
---|
| 264 | |
---|
[7179] | 265 | private: |
---|
[7401] | 266 | ConsoleCommand* command_; ///< The command which is being manipulated by this object |
---|
[7179] | 267 | }; |
---|
| 268 | |
---|
| 269 | public: |
---|
[10624] | 270 | ConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true); |
---|
[7236] | 271 | ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true); |
---|
| 272 | ~ConsoleCommand(); |
---|
[7179] | 273 | |
---|
[7236] | 274 | ConsoleCommand& addShortcut(); |
---|
| 275 | ConsoleCommand& addShortcut(const std::string& name); |
---|
| 276 | ConsoleCommand& addGroup(const std::string& group); |
---|
| 277 | ConsoleCommand& addGroup(const std::string& group, const std::string& name); |
---|
[7179] | 278 | |
---|
[7401] | 279 | /// Returns the name that was first used for this command. |
---|
[7218] | 280 | inline const std::string& getName() const |
---|
| 281 | { return this->baseName_; } |
---|
| 282 | |
---|
| 283 | const ExecutorPtr& getExecutor() const; |
---|
[7401] | 284 | /// Returns the functor that defines the required header for this command (but isn't necessarily executed). |
---|
[7267] | 285 | inline const FunctorPtr& getBaseFunctor() const |
---|
| 286 | { return this->baseFunctor_; } |
---|
[7218] | 287 | |
---|
[7401] | 288 | /// Changes the activity of the command. |
---|
[7236] | 289 | inline ConsoleCommand& setActive(bool bActive) |
---|
[7215] | 290 | { this->bActive_ = bActive; return *this; } |
---|
[7401] | 291 | /// Activates the command. |
---|
[7236] | 292 | inline ConsoleCommand& activate() |
---|
[7215] | 293 | { return this->setActive(true); } |
---|
[7401] | 294 | /// Deactivates the command. |
---|
[7236] | 295 | inline ConsoleCommand& deactivate() |
---|
[7215] | 296 | { return this->setActive(false); } |
---|
| 297 | |
---|
[7401] | 298 | /// Changes the visibility of the command. |
---|
[7236] | 299 | inline ConsoleCommand& setHidden(bool bHidden) |
---|
[7215] | 300 | { this->bHidden_ = bHidden; return *this; } |
---|
[7401] | 301 | /// Hides the command (can still be executed, but is not visible in the list of available commands). |
---|
[7236] | 302 | inline ConsoleCommand& hide() |
---|
[7215] | 303 | { return this->setHidden(true); } |
---|
[7401] | 304 | /// Makes the command visible. |
---|
[7236] | 305 | inline ConsoleCommand& show() |
---|
[7215] | 306 | { return this->setHidden(false); } |
---|
| 307 | |
---|
[7214] | 308 | bool isActive() const; |
---|
[7215] | 309 | bool hasAccess() const; |
---|
[7401] | 310 | /// Returns true if the command is currently hidden. |
---|
[7222] | 311 | inline bool isHidden() const |
---|
| 312 | { return this->bHidden_; } |
---|
[7179] | 313 | |
---|
[7236] | 314 | ConsoleCommand& description(const std::string& description); |
---|
[7215] | 315 | const std::string& getDescription() const; |
---|
| 316 | |
---|
[7401] | 317 | ConsoleCommand& descriptionParam(unsigned int index, const std::string& description); |
---|
| 318 | const std::string& getDescriptionParam(unsigned int index) const; |
---|
[7215] | 319 | |
---|
[7236] | 320 | ConsoleCommand& descriptionReturnvalue(const std::string& description); |
---|
[7401] | 321 | const std::string& getDescriptionReturnvalue(int index) const; |
---|
[7215] | 322 | |
---|
[7401] | 323 | ConsoleCommand& defaultValues(const MultiType& arg1); |
---|
| 324 | ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2); |
---|
| 325 | ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3); |
---|
| 326 | ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4); |
---|
| 327 | ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5); |
---|
| 328 | ConsoleCommand& defaultValue(unsigned int index, const MultiType& arg); |
---|
[7215] | 329 | |
---|
[7401] | 330 | /// Changes the access level of the command. |
---|
[11071] | 331 | inline ConsoleCommand& accessLevel(AccessLevel level) |
---|
[7215] | 332 | { this->accessLevel_ = level; return *this; } |
---|
[7401] | 333 | /// Returns the access level of the command. |
---|
[11071] | 334 | inline AccessLevel getAccessLevel() const |
---|
[7215] | 335 | { return this->accessLevel_; } |
---|
| 336 | |
---|
[7401] | 337 | ConsoleCommand& argumentCompleter(unsigned int index, ArgumentCompleter* completer); |
---|
| 338 | ArgumentCompleter* getArgumentCompleter(unsigned int index) const; |
---|
[7215] | 339 | |
---|
[7401] | 340 | /// Defines the command to be an input command |
---|
[7236] | 341 | inline ConsoleCommand& setAsInputCommand() |
---|
[7215] | 342 | { |
---|
| 343 | this->keybindMode(KeybindMode::OnHold); |
---|
| 344 | this->defaultValue(0, Vector2(0.0f, 0.0f)); |
---|
| 345 | this->inputConfiguredParam(0); |
---|
| 346 | return *this; |
---|
| 347 | } |
---|
| 348 | |
---|
[7861] | 349 | /// Sets the keybind mode. Note: use changeKeybindMode if you intend to change the mode. |
---|
[7236] | 350 | inline ConsoleCommand& keybindMode(KeybindMode::Value mode) |
---|
[7215] | 351 | { this->keybindMode_ = mode; return *this; } |
---|
[7401] | 352 | /// Returns the keybind mode |
---|
[7215] | 353 | inline KeybindMode::Value getKeybindMode() const |
---|
| 354 | { return this->keybindMode_; } |
---|
| 355 | |
---|
[7861] | 356 | ConsoleCommand& changeKeybindMode(KeybindMode::Value mode); |
---|
| 357 | |
---|
[7401] | 358 | /// Changes the input configured param to the given index. |
---|
[7236] | 359 | inline ConsoleCommand& inputConfiguredParam(int index) |
---|
[7215] | 360 | { this->inputConfiguredParam_ = index; return *this; } |
---|
[7401] | 361 | /// Returns the input configured param. |
---|
[9983] | 362 | inline int getInputConfiguredParam() const |
---|
[7215] | 363 | { return this->inputConfiguredParam_; } |
---|
| 364 | |
---|
[7401] | 365 | /// Returns a manipulator for this command. |
---|
[9348] | 366 | inline ConsoleCommandManipulator getManipulator() |
---|
[7185] | 367 | { return this; } |
---|
| 368 | |
---|
[10624] | 369 | inline const std::vector<CommandName>& getNames() |
---|
| 370 | { return this->names_; } |
---|
| 371 | |
---|
[7179] | 372 | private: |
---|
[10624] | 373 | void init(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized); |
---|
| 374 | |
---|
[7214] | 375 | bool headersMatch(const FunctorPtr& functor); |
---|
| 376 | bool headersMatch(const ExecutorPtr& executor); |
---|
| 377 | |
---|
| 378 | bool setFunction(const ExecutorPtr& executor, bool bForce = false); |
---|
| 379 | bool setFunction(const FunctorPtr& functor, bool bForce = false); |
---|
| 380 | void pushFunction(const ExecutorPtr& executor, bool bForce = false); |
---|
| 381 | void pushFunction(const FunctorPtr& functor, bool bForce = false); |
---|
| 382 | void pushFunction(); |
---|
| 383 | void popFunction(); |
---|
[7218] | 384 | void resetFunction(); |
---|
[7179] | 385 | |
---|
[7214] | 386 | bool setObject(void* object); |
---|
[7185] | 387 | void pushObject(void* object); |
---|
| 388 | void popObject(); |
---|
| 389 | void* getObject() const; |
---|
[7179] | 390 | |
---|
[7401] | 391 | bool bActive_; ///< True if the command should be active (it can still be inactive, for example if the function is missing) |
---|
| 392 | bool bHidden_; ///< True if the command is hidden (it is still executable, but not visible in the list of available commands) |
---|
[11071] | 393 | AccessLevel accessLevel_; ///< The access level (the state of the game in which you can access the command) |
---|
[7401] | 394 | std::string baseName_; ///< The name that was first assigned to the command |
---|
[10624] | 395 | std::vector<CommandName> names_; ///< All names and aliases of this command |
---|
[7401] | 396 | FunctorPtr baseFunctor_; ///< The functor that defines the header of the command-function |
---|
[7214] | 397 | |
---|
[7401] | 398 | ExecutorPtr executor_; ///< The Executor that is used to execute the command |
---|
| 399 | std::stack<Command> commandStack_; ///< A stack of commands, used to push and pop different functions |
---|
| 400 | std::vector<void*> objectStack_; ///< A stack of objects, used to push and pop different objects for a function |
---|
[7215] | 401 | |
---|
[7401] | 402 | ArgumentCompleter* argumentCompleter_[MAX_FUNCTOR_ARGUMENTS]; ///< ArgumentCompleter for each argument |
---|
[7215] | 403 | |
---|
[7401] | 404 | KeybindMode::Value keybindMode_; ///< The keybind mode |
---|
| 405 | int inputConfiguredParam_; ///< The input configured param |
---|
[7215] | 406 | |
---|
[7401] | 407 | LanguageEntryLabel description_; ///< The description of the command |
---|
| 408 | LanguageEntryLabel descriptionReturnvalue_; ///< A description of the return-value |
---|
| 409 | LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; ///< A description for each argument |
---|
[7179] | 410 | }; |
---|
| 411 | } |
---|
| 412 | |
---|
[1505] | 413 | #endif /* _ConsoleCommand_H__ */ |
---|