ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
Revision: 1.51
Committed: Sat Mar 10 22:18:51 2007 UTC (17 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.50: +10 -1 lines
Log Message:
another if cascade for searching the right map (will hopefully fix all
other places where no care is taken about .map)

File Contents

# User Rev Content
1 elmex 1.1 package GCE::MapEditor;
2    
3     =head1 NAME
4    
5     GCE::MapEditor - the map editing widget
6    
7     =cut
8    
9     use Gtk2;
10     use Gtk2::Gdk::Keysyms;
11     use Gtk2::SimpleMenu;
12    
13     use Crossfire;
14 root 1.3 use Crossfire::Map;
15 elmex 1.1 use Crossfire::MapWidget;
16    
17     use GCE::AttrEdit;
18 elmex 1.22 use GCE::Util;
19 elmex 1.44 use GCE::HashDialog;
20 elmex 1.1
21 elmex 1.49 use POSIX qw/strftime/;
22    
23 elmex 1.4 use Glib::Object::Subclass
24 elmex 1.6 Gtk2::Window;
25 elmex 1.1
26 elmex 1.45 use Storable qw/dclone/;
27    
28 elmex 1.1 use strict;
29    
30 elmex 1.44 #################################################################
31     ###### WINDOW MANAGEMENT ########################################
32     #################################################################
33    
34     sub save_layout {
35     my ($self) = @_;
36    
37     $self->{attach_editor}->save_layout if $self->{attach_editor};
38     $self->{map_properties}->save_layout if $self->{map_properties};
39     $self->{meta_info_win}->save_layout if $self->{meta_info_win};
40 elmex 1.49
41     $main::CFG->{map_info} = main::get_pos_and_size ($self->{map_info})
42     if $self->{map_info};
43 elmex 1.44 }
44    
45     sub close_windows {
46     my ($self) = @_;
47    
48     $self->{attach_editor}->destroy if $self->{attach_editor};
49     $self->{map_properties}->destroy if $self->{map_properties};
50     $self->{meta_info_win}->destroy if $self->{meta_info_win};
51     }
52    
53     #################################################################
54     ###### MENU MANAGEMENT ##########################################
55     #################################################################
56    
57 elmex 1.35 sub do_context_menu {
58     my ($self, $map, $event) = @_;
59    
60     my ($x, $y) = $map->coord ($event->x, $event->y);
61    
62     my $menu = Gtk2::Menu->new;
63     foreach my $cm (
64     [
65     Follow => sub {
66 elmex 1.36 $::MAINWIN->{edit_collection}{followexit}->edit ($map, $x, $y, $self)
67 elmex 1.38 },
68 elmex 1.35 ]
69     ) {
70     my $item = Gtk2::MenuItem->new ($cm->[0]);
71     $menu->append ($item);
72     $item->show;
73     $item->signal_connect (activate => $cm->[1]);
74     }
75 elmex 1.38
76 elmex 1.47 $menu->append (my $sep = new Gtk2::SeparatorMenuItem);
77     $sep->show;
78 elmex 1.38
79     for my $sr (reverse $self->get_stack_refs ($map, $x, $y)) {
80     my $item = Gtk2::MenuItem->new ($sr->longname);
81 elmex 1.47 $menu->append ($item);
82     $item->set_submenu (my $smenu = new Gtk2::Menu);
83    
84     for my $act (
85     [ 'Add inventory' => sub { $_[0]->add_inv ($::MAINWIN->get_pick) } ],
86     [ 'Find in picker' => sub { $::MAINWIN->open_pick_window ({ selection => $sr->picker_folder }) } ],
87     ) {
88     my $sitem = Gtk2::MenuItem->new ($act->[0]);
89     $smenu->append ($sitem);
90     $sitem->signal_connect (activate => sub { $act->[1]->($sr) });
91     $sitem->show;
92     }
93    
94 elmex 1.38 $item->show;
95     }
96    
97 elmex 1.35 $menu->popup (undef, undef, undef, undef, $event->button, $event->time);
98     }
99    
100 root 1.9 sub build_menu {
101     my ($self) = @_;
102    
103     my $menu_tree = [
104     _File => {
105     item_type => '<Branch>',
106     children => [
107     "_Save" => {
108 root 1.10 callback => sub { $self->save_map },
109 root 1.9 accelerator => '<ctrl>S'
110     },
111 root 1.10 "Save As" => {
112     callback => sub { $self->save_map_as },
113     },
114 elmex 1.49 "Map _Info" => {
115     callback => sub { $self->open_map_info },
116     accelerator => "<ctrl>I",
117     },
118 elmex 1.42 "Map _Properties" => {
119 elmex 1.32 callback => sub { $self->open_map_prop },
120     accelerator => "<ctrl>P"
121     },
122 elmex 1.42 "Map _Attachments" => {
123     callback => sub { $self->open_attach_edit },
124     accelerator => "<ctrl>A"
125     },
126 elmex 1.44 "Map Meta _Info" => {
127     callback => sub { $self->open_meta_info },
128     },
129 elmex 1.45 Upload => {
130     item_type => '<Branch>',
131     children => [
132     "Upload for testing" => {
133     callback => sub { $self->upload_map_test },
134     },
135     "Upload for inclusion" => {
136     callback => sub { $self->upload_map_incl },
137     },
138     ]
139     },
140 elmex 1.32 "_Map Resize" => {
141     callback => sub { $self->open_resize_map },
142     },
143 root 1.13 "Close" => {
144 elmex 1.31 callback => sub { $self->destroy },
145 root 1.13 },
146 root 1.10 ]
147 root 1.9 },
148     _Edit => {
149     item_type => '<Branch>',
150     children => [
151     "_Undo" => {
152     callback => sub { $self->undo },
153 elmex 1.17 accelerator => "<ctrl>Z"
154 root 1.9 },
155     "_Redo" => {
156     callback => sub { $self->redo },
157 elmex 1.17 accelerator => "<ctrl>Y"
158     },
159 root 1.9 ]
160     },
161 elmex 1.27 _Go => {
162     item_type => '<Branch>',
163     children => [
164     "_Up" => {
165     callback => sub { $self->follow ('u') },
166 elmex 1.33 accelerator => "<ctrl>Up"
167 elmex 1.27 },
168     "_Down" => {
169     callback => sub { $self->follow ('d') },
170 elmex 1.33 accelerator => "<ctrl>Down"
171 elmex 1.27 },
172     "_Right" => {
173     callback => sub { $self->follow ('r') },
174 elmex 1.33 accelerator => "<ctrl>Right"
175 elmex 1.27 },
176     "_Left" => {
177     callback => sub { $self->follow ('l') },
178 elmex 1.33 accelerator => "<ctrl>Left"
179 elmex 1.27 },
180     ]
181     },
182 elmex 1.29 _Help => {
183     item_type => '<Branch>',
184     children => [
185 elmex 1.30 _Manual => {
186 elmex 1.29 callback => sub { $::MAINWIN->show_help_window },
187     accelerator => "<ctrl>H"
188     },
189     ]
190     },
191 root 1.9 ];
192    
193     my $men =
194     Gtk2::SimpleMenu->new (
195     menu_tree => $menu_tree,
196     default_callback => \&default_cb,
197     );
198    
199 elmex 1.23 for (
200     [i => 'pick'],
201     [p => 'place'],
202 elmex 1.24 [e => 'erase'],
203     [s => 'select'],
204     [l => 'eval'],
205 elmex 1.37 [t => 'connect'],
206 elmex 1.24 [f => 'followexit']
207 elmex 1.23 )
208     {
209 elmex 1.24 my $tool = $_->[1];
210 elmex 1.23 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible',
211 elmex 1.24 sub { $::MAINWIN->set_edit_tool ($tool) });
212 elmex 1.23 }
213    
214 elmex 1.39 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'r'}, ['control-mask'], 'visible',
215     sub { $self->redo });
216    
217 root 1.9 $self->add_accel_group ($men->{accel_group});
218    
219     return $men->{widget};
220     }
221    
222 elmex 1.44 #################################################################
223     ###### EDIT TOOL STUFF ##########################################
224     #################################################################
225    
226 elmex 1.31 sub set_edit_tool {
227     my ($self, $tool) = @_;
228    
229     $self->{etool} = $tool;
230    
231     if ($self->ea->special_arrow) {
232     $self->{map}{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow));
233 elmex 1.34 } else {
234     # FIXME: Get the original cursor and insert it here
235     $self->{map}{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR'));
236 elmex 1.31 }
237     }
238    
239 elmex 1.19 sub ea {
240     my ($self) = @_;
241 elmex 1.31 $self->{ea_alt} || $self->{etool};
242 elmex 1.19 }
243    
244 elmex 1.34 sub start_drawmode {
245     my ($self, $map) = @_;
246    
247     $self->{draw_mode} and return;
248    
249     # XXX: is this okay? my ($x, $y) = $map->coord ($event->x, $event->y);
250     my ($x, $y) = $map->coord ($map->get_pointer);
251    
252     my $ea = $self->ea;
253    
254 elmex 1.36 $ea->begin ($map, $x, $y, $self);
255    
256     $ea->edit ($map, $x, $y, $self)
257 elmex 1.34 if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height};
258    
259     $self->{draw_mode} = [$x, $y];
260     }
261    
262     sub stop_drawmode {
263     my ($self, $map) = @_;
264    
265     $self->{draw_mode} or return;
266    
267     my ($x, $y) = $map->coord ($map->get_pointer);
268    
269     my $ea = $self->ea;
270     $ea->end ($map, $x, $y, $self);
271    
272     delete $self->{draw_mode};
273     }
274    
275 elmex 1.44 #################################################################
276     ###### UTILITY FUNCTIONS ########################################
277     #################################################################
278    
279     sub follow {
280     my ($self, $dir) = @_;
281    
282     my %dir_to_path = (
283     u => 'tile_path_1',
284     d => 'tile_path_3',
285     r => 'tile_path_2',
286     l => 'tile_path_4',
287     );
288    
289     defined $dir_to_path{$dir}
290     or return;
291     my $map = $self->{map}{map}{info}{$dir_to_path{$dir}}
292     or return;
293    
294     $map = map2abs ($map, $self);
295     $::MAINWIN->open_map_editor ($map);
296     }
297    
298 elmex 1.16 # FIXME: Fix the automatic update of the attribute editor! and also the stack view!
299 root 1.9 sub undo {
300     my ($self) = @_;
301 elmex 1.8
302 root 1.9 my $map = $self->{map}; # the Crossfire::MapWidget
303 elmex 1.1
304 root 1.9 $map->{undo_stack_pos}
305     or return;
306 elmex 1.1
307 root 1.9 $map->change_swap ($map->{undo_stack}[--$map->{undo_stack_pos}]);
308     }
309 elmex 1.1
310 elmex 1.38 sub get_stack_refs {
311     my ($self, $map, $x, $y) = @_;
312    
313     my $cstack = $map->get ($x, $y);
314    
315     return [] unless @$cstack;
316    
317     my @refs;
318    
319     for my $arch (@$cstack) {
320     my ($ox, $oy) = ($x, $y);
321     if ($arch->{_virtual}) {
322     $ox = $arch->{virtual_x};
323     $oy = $arch->{virtual_y};
324     $arch = $arch->{_virtual};
325     $cstack = $map->get ($ox, $oy);
326     # XXX: This heavily blows up if $arch isn't on $cstack now.. and it actually really does :(
327     }
328    
329     push @refs,
330     GCE::ArchRef->new (
331     arch => $arch,
332     cb => sub {
333     $map->change_begin ('attredit');
334     $map->change_stack ($ox, $oy, $cstack);
335    
336     if (my $changeset = $map->change_end) {
337     splice @{ $map->{undo_stack} ||= [] },
338     $map->{undo_stack_pos}++, 1e6,
339     $changeset;
340     }
341     }
342     );
343     }
344    
345     return @refs;
346     }
347    
348 root 1.9 sub redo {
349     my ($self) = @_;
350 elmex 1.7
351 root 1.9 my $map = $self->{map}; # the Crossfire::MapWidget
352 elmex 1.7
353 elmex 1.14 $map->{undo_stack}
354     and $map->{undo_stack_pos} < @{$map->{undo_stack}}
355     or return;
356 elmex 1.1
357 root 1.9 $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]);
358 root 1.3 }
359    
360 elmex 1.43 sub load_meta_info {
361     my ($mapfile) = @_;
362     if (-e "$mapfile.meta") {
363     open my $metafh, "<", "$mapfile.meta"
364     or warn "Couldn't open meta file $mapfile.meta: $!";
365     my $metadata = do { local $/; <$metafh> };
366     return Crossfire::from_json ($metadata);
367     }
368     }
369    
370     sub save_meta_info {
371     my ($mapfile, $metainfo) = @_;
372     open my $metafh, ">", "$mapfile.meta"
373     or warn "Couldn't write meta file $mapfile.meta: $!";
374     print $metafh Crossfire::to_json ($metainfo);
375     }
376    
377 root 1.3 sub open_map {
378 elmex 1.26 my ($self, $path, $key) = @_;
379    
380     $self->{mapkey} = $key;
381 root 1.3
382 elmex 1.18 if (ref $path) {
383     $self->{map}->set_map ($path);
384 elmex 1.43 delete $self->{meta_info};
385 elmex 1.39 $self->set_title ('<ram>');
386 elmex 1.18
387     } else {
388 elmex 1.51 my $ok = 0;
389 elmex 1.48 unless (-e $path && -f $path) {
390 elmex 1.51 unless ($path =~ m/\.map$/) { # yuck
391     my $p = $path . '.map';
392     if ($ok = -e $p && -f $p) {
393     $path = $p;
394     }
395     }
396     }
397     unless ($ok) {
398     die "Couldn't open '$path' or '$path.map': No such file or it is not a file.\n";
399 elmex 1.48 }
400 elmex 1.18 $self->{path} = $path;
401     $self->{map}->set_map (my $m = new_from_file Crossfire::Map $path);
402 elmex 1.43 $self->{meta_info} = load_meta_info ($path);
403 elmex 1.39 $self->set_title ("gce - map editor - $self->{path}");
404 elmex 1.18 }
405 elmex 1.44 $self->close_windows;
406 root 1.3 }
407    
408 root 1.13 sub save_map {
409     my ($self) = @_;
410    
411 elmex 1.19 if ($self->{path}) {
412     $self->{map}{map}->write_file ($self->{path});
413 elmex 1.43 if ($self->{meta_info}) {
414     save_meta_info ($self->{path}, $self->{meta_info});
415     }
416 elmex 1.22 quick_msg ($self, "saved to $self->{path}");
417 elmex 1.39 $self->set_title ("gce - map editor - $self->{path}");
418 elmex 1.22 } else {
419     $self->save_map_as;
420 elmex 1.19 }
421 root 1.13 }
422    
423     sub save_map_as {
424     my ($self) = @_;
425 elmex 1.19
426 elmex 1.22 my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1, $self->{path});
427 elmex 1.19
428     if ('ok' eq $fc->run) {
429    
430     $::MAINWIN->{fc_last_folder} = $fc->get_current_folder;
431     $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++;
432    
433     $self->{map}{map}->write_file ($self->{path} = $fc->get_filename);
434 elmex 1.43 if ($self->{meta_info}) {
435     save_meta_info ($self->{path}, $self->{meta_info});
436     }
437 elmex 1.22 quick_msg ($self, "saved to $self->{path}");
438 elmex 1.39 $self->set_title ("gce - map editor - $self->{path}");
439 elmex 1.19 }
440    
441     $fc->destroy;
442 root 1.13 }
443    
444 elmex 1.44 #################################################################
445     ###### DIALOGOUES ###############################################
446     #################################################################
447 elmex 1.17
448     sub open_resize_map {
449     my ($self) = @_;
450    
451 elmex 1.44 return if $self->{meta_info_win};
452 elmex 1.17
453 elmex 1.44 my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
454 elmex 1.17
455 elmex 1.44 $w->init (
456     dialog_default_size => [500, 200, 220, 20],
457     layout_name => 'resize_win',
458     title => 'resize map',
459     ref_hash => $self->{map}{map}{info},
460     dialog => [
461     [width => 'Width' => 'string'],
462     [height => 'Height' => 'string'],
463     ],
464 elmex 1.50 close_on_save => 1,
465 elmex 1.44 save_cb => sub {
466     my ($info) = @_;
467     $self->{map}{map}->resize ($info->{width}, $info->{height});
468     $self->{map}->invalidate_all;
469     }
470 elmex 1.27 );
471    
472 elmex 1.44 $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
473 elmex 1.27
474 elmex 1.44 $w->show_all;
475 elmex 1.27 }
476    
477 elmex 1.42 sub open_attach_edit {
478     my ($self) = @_;
479    
480     my $w = GCE::AttachEditor->new;
481     $w->set_attachment (
482     $self->{map}{map}{info}{attach},
483     sub {
484     if (@{$_[0]}) {
485     $self->{map}{map}{info}{attach} = $_[0]
486     } else {
487     delete $self->{map}{map}{info}{attach};
488     }
489     }
490     );
491     $self->{attach_editor} = $w;
492     $w->signal_connect (destroy => sub { delete $self->{attach_editor} });
493     $w->show_all;
494     }
495    
496 elmex 1.45 sub upload_map_incl {
497     my ($self) = @_;
498    
499     my $meta = dclone $self->{meta_info};
500    
501     my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
502    
503     $w->init (
504     dialog_default_size => [500, 300, 220, 20],
505     layout_name => 'map_upload_incl',
506     title => 'gce - map inclusion upload',
507     ref_hash => $meta,
508     text_entry => { key => 'changes', label => 'Changes (required for inclusion):' },
509     dialog => [
510     [gameserver => 'Game server' => 'label'],
511     [testserver => 'Test server' => 'label'],
512     [undef => x => 'sep' ],
513     [cf_login => 'Server login name' => 'string'],
514     [cf_password=> 'Password' => 'password'],
515     [path => 'Map path' => 'string'],
516     ],
517 elmex 1.50 close_on_save => 1,
518 elmex 1.45 save_cb => sub {
519     my ($meta) = @_;
520     warn "UPLOAD[".Crossfire::to_json ($meta)."]\n";
521     }
522     );
523    
524     $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
525    
526     $w->show_all;
527     }
528    
529     sub upload_map_test {
530     my ($self) = @_;
531    
532     my $meta = dclone $self->{meta_info};
533    
534     my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
535    
536     $w->init (
537     dialog_default_size => [500, 300, 220, 20],
538     layout_name => 'map_upload_test',
539     title => 'gce - map test upload',
540     ref_hash => $meta,
541     dialog => [
542     [gameserver => 'Game server' => 'string'],
543     [testserver => 'Test server' => 'string'],
544     [undef => x => 'sep' ],
545     [cf_login => 'Server login name' => 'string'],
546     [cf_password=> 'Password' => 'password'],
547     [path => 'Map path' => 'string'],
548     ],
549     save_cb => sub {
550     my ($meta) = @_;
551     warn "UPLOAD[".Crossfire::to_json ($meta)."]\n";
552     }
553     );
554    
555     $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
556    
557     $w->show_all;
558    
559    
560     }
561 elmex 1.44
562     sub open_meta_info {
563 elmex 1.42 my ($self) = @_;
564    
565 elmex 1.44 return if $self->{meta_info_win};
566    
567     my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
568    
569     $w->init (
570     dialog_default_size => [500, 300, 220, 20],
571     layout_name => 'meta_info_win',
572     title => 'meta info',
573     ref_hash => $self->{meta_info},
574     dialog => [
575     [path => 'Map path' => 'string'],
576     [cf_login => 'Login name' => 'string'],
577     [revision => 'CVS Revision' => 'label'],
578     [cvs_root => 'CVS Root' => 'label'],
579     [lib_root => 'LIB Root' => 'label'],
580     [testserver => 'Test server' => 'label'],
581     [gameserver => 'Game server' => 'label'],
582     ],
583     );
584    
585     $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
586    
587     $w->show_all;
588 elmex 1.42 }
589    
590 elmex 1.49 sub open_map_info {
591     my ($self) = @_;
592     return if $self->{map_info};
593    
594     my $w = $self->{map_info} = Gtk2::Window->new ('toplevel');
595     $w->set_title ("gcrossedit - map info");
596    
597     $w->add (my $vb = Gtk2::VBox->new);
598     $vb->add (my $sw = Gtk2::ScrolledWindow->new);
599     $sw->set_policy ('automatic', 'automatic');
600     $sw->add (my $txt = Gtk2::TextView->new);
601     $vb->pack_start (my $hb = Gtk2::HBox->new (1, 1), 0, 1, 0);
602     $hb->pack_start (my $svbtn = Gtk2::Button->new ("save"), 1, 1, 0);
603     $hb->pack_start (my $logbtn = Gtk2::Button->new ("add log"), 1, 1, 0);
604     $hb->pack_start (my $closebtn = Gtk2::Button->new ("close"), 1, 1, 0);
605    
606     my $buf = $txt->get_buffer ();
607     $buf->set_text ($self->{map}{map}{info}{msg});
608    
609     $svbtn->signal_connect (clicked => sub {
610     my $buf = $txt->get_buffer ();
611     my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0);
612     $self->{map}{map}{info}{msg} = $txt;
613     });
614    
615     $logbtn->signal_connect (clicked => sub {
616     my $buf = $txt->get_buffer ();
617     $buf->insert ($buf->get_start_iter, "- " . strftime ("%F %T %Z", localtime (time)) . " by " . ($main::CFG->{username} || $ENV{USER}) . ":\n");
618     $txt->set_buffer ($buf);
619     });
620    
621     $closebtn->signal_connect (clicked => sub {
622     $w->destroy;
623     });
624    
625     ::set_pos_and_size ($w, $main::CFG->{map_info}, 400, 400, 220, 20);
626     $w->signal_connect (destroy => sub {
627     delete $self->{map_info};
628     });
629     $w->show_all;
630     }
631    
632 elmex 1.17 sub open_map_prop {
633     my ($self) = @_;
634    
635 elmex 1.42 return if $self->{map_properties};
636    
637 elmex 1.44 my $w = $self->{map_properties} = GCE::HashDialogue->new ();
638 elmex 1.17
639 elmex 1.44 $w->init (
640     dialog_default_size => [500, 500, 220, 20],
641     layout_name => 'map_prop_win',
642     title => 'map properties',
643     ref_hash => $self->{map}{map}{info},
644 elmex 1.50 close_on_save => 1,
645 elmex 1.44 dialog => [
646 elmex 1.27 [qw/name Name string/],
647     [qw/region Region string/],
648     [qw/enter_x Enter-x string/],
649     [qw/enter_y Enter-y string/],
650     [qw/reset_timeout Reset-timeout string/],
651     [qw/swap_time Swap-timeout string/],
652 elmex 1.44 [undef, qw/x sep/],
653 elmex 1.27 [qw/difficulty Difficulty string/],
654     [qw/windspeed Windspeed string/],
655     [qw/pressure Pressure string/],
656     [qw/humid Humid string/],
657     [qw/temp Temp string/],
658     [qw/darkness Darkness string/],
659     [qw/sky Sky string/],
660     [qw/winddir Winddir string/],
661 elmex 1.44 [undef, qw/x sep/],
662 elmex 1.27 [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }],
663     [qw/height Height label/], # sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }],
664 elmex 1.44 [undef, qw/x sep/],
665     # [qw/msg Text text/],
666     # [qw/maplore Maplore text/],
667 elmex 1.27 [qw/outdoor Outdoor check/],
668     [qw/unique Unique check/],
669     [qw/fixed_resettime Fixed-resettime check/],
670 elmex 1.44 [undef, qw/x sep/],
671 elmex 1.27 [qw/tile_path_1 Northpath string/],
672     [qw/tile_path_2 Eastpath string/],
673     [qw/tile_path_3 Southpath string/],
674     [qw/tile_path_4 Westpath string/],
675     [qw/tile_path_5 Toppath string/],
676     [qw/tile_path_6 Bottompath string/],
677 elmex 1.44 [undef, qw/x sep/],
678     [undef, 'For shop description look in the manual',
679     'button', sub { $::MAINWIN->show_help_window }],
680 elmex 1.39 [qw/shopmin Shopmin string/],
681     [qw/shopmax Shopmax string/],
682     [qw/shoprace Shoprace string/],
683     [qw/shopgreed Shopgreed string/],
684     [qw/shopitems Shopitems string/],
685 elmex 1.44 ]
686     );
687 elmex 1.17
688 elmex 1.44 $w->signal_connect (destroy => sub { delete $self->{map_properties} });
689 elmex 1.17 $w->show_all;
690     }
691    
692 elmex 1.44 #################################################################
693     ###### MAP EDITOR INIT ##########################################
694     #################################################################
695    
696     sub INIT_INSTANCE {
697     my ($self) = @_;
698    
699     $self->set_title ('gce - map editor');
700     $self->add (my $vb = Gtk2::VBox->new);
701    
702     $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0);
703    
704     $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0);
705    
706     $map->signal_connect_after (key_press_event => sub {
707     my ($map, $event) = @_;
708    
709     my $kv = $event->keyval;
710    
711     my $ret = 0;
712    
713     my ($x, $y) = $map->coord ($map->get_pointer);
714     for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }],
715     [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }],
716     [c => sub { $::MAINWIN->{edit_collection}{select}->copy }],
717     [v => sub { $::MAINWIN->{edit_collection}{select}->paste ($map, $x, $y) }],
718     [n => sub { $::MAINWIN->{edit_collection}{select}->invoke }],
719     )
720     {
721     my $ed = $_;
722    
723     if ($kv == $Gtk2::Gdk::Keysyms{$ed->[0]}) {
724     my $was_in_draw = defined $self->{draw_mode};
725    
726     $self->stop_drawmode ($map)
727     if $was_in_draw && grep { $ed->[0] eq $_ } qw/Control_L Alt_L/;
728    
729     $ed->[1]->();
730     $ret = 1;
731    
732     $self->start_drawmode ($map)
733     if $was_in_draw && grep { $ed->[0] eq $_ } qw/Control_L Alt_L/;
734     }
735     }
736    
737     if ($self->ea->special_arrow) {
738     $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow));
739     } else {
740     # FIXME: Get the original cursor and insert it here
741     $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR'));
742     }
743    
744     $ret
745     });
746    
747     $map->signal_connect_after (key_release_event => sub {
748     my ($map, $event) = @_;
749    
750     my $ret = 0;
751    
752     if ($event->keyval == $Gtk2::Gdk::Keysyms{Control_L}
753     or $event->keyval == $Gtk2::Gdk::Keysyms{Alt_L})
754     {
755     my $was_in_draw = defined $self->{draw_mode};
756    
757     $self->stop_drawmode ($map)
758     if $was_in_draw;
759    
760     delete $self->{ea_alt};
761     $ret = 1;
762    
763     $self->start_drawmode ($map)
764     if $was_in_draw;
765     }
766    
767     if ($self->ea->special_arrow) {
768     $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow));
769     } else {
770     # FIXME: Get the original cursor and insert it here
771     $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR'));
772     }
773    
774     $ret
775     });
776     $map->signal_connect_after (button_press_event => sub {
777     my ($map, $event) = @_;
778    
779     if ((not $self->{draw_mode}) and $event->button == 1) {
780     my $ea = $self->ea;
781    
782     $self->start_drawmode ($map);
783    
784     $ea->want_cursor
785     or $map->disable_tooltip;
786    
787     return 1;
788     } elsif ($event->button == 3) {
789     $self->do_context_menu ($map, $event);
790     return 1;
791     }
792    
793     0
794     });
795    
796     $map->signal_connect_after (motion_notify_event => sub {
797     my ($map, $event) = @_;
798    
799     $self->{draw_mode}
800     or return;
801    
802     my $ea = $self->ea;
803    
804     my ($X, $Y) = @{$self->{draw_mode}}[0,1];
805     my ($x, $y) = $map->coord ($map->get_pointer);
806    
807     while ($x != $X || $y != $Y) {
808    
809     $X++ if $X < $x;
810     $X-- if $X > $x;
811     $Y++ if $Y < $y;
812     $Y-- if $Y > $y;
813    
814     unless ($ea->only_on_click) {
815     $ea->edit ($map, $X, $Y, $self)
816     if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height};
817     }
818     }
819    
820     @{$self->{draw_mode}}[0,1] = ($X, $Y);
821    
822     1
823     });
824    
825     $map->signal_connect_after (button_release_event => sub {
826     my ($map, $event) = @_;
827    
828     if ($self->{draw_mode} and $event->button == 1) {
829     my $ea = $self->ea;
830    
831     $self->stop_drawmode ($map);
832    
833     $ea->want_cursor
834     or $map->enable_tooltip;
835    
836     return 1;
837     }
838    
839     0
840     });
841    
842     ::set_pos_and_size ($self, $main::CFG->{map_window}, 500, 500, 200, 0);
843     }
844    
845 elmex 1.1 =head1 AUTHOR
846    
847     Marc Lehmann <schmorp@schmorp.de>
848     http://home.schmorp.de/
849    
850     Robin Redeker <elmex@ta-sa.org>
851     http://www.ta-sa.org/
852    
853     =cut
854 root 1.46
855     1
856 elmex 1.1