source: golgotha/src/golg/editor/editor.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 27.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "editor/editor.hh"
10#include "controller.hh"
11#include "map.hh"
12#include "tile.hh"
13#include "window/win_evt.hh"
14#include "string/string.hh"
15#include "draw_context.hh"
16#include "font/font.hh"
17#include "window/style.hh"
18#include "saver.hh"
19#include "editor/pmenu.hh"
20#include "menu/pull.hh"
21#include "resources.hh"
22#include "editor/dialogs/obj_win.hh"
23#include "math/pi.hh"
24#include "mess_id.hh"
25#include "loaders/load.hh"
26#include "editor/edit_id.hh"
27#include "editor/contedit.hh"
28#include "editor/e_state.hh"
29#include "editor/dialogs/e_time.hh"
30#include "m_flow.hh"
31#include "editor/dialogs/scene.hh"
32#include "light.hh"
33#include "math/spline.hh"
34#include "file/get_filename.hh"
35
36#include "time/gui_prof.hh"
37#include "border_frame.hh"
38#include "remove_man.hh"
39#include "status/status.hh"
40#include "status/gui_stat.hh"
41#include "editor/dialogs/tile_picker.hh"
42// #include "editor/dialogs/path_win.hh"
43#include "editor/dialogs/debug_win.hh"
44#include "r1_api.hh"
45#include "g1_render.hh"
46#include "gui/create_dialog.hh"
47#include "gui/text_input.hh"
48#include "r1_win.hh"
49// #include "critical_graph.hh"
50#include "app/app.hh"
51
52#include "editor/mode/e_tile.hh"
53#include "editor/mode/e_object.hh"
54#include "dll/dll_man.hh"
55#include "window/wmanager.hh"
56#include "editor/e_res.hh"
57#include "lisp/lisp.hh"
58#include "lisp/li_init.hh"
59#include "gui/li_pull_menu.hh"
60#include "player.hh"
61
62#include "level_load.hh"
63#include "map_vert.hh"
64#include "lisp/li_dialog.hh"
65#include "map_view.hh"
66#include "main/main.hh"
67
68g1_editor_class g1_editor_instance;
69
70
71int g1_controller_edit_class::get_current_splines(i4_spline_class **buffer, int buf_size)
72{
73  return g1_editor_instance.get_current_splines(buffer, buf_size);
74}
75
76void g1_editor_class::create_radar()
77{
78  if (!radar_parent.get())
79  {
80    g1_map_class *map=g1_get_map();
81    i4_parent_window_class *mv=g1_create_radar_view(map->width(), map->height(),
82                                                    G1_RADAR_CLICK_HOLDS_VIEW |
83                                                    G1_RADAR_DRAW_ALL_PATHS);
84
85
86
87    i4_parent_window_class *p;
88    int y=i4_current_app->get_window_manager()->height()-mv->height()-30;
89    p=i4_current_app->get_style()->create_mp_window(0, y,
90                                                    mv->width(), mv->height(),
91                                                    g1_ges("radar_title"));
92    p->add_child(0,0, mv);
93    radar_parent=p;
94  } 
95}
96
97int g1_editor_class::get_current_splines(i4_spline_class **buffer, int buf_size)
98{
99  if (!have_map() || !get_map()->current_movie || !get_map()->current_movie->t_cut_scenes)
100    return 0;
101
102  g1_cut_scene_class *s=get_map()->current_movie->current();
103
104  if (s && buf_size>g1_cut_scene_class::T_PATHS)
105  {
106    for (int i=0; i<g1_cut_scene_class::T_PATHS; i++)
107      buffer[i]=&s->paths[i];
108
109    return g1_cut_scene_class::T_PATHS;
110  }
111
112  return 0;
113}
114
115
116
117
118void g1_editor_class::create_views()
119{
120  if (edit_mode)
121  {
122    sw32 x1=0,
123      x2=parent->width()-1-g1_edit_state.tools_width(),
124      y1=style->font_hint->normal_font->largest_height()+8;
125
126    int y2=parent->height()-1;
127    if (time_line) y2-=time_line->height();
128
129    w32 div;
130    for (div=1; div*div<t_views; div++);
131
132    sw32 x=x1, y=y1, w=(x2-x1+1)/div, h=(y2-y1+1)/div;
133
134
135    for (w32 i=0; i<t_views; i++)
136    {
137      r1_expand_type expand=(r1_expand_type) g1_resources.render_window_expand_mode;
138
139      view_wins[i]=g1_render.r_api->create_render_window(w,h, expand);
140                                                                         
141      views[i]=new g1_controller_edit_class(view_wins[i]->render_area_width(),
142                                            view_wins[i]->render_area_height(), style);
143
144      view_wins[i]->add_child(0,0,views[i]);
145      parent->add_child_front(x,y, view_wins[i]);
146
147      if (i==1)
148      {
149        x=x1;
150        y+=h;
151      }
152      else x+=w;
153
154      views[i]->view=view_states[i];
155      views[i]->view.suggest_camera_mode(G1_EDIT_MODE);
156    }
157   
158    g1_current_controller=views[0];
159  }
160  else
161    g1_cwin_man_class::create_views();
162}
163
164void g1_editor_class::destroy_views()
165{
166  if (edit_mode)
167  {
168    for (w32 i=0; i<t_views; i++)
169    {
170      views[i]->hide_focus();
171      views[i]->view=view_states[i];
172
173      delete view_wins[i];
174      views[i]=0;
175      view_wins[i]=0;
176    }     
177
178
179  } else g1_cwin_man_class::destroy_views();
180}
181 
182
183
184
185void g1_editor_class::close_windows()
186{
187  scene_edit.hide();
188
189  for (g1_mode_creator *mc=g1_mode_creator::first; mc; mc=mc->next)
190    mc->cleanup();
191
192  if (radar_parent.get())
193    i4_kernel.delete_handler(radar_parent.get());
194}
195
196
197
198
199void g1_editor_class::set_edit_mode(i4_bool yes_no)
200{
201  if (yes_no)
202  {
203    // remove play save name so game doesn't try to load movie start
204    i4_unlink(i4gets("play_savename"));
205    i4_user_message_event_class movie_stop(G1_STOP_MOVIE);  // stop game movie if there was one
206    i4_kernel.send_event(i4_current_app, &movie_stop);
207
208    changed();
209
210    g1_cwin_man_class::destroy_views();   // kill the normal game views
211    edit_mode=i4_T;
212
213    g1_change_key_context(G1_EDIT_MODE);
214
215    if (menu) delete menu;
216    menu=li_create_pull_menu("scheme/menu.scm");
217    menu->show(parent, 0,0);
218   
219    //time_line=new g1_time_line(parent, style, &g1_edit_state);
220
221    t_views=4;
222
223    int th=parent->height();
224    if (time_line) th-=time_line->height();
225    g1_edit_state.show_tools(parent, th);
226   
227    create_views();    // create sup'd up edit controllers
228
229    g1_change_key_context(G1_EDIT_MODE);
230
231    li_call("Pause");  // stop the game from running while the editor is going
232
233  } else
234  {
235    menu->hide();
236    delete menu;
237    menu=0;
238   
239    close_windows();
240
241    destroy_views();
242
243    edit_mode=i4_F;
244
245
246    if (time_line)
247      delete time_line;
248
249    g1_edit_state.hide_tools();
250   
251    g1_cwin_man_class::create_views();   // create the normal game views
252
253   
254
255    li_call("Pause");     // start the game running again
256  }
257}
258
259
260g1_editor_class::g1_editor_class()
261{
262  memset(&movement, 0, sizeof(movement));
263
264  for (int i=0; i<MAX_VIEWS; i++)
265    view_states[i].suggest_camera_mode(G1_EDIT_MODE);
266
267  vert_noise_amount=3;
268  use_view_state=i4_F;
269
270  delete_icon=0;
271
272  tool_window=0;
273  time_line=0;
274
275  menu=0;
276
277  edit_mode=i4_F;
278  need_save=i4_F;
279  can_undo=i4_F;
280  can_redo=i4_F;
281  selection=i4_F;
282  profile_view=i4_F;
283  paste_buffer_valid=i4_F;
284
285  objects_window=0;
286  views[0]=0;
287
288  modal_window=0;
289
290  g1_cwin_man=this;
291}
292
293void g1_editor_class::changed()
294{
295  need_save=i4_T;
296}
297
298
299void g1_editor_key_item::action()
300{
301  g1_editor_instance.do_command(command_id);
302}
303
304
305void g1_editor_class::save()
306{
307  if (have_map())
308  {
309    get_map()->recalc_static_stuff();
310
311    i4_bool restore_edit_mode=i4_T;
312   
313    g1_edit_state.hide_focus();
314    get_map()->recalc_static_stuff();
315
316    i4_file_class *out=i4_open(get_map()->get_filename(), I4_WRITE);
317    if (out)
318    {
319      g1_saver_class *save=new g1_saver_class(out);
320
321      get_map()->save(save, G1_MAP_ALL);
322
323      if (save->begin_data_write())
324        get_map()->save(save, G1_MAP_ALL);
325
326      delete save;
327    }
328
329
330    g1_edit_state.show_focus();
331
332    need_save=i4_F;
333  }
334}
335
336void g1_editor_class::do_command(w16 command_id)
337{
338  switch (command_id)
339  {
340    case G1_EDITOR_UNDO :
341      do_undo();
342      break;
343
344    case G1_EDITOR_REDO :
345      do_redo();
346      break;
347     
348    case G1_EDITOR_NEW :
349      open_new_level_window();
350      break;
351
352    case G1_EDITOR_SAVE :
353    {
354      save();     
355    } break;
356
357    case G1_EDITOR_SAVEAS :
358    {
359      open_saveas();
360    } break;
361     
362    case G1_EDITOR_LOAD :
363      open_file();
364      break;
365
366    case G1_EDITOR_OPEN_DLL :
367      open_dll();
368      break;
369
370    case G1_EDITOR_EXIT :
371    {
372      i4_user_message_event_class ex(G1_QUIT);
373      i4_kernel.send_event(i4_current_app, &ex);
374    } break;
375
376    case G1_EDITOR_TOGGLE :
377      set_edit_mode((i4_bool)!edit_mode);
378      break;
379
380
381    case G1_EDITOR_TILE_PICKER :
382      if (g1_map_is_loaded())
383        g1_e_tile.open_picker();
384      break;
385
386
387    case G1_EDITOR_WINDOW_RADAR :
388      if (g1_map_is_loaded())
389      {
390        if (radar_parent.get())
391          i4_current_app->get_style()->close_mp_window(radar_parent.get());
392        else
393          create_radar();
394      }
395      break;
396
397    case G1_EDITOR_WINDOW_OBJECTS :
398      if (g1_map_is_loaded())
399        li_call("toggle_object_picker");
400
401      break;
402
403
404   
405//     case G1_EDITOR_AI_WINDOW:
406//     {
407//       if (!path_window)
408//       {
409//         enum { MAX_NUM=40 };
410
411//         get_map()->get_critical_graph()->expand_critical_graph();
412
413//         i4_image_class *img[MAX_NUM];
414
415//         i4_const_str::iterator i1=get_editor_string("path_start").begin();
416//         img[0] = g1_edit_state.get_icon(i1.read_number());
417
418//         i1=get_editor_string("path_dest").begin();
419//         img[1] = g1_edit_state.get_icon(i1.read_number());
420
421//         i1=get_editor_string("path_critical").begin();
422//         img[2] = g1_edit_state.get_icon(i1.read_number());
423
424//         path_window = new g1_path_window_class(get_map(), img);
425
426//         // Create MPWindow
427//         i4_parent_window_class *mpw;
428//         i4_user_message_event_class *close=
429//           new i4_user_message_event_class(G1_EDITOR_AI_WINDOW_CLOSED);
430//         mpw=style->
431//           create_mp_window(-1,-1,
432//                            path_window->width()+40,
433//                            path_window->height(),
434//                            e_strs.get("ai_window_title"),
435//                            new i4_event_reaction_class(this, close));
436//         mpw->add_child(40,0, path_window);
437       
438//         // Create Toolbar
439//         i4_const_str *nums;
440//         i4_const_str *help_names[MAX_NUM];
441
442//         nums = get_editor_array("path_tool_win_icons");
443//         if (nums)
444//         {
445//           int n=0;
446//           for (i4_const_str* p=nums;  !p->null();  n++)
447//           {
448//             i4_const_str::iterator i1=p->begin();
449//             img[n] = g1_edit_state.get_icon(i1.read_number());
450//             ++p;
451
452//             help_names[n] = p;
453//             ++p;
454//           }
455
456//           g1_path_tool_window_class *path_tool =
457//             new g1_path_tool_window_class(style, path_window, n, img, help_names );
458//           mpw->add_child(0,0, path_tool);
459//           mpw->resize_to_fit_children();
460
461//           i4_free(nums);
462//         }
463//       }
464//     } break;
465
466
467    case G1_EDITOR_RESIZE_MAP :
468      open_resize_level_window();
469      break;
470
471    case G1_EDITOR_WINDOW_SCENES :
472      if (have_map() && get_map()->get_current_movie())
473      {
474        scene_edit.show(parent, get_map()->get_current_movie(), style);
475      }
476      break;
477
478    case G1_EDITOR_SELECT_ALL_VERTS :
479      select_all_verts();
480      break;
481
482    case G1_EDITOR_1_VIEW:
483    {
484      destroy_views();
485      t_views=1;
486      create_views();
487    } break;
488
489    case G1_EDITOR_TICK_MAP:
490    {
491      if (edit_mode && have_map())
492      {
493        get_map()->think_objects();
494        g1_remove_man.process_requests();
495        li_call("redraw");
496      }
497    } break;
498
499    case G1_EDITOR_PROFILE:
500    {
501      sw32 x=0, y=0;
502      i4_user_message_event_class *ue=new i4_user_message_event_class(G1_EDITOR_PROFILE_CLOSED);
503      i4_event_reaction_class *prof_closed;
504      prof_closed=new i4_event_reaction_class(this, ue);
505      i4_profile_watch(style, parent, x,y, 200,280,!profile_view, prof_closed);
506      profile_view=!profile_view;
507    } break;
508
509    case G1_EDITOR_DEBUG:
510    {
511      if (debug_view) {
512        g1_debug_close(style);
513        debug_view = 0;
514      }
515      else {
516        i4_user_message_event_class *ue=
517          new i4_user_message_event_class(G1_EDITOR_DEBUG_CLOSED);
518        i4_event_reaction_class *debug_closed=
519          new i4_event_reaction_class(this, ue);
520        g1_debug_open(style, parent, g1_ges("debug_title"), 3, debug_closed);
521        debug_view=1;
522      }
523    } break;
524
525    case G1_EDITOR_4_VIEWS:
526    {
527      destroy_views();
528      t_views=4;
529      create_views();
530    } break;
531
532    case G1_EDITOR_RECALC_LIGHT :
533//       if (map)
534//         calc_map_lighting(0,0, get_map()->width(), get_map()->height());
535      break;
536
537    case G1_EDITOR_MERGE_TERRAIN :
538      merge_terrain();
539      break;
540
541    case G1_EDITOR_FLATTEN_TERRAIN :
542      flatten_terrain();
543      break;
544
545    case G1_EDITOR_SMOOTH_TERRAIN :
546      smooth_terrain();
547      break;
548
549    case G1_EDITOR_NOISE_TERRAIN :
550      noise_terrain();
551      break;
552
553    case G1_EDITOR_LOAD_HEIGHT_MAP :
554      load_height_bitmap();
555      break;
556
557    case G1_EDITOR_SAVE_HEIGHT_MAP :
558      save_height_bitmap();
559      break;
560
561    case G1_EDITOR_FOG_ALL :
562      break;
563     
564    case G1_EDITOR_FOG_NONE :
565      break;
566
567    case G1_EDITOR_SET_SKY :
568      create_sky_window();      // defined in editor/sky.cc
569      break;
570
571    case G1_EDITOR_SNAP_CENTER :
572      g1_edit_state.snap=g1_edit_state_class::SNAP_CENTER;
573      break;
574
575    case G1_EDITOR_NO_SNAP :
576      g1_edit_state.snap=g1_edit_state_class::NO_SNAP;
577      break;
578
579    case G1_EDITOR_SNAP_ORIGIN :
580      g1_edit_state.snap=g1_edit_state_class::SNAP_ORIGIN;
581      break;
582
583
584  }
585}
586
587void g1_editor_class::close_modal()
588{
589  if (modal_window.get())
590  {
591    style->close_mp_window(modal_window.get());
592    modal_window=0;
593  }
594}
595
596
597
598char *cmd_2_enum[]=
599{
600  "File/New",                    // G1_EDITOR_NEW,
601  "File/Save",                   // G1_EDITOR_SAVE,
602  "File/Save As",                // G1_EDITOR_SAVEAS,
603  "File/Open",                   // G1_EDITOR_LOAD,
604  "",                            // G1_EDITOR_MERGE_TERRAIN,
605  "File/Exit",                   // G1_EDITOR_EXIT,
606
607  "Edit/Undo",                   // G1_EDITOR_UNDO,
608  "Edit/Redo",                   // G1_EDITOR_REDO,
609  "",                            // G1_EDITOR_CUT,
610  "",                            // G1_EDITOR_COPY,
611  "",                            // G1_EDITOR_PASTE,
612  "Edit/Toggle Menu",            // G1_EDITOR_TOGGLE,
613  "Edit/No Snap",                // G1_EDITOR_NO_SNAP,
614  "Edit/Snap Cell Center",       // G1_EDITOR_SNAP_CENTER,
615  "Edit/Snap Cell Origin",       // G1_EDITOR_SNAP_ORIGIN,
616
617
618  "Tools/Objects",               // G1_EDITOR_WINDOW_OBJECTS,
619  "Tools/Scenes",                // G1_EDITOR_WINDOW_SCENES,
620  "Tools/Radar",                 // G1_EDITOR_WINDOW_RADAR,
621  "View/1 View",                 // G1_EDITOR_1_VIEW,
622  "View/4 Views",                // G1_EDITOR_4_VIEWS,
623  "Tools/Tiles",                 // G1_EDITOR_TILE_PICKER,
624
625  "",                            // G1_EDITOR_RECALC_LIGHT,
626  "Terrain/Select All",          // G1_EDITOR_SELECT_ALL_VERTS,
627  "Map/Resize",                  // G1_EDITOR_RESIZE_MAP,
628  "Map/Change Sky",              // G1_EDITOR_SET_SKY,
629
630  "Map/Fog Out",                 // G1_EDITOR_FOG_ALL,
631  "Map/Unfog",                   // G1_EDITOR_FOG_NONE,
632
633  "Map/Simulate Tick",           // G1_EDITOR_TICK_MAP,
634  "Tools/Profile",               // G1_EDITOR_PROFILE,
635  "Tools/Debug",                 // G1_EDITOR_DEBUG,
636  "Tools/AI",                    // G1_EDITOR_AI_WINDOW,
637
638  "Terrain/Load Image Heightmap",// G1_EDITOR_LOAD_HEIGHT_MAP,
639  "Terrain/Save Image Heightmap",// G1_EDITOR_SAVE_HEIGHT_MAP,
640
641  "Terrain/Flatten Selected",    // G1_EDITOR_FLATTEN_TERRAIN,
642  "Terrain/Smooth Selected",     // G1_EDITOR_SMOOTH_TERRAIN,
643  "Terrain/Add Noise to Selected",  // G1_EDITOR_NOISE_TERRAIN,
644
645  "File/Open DLL",               // G1_EDITOR_OPEN_DLL,
646  0};
647
648 
649
650// these ID's are defined in mess_id.hh
651void g1_editor_class::receive_event(i4_event *ev)
652{
653  if (ev->type()==i4_event::USER_MESSAGE)
654  {
655    CAST_PTR(uev, i4_user_message_event_class, ev);
656    switch (uev->sub_type)
657    {           
658      case G1_EDITOR_TERRAIN_NOISE_OK :
659        noise_terrain_ok();
660        break;
661
662
663      case G1_EDITOR_SET_SKY_OK :
664        set_sky();                // defined in editor/sky.cc
665        break;
666
667      case G1_TMERGE_FILE_OPEN_OK :
668        merge_terrain_ok(uev);
669        break;
670
671      case G1_FILE_OPEN_OK :
672        open_file_ok(uev);
673        break;
674
675      case G1_OPEN_DLL_OK :
676        open_dll_ok(uev);
677        break;
678
679
680      case G1_FILE_SAVEAS_OK :
681        open_saveas_ok(uev);
682        break;
683
684      case G1_EDITOR_LOAD_TERRAIN_HEIGHT_OK :
685        load_height_bitmap_ok(ev);
686        break;
687
688      case G1_EDITOR_SAVE_TERRAIN_HEIGHT_OK :
689        save_height_bitmap_ok(ev);
690        break;
691         
692      case G1_EDITOR_RESIZE_PLACE_LT :
693      case G1_EDITOR_RESIZE_PLACE_CT :
694      case G1_EDITOR_RESIZE_PLACE_RT :
695      case G1_EDITOR_RESIZE_PLACE_LC :
696      case G1_EDITOR_RESIZE_PLACE_CC :
697      case G1_EDITOR_RESIZE_PLACE_RC :
698      case G1_EDITOR_RESIZE_PLACE_BL :
699      case G1_EDITOR_RESIZE_PLACE_BC :
700      case G1_EDITOR_RESIZE_PLACE_BR :
701        resize_dialog.orient=uev->sub_type-G1_EDITOR_RESIZE_PLACE_LT;
702        break;
703
704
705      case G1_EDITOR_RESIZE_MAP_OK :
706        resize_level();
707        break;
708
709      case G1_EDITOR_NEW_OK :
710        new_level_from_dialog();
711        break;
712       
713
714      case G1_EDITOR_MODAL_BOX_CANCEL :
715        close_modal();
716        break;
717     
718      case G1_EDITOR_MODAL_CLOSED :
719        modal_window=0;
720        break;
721
722       
723      case G1_EDITOR_AI_WINDOW_CLOSED :
724        path_window=0;
725        break;
726       
727
728      case G1_EDITOR_PROFILE_CLOSED :
729      {
730        profile_view=0;
731      } break;
732
733      case G1_EDITOR_DEBUG_CLOSED :
734      {
735        debug_view=0;
736      } break;
737    }
738  }
739  else
740  {     
741    g1_cwin_man_class::receive_event(ev);
742  }
743
744}
745
746i4_image_class *g1_editor_class::load_compatiable_image(const i4_const_str &fname)
747{
748  i4_image_class *im=i4_load_image(fname);
749  if (im)
750  {
751    i4_draw_context_class c(0,0, im->width()-1, im->height()-1);
752
753    i4_image_class *i=g1_render.r_api->create_compatible_image(im->width(), im->height());
754    if (!i)
755    {
756      delete im;
757      return 0;
758    }
759
760    im->put_image(i, 0,0, c);
761    delete im;
762    return i;     
763  }
764  return 0;
765}
766
767
768li_object *g1_old_pull_menu_command(li_object *o, li_environment *env)
769{
770  char *cmd_name=li_symbol::get(env->current_function(),env)->name()->value();
771 
772  int id=0;
773  for (char **cmd=cmd_2_enum; *cmd; cmd++, id++)
774    if (strcmp(*cmd, cmd_name)==0)
775      g1_editor_instance.do_command(id);
776 
777  return 0;
778}
779
780void g1_editor_class::redraw_all()
781{
782  for (int i=0; i<t_views; i++)
783    if (views[i])
784      views[i]->request_redraw(i4_F);
785}
786
787li_object *g1_editor_redraw_all(li_object *o, li_environment *env)
788{
789  g1_editor_instance.redraw_all();
790  return 0;
791}
792
793void g1_editor_class::init(i4_parent_window_class *_parent,
794                           i4_graphical_style_class *_style,
795                           i4_image_class *_root_image,
796                           i4_display_class *display,
797                           i4_window_manager_class *wm)
798
799{
800  li_add_function("redraw_all", g1_editor_redraw_all);
801
802  for (char **cmd=cmd_2_enum; *cmd; cmd++)
803    li_add_function(*cmd, g1_old_pull_menu_command); 
804 
805  g1_cwin_man_class::init(_parent, _style, _root_image, display, wm);
806
807  e_strs.load(i4gets("editor_strs"));
808
809
810  pick_act=load_compatiable_image(e_strs.get("pick_act"));
811  pick_pass=load_compatiable_image(e_strs.get("pick_pass"));
812
813  views[0]=0;
814
815  menu=0;
816
817  delete_icon=i4_load_image(e_strs.get("delete_icon")); 
818
819
820  i4_bool determantistic=i4_F;
821  for (int i=0; i<i4_global_argc; i++)
822    if (i4_global_argv[i]=="-deterministic")
823      determantistic=i4_T;
824
825  if (!determantistic)
826    i4_init_gui_status(wm, display);
827
828}
829
830void g1_editor_class::uninit()
831{
832  close_modal();
833
834  i4_uninit_gui_status();
835
836  for (g1_mode_creator *mc=g1_mode_creator::first; mc; mc=mc->next)
837    mc->cleanup();
838
839  if (debug_view) {
840    g1_debug_close(style);
841    debug_view = 0;
842  }
843
844
845  if (pick_act)
846    delete pick_act;
847
848  if (pick_pass)
849    delete pick_pass; 
850
851  delete menu;
852  menu=0;
853
854  delete delete_icon;
855   
856  g1_edit_state.uninit(); 
857}
858
859void g1_controller_edit_class::changed()
860{
861  g1_editor_instance.changed();   // so the user can save
862}
863
864
865
866void g1_editor_class::set_tool_window(i4_window_class **window)
867{
868  if (tool_window && tool_window!=window)
869  {
870    delete *tool_window;
871    *tool_window=0;
872    tool_window=0;
873  }
874
875  if (parent)
876  {
877    parent->add_child(parent->width()-(*window)->width(),
878                      0,
879                      (*window));
880    tool_window=window;
881  } else
882  {
883    delete *window;
884    window=0;
885  }
886}
887
888
889void g1_controller_edit_class::display_edit_win()  // defined in editor.cc
890{
891  g1_editor_instance.set_tool_window(&edit_win);
892}
893
894
895void g1_controller_edit_class::move_selected_heights(sw32 z_change)
896{
897  g1_editor_instance.unmark_all_selected_verts_for_undo_save();
898  g1_editor_instance.mark_selected_verts_for_undo_save();
899  g1_editor_instance.add_undo(G1_MAP_SELECTED_VERTS);
900
901
902  w32 w=(get_map()->width()+1), h=(get_map()->height()+1),c;
903  g1_map_vertex_class *v=get_map()->vertex(0,0);
904
905  i4_status_class *status = i4_create_status(g1_ges("moving vertices"));
906
907  for (sw32 vy=0; vy<h; vy++)
908  {
909    if (status)
910      status->update(vy/(float)h);
911
912    for (sw32 vx=0; vx<w; vx++, v++)
913    {
914      if (v->is_selected())
915      {
916        w8 nh;
917
918        if ((sw32)v->height+z_change<0)
919          nh=0;
920        else if ((sw32)v->height+z_change>255)
921          nh=255;
922        else
923          nh=v->height+z_change;
924
925        get_map()->change_vert_height(vx,vy, nh);
926      }
927    }
928  }
929
930  if (status)
931    delete status;
932
933  changed();
934  refresh();
935}
936
937
938void g1_controller_edit_class::change_light_direction()
939{
940  if (g1_map_is_loaded())
941  {
942    g1_editor_instance.add_undo(G1_MAP_VERTS | G1_MAP_LIGHTS);
943
944
945    i4_3d_vector one_z(0,0,-1), center, light;
946    transform.transform(one_z, light);
947    transform.transform(i4_3d_vector(0,0,0), center);
948    light-=center;
949
950
951
952    changed();
953    refresh();
954  } 
955}
956
957void g1_editor_class::select_all_verts()
958{
959  add_undo(G1_MAP_VERTS);
960
961  sw32 w=get_map()->width(), h=get_map()->height();
962
963  for (int j=0; j<=h; j++)
964    for (int i=0; i<=w; i++)
965      get_map()->vertex(i,j)->set_is_selected(i4_T);
966
967  changed();
968  li_call("redraw");
969}
970
971
972void g1_editor_class::open_file()
973{
974  i4_str *start_dir=0;
975
976  if (g1_map_is_loaded() && !g1_get_map()->get_filename().null())
977  {
978    i4_filename_struct fn;
979    i4_split_path(g1_get_map()->get_filename(), fn);
980
981    if (fn.path[0])
982      start_dir=new i4_str(fn.path);
983  }
984
985  if (!start_dir)
986    start_dir=new i4_str(get_editor_string("open_start_dir"));
987
988  i4_create_file_open_dialog(style,
989                             get_editor_string("open_title"),
990                             *start_dir,
991                             get_editor_string("open_file_mask"),
992                             get_editor_string("open_mask_name"),
993                             this,
994                             G1_FILE_OPEN_OK,
995                             G1_FILE_OPEN_CANCEL);
996
997  delete start_dir;
998}
999
1000
1001void g1_editor_class::open_dll()
1002{
1003  i4_create_file_open_dialog(style,
1004                             get_editor_string("open_dll_title"),
1005                             i4_const_str(i4_dll_dir),
1006                             get_editor_string("open_dll_file_mask"),
1007                             get_editor_string("open_dll_mask_name"),
1008                             this,
1009                             G1_OPEN_DLL_OK,
1010                             G1_FILE_OPEN_CANCEL);
1011}
1012
1013
1014
1015void g1_editor_class::open_saveas()
1016{
1017  if (have_map())
1018  {
1019    i4_create_file_save_dialog(style,
1020                               get_map()->get_filename(),
1021                               get_editor_string("open_title"),
1022                               get_editor_string("open_start_dir"),
1023                               get_editor_string("open_file_mask"),
1024                               get_editor_string("open_mask_name"),
1025                               this,
1026                               G1_FILE_SAVEAS_OK,
1027                               G1_FILE_OPEN_CANCEL);
1028   
1029  }
1030}
1031
1032
1033void g1_editor_class::open_file_ok(i4_user_message_event_class *ev)
1034{
1035  CAST_PTR(f, i4_file_open_message_class, ev);
1036
1037  g1_load_level(*f->filename, 1, 0);
1038
1039}
1040
1041void g1_editor_class::open_dll_ok(i4_user_message_event_class *ev)
1042{
1043  CAST_PTR(f, i4_file_open_message_class, ev);
1044  if (f->filename)
1045    i4_dll_man.load(*f->filename);
1046}
1047
1048void g1_editor_class::open_saveas_ok(i4_user_message_event_class *ev)
1049{
1050  if (have_map())
1051  {
1052
1053    CAST_PTR(f, i4_file_open_message_class, ev);
1054
1055    get_map()->set_filename(*f->filename);
1056
1057    save();   
1058  }
1059}
1060
1061
1062i4_parent_window_class *g1_editor_class::create_modal(w32 w, w32 h, char *title_res)
1063{
1064  close_modal();
1065
1066  i4_object_message_event_class *closed_modal;
1067  closed_modal=new i4_object_message_event_class(this, G1_EDITOR_MODAL_CLOSED);
1068
1069
1070  modal_window=style->create_mp_window(-1, -1, w, h,
1071                                       g1_ges(title_res),
1072                                       new i4_event_reaction_class(this, closed_modal));
1073
1074  return modal_window.get();
1075}
1076
1077
1078void g1_editor_class::mark_selected_verts_for_undo_save()
1079{
1080  if (have_map())
1081  {
1082    int t=(get_map()->width()+1) * (get_map()->height()+1);
1083    g1_map_vertex_class *v=get_map()->verts;
1084
1085    for (int i=0; i<t; i++, v++)
1086      if (v->is_selected())
1087        v->set_need_undo(i4_T);
1088  }
1089}
1090
1091
1092void g1_editor_class::unmark_all_selected_verts_for_undo_save()
1093{
1094  int t=(get_map()->width()+1) * (get_map()->height()+1);
1095  g1_map_vertex_class *v=get_map()->verts;
1096
1097  for (int i=0; i<t; i++, v++)
1098    v->set_need_undo(i4_F);
1099}
1100
1101
1102
1103
1104void g1_editor_class::save_views(g1_saver_class *fp)
1105{
1106  g1_cwin_man_class::save_views(fp);
1107
1108  for (int i=0; i<t_views; i++)
1109  {
1110    char section_name[50];
1111    sprintf(section_name, "editor view %d v1", i);
1112    fp->mark_section(section_name);
1113
1114    if (views[i])
1115      view_states[i]=views[i]->view;
1116
1117    view_states[i].save(fp);
1118  }
1119}
1120
1121void g1_editor_class::load_views(g1_loader_class *fp)
1122{
1123  g1_cwin_man_class::load_views(fp);
1124
1125  if (!fp)
1126  {
1127    for (int i=0; i<MAX_VIEWS; i++)
1128    {
1129      if (views[i])
1130        views[i]->view.load(0);
1131      else
1132        view_states[i].load(0);
1133    }
1134  }
1135  else
1136  {
1137    for (int i=0; 1; i++)
1138    {
1139      char section_name[50];
1140      sprintf(section_name, "editor view %d v1", i);
1141      if (!fp->goto_section(section_name))
1142        return ;
1143
1144      view_states[i].load(fp);
1145      if (views[i])
1146        views[i]->view=view_states[i];
1147    }
1148  }
1149}
1150
1151
1152const i4_const_str &g1_ges(char *res)
1153{
1154  return g1_editor_instance.get_editor_string(res);
1155}
1156
1157g1_controller_edit_class *g1_editor_class::get_current_view()
1158{
1159  for (int i=0; i<MAX_VIEWS; i++)
1160    if (views[i]==g1_current_controller.get())
1161      return views[i];
1162 
1163  return 0; 
1164}
Note: See TracBrowser for help on using the repository browser.