Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound4/src/libraries/core/Shell.h @ 6655

Last change on this file since 6655 was 6432, checked in by rgrieder, 15 years ago

Changed the way config values associated with general settings (ConfigFileType::Settings) are handled:

  • ConfigFileManager only handles config files listed in the ConfigFileType enum (normal enum again)
  • ConfigFileManager only takes care of ConfigFiles and returns a pointer to the right one, just two functions left. —> use like: ConfigFileManager::getInstance().getConfigFile(myType)→doSomething();
  • Moved all code (except for the argument completion functions) relating to ConfigFileType::Settings to a new class: SettingsConfigFile, which is a Singleton (it doesn't make sense to have multiple instances unless you start coding a lot more)
  • SettingsConfigFile handles config value containers according to their section and entry in the ini file, not according to class and variables names. (In most cases it will be class and variable names though)
  • SettingsConfigFile supports:
    • clear() (removes any file entries not associated to a config value container)
    • updateConfigValues() (does exactly that through the identifier)
    • config, tconfig and getConfig
    • commands listed above are exported to tolua, and tconfig, config and getConfig were given shortcuts in Lua (e.g. orxonox.config)
  • If you need to organise ConfigFiles yourself, just do it without the ConfigFileManager, like the KeyBinder does.
  • All getValue() functions have been split into getOrCreateValue() and getValue(), which is const
  • Removed obsolete config value management code in the Identifier (it still stores and destroys them and provides access to them)

All of that leads to one HUGE advantage:
"config OutputHandler softDebugLevelInGameConsole"
works now :D (any further implications are up to the reader…)
(it didn't work before because the actual config value container is in the InGameConsole singleton)

  • Property svn:eol-style set to native
File size: 5.5 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 *      Reto Grieder
26 *
27 */
28
29#ifndef _Shell_H__
30#define _Shell_H__
31
32#include "CorePrereqs.h"
33
34#include <list>
35#include <sstream>
36#include <string>
37#include <vector>
38
39#include "util/OutputHandler.h"
40#include "OrxonoxClass.h"
41#include "input/InputBuffer.h"
42
43namespace orxonox
44{
45    class _CoreExport ShellListener
46    {
47        friend class Shell;
48
49        public:
50            virtual ~ShellListener() {}
51
52        private:
53            virtual void linesChanged() {}
54            virtual void onlyLastLineChanged() {}
55            virtual void lineAdded() {}
56            virtual void inputChanged() {}
57            virtual void cursorChanged() {}
58            virtual void executed() {}
59            virtual void exit() {}
60    };
61
62
63    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
64    {
65        public:
66            enum LineType
67            {
68                None    = OutputLevel::None,
69                Warning = OutputLevel::Warning,
70                Error   = OutputLevel::Error,
71                Info    = OutputLevel::Info,
72                Debug   = OutputLevel::Debug,
73                Verbose = OutputLevel::Verbose,
74                Ultra   = OutputLevel::Ultra,
75                Input,
76                Command,
77                Hint
78            };
79
80            Shell(const std::string& consoleName, bool bScrollable);
81            ~Shell();
82
83            void setConfigValues();
84            void commandHistoryOffsetChanged();
85            void commandHistoryLengthChanged();
86
87            void registerListener(ShellListener* listener);
88            void unregisterListener(ShellListener* listener);
89
90            inline InputBuffer* getInputBuffer()
91                { return this->inputBuffer_; }
92
93            void setCursorPosition(unsigned int cursor);
94            inline unsigned int getCursorPosition() const
95                { return this->inputBuffer_->getCursorPosition(); }
96
97            inline const std::string& getInput() const
98                { return this->inputBuffer_->get(); }
99
100            typedef std::list<std::pair<std::string, LineType> > LineList;
101            LineList::const_iterator getNewestLineIterator() const;
102            LineList::const_iterator getEndIterator() const;
103
104            void addOutput(const std::string& text, LineType type = None);
105            void clearOutput();
106
107            inline unsigned int getNumLines() const
108                { return this->outputLines_.size(); }
109            inline unsigned int getScrollPosition() const
110                { return this->scrollPosition_; }
111
112            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
113            void setPromptPrefix(const std::string& str);
114
115        private:
116            Shell(const Shell& other);
117
118            void addToHistory(const std::string& command);
119            const std::string& getFromHistory() const;
120            void clearInput();
121            // OutputListener
122            void outputChanged(int level);
123
124            void configureInputBuffer();
125
126            // InputBuffer callbacks
127            void inputChanged();
128            void execute();
129            void hintAndComplete();
130            void backspace();
131            void deleteChar();
132            void cursorRight();
133            void cursorLeft();
134            void cursorEnd();
135            void cursorHome();
136            void historyUp();
137            void historyDown();
138            void historySearchUp();
139            void historySearchDown();
140            void scrollUp();
141            void scrollDown();
142            void exit();
143
144            template <void (ShellListener::*F)()>
145            void updateListeners()
146            {
147                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
148                    ((*(it++))->*F)();
149            }
150
151            std::list<ShellListener*> listeners_;
152            InputBuffer*              inputBuffer_;
153            std::stringstream         outputBuffer_;
154            bool                      bFinishedLastLine_;
155            LineList                  outputLines_;
156            LineList::const_iterator  scrollIterator_;
157            unsigned int              scrollPosition_;
158            unsigned int              historyPosition_;
159
160            std::string               promptPrefix_;
161            const std::string         consoleName_;
162            const bool                bScrollable_;
163
164            // Config values
165            unsigned int              maxHistoryLength_;
166            unsigned int              historyOffset_;
167            std::vector<std::string>  commandHistory_;
168            int                       softDebugLevel_;
169    };
170}
171
172#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.