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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CAudioMenuState
  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. CAudioMenuState *CAudioMenuState::m_instance = 0;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. CAudioMenuState::CAudioMenuState()
  24. {
  25. }
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. CAudioMenuState::~CAudioMenuState()
  30. {
  31. }
  32.  
  33. //-------------------------------------------------------------
  34.  
  35. CGameState *CAudioMenuState::instance()
  36. {
  37.     if (!m_instance)
  38.         m_instance = new CAudioMenuState;
  39.  
  40.     return m_instance;
  41. }
  42.  
  43. //-------------------------------------------------------------
  44.  
  45. void CAudioMenuState::copyOptionsToMenu()
  46. {
  47.     m_menu.setValue(OM_MUSIC        ,Options.getOption(OPTION_MUSIC));
  48.     m_menu.setValue(OM_SOUNDFX        ,Options.getOption(OPTION_SOUNDFX));
  49. }
  50.  
  51. //-------------------------------------------------------------
  52.  
  53. void CAudioMenuState::copyMenuToOptions()
  54. {
  55.     Options.setOption(OPTION_MUSIC        ,m_menu.getValue(OM_MUSIC));
  56.     Options.setOption(OPTION_SOUNDFX    ,m_menu.getValue(OM_SOUNDFX));
  57. }
  58.  
  59. //-------------------------------------------------------------
  60.  
  61. bool CAudioMenuState::create()
  62. {
  63.     m_menu.clear();
  64.  
  65.     m_menu.addSlider("   Music",10,0,10);
  66.     m_menu.addSlider("Sound FX",10,0,10);
  67.  
  68.     copyOptionsToMenu();
  69.  
  70.     m_menu.addSeperator();
  71.     m_menu.addSelection("Apply");
  72.     m_menu.addSelection("Cancel");
  73.  
  74.     m_menu.setWrap(true);
  75.     m_menu.setPosition(gsCPoint(0,150));
  76.     m_menu.setSpacing(gsCPoint(0,30));
  77.     m_menu.setCurrentItem(OM_CANCEL);
  78.     m_menu.setFont(&m_medium_font);
  79.  
  80.     return true;
  81. }
  82.  
  83. //-------------------------------------------------------------
  84.  
  85. bool CAudioMenuState::update()
  86. {
  87.     if (!CGameState::update())
  88.         return false;
  89.  
  90.     if (Options.getOption(OPTION_BACKDROP))
  91.         m_backdrop.draw(gsCPoint(0,0));
  92.     else
  93.         m_screen.clear(gsCColour(gsBLACK));
  94.  
  95.     m_starfield.move(4);
  96.     m_starfield.draw();
  97.  
  98.     m_medium_font.setTextCursor(gsCPoint(0,50));
  99.     m_medium_font.justifyString("Audio Options");
  100.  
  101.     m_menu.draw();
  102.     
  103.     m_screen.flip();
  104.  
  105.     AudioMenuItem item = (AudioMenuItem) m_menu.getCurrentItem();
  106.  
  107.     switch (getKey()) {
  108.         case gsKEY_RETURN:
  109.         case gsKEY_ENTER:
  110.         case gsKEY_LCONTROL:
  111.             if (item == OM_APPLY) {
  112.                 CGameState::playSample(SAMPLE_MENU_SELECTION);
  113.                 copyMenuToOptions();
  114.                 if (Options.areChanged()) {
  115.  
  116.                     gsCFile::setDirectory(DIRECTORY_ROOT);
  117.  
  118.                     Options.save(OPTIONS_FILENAME);
  119.  
  120.                     updateVolume();
  121.  
  122.                     if (Options.requireReload()) {
  123.                         CMessageBoxState::setup("Restart to apply options ?",
  124.                                                 "Yes",0,
  125.                                                 "No",COptionsMenuState::instance(),
  126.                                                 true);
  127.                         return changeState(CMessageBoxState::instance());
  128.                         }
  129.                     else
  130.                         return changeState(COptionsMenuState::instance());
  131.                     }
  132.                 else
  133.                     return changeState(COptionsMenuState::instance());
  134.                 }
  135.             else if (item == OM_CANCEL) {
  136.                 CGameState::playSample(SAMPLE_MENU_BACK);
  137.                 return changeState(COptionsMenuState::instance());
  138.                 }
  139.             break;
  140.         case gsKEY_UP:
  141.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  142.             m_menu.scroll(-1);
  143.             break;
  144.         case gsKEY_DOWN:
  145.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  146.             m_menu.scroll(1);
  147.             break;
  148.         case gsKEY_LEFT:
  149.             if (m_menu.setValue(item,m_menu.getValue(item) - 1))
  150.                 CGameState::playSample(SAMPLE_MENU_OPTION);
  151.             break;
  152.         case gsKEY_RIGHT:
  153.             if (m_menu.setValue(item,m_menu.getValue(item) + 1))
  154.                 CGameState::playSample(SAMPLE_MENU_OPTION);
  155.             break;
  156.         }
  157.  
  158.     return true;
  159. }
  160.  
  161. //-------------------------------------------------------------
  162.  
  163.