1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-05 15:55:45 +00:00
OpenMW/apps/openmw/mwgui/console.hpp

106 lines
3.2 KiB
C++
Raw Normal View History

2010-07-20 19:10:51 +00:00
#ifndef MWGUI_CONSOLE_H
#define MWGUI_CONSOLE_H
#include <list>
#include <string>
#include <vector>
#include <components/compiler/errorhandler.hpp>
#include <components/compiler/lineparser.hpp>
#include <components/compiler/scanner.hpp>
#include <components/compiler/locals.hpp>
2010-07-21 08:08:38 +00:00
#include <components/compiler/output.hpp>
#include <components/compiler/extensions.hpp>
2010-07-21 08:08:38 +00:00
#include <components/interpreter/interpreter.hpp>
#include "../mwscript/compilercontext.hpp"
2010-07-21 08:08:38 +00:00
#include "../mwscript/interpretercontext.hpp"
2010-07-20 19:10:51 +00:00
#include "referenceinterface.hpp"
#include "windowbase.hpp"
2010-07-20 19:10:51 +00:00
namespace MWGui
{
class Console : public WindowBase, private Compiler::ErrorHandler, public ReferenceInterface
{
public:
/// Set the implicit object for script execution
void setSelectedObject(const MWWorld::Ptr& object);
2011-01-12 17:24:00 +00:00
MyGUI::EditBox* mCommandLine;
MyGUI::EditBox* mHistory;
2011-01-12 17:24:00 +00:00
typedef std::list<std::string> StringList;
// History of previous entered commands
StringList mCommandHistory;
StringList::iterator mCurrent;
std::string mEditString;
Console(int w, int h, bool consoleOnlyScripts);
2011-01-12 17:24:00 +00:00
virtual void open();
virtual void close();
2011-01-12 17:24:00 +00:00
virtual void exit();
void setFont(const std::string &fntName);
void onResChange(int width, int height);
void clearHistory();
// Print a message to the console. Messages may contain color
// code, eg. "#FFFFFF this is white".
void print(const std::string &msg);
// These are pre-colored versions that you should use.
2010-07-20 19:10:51 +00:00
/// Output from successful console command
void printOK(const std::string &msg);
2010-07-20 19:10:51 +00:00
/// Error message
void printError(const std::string &msg);
2010-07-20 19:10:51 +00:00
void execute (const std::string& command);
2010-07-21 08:08:38 +00:00
void executeFile (const std::string& path);
2010-07-21 08:08:38 +00:00
virtual void resetReference ();
protected:
2010-07-21 08:08:38 +00:00
virtual void onReferenceUnavailable();
private:
2010-07-20 19:10:51 +00:00
void keyPress(MyGUI::Widget* _sender,
MyGUI::KeyCode key,
MyGUI::Char _char);
2010-07-20 19:10:51 +00:00
void acceptCommand(MyGUI::EditBox* _sender);
2010-07-20 19:10:51 +00:00
std::string complete( std::string input, std::vector<std::string> &matches );
2010-07-20 19:10:51 +00:00
Compiler::Extensions mExtensions;
MWScript::CompilerContext mCompilerContext;
std::vector<std::string> mNames;
bool mConsoleOnlyScripts;
2010-07-20 19:10:51 +00:00
bool compile (const std::string& cmd, Compiler::Output& output);
/// Report error to the user.
virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type);
2012-07-30 10:37:46 +00:00
/// Report a file related error
virtual void report (const std::string& message, Type type);
2010-07-20 19:10:51 +00:00
/// Write all valid identifiers and keywords into mNames and sort them.
/// \note If mNames is not empty, this function is a no-op.
/// \note The list may contain duplicates (if a name is a keyword and an identifier at the same
/// time).
void listNames();
2010-07-20 19:10:51 +00:00
};
}
#endif