home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / xenon / source / controlmenustate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-13  |  5.8 KB  |  207 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CControlMenuState
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CGameState
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. CControlMenuState *CControlMenuState::m_instance = 0;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. CControlMenuState::CControlMenuState()
  24. {
  25. }
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. CControlMenuState::~CControlMenuState()
  30. {
  31. }
  32.  
  33. //-------------------------------------------------------------
  34.  
  35. CGameState *CControlMenuState::instance()
  36. {
  37.     if (!m_instance)
  38.         m_instance = new CControlMenuState;
  39.  
  40.     return m_instance;
  41. }
  42.  
  43. //-------------------------------------------------------------
  44.  
  45. void CControlMenuState::copyOptionsToMenu()
  46. {
  47.     m_menu.setValue(CM_CONTROL1    ,Options.getOption(OPTION_CONTROL1));
  48.     m_menu.setValue(CM_CONTROL2    ,Options.getOption(OPTION_CONTROL2));
  49. }
  50.  
  51. //-------------------------------------------------------------
  52.  
  53. void CControlMenuState::copyMenuToOptions()
  54. {
  55.     Options.setOption(OPTION_CONTROL1    ,m_menu.getValue(CM_CONTROL1));
  56.     Options.setOption(OPTION_CONTROL2    ,m_menu.getValue(CM_CONTROL2));
  57. }
  58.  
  59. //-------------------------------------------------------------
  60.  
  61. bool CControlMenuState::create()
  62. {
  63.     m_menu.clear();
  64.  
  65. //    m_menu.addOptionList("Player 1","Keyboard Layout A","Keyboard Layout B","Joystick 1","Joystick 2",0);
  66. //    m_menu.addOptionList("Player 2","Keyboard Layout A","Keyboard Layout B","Joystick 1","Joystick 2",0);
  67.  
  68.     m_menu.addOptionList("Player 1","Keyboard Layout A","Keyboard Layout B",0);
  69.     m_menu.addOptionList("Player 2","Keyboard Layout A","Keyboard Layout B",0);
  70.  
  71.     m_menu.addSeperator();
  72.     m_menu.addSelection("Apply");
  73.     m_menu.addSelection("Cancel");
  74.  
  75.     m_menu.setWrap(true);
  76.     m_menu.setPosition(gsCPoint(0,100));
  77.     m_menu.setSpacing(gsCPoint(0,30));
  78.     m_menu.setCurrentItem(CM_CANCEL);
  79.     m_menu.setFont(&m_medium_font);
  80.  
  81.     copyOptionsToMenu();
  82.  
  83.     return true;
  84. }
  85.  
  86. //-------------------------------------------------------------
  87.  
  88. bool CControlMenuState::update()
  89. {
  90.     const char *move_names[4] = { "Cursor Keys", "Cursor Keys","Joystick 1","Joystick 2" };
  91.     const char *fire_names[4] = { "Left Control","A","Button 0","Button 0" };
  92.     const char *rev_names[4]  = { "Left Alt",    "S","Button 1","Button 1" };
  93.     const char *dive_names[4] = { "Left Shift",  "D","Button 2","Button 2" };
  94.  
  95.     if (!CGameState::update())
  96.         return false;
  97.  
  98.     if (Options.getOption(OPTION_BACKDROP))
  99.         m_backdrop.draw(gsCPoint(0,0));
  100.     else
  101.         m_screen.clear(gsCColour(gsBLACK));
  102.  
  103.     m_starfield.move(4);
  104.     m_starfield.draw();
  105.  
  106.     m_medium_font.setTextCursor(gsCPoint(0,50));
  107.     m_medium_font.justifyString("Control Options");
  108.  
  109.     m_menu.draw();
  110.  
  111.     m_small_font.setTextCursor(gsCPoint(200,300));
  112.     m_small_font.printString("Player 1");
  113.     m_small_font.setTextCursor(gsCPoint(400,300));
  114.     m_small_font.printString("Player 2");
  115.  
  116.     m_small_font.setTextCursor(gsCPoint(50,330));
  117.     m_small_font.printString("Movement:");
  118.     m_small_font.setTextCursor(gsCPoint(50,350));
  119.     m_small_font.printString("Fire:");
  120.     m_small_font.setTextCursor(gsCPoint(50,370));
  121.     m_small_font.printString("Reverse:");
  122.     m_small_font.setTextCursor(gsCPoint(50,390));
  123.     m_small_font.printString("Dive:");
  124.  
  125.     int control1 = m_menu.getValue(CM_CONTROL1);
  126.  
  127.     m_small_font.setTextCursor(gsCPoint(200,330));
  128.     m_small_font.printString(move_names[control1]);
  129.     m_small_font.setTextCursor(gsCPoint(200,350));
  130.     m_small_font.printString(fire_names[control1]);
  131.     m_small_font.setTextCursor(gsCPoint(200,370));
  132.     m_small_font.printString(rev_names[control1]);
  133.     m_small_font.setTextCursor(gsCPoint(200,390));
  134.     m_small_font.printString(dive_names[control1]);
  135.  
  136.     int control2 = m_menu.getValue(CM_CONTROL2);
  137.  
  138.     m_small_font.setTextCursor(gsCPoint(400,330));
  139.     m_small_font.printString(move_names[control2]);
  140.     m_small_font.setTextCursor(gsCPoint(400,350));
  141.     m_small_font.printString(fire_names[control2]);
  142.     m_small_font.setTextCursor(gsCPoint(400,370));
  143.     m_small_font.printString(rev_names[control2]);
  144.     m_small_font.setTextCursor(gsCPoint(400,390));
  145.     m_small_font.printString(dive_names[control2]);
  146.  
  147.     m_screen.flip();
  148.  
  149.     ControlMenuItem item = (ControlMenuItem) m_menu.getCurrentItem();
  150.  
  151.     switch (getKey()) {
  152.         case gsKEY_RETURN:
  153.         case gsKEY_ENTER:
  154.         case gsKEY_LCONTROL:
  155.             if (item == CM_APPLY) {
  156.                 CGameState::playSample(SAMPLE_MENU_SELECTION);
  157.                 copyMenuToOptions();
  158.                 if (Options.areChanged()) {
  159.  
  160.                     gsCFile::setDirectory(DIRECTORY_ROOT);
  161.  
  162.                     Options.save(OPTIONS_FILENAME);
  163.  
  164.                     updateVolume();
  165.  
  166.                     if (Options.requireReload()) {
  167.                         CMessageBoxState::setup("Restart to apply options ?",
  168.                                                 "Yes",0,
  169.                                                 "No",COptionsMenuState::instance(),
  170.                                                 true);
  171.                         return changeState(CMessageBoxState::instance());
  172.                         }
  173.                     else
  174.                         return changeState(COptionsMenuState::instance());
  175.                     }
  176.                 else
  177.                     return changeState(COptionsMenuState::instance());
  178.                 }
  179.             else if (item == CM_CANCEL) {
  180.                 CGameState::playSample(SAMPLE_MENU_BACK);
  181.                 return changeState(COptionsMenuState::instance());
  182.                 }
  183.             break;
  184.         case gsKEY_UP:
  185.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  186.             m_menu.scroll(-1);
  187.             break;
  188.         case gsKEY_DOWN:
  189.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  190.             m_menu.scroll(1);
  191.             break;
  192.         case gsKEY_LEFT:
  193.             if (m_menu.setValue(item,m_menu.getValue(item) - 1))
  194.                 CGameState::playSample(SAMPLE_MENU_OPTION);
  195.             break;
  196.         case gsKEY_RIGHT:
  197.             if (m_menu.setValue(item,m_menu.getValue(item) + 1))
  198.                 CGameState::playSample(SAMPLE_MENU_OPTION);
  199.             break;
  200.         }
  201.  
  202.     return true;
  203. }
  204.  
  205. //-------------------------------------------------------------
  206.  
  207.