Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ceguilua/src/core/ConsoleCommand.h @ 2087

Last change on this file since 2087 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
Line 
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"
35#include "Identifier.h"
36#include "CommandExecutor.h"
37#include "ArgumentCompletionFunctions.h"
38
39
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)
46
47#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
48    orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
49
50
51#define SetConsoleCommandShortcut(classname, function) \
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))
57
58#define SetConsoleCommandShortcutExtern(function) \
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))
64
65#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
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
84    class _CoreExport ConsoleCommand : public Executor
85    {
86        public:
87            ConsoleCommand(Functor* functor, const std::string& name = "");
88
89            inline ConsoleCommand& description(const std::string& description)
90                { this->Executor::setDescription(description); return (*this); }
91            inline ConsoleCommand& descriptionParam(int param, const std::string& description)
92                { this->Executor::setDescriptionParam(param, description); return (*this); }
93            inline ConsoleCommand& descriptionReturnvalue(const std::string& description)
94                { this->Executor::setDescriptionReturnvalue(description); return (*this); }
95            inline ConsoleCommand& defaultValues(const MultiType& param1)
96                { this->Executor::setDefaultValues(param1); return (*this); }
97            inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2)
98                { this->Executor::setDefaultValues(param1, param2); return (*this); }
99            inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
100                { this->Executor::setDefaultValues(param1, param2, param3); return (*this); }
101            inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
102                { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); }
103            inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
104                { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
105            inline ConsoleCommand& defaultValue(unsigned int index, const MultiType& param)
106                { this->Executor::setDefaultValue(index, param); return (*this); }
107
108            inline ConsoleCommand& accessLevel(AccessLevel::Level level)
109                { this->accessLevel_ = level; return (*this); }
110            inline AccessLevel::Level getAccessLevel() const
111                { return this->accessLevel_; }
112
113            ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);
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
124            inline ConsoleCommand& keybindMode(KeybindMode::Enum mode)
125                { this->keybindMode_ = mode; return *this; }
126            inline KeybindMode::Enum getKeybindMode() const
127                { return this->keybindMode_; }
128
129            inline ConsoleCommand& axisParamIndex(int index)
130                { this->axisParamIndex_ = index; return *this; }
131            inline int getAxisParamIndex() const
132                { return this->axisParamIndex_; }
133
134            inline ConsoleCommand& isAxisRelative(bool val)
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
149    inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")
150    {
151        return new ConsoleCommand(functor, name);
152    }
153}
154
155#endif /* _ConsoleCommand_H__ */
Note: See TracBrowser for help on using the repository browser.