… | |
… | |
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 | use GCE::Util; |
|
|
19 | use GCE::HashDialog; |
|
|
20 | |
|
|
21 | use POSIX qw/strftime/; |
19 | |
22 | |
20 | use Glib::Object::Subclass |
23 | use Glib::Object::Subclass |
21 | Gtk2::Window; |
24 | Gtk2::Window; |
22 | |
25 | |
|
|
26 | use Storable qw/dclone/; |
|
|
27 | |
23 | use strict; |
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 | ################################################################# |
24 | |
56 | |
25 | sub do_context_menu { |
57 | sub do_context_menu { |
26 | my ($self, $map, $event) = @_; |
58 | my ($self, $map, $event) = @_; |
27 | |
59 | |
28 | my ($x, $y) = $map->coord ($event->x, $event->y); |
60 | my ($x, $y) = $map->coord ($event->x, $event->y); |
… | |
… | |
30 | my $menu = Gtk2::Menu->new; |
62 | my $menu = Gtk2::Menu->new; |
31 | foreach my $cm ( |
63 | foreach my $cm ( |
32 | [ |
64 | [ |
33 | Follow => sub { |
65 | Follow => sub { |
34 | $::MAINWIN->{edit_collection}{followexit}->edit ($map, $x, $y, $self) |
66 | $::MAINWIN->{edit_collection}{followexit}->edit ($map, $x, $y, $self) |
35 | } |
67 | }, |
36 | ] |
68 | ] |
37 | ) { |
69 | ) { |
38 | my $item = Gtk2::MenuItem->new ($cm->[0]); |
70 | my $item = Gtk2::MenuItem->new ($cm->[0]); |
39 | $menu->append ($item); |
71 | $menu->append ($item); |
40 | $item->show; |
72 | $item->show; |
41 | $item->signal_connect (activate => $cm->[1]); |
73 | $item->signal_connect (activate => $cm->[1]); |
42 | } |
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 | |
43 | $menu->popup (undef, undef, undef, undef, $event->button, $event->time); |
97 | $menu->popup (undef, undef, undef, undef, $event->button, $event->time); |
44 | } |
98 | } |
45 | |
99 | |
46 | sub build_menu { |
100 | sub build_menu { |
47 | my ($self) = @_; |
101 | my ($self) = @_; |
… | |
… | |
55 | accelerator => '<ctrl>S' |
109 | accelerator => '<ctrl>S' |
56 | }, |
110 | }, |
57 | "Save As" => { |
111 | "Save As" => { |
58 | callback => sub { $self->save_map_as }, |
112 | callback => sub { $self->save_map_as }, |
59 | }, |
113 | }, |
|
|
114 | "Map _Info" => { |
|
|
115 | callback => sub { $self->open_map_info }, |
|
|
116 | accelerator => "<ctrl>I", |
|
|
117 | }, |
60 | "_Map Properties" => { |
118 | "Map _Properties" => { |
61 | callback => sub { $self->open_map_prop }, |
119 | callback => sub { $self->open_map_prop }, |
62 | accelerator => "<ctrl>P" |
120 | accelerator => "<ctrl>P" |
63 | }, |
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 | }, |
64 | "_Map Resize" => { |
140 | "_Map Resize" => { |
65 | callback => sub { $self->open_resize_map }, |
141 | callback => sub { $self->open_resize_map }, |
66 | accelerator => "<ctrl>R" |
|
|
67 | }, |
142 | }, |
68 | "Close" => { |
143 | "Close" => { |
69 | callback => sub { $self->destroy }, |
144 | callback => sub { $self->destroy }, |
70 | }, |
145 | }, |
71 | ] |
146 | ] |
… | |
… | |
134 | my $tool = $_->[1]; |
209 | my $tool = $_->[1]; |
135 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible', |
210 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{$_->[0]}, [], 'visible', |
136 | sub { $::MAINWIN->set_edit_tool ($tool) }); |
211 | sub { $::MAINWIN->set_edit_tool ($tool) }); |
137 | } |
212 | } |
138 | |
213 | |
|
|
214 | $men->{accel_group}->connect ($Gtk2::Gdk::Keysyms{'r'}, ['control-mask'], 'visible', |
|
|
215 | sub { $self->redo }); |
|
|
216 | |
139 | $self->add_accel_group ($men->{accel_group}); |
217 | $self->add_accel_group ($men->{accel_group}); |
140 | |
218 | |
141 | return $men->{widget}; |
219 | return $men->{widget}; |
142 | } |
220 | } |
|
|
221 | |
|
|
222 | ################################################################# |
|
|
223 | ###### EDIT TOOL STUFF ########################################## |
|
|
224 | ################################################################# |
143 | |
225 | |
144 | sub set_edit_tool { |
226 | sub set_edit_tool { |
145 | my ($self, $tool) = @_; |
227 | my ($self, $tool) = @_; |
146 | |
228 | |
147 | $self->{etool} = $tool; |
229 | $self->{etool} = $tool; |
… | |
… | |
156 | |
238 | |
157 | sub ea { |
239 | sub ea { |
158 | my ($self) = @_; |
240 | my ($self) = @_; |
159 | $self->{ea_alt} || $self->{etool}; |
241 | $self->{ea_alt} || $self->{etool}; |
160 | } |
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 | source => 'map', |
|
|
333 | cb => sub { |
|
|
334 | $map->change_begin ('attredit'); |
|
|
335 | $map->change_stack ($ox, $oy, $cstack); |
|
|
336 | |
|
|
337 | if (my $changeset = $map->change_end) { |
|
|
338 | splice @{ $map->{undo_stack} ||= [] }, |
|
|
339 | $map->{undo_stack_pos}++, 1e6, |
|
|
340 | $changeset; |
|
|
341 | } |
|
|
342 | } |
|
|
343 | ); |
|
|
344 | } |
|
|
345 | |
|
|
346 | return @refs; |
|
|
347 | } |
|
|
348 | |
|
|
349 | sub redo { |
|
|
350 | my ($self) = @_; |
|
|
351 | |
|
|
352 | my $map = $self->{map}; # the Crossfire::MapWidget |
|
|
353 | |
|
|
354 | $map->{undo_stack} |
|
|
355 | and $map->{undo_stack_pos} < @{$map->{undo_stack}} |
|
|
356 | or return; |
|
|
357 | |
|
|
358 | $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]); |
|
|
359 | } |
|
|
360 | |
|
|
361 | sub load_meta_info { |
|
|
362 | my ($mapfile) = @_; |
|
|
363 | if (-e "$mapfile.meta") { |
|
|
364 | open my $metafh, "<", "$mapfile.meta" |
|
|
365 | or warn "Couldn't open meta file $mapfile.meta: $!"; |
|
|
366 | my $metadata = do { local $/; <$metafh> }; |
|
|
367 | return Crossfire::from_json ($metadata); |
|
|
368 | } |
|
|
369 | } |
|
|
370 | |
|
|
371 | sub save_meta_info { |
|
|
372 | my ($mapfile, $metainfo) = @_; |
|
|
373 | open my $metafh, ">", "$mapfile.meta" |
|
|
374 | or warn "Couldn't write meta file $mapfile.meta: $!"; |
|
|
375 | print $metafh Crossfire::to_json ($metainfo); |
|
|
376 | } |
|
|
377 | |
|
|
378 | sub open_map { |
|
|
379 | my ($self, $path, $key) = @_; |
|
|
380 | |
|
|
381 | $self->{mapkey} = $key; |
|
|
382 | |
|
|
383 | if (ref $path) { |
|
|
384 | $self->{map}->set_map ($path); |
|
|
385 | delete $self->{meta_info}; |
|
|
386 | $self->set_title ('<ram>'); |
|
|
387 | |
|
|
388 | } else { |
|
|
389 | my $ok = 0; |
|
|
390 | if (-e $path && -f $path) { |
|
|
391 | $ok = 1; |
|
|
392 | } else { |
|
|
393 | unless ($path =~ m/\.map$/) { # yuck |
|
|
394 | my $p = $path . '.map'; |
|
|
395 | if ($ok = -e $p && -f $p) { |
|
|
396 | $path = $p; |
|
|
397 | } |
|
|
398 | } |
|
|
399 | } |
|
|
400 | unless ($ok) { |
|
|
401 | die "Couldn't open '$path' or find '$path.map': No such file or it is not a file.\n"; |
|
|
402 | } |
|
|
403 | $self->{path} = $path; |
|
|
404 | $self->{map}->set_map (my $m = new_from_file Crossfire::Map $path); |
|
|
405 | $self->{meta_info} = load_meta_info ($path); |
|
|
406 | $self->set_title ("gce - map editor - $self->{path}"); |
|
|
407 | } |
|
|
408 | $self->close_windows; |
|
|
409 | } |
|
|
410 | |
|
|
411 | sub save_map { |
|
|
412 | my ($self) = @_; |
|
|
413 | |
|
|
414 | if ($self->{path}) { |
|
|
415 | $self->{map}{map}->write_file ($self->{path}); |
|
|
416 | if ($self->{meta_info}) { |
|
|
417 | save_meta_info ($self->{path}, $self->{meta_info}); |
|
|
418 | } |
|
|
419 | quick_msg ($self, "saved to $self->{path}"); |
|
|
420 | $self->set_title ("gce - map editor - $self->{path}"); |
|
|
421 | } else { |
|
|
422 | $self->save_map_as; |
|
|
423 | } |
|
|
424 | } |
|
|
425 | |
|
|
426 | sub save_map_as { |
|
|
427 | my ($self) = @_; |
|
|
428 | |
|
|
429 | my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1, $self->{path}); |
|
|
430 | |
|
|
431 | if ('ok' eq $fc->run) { |
|
|
432 | |
|
|
433 | $::MAINWIN->{fc_last_folder} = $fc->get_current_folder; |
|
|
434 | $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++; |
|
|
435 | |
|
|
436 | $self->{map}{map}->write_file ($self->{path} = $fc->get_filename); |
|
|
437 | if ($self->{meta_info}) { |
|
|
438 | save_meta_info ($self->{path}, $self->{meta_info}); |
|
|
439 | } |
|
|
440 | quick_msg ($self, "saved to $self->{path}"); |
|
|
441 | $self->set_title ("gce - map editor - $self->{path}"); |
|
|
442 | } |
|
|
443 | |
|
|
444 | $fc->destroy; |
|
|
445 | } |
|
|
446 | |
|
|
447 | ################################################################# |
|
|
448 | ###### DIALOGOUES ############################################### |
|
|
449 | ################################################################# |
|
|
450 | |
|
|
451 | sub open_resize_map { |
|
|
452 | my ($self) = @_; |
|
|
453 | |
|
|
454 | return if $self->{meta_info_win}; |
|
|
455 | |
|
|
456 | my $w = $self->{meta_info_win} = GCE::HashDialogue->new (); |
|
|
457 | |
|
|
458 | $w->init ( |
|
|
459 | dialog_default_size => [500, 200, 220, 20], |
|
|
460 | layout_name => 'resize_win', |
|
|
461 | title => 'resize map', |
|
|
462 | ref_hash => $self->{map}{map}{info}, |
|
|
463 | dialog => [ |
|
|
464 | [width => 'Width' => 'string'], |
|
|
465 | [height => 'Height' => 'string'], |
|
|
466 | ], |
|
|
467 | close_on_save => 1, |
|
|
468 | save_cb => sub { |
|
|
469 | my ($info) = @_; |
|
|
470 | $self->{map}{map}->resize ($info->{width}, $info->{height}); |
|
|
471 | $self->{map}->invalidate_all; |
|
|
472 | } |
|
|
473 | ); |
|
|
474 | |
|
|
475 | $w->signal_connect (destroy => sub { delete $self->{meta_info_win} }); |
|
|
476 | |
|
|
477 | $w->show_all; |
|
|
478 | } |
|
|
479 | |
|
|
480 | sub open_attach_edit { |
|
|
481 | my ($self) = @_; |
|
|
482 | |
|
|
483 | my $w = GCE::AttachEditor->new; |
|
|
484 | $w->set_attachment ( |
|
|
485 | $self->{map}{map}{info}{attach}, |
|
|
486 | sub { |
|
|
487 | if (@{$_[0]}) { |
|
|
488 | $self->{map}{map}{info}{attach} = $_[0] |
|
|
489 | } else { |
|
|
490 | delete $self->{map}{map}{info}{attach}; |
|
|
491 | } |
|
|
492 | } |
|
|
493 | ); |
|
|
494 | $self->{attach_editor} = $w; |
|
|
495 | $w->signal_connect (destroy => sub { delete $self->{attach_editor} }); |
|
|
496 | $w->show_all; |
|
|
497 | } |
|
|
498 | |
|
|
499 | sub upload_map_incl { |
|
|
500 | my ($self) = @_; |
|
|
501 | |
|
|
502 | my $meta = dclone $self->{meta_info}; |
|
|
503 | |
|
|
504 | my $w = $self->{meta_info_win} = GCE::HashDialogue->new (); |
|
|
505 | |
|
|
506 | $w->init ( |
|
|
507 | dialog_default_size => [500, 300, 220, 20], |
|
|
508 | layout_name => 'map_upload_incl', |
|
|
509 | title => 'gce - map inclusion upload', |
|
|
510 | ref_hash => $meta, |
|
|
511 | text_entry => { key => 'changes', label => 'Changes (required for inclusion):' }, |
|
|
512 | dialog => [ |
|
|
513 | [gameserver => 'Game server' => 'label'], |
|
|
514 | [testserver => 'Test server' => 'label'], |
|
|
515 | [undef => x => 'sep' ], |
|
|
516 | [cf_login => 'Server login name' => 'string'], |
|
|
517 | [cf_password=> 'Password' => 'password'], |
|
|
518 | [path => 'Map path' => 'string'], |
|
|
519 | ], |
|
|
520 | close_on_save => 1, |
|
|
521 | save_cb => sub { |
|
|
522 | my ($meta) = @_; |
|
|
523 | warn "UPLOAD[".Crossfire::to_json ($meta)."]\n"; |
|
|
524 | } |
|
|
525 | ); |
|
|
526 | |
|
|
527 | $w->signal_connect (destroy => sub { delete $self->{meta_info_win} }); |
|
|
528 | |
|
|
529 | $w->show_all; |
|
|
530 | } |
|
|
531 | |
|
|
532 | sub upload_map_test { |
|
|
533 | my ($self) = @_; |
|
|
534 | |
|
|
535 | my $meta = dclone $self->{meta_info}; |
|
|
536 | |
|
|
537 | my $w = $self->{meta_info_win} = GCE::HashDialogue->new (); |
|
|
538 | |
|
|
539 | $w->init ( |
|
|
540 | dialog_default_size => [500, 300, 220, 20], |
|
|
541 | layout_name => 'map_upload_test', |
|
|
542 | title => 'gce - map test upload', |
|
|
543 | ref_hash => $meta, |
|
|
544 | dialog => [ |
|
|
545 | [gameserver => 'Game server' => 'string'], |
|
|
546 | [testserver => 'Test server' => 'string'], |
|
|
547 | [undef => x => 'sep' ], |
|
|
548 | [cf_login => 'Server login name' => 'string'], |
|
|
549 | [cf_password=> 'Password' => 'password'], |
|
|
550 | [path => 'Map path' => 'string'], |
|
|
551 | ], |
|
|
552 | save_cb => sub { |
|
|
553 | my ($meta) = @_; |
|
|
554 | warn "UPLOAD[".Crossfire::to_json ($meta)."]\n"; |
|
|
555 | } |
|
|
556 | ); |
|
|
557 | |
|
|
558 | $w->signal_connect (destroy => sub { delete $self->{meta_info_win} }); |
|
|
559 | |
|
|
560 | $w->show_all; |
|
|
561 | |
|
|
562 | |
|
|
563 | } |
|
|
564 | |
|
|
565 | sub open_meta_info { |
|
|
566 | my ($self) = @_; |
|
|
567 | |
|
|
568 | return if $self->{meta_info_win}; |
|
|
569 | |
|
|
570 | my $w = $self->{meta_info_win} = GCE::HashDialogue->new (); |
|
|
571 | |
|
|
572 | $w->init ( |
|
|
573 | dialog_default_size => [500, 300, 220, 20], |
|
|
574 | layout_name => 'meta_info_win', |
|
|
575 | title => 'meta info', |
|
|
576 | ref_hash => $self->{meta_info}, |
|
|
577 | dialog => [ |
|
|
578 | [path => 'Map path' => 'string'], |
|
|
579 | [cf_login => 'Login name' => 'string'], |
|
|
580 | [revision => 'CVS Revision' => 'label'], |
|
|
581 | [cvs_root => 'CVS Root' => 'label'], |
|
|
582 | [lib_root => 'LIB Root' => 'label'], |
|
|
583 | [testserver => 'Test server' => 'label'], |
|
|
584 | [gameserver => 'Game server' => 'label'], |
|
|
585 | ], |
|
|
586 | ); |
|
|
587 | |
|
|
588 | $w->signal_connect (destroy => sub { delete $self->{meta_info_win} }); |
|
|
589 | |
|
|
590 | $w->show_all; |
|
|
591 | } |
|
|
592 | |
|
|
593 | sub open_map_info { |
|
|
594 | my ($self) = @_; |
|
|
595 | return if $self->{map_info}; |
|
|
596 | |
|
|
597 | my $w = $self->{map_info} = Gtk2::Window->new ('toplevel'); |
|
|
598 | $w->set_title ("gcrossedit - map info"); |
|
|
599 | |
|
|
600 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
601 | $vb->add (my $sw = Gtk2::ScrolledWindow->new); |
|
|
602 | $sw->set_policy ('automatic', 'automatic'); |
|
|
603 | $sw->add (my $txt = Gtk2::TextView->new); |
|
|
604 | $vb->pack_start (my $hb = Gtk2::HBox->new (1, 1), 0, 1, 0); |
|
|
605 | $hb->pack_start (my $svbtn = Gtk2::Button->new ("save"), 1, 1, 0); |
|
|
606 | $hb->pack_start (my $logbtn = Gtk2::Button->new ("add log"), 1, 1, 0); |
|
|
607 | $hb->pack_start (my $closebtn = Gtk2::Button->new ("close"), 1, 1, 0); |
|
|
608 | |
|
|
609 | my $buf = $txt->get_buffer (); |
|
|
610 | $buf->set_text ($self->{map}{map}{info}{msg}); |
|
|
611 | |
|
|
612 | $svbtn->signal_connect (clicked => sub { |
|
|
613 | my $buf = $txt->get_buffer (); |
|
|
614 | my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0); |
|
|
615 | $self->{map}{map}{info}{msg} = $txt; |
|
|
616 | }); |
|
|
617 | |
|
|
618 | $logbtn->signal_connect (clicked => sub { |
|
|
619 | my $buf = $txt->get_buffer (); |
|
|
620 | $buf->insert ($buf->get_start_iter, "- " . strftime ("%F %T %Z", localtime (time)) . " by " . ($main::CFG->{username} || $ENV{USER}) . ":\n"); |
|
|
621 | $txt->set_buffer ($buf); |
|
|
622 | }); |
|
|
623 | |
|
|
624 | $closebtn->signal_connect (clicked => sub { |
|
|
625 | $w->destroy; |
|
|
626 | }); |
|
|
627 | |
|
|
628 | ::set_pos_and_size ($w, $main::CFG->{map_info}, 400, 400, 220, 20); |
|
|
629 | $w->signal_connect (destroy => sub { |
|
|
630 | delete $self->{map_info}; |
|
|
631 | }); |
|
|
632 | $w->show_all; |
|
|
633 | } |
|
|
634 | |
|
|
635 | sub open_map_prop { |
|
|
636 | my ($self) = @_; |
|
|
637 | |
|
|
638 | return if $self->{map_properties}; |
|
|
639 | |
|
|
640 | my $w = $self->{map_properties} = GCE::HashDialogue->new (); |
|
|
641 | |
|
|
642 | $w->init ( |
|
|
643 | dialog_default_size => [500, 500, 220, 20], |
|
|
644 | layout_name => 'map_prop_win', |
|
|
645 | title => 'map properties', |
|
|
646 | ref_hash => $self->{map}{map}{info}, |
|
|
647 | close_on_save => 1, |
|
|
648 | dialog => [ |
|
|
649 | [qw/name Name string/], |
|
|
650 | [qw/region Region string/], |
|
|
651 | [qw/enter_x Enter-x string/], |
|
|
652 | [qw/enter_y Enter-y string/], |
|
|
653 | [qw/reset_timeout Reset-timeout string/], |
|
|
654 | [qw/swap_time Swap-timeout string/], |
|
|
655 | [undef, qw/x sep/], |
|
|
656 | [qw/difficulty Difficulty string/], |
|
|
657 | [qw/windspeed Windspeed string/], |
|
|
658 | [qw/pressure Pressure string/], |
|
|
659 | [qw/humid Humid string/], |
|
|
660 | [qw/temp Temp string/], |
|
|
661 | [qw/darkness Darkness string/], |
|
|
662 | [qw/sky Sky string/], |
|
|
663 | [qw/winddir Winddir string/], |
|
|
664 | [undef, qw/x sep/], |
|
|
665 | [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }], |
|
|
666 | [qw/height Height label/], # sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }], |
|
|
667 | [undef, qw/x sep/], |
|
|
668 | # [qw/msg Text text/], |
|
|
669 | # [qw/maplore Maplore text/], |
|
|
670 | [qw/outdoor Outdoor check/], |
|
|
671 | [qw/unique Unique check/], |
|
|
672 | [qw/fixed_resettime Fixed-resettime check/], |
|
|
673 | [per_player => 'Per player' => 'check'], |
|
|
674 | [per_party => 'Per party' => 'check'], |
|
|
675 | [no_reset => 'No reset' => 'check'], |
|
|
676 | [undef, qw/x sep/], |
|
|
677 | [qw/tile_path_1 Northpath string/], |
|
|
678 | [qw/tile_path_2 Eastpath string/], |
|
|
679 | [qw/tile_path_3 Southpath string/], |
|
|
680 | [qw/tile_path_4 Westpath string/], |
|
|
681 | [qw/tile_path_5 Toppath string/], |
|
|
682 | [qw/tile_path_6 Bottompath string/], |
|
|
683 | [undef, qw/x sep/], |
|
|
684 | [undef, 'For shop description look in the manual', |
|
|
685 | 'button', sub { $::MAINWIN->show_help_window }], |
|
|
686 | [qw/shopmin Shopmin string/], |
|
|
687 | [qw/shopmax Shopmax string/], |
|
|
688 | [qw/shoprace Shoprace string/], |
|
|
689 | [qw/shopgreed Shopgreed string/], |
|
|
690 | [qw/shopitems Shopitems string/], |
|
|
691 | ] |
|
|
692 | ); |
|
|
693 | |
|
|
694 | $w->signal_connect (destroy => sub { delete $self->{map_properties} }); |
|
|
695 | $w->show_all; |
|
|
696 | } |
|
|
697 | |
|
|
698 | ################################################################# |
|
|
699 | ###### MAP EDITOR INIT ########################################## |
|
|
700 | ################################################################# |
161 | |
701 | |
162 | sub INIT_INSTANCE { |
702 | sub INIT_INSTANCE { |
163 | my ($self) = @_; |
703 | my ($self) = @_; |
164 | |
704 | |
165 | $self->set_title ('gce - map editor'); |
705 | $self->set_title ('gce - map editor'); |
… | |
… | |
275 | $X++ if $X < $x; |
815 | $X++ if $X < $x; |
276 | $X-- if $X > $x; |
816 | $X-- if $X > $x; |
277 | $Y++ if $Y < $y; |
817 | $Y++ if $Y < $y; |
278 | $Y-- if $Y > $y; |
818 | $Y-- if $Y > $y; |
279 | |
819 | |
|
|
820 | unless ($ea->only_on_click) { |
280 | $ea->edit ($map, $X, $Y, $self) |
821 | $ea->edit ($map, $X, $Y, $self) |
281 | if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height}; |
822 | if $X >= 0 and $Y >= 0 and $X < $map->{map}{width} and $Y < $map->{map}{height}; |
|
|
823 | } |
282 | } |
824 | } |
283 | |
825 | |
284 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
826 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
285 | |
827 | |
286 | 1 |
828 | 1 |
… | |
… | |
300 | return 1; |
842 | return 1; |
301 | } |
843 | } |
302 | |
844 | |
303 | 0 |
845 | 0 |
304 | }); |
846 | }); |
305 | } |
|
|
306 | |
847 | |
307 | sub start_drawmode { |
848 | ::set_pos_and_size ($self, $main::CFG->{map_window}, 500, 500, 200, 0); |
308 | my ($self, $map) = @_; |
|
|
309 | |
|
|
310 | $self->{draw_mode} and return; |
|
|
311 | |
|
|
312 | # XXX: is this okay? my ($x, $y) = $map->coord ($event->x, $event->y); |
|
|
313 | my ($x, $y) = $map->coord ($map->get_pointer); |
|
|
314 | |
|
|
315 | my $ea = $self->ea; |
|
|
316 | |
|
|
317 | $ea->begin ($map, $x, $y, $self); |
|
|
318 | |
|
|
319 | $ea->edit ($map, $x, $y, $self) |
|
|
320 | if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; |
|
|
321 | |
|
|
322 | $self->{draw_mode} = [$x, $y]; |
|
|
323 | } |
|
|
324 | |
|
|
325 | sub stop_drawmode { |
|
|
326 | my ($self, $map) = @_; |
|
|
327 | |
|
|
328 | $self->{draw_mode} or return; |
|
|
329 | |
|
|
330 | my ($x, $y) = $map->coord ($map->get_pointer); |
|
|
331 | |
|
|
332 | my $ea = $self->ea; |
|
|
333 | $ea->end ($map, $x, $y, $self); |
|
|
334 | |
|
|
335 | delete $self->{draw_mode}; |
|
|
336 | } |
|
|
337 | |
|
|
338 | # FIXME: Fix the automatic update of the attribute editor! and also the stack view! |
|
|
339 | sub undo { |
|
|
340 | my ($self) = @_; |
|
|
341 | |
|
|
342 | my $map = $self->{map}; # the Crossfire::MapWidget |
|
|
343 | |
|
|
344 | $map->{undo_stack_pos} |
|
|
345 | or return; |
|
|
346 | |
|
|
347 | $map->change_swap ($map->{undo_stack}[--$map->{undo_stack_pos}]); |
|
|
348 | } |
|
|
349 | |
|
|
350 | sub redo { |
|
|
351 | my ($self) = @_; |
|
|
352 | |
|
|
353 | my $map = $self->{map}; # the Crossfire::MapWidget |
|
|
354 | |
|
|
355 | $map->{undo_stack} |
|
|
356 | and $map->{undo_stack_pos} < @{$map->{undo_stack}} |
|
|
357 | or return; |
|
|
358 | |
|
|
359 | $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]); |
|
|
360 | } |
|
|
361 | |
|
|
362 | sub open_map { |
|
|
363 | my ($self, $path, $key) = @_; |
|
|
364 | |
|
|
365 | $self->{mapkey} = $key; |
|
|
366 | |
|
|
367 | if (ref $path) { |
|
|
368 | $self->{map}->set_map ($path); |
|
|
369 | |
|
|
370 | } else { |
|
|
371 | $self->{path} = $path; |
|
|
372 | # print "OPENMAP $path\n"; |
|
|
373 | $self->{map}->set_map (my $m = new_from_file Crossfire::Map $path); |
|
|
374 | require Data::Dumper; |
|
|
375 | # print "FOO:" .Data::Dumper::Dumper ($m) . "\n"; |
|
|
376 | } |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub save_map { |
|
|
380 | my ($self) = @_; |
|
|
381 | |
|
|
382 | if ($self->{path}) { |
|
|
383 | $self->{map}{map}->write_file ($self->{path}); |
|
|
384 | quick_msg ($self, "saved to $self->{path}"); |
|
|
385 | } else { |
|
|
386 | $self->save_map_as; |
|
|
387 | } |
|
|
388 | } |
|
|
389 | |
|
|
390 | sub save_map_as { |
|
|
391 | my ($self) = @_; |
|
|
392 | |
|
|
393 | my $fc = $::MAINWIN->new_filechooser ('gce - save map', 1, $self->{path}); |
|
|
394 | |
|
|
395 | if ('ok' eq $fc->run) { |
|
|
396 | |
|
|
397 | $::MAINWIN->{fc_last_folder} = $fc->get_current_folder; |
|
|
398 | $::MAINWIN->{fc_last_folders}->{$self->{fc_last_folder}}++; |
|
|
399 | |
|
|
400 | $self->{map}{map}->write_file ($self->{path} = $fc->get_filename); |
|
|
401 | quick_msg ($self, "saved to $self->{path}"); |
|
|
402 | } |
|
|
403 | |
|
|
404 | $fc->destroy; |
|
|
405 | } |
|
|
406 | |
|
|
407 | sub _add_prop_entry { |
|
|
408 | my ($self, $table, $idx, $key, $desc, $type, $changecb) = @_; |
|
|
409 | |
|
|
410 | my $edwid; |
|
|
411 | |
|
|
412 | if ($type eq 'string') { |
|
|
413 | $table->attach_defaults (my $lbl = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
|
|
414 | $edwid = Gtk2::Entry->new; |
|
|
415 | $edwid->set_text ($self->{map}{map}{info}{$key}); |
|
|
416 | $edwid->signal_connect (changed => sub { |
|
|
417 | $self->{map}{map}{info}{$key} = $_[0]->get_text; |
|
|
418 | if ($changecb) { |
|
|
419 | $changecb->($_[0]->get_text); |
|
|
420 | } |
|
|
421 | }); |
|
|
422 | $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1); |
|
|
423 | |
|
|
424 | } elsif ($type eq 'button') { |
|
|
425 | $table->attach_defaults (my $b = Gtk2::Button->new_with_label ($desc), 0, 2, $idx, $idx + 1); |
|
|
426 | $b->signal_connect (clicked => ($changecb || sub {})); |
|
|
427 | |
|
|
428 | } elsif ($type eq 'label') { |
|
|
429 | $table->attach_defaults (my $lbl = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
|
|
430 | $edwid = Gtk2::Label->new ($self->{map}{map}{info}{$key}); |
|
|
431 | $table->attach_defaults ($edwid, 1, 2, $idx, $idx + 1); |
|
|
432 | |
|
|
433 | } elsif ($type eq 'check') { |
|
|
434 | $table->attach_defaults (my $lbl1 = Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
|
|
435 | $table->attach_defaults (my $lbl = Gtk2::CheckButton->new, 1, 2, $idx, $idx + 1); |
|
|
436 | $lbl->set_active ($self->{map}{map}{info}{$key}); |
|
|
437 | $lbl->signal_connect (toggled => sub { |
|
|
438 | my ($lbl) = @_; |
|
|
439 | $self->{map}{map}{info}{$key} = $lbl->get_active * 1; |
|
|
440 | ($changecb || sub {})->($lbl->get_active); |
|
|
441 | }); |
|
|
442 | |
|
|
443 | } elsif ($type eq 'sep') { |
|
|
444 | $table->attach_defaults (my $lbl1 = Gtk2::HSeparator->new, 0, 2, $idx, $idx + 1); |
|
|
445 | } else { |
|
|
446 | $edwid = Gtk2::Label->new ("FOO"); |
|
|
447 | } |
|
|
448 | } |
|
|
449 | |
|
|
450 | sub open_resize_map { |
|
|
451 | my ($self) = @_; |
|
|
452 | |
|
|
453 | my $w = Gtk2::Window->new ('toplevel'); |
|
|
454 | $w->set_default_size (250, 150); |
|
|
455 | $w->add (my $sw = Gtk2::ScrolledWindow->new); |
|
|
456 | $sw->add_with_viewport (my $v = Gtk2::VBox->new); |
|
|
457 | $sw->set_policy ('automatic', 'automatic'); |
|
|
458 | $v->pack_start (my $t = Gtk2::Table->new (2, 10), 0, 0, 0); |
|
|
459 | |
|
|
460 | my $i = 0; |
|
|
461 | for ( |
|
|
462 | [qw/width Width string/], |
|
|
463 | [qw/height Height string/], |
|
|
464 | [qw/save Save button/, |
|
|
465 | sub { |
|
|
466 | $self->{map}{map}->resize ($self->{map}{map}{info}{width}, $self->{map}{map}{info}{height}); |
|
|
467 | $self->{map}->invalidate_all; |
|
|
468 | $w->destroy; |
|
|
469 | } |
|
|
470 | ], |
|
|
471 | ) |
|
|
472 | { |
|
|
473 | $self->_add_prop_entry ($t, $i++, @$_); |
|
|
474 | } |
|
|
475 | |
|
|
476 | $w->show_all; |
|
|
477 | } |
|
|
478 | |
|
|
479 | sub follow { |
|
|
480 | my ($self, $dir) = @_; |
|
|
481 | |
|
|
482 | my %dir_to_path = ( |
|
|
483 | u => 'tile_path_1', |
|
|
484 | d => 'tile_path_3', |
|
|
485 | r => 'tile_path_2', |
|
|
486 | l => 'tile_path_4', |
|
|
487 | ); |
|
|
488 | |
|
|
489 | defined $dir_to_path{$dir} |
|
|
490 | or return; |
|
|
491 | my $map = $self->{map}{map}{info}{$dir_to_path{$dir}} |
|
|
492 | or return; |
|
|
493 | |
|
|
494 | $map = map2abs ($map, $self); |
|
|
495 | $::MAINWIN->open_map_editor ($map); |
|
|
496 | } |
|
|
497 | |
|
|
498 | sub open_map_prop { |
|
|
499 | my ($self) = @_; |
|
|
500 | |
|
|
501 | |
|
|
502 | my $w = Gtk2::Window->new ('toplevel'); |
|
|
503 | $w->set_default_size (500, 500); |
|
|
504 | $w->add (my $sw = Gtk2::ScrolledWindow->new); |
|
|
505 | $sw->add_with_viewport (my $v = Gtk2::VBox->new); |
|
|
506 | $sw->set_policy ('automatic', 'automatic'); |
|
|
507 | $v->pack_start (my $t = Gtk2::Table->new (2, 10), 0, 0, 0); |
|
|
508 | |
|
|
509 | my $i = 0; |
|
|
510 | for ( |
|
|
511 | [qw/name Name string/], |
|
|
512 | [qw/region Region string/], |
|
|
513 | [qw/enter_x Enter-x string/], |
|
|
514 | [qw/enter_y Enter-y string/], |
|
|
515 | [qw/reset_timeout Reset-timeout string/], |
|
|
516 | [qw/swap_time Swap-timeout string/], |
|
|
517 | [qw/x x sep/], |
|
|
518 | [qw/difficulty Difficulty string/], |
|
|
519 | [qw/windspeed Windspeed string/], |
|
|
520 | [qw/pressure Pressure string/], |
|
|
521 | [qw/humid Humid string/], |
|
|
522 | [qw/temp Temp string/], |
|
|
523 | [qw/darkness Darkness string/], |
|
|
524 | [qw/sky Sky string/], |
|
|
525 | [qw/winddir Winddir string/], |
|
|
526 | [qw/x x sep/], |
|
|
527 | [qw/width Width label/], # sub { $self->{map}{map}->resize ($_[0], $self->{map}{map}{height}) }], |
|
|
528 | [qw/height Height label/], # sub { $self->{map}{map}->resize ($self->{map}{map}{width}, $_[0]) }], |
|
|
529 | [qw/x x sep/], |
|
|
530 | [qw/msg Text text/], |
|
|
531 | [qw/maplore Maplore text/], |
|
|
532 | [qw/outdoor Outdoor check/], |
|
|
533 | [qw/unique Unique check/], |
|
|
534 | [qw/fixed_resettime Fixed-resettime check/], |
|
|
535 | [qw/x x sep/], |
|
|
536 | [qw/tile_path_1 Northpath string/], |
|
|
537 | [qw/tile_path_2 Eastpath string/], |
|
|
538 | [qw/tile_path_3 Southpath string/], |
|
|
539 | [qw/tile_path_4 Westpath string/], |
|
|
540 | [qw/tile_path_5 Toppath string/], |
|
|
541 | [qw/tile_path_6 Bottompath string/], |
|
|
542 | ) |
|
|
543 | { |
|
|
544 | $self->_add_prop_entry ($t, $i++, @$_); |
|
|
545 | } |
|
|
546 | |
|
|
547 | $w->show_all; |
|
|
548 | } |
849 | } |
549 | |
850 | |
550 | =head1 AUTHOR |
851 | =head1 AUTHOR |
551 | |
852 | |
552 | Marc Lehmann <schmorp@schmorp.de> |
853 | Marc Lehmann <schmorp@schmorp.de> |
… | |
… | |
554 | |
855 | |
555 | Robin Redeker <elmex@ta-sa.org> |
856 | Robin Redeker <elmex@ta-sa.org> |
556 | http://www.ta-sa.org/ |
857 | http://www.ta-sa.org/ |
557 | |
858 | |
558 | =cut |
859 | =cut |
559 | 1; |
|
|
560 | |
860 | |
|
|
861 | 1 |
|
|
862 | |