diff --git a/gui/bindings.d b/gui/bindings.d index 5fd514973..4e91ec58e 100644 --- a/gui/bindings.d +++ b/gui/bindings.d @@ -31,9 +31,13 @@ extern(C): typedef void* WidgetPtr; void gui_setupGUI(int debugOut); void gui_toggleGui(); -void gui_toggleConsole(); void gui_setCellName(char *str); +// Console stuff +void gui_toggleConsole(); +void gui_setConsoleFont(char*); +void gui_clearConsole(); + // Get the widget type, as a string char *gui_widgetType(WidgetPtr); diff --git a/gui/cpp_console.cpp b/gui/cpp_console.cpp index 637e94018..0b4ec008d 100644 --- a/gui/cpp_console.cpp +++ b/gui/cpp_console.cpp @@ -21,12 +21,26 @@ */ +// These are defined in gui/gui.d. At some point later we will just +// use the C++ bindings included with Monster, but these don't cover +// the console stuff yet. +enum + { + CR_OK = 1, // Command was executed + CR_ERROR = 2, // An error occured + CR_MORE = 3, // More input is needed + CR_EMPTY = 4 // The line had no effect + }; + +extern "C" int32_t console_input(const char* command); +extern "C" char* console_output(); + class Console : public Layout { +public: MyGUI::EditPtr command; MyGUI::EditPtr history; -public: Console() : Layout("openmw_console_layout.xml") { @@ -58,17 +72,35 @@ public: const Ogre::UTFString &cm = command->getCaption(); if(cm.empty()) return; - if(cm == "big") - history->setFontName("youtube"); + history->addText("#FFFFFF" + cm + "\n"); + + int res = console_input(cm.asUTF8_c_str()); + Ogre::UTFString out = console_output(); + + if(res == CR_OK) + history->addText("#FF00FF" + out); + else if(res == CR_ERROR) + history->addText("#FF2222" + out); + else if(res == CR_MORE) + history->addText("#1111FF... more input needed"); - history->addText(cm + "\n"); - history->addText("this is a fake output result\n"); + exit: command->setCaption(""); } }; Console *cons; +extern "C" void gui_setConsoleFont(const char* fntName) +{ + cons->history->setFontName(fntName); +} + +extern "C" void gui_clearConsole() +{ + cons->history->setCaption(""); +} + extern "C" void gui_toggleConsole() { if(consoleMode) diff --git a/gui/gui.d b/gui/gui.d index 451f49751..b089f63d1 100644 --- a/gui/gui.d +++ b/gui/gui.d @@ -25,8 +25,12 @@ module gui.gui; import monster.monster; import monster.vm.mclass; +import monster.modules.console; +import input.events : exitProgram; import gui.bindings; +import bullet.bindings; import std.string; +import std.stdio; // Widget class and gui module MonsterClass @@ -253,4 +257,35 @@ void setupGUIScripts() gmc.bind("loadLayout", &loadLayout); gmc.bind("getWidth", &getWidth); gmc.bind("getHeight", &getHeight); + + // Set up the console + auto cmc = vm.load("Console"); + auto cmo = cmc.createObject; + cons = new Console(cmo); + + // Bind native functions + cmc.bind("walk", { bullet_walk(); }); + cmc.bind("fly", { bullet_fly(); }); + cmc.bind("ghost", { bullet_ghost(); }); + cmc.bind("setfont", { gui_setConsoleFont(toStringz(stack.popString8())); }); + cmc.bind("clear", { gui_clearConsole(); }); + cmc.bind("exit", { exitProgram(); }); + cmc.bind("wireframe", { writefln("Wireframe not fixed yet"); }); +} + +Console cons; + +// Some glue code that will go away later when we use the C++ +// interface to Monster directly. +extern(C): +int console_input(char* str) +{ + char[] dstr = toString(str); + return cons.input(dstr); +} + +char* console_output() +{ + char[] dstr = cons.output(); + return toStringz(dstr); } diff --git a/media_mygui/openmw.font.xml b/media_mygui/openmw.font.xml index 5a4f6b580..48ba4e8f8 100644 --- a/media_mygui/openmw.font.xml +++ b/media_mygui/openmw.font.xml @@ -18,7 +18,7 @@ - + diff --git a/monster/modules/console.d b/monster/modules/console.d index 00a5f4540..21f52c893 100644 --- a/monster/modules/console.d +++ b/monster/modules/console.d @@ -53,11 +53,11 @@ import monster.monster; // Console results enum CR { - Ok, // Command was executed - Error, // An error occurred - More, // An unterminated multi-line statement was entered, need - // more input - Empty, // The line was empty (nothing was executed) + Ok = 1, // Command was executed + Error = 2, // An error occurred + More = 3, // An unterminated multi-line statement was entered, need + // more input + Empty = 4, // The line was empty (nothing was executed) } class Console diff --git a/mscripts/console.mn b/mscripts/console.mn index 1d1cee93f..0ad88d683 100644 --- a/mscripts/console.mn +++ b/mscripts/console.mn @@ -29,11 +29,22 @@ class Console import game -native walk() -native fly() -native ghost() +// Change player physics mode +native walk(); +native fly(); +native ghost(); -native wireframe() -tvf() { wireframe() } +// Clear the console +native clear(); + +// Set the console log font +native setfont(char[] name); + +// Exit the game +native exit(); +quit() { exit(); } + +// Toggle wireframe mode +native wireframe(); +twf() { wireframe() } -native fontsize(int size) diff --git a/ogre/ogre.d b/ogre/ogre.d index d07d5e342..287230f80 100644 --- a/ogre/ogre.d +++ b/ogre/ogre.d @@ -27,6 +27,7 @@ import core.resource; import core.config; import ogre.bindings; +import gui.bindings; import mscripts.setup; import bullet.bindings;