Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/ConsoleCommand.h @ 1967

Last change on this file since 1967 was 1755, checked in by rgrieder, 16 years ago

merged gui back to trunk.
update the media repository!

  • Property svn:eol-style set to native
File size: 7.4 KB
RevLine 
[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
34#include "Executor.h"
[1549]35#include "Identifier.h"
[1505]36#include "CommandExecutor.h"
37#include "ArgumentCompletionFunctions.h"
38
39
[1747]40#define SetConsoleCommand(classname, function, bCreateShortcut) \
41    SetConsoleCommandAliasMulti(classname, function, #function, 0, bCreateShortcut)
42#define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
43    SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut)
44#define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \
45    SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
[1505]46
47#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
[1747]48    orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
[1505]49
50
51#define SetConsoleCommandShortcut(classname, function) \
[1747]52    SetConsoleCommandShortcutAliasMulti(classname, function, #function, 0)
53#define SetConsoleCommandShortcutAlias(classname, function, name) \
54    SetConsoleCommandShortcutAliasMulti(classname, function, name, 0)
55#define SetConsoleCommandShortcutAliasMulti(classname, function, name, number) \
56    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
[1505]57
58#define SetConsoleCommandShortcutExtern(function) \
[1747]59    SetConsoleCommandShortcutExternAliasMulti(function, #function, 0)
60#define SetConsoleCommandShortcutExternAlias(function, name) \
61    SetConsoleCommandShortcutExternAliasMulti(function, name, 0)
62#define SetConsoleCommandShortcutExternAliasMulti(function, name, number) \
63    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
[1505]64
65#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
[1534]66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
[1505]67
68
69namespace orxonox
70{
71    namespace AccessLevel
72    {
73        enum Level
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
[1747]108            inline ConsoleCommand& accessLevel(AccessLevel::Level level)
[1505]109                { this->accessLevel_ = level; return (*this); }
110            inline AccessLevel::Level getAccessLevel() const
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
[1747]124            inline ConsoleCommand& keybindMode(KeybindMode::Enum mode)
[1505]125                { this->keybindMode_ = mode; return *this; }
126            inline KeybindMode::Enum getKeybindMode() const
127                { return this->keybindMode_; }
128
[1747]129            inline ConsoleCommand& axisParamIndex(int index)
[1505]130                { this->axisParamIndex_ = index; return *this; }
131            inline int getAxisParamIndex() const
132                { return this->axisParamIndex_; }
133
[1747]134            inline ConsoleCommand& isAxisRelative(bool val)
[1505]135                { this->bAxisRelative_ = val; return *this; }
136            inline int getIsAxisRelative() const
137                { return this->bAxisRelative_; }
138
139        private:
140            AccessLevel::Level accessLevel_;
141            ArgumentCompleter* argumentCompleter_[5];
142            ArgumentCompletionList argumentList_;
143
144            KeybindMode::Enum keybindMode_;
145            int axisParamIndex_;
146            bool bAxisRelative_;
147    };
148
[1755]149    inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")
[1505]150    {
151        return new ConsoleCommand(functor, name);
152    }
153}
154
155#endif /* _ConsoleCommand_H__ */
Note: See TracBrowser for help on using the repository browser.