ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
(Generate patch)

Comparing deliantra/gde/GCE/MapEditor.pm (file contents):
Revision 1.23 by elmex, Thu Mar 16 22:19:35 2006 UTC vs.
Revision 1.29 by elmex, Mon Mar 20 04:11:41 2006 UTC

60 callback => sub { $self->open_resize_map }, 60 callback => sub { $self->open_resize_map },
61 accelerator => "<ctrl>R" 61 accelerator => "<ctrl>R"
62 }, 62 },
63 ] 63 ]
64 }, 64 },
65 65 _Go => {
66 item_type => '<Branch>',
67 children => [
68 "_Up" => {
69 callback => sub { $self->follow ('u') },
70 accelerator => "<ctrl>U"
71 },
72 "_Down" => {
73 callback => sub { $self->follow ('d') },
74 accelerator => "<ctrl>D"
75 },
76 "_Right" => {
77 callback => sub { $self->follow ('r') },
78 accelerator => "<ctrl>R"
79 },
80 "_Left" => {
81 callback => sub { $self->follow ('l') },
82 accelerator => "<ctrl>L"
83 },
84 ]
85 },
86 _Help => {
87 item_type => '<Branch>',
88 children => [
89 _Help => {
90 callback => sub { $::MAINWIN->show_help_window },
91 accelerator => "<ctrl>H"
92 },
93 ]
94 },
66 ]; 95 ];
67 96
68 my $men = 97 my $men =
69 Gtk2::SimpleMenu->new ( 98 Gtk2::SimpleMenu->new (
70 menu_tree => $menu_tree, 99 menu_tree => $menu_tree,
72 ); 101 );
73 102
74 for ( 103 for (
75 [i => 'pick'], 104 [i => 'pick'],
76 [p => 'place'], 105 [p => 'place'],
77 [e => 'erase'] 106 [e => 'erase'],
107 [s => 'select'],
108 [l => 'eval'],
109 [x => 'connectexit'],
110 [f => 'followexit']
78 ) 111 )
79 { 112 {
113 my $tool = $_->[1];
80 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible', 114 $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible',
81 sub { $::MAINWIN->set_edit_tool ($_->[1]) }); 115 sub { $::MAINWIN->set_edit_tool ($tool) });
82 } 116 }
83 117
84 $self->add_accel_group ($men->{accel_group}); 118 $self->add_accel_group ($men->{accel_group});
85 119
86 return $men->{widget}; 120 return $men->{widget};
95 my ($self) = @_; 129 my ($self) = @_;
96 130
97 $self->set_title ('gce - map editor'); 131 $self->set_title ('gce - map editor');
98 $self->add (my $vb = Gtk2::VBox->new); 132 $self->add (my $vb = Gtk2::VBox->new);
99 133
100 $self->signal_connect (delete_event => sub { $self->delete }); 134 $self->signal_connect (delete_event => sub { $self->delete; 1 });
101 135
102 $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); 136 $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0);
103 137
104 $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0); 138 $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0);
105 139
120 154
121 my ($x, $y) = $map->coord ($map->get_pointer); 155 my ($x, $y) = $map->coord ($map->get_pointer);
122 for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }], 156 for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }],
123 [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }], 157 [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }],
124 [c => sub { $::MAINWIN->{edit_collection}{select}->copy }], 158 [c => sub { $::MAINWIN->{edit_collection}{select}->copy }],
125 [v => sub { $::MAINWIN->{edit_collection}{select}->paste ($x, $y) }] 159 [v => sub { $::MAINWIN->{edit_collection}{select}->paste ($map, $x, $y) }],
160 [n => sub { $::MAINWIN->{edit_collection}{select}->invoke }],
126 ) 161 )
127 { 162 {
128 if ($kv == $Gtk2::Gdk::Keysyms{$_->[0]}) { 163 if ($kv == $Gtk2::Gdk::Keysyms{$_->[0]}) {
129 $_->[1]->(); 164 $_->[1]->();
130 } 165 }
250sub delete { 285sub delete {
251 my ($self) = @_; 286 my ($self) = @_;
252 287
253 # check and modla dialog if "dirty" 288 # check and modla dialog if "dirty"
254 289
290 if ($self->{mapkey}) {
291 # XXX: This should be in a delete event handler in the MainWindow.pm... but it doesnt work
292 delete $::MAINWIN->{loaded_maps}->{$self->{mapkey}};
293 }
294
255 $self->destroy; 295 $self->destroy;
256} 296}
257 297
258sub open_map { 298sub open_map {
259 my ($self, $path) = @_; 299 my ($self, $path, $key) = @_;
300
301 $self->{mapkey} = $key;
260 302
261 if (ref $path) { 303 if (ref $path) {
262 $self->{map}->set_map ($path); 304 $self->{map}->set_map ($path);
263 305
264 } else { 306 } else {
322 } elsif ($type eq 'label') { 364 } elsif ($type eq 'label') {
323 $table->attach_defaults (my $lbl = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); 365 $table->attach_defaults (my $lbl = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1);
324 $edwid = Gtk2::Label->new ($self->{map}{map}{info}{$key}); 366 $edwid = Gtk2::Label->new ($self->{map}{map}{info}{$key});
325 $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1); 367 $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1);
326 368
369 } elsif ($type eq 'check') {
370 $table->attach_defaults (my $lbl1 = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1);
371 $table->attach_defaults (my $lbl = Gtk2::CheckButton->new, 1, 2, $idx, $idx + 1);
372 $lbl->set_active ($self->{map}{map}{info}{$key});
373 $lbl->signal_connect (toggled => sub {
374 my ($lbl) = @_;
375 $self->{map}{map}{info}{$key} = $lbl->get_active * 1;
376 ($changecb || sub {})->($lbl->get_active);
377 });
378
379 } elsif ($type eq 'sep') {
380 $table->attach_defaults (my $lbl1 = Gtk2::HSeparator->new, 0, 2, $idx, $idx + 1);
327 } else { 381 } else {
328 $edwid = Gtk2::Label->new ("FOO"); 382 $edwid = Gtk2::Label->new ("FOO");
329 } 383 }
330} 384}
331 385
356 } 410 }
357 411
358 $w->show_all; 412 $w->show_all;
359} 413}
360 414
415sub follow {
416 my ($self, $dir) = @_;
417
418 my %dir_to_path = (
419 u => 'tile_path_1',
420 d => 'tile_path_3',
421 r => 'tile_path_2',
422 l => 'tile_path_4',
423 );
424
425 defined $dir_to_path{$dir}
426 or return;
427 my $map = $self->{map}{map}{info}{$dir_to_path{$dir}}
428 or return;
429
430 $map = map2abs ($map, $self);
431 $::MAINWIN->open_map_editor ($map);
432}
433
361sub open_map_prop { 434sub open_map_prop {
362 my ($self) = @_; 435 my ($self) = @_;
363 436
364 437
365 my $w = Gtk2::Window->new ('toplevel'); 438 my $w = Gtk2::Window->new ('toplevel');
369 $sw->set_policy ('automatic', 'automatic'); 442 $sw->set_policy ('automatic', 'automatic');
370 $v->pack_start (my $t = Gtk2::Table->new (2, 10), 0, 0, 0); 443 $v->pack_start (my $t = Gtk2::Table->new (2, 10), 0, 0, 0);
371 444
372 my $i = 0; 445 my $i = 0;
373 for ( 446 for (
374 [qw/name Name string/], 447 [qw/name Name string/],
375 [qw/region Region string/], 448 [qw/region Region string/],
449 [qw/enter_x Enter-x string/],
450 [qw/enter_y Enter-y string/],
451 [qw/reset_timeout Reset-timeout string/],
452 [qw/swap_time Swap-timeout string/],
453 [qw/x x sep/],
376 [qw/difficulty Difficulty string/], 454 [qw/difficulty Difficulty string/],
455 [qw/windspeed Windspeed string/],
456 [qw/pressure Pressure string/],
457 [qw/humid Humid string/],
458 [qw/temp Temp string/],
459 [qw/darkness Darkness string/],
460 [qw/sky Sky string/],
461 [qw/winddir Winddir string/],
462 [qw/x x sep/],
377 [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }], 463 [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }],
378 [qw/height Height label/],# sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }], 464 [qw/height Height label/], # sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }],
465 [qw/x x sep/],
379 [qw/msg Text text/], 466 [qw/msg Text text/],
467 [qw/maplore Maplore text/],
468 [qw/outdoor Outdoor check/],
469 [qw/unique Unique check/],
470 [qw/fixed_resettime Fixed-resettime check/],
471 [qw/x x sep/],
380 [qw/tile_path_1 Northpath string/], 472 [qw/tile_path_1 Northpath string/],
381 [qw/tile_path_2 Eastpath string/], 473 [qw/tile_path_2 Eastpath string/],
382 [qw/tile_path_3 Southpath string/], 474 [qw/tile_path_3 Southpath string/],
383 [qw/tile_path_4 Westpath string/], 475 [qw/tile_path_4 Westpath string/],
384 [qw/tile_path_5 Toppath string/], 476 [qw/tile_path_5 Toppath string/],
385 [qw/tile_path_6 Bottompath string/], 477 [qw/tile_path_6 Bottompath string/],
386 ) 478 )
387 { 479 {
388 $self->_add_prop_entry ($t, $i++, @$_); 480 $self->_add_prop_entry ($t, $i++, @$_);
389 } 481 }
390 482
391 $w->show_all; 483 $w->show_all;
392} 484}
393 485
394# 'info' => {
395# 'windspeed' => '10',
396# 'outdoor' => '1',
397# 'width' => '20',
398# 'pressure' => '8',
399# 'test' => '',
400# 'tile_path_2' => 'east',
401# 'tile_path_3' => 'south',
402# 'enter_y' => '2',
403# 'tile_path_6' => 'bottom',
404# 'enter_x' => '1',
405# 'tile_path_5' => 'top',
406# 'darkness' => '4',
407# 'maplore' => '',
408# 'sky' => '12',
409# 'winddir' => '11',
410# 'unique' => '1',
411# 'msg' => 'Creator: CF Java FUCK Map Editor
412#Date: 3/12/2006
413#',
414# 'difficulty' => '3',
415# 'humid' => '9',
416# 'endmaplore' => '',
417# 'fixed_resettime' => '1',
418# 'name' => 'test',
419# 'region' => 'REGION',
420# 'height' => '40',
421# 'reset_timeout' => '6',
422# '_name' => 'map',
423# 'swap_time' => '5',
424# 'temp' => '7',
425# 'tile_path_4' => 'west',
426# 'tile_path_1' => 'north'
427# },
428
429
430=head1 AUTHOR 486=head1 AUTHOR
431 487
432 Marc Lehmann <schmorp@schmorp.de> 488 Marc Lehmann <schmorp@schmorp.de>
433 http://home.schmorp.de/ 489 http://home.schmorp.de/
434 490

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines