mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:23:53 +00:00
Fixes the console sometimes receiving text after it was closed
This commit is contained in:
parent
1bc343f363
commit
8407e2b3aa
4 changed files with 48 additions and 49 deletions
|
@ -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<std::string> matches;
|
||||
listNames();
|
||||
command->setCaption(complete( command->getCaption(), matches ));
|
||||
mCommandLine->setCaption(complete( mCommandLine->getCaption(), matches ));
|
||||
#if 0
|
||||
int i = 0;
|
||||
for(std::vector<std::string>::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<std::string> &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()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef MWGUI_CONSOLE_H
|
||||
#define MWGUI_CONSOLE_H
|
||||
|
||||
#include <openengine/gui/layout.hpp>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -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<std::string> 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:
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<Property key="Caption" value="#{sConsoleTitle}"/>
|
||||
<Property key="MinSize" value="200 100"/>
|
||||
<Property key="MaxSize" value="2000 2000"/>
|
||||
<Property key="Visible" value="false"/>
|
||||
|
||||
<!-- Log window -->
|
||||
<Widget type="EditBox" skin="MW_ConsoleLog" position="5 5 380 330" align="Stretch" name="list_History">
|
||||
|
|
Loading…
Reference in a new issue