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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CMessageBoxState
  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. CMessageBoxState *CMessageBoxState::m_instance = 0;
  20.  
  21. const char *CMessageBoxState::m_message = 0;
  22. const char *CMessageBoxState::m_yes_option = 0;
  23. const char *CMessageBoxState::m_no_option = 0;
  24. CGameState *CMessageBoxState::m_yes_state = 0;
  25. CGameState *CMessageBoxState::m_no_state = 0;
  26. bool CMessageBoxState::m_restart = false;
  27.  
  28. //-------------------------------------------------------------
  29.  
  30. CMessageBoxState::CMessageBoxState()
  31. {
  32. }
  33.  
  34. //-------------------------------------------------------------
  35.  
  36. CMessageBoxState::~CMessageBoxState()
  37. {
  38. }
  39.  
  40. //-------------------------------------------------------------
  41.  
  42. CGameState *CMessageBoxState::instance()
  43. {
  44.     if (!m_instance)
  45.         m_instance = new CMessageBoxState;
  46.  
  47.     return m_instance;
  48. }
  49.  
  50. //-------------------------------------------------------------
  51.  
  52. void CMessageBoxState::setup(const char *message,const char *yes_option,CGameState *yes_state,
  53.                              const char *no_option,CGameState *no_state,bool restart_on_yes)
  54. {
  55.     m_message = message;
  56.     m_yes_option = yes_option;
  57.     m_no_option = no_option;
  58.     m_yes_state = yes_state;
  59.     m_no_state = no_state;
  60.     m_restart = restart_on_yes;
  61. }
  62.  
  63. //-------------------------------------------------------------
  64.  
  65. bool CMessageBoxState::create()
  66. {
  67.     m_menu.clear();
  68.  
  69.     m_menu.addSelection(m_yes_option);
  70.  
  71.     if (m_no_option)
  72.         m_menu.addSelection(m_no_option);
  73.  
  74.     m_menu.setWrap(true);
  75.     m_menu.setPosition(gsCPoint(0,150));
  76.     m_menu.setSpacing(gsCPoint(0,30));
  77.     m_menu.setCurrentItem(MB_YES);
  78.     m_menu.setFont(&m_medium_font);
  79.  
  80.     return true;
  81. }
  82.  
  83. //-------------------------------------------------------------
  84.  
  85. bool CMessageBoxState::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(m_message);
  100.  
  101.     m_menu.draw();
  102.     
  103.     m_screen.flip();
  104.  
  105.     MessageBoxItem item = (MessageBoxItem) m_menu.getCurrentItem();
  106.  
  107.     switch (getKey()) {
  108.         case gsKEY_RETURN:
  109.         case gsKEY_ENTER:
  110.         case gsKEY_LCONTROL:
  111.             if (item == MB_YES) {
  112.                 if (m_yes_state)
  113.                     return changeState(m_yes_state);
  114.                 else {
  115.                     if (m_restart)
  116.                         gsCApplication::requestRestart();
  117.                     return false;
  118.                     }
  119.                 }
  120.             if (item == MB_NO) {
  121.                 if (m_no_state)
  122.                     return changeState(m_no_state);
  123.                 else
  124.                     return false;
  125.                 }
  126.             break;
  127.         case gsKEY_UP:
  128.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  129.             m_menu.scroll(-1);
  130.             break;
  131.         case gsKEY_DOWN:
  132.             CGameState::playSample(SAMPLE_MENU_SELECTION);
  133.             m_menu.scroll(1);
  134.             break;
  135.         }
  136.  
  137.     return true;
  138. }
  139.  
  140. //-------------------------------------------------------------
  141.