2 * $Logfile: /Freespace2/code/FRED2/OrientEditor.cpp $
7 * Object orientation editor (or just object editor) dialog box handling code
10 * Revision 1.1 2002/05/03 03:28:08 root
14 * 2 10/07/98 6:28p Dave
15 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
16 * Fred. Globalized mission and campaign file extensions. Removed Silent
17 * Threat specific code.
19 * 1 10/07/98 3:02p Dave
21 * 1 10/07/98 3:00p Dave
23 * 18 7/13/98 10:04a Hoffoss
24 * Fixed bug where jump nodes in mission would screw up indexing.
26 * 17 3/12/98 2:21p Johnson
27 * Fixed some Fred bugs related to jump nodes.
29 * 16 9/16/97 9:41p Hoffoss
30 * Changed Fred code around to stop using Parse_player structure for
31 * player information, and use actual ships instead.
33 * 15 8/16/97 2:02a Hoffoss
34 * Made docked objects move together in Fred.
36 * 14 8/15/97 8:24p Hoffoss
37 * Fixed bug with orient editor.
39 * 13 8/14/97 3:14p Hoffoss
40 * Fixed name displayed for players.
42 * 12 7/29/97 2:20p Hoffoss
43 * Fixed some minor bugs.
45 * 11 6/26/97 11:18a Hoffoss
46 * Fixed bug in orient editor. OBJ_POINT type wasn't accounted for.
48 * 10 5/20/97 2:28p Hoffoss
49 * Added message box queries for close window operation on all modal
52 * 9 5/14/97 4:08p Lawrance
53 * removing my_index from game arrays
55 * 8 4/17/97 2:01p Hoffoss
56 * All dialog box window states are saved between sessions now.
58 * 7 3/12/97 4:33p Hoffoss
59 * added spin controls to orient editor, light intensity level can be
60 * specified in BG editor.
62 * 6 2/28/97 11:31a Hoffoss
63 * Implemented modeless dialog saving and restoring, and changed some
66 * 5 2/21/97 5:34p Hoffoss
67 * Added extensive modification detection and fixed a bug in initial
70 * 4 2/17/97 5:28p Hoffoss
71 * Checked RCS headers, added them were missing, changing description to
72 * something better, etc where needed.
79 #include "orienteditor.h"
80 #include "management.h"
87 static char THIS_FILE[] = __FILE__;
92 /////////////////////////////////////////////////////////////////////////////
93 // orient_editor dialog
95 orient_editor::orient_editor(CWnd* pParent /*=NULL*/)
96 : CDialog(orient_editor::IDD, pParent)
100 //{{AFX_DATA_INIT(orient_editor)
103 m_position_z = _T("");
104 m_position_y = _T("");
105 m_position_x = _T("");
106 m_location_x = _T("0.0");
107 m_location_y = _T("0.0");
108 m_location_z = _T("0.0");
110 Assert(query_valid_object());
111 pos = Objects[cur_object_index].pos;
112 m_position_x.Format("%.1f", pos.x);
113 m_position_y.Format("%.1f", pos.y);
114 m_position_z.Format("%.1f", pos.z);
117 void orient_editor::DoDataExchange(CDataExchange* pDX)
119 CDialog::DoDataExchange(pDX);
120 //{{AFX_DATA_MAP(orient_editor)
121 DDX_Control(pDX, IDC_SPIN6, m_spin6);
122 DDX_Control(pDX, IDC_SPIN5, m_spin5);
123 DDX_Control(pDX, IDC_SPIN4, m_spin4);
124 DDX_Control(pDX, IDC_SPIN3, m_spin3);
125 DDX_Control(pDX, IDC_SPIN2, m_spin2);
126 DDX_Control(pDX, IDC_SPIN1, m_spin1);
127 DDX_CBIndex(pDX, IDC_OBJECT_LIST, m_object_index);
128 DDX_Check(pDX, IDC_POINT_TO_CHECKBOX, m_point_to);
129 DDX_Text(pDX, IDC_POSITION_Z, m_position_z);
130 DDX_Text(pDX, IDC_POSITION_Y, m_position_y);
131 DDX_Text(pDX, IDC_POSITION_X, m_position_x);
132 DDX_Text(pDX, IDC_LOCATION_X, m_location_x);
133 DDX_Text(pDX, IDC_LOCATION_Y, m_location_y);
134 DDX_Text(pDX, IDC_LOCATION_Z, m_location_z);
138 BEGIN_MESSAGE_MAP(orient_editor, CDialog)
139 //{{AFX_MSG_MAP(orient_editor)
144 /////////////////////////////////////////////////////////////////////////////
145 // orient_editor message handlers
147 BOOL orient_editor::OnInitDialog()
154 CDialog::OnInitDialog();
155 theApp.init_window(&Object_wnd_data, this);
156 ((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->SetCheck(1);
157 box = (CComboBox *) GetDlgItem(IDC_OBJECT_LIST);
161 ptr = GET_FIRST(&obj_used_list);
162 while (ptr != END_OF_LIST(&obj_used_list)) {
163 if (Marked != 1 || OBJ_INDEX(ptr) != cur_object_index) {
164 if ((ptr->type == OBJ_START) || (ptr->type == OBJ_SHIP)) {
165 box->AddString(Ships[ptr->instance].ship_name);
166 index[total++] = OBJ_INDEX(ptr);
168 } else if (ptr->type == OBJ_WAYPOINT) {
169 sprintf(text, "%s:%d", Waypoint_lists[ptr->instance / 65536].name,
170 (ptr->instance & 0xffff) + 1);
172 box->AddString(text);
173 index[total++] = OBJ_INDEX(ptr);
175 } else if ((ptr->type == OBJ_POINT) || (ptr->type == OBJ_JUMP_NODE)) {
177 Assert(0); // unknown object type.
183 type = Objects[cur_object_index].type;
184 if (Marked == 1 && type == OBJ_WAYPOINT) {
185 GetDlgItem(IDC_POINT_TO_CHECKBOX)->EnableWindow(0);
186 GetDlgItem(IDC_POINT_TO_OBJECT)->EnableWindow(0);
187 GetDlgItem(IDC_POINT_TO_LOCATION)->EnableWindow(0);
188 GetDlgItem(IDC_OBJECT_LIST)->EnableWindow(0);
189 GetDlgItem(IDC_LOCATION_X)->EnableWindow(0);
190 GetDlgItem(IDC_LOCATION_Y)->EnableWindow(0);
191 GetDlgItem(IDC_LOCATION_Z)->EnableWindow(0);
198 m_spin1.SetRange(99999, -99999);
199 m_spin1.SetPos((int) convert(m_position_x));
200 m_spin2.SetRange(99999, -99999);
201 m_spin2.SetPos((int) convert(m_position_y));
202 m_spin3.SetRange(99999, -99999);
203 m_spin3.SetPos((int) convert(m_position_z));
204 m_spin4.SetRange(99999, -99999);
205 m_spin5.SetRange(99999, -99999);
206 m_spin6.SetRange(99999, -99999);
211 int orient_editor::query_modified()
215 dif = Objects[cur_object_index].pos.x - convert(m_position_x);
216 if ((dif > PREC) || (dif < -PREC))
218 dif = Objects[cur_object_index].pos.y - convert(m_position_y);
219 if ((dif > PREC) || (dif < -PREC))
221 dif = Objects[cur_object_index].pos.z - convert(m_position_z);
222 if ((dif > PREC) || (dif < -PREC))
225 if (((CButton *) GetDlgItem(IDC_POINT_TO_CHECKBOX))->GetCheck() == 1)
231 void orient_editor::OnOK()
237 pos.x = convert(m_position_x);
238 pos.y = convert(m_position_y);
239 pos.z = convert(m_position_z);
241 if ((((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->GetCheck() == 1) ||
242 (((CButton *) GetDlgItem(IDC_POINT_TO_LOCATION))->GetCheck() == 1))
245 vm_vec_sub(&delta, &pos, &Objects[cur_object_index].pos);
246 if (delta.x || delta.y || delta.z)
249 ptr = GET_FIRST(&obj_used_list);
250 while (ptr != END_OF_LIST(&obj_used_list)) {
251 if (ptr->flags & OF_MARKED) {
252 vm_vec_add2(&ptr->pos, &delta);
259 ptr = GET_FIRST(&obj_used_list);
260 while (ptr != END_OF_LIST(&obj_used_list)) {
261 if (ptr->flags & OF_MARKED)
267 theApp.record_window_data(&Object_wnd_data, this);
271 void orient_editor::update_object(object *ptr)
273 if (ptr->type != OBJ_WAYPOINT && m_point_to) {
277 memset(&v, 0, sizeof(vector));
278 loc.x = convert(m_location_x);
279 loc.y = convert(m_location_y);
280 loc.z = convert(m_location_z);
281 if (((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->GetCheck() == 1) {
282 v = Objects[index[m_object_index]].pos;
283 vm_vec_sub2(&v, &ptr->pos);
285 } else if (((CButton *) GetDlgItem(IDC_POINT_TO_LOCATION))->GetCheck() == 1) {
286 vm_vec_sub(&v, &loc, &ptr->pos);
289 Assert(0); // neither radio button is checked.
292 if (!v.x && !v.y && !v.z){
293 return; // can't point to itself.
296 vm_vector_2_matrix(&m, &v, NULL, NULL);
301 float orient_editor::convert(CString &str)
306 string_copy(buf, str, 255);
308 for (i=j=0; i<len; i++)
313 return (float) atof(buf);
316 void orient_editor::OnCancel()
318 theApp.record_window_data(&Object_wnd_data, this);
322 void orient_editor::OnClose()
326 if (query_modified()) {
327 z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);