diff options
Diffstat (limited to 'src/interfaceconsole.cpp')
-rw-r--r-- | src/interfaceconsole.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/interfaceconsole.cpp b/src/interfaceconsole.cpp index 49be5c1..e652da8 100644 --- a/src/interfaceconsole.cpp +++ b/src/interfaceconsole.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include "smlnode.h" | 3 | #include "smlnode.h" |
4 | #include "gamestate.h" | 4 | #include "gamestate.h" |
5 | #include "situation.h" | ||
6 | #include "command.h" | ||
5 | 7 | ||
6 | #include <bu/sio.h> | 8 | #include <bu/sio.h> |
7 | 9 | ||
@@ -12,6 +14,8 @@ | |||
12 | #include <gats/gatsstream.h> | 14 | #include <gats/gatsstream.h> |
13 | #include <bu/file.h> | 15 | #include <bu/file.h> |
14 | 16 | ||
17 | #include <stdlib.h> | ||
18 | |||
15 | PluginInterface3( plugin_interface_console, console, InterfaceConsole, | 19 | PluginInterface3( plugin_interface_console, console, InterfaceConsole, |
16 | Interface, "Mike Buland", 1, 0 ); | 20 | Interface, "Mike Buland", 1, 0 ); |
17 | 21 | ||
@@ -34,10 +38,45 @@ void InterfaceConsole::run( Game *pGame ) | |||
34 | while( gs.isRunning() ) | 38 | while( gs.isRunning() ) |
35 | { | 39 | { |
36 | char buf[1024]; | 40 | char buf[1024]; |
37 | sio << sio.nl << "command> " << sio.flush; | 41 | switch( gs.getCurSituation()->getInputType() ) |
38 | fgets( buf, 1024, stdin ); | 42 | { |
43 | case Situation::inputCommand: | ||
44 | sio << sio.nl << "command> " << sio.flush; | ||
45 | fgets( buf, 1024, stdin ); | ||
46 | |||
47 | gs.execCommand( buf ); | ||
48 | break; | ||
49 | |||
50 | case Situation::inputOption: | ||
51 | sio << sio.nl; | ||
52 | { | ||
53 | const CommandSet::CommandList &cl = | ||
54 | gs.getCurSituation()->getCommandSet().getCommandList(); | ||
39 | 55 | ||
40 | gs.execCommand( buf ); | 56 | int j = 1; |
57 | for( CommandSet::CommandList::const_iterator i = cl.begin(); | ||
58 | i; i++ ) | ||
59 | { | ||
60 | sio << " " << j << ") " << (*i)->getRoot() << sio.nl; | ||
61 | j++; | ||
62 | } | ||
63 | sio << "Enter your selection: " << sio.flush; | ||
64 | fgets( buf, 1024, stdin ); | ||
65 | if( buf[0] < '1' || buf[0] > '9' ) | ||
66 | j = -1; | ||
67 | else | ||
68 | j = strtol( buf, NULL, 10 ); | ||
69 | if( j < 1 || j > cl.getSize() ) | ||
70 | { | ||
71 | sio << "Invalid selection, try again." << sio.nl; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | gs.execOption( j-1 ); | ||
76 | } | ||
77 | } | ||
78 | break; | ||
79 | } | ||
41 | } | 80 | } |
42 | } | 81 | } |
43 | 82 | ||