QuickGUI::Console

Teknoman117

20-07-2010 00:17:09

I am using the console widget, or would like to in my game to interface with the Lua interpreter that is the scripting engine for it. I can't find the event that triggers when the user inputs text. I found the addCharEnteredEventHandler function but when casting the event object in the event function to QuickGUI::KeyEventArgs, it doesn't respond to the enter key. So how would I detect when someone entered information and hit enter in the console? I also tried addWidgetEventHandler triggering on KEY_DOWN but it produced no results. Can anyone help?

kungfoomasta

20-07-2010 01:00:05

You have to make use of the setConsoleInputHandler API. In this API you supply a handler that is called whenever the Enter button is pressed. The signature is different than regular event handlers, since you can clear the input box and/or add the submitted text to the text area from this handler, by modifying parameters.

Teknoman117

20-07-2010 03:37:56

Thank you! That solved my problem - now I can inject commands into my Lua script system!
Just for anyone who might stumble across this thread at some point in the future, here is the code that solved my problem:


void UIController::onConsoleInput(QuickGUI::Console* console, bool& clearInputBox, bool& addToDisplayArea) {
clearInputBox = true;
addToDisplayArea = false;
console->addDisplayAreaText(console->getInputBoxText(), console->getInputBoxDefaultFont(), console->getInputBoxDefaultColor(), false);
console->addDisplayAreaText(">", console->getInputBoxDefaultFont(), console->getInputBoxDefaultColor(), true);
/* Check input text for specifics */
if((console->getInputBoxText() == "clear") || (console->getInputBoxText() == "cls")) console->clearDisplayArea();
}


/* snippit from my ui controller constructor */
mLuaConsole = mSheet->createConsole(QuickGUI::Rect(width/2, height/2, width/2, height/2));
mLuaConsole->setBaseColor(QuickGUI::ColourValue::Black);
mLuaConsole->setInputBoxDefaultFont("Monospace");
mLuaConsole->addDisplayAreaText("Teknogin version 0.1", "Monospace", QuickGUI::ColourValue::White, true);
mLuaConsole->addDisplayAreaText("Lua 5.1.4 Console", "Monospace", QuickGUI::ColourValue::White, true);
mLuaConsole->addDisplayAreaText(">", "Monospace", QuickGUI::ColourValue::White, true);
mLuaConsole->setInputBoxHeight(32);
mLuaConsole->setConsoleInputHandler(&UIController::onConsoleInput,this);