]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/ignoreordersdlg.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / ignoreordersdlg.cpp
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/FRED2/IgnoreOrdersDlg.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * C code for dialog to set which orders from the player that a particular ship should ignore
16  *
17  */
18
19 #include "stdafx.h"
20 #include "fred.h"
21 #include "ignoreordersdlg.h"
22 #include "hudsquadmsg.h"                                // need this for the menu stuff
23 #include "linklist.h"
24
25 #ifdef _DEBUG
26 #define new DEBUG_NEW
27 #undef THIS_FILE
28 static char THIS_FILE[] = __FILE__;
29 #endif
30
31 // super cool macro to make IDC_* names
32
33 // note: If you change this table at all, keep it in sync with version in HUDsquadmsg.cpp
34 fred_comm_order Fred_comm_orders[] = {
35         ATTACK_TARGET_ITEM, "Attack my target",
36         DISABLE_TARGET_ITEM, "Disable my target",
37         DISARM_TARGET_ITEM, "Disarm my target",
38         DISABLE_SUBSYSTEM_ITEM, "Destroy my subsystem",
39         PROTECT_TARGET_ITEM, "Protect my target",
40         IGNORE_TARGET_ITEM, "Ignore my target",
41         FORMATION_ITEM, "Form on my wing",
42         COVER_ME_ITEM, "Cover me",
43         ENGAGE_ENEMY_ITEM, "Engage enemy",
44         CAPTURE_TARGET_ITEM, "Capture my target",
45         REARM_REPAIR_ME_ITEM, "Rearm/repair me",
46         ABORT_REARM_REPAIR_ITEM, "Abort rearm repair",
47         DEPART_ITEM, "Depart",
48 };
49
50 int Fred_comm_orders_max = sizeof(Fred_comm_orders)/sizeof(fred_comm_order);
51
52 /////////////////////////////////////////////////////////////////////////////
53 // ignore_orders_dlg dialog
54
55 ignore_orders_dlg::ignore_orders_dlg(CWnd* pParent /*=NULL*/)
56         : CDialog(ignore_orders_dlg::IDD, pParent)
57 {
58         //{{AFX_DATA_INIT(ignore_orders_dlg)
59                 // NOTE: the ClassWizard will add member initialization here
60         //}}AFX_DATA_INIT
61 }
62
63 void ignore_orders_dlg::DoDataExchange(CDataExchange* pDX)
64 {
65         CDialog::DoDataExchange(pDX);
66         //{{AFX_DATA_MAP(ignore_orders_dlg)
67                 // NOTE: the ClassWizard will add DDX and DDV calls here
68         //}}AFX_DATA_MAP
69 }
70
71
72 BEGIN_MESSAGE_MAP(ignore_orders_dlg, CDialog)
73         //{{AFX_MSG_MAP(ignore_orders_dlg)
74         ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
75         ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
76         ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
77         ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
78         ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
79         ON_BN_CLICKED(IDC_CHECK6, OnCheck6)
80         ON_BN_CLICKED(IDC_CHECK7, OnCheck7)
81         ON_BN_CLICKED(IDC_CHECK8, OnCheck8)
82         ON_BN_CLICKED(IDC_CHECK9, OnCheck9)
83         ON_BN_CLICKED(IDC_CHECK10, OnCheck10)
84         //}}AFX_MSG_MAP
85 END_MESSAGE_MAP()
86
87 /////////////////////////////////////////////////////////////////////////////
88 // ignore_orders_dlg message handlers
89
90 BOOL ignore_orders_dlg::OnInitDialog() 
91 {
92         int i, default_orders, last_bottom, orders_accepted;
93         RECT    window_size;
94         char buf[128];
95         object *objp;
96
97         CDialog::OnInitDialog();
98         
99         check_boxes[0].button = (CButton *)GetDlgItem( IDC_CHECK1 );
100         check_boxes[1].button = (CButton *)GetDlgItem( IDC_CHECK2 );
101         check_boxes[2].button = (CButton *)GetDlgItem( IDC_CHECK3 );
102         check_boxes[3].button = (CButton *)GetDlgItem( IDC_CHECK4 );
103         check_boxes[4].button = (CButton *)GetDlgItem( IDC_CHECK5 );
104         check_boxes[5].button = (CButton *)GetDlgItem( IDC_CHECK6 );
105         check_boxes[6].button = (CButton *)GetDlgItem( IDC_CHECK7 );
106         check_boxes[7].button = (CButton *)GetDlgItem( IDC_CHECK8 );
107         check_boxes[8].button = (CButton *)GetDlgItem( IDC_CHECK9 );
108         check_boxes[9].button = (CButton *)GetDlgItem( IDC_CHECK10 );
109
110         // change the labels on the check boxes to reflect the set of default
111         // orders for this ship
112         if ( m_ship >= 0 ) {
113                 default_orders = ship_get_default_orders_accepted( &Ship_info[Ships[m_ship].ship_info_index] );
114         } else {
115                 // we are doing multiple edit on ships.  We just need to get default orders for
116                 // the first marked ship since they'd better all be the same anyway!!!
117                 default_orders = 0;
118                 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
119                         if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
120                                 int these_orders;
121
122                                 these_orders = ship_get_default_orders_accepted( &Ship_info[Ships[objp->instance].ship_info_index] );
123                                 if ( default_orders == 0 )
124                                         default_orders = these_orders;
125                                 else if ( default_orders != these_orders )
126                                         Int3();
127                         }
128                 }
129
130         }
131
132         // set the checkboxes for the orders accepted
133         m_num_checks_active = 0;
134         for (i = 0; i < MAX_SHIP_ORDERS; i++ ) {
135                 if ( default_orders & Fred_comm_orders[i].value ) {
136                         SDL_assert( m_num_checks_active < MAX_CHECKBOXES );
137                         check_boxes[m_num_checks_active].button->SetWindowText( Fred_comm_orders[i].menu_text );
138                         check_boxes[m_num_checks_active].id = Fred_comm_orders[i].value;
139                         m_num_checks_active++;
140                 }
141         }
142
143         // resize the dialog by shrinking the height by the number of checkboxes that
144         // we removed
145         GetWindowRect( &window_size );
146
147         // hide the rest of the dialog items
148         last_bottom = 0;
149         for ( i = MAX_CHECKBOXES - 1; i >= m_num_checks_active; i-- ) {
150                 RECT check_size;
151
152                 // get the size of the checkbox, then hide it.
153                 check_boxes[i].button->GetWindowRect( &check_size );
154                 check_boxes[i].button->ShowWindow(SW_HIDE);
155
156                 // shrink the size of the parent window by the size of the checkbox
157                 if ( last_bottom != 0 )
158                         window_size.bottom -= (last_bottom - check_size.bottom );
159
160                 last_bottom = check_size.bottom;
161
162         }
163
164         // call MoveWindow to resize the window
165         MoveWindow( &window_size, TRUE );
166
167         // set the check marks in the box based on orders_accepted valud in the ship structure(s)
168         if ( m_ship >= 0 ) {
169                 orders_accepted = Ships[m_ship].orders_accepted;
170                 for ( i = 0; i < m_num_checks_active; i++ ) {
171                         if ( check_boxes[i].id & orders_accepted )
172                                 check_boxes[i].button->SetCheck(1);
173                 }
174         } else {
175                 int first_time;
176
177                 first_time = 1;
178                 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
179                         if (((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) && (objp->flags & OF_MARKED)) {
180
181                                 // get the orders for this ship.  If a state is not set 
182                                 orders_accepted = Ships[objp->instance].orders_accepted;
183                                 if ( first_time ) {
184                                         for ( i = 0; i < m_num_checks_active; i++ ) {
185                                                 if ( check_boxes[i].id & orders_accepted )
186                                                         check_boxes[i].button->SetCheck(1);
187                                         }
188                                         first_time = 0;
189                                 } else {
190                                         for ( i = 0; i < m_num_checks_active; i++ ) {
191                                                 // see if the order matches the check box order
192                                                 if ( check_boxes[i].id & orders_accepted ) {
193                                                         // if it matches, if it is not already set, then it is indeterminate.
194                                                         if ( !check_boxes[i].button->GetCheck() )
195                                                                 check_boxes[i].button->SetCheck(2);
196                                                 } else {
197                                                         // if the order isn't active, and already set, mark as indeterminite.
198                                                         if ( check_boxes[i].button->GetCheck() )
199                                                                 check_boxes[i].button->SetCheck(2);
200                                                 }
201                                         }
202                                 }
203                         }
204                 }
205         }
206
207         // finally, set the title of the window to be something else.  We really aren't checking orders
208         // which will be ignore, but rather orders which will be accepted
209         sprintf(buf, "Player orders accepted" );
210         SetWindowText(buf);
211
212         return TRUE;  // return TRUE unless you set the focus to a control
213                       // EXCEPTION: OCX Property Pages should return FALSE
214 }
215
216 // for the OnOK function, we scan through the list of checkboxes, and reset the ship's orders accepted
217 // variable based on the state of the checkboxes
218 void ignore_orders_dlg::OnOK() 
219 {
220         int orders_accepted, i;
221         object *objp;
222
223         // clear out the orders, then set the bits according to which check boxes are set
224         if ( m_ship >= 0 ) {
225                 orders_accepted = 0;
226                 for ( i = 0; i < m_num_checks_active; i++ ) {
227                         if ( check_boxes[i].button->GetCheck() )
228                                 orders_accepted |= check_boxes[i].id;
229                 }
230                 Ships[m_ship].orders_accepted = orders_accepted;
231         } else {
232                 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
233                         if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
234                                 Ships[objp->instance].orders_accepted = 0;
235                                 for ( i = 0; i < m_num_checks_active; i++ ) {
236                                         int box_value;
237
238                                         box_value = check_boxes[i].button->GetCheck();
239                                         // get the status of the checkbox -- if in the indeterminite state, then
240                                         // skip it
241                                         if ( box_value == 2 )
242                                                 continue;
243
244                                         // if the button is set, then set the bit, otherwise, clear the bit
245                                         if ( box_value == 1 )
246                                                 Ships[objp->instance].orders_accepted |= check_boxes[i].id;
247                                         else
248                                                 Ships[objp->instance].orders_accepted &= ~(check_boxes[i].id);
249                                 }
250                         }
251                 }
252         }
253         
254         CDialog::OnOK();
255 }
256
257 // stupid routines to deal with the tri-state values of the checkboxes
258 void ignore_orders_dlg::OnCheck1() 
259 {
260         CButton *button;
261
262         button = (CButton *)GetDlgItem(IDC_CHECK1);
263         if (button->GetCheck() == 1)
264                 button->SetCheck(0);
265         else
266                 button->SetCheck(1);
267 }
268
269 void ignore_orders_dlg::OnCheck2() 
270 {
271         CButton *button;
272
273         button = (CButton *)GetDlgItem(IDC_CHECK2);
274         if (button->GetCheck() == 1)
275                 button->SetCheck(0);
276         else
277                 button->SetCheck(1);
278 }
279
280 void ignore_orders_dlg::OnCheck3() 
281 {
282         CButton *button;
283
284         button = (CButton *)GetDlgItem(IDC_CHECK3);
285         if (button->GetCheck() == 1)
286                 button->SetCheck(0);
287         else
288                 button->SetCheck(1);
289 }
290
291 void ignore_orders_dlg::OnCheck4() 
292 {
293         CButton *button;
294
295         button = (CButton *)GetDlgItem(IDC_CHECK4);
296         if (button->GetCheck() == 1)
297                 button->SetCheck(0);
298         else
299                 button->SetCheck(1);
300 }
301
302 void ignore_orders_dlg::OnCheck5() 
303 {
304         CButton *button;
305
306         button = (CButton *)GetDlgItem(IDC_CHECK5);
307         if (button->GetCheck() == 1)
308                 button->SetCheck(0);
309         else
310                 button->SetCheck(1);
311 }
312
313 void ignore_orders_dlg::OnCheck6() 
314 {
315         CButton *button;
316
317         button = (CButton *)GetDlgItem(IDC_CHECK6);
318         if (button->GetCheck() == 1)
319                 button->SetCheck(0);
320         else
321                 button->SetCheck(1);
322 }
323
324 void ignore_orders_dlg::OnCheck7() 
325 {
326         CButton *button;
327
328         button = (CButton *)GetDlgItem(IDC_CHECK7);
329         if (button->GetCheck() == 1)
330                 button->SetCheck(0);
331         else
332                 button->SetCheck(1);
333 }
334
335 void ignore_orders_dlg::OnCheck8() 
336 {
337         CButton *button;
338
339         button = (CButton *)GetDlgItem(IDC_CHECK8);
340         if (button->GetCheck() == 1)
341                 button->SetCheck(0);
342         else
343                 button->SetCheck(1);
344 }
345
346 void ignore_orders_dlg::OnCheck9() 
347 {
348         CButton *button;
349
350         button = (CButton *)GetDlgItem(IDC_CHECK9);
351         if (button->GetCheck() == 1)
352                 button->SetCheck(0);
353         else
354                 button->SetCheck(1);
355 }
356
357 void ignore_orders_dlg::OnCheck10() 
358 {
359         CButton *button;
360
361         button = (CButton *)GetDlgItem(IDC_CHECK10);
362         if (button->GetCheck() == 1)
363                 button->SetCheck(0);
364         else
365                 button->SetCheck(1);
366 }
367