home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / RandomProps.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-16  |  3.1 KB  |  139 lines

  1. #include "stdafx.h"
  2. #include "RandomProps.h"
  3.  
  4. int random_placement_platform = 140, random_placement_any = 150, random_placement_on = 50,
  5.     random_placement_between = 0, random_placement_under = 20;    
  6.  
  7. static int random_object = 0;
  8.  
  9. CRandomProps::CRandomProps(CWnd* pParent)
  10.     : CDialog(CRandomProps::IDD, pParent)
  11. {
  12.     //{{AFX_DATA_INIT(CRandomProps)
  13.     //}}AFX_DATA_INIT
  14. }
  15.  
  16. void CRandomProps::DoDataExchange(CDataExchange* pDX)
  17. {
  18.     CDialog::DoDataExchange(pDX);
  19.     //{{AFX_DATA_MAP(CRandomProps)
  20.     DDX_Control(pDX, IDC_RANDPROPS_UNDER, m_Under);
  21.     DDX_Control(pDX, IDC_RANDPROPS_PLATFORM, m_Platform);
  22.     DDX_Control(pDX, IDC_RANDPROPS_ON, m_On);
  23.     DDX_Control(pDX, IDC_RANDPROPS_BETWEEN, m_Between);
  24.     DDX_Control(pDX, IDC_RANDPROPS_ANY, m_Any);
  25.     DDX_Control(pDX, IDC_RANDOMPROPS_SLIDER, m_Slider);
  26.     DDX_Control(pDX, IDC_RANDOMPROPS_LIST, m_List);
  27.     //}}AFX_DATA_MAP
  28. }
  29.  
  30. BEGIN_MESSAGE_MAP(CRandomProps, CDialog)
  31.     //{{AFX_MSG_MAP(CRandomProps)
  32.     ON_LBN_SELCHANGE(IDC_RANDOMPROPS_LIST, OnSelchangeRandompropsList)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. static char *place(tplacement p)
  37. {
  38.     switch(p)
  39.     {
  40.     case PLACEMENT_ANY:
  41.         return "ANY";
  42.  
  43.     case PLACEMENT_PLATFORM:
  44.         return "PLATFORM";
  45.  
  46.     case PLACEMENT_ON_PLATFORM:
  47.         return "ON PLATFORM";
  48.  
  49.     case PLACEMENT_BETWEEN_PLATFORMS:
  50.         return "BETWEEN PLATFORMS";
  51.  
  52.     case PLACEMENT_UNDER_PLATFORM:
  53.         return "UNDER PLATFORM";
  54.     }
  55.  
  56.     return 0;
  57. }
  58.  
  59. BOOL CRandomProps::OnInitDialog() 
  60. {
  61.     CDialog::OnInitDialog();
  62.  
  63.     m_Platform.SetRange(0, 300);
  64.     m_Platform.SetTicFreq(100);
  65.     m_Platform.SetPos(random_placement_platform);
  66.  
  67.     m_Any.SetRange(0, 300);
  68.     m_Any.SetTicFreq(100);
  69.     m_Any.SetPos(random_placement_any);
  70.  
  71.     m_On.SetRange(0, 300);
  72.     m_On.SetTicFreq(100);
  73.     m_On.SetPos(random_placement_on);
  74.  
  75.     m_Between.SetRange(0, 300);
  76.     m_Between.SetTicFreq(100);
  77.     m_Between.SetPos(random_placement_between);
  78.  
  79.     m_Under.SetRange(0, 300);
  80.     m_Under.SetTicFreq(100);
  81.     m_Under.SetPos(random_placement_under);        
  82.  
  83.     for (cProperties *p = props; p != 0; p = (cProperties *)p->next)
  84.         if (p->placement != PLACEMENT_NEVER)
  85.         {
  86.             int i = m_List.AddString(construct("%s / %s / %s", place(p->placement), p->type, p->name));
  87.             m_List.SetItemDataPtr(i, p);
  88.         }
  89.  
  90.     m_List.SetCurSel(random_object);
  91.  
  92.     SetSlider();
  93.     
  94.     return TRUE;
  95. }
  96.  
  97. void CRandomProps::OnOK() 
  98. {
  99.     random_placement_platform = m_Platform.GetPos();
  100.     random_placement_any = m_Any.GetPos();
  101.     random_placement_on = m_On.GetPos();
  102.     random_placement_between = m_Between.GetPos();
  103.     random_placement_under = m_Under.GetPos();
  104.  
  105.     AcceptSliders();
  106.     
  107.     CDialog::OnOK();
  108. }
  109.  
  110. void CRandomProps::OnSelchangeRandompropsList() 
  111. {
  112.     AcceptSliders();
  113.  
  114.     SetSlider();
  115. }
  116.  
  117. void CRandomProps::SetSlider()
  118. {
  119.     // Set slider range
  120.  
  121.     m_Slider.SetRange(0, 1000);
  122.     m_Slider.SetTicFreq(100);
  123.  
  124.     // Get selected object
  125.  
  126.     random_object = m_List.GetCurSel();
  127.  
  128.     // Set slider value
  129.  
  130.     m_Slider.SetPos(((cProperties *)m_List.GetItemDataPtr(random_object))->occurence);
  131. }
  132.  
  133. void CRandomProps::AcceptSliders()
  134. {    
  135.     // Save slider value
  136.  
  137.     ((cProperties *)m_List.GetItemDataPtr(random_object))->occurence = m_Slider.GetPos();
  138. }
  139.