home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / ScriptTest / ScriptTestDlg.cpp < prev    next >
C/C++ Source or Header  |  2002-06-19  |  5KB  |  209 lines

  1. // ScriptTestDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ScriptTest.h"
  6. #include "ScriptTestDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CAboutDlg dialog used for App About
  17.  
  18. class CAboutDlg : public CDialog
  19. {
  20. public:
  21.     CAboutDlg();
  22.  
  23. // Dialog Data
  24.     //{{AFX_DATA(CAboutDlg)
  25.     enum { IDD = IDD_ABOUTBOX };
  26.     //}}AFX_DATA
  27.  
  28.     // ClassWizard generated virtual function overrides
  29.     //{{AFX_VIRTUAL(CAboutDlg)
  30.     protected:
  31.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  32.     //}}AFX_VIRTUAL
  33.  
  34. // Implementation
  35. protected:
  36.     //{{AFX_MSG(CAboutDlg)
  37.     //}}AFX_MSG
  38.     DECLARE_MESSAGE_MAP()
  39. };
  40.  
  41. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  42. {
  43.     //{{AFX_DATA_INIT(CAboutDlg)
  44.     //}}AFX_DATA_INIT
  45. }
  46.  
  47. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CAboutDlg)
  51.     //}}AFX_DATA_MAP
  52. }
  53.  
  54. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  55.     //{{AFX_MSG_MAP(CAboutDlg)
  56.         // No message handlers
  57.     //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CScriptTestDlg dialog
  62.  
  63. CScriptTestDlg::CScriptTestDlg(CWnd* pParent /*=NULL*/)
  64.     : CDialog(CScriptTestDlg::IDD, pParent)
  65. {
  66.     //{{AFX_DATA_INIT(CScriptTestDlg)
  67.         // NOTE: the ClassWizard will add member initialization here
  68.     //}}AFX_DATA_INIT
  69.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  70.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  71.     m_pScript = 0;
  72. }
  73.  
  74. void CScriptTestDlg::DoDataExchange(CDataExchange* pDX)
  75. {
  76.     CDialog::DoDataExchange(pDX);
  77.     //{{AFX_DATA_MAP(CScriptTestDlg)
  78.     DDX_Control(pDX, IDC_SPIN_PLAYER_STRENGTH, m_PlayerStrength);
  79.     DDX_Control(pDX, IDC_SPIN_MONSTER_STRENGTH, m_MonsterStrength);
  80.     //}}AFX_DATA_MAP
  81. }
  82.  
  83. BEGIN_MESSAGE_MAP(CScriptTestDlg, CDialog)
  84.     //{{AFX_MSG_MAP(CScriptTestDlg)
  85.     ON_WM_SYSCOMMAND()
  86.     ON_WM_PAINT()
  87.     ON_WM_QUERYDRAGICON()
  88.     ON_WM_DESTROY()
  89.     ON_BN_CLICKED(IDC_ENCOUNTER_MONSTER, OnEncounterMonster)
  90.     //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CScriptTestDlg message handlers
  95.  
  96. BOOL CScriptTestDlg::OnInitDialog()
  97. {
  98.     CDialog::OnInitDialog();
  99.  
  100.     // Add "About..." menu item to system menu.
  101.  
  102.     // IDM_ABOUTBOX must be in the system command range.
  103.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  104.     ASSERT(IDM_ABOUTBOX < 0xF000);
  105.  
  106.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  107.     if (pSysMenu != NULL)
  108.     {
  109.         CString strAboutMenu;
  110.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  111.         if (!strAboutMenu.IsEmpty())
  112.         {
  113.             pSysMenu->AppendMenu(MF_SEPARATOR);
  114.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  115.         }
  116.     }
  117.  
  118.     // Set the icon for this dialog.  The framework does this automatically
  119.     //  when the application's main window is not a dialog
  120.     SetIcon(m_hIcon, TRUE);            // Set big icon
  121.     SetIcon(m_hIcon, FALSE);        // Set small icon
  122.     
  123.     m_MonsterStrength.SetRange(1, 5);
  124.     m_MonsterStrength.SetPos(1);
  125.     m_PlayerStrength.SetRange(1, 5);
  126.     m_PlayerStrength.SetPos(1);
  127.  
  128.     AudioMgrInit init;
  129.     init.m_hWnd = ::AfxGetMainWnd()->GetSafeHwnd();
  130.     AudioMgr()->Init(init);
  131.  
  132.     if(!AudioMgr()->CreateAudioScript(m_pScript))
  133.         AfxMessageBox("Could not create audio script");
  134.     AudioScriptInit asinit;
  135.     asinit.m_bMusic = false;
  136.     asinit.m_sFileName = "..\\data\\dmscript\\Voice Script.spt";
  137.     m_pScript->Init(asinit);
  138.     m_pScript->Load();
  139.     
  140.     m_pScript->SetVariable("PlayerStrength", 3);
  141.     m_pScript->SetVariable("MonsterStrength", 3);
  142.  
  143.     return TRUE;  // return TRUE  unless you set the focus to a control
  144. }
  145.  
  146. void CScriptTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  147. {
  148.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  149.     {
  150.         CAboutDlg dlgAbout;
  151.         dlgAbout.DoModal();
  152.     }
  153.     else
  154.     {
  155.         CDialog::OnSysCommand(nID, lParam);
  156.     }
  157. }
  158.  
  159. // If you add a minimize button to your dialog, you will need the code below
  160. //  to draw the icon.  For MFC applications using the document/view model,
  161. //  this is automatically done for you by the framework.
  162.  
  163. void CScriptTestDlg::OnPaint() 
  164. {
  165.     if (IsIconic())
  166.     {
  167.         CPaintDC dc(this); // device context for painting
  168.  
  169.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  170.  
  171.         // Center icon in client rectangle
  172.         int cxIcon = GetSystemMetrics(SM_CXICON);
  173.         int cyIcon = GetSystemMetrics(SM_CYICON);
  174.         CRect rect;
  175.         GetClientRect(&rect);
  176.         int x = (rect.Width() - cxIcon + 1) / 2;
  177.         int y = (rect.Height() - cyIcon + 1) / 2;
  178.  
  179.         // Draw the icon
  180.         dc.DrawIcon(x, y, m_hIcon);
  181.     }
  182.     else
  183.     {
  184.         CDialog::OnPaint();
  185.     }
  186. }
  187.  
  188. // The system calls this to obtain the cursor to display while the user drags
  189. //  the minimized window.
  190. HCURSOR CScriptTestDlg::OnQueryDragIcon()
  191. {
  192.     return (HCURSOR) m_hIcon;
  193. }
  194.  
  195. void CScriptTestDlg::OnDestroy() 
  196. {
  197.     CDialog::OnDestroy();
  198.     
  199.     AudioMgr()->Term();
  200.     
  201. }
  202.  
  203. void CScriptTestDlg::OnEncounterMonster() 
  204. {
  205.     m_pScript->SetVariable("PlayerStrength", m_PlayerStrength.GetPos());
  206.     m_pScript->SetVariable("MonsterStrength", m_MonsterStrength.GetPos());
  207.     m_pScript->CallRoutine("EncounterMonster");
  208. }
  209.