diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index f438d5e09..3bc0de4cb 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -101,59 +101,58 @@ namespace MWGui } Console::Console(int w, int h, bool consoleOnlyScripts) - : Layout("openmw_console.layout"), + : WindowBase("openmw_console.layout"), mCompilerContext (MWScript::CompilerContext::Type_Console), mConsoleOnlyScripts (consoleOnlyScripts) { setCoord(10,10, w-10, h/2); - getWidget(command, "edit_Command"); - getWidget(history, "list_History"); + getWidget(mCommandLine, "edit_Command"); + getWidget(mHistory, "list_History"); // Set up the command line box - command->eventEditSelectAccept += + mCommandLine->eventEditSelectAccept += newDelegate(this, &Console::acceptCommand); - command->eventKeyButtonPressed += + mCommandLine->eventKeyButtonPressed += newDelegate(this, &Console::keyPress); // Set up the log window - history->setOverflowToTheLeft(true); - history->setEditStatic(true); - history->setVisibleVScroll(true); + mHistory->setOverflowToTheLeft(true); + mHistory->setEditStatic(true); + mHistory->setVisibleVScroll(true); // compiler MWScript::registerExtensions (mExtensions, mConsoleOnlyScripts); mCompilerContext.setExtensions (&mExtensions); } - void Console::enable() + void Console::open() { - setVisible(true); - // Give keyboard focus to the combo box whenever the console is // turned on - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command); + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCommandLine); } - void Console::disable() + void Console::close() { - setVisible(false); + // Apparently, hidden widgets can retain key focus + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(NULL); } void Console::setFont(const std::string &fntName) { - history->setFontName(fntName); - command->setFontName(fntName); + mHistory->setFontName(fntName); + mCommandLine->setFontName(fntName); } void Console::clearHistory() { - history->setCaption(""); + mHistory->setCaption(""); } void Console::print(const std::string &msg) { - history->addText(msg); + mHistory->addText(msg); } void Console::printOK(const std::string &msg) @@ -215,7 +214,7 @@ namespace MWGui { std::vector matches; listNames(); - command->setCaption(complete( command->getCaption(), matches )); + mCommandLine->setCaption(complete( mCommandLine->getCaption(), matches )); #if 0 int i = 0; for(std::vector::iterator it=matches.begin(); it < matches.end(); it++,i++ ) @@ -227,50 +226,50 @@ namespace MWGui #endif } - if(command_history.empty()) return; + if(mCommandHistory.empty()) return; // Traverse history with up and down arrows if(key == MyGUI::KeyCode::ArrowUp) { // If the user was editing a string, store it for later - if(current == command_history.end()) - editString = command->getCaption(); + if(mCurrent == mCommandHistory.end()) + mEditString = mCommandLine->getCaption(); - if(current != command_history.begin()) + if(mCurrent != mCommandHistory.begin()) { - current--; - command->setCaption(*current); + mCurrent--; + mCommandLine->setCaption(*mCurrent); } } else if(key == MyGUI::KeyCode::ArrowDown) { - if(current != command_history.end()) + if(mCurrent != mCommandHistory.end()) { - current++; + mCurrent++; - if(current != command_history.end()) - command->setCaption(*current); + if(mCurrent != mCommandHistory.end()) + mCommandLine->setCaption(*mCurrent); else // Restore the edit string - command->setCaption(editString); + mCommandLine->setCaption(mEditString); } } } void Console::acceptCommand(MyGUI::EditBox* _sender) { - const std::string &cm = command->getCaption(); + const std::string &cm = mCommandLine->getCaption(); if(cm.empty()) return; // Add the command to the history, and set the current pointer to // the end of the list - command_history.push_back(cm); - current = command_history.end(); - editString.clear(); + mCommandHistory.push_back(cm); + mCurrent = mCommandHistory.end(); + mEditString.clear(); execute (cm); - command->setCaption(""); + mCommandLine->setCaption(""); } std::string Console::complete( std::string input, std::vector &matches ) @@ -412,7 +411,7 @@ namespace MWGui setTitle("#{sConsoleTitle}"); mPtr = MWWorld::Ptr(); } - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command); + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCommandLine); } void Console::onReferenceUnavailable() diff --git a/apps/openmw/mwgui/console.hpp b/apps/openmw/mwgui/console.hpp index b1d961ed2..890176363 100644 --- a/apps/openmw/mwgui/console.hpp +++ b/apps/openmw/mwgui/console.hpp @@ -1,7 +1,6 @@ #ifndef MWGUI_CONSOLE_H #define MWGUI_CONSOLE_H -#include #include #include #include @@ -18,10 +17,11 @@ #include "../mwscript/interpretercontext.hpp" #include "referenceinterface.hpp" +#include "windowbase.hpp" namespace MWGui { - class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler, public ReferenceInterface + class Console : public WindowBase, private Compiler::ErrorHandler, public ReferenceInterface { private: @@ -55,21 +55,20 @@ namespace MWGui public: - MyGUI::EditBox* command; - MyGUI::EditBox* history; + MyGUI::EditBox* mCommandLine; + MyGUI::EditBox* mHistory; typedef std::list StringList; // History of previous entered commands - StringList command_history; - StringList::iterator current; - std::string editString; + StringList mCommandHistory; + StringList::iterator mCurrent; + std::string mEditString; Console(int w, int h, bool consoleOnlyScripts); - void enable(); - - void disable(); + virtual void open(); + virtual void close(); void setFont(const std::string &fntName); @@ -91,7 +90,7 @@ namespace MWGui void execute (const std::string& command); - void executeFile (const std::string& command); + void executeFile (const std::string& path); private: diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 5dbdbf90a..38bc0481d 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -329,7 +329,7 @@ namespace MWGui mMap->setVisible(false); mMenu->setVisible(false); mStatsWindow->setVisible(false); - mConsole->disable(); + mConsole->setVisible(false); mJournal->setVisible(false); mDialogueWindow->setVisible(false); mContainerWindow->setVisible(false); @@ -398,7 +398,7 @@ namespace MWGui mInventoryWindow->setVisible(mInventoryWindow->pinned()); mSpellWindow->setVisible(mSpellWindow->pinned()); - mConsole->enable(); + mConsole->setVisible(true); break; case GM_Scroll: mScrollWindow->setVisible(true); diff --git a/files/mygui/openmw_console.layout b/files/mygui/openmw_console.layout index 732684ad1..6b0bb9f17 100644 --- a/files/mygui/openmw_console.layout +++ b/files/mygui/openmw_console.layout @@ -4,6 +4,7 @@ +