FS2_Open
Open source remastering of the Freespace 2 engine
ignoreordersdlg.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "stdafx.h"
13 #include "FRED.h"
14 #include "IgnoreOrdersDlg.h"
15 #include "hud/hudsquadmsg.h" // need this for the menu stuff
16 #include "globalincs/linklist.h"
17 
18 #ifdef _DEBUG
19 #undef THIS_FILE
20 static char THIS_FILE[] = __FILE__;
21 #endif
22 
23 // super cool macro to make IDC_* names
24 
26 // ignore_orders_dlg dialog
27 
28 ignore_orders_dlg::ignore_orders_dlg(CWnd* pParent /*=NULL*/)
29  : CDialog(ignore_orders_dlg::IDD, pParent)
30 {
31  //{{AFX_DATA_INIT(ignore_orders_dlg)
32  // NOTE: the ClassWizard will add member initialization here
33  //}}AFX_DATA_INIT
34 }
35 
36 void ignore_orders_dlg::DoDataExchange(CDataExchange* pDX)
37 {
38  CDialog::DoDataExchange(pDX);
39  //{{AFX_DATA_MAP(ignore_orders_dlg)
40  // NOTE: the ClassWizard will add DDX and DDV calls here
41  //}}AFX_DATA_MAP
42 }
43 
44 
45 BEGIN_MESSAGE_MAP(ignore_orders_dlg, CDialog)
46  //{{AFX_MSG_MAP(ignore_orders_dlg)
47  ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
48  ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
49  ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
50  ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
51  ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
52  ON_BN_CLICKED(IDC_CHECK6, OnCheck6)
53  ON_BN_CLICKED(IDC_CHECK7, OnCheck7)
54  ON_BN_CLICKED(IDC_CHECK8, OnCheck8)
55  ON_BN_CLICKED(IDC_CHECK9, OnCheck9)
56  ON_BN_CLICKED(IDC_CHECK10, OnCheck10)
57  //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
59 
61 // ignore_orders_dlg message handlers
62 
63 BOOL ignore_orders_dlg::OnInitDialog()
64 {
65  int i, default_orders, last_bottom, orders_accepted;
66  RECT window_size;
67  char buf[128];
68  object *objp;
69 
70  CDialog::OnInitDialog();
71 
72  check_boxes[0].button = (CButton *)GetDlgItem( IDC_CHECK1 );
73  check_boxes[1].button = (CButton *)GetDlgItem( IDC_CHECK2 );
74  check_boxes[2].button = (CButton *)GetDlgItem( IDC_CHECK3 );
75  check_boxes[3].button = (CButton *)GetDlgItem( IDC_CHECK4 );
76  check_boxes[4].button = (CButton *)GetDlgItem( IDC_CHECK5 );
77  check_boxes[5].button = (CButton *)GetDlgItem( IDC_CHECK6 );
78  check_boxes[6].button = (CButton *)GetDlgItem( IDC_CHECK7 );
79  check_boxes[7].button = (CButton *)GetDlgItem( IDC_CHECK8 );
80  check_boxes[8].button = (CButton *)GetDlgItem( IDC_CHECK9 );
81  check_boxes[9].button = (CButton *)GetDlgItem( IDC_CHECK10 );
82 
83  // change the labels on the check boxes to reflect the set of default
84  // orders for this ship
85  if ( m_ship >= 0 ) {
86  default_orders = ship_get_default_orders_accepted( &Ship_info[Ships[m_ship].ship_info_index] );
87  } else {
88  // we are doing multiple edit on ships. We just need to get default orders for
89  // the first marked ship since they'd better all be the same anyway!!!
90  default_orders = 0;
91  for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
92  if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
93  int these_orders;
94 
96  if ( default_orders == 0 )
97  default_orders = these_orders;
98  else if ( default_orders != these_orders )
99  Int3();
100  }
101  }
102 
103  }
104 
105  // set the checkboxes for the orders accepted
106  m_num_checks_active = 0;
107  for (i = 0; i < NUM_COMM_ORDER_ITEMS; i++ )
108  {
109  if (default_orders & Comm_orders[i].item)
110  {
111  // Not enough space to display checkboxes for all comm orders!
112  // Need to add more checkboxes.
113  if (m_num_checks_active >= MAX_CHECKBOXES)
114  {
115  Int3();
116  break;
117  }
118 
119  check_boxes[m_num_checks_active].button->SetWindowText(Comm_orders[i].name);
120  check_boxes[m_num_checks_active].id = Comm_orders[i].item;
121  m_num_checks_active++;
122  }
123  }
124 
125  // resize the dialog by shrinking the height by the number of checkboxes that
126  // we removed
127  GetWindowRect( &window_size );
128 
129  // hide the rest of the dialog items
130  last_bottom = 0;
131  for ( i = MAX_CHECKBOXES - 1; i >= m_num_checks_active; i-- ) {
132  RECT check_size;
133 
134  // get the size of the checkbox, then hide it.
135  check_boxes[i].button->GetWindowRect( &check_size );
136  check_boxes[i].button->ShowWindow(SW_HIDE);
137 
138  // shrink the size of the parent window by the size of the checkbox
139  if ( last_bottom != 0 )
140  window_size.bottom -= (last_bottom - check_size.bottom );
141 
142  last_bottom = check_size.bottom;
143 
144  }
145 
146  // call MoveWindow to resize the window
147  MoveWindow( &window_size, TRUE );
148 
149  // set the check marks in the box based on orders_accepted valud in the ship structure(s)
150  if ( m_ship >= 0 ) {
151  orders_accepted = Ships[m_ship].orders_accepted;
152  for ( i = 0; i < m_num_checks_active; i++ ) {
153  if ( check_boxes[i].id & orders_accepted )
154  check_boxes[i].button->SetCheck(1);
155  }
156  } else {
157  int first_time;
158 
159  first_time = 1;
160  for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
161  if (((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) && (objp->flags & OF_MARKED)) {
162 
163  // get the orders for this ship. If a state is not set
164  orders_accepted = Ships[objp->instance].orders_accepted;
165  if ( first_time ) {
166  for ( i = 0; i < m_num_checks_active; i++ ) {
167  if ( check_boxes[i].id & orders_accepted )
168  check_boxes[i].button->SetCheck(1);
169  }
170  first_time = 0;
171  } else {
172  for ( i = 0; i < m_num_checks_active; i++ ) {
173  // see if the order matches the check box order
174  if ( check_boxes[i].id & orders_accepted ) {
175  // if it matches, if it is not already set, then it is indeterminate.
176  if ( !check_boxes[i].button->GetCheck() )
177  check_boxes[i].button->SetCheck(2);
178  } else {
179  // if the order isn't active, and already set, mark as indeterminite.
180  if ( check_boxes[i].button->GetCheck() )
181  check_boxes[i].button->SetCheck(2);
182  }
183  }
184  }
185  }
186  }
187  }
188 
189  // finally, set the title of the window to be something else. We really aren't checking orders
190  // which will be ignore, but rather orders which will be accepted
191  sprintf(buf, "Player orders accepted" );
192  SetWindowText(buf);
193 
194  return TRUE; // return TRUE unless you set the focus to a control
195  // EXCEPTION: OCX Property Pages should return FALSE
196 }
197 
198 // for the OnOK function, we scan through the list of checkboxes, and reset the ship's orders accepted
199 // variable based on the state of the checkboxes
201 {
202  int orders_accepted, i;
203  object *objp;
204 
205  // clear out the orders, then set the bits according to which check boxes are set
206  if ( m_ship >= 0 ) {
207  orders_accepted = 0;
208  for ( i = 0; i < m_num_checks_active; i++ ) {
209  if ( check_boxes[i].button->GetCheck() )
210  orders_accepted |= check_boxes[i].id;
211  }
212  Ships[m_ship].orders_accepted = orders_accepted;
213  } else {
214  for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
215  if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
216  Ships[objp->instance].orders_accepted = 0;
217  for ( i = 0; i < m_num_checks_active; i++ ) {
218  int box_value;
219 
220  box_value = check_boxes[i].button->GetCheck();
221  // get the status of the checkbox -- if in the indeterminite state, then
222  // skip it
223  if ( box_value == 2 )
224  continue;
225 
226  // if the button is set, then set the bit, otherwise, clear the bit
227  if ( box_value == 1 )
229  else
231  }
232  }
233  }
234  }
235 
236  CDialog::OnOK();
237 }
238 
239 // stupid routines to deal with the tri-state values of the checkboxes
241 {
242  CButton *button;
243 
244  button = (CButton *)GetDlgItem(IDC_CHECK1);
245  if (button->GetCheck() == 1)
246  button->SetCheck(0);
247  else
248  button->SetCheck(1);
249 }
250 
252 {
253  CButton *button;
254 
255  button = (CButton *)GetDlgItem(IDC_CHECK2);
256  if (button->GetCheck() == 1)
257  button->SetCheck(0);
258  else
259  button->SetCheck(1);
260 }
261 
263 {
264  CButton *button;
265 
266  button = (CButton *)GetDlgItem(IDC_CHECK3);
267  if (button->GetCheck() == 1)
268  button->SetCheck(0);
269  else
270  button->SetCheck(1);
271 }
272 
274 {
275  CButton *button;
276 
277  button = (CButton *)GetDlgItem(IDC_CHECK4);
278  if (button->GetCheck() == 1)
279  button->SetCheck(0);
280  else
281  button->SetCheck(1);
282 }
283 
285 {
286  CButton *button;
287 
288  button = (CButton *)GetDlgItem(IDC_CHECK5);
289  if (button->GetCheck() == 1)
290  button->SetCheck(0);
291  else
292  button->SetCheck(1);
293 }
294 
296 {
297  CButton *button;
298 
299  button = (CButton *)GetDlgItem(IDC_CHECK6);
300  if (button->GetCheck() == 1)
301  button->SetCheck(0);
302  else
303  button->SetCheck(1);
304 }
305 
307 {
308  CButton *button;
309 
310  button = (CButton *)GetDlgItem(IDC_CHECK7);
311  if (button->GetCheck() == 1)
312  button->SetCheck(0);
313  else
314  button->SetCheck(1);
315 }
316 
318 {
319  CButton *button;
320 
321  button = (CButton *)GetDlgItem(IDC_CHECK8);
322  if (button->GetCheck() == 1)
323  button->SetCheck(0);
324  else
325  button->SetCheck(1);
326 }
327 
329 {
330  CButton *button;
331 
332  button = (CButton *)GetDlgItem(IDC_CHECK9);
333  if (button->GetCheck() == 1)
334  button->SetCheck(0);
335  else
336  button->SetCheck(1);
337 }
338 
340 {
341  CButton *button;
342 
343  button = (CButton *)GetDlgItem(IDC_CHECK10);
344  if (button->GetCheck() == 1)
345  button->SetCheck(0);
346  else
347  button->SetCheck(1);
348 }
afx_msg void OnCheck3()
afx_msg void OnCheck1()
afx_msg void OnCheck7()
ignore_orders_dlg(CWnd *pParent=NULL)
int i
Definition: multi_pxo.cpp:466
afx_msg void OnCheck9()
#define NUM_COMM_ORDER_ITEMS
Definition: hudsquadmsg.h:36
virtual void DoDataExchange(CDataExchange *pDX)
virtual void OnOK()
#define TRUE
Definition: pstypes.h:399
object obj_used_list
Definition: object.cpp:53
#define IDC_CHECK6
Definition: resource.h:430
object * objp
Definition: lua.cpp:3105
#define Int3()
Definition: pstypes.h:292
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: Glext.h:7308
CButton * button
check_box_info check_boxes[MAX_CHECKBOXES]
int orders_accepted
Definition: ship.h:624
int instance
Definition: object.h:150
#define OBJ_START
Definition: object.h:35
afx_msg void OnCheck8()
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
#define IDC_CHECK1
Definition: resource.h:177
#define IDC_CHECK2
Definition: resource.h:878
afx_msg void OnCheck5()
comm_order Comm_orders[NUM_COMM_ORDER_ITEMS]
#define OF_MARKED
Definition: object.h:125
#define OBJ_SHIP
Definition: object.h:32
GLuint const GLchar * name
Definition: Glext.h:5608
int BOOL
Definition: config.h:80
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
#define IDC_CHECK8
Definition: resource.h:435
afx_msg void OnCheck2()
afx_msg void OnCheck10()
int ship_info_index
Definition: ship.h:539
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
#define IDC_CHECK3
Definition: resource.h:422
int ship_get_default_orders_accepted(ship_info *sip)
Definition: ship.cpp:5480
afx_msg void OnCheck4()
#define MAX_CHECKBOXES
afx_msg void OnCheck6()
#define IDC_CHECK9
Definition: resource.h:438
uint flags
Definition: object.h:151
#define IDC_CHECK10
Definition: resource.h:441
#define IDC_CHECK4
Definition: resource.h:425
char type
Definition: object.h:146
#define IDC_CHECK5
Definition: resource.h:428
#define IDC_CHECK7
Definition: resource.h:432