29 #include <boost/bind.hpp> 74 _font(
FontMan.get(font, fontHeight)), _historySizeMax(history),
75 _historySizeCurrent(0), _historyStart(0), _cursorPosition(0),
76 _overwrite(false), _cursorBlinkState(false), _lastCursorBlink(0) {
79 assert(history >= lines);
90 _prompt->disableColorTokens(
true);
91 _input->disableColorTokens(
true);
101 _lines.reserve(lines - 1);
102 for (
size_t i = 0; i < (lines - 1); i++) {
104 _lines.back()->disableColorTokens(
true);
123 for (std::vector<Graphics::Aurora::Text *>::iterator l =
_lines.begin();
131 for (std::vector<Graphics::Aurora::Text *>::iterator l =
_lines.begin();
148 for (std::vector<Graphics::Aurora::Text *>::iterator l =
_lines.begin();
265 for (std::vector<Graphics::Aurora::Text *>::iterator l =
_lines.begin();
272 std::vector<Common::UString> lines;
275 for (std::vector<Common::UString>::iterator l = lines.begin(); l != lines.end(); ++l)
306 if (redirect.
empty())
329 logFile =
ConfigMan.getString(
"consolelog");
330 if (
ConfigMan.getBool(
"noconsolelog",
false))
369 const ptrdiff_t x =
MIN(start, end);
370 const size_t length =
ABS(start - end);
379 CursorMan.toScreenCoordinates(cursorX, cursorY, realX, realY);
384 if ((x < 0.0f) || (x >
_width))
386 if ((y < 0.0f) || (y >
_height))
393 y = CLIP<size_t>(y, 0,
_lines.size());
404 x =
CLIP(x, minX, maxX);
427 size_t endX = floor(lineX);
443 size_t wX = floor(lineX);
444 size_t wY = floor(lineY);
450 const size_t pos = (wY == 0) ? (wX -
_prompt->
get().size()) : wX;
507 start = MAX<ptrdiff_t>(0, start);
508 end = MAX<ptrdiff_t>(0, end );
574 glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
579 glVertex2f(
_x ,
_y );
586 glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
588 glVertex2f(
_x ,
_y - 3.0f);
591 glVertex2f(
_x ,
_y );
595 glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
604 glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
612 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
616 int newWidth,
int newHeight) {
620 _x = -(newWidth / 2.0f);
625 _lines[i]->setPosition(
_x, textY, -1001.0f);
635 if ((it == line.
end()) || (*it ==
' '))
638 while ((it != line.
begin()) && (*it !=
' '))
649 if ((it == line.
end()) || (*it ==
' '))
652 while ((it != line.
end()) && (*it !=
' '))
663 _cursor->setPosition(cursorX,
_y, -1002.0f);
666 _cursor->setWidth(cursorWidth);
672 std::list<Common::UString>::reverse_iterator h =
_history.rbegin();
675 for (
int i =
_lines.size() - 1; (i >= 0) && (h !=
_history.rend()); i--, ++h)
687 const float height =
_height - 4.0f;
692 float position = 0.0f;
704 _engine(&engine), _neverShown(true), _visible(false), _tabCount(0),
705 _printedCompleteWarning(false), _lastClickCount(-1),
706 _lastClickButton(0), _lastClickTime(0), _lastClickX(0), _lastClickY(0),
707 _maxSizeVideos(0), _maxSizeSounds(0) {
715 "Usage: help [<command>]\nPrint help text");
717 "Usage: clear\nClear the console window");
719 "Usage: close\nClose the console window, returning to the game");
721 "Usage: quit\nQuit xoreos entirely");
723 "Usage: dumpreslist <file>\nDump the current list of resources to file");
725 "Usage: dumpres <resource>\nDump a resource to file");
727 "Usage: dumptga <resource>\nDump an image resource into a TGA");
729 "Usage: dump2da <2da>\nDump a 2DA to file");
731 "Usage: dumpall2da\nDump all 2DA to file");
733 "Usage: listvideos\nList all available videos");
735 "Usage: playvideo <video>\nPlay the specified video");
737 "Usage: listsounds\nList all available sounds");
739 "Usage: playsound <sound>\nPlay the specified sound");
741 "Usage: silence\nStop all playing sounds and music");
743 "Usage: getoption <option>\nPrint the value of a config options");
745 "Usage: setoption <option> <value>\nSet the value of a config option for this session");
747 "Usage: showfps <true/false>\nShow/Hide the frames-per-second display");
749 "Usage: listlangs\nLists all languages supported by this game version");
751 "Usage: getlang\nPrint the current language settings");
753 "Usage: setlang <language>\n setlang <language_text> <language_voice>\n" 754 "Change the game's current language");
756 "Usage: getstring <strref>\nGet a string from the talk manager and print it");
758 "Usage: getcamera\nPrint the current camera position and orientation");
760 "Usage: setcamera <posX> <posY> <posZ> [<orientX> <orientY> <orientZ>]\n" 761 "Set the camera position (and orientation)");
763 _console->print(
"Console ready...");
775 _console->print(
"Type 'close' to return to the game. Type 'help' for a list of commands.");
806 return _console->getContentHeight();
823 const uint8 button =
event.button.button;
824 const uint8 pasteMask1 = SDL_BUTTON_MMASK;
825 const uint8 pasteMask2 = SDL_BUTTON_LMASK | SDL_BUTTON_RMASK;
828 if (((button & pasteMask1) == pasteMask1) || ((button & pasteMask2) == pasteMask2)) {
836 if (button & SDL_BUTTON_LMASK) {
837 _console->startHighlight(event.button.x, event.button.y);
845 if (event.motion.state & SDL_BUTTON_LMASK) {
846 _console->stopHighlight(event.button.x, event.button.y);
867 if (event.button.button & SDL_BUTTON_LMASK) {
870 _console->stopHighlight(event.button.x, event.button.y);
873 _console->highlightWord(event.button.x, event.button.y);
876 _console->highlightLine(event.button.x, event.button.y);
887 if (event.key.keysym.sym != SDLK_TAB) {
894 if ((event.key.keysym.sym == SDLK_ESCAPE) ||
895 ((event.key.keysym.sym == SDLK_d) && (event.key.keysym.mod & KMOD_CTRL))) {
901 if ((event.key.keysym.sym == SDLK_l) && (event.key.keysym.mod & KMOD_CTRL)) {
907 if ((event.key.keysym.sym == SDLK_PAGEUP) && (event.key.keysym.mod & KMOD_SHIFT)) {
913 if ((event.key.keysym.sym == SDLK_PAGEDOWN) && (event.key.keysym.mod & KMOD_SHIFT)) {
919 if (event.key.keysym.sym == SDLK_PAGEUP) {
925 if (event.key.keysym.sym == SDLK_PAGEDOWN) {
931 if ((event.key.keysym.sym == SDLK_HOME) && (event.key.keysym.mod & KMOD_SHIFT)) {
937 if ((event.key.keysym.sym == SDLK_END) && (event.key.keysym.mod & KMOD_SHIFT)) {
946 if (event.wheel.y > 0) {
951 if (event.wheel.y < 0) {
958 if (!
_readLine->processEvent(event, command))
973 CommandMap::iterator c =
_commands.find(cmd);
979 c->second.disabled =
true;
980 c->second.disableReason = reason;
984 CommandMap::iterator c =
_commands.find(cmd);
990 c->second.disabled =
false;
1024 printf(
"Unknown command \"%s\". Type 'help' for a list of available commands.",
1029 if (cmd->second.disabled) {
1030 if (cmd->second.disableReason.empty())
1033 printf(
"Command \"%s\" is currently disabled: %s.", cl.
cmd.
c_str(),
1034 cmd->second.disableReason.c_str());
1040 if (!
_console->setRedirect(redirect))
1045 cmd->second.callback(cl);
1057 const std::vector<Common::UString> &hints =
_readLine->getCompleteHint(maxSize);
1061 maxSize = MAX<size_t>(maxSize, 3) + 2;
1063 size_t lines = hints.size() / lineSize;
1067 printf(
"%u completion candidates", (
uint)hints.size());
1107 if (stack.empty()) {
1108 print(
"FATAL ERROR");
1112 printf(
"%s%s", prefix.
c_str(), stack.top().c_str());
1116 while (!stack.empty()) {
1117 printf(
"'- Because: %s", stack.top().c_str());
1131 std::list<Aurora::ResourceManager::ResourceID> videos;
1134 for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator v = videos.begin();
1135 v != videos.end(); ++v) {
1149 std::list<Aurora::ResourceManager::ResourceID> sounds;
1152 for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator s = sounds.begin();
1153 s != sounds.end(); ++s) {
1194 printf(
"Dumped list of resources to file \"%s\"", file.
c_str());
1196 printf(
"Failed dumping list of resources to file \"%s\"", file.
c_str());
1242 std::list<Aurora::ResourceManager::ResourceID> twoda;
1245 std::list<Aurora::ResourceManager::ResourceID>::const_iterator t;
1246 for (t = twoda.begin(); t != twoda.end(); ++t) {
1250 printf(
"Dumped 2DA \"%s\" to \"%s\"", t->name.c_str(), file.
c_str());
1252 printf(
"Failed dumping 2DA \"%s\"", t->name.c_str());
1289 std::vector<Common::UString> args;
1297 printf(
"\"%s\" = \"%s\"", args[0].c_str(),
ConfigMan.getString(args[0]).c_str());
1301 std::vector<Common::UString> args;
1304 if (args.size() < 2) {
1309 ConfigMan.setCommandlineKey(args[0], args[1]);
1312 printf(
"\"%s\" = \"%s\"", args[0].c_str(),
ConfigMan.getString(args[0]).c_str());
1326 std::vector<Aurora::Language> langs;
1328 if (!langs.empty()) {
1329 printf(
"Available languages:");
1330 for (std::vector<Aurora::Language>::iterator l = langs.begin(); l != langs.end(); ++l)
1335 std::vector<Aurora::Language> langsT, langsV;
1337 if (!langsT.empty()) {
1338 printf(
"Available text languages:");
1339 for (std::vector<Aurora::Language>::iterator l = langsT.begin(); l != langsT.end(); ++l)
1343 if (!langsV.empty()) {
1344 printf(
"Available voice languages:");
1345 for (std::vector<Aurora::Language>::iterator l = langsV.begin(); l != langsV.end(); ++l)
1358 printf(
"%s text + %s voices",
LangMan.getLanguageName(langT).c_str(),
1359 LangMan.getLanguageName(langV).c_str());
1363 std::vector<Common::UString> args;
1366 if (args.size() == 1) {
1367 ConfigMan.setCommandlineKey(
"lang" , args[0]);
1368 ConfigMan.setCommandlineKey(
"langtext" , args[0]);
1369 ConfigMan.setCommandlineKey(
"langvoice", args[0]);
1370 }
else if (args.size() == 2) {
1371 ConfigMan.setCommandlineKey(
"langtext" , args[0]);
1372 ConfigMan.setCommandlineKey(
"langvoice", args[1]);
1381 printf(
"Changed language to %s",
LangMan.getLanguageName(lang).c_str());
1385 printf(
"Change language to %s text + %s voices",
LangMan.getLanguageName(langT).c_str(),
1386 LangMan.getLanguageName(langV).c_str());
1388 printf(
"Failed to change the language");
1392 CommandMap::const_iterator c =
_commands.find(cmd);
1398 print(c->second.help);
1407 uint32 strRef = 0xFFFFFFFF;
1419 const float *pos =
CameraMan.getPosition();
1420 const float *orient =
CameraMan.getOrientation();
1422 printf(
"Position : % 9.3f, % 9.3f, % 9.3f", pos [0], pos [1], pos [2]);
1423 printf(
"Orientation: % 9.3f, % 9.3f, % 9.3f", orient[0], orient[1], orient[2]);
1427 std::vector<Common::UString> args;
1430 if ((args.size() != 3) && (args.size() != 6)) {
1435 float pos[3] = {0.0f, 0.0f, 0.0f}, orient[3] = {0.0f, 0.0f, 0.0f};
1438 for (
size_t i = 0; i < 3; i++)
1445 if (args.size() > 3) {
1447 for (
size_t i = 0; i < 3; i++)
1455 CameraMan.setPosition(pos[0], pos[1], pos[2]);
1457 if (args.size() > 3)
1458 CameraMan.setOrientation(orient[0], orient[1], orient[2]);
1464 print(
"Available commands (help <command> for further help on each command):");
1467 std::vector<Common::UString> commands;
1471 commands.push_back(c->second.cmd);
1473 maxSize =
MAX(maxSize, commands.back().size());
1484 for (std::vector<Common::UString>::const_iterator l = list.begin(); l != list.end(); ++l)
1485 maxSize = MAX<size_t>(maxSize, l->size());
1487 maxSize = MAX<size_t>(maxSize, 3);
1490 size_t lineSize = 1;
1491 if (maxSize >= (columns - 2))
1493 else if (maxSize > 0)
1494 lineSize = columns / (maxSize + 2);
1497 size_t toPrint = MIN<size_t>((
kConsoleHistory - 1) * lineSize, list.size());
1498 size_t linesCut = list.size() - toPrint;
1509 std::vector<Common::UString>::const_iterator l = list.begin();
1510 std::advance(l, linesCut);
1513 while (l != list.end()) {
1517 for (
size_t i = 0; (i < lineSize) && (l != list.end()); i++, ++l) {
1520 size_t itemSize = item.
size();
1522 if (itemSize > maxSize) {
1528 size_t pad = (maxSize + 2) - itemSize;
1540 bool inQuote =
false;
1551 if (*c ==
' ' && !inQuote) {
1552 if (!args.back().empty())
1561 if (args.back().empty())
1580 std::pair<CommandMap::iterator, bool> result;
1586 result.first->second.cmd = cmd;
1587 result.first->second.help = help;
1589 result.first->second.callback = callback;
1591 result.first->second.disabled =
false;
1601 std::vector<Common::UString> commands;
1603 commands.push_back(c->second.cmd);
1605 _readLine->setArguments(
"help", commands);
void printLine(const Common::UString &line)
virtual bool getLanguage(Aurora::Language &language) const
Return the game's current language.
float getContentHeight() const
#define ResMan
Shortcut for accessing the sound manager.
Common::ScopedPtr< Graphics::Aurora::Text > _input
Table data, 2-dimensional text array.
static UString getUserDataDirectory()
Return the OS-specific path of the user data directory.
std::vector< Common::UString > _sounds
bool setRedirect(Common::UString redirect="")
virtual void show()
Show the object.
void playVideo(const Common::UString &video)
Play this video resource.
float getContentWidth() const
The global graphics manager.
void highlightLine(int x, int y)
void updateHelpArguments()
#define TalkMan
Shortcut for accessing the talk manager.
virtual void hide()
Hide the object.
void cmdDumpTGA(const CommandLine &cl)
void updateScrollbarLength()
Generic engine interface.
A class holding an UTF-8 string.
#define TextureMan
Shortcut for accessing the texture manager.
bool isIn(float x, float y) const
Is that point within the object?
void writeString(const UString &str)
Write the given string to the stream, encoded as UTF-8.
void reset(PointerType o=0)
Resets the pointer with the new value.
double _distance
The distance of the object from the viewer.
The global config manager.
bool dumpResList(const Common::UString &name)
Debug method to quickly dump the current list of resource to disk.
void updateScrollbarPosition()
static void splitArguments(Common::UString argLine, std::vector< Common::UString > &args)
Graphics::Aurora::FontHandle _font
float getLineWidth(const Common::UString &text) const
Return the width of this string.
static const size_t kConsoleHistory
virtual float getLineSpacing() const
Return the size of space between lines.
The Aurora texture manager.
static size_t findWordStart(const Common::UString &line, size_t pos)
static const uint32 kDoubleClickTime
static const size_t kConsoleLines
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
void truncate(const iterator &it)
iterator getPosition(size_t n) const
Convert a numerical position into an iterator.
bool _printedCompleteWarning
bool dumpResource(const Common::UString &name, Aurora::FileType type, const Common::UString &file)
Debug method to quickly dump a resource to disk.
void cmdListLangs(const CommandLine &cl)
bool printHints(const Common::UString &command)
void stopHighlight(int x, int y)
void highlightClip(size_t &x, size_t &y) const
std::vector< Common::UString > _videos
void execute(const Common::UString &line)
void cmdDumpAll2DA(const CommandLine &cl)
iterator findFirst(uint32 c) const
void setPrompt(const Common::UString &prompt)
Utility templates and functions for working with strings and streams.
void calculateDistance()
Calculate the object's distance.
Exception that provides a stack of explanations.
Common::UString getHighlight() const
static const size_t kCommandHistorySize
Common::ScopedPtr< Graphics::Aurora::Text > _prompt
void cmdSetOption(const CommandLine &cl)
A class providing (limited) readline-like capabilities.
Mouse button was pressed.
Keyboard key was pressed.
void cmdDumpResList(const CommandLine &cl)
Mouse button was released.
virtual void showCallback()
std::stack< UString > Stack
void disableCommand(const Common::UString &cmd, const Common::UString &reason="")
UString substr(iterator from, iterator to) const
void cmdListSounds(const CommandLine &cl)
utf8::iterator< std::string::const_iterator > iterator
const char * c_str() const
Return the (utf8 encoded) string data.
size_t getColumns() const
static UString getUserDataFile(UString file)
Return a path suitable for writing into.
void setClickable(bool clickable)
Set the object's clickable state.
bool open(const UString &fileName)
Try to open the file with the given fileName.
void cmdClose(const CommandLine &cl)
Common::ScopedPtr< ConsoleWindow > _console
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
void cmdGetCamera(const CommandLine &cl)
void cmdGetString(const CommandLine &cl)
#define ConfigMan
Shortcut for accessing the config manager.
Utility templates and functions.
bool dumpTGA(const Common::UString &name, const Common::UString &file)
Debug method to quickly dump an image resource to disk.
void cmdSilence(const CommandLine &cl)
void cmdPlayVideo(const CommandLine &cl)
void cmdGetLang(const CommandLine &cl)
void print(const Common::UString &line)
The global events manager.
void cmdSetCamera(const CommandLine &cl)
bool isOpen() const
Checks if the object opened a file successfully.
Common::ScopedPtr< Common::ReadLine > _readLine
void setInput(const Common::UString &input, size_t cursorPos, bool overwrite)
void printList(const std::vector< Common::UString > &list, size_t maxSize=0)
static UString canonicalize(const UString &p, bool resolveSymLinks=true)
Return the canonical, absolutized and normalized path.
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Generic Aurora engines (debug) console.
ConsoleWindow(const Common::UString &font, size_t lines, size_t history, int fontHeight=0)
#define SoundMan
Shortcut for accessing the sound manager.
bool dump2DA(const Common::UString &name, const Common::UString &file)
Debug method to quickly dump a 2DA to disk.
static UString getDirectory(const UString &p)
Return a path's directory.
void writeByte(byte value)
#define CursorMan
Shortcut for accessing the cursor manager.
void cmdSetLang(const CommandLine &cl)
void highlightWord(int x, int y)
#define EventMan
Shortcut for accessing the events manager.
void flush()
Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the ...
The Aurora cursor manager.
bool getPosition(int cursorX, int cursorY, float &x, float &y)
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
void printException(Common::Exception &e, const Common::UString &prefix="ERROR: ")
void enableCommand(const Common::UString &cmd)
PointerType get() const
Returns the plain pointer value.
#define WindowMan
Shortcut for accessing the window manager.
The base class for an engine within BioWare's Aurora family.
virtual bool changeLanguage()
Change the game's current language.
void close()
Close the file, if open.
Common::WriteFile _redirect
size_t size() const
Return the size of the string, in characters.
static const char * kPrompt
#define LangMan
Shortcut for accessing the language manager.
bool isVisible() const
Is the object visible?
void cmdShowFPS(const CommandLine &cl)
void cmdDumpRes(const CommandLine &cl)
static bool createDirectories(const UString &path)
Create all directories in this path.
static size_t findWordEnd(const Common::UString &line, size_t pos)
void showFPS()
Evaluate the FPS display setting and show/hide the FPS display.
The global talk manager for Aurora strings.
void show()
Show the object.
void cmdListVideos(const CommandLine &cl)
Console(Engine &engine, const Common::UString &font, int fontHeight=0)
std::list< Common::UString > _history
void scrollDown(size_t n=1)
void render(Graphics::RenderPass pass)
Render the object.
void cmdGetOption(const CommandLine &cl)
void printf(const char *s,...) GCC_PRINTF(2
bool processEvent(const Events::Event &event)
void setTag(const Common::UString &tag)
Set the object's tag.
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _cursor
void cmdPlaySound(const CommandLine &cl)
void print(const Common::UString &line)
#define CameraMan
Shortcut for accessing the camera manager.
void cmdDump2DA(const CommandLine &cl)
size_t _historySizeCurrent
Generic Aurora engines utility functions.
ptrdiff_t _highlightLength
Common::UString _inputText
void cmdClear(const CommandLine &cl)
virtual void updateCaches()
void printCommandHelp(const Common::UString &cmd)
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
void startHighlight(int x, int y)
void cmdHelp(const CommandLine &cl)
boost::function< void(const CommandLine &cl)> CommandCallback
size_t getColumns() const
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _highlight
void NORETURN_PRE error(const char *s,...)
T CLIP(T v, T amin, T amax)
virtual bool detectLanguages(Aurora::GameID game, const Common::UString &target, Aurora::Platform platform, std::vector< Aurora::Language > &languages) const
Detect which languages this game instance supports.
A textured quad for a GUI element.
Common::WriteFile _logFile
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
virtual float getHeight() const =0
Return the height of a character.
void clear()
Clear the string's contents.
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
void cmdQuit(const CommandLine &cl)
#define GfxMan
Shortcut for accessing the graphics manager.
std::vector< Graphics::Aurora::Text * > _lines
virtual float getWidth(uint32 c) const =0
Return the width of a character.
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
Only render opaque parts.
#define FontMan
Shortcut for accessing the font manager.
void SWAP(T &a, T &b)
Template method which swaps the values of its two parameters.
void hide()
Hide the object.
void scrollUp(size_t n=1)