GAMEMENU.CPP 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #include "gui.h"
  2. #include "gfx.h"
  3. class PageTextButton : public Button
  4. {
  5. char *zText;
  6. int nFont;
  7. uchar uForeHue;
  8. uchar uBackHue;
  9. public:
  10. PageTextButton( int left, int top, int width, int height, char *text, CLICK_PROC clickProc ) :
  11. Button( left, top, width, height, clickProc),
  12. zText(text), nFont(0), uForeHue(31), uBackHue(-1) { canFocus = TRUE; };
  13. SetHue( int foreHue, int backHue );
  14. virtual void Paint( int x, int y, BOOL hasFocus );
  15. };
  16. virtual void PageTextButton::Paint( int x, int y, BOOL hasFocus )
  17. {
  18. gfxDrawText( x, y, uForeHue, zText, NULL );
  19. }
  20. class PageButton : public Button
  21. {
  22. int nTile;
  23. public:
  24. virtual void Paint( int x, int y, BOOL hasFocus );
  25. // assumes nTile + 1 is focus state bitmap
  26. PageButton( int top, int left, int width, int height, int nTile, CLICK_PROC clickProc ) :
  27. Button( int top, int left ) { canFocus = TRUE; };
  28. };
  29. PageButton::PageButton( int top, int left, RESHANDLE hBitmap1,
  30. RESHANDLE hBitmap1, CLICK_PROC clickProc ) :
  31. Button( left, top, width, height, clickProc), hBitmap(hBitmap), text(NULL) {};
  32. {
  33. }
  34. PageButton::PageButton( int top, int left, char *text, CLICK_PROC clickProc ) :
  35. Button( int left, int top, int width, int height, CLICK_PROC clickProc ):
  36. Button(left, top, width, height, result), text(text)
  37. {
  38. }
  39. virtual void PageButton::Paint( int x, int y, BOOL hasFocus )
  40. {
  41. if (text != NULL
  42. }
  43. class PageBook : public Container
  44. {
  45. protected:
  46. Container *focusPage;
  47. public:
  48. PageBook( int top, int left, int width, int height );
  49. ~PageBook();
  50. virtual BOOL SetFocus( int dir );
  51. virtual MODAL_RESULT HandleKey( BYTE key );
  52. // virtual MODAL_RESULT HandleMouse( MEVENT event );
  53. };
  54. PageBook::PageBook( int top, int left, int width, int height )
  55. {
  56. focusPage = NULL;
  57. }
  58. virtual BOOL PageBook::SetFocus( int dir )
  59. {
  60. do
  61. {
  62. if (focus->isContainer)
  63. {
  64. if ( ((Container *)focus)->SetFocus(dir) )
  65. return TRUE;
  66. }
  67. if (dir > 0)
  68. focus = focus->next;
  69. else
  70. focus = focus->prev;
  71. if (focus == &head)
  72. return FALSE;
  73. } while (!focus->canFocus);
  74. return TRUE;
  75. }
  76. virtual MODAL_RESULT PageBook::HandleKey( BYTE key )
  77. {
  78. switch (key)
  79. {
  80. case KEY_UP:
  81. break;
  82. case KEY_DOWN:
  83. break;
  84. case KEY_ESC:
  85. break;
  86. default:
  87. {
  88. char c;
  89. if (keystatus[KEY_LSHIFT] || keystatus[KEY_RSHIFT])
  90. c = ScanToAsciiShifted[key];
  91. else
  92. c = ScanToAscii[key];
  93. if ( c != 0 )
  94. {
  95. // read through the MenuLine hotkeys
  96. }
  97. break;
  98. }
  99. }
  100. return mrNone;
  101. }
  102. ShowMenu( Container *dialog )
  103. {
  104. BYTE key;
  105. MODAL_RESULT result = mrNone;
  106. Container desktop(0, 0, xdim, ydim);
  107. desktop.Insert(dialog);
  108. // find first item for focus
  109. while (!desktop.SetFocus(+1));
  110. while ( (key = keyGet()) != 0 )
  111. {
  112. switch (key)
  113. {
  114. case KEY_ESC:
  115. keystatus[KEY_ESC] = 0; // some of Ken's stuff still checks this!
  116. result = mrCancel;
  117. break;
  118. case KEY_ENTER:
  119. result = mrOk;
  120. break;
  121. case KEY_TAB:
  122. if (keystatus[KEY_LSHIFT] || keystatus[KEY_RSHIFT])
  123. while (!desktop.SetFocus(-1));
  124. else
  125. while (!desktop.SetFocus(+1));
  126. break;
  127. default:
  128. result = desktop.HandleKey(key);
  129. }
  130. }
  131. desktop.Paint(0, 0, FALSE);
  132. // draw cursors
  133. desktop.Remove(dialog);
  134. return result;
  135. }
  136. ///////////////////////////////////////////
  137. enum MOBTYPE {
  138. MOBTYPE_Menu,
  139. MOBTYPE_Button,
  140. MOBTYPE_HSlider
  141. };
  142. struct MOBFLAGS {
  143. ushort disabled : 1;
  144. ushort invisible : 1;
  145. ushort pad : 14;
  146. };
  147. struct MenuObject {
  148. MOBTYPE type;
  149. void *object;
  150. MOBFLAGS flags;
  151. };
  152. class HSlider
  153. {
  154. private:
  155. protected:
  156. public:
  157. HSlider( void );
  158. ~HSlider();
  159. void Draw( void );
  160. };
  161. class GameMenu
  162. {
  163. private:
  164. MenuObject *head;
  165. protected:
  166. public:
  167. GameMenu( void );
  168. ~GameMenu();
  169. void Draw( void );
  170. void AddButton( char *text, void (*MenuProc)( void ) );
  171. void AddButton( char *text, GameMenu &subMenu );
  172. void AddHSlider( char *text, HSlider &theSlider );
  173. void AddSpace( void );
  174. };
  175. // draw the
  176. void GameMenu::Draw( void )
  177. {
  178. }
  179. GameMenu gMainMenu;
  180. GameMenu gOptMenu;
  181. GameMenu gSoundMenu;
  182. GameMenu gSwitchMenu;
  183. //
  184. // Global menu objects initialized in main() in BLOOD.C
  185. //
  186. void InitMenus( void )
  187. {
  188. gMainMenu.AddButton( "New Game", menuNewGame );
  189. gMainMenu.AddButton( "Load Game", menuLoadGame );
  190. gMainMenu.AddButton( "Save Game", menuSaveGame );
  191. gMainMenu.AddButton( "Options", gOptMenu );
  192. gMainMenu.AddButton( "Order Info", menuOrderInfo );
  193. gMainMenu.AddButton( "Quit", menuQuit );
  194. gOptMenu.AddButton( "End Game" );
  195. gOptMenu.AddHSlider( "Detail", SliderDrawDetail );
  196. gOptMenu.AddHSlider( "Mouse Sensitivity", SliderDrawMouse );
  197. gOptMenu.AddSpace();
  198. gOptMenu.AddButton( "Sound Volume", gSoundMenu );
  199. gOptMenu.AddButton( "Game Toggles", gSwitchMenu );
  200. gSoundMenu.AddHSlider( "FX Volume", SliderDrawFXVolume );
  201. gSoundMenu.AddSpace();
  202. gSoundMenu.AddHSlider( "Music Volume", SliderDrawMusicVolume );
  203. gSoundMenu.AddSpace();
  204. gSwitchMenu.AddButton( "Mouse", menuMouseToggle );
  205. gSwitchMenu.AddButton( "Joystick", menuJoyToggle );
  206. gSwitchMenu.AddButton( "Bobbing", menuBobToggle );
  207. gSwitchMenu.AddButton( "Detail", menuDetailToggle );
  208. }
  209. //
  210. // Draw method for global menu object called in DrawScreen in BLOOD.C
  211. //
  212. //void DrawScreen( void )
  213. //{
  214. // ...
  215. //
  216. // if ( bMenuUp )
  217. // bMenuUp = (ShowMenu() == mrNone);
  218. // //LocalKeys should set bMenuUp => TRUE
  219. // scrSetDac(gFrameTicks); // this could be a problem for menus
  220. // scrNextPage();
  221. //}
  222. void OptionClick( Widget* /* widget */ )
  223. {
  224. gGameMenuNotebook.SetPage(kPageOptionMenu);
  225. }
  226. gGameMenuNotebook.Insert(gMainPage);
  227. gGameMenuNotebook.Insert(gOptionPage);
  228. gGameMenuNotebook.Insert(gSoundPage);
  229. gMainPage.Insert(new MenuLine("Options", OptionClick));