00001
00002
00003
00004
00005
00006
00007
00008
00009
00041 #ifndef MENU_H
00042 #define MENU_H
00043
00044 #include <SDL/SDL.h>
00045 #include <adsoio.h>
00046 #include <adsolua.h>
00047 #include "netlink.h"
00048 #include "net.h"
00049 #include "view.h"
00050
00051 #define MENU_MAX_VARIABLES 8
00052 #define MENU_MAX_CONDITIONS 8
00053
00054 #define MENU_COND_TESTMODE 0
00055 #define MENU_COND_NETLINK 1
00056 #define MENU_COND_CHGMODE 2
00057
00058 #define MISSION_PAGE 4
00059 #define DEATHMATCH_PAGE 8
00060 #define NET_PAGE 2
00061 #define LINK_PAGE 7
00062 #define NETBASE_WARNING_PAGE 5
00063 #define NETBASE_DETAILS_PAGE 6
00064
00065
00066 #define MEVENT_META 1024
00067 #define MEVENT_NETLINK_CONNECTED (MEVENT_META|1)
00068 #define MEVENT_NETLINK_CONNECT_FAIL (MEVENT_META|2)
00069 #define MEVENT_NET_UPDATE_ONLINETABLE (MEVENT_META|3)
00070 #define MEVENT_NET_UPDATE_SCORETEXT (MEVENT_META|4)
00071 #define MEVENT_NET_USERNAME_UPDATED (MEVENT_META|5)
00072 #define MEVENT_NET_USERNAME_FAILED (MEVENT_META|6)
00073 #define MEVENT_NET_GOT_USERNAME (MEVENT_META|7)
00074 #define MEVENT_ACCEPT_LINK (MEVENT_META|8)
00075
00076 class Menu : public AdsoLuaInterface, public Overlay, public KeyboardHandler {
00077
00078 struct MenuVariable {
00079 char name[16];
00080 char value[128];
00081 const char *boundValue;
00082 MenuVariable(){
00083 boundValue = 0;
00084 }
00085 };
00086
00087 int active;
00088 int page;
00089 float dimLevel;
00090 double print_time;
00091 double lastDrawTime;
00092 bool condition[MENU_MAX_CONDITIONS];
00093 int cursorLine, cursorColumn, cursorPage;
00094 int cursorLineSave, cursorColumnSave, cursorPageSave;
00095 int showCursor, largeCursor;
00096 float cursorTimer;
00097 int hboxLength, hboxLine, hboxColumn;
00098 int showHBox;
00099 int preScore, nameDialogState, linkDialogState;
00100 vector<DBOnlineEntry> *onlineDump;
00101 int linkSelect, drawOnlineDump;
00102 char userNameStr[16];
00103 int userNameCnt;
00104 char linkAddrStr[32];
00105 int linkAddrCnt;
00106 int netWarningReturnPage;
00107
00108 int translateKeys;
00109
00110 int nPages;
00111 char (*text)[40][80];
00112
00113 MenuVariable variables[MENU_MAX_VARIABLES];
00114 int variableCount;
00115
00116 void variableSubstitution(char *dst, char *src, int n);
00117 const char *variableLookup(char *name);
00118
00119 int luaCallback(lua_State *L, AdsoLuaUserData *ud);
00120 void luaSetupInterface(AdsoLua*);
00121
00122 public:
00123 AdsoLua menuCtrl;
00124 int event(int);
00125 bool onKeyEvent(SDLKey key);
00126 void show();
00127 void hide();
00128 void setPage(int p){ page = p; print_time = 0.0; }
00129 int getPage(){ return page; }
00130 void setCondition(int n, bool c){
00131 if(n>MENU_MAX_CONDITIONS || n<0) iFatal("Menu condtion number out of bounds");
00132 condition[n] = c;
00133 }
00134 int isHidden(){ return !active; }
00135 void draw();
00136 void setText(char *t);
00137
00139 void setPageText(const char *t, int page, int line);
00140 void clearPage(int page, int line, int count);
00141 void setVariable(char *name, const char *value);
00142 void bindVariable(char *name, const char *str);
00143 void setCursor(int p, int l, int c);
00144 void pushCursorPos(int p, int l, int c);
00145 void popCursorPos();
00146 void mprint(const char *fmt,...);
00147 Menu();
00148 };
00149
00150 extern Menu menu;
00151
00152 #endif
00153