Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
command.h
Go to the documentation of this file.
1 #ifndef COMMANDINTERP
2 #define COMMANDINTERP
3 
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include "functors.h"
8 #include "rendertext.h" //menusystem
9 #include "in.h"
10 
11 //#include "areas.h" //must be at the bottom
12 
13 //this class is ONLY used by commandI.
14 //it encapsulates a function pointer, with a name and an ARG_TYPE.
15 class coms
16 {
17 public:
18  virtual ~coms();
19  coms( TFunctor *t_in );
20  coms( coms *oldCom );
21  coms( const coms &in );
22  std::string Name;
24 };
25 
26 //hmm so how do we do menus. Should they be done right in here?
27 //two classes, menu class, menuitem class, and a vector of menu's.
28 //and a vector of menuitems on the menu class.
29 class mItem
30 {
31 //no destructor is made for this item, there do not need to be ANY
32 //pointers here.
33 public:
34 //~mItem(){}
36  {
37  inputbit = false;
38  inputbit2 = false;
39  autoreprint = false;
40  }
41  std::string Name; //menuitem name
42  std::string action; //menuitem action -- arguments for the com
43  std::string display; //display txt
44 //object all menuitems *should* have but may not.
45  std::string func2call; //function 2 call
46 //coms *COM; //don't ever DELETE this pointer!
47 //and don't ever use a NEW on it either!
48 //it should be an existing coms object in the command
49 //vector!!!
50  bool inputbit; //if this menuitem expects input from the user
51  bool inputbit2;
52  bool autoreprint; //autoreprint the menu after it's called
53  std::string menubuf; //holds a buffer to be executed later
54 //if inputbit2 is true.
55  std::string selectstring; //string to be displayed when selected
56  std::string predisplay; //call virtual function Display(std::string &)
57  //using this string, IF it's larger than 0.
58 };
59 
60 class menu
61 {
62 public:
63  virtual ~menu();
64  menu()
65  {
66  selected = false;
67  noescape = false;
68  autoselect = false;
69  defaultInput = false;
70  }
71  menu( const std::string n_in, char const *d_in, char const *e_in )
72  {
73  selected = false;
74  noescape = false;
75  autoselect = false;
76  defaultInput = false;
77  Name.append( n_in );
78  Display.append( d_in );
79  escape.append( e_in );
80  }
81  std::string Name; //menuname
82  std::string Display; //display string.
83  std::vector< mItem* >items; //items on the menu.
84  bool selected; //is an item selected?
85  mItem *iselected; //selected item in this menu
86  std::string escape; //escape string \n\r for enter
87  bool noescape; //escaping this menu not allowed
88  bool autoselect; //autoselect menuitem below
89  mItem *aselect; //item to autoselect
90  bool defaultInput; //enable defaultinput mItem below
91  mItem *idefaultInput; //if a menu item isn't selected while in a menu
92 //and the input isn't a menuitem name, sent it to this menuitem
93 //example usage: password menu, don't need to press 1 but you still can
94 };
95 
96 class commandI : public RText
97 {
98 private:
99 //new command interpretor
100 //static std::vector<coms *> commands; //our vector of POINTERS
101 //to encapsulated COM objects. (see top of this file)
102  coms * findCommand( const char *comm, int &sock_in );
103 //mud *World; //to print to the charactor - server object
104  menu *lastmenuadded;
105  std::vector< menu* >menus;
106  menu *menu_in; //menu currently in
107  std::vector< menu* >menustack; //stack menus
108 //for nested menus.
109  bool menumode;
110 //object *player; -- player object
111  std::string lastcommand;
112 public:
113  virtual ~commandI();
114  commandI();
115 //commandI(mud *mud_in);
116 //commandI(mud *mud_in, object *player_in);
117  bool console;
118  bool immortal;
119  static void keypress( int code, int modifiers, bool isDown, int x, int y );
120  bool getmenumode() const
121  {
122  return menumode;
123  }
124 //creates a coms object, adds it to the command vector
125 //if args is not supplied it assumes your function
126 //has no arguements (not even a void)
127  void help( std::string &d ); //help command, should read a help file
128  void addCommand( TFunctor *com, const char *name ); //add a downcasted Functor
129  void remCommand( char *name );
130  void remCommand( TFunctor *com ); //use this now if possible
131  void dummy( std::vector< std::string* > *d ); //{return;}; //first thing to be added to the vecto
132  void prompt();
133  void pcommands(); //lists all the commands to the socket
134 //commands.at(0), returned by findcommand if nothing els //is found.
135  bool execute( std::string *incommand, bool isDown, int sock_in = 0 );
136  bool fexecute( std::string *incommand, bool isDown, int sock_in = 0 );
137 //so far ONLY void XXX:XXX(bool *) is called even if isDown
138 //is false. Everything else is only called when isDown is true.
139 //Cube string stuff
140 //splits up input by line using strsep() (renamed for microsoft windows compatibility)
141  bool execCommand( std::string *string, bool isDown );
142  bool addMenu( menu *menu2add );
143  bool addMenuItem( mItem *mitem2add, menu* = NULL );
144 //the args added at addMenu are appended when the
145 //menuitem is called
146  bool callMenu( char *name, char *args, std::string &s2manip );
147  std::string setMenu( std::string name ); //force a menu set.
148  std::string displaymenu(); //utility to display the current menu
149  void breakmenu(); //utility to force a break from all menus
150  virtual std::string display( std::string &s ); //build parts
151 //of the menu, eg, if(s.compare("SHIPNAME") == 0 )return editingship->Name;
152 };
153 
155 {
156 public:
158  void runPy( std::string &argsin );
159 };
160 
161 enum
162 {
165 };
166 
167 namespace ConsoleKeys
168 {
169 extern void BringConsole( const KBData&, KBSTATE a );
170 }
171 //#include "areas.h"
172 #endif
173