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 
20 /////////////////////////////////////////////////////////////////////////////
21 // restrict_paths dialog
22 
restrict_paths(CWnd * pParent)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 
DoDataExchange(CDataExchange * pDX)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 
BEGIN_MESSAGE_MAP(restrict_paths,CDialog)37 BEGIN_MESSAGE_MAP(restrict_paths, CDialog)
38 	//{{AFX_MSG_MAP(restrict_paths)
39 	//}}AFX_MSG_MAP
40 END_MESSAGE_MAP()
41 
42 /////////////////////////////////////////////////////////////////////////////
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();
55 	theApp.init_window(&Player_wnd_data, this);
56 
57 	// set up gui
58 	reset_controls();
59 
60 	return TRUE;
61 }
62 
reset_controls()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
OnCancel()99 void restrict_paths::OnCancel()
100 {
101 	theApp.record_window_data(&Player_wnd_data, this);
102 	CDialog::OnCancel();
103 }
104 
105 // ok
OnOK()106 void restrict_paths::OnOK()
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 
128 	theApp.record_window_data(&Player_wnd_data, this);
129 	CDialog::OnOK();
130 }
131