… | |
… | |
13 | use Crossfire; |
13 | use Crossfire; |
14 | use Crossfire::Map; |
14 | use Crossfire::Map; |
15 | use Crossfire::MapWidget; |
15 | use Crossfire::MapWidget; |
16 | |
16 | |
17 | use GCE::AttrEdit; |
17 | use GCE::AttrEdit; |
|
|
18 | use GCE::Util; |
18 | |
19 | |
19 | use Glib::Object::Subclass |
20 | use Glib::Object::Subclass |
20 | Gtk2::Window; |
21 | Gtk2::Window; |
21 | |
22 | |
22 | use strict; |
23 | use strict; |
… | |
… | |
59 | callback => sub { $self->open_resize_map }, |
60 | callback => sub { $self->open_resize_map }, |
60 | accelerator => "<ctrl>R" |
61 | accelerator => "<ctrl>R" |
61 | }, |
62 | }, |
62 | ] |
63 | ] |
63 | }, |
64 | }, |
64 | |
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 | }, |
65 | ]; |
95 | ]; |
66 | |
96 | |
67 | my $men = |
97 | my $men = |
68 | Gtk2::SimpleMenu->new ( |
98 | Gtk2::SimpleMenu->new ( |
69 | menu_tree => $menu_tree, |
99 | menu_tree => $menu_tree, |
70 | default_callback => \&default_cb, |
100 | default_callback => \&default_cb, |
71 | ); |
101 | ); |
72 | |
102 | |
|
|
103 | for ( |
|
|
104 | [i => 'pick'], |
|
|
105 | [p => 'place'], |
|
|
106 | [e => 'erase'], |
|
|
107 | [s => 'select'], |
|
|
108 | [l => 'eval'], |
|
|
109 | [x => 'connectexit'], |
|
|
110 | [f => 'followexit'] |
|
|
111 | ) |
|
|
112 | { |
|
|
113 | my $tool = $_->[1]; |
73 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'i'}, [], 'visible', |
114 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible', |
74 | sub { $::MAINWIN->set_edit_tool ('pick') }); |
|
|
75 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'p'}, [], 'visible', |
|
|
76 | sub { $::MAINWIN->set_edit_tool ('place') }); |
115 | sub { $::MAINWIN->set_edit_tool ($tool) }); |
77 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'e'}, [], 'visible', |
116 | } |
78 | sub { $::MAINWIN->set_edit_tool ('erase') }); |
117 | |
79 | $self->add_accel_group ($men->{accel_group}); |
118 | $self->add_accel_group ($men->{accel_group}); |
80 | |
119 | |
81 | return $men->{widget}; |
120 | return $men->{widget}; |
82 | } |
121 | } |
83 | |
122 | |
… | |
… | |
90 | my ($self) = @_; |
129 | my ($self) = @_; |
91 | |
130 | |
92 | $self->set_title ('gce - map editor'); |
131 | $self->set_title ('gce - map editor'); |
93 | $self->add (my $vb = Gtk2::VBox->new); |
132 | $self->add (my $vb = Gtk2::VBox->new); |
94 | |
133 | |
95 | $self->signal_connect (delete_event => sub { $self->delete }); |
134 | $self->signal_connect (delete_event => sub { $self->delete; 1 }); |
96 | |
135 | |
97 | $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); |
136 | $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); |
98 | |
137 | |
99 | $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); |
100 | |
139 | |
… | |
… | |
103 | if ($ea->special_arrow) { |
142 | if ($ea->special_arrow) { |
104 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($ea->special_arrow)); |
143 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($ea->special_arrow)); |
105 | } else { |
144 | } else { |
106 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
145 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
107 | } |
146 | } |
|
|
147 | delete $self->{ea_alt}; |
108 | }); |
148 | }); |
109 | |
149 | |
110 | $map->signal_connect (key_press_event => sub { |
150 | $map->signal_connect (key_press_event => sub { |
111 | my ($map, $event) = @_; |
151 | my ($map, $event) = @_; |
112 | |
152 | |
113 | my $kv = $event->keyval; |
153 | my $kv = $event->keyval; |
114 | |
154 | |
115 | if ($kv == $Gtk2::Gdk::Keysyms{Control_L}) { |
|
|
116 | $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase}; |
|
|
117 | |
|
|
118 | } elsif ($kv == $Gtk2::Gdk::Keysyms{Alt_L}) { |
|
|
119 | $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick}; |
|
|
120 | } elsif ($kv == $Gtk2::Gdk::Keysyms{x}) { |
|
|
121 | $::MAINWIN->{edit_collection}{select}->move; |
|
|
122 | } elsif ($kv == $Gtk2::Gdk::Keysyms{c}) { |
|
|
123 | $::MAINWIN->{edit_collection}{select}->copy; |
|
|
124 | } elsif ($kv == $Gtk2::Gdk::Keysyms{v}) { |
|
|
125 | my ($x, $y) = $map->coord ($map->get_pointer); |
155 | my ($x, $y) = $map->coord ($map->get_pointer); |
|
|
156 | for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }], |
|
|
157 | [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }], |
|
|
158 | [c => sub { $::MAINWIN->{edit_collection}{select}->copy }], |
126 | $::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 }], |
|
|
161 | ) |
|
|
162 | { |
|
|
163 | if ($kv == $Gtk2::Gdk::Keysyms{$_->[0]}) { |
|
|
164 | $_->[1]->(); |
|
|
165 | } |
127 | } |
166 | } |
128 | |
167 | |
129 | if ($self->ea->special_arrow) { |
168 | if ($self->ea->special_arrow) { |
130 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
169 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
131 | } |
170 | } |
… | |
… | |
156 | |
195 | |
157 | if ((not $self->{draw_mode}) and $event->button != 2) { |
196 | if ((not $self->{draw_mode}) and $event->button != 2) { |
158 | |
197 | |
159 | my $ea = $self->ea; |
198 | my $ea = $self->ea; |
160 | |
199 | |
161 | $ea->begin ($map, $x, $y) |
200 | $ea->begin ($map, $x, $y, $self) |
162 | if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; |
201 | if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; |
163 | |
202 | |
164 | $self->{draw_mode} = [$x, $y]; |
203 | $self->{draw_mode} = [$x, $y]; |
165 | |
204 | |
166 | $ea->want_cursor |
205 | $ea->want_cursor |
… | |
… | |
187 | $X++ if $X < $x; |
226 | $X++ if $X < $x; |
188 | $X-- if $X > $x; |
227 | $X-- if $X > $x; |
189 | $Y++ if $Y < $y; |
228 | $Y++ if $Y < $y; |
190 | $Y-- if $Y > $y; |
229 | $Y-- if $Y > $y; |
191 | |
230 | |
192 | $ea->edit ($map, $X, $Y) |
231 | $ea->edit ($map, $X, $Y, $self) |
193 | if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height}; |
232 | if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height}; |
194 | } |
233 | } |
195 | |
234 | |
196 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
235 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
197 | |
236 | |
… | |
… | |
203 | |
242 | |
204 | if ($self->{draw_mode}) { |
243 | if ($self->{draw_mode}) { |
205 | my ($x, $y) = $map->coord ($map->get_pointer); |
244 | my ($x, $y) = $map->coord ($map->get_pointer); |
206 | |
245 | |
207 | my $ea = $self->ea; |
246 | my $ea = $self->ea; |
208 | $ea->end ($map, $x, $y); |
247 | $ea->end ($map, $x, $y, $self); |
209 | |
248 | |
210 | delete $self->{draw_mode}; |
249 | delete $self->{draw_mode}; |
211 | |
250 | |
212 | $ea->want_cursor |
251 | $ea->want_cursor |
213 | or $map->enable_tooltip; |
252 | or $map->enable_tooltip; |
… | |
… | |
246 | sub delete { |
285 | sub delete { |
247 | my ($self) = @_; |
286 | my ($self) = @_; |
248 | |
287 | |
249 | # check and modla dialog if "dirty" |
288 | # check and modla dialog if "dirty" |
250 | |
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 | |
251 | $self->destroy; |
295 | $self->destroy; |
252 | } |
296 | } |
253 | |
297 | |
254 | sub open_map { |
298 | sub open_map { |
255 | my ($self, $path) = @_; |
299 | my ($self, $path, $key) = @_; |
|
|
300 | |
|
|
301 | $self->{mapkey} = $key; |
256 | |
302 | |
257 | if (ref $path) { |
303 | if (ref $path) { |
258 | $self->{map}->set_map ($path); |
304 | $self->{map}->set_map ($path); |
259 | |
305 | |
260 | } else { |
306 | } else { |
… | |
… | |
269 | sub save_map { |
315 | sub save_map { |
270 | my ($self) = @_; |
316 | my ($self) = @_; |
271 | |
317 | |
272 | if ($self->{path}) { |
318 | if ($self->{path}) { |
273 | $self->{map}{map}->write_file ($self->{path}); |
319 | $self->{map}{map}->write_file ($self->{path}); |
|
|
320 | quick_msg ($self, "saved to $self->{path}"); |
|
|
321 | } else { |
|
|
322 | $self->save_map_as; |
274 | } |
323 | } |
275 | } |
324 | } |
276 | |
325 | |
277 | sub save_map_as { |
326 | sub save_map_as { |
278 | my ($self) = @_; |
327 | my ($self) = @_; |
279 | |
328 | |
280 | my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1); |
329 | my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1, $self->{path}); |
281 | |
330 | |
282 | if ('ok' eq $fc->run) { |
331 | if ('ok' eq $fc->run) { |
283 | |
332 | |
284 | $::MAINWIN->{fc_last_folder} = $fc->get_current_folder; |
333 | $::MAINWIN->{fc_last_folder} = $fc->get_current_folder; |
285 | $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++; |
334 | $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++; |
286 | |
335 | |
287 | $self->{map}{map}->write_file ($self->{path} = $fc->get_filename); |
336 | $self->{map}{map}->write_file ($self->{path} = $fc->get_filename); |
|
|
337 | quick_msg ($self, "saved to $self->{path}"); |
288 | } |
338 | } |
289 | |
339 | |
290 | $fc->destroy; |
340 | $fc->destroy; |
291 | } |
341 | } |
292 | |
342 | |
… | |
… | |
314 | } elsif ($type eq 'label') { |
364 | } elsif ($type eq 'label') { |
315 | $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); |
316 | $edwid = Gtk2::Label->new ($self->{map}{map}{info}{$key}); |
366 | $edwid = Gtk2::Label->new ($self->{map}{map}{info}{$key}); |
317 | $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1); |
367 | $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1); |
318 | |
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); |
319 | } else { |
381 | } else { |
320 | $edwid = Gtk2::Label->new ("FOO"); |
382 | $edwid = Gtk2::Label->new ("FOO"); |
321 | } |
383 | } |
322 | } |
384 | } |
323 | |
385 | |
… | |
… | |
348 | } |
410 | } |
349 | |
411 | |
350 | $w->show_all; |
412 | $w->show_all; |
351 | } |
413 | } |
352 | |
414 | |
|
|
415 | sub 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 | |
353 | sub open_map_prop { |
434 | sub open_map_prop { |
354 | my ($self) = @_; |
435 | my ($self) = @_; |
355 | |
436 | |
356 | |
437 | |
357 | my $w = Gtk2::Window->new ('toplevel'); |
438 | my $w = Gtk2::Window->new ('toplevel'); |
… | |
… | |
361 | $sw->set_policy ('automatic', 'automatic'); |
442 | $sw->set_policy ('automatic', 'automatic'); |
362 | $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); |
363 | |
444 | |
364 | my $i = 0; |
445 | my $i = 0; |
365 | for ( |
446 | for ( |
366 | [qw/name Name string/], |
447 | [qw/name Name string/], |
367 | [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/], |
368 | [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/], |
369 | [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}) }], |
370 | [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/], |
371 | [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/], |
372 | [qw/tile_path_1 Northpath string/], |
472 | [qw/tile_path_1 Northpath string/], |
373 | [qw/tile_path_2 Eastpath string/], |
473 | [qw/tile_path_2 Eastpath string/], |
374 | [qw/tile_path_3 Southpath string/], |
474 | [qw/tile_path_3 Southpath string/], |
375 | [qw/tile_path_4 Westpath string/], |
475 | [qw/tile_path_4 Westpath string/], |
376 | [qw/tile_path_5 Toppath string/], |
476 | [qw/tile_path_5 Toppath string/], |
377 | [qw/tile_path_6 Bottompath string/], |
477 | [qw/tile_path_6 Bottompath string/], |
378 | ) |
478 | ) |
379 | { |
479 | { |
380 | $self->_add_prop_entry ($t, $i++, @$_); |
480 | $self->_add_prop_entry ($t, $i++, @$_); |
381 | } |
481 | } |
382 | |
482 | |
383 | $w->show_all; |
483 | $w->show_all; |
384 | } |
484 | } |
385 | |
485 | |
386 | # 'info' => { |
|
|
387 | # 'windspeed' => '10', |
|
|
388 | # 'outdoor' => '1', |
|
|
389 | # 'width' => '20', |
|
|
390 | # 'pressure' => '8', |
|
|
391 | # 'test' => '', |
|
|
392 | # 'tile_path_2' => 'east', |
|
|
393 | # 'tile_path_3' => 'south', |
|
|
394 | # 'enter_y' => '2', |
|
|
395 | # 'tile_path_6' => 'bottom', |
|
|
396 | # 'enter_x' => '1', |
|
|
397 | # 'tile_path_5' => 'top', |
|
|
398 | # 'darkness' => '4', |
|
|
399 | # 'maplore' => '', |
|
|
400 | # 'sky' => '12', |
|
|
401 | # 'winddir' => '11', |
|
|
402 | # 'unique' => '1', |
|
|
403 | # 'msg' => 'Creator: CF Java FUCK Map Editor |
|
|
404 | #Date: 3/12/2006 |
|
|
405 | #', |
|
|
406 | # 'difficulty' => '3', |
|
|
407 | # 'humid' => '9', |
|
|
408 | # 'endmaplore' => '', |
|
|
409 | # 'fixed_resettime' => '1', |
|
|
410 | # 'name' => 'test', |
|
|
411 | # 'region' => 'REGION', |
|
|
412 | # 'height' => '40', |
|
|
413 | # 'reset_timeout' => '6', |
|
|
414 | # '_name' => 'map', |
|
|
415 | # 'swap_time' => '5', |
|
|
416 | # 'temp' => '7', |
|
|
417 | # 'tile_path_4' => 'west', |
|
|
418 | # 'tile_path_1' => 'north' |
|
|
419 | # }, |
|
|
420 | |
|
|
421 | |
|
|
422 | =head1 AUTHOR |
486 | =head1 AUTHOR |
423 | |
487 | |
424 | Marc Lehmann <schmorp@schmorp.de> |
488 | Marc Lehmann <schmorp@schmorp.de> |
425 | http://home.schmorp.de/ |
489 | http://home.schmorp.de/ |
426 | |
490 | |