forked from mirror/openmw-tes3mp
- bound the console to Monster
git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@105 ea6a568a-9f4f-0410-981a-c910a81bb256
This commit is contained in:
parent
876fc482ca
commit
b7bdb1f815
7 changed files with 101 additions and 18 deletions
|
@ -31,9 +31,13 @@ extern(C):
|
||||||
typedef void* WidgetPtr;
|
typedef void* WidgetPtr;
|
||||||
void gui_setupGUI(int debugOut);
|
void gui_setupGUI(int debugOut);
|
||||||
void gui_toggleGui();
|
void gui_toggleGui();
|
||||||
void gui_toggleConsole();
|
|
||||||
void gui_setCellName(char *str);
|
void gui_setCellName(char *str);
|
||||||
|
|
||||||
|
// Console stuff
|
||||||
|
void gui_toggleConsole();
|
||||||
|
void gui_setConsoleFont(char*);
|
||||||
|
void gui_clearConsole();
|
||||||
|
|
||||||
// Get the widget type, as a string
|
// Get the widget type, as a string
|
||||||
char *gui_widgetType(WidgetPtr);
|
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
|
class Console : public Layout
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
MyGUI::EditPtr command;
|
MyGUI::EditPtr command;
|
||||||
MyGUI::EditPtr history;
|
MyGUI::EditPtr history;
|
||||||
|
|
||||||
public:
|
|
||||||
Console()
|
Console()
|
||||||
: Layout("openmw_console_layout.xml")
|
: Layout("openmw_console_layout.xml")
|
||||||
{
|
{
|
||||||
|
@ -58,17 +72,35 @@ public:
|
||||||
const Ogre::UTFString &cm = command->getCaption();
|
const Ogre::UTFString &cm = command->getCaption();
|
||||||
if(cm.empty()) return;
|
if(cm.empty()) return;
|
||||||
|
|
||||||
if(cm == "big")
|
history->addText("#FFFFFF" + cm + "\n");
|
||||||
history->setFontName("youtube");
|
|
||||||
|
|
||||||
history->addText(cm + "\n");
|
int res = console_input(cm.asUTF8_c_str());
|
||||||
history->addText("this is a fake output result\n");
|
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");
|
||||||
|
|
||||||
|
exit:
|
||||||
command->setCaption("");
|
command->setCaption("");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Console *cons;
|
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()
|
extern "C" void gui_toggleConsole()
|
||||||
{
|
{
|
||||||
if(consoleMode)
|
if(consoleMode)
|
||||||
|
|
35
gui/gui.d
35
gui/gui.d
|
@ -25,8 +25,12 @@ module gui.gui;
|
||||||
|
|
||||||
import monster.monster;
|
import monster.monster;
|
||||||
import monster.vm.mclass;
|
import monster.vm.mclass;
|
||||||
|
import monster.modules.console;
|
||||||
|
import input.events : exitProgram;
|
||||||
import gui.bindings;
|
import gui.bindings;
|
||||||
|
import bullet.bindings;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
// Widget class and gui module
|
// Widget class and gui module
|
||||||
MonsterClass
|
MonsterClass
|
||||||
|
@ -253,4 +257,35 @@ void setupGUIScripts()
|
||||||
gmc.bind("loadLayout", &loadLayout);
|
gmc.bind("loadLayout", &loadLayout);
|
||||||
gmc.bind("getWidth", &getWidth);
|
gmc.bind("getWidth", &getWidth);
|
||||||
gmc.bind("getHeight", &getHeight);
|
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>
|
</Font>
|
||||||
|
|
||||||
<!-- Useful for youtube videos :) -->
|
<!-- 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="33 126"/>
|
||||||
<Code range="1025 1105"/>
|
<Code range="1025 1105"/>
|
||||||
</Font>
|
</Font>
|
||||||
|
|
|
@ -53,11 +53,11 @@ import monster.monster;
|
||||||
// Console results
|
// Console results
|
||||||
enum CR
|
enum CR
|
||||||
{
|
{
|
||||||
Ok, // Command was executed
|
Ok = 1, // Command was executed
|
||||||
Error, // An error occurred
|
Error = 2, // An error occurred
|
||||||
More, // An unterminated multi-line statement was entered, need
|
More = 3, // An unterminated multi-line statement was entered, need
|
||||||
// more input
|
// more input
|
||||||
Empty, // The line was empty (nothing was executed)
|
Empty = 4, // The line was empty (nothing was executed)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Console
|
class Console
|
||||||
|
|
|
@ -29,11 +29,22 @@ class Console
|
||||||
|
|
||||||
import game
|
import game
|
||||||
|
|
||||||
native walk()
|
// Change player physics mode
|
||||||
native fly()
|
native walk();
|
||||||
native ghost()
|
native fly();
|
||||||
|
native ghost();
|
||||||
|
|
||||||
native wireframe()
|
// Clear the console
|
||||||
tvf() { wireframe() }
|
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 core.config;
|
||||||
|
|
||||||
import ogre.bindings;
|
import ogre.bindings;
|
||||||
|
import gui.bindings;
|
||||||
import mscripts.setup;
|
import mscripts.setup;
|
||||||
|
|
||||||
import bullet.bindings;
|
import bullet.bindings;
|
||||||
|
|
Loading…
Reference in a new issue