FS2_Open
Open source remastering of the Freespace 2 engine
restrictpaths.cpp
Go to the documentation of this file.
1 /*
2  * Created by Ian "Goober5000" Warfield for the FreeSpace2 Source Code Project.
3  * You may not sell or otherwise commercially exploit the source or things you
4  * create based on the source.
5  */
6 
7 
8 
9 #include "stdafx.h"
10 #include "FRED.h"
11 #include "restrictpaths.h"
12 #include "ship/ship.h"
13 #include "model/model.h"
14 
15 #ifdef _DEBUG
16 #undef THIS_FILE
17 static char THIS_FILE[] = __FILE__;
18 #endif
19 
21 // restrict_paths dialog
22 
23 restrict_paths::restrict_paths(CWnd* pParent) : CDialog(restrict_paths::IDD, pParent)
24 {
25  //{{AFX_DATA_INIT(restrict_paths)
26  //}}AFX_DATA_INIT
27 }
28 
29 void restrict_paths::DoDataExchange(CDataExchange* pDX)
30 {
31  CDialog::DoDataExchange(pDX);
32  //{{AFX_DATA_MAP(restrict_paths)
33  DDX_Control(pDX, IDC_PATH_LIST, m_path_list);
34  //}}AFX_DATA_MAP
35 }
36 
37 BEGIN_MESSAGE_MAP(restrict_paths, CDialog)
38  //{{AFX_MSG_MAP(restrict_paths)
39  //}}AFX_MSG_MAP
40 END_MESSAGE_MAP()
41 
43 // restrict_paths message handlers
44 
45 BOOL restrict_paths::OnInitDialog()
46 {
47  // get stuff from params
48  m_model = model_get(Ship_info[m_ship_class].model_num);
49  Assert(m_model->ship_bay);
50  m_num_paths = m_model->ship_bay->num_paths;
51  Assert(m_num_paths > 0);
52 
53  // misc window crap
54  CDialog::OnInitDialog();
56 
57  // set up gui
58  reset_controls();
59 
60  return TRUE;
61 }
62 
63 void restrict_paths::reset_controls()
64 {
65  int i;
66  BOOL allowed;
67 
68  // initialize checkbox
69  m_path_list.ResetContent();
70  for (i = 0; i < m_num_paths; i++)
71  {
72  // add name
73  m_path_list.AddString(m_model->paths[m_model->ship_bay->path_indexes[i]].name);
74 
75  // toggle according to mask
76  if (m_path_mask == 0)
77  allowed = TRUE;
78  else
79  allowed = (*m_path_mask & (1 << i)) ? TRUE : FALSE;
80 
81  m_path_list.SetCheck(i, allowed);
82  }
83 
84  // set up the label
85  CStatic *label = (CStatic *) GetDlgItem(IDC_RESTRICT_PATHS_LABEL);
86  if (m_arrival)
87  label->SetWindowText("Restrict arrival paths to the following:");
88  else
89  label->SetWindowText("Restrict departure paths to the following:");
90 
91  // be sure that nothing is selected
92  m_path_list.SetCurSel(-1);
93 
94  // store stuff to gui
95  UpdateData(FALSE);
96 }
97 
98 // cancel
100 {
102  CDialog::OnCancel();
103 }
104 
105 // ok
107 {
108  int i, num_allowed = 0;
109 
110  // grab stuff from GUI
111  UpdateData(TRUE);
112 
113  // store mask data
114  *m_path_mask = 0;
115  for (i = 0; i < m_num_paths; i++)
116  {
117  if (m_path_list.GetCheck(i))
118  {
119  *m_path_mask |= (1 << i);
120  num_allowed++;
121  }
122  }
123 
124  // if all allowed, mask is 0
125  if (num_allowed == m_num_paths)
126  *m_path_mask = 0;
127 
129  CDialog::OnOK();
130 }
void record_window_data(window_data *wndd, CWnd *wnd)
Definition: fred.cpp:670
int i
Definition: multi_pxo.cpp:466
CFREDApp theApp
Definition: fred.cpp:115
polymodel * model_get(int model_num)
Definition: modelread.cpp:3134
CCheckListBox m_path_list
Definition: restrictpaths.h:30
Assert(pm!=NULL)
int init_window(window_data *wndd, CWnd *wnd, int adjust=0, int pre=0)
Definition: fred.cpp:639
virtual void DoDataExchange(CDataExchange *pDX)
#define TRUE
Definition: pstypes.h:399
ship_bay_t * ship_bay
Definition: model.h:776
#define IDC_PATH_LIST
Definition: resource.h:1126
char name[MAX_NAME_LEN]
Definition: model.h:415
restrict_paths(CWnd *pParent=NULL)
int BOOL
Definition: config.h:80
const char * label
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
#define IDC_RESTRICT_PATHS_LABEL
Definition: resource.h:1125
model_path * paths
Definition: model.h:784
int model_num
Definition: lua.cpp:4996
#define FALSE
Definition: pstypes.h:400
window_data Player_wnd_data
Definition: fred.cpp:67
int path_indexes[MAX_SHIP_BAY_PATHS]
Definition: model.h:541