Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2988 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • 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) \
[2662]66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
[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
[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
[1747]132            inline ConsoleCommand& keybindMode(KeybindMode::Enum mode)
[1505]133                { this->keybindMode_ = mode; return *this; }
134            inline KeybindMode::Enum getKeybindMode() const
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:
143            AccessLevel::Level accessLevel_;
144            ArgumentCompleter* argumentCompleter_[5];
145            ArgumentCompletionList argumentList_;
146
147            KeybindMode::Enum 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__ */
Note: See TracBrowser for help on using the repository browser.