- bound the console to Monster

git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@105 ea6a568a-9f4f-0410-981a-c910a81bb256
actorid
nkorslund 16 years ago
parent 876fc482ca
commit b7bdb1f815

@ -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);

@ -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)

@ -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);
}

@ -18,7 +18,7 @@
</Font>
<!-- Useful for youtube videos :) -->
<Font name="youtube" default_height="34" source="VeraMono.ttf" size="36" resolution="50" antialias_colour="false" space_width="4" tab_width="8" cursor_width="2" distance="5" offset_height="0">
<Font name="youtube" default_height="34" source="VeraMono.ttf" size="36" resolution="50" antialias_colour="false" space_width="8" tab_width="16" cursor_width="4" distance="10" offset_height="0">
<Code range="33 126"/>
<Code range="1025 1105"/>
</Font>

@ -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

@ -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)

@ -27,6 +27,7 @@ import core.resource;
import core.config;
import ogre.bindings;
import gui.bindings;
import mscripts.setup;
import bullet.bindings;

Loading…
Cancel
Save