mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 11:53: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)
|
Console::Console(int w, int h, bool consoleOnlyScripts)
|
||||||
: Layout("openmw_console.layout"),
|
: WindowBase("openmw_console.layout"),
|
||||||
mCompilerContext (MWScript::CompilerContext::Type_Console),
|
mCompilerContext (MWScript::CompilerContext::Type_Console),
|
||||||
mConsoleOnlyScripts (consoleOnlyScripts)
|
mConsoleOnlyScripts (consoleOnlyScripts)
|
||||||
{
|
{
|
||||||
setCoord(10,10, w-10, h/2);
|
setCoord(10,10, w-10, h/2);
|
||||||
|
|
||||||
getWidget(command, "edit_Command");
|
getWidget(mCommandLine, "edit_Command");
|
||||||
getWidget(history, "list_History");
|
getWidget(mHistory, "list_History");
|
||||||
|
|
||||||
// Set up the command line box
|
// Set up the command line box
|
||||||
command->eventEditSelectAccept +=
|
mCommandLine->eventEditSelectAccept +=
|
||||||
newDelegate(this, &Console::acceptCommand);
|
newDelegate(this, &Console::acceptCommand);
|
||||||
command->eventKeyButtonPressed +=
|
mCommandLine->eventKeyButtonPressed +=
|
||||||
newDelegate(this, &Console::keyPress);
|
newDelegate(this, &Console::keyPress);
|
||||||
|
|
||||||
// Set up the log window
|
// Set up the log window
|
||||||
history->setOverflowToTheLeft(true);
|
mHistory->setOverflowToTheLeft(true);
|
||||||
history->setEditStatic(true);
|
mHistory->setEditStatic(true);
|
||||||
history->setVisibleVScroll(true);
|
mHistory->setVisibleVScroll(true);
|
||||||
|
|
||||||
// compiler
|
// compiler
|
||||||
MWScript::registerExtensions (mExtensions, mConsoleOnlyScripts);
|
MWScript::registerExtensions (mExtensions, mConsoleOnlyScripts);
|
||||||
mCompilerContext.setExtensions (&mExtensions);
|
mCompilerContext.setExtensions (&mExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::enable()
|
void Console::open()
|
||||||
{
|
{
|
||||||
setVisible(true);
|
|
||||||
|
|
||||||
// Give keyboard focus to the combo box whenever the console is
|
// Give keyboard focus to the combo box whenever the console is
|
||||||
// turned on
|
// 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)
|
void Console::setFont(const std::string &fntName)
|
||||||
{
|
{
|
||||||
history->setFontName(fntName);
|
mHistory->setFontName(fntName);
|
||||||
command->setFontName(fntName);
|
mCommandLine->setFontName(fntName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::clearHistory()
|
void Console::clearHistory()
|
||||||
{
|
{
|
||||||
history->setCaption("");
|
mHistory->setCaption("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::print(const std::string &msg)
|
void Console::print(const std::string &msg)
|
||||||
{
|
{
|
||||||
history->addText(msg);
|
mHistory->addText(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::printOK(const std::string &msg)
|
void Console::printOK(const std::string &msg)
|
||||||
|
@ -215,7 +214,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
std::vector<std::string> matches;
|
std::vector<std::string> matches;
|
||||||
listNames();
|
listNames();
|
||||||
command->setCaption(complete( command->getCaption(), matches ));
|
mCommandLine->setCaption(complete( mCommandLine->getCaption(), matches ));
|
||||||
#if 0
|
#if 0
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(std::vector<std::string>::iterator it=matches.begin(); it < matches.end(); it++,i++ )
|
for(std::vector<std::string>::iterator it=matches.begin(); it < matches.end(); it++,i++ )
|
||||||
|
@ -227,50 +226,50 @@ namespace MWGui
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command_history.empty()) return;
|
if(mCommandHistory.empty()) return;
|
||||||
|
|
||||||
// Traverse history with up and down arrows
|
// Traverse history with up and down arrows
|
||||||
if(key == MyGUI::KeyCode::ArrowUp)
|
if(key == MyGUI::KeyCode::ArrowUp)
|
||||||
{
|
{
|
||||||
// If the user was editing a string, store it for later
|
// If the user was editing a string, store it for later
|
||||||
if(current == command_history.end())
|
if(mCurrent == mCommandHistory.end())
|
||||||
editString = command->getCaption();
|
mEditString = mCommandLine->getCaption();
|
||||||
|
|
||||||
if(current != command_history.begin())
|
if(mCurrent != mCommandHistory.begin())
|
||||||
{
|
{
|
||||||
current--;
|
mCurrent--;
|
||||||
command->setCaption(*current);
|
mCommandLine->setCaption(*mCurrent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(key == MyGUI::KeyCode::ArrowDown)
|
else if(key == MyGUI::KeyCode::ArrowDown)
|
||||||
{
|
{
|
||||||
if(current != command_history.end())
|
if(mCurrent != mCommandHistory.end())
|
||||||
{
|
{
|
||||||
current++;
|
mCurrent++;
|
||||||
|
|
||||||
if(current != command_history.end())
|
if(mCurrent != mCommandHistory.end())
|
||||||
command->setCaption(*current);
|
mCommandLine->setCaption(*mCurrent);
|
||||||
else
|
else
|
||||||
// Restore the edit string
|
// Restore the edit string
|
||||||
command->setCaption(editString);
|
mCommandLine->setCaption(mEditString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::acceptCommand(MyGUI::EditBox* _sender)
|
void Console::acceptCommand(MyGUI::EditBox* _sender)
|
||||||
{
|
{
|
||||||
const std::string &cm = command->getCaption();
|
const std::string &cm = mCommandLine->getCaption();
|
||||||
if(cm.empty()) return;
|
if(cm.empty()) return;
|
||||||
|
|
||||||
// Add the command to the history, and set the current pointer to
|
// Add the command to the history, and set the current pointer to
|
||||||
// the end of the list
|
// the end of the list
|
||||||
command_history.push_back(cm);
|
mCommandHistory.push_back(cm);
|
||||||
current = command_history.end();
|
mCurrent = mCommandHistory.end();
|
||||||
editString.clear();
|
mEditString.clear();
|
||||||
|
|
||||||
execute (cm);
|
execute (cm);
|
||||||
|
|
||||||
command->setCaption("");
|
mCommandLine->setCaption("");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Console::complete( std::string input, std::vector<std::string> &matches )
|
std::string Console::complete( std::string input, std::vector<std::string> &matches )
|
||||||
|
@ -412,7 +411,7 @@ namespace MWGui
|
||||||
setTitle("#{sConsoleTitle}");
|
setTitle("#{sConsoleTitle}");
|
||||||
mPtr = MWWorld::Ptr();
|
mPtr = MWWorld::Ptr();
|
||||||
}
|
}
|
||||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCommandLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::onReferenceUnavailable()
|
void Console::onReferenceUnavailable()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef MWGUI_CONSOLE_H
|
#ifndef MWGUI_CONSOLE_H
|
||||||
#define MWGUI_CONSOLE_H
|
#define MWGUI_CONSOLE_H
|
||||||
|
|
||||||
#include <openengine/gui/layout.hpp>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -18,10 +17,11 @@
|
||||||
#include "../mwscript/interpretercontext.hpp"
|
#include "../mwscript/interpretercontext.hpp"
|
||||||
|
|
||||||
#include "referenceinterface.hpp"
|
#include "referenceinterface.hpp"
|
||||||
|
#include "windowbase.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler, public ReferenceInterface
|
class Console : public WindowBase, private Compiler::ErrorHandler, public ReferenceInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -55,21 +55,20 @@ namespace MWGui
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyGUI::EditBox* command;
|
MyGUI::EditBox* mCommandLine;
|
||||||
MyGUI::EditBox* history;
|
MyGUI::EditBox* mHistory;
|
||||||
|
|
||||||
typedef std::list<std::string> StringList;
|
typedef std::list<std::string> StringList;
|
||||||
|
|
||||||
// History of previous entered commands
|
// History of previous entered commands
|
||||||
StringList command_history;
|
StringList mCommandHistory;
|
||||||
StringList::iterator current;
|
StringList::iterator mCurrent;
|
||||||
std::string editString;
|
std::string mEditString;
|
||||||
|
|
||||||
Console(int w, int h, bool consoleOnlyScripts);
|
Console(int w, int h, bool consoleOnlyScripts);
|
||||||
|
|
||||||
void enable();
|
virtual void open();
|
||||||
|
virtual void close();
|
||||||
void disable();
|
|
||||||
|
|
||||||
void setFont(const std::string &fntName);
|
void setFont(const std::string &fntName);
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ namespace MWGui
|
||||||
|
|
||||||
void execute (const std::string& command);
|
void execute (const std::string& command);
|
||||||
|
|
||||||
void executeFile (const std::string& command);
|
void executeFile (const std::string& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,7 @@ namespace MWGui
|
||||||
mMap->setVisible(false);
|
mMap->setVisible(false);
|
||||||
mMenu->setVisible(false);
|
mMenu->setVisible(false);
|
||||||
mStatsWindow->setVisible(false);
|
mStatsWindow->setVisible(false);
|
||||||
mConsole->disable();
|
mConsole->setVisible(false);
|
||||||
mJournal->setVisible(false);
|
mJournal->setVisible(false);
|
||||||
mDialogueWindow->setVisible(false);
|
mDialogueWindow->setVisible(false);
|
||||||
mContainerWindow->setVisible(false);
|
mContainerWindow->setVisible(false);
|
||||||
|
@ -398,7 +398,7 @@ namespace MWGui
|
||||||
mInventoryWindow->setVisible(mInventoryWindow->pinned());
|
mInventoryWindow->setVisible(mInventoryWindow->pinned());
|
||||||
mSpellWindow->setVisible(mSpellWindow->pinned());
|
mSpellWindow->setVisible(mSpellWindow->pinned());
|
||||||
|
|
||||||
mConsole->enable();
|
mConsole->setVisible(true);
|
||||||
break;
|
break;
|
||||||
case GM_Scroll:
|
case GM_Scroll:
|
||||||
mScrollWindow->setVisible(true);
|
mScrollWindow->setVisible(true);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<Property key="Caption" value="#{sConsoleTitle}"/>
|
<Property key="Caption" value="#{sConsoleTitle}"/>
|
||||||
<Property key="MinSize" value="200 100"/>
|
<Property key="MinSize" value="200 100"/>
|
||||||
<Property key="MaxSize" value="2000 2000"/>
|
<Property key="MaxSize" value="2000 2000"/>
|
||||||
|
<Property key="Visible" value="false"/>
|
||||||
|
|
||||||
<!-- Log window -->
|
<!-- Log window -->
|
||||||
<Widget type="EditBox" skin="MW_ConsoleLog" position="5 5 380 330" align="Stretch" name="list_History">
|
<Widget type="EditBox" skin="MW_ConsoleLog" position="5 5 380 330" align="Stretch" name="list_History">
|
||||||
|
|
Loading…
Reference in a new issue