ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
Revision: 1.49
Committed: Fri Jan 5 19:20:44 2007 UTC (17 years, 5 months ago) by elmex
Branch: MAIN
Changes since 1.48: +51 -0 lines
Log Message:
added map info dialog where you can add logs now with timestamp and username,
which is by default the environment variable USER or a configured string in the
editor preferences/properties.

File Contents

# Content
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 use Crossfire::Map;
15 use Crossfire::MapWidget;
16
17 use GCE::AttrEdit;
18 use GCE::Util;
19 use GCE::HashDialog;
20
21 use POSIX qw/strftime/;
22
23 use Glib::Object::Subclass
24 Gtk2::Window;
25
26 use Storable qw/dclone/;
27
28 use strict;
29
30 #################################################################
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
41 $main::CFG->{map_info} = main::get_pos_and_size ($self->{map_info})
42 if $self->{map_info};
43 }
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 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 $::MAINWIN->{edit_collection}{followexit}->edit ($map, $x, $y, $self)
67 },
68 ]
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
76 $menu->append (my $sep = new Gtk2::SeparatorMenuItem);
77 $sep->show;
78
79 for my $sr (reverse $self->get_stack_refs ($map, $x, $y)) {
80 my $item = Gtk2::MenuItem->new ($sr->longname);
81 $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 $item->show;
95 }
96
97 $menu->popup (undef, undef, undef, undef, $event->button, $event->time);
98 }
99
100 sub build_menu {
101 my ($self) = @_;
102
103 my $menu_tree = [
104 _File => {
105 item_type => '<Branch>',
106 children => [
107 "_Save" => {
108 callback => sub { $self->save_map },
109 accelerator => '<ctrl>S'
110 },
111 "Save As" => {
112 callback => sub { $self->save_map_as },
113 },
114 "Map _Info" => {
115 callback => sub { $self->open_map_info },
116 accelerator => "<ctrl>I",
117 },
118 "Map _Properties" => {
119 callback => sub { $self->open_map_prop },
120 accelerator => "<ctrl>P"
121 },
122 "Map _Attachments" => {
123 callback => sub { $self->open_attach_edit },
124 accelerator => "<ctrl>A"
125 },
126 "Map Meta _Info" => {
127 callback => sub { $self->open_meta_info },
128 },
129 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 "_Map Resize" => {
141 callback => sub { $self->open_resize_map },
142 },
143 "Close" => {
144 callback => sub { $self->destroy },
145 },
146 ]
147 },
148 _Edit => {
149 item_type => '<Branch>',
150 children => [
151 "_Undo" => {
152 callback => sub { $self->undo },
153 accelerator => "<ctrl>Z"
154 },
155 "_Redo" => {
156 callback => sub { $self->redo },
157 accelerator => "<ctrl>Y"
158 },
159 ]
160 },
161 _Go => {
162 item_type => '<Branch>',
163 children => [
164 "_Up" => {
165 callback => sub { $self->follow ('u') },
166 accelerator => "<ctrl>Up"
167 },
168 "_Down" => {
169 callback => sub { $self->follow ('d') },
170 accelerator => "<ctrl>Down"
171 },
172 "_Right" => {
173 callback => sub { $self->follow ('r') },
174 accelerator => "<ctrl>Right"
175 },
176 "_Left" => {
177 callback => sub { $self->follow ('l') },
178 accelerator => "<ctrl>Left"
179 },
180 ]
181 },
182 _Help => {
183 item_type => '<Branch>',
184 children => [
185 _Manual => {
186 callback => sub { $::MAINWIN->show_help_window },
187 accelerator => "<ctrl>H"
188 },
189 ]
190 },
191 ];
192
193 my $men =
194 Gtk2::SimpleMenu->new (
195 menu_tree => $menu_tree,
196 default_callback => \&default_cb,
197 );
198
199 for (
200 [i => 'pick'],
201 [p => 'place'],
202 [e => 'erase'],
203 [s => 'select'],
204 [l => 'eval'],
205 [t => 'connect'],
206 [f => 'followexit']
207 )
208 {
209 my $tool = $_->[1];
210 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible',
211 sub { $::MAINWIN->set_edit_tool ($tool) });
212 }
213
214 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'r'}, ['control-mask'], 'visible',
215 sub { $self->redo });
216
217 $self->add_accel_group ($men->{accel_group});
218
219 return $men->{widget};
220 }
221
222 #################################################################
223 ###### EDIT TOOL STUFF ##########################################
224 #################################################################
225
226 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 } 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 }
237 }
238
239 sub ea {
240 my ($self) = @_;
241 $self->{ea_alt} || $self->{etool};
242 }
243
244 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 $ea->begin ($map, $x, $y, $self);
255
256 $ea->edit ($map, $x, $y, $self)
257 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 #################################################################
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 # FIXME: Fix the automatic update of the attribute editor! and also the stack view!
299 sub undo {
300 my ($self) = @_;
301
302 my $map = $self->{map}; # the Crossfire::MapWidget
303
304 $map->{undo_stack_pos}
305 or return;
306
307 $map->change_swap ($map->{undo_stack}[--$map->{undo_stack_pos}]);
308 }
309
310 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 sub redo {
349 my ($self) = @_;
350
351 my $map = $self->{map}; # the Crossfire::MapWidget
352
353 $map->{undo_stack}
354 and $map->{undo_stack_pos} < @{$map->{undo_stack}}
355 or return;
356
357 $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]);
358 }
359
360 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 sub open_map {
378 my ($self, $path, $key) = @_;
379
380 $self->{mapkey} = $key;
381
382 if (ref $path) {
383 $self->{map}->set_map ($path);
384 delete $self->{meta_info};
385 $self->set_title ('<ram>');
386
387 } else {
388 unless (-e $path && -f $path) {
389 die "Couldn't open '$path': No such file or it is not a file.\n";
390 }
391 $self->{path} = $path;
392 $self->{map}->set_map (my $m = new_from_file Crossfire::Map $path);
393 $self->{meta_info} = load_meta_info ($path);
394 $self->set_title ("gce - map editor - $self->{path}");
395 }
396 $self->close_windows;
397 }
398
399 sub save_map {
400 my ($self) = @_;
401
402 if ($self->{path}) {
403 $self->{map}{map}->write_file ($self->{path});
404 if ($self->{meta_info}) {
405 save_meta_info ($self->{path}, $self->{meta_info});
406 }
407 quick_msg ($self, "saved to $self->{path}");
408 $self->set_title ("gce - map editor - $self->{path}");
409 } else {
410 $self->save_map_as;
411 }
412 }
413
414 sub save_map_as {
415 my ($self) = @_;
416
417 my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1, $self->{path});
418
419 if ('ok' eq $fc->run) {
420
421 $::MAINWIN->{fc_last_folder} = $fc->get_current_folder;
422 $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++;
423
424 $self->{map}{map}->write_file ($self->{path} = $fc->get_filename);
425 if ($self->{meta_info}) {
426 save_meta_info ($self->{path}, $self->{meta_info});
427 }
428 quick_msg ($self, "saved to $self->{path}");
429 $self->set_title ("gce - map editor - $self->{path}");
430 }
431
432 $fc->destroy;
433 }
434
435 #################################################################
436 ###### DIALOGOUES ###############################################
437 #################################################################
438
439 sub open_resize_map {
440 my ($self) = @_;
441
442 return if $self->{meta_info_win};
443
444 my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
445
446 $w->init (
447 dialog_default_size => [500, 200, 220, 20],
448 layout_name => 'resize_win',
449 title => 'resize map',
450 ref_hash => $self->{map}{map}{info},
451 dialog => [
452 [width => 'Width' => 'string'],
453 [height => 'Height' => 'string'],
454 ],
455 save_cb => sub {
456 my ($info) = @_;
457 $self->{map}{map}->resize ($info->{width}, $info->{height});
458 $self->{map}->invalidate_all;
459 $w->destroy;
460 }
461 );
462
463 $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
464
465 $w->show_all;
466 }
467
468 sub open_attach_edit {
469 my ($self) = @_;
470
471 my $w = GCE::AttachEditor->new;
472 $w->set_attachment (
473 $self->{map}{map}{info}{attach},
474 sub {
475 if (@{$_[0]}) {
476 $self->{map}{map}{info}{attach} = $_[0]
477 } else {
478 delete $self->{map}{map}{info}{attach};
479 }
480 }
481 );
482 $self->{attach_editor} = $w;
483 $w->signal_connect (destroy => sub { delete $self->{attach_editor} });
484 $w->show_all;
485 }
486
487 sub upload_map_incl {
488 my ($self) = @_;
489
490 my $meta = dclone $self->{meta_info};
491
492 my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
493
494 $w->init (
495 dialog_default_size => [500, 300, 220, 20],
496 layout_name => 'map_upload_incl',
497 title => 'gce - map inclusion upload',
498 ref_hash => $meta,
499 text_entry => { key => 'changes', label => 'Changes (required for inclusion):' },
500 dialog => [
501 [gameserver => 'Game server' => 'label'],
502 [testserver => 'Test server' => 'label'],
503 [undef => x => 'sep' ],
504 [cf_login => 'Server login name' => 'string'],
505 [cf_password=> 'Password' => 'password'],
506 [path => 'Map path' => 'string'],
507 ],
508 save_cb => sub {
509 my ($meta) = @_;
510 warn "UPLOAD[".Crossfire::to_json ($meta)."]\n";
511 }
512 );
513
514 $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
515
516 $w->show_all;
517 }
518
519 sub upload_map_test {
520 my ($self) = @_;
521
522 my $meta = dclone $self->{meta_info};
523
524 my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
525
526 $w->init (
527 dialog_default_size => [500, 300, 220, 20],
528 layout_name => 'map_upload_test',
529 title => 'gce - map test upload',
530 ref_hash => $meta,
531 dialog => [
532 [gameserver => 'Game server' => 'string'],
533 [testserver => 'Test server' => 'string'],
534 [undef => x => 'sep' ],
535 [cf_login => 'Server login name' => 'string'],
536 [cf_password=> 'Password' => 'password'],
537 [path => 'Map path' => 'string'],
538 ],
539 save_cb => sub {
540 my ($meta) = @_;
541 warn "UPLOAD[".Crossfire::to_json ($meta)."]\n";
542 }
543 );
544
545 $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
546
547 $w->show_all;
548
549
550 }
551
552 sub open_meta_info {
553 my ($self) = @_;
554
555 return if $self->{meta_info_win};
556
557 my $w = $self->{meta_info_win} = GCE::HashDialogue->new ();
558
559 $w->init (
560 dialog_default_size => [500, 300, 220, 20],
561 layout_name => 'meta_info_win',
562 title => 'meta info',
563 ref_hash => $self->{meta_info},
564 dialog => [
565 [path => 'Map path' => 'string'],
566 [cf_login => 'Login name' => 'string'],
567 [revision => 'CVS Revision' => 'label'],
568 [cvs_root => 'CVS Root' => 'label'],
569 [lib_root => 'LIB Root' => 'label'],
570 [testserver => 'Test server' => 'label'],
571 [gameserver => 'Game server' => 'label'],
572 ],
573 );
574
575 $w->signal_connect (destroy => sub { delete $self->{meta_info_win} });
576
577 $w->show_all;
578 }
579
580 sub open_map_info {
581 my ($self) = @_;
582 return if $self->{map_info};
583
584 my $w = $self->{map_info} = Gtk2::Window->new ('toplevel');
585 $w->set_title ("gcrossedit - map info");
586
587 $w->add (my $vb = Gtk2::VBox->new);
588 $vb->add (my $sw = Gtk2::ScrolledWindow->new);
589 $sw->set_policy ('automatic', 'automatic');
590 $sw->add (my $txt = Gtk2::TextView->new);
591 $vb->pack_start (my $hb = Gtk2::HBox->new (1, 1), 0, 1, 0);
592 $hb->pack_start (my $svbtn = Gtk2::Button->new ("save"), 1, 1, 0);
593 $hb->pack_start (my $logbtn = Gtk2::Button->new ("add log"), 1, 1, 0);
594 $hb->pack_start (my $closebtn = Gtk2::Button->new ("close"), 1, 1, 0);
595
596 my $buf = $txt->get_buffer ();
597 $buf->set_text ($self->{map}{map}{info}{msg});
598
599 $svbtn->signal_connect (clicked => sub {
600 my $buf = $txt->get_buffer ();
601 my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0);
602 $self->{map}{map}{info}{msg} = $txt;
603 });
604
605 $logbtn->signal_connect (clicked => sub {
606 my $buf = $txt->get_buffer ();
607 $buf->insert ($buf->get_start_iter, "- " . strftime ("%F %T %Z", localtime (time)) . " by " . ($main::CFG->{username} || $ENV{USER}) . ":\n");
608 $txt->set_buffer ($buf);
609 });
610
611 $closebtn->signal_connect (clicked => sub {
612 $w->destroy;
613 });
614
615 ::set_pos_and_size ($w, $main::CFG->{map_info}, 400, 400, 220, 20);
616 $w->signal_connect (destroy => sub {
617 delete $self->{map_info};
618 });
619 $w->show_all;
620 }
621
622 sub open_map_prop {
623 my ($self) = @_;
624
625 return if $self->{map_properties};
626
627 my $w = $self->{map_properties} = GCE::HashDialogue->new ();
628
629 $w->init (
630 dialog_default_size => [500, 500, 220, 20],
631 layout_name => 'map_prop_win',
632 title => 'map properties',
633 ref_hash => $self->{map}{map}{info},
634 dialog => [
635 [qw/name Name string/],
636 [qw/region Region string/],
637 [qw/enter_x Enter-x string/],
638 [qw/enter_y Enter-y string/],
639 [qw/reset_timeout Reset-timeout string/],
640 [qw/swap_time Swap-timeout string/],
641 [undef, qw/x sep/],
642 [qw/difficulty Difficulty string/],
643 [qw/windspeed Windspeed string/],
644 [qw/pressure Pressure string/],
645 [qw/humid Humid string/],
646 [qw/temp Temp string/],
647 [qw/darkness Darkness string/],
648 [qw/sky Sky string/],
649 [qw/winddir Winddir string/],
650 [undef, qw/x sep/],
651 [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }],
652 [qw/height Height label/], # sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }],
653 [undef, qw/x sep/],
654 # [qw/msg Text text/],
655 # [qw/maplore Maplore text/],
656 [qw/outdoor Outdoor check/],
657 [qw/unique Unique check/],
658 [qw/fixed_resettime Fixed-resettime check/],
659 [undef, qw/x sep/],
660 [qw/tile_path_1 Northpath string/],
661 [qw/tile_path_2 Eastpath string/],
662 [qw/tile_path_3 Southpath string/],
663 [qw/tile_path_4 Westpath string/],
664 [qw/tile_path_5 Toppath string/],
665 [qw/tile_path_6 Bottompath string/],
666 [undef, qw/x sep/],
667 [undef, 'For shop description look in the manual',
668 'button', sub { $::MAINWIN->show_help_window }],
669 [qw/shopmin Shopmin string/],
670 [qw/shopmax Shopmax string/],
671 [qw/shoprace Shoprace string/],
672 [qw/shopgreed Shopgreed string/],
673 [qw/shopitems Shopitems string/],
674 ]
675 );
676
677 $w->signal_connect (destroy => sub { delete $self->{map_properties} });
678 $w->show_all;
679 }
680
681 #################################################################
682 ###### MAP EDITOR INIT ##########################################
683 #################################################################
684
685 sub INIT_INSTANCE {
686 my ($self) = @_;
687
688 $self->set_title ('gce - map editor');
689 $self->add (my $vb = Gtk2::VBox->new);
690
691 $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0);
692
693 $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0);
694
695 $map->signal_connect_after (key_press_event => sub {
696 my ($map, $event) = @_;
697
698 my $kv = $event->keyval;
699
700 my $ret = 0;
701
702 my ($x, $y) = $map->coord ($map->get_pointer);
703 for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }],
704 [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }],
705 [c => sub { $::MAINWIN->{edit_collection}{select}->copy }],
706 [v => sub { $::MAINWIN->{edit_collection}{select}->paste ($map, $x, $y) }],
707 [n => sub { $::MAINWIN->{edit_collection}{select}->invoke }],
708 )
709 {
710 my $ed = $_;
711
712 if ($kv == $Gtk2::Gdk::Keysyms{$ed->[0]}) {
713 my $was_in_draw = defined $self->{draw_mode};
714
715 $self->stop_drawmode ($map)
716 if $was_in_draw && grep { $ed->[0] eq $_ } qw/Control_L Alt_L/;
717
718 $ed->[1]->();
719 $ret = 1;
720
721 $self->start_drawmode ($map)
722 if $was_in_draw && grep { $ed->[0] eq $_ } qw/Control_L Alt_L/;
723 }
724 }
725
726 if ($self->ea->special_arrow) {
727 $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow));
728 } else {
729 # FIXME: Get the original cursor and insert it here
730 $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR'));
731 }
732
733 $ret
734 });
735
736 $map->signal_connect_after (key_release_event => sub {
737 my ($map, $event) = @_;
738
739 my $ret = 0;
740
741 if ($event->keyval == $Gtk2::Gdk::Keysyms{Control_L}
742 or $event->keyval == $Gtk2::Gdk::Keysyms{Alt_L})
743 {
744 my $was_in_draw = defined $self->{draw_mode};
745
746 $self->stop_drawmode ($map)
747 if $was_in_draw;
748
749 delete $self->{ea_alt};
750 $ret = 1;
751
752 $self->start_drawmode ($map)
753 if $was_in_draw;
754 }
755
756 if ($self->ea->special_arrow) {
757 $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow));
758 } else {
759 # FIXME: Get the original cursor and insert it here
760 $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR'));
761 }
762
763 $ret
764 });
765 $map->signal_connect_after (button_press_event => sub {
766 my ($map, $event) = @_;
767
768 if ((not $self->{draw_mode}) and $event->button == 1) {
769 my $ea = $self->ea;
770
771 $self->start_drawmode ($map);
772
773 $ea->want_cursor
774 or $map->disable_tooltip;
775
776 return 1;
777 } elsif ($event->button == 3) {
778 $self->do_context_menu ($map, $event);
779 return 1;
780 }
781
782 0
783 });
784
785 $map->signal_connect_after (motion_notify_event => sub {
786 my ($map, $event) = @_;
787
788 $self->{draw_mode}
789 or return;
790
791 my $ea = $self->ea;
792
793 my ($X, $Y) = @{$self->{draw_mode}}[0,1];
794 my ($x, $y) = $map->coord ($map->get_pointer);
795
796 while ($x != $X || $y != $Y) {
797
798 $X++ if $X < $x;
799 $X-- if $X > $x;
800 $Y++ if $Y < $y;
801 $Y-- if $Y > $y;
802
803 unless ($ea->only_on_click) {
804 $ea->edit ($map, $X, $Y, $self)
805 if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height};
806 }
807 }
808
809 @{$self->{draw_mode}}[0,1] = ($X, $Y);
810
811 1
812 });
813
814 $map->signal_connect_after (button_release_event => sub {
815 my ($map, $event) = @_;
816
817 if ($self->{draw_mode} and $event->button == 1) {
818 my $ea = $self->ea;
819
820 $self->stop_drawmode ($map);
821
822 $ea->want_cursor
823 or $map->enable_tooltip;
824
825 return 1;
826 }
827
828 0
829 });
830
831 ::set_pos_and_size ($self, $main::CFG->{map_window}, 500, 500, 200, 0);
832 }
833
834 =head1 AUTHOR
835
836 Marc Lehmann <schmorp@schmorp.de>
837 http://home.schmorp.de/
838
839 Robin Redeker <elmex@ta-sa.org>
840 http://www.ta-sa.org/
841
842 =cut
843
844 1
845