ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MainWindow.pm
Revision: 1.80
Committed: Mon Aug 20 07:56:58 2007 UTC (16 years, 9 months ago) by elmex
Branch: MAIN
CVS Tags: rel-2_2
Changes since 1.79: +74 -1 lines
Log Message:
applied irwiss patch with two minor modifications:

- ->isa instead of =~ /MenuBar/
- wrapped the reading of recent files in a block

File Contents

# User Rev Content
1 elmex 1.1 package GCE::MainWindow;
2    
3     =head1 NAME
4    
5     GCE::MainWindow - the main window class for gce
6    
7     =cut
8    
9 elmex 1.58 use Cwd qw/abs_path getcwd/;
10 elmex 1.1 use Gtk2;
11     use Gtk2::Gdk::Keysyms;
12 elmex 1.2 use Gtk2::SimpleMenu;
13 root 1.7
14     use Crossfire;
15 elmex 1.32 use Crossfire::Map;
16 root 1.7 use Crossfire::MapWidget;
17    
18 elmex 1.2 use GCE::AttrEdit;
19 elmex 1.13 use GCE::MapEditor;
20 elmex 1.15 use GCE::StackView;
21 elmex 1.17 use GCE::EditAction;
22     use GCE::PickWindow;
23 elmex 1.2
24 elmex 1.53 use Glib::Object::Subclass
25 elmex 1.13 Gtk2::Window;
26 elmex 1.2
27 elmex 1.28 use GCE::Util;
28 elmex 1.54 use GCE::DragHelper;
29 elmex 1.28
30 elmex 1.2 use strict;
31    
32 elmex 1.80 my $recentfile = "$Crossfire::VARDIR/gcerecent";
33    
34 elmex 1.18 # XXX: make a recursive call from save_layout to all (interesting) sub-widgets
35 elmex 1.17 sub save_layout {
36     my ($self) = @_;
37    
38 elmex 1.58 # $main::CFG->{attr_edit_on} = exists $self->{attr_edit} ? 1 : 0;
39 elmex 1.17 $main::CFG->{stack_view_on} = exists $self->{sv} ? 1 : 0;
40     $main::CFG->{picker_on} = exists $self->{last_pick_window} ? 1 : 0;
41     $main::CFG->{main_window} = main::get_pos_and_size ($self);
42     $main::CFG->{stack_view} = main::get_pos_and_size ($self->{sv_win}) if $self->{sv_win};
43     $main::CFG->{attr_view} = main::get_pos_and_size ($self->{attr_edit_win}) if $self->{attr_edit_win};
44    
45 elmex 1.70 if ($self->{last_map_window}) {
46     $main::CFG->{map_window} = main::get_pos_and_size ($self->{last_map_window});
47     $self->{last_map_window}->save_layout ();
48     }
49 elmex 1.69
50 elmex 1.75 $self->{worldmap_coord_query}->save_layout ()
51     if $self->{worldmap_coord_query};
52 elmex 1.73
53 elmex 1.37 $main::CFG->{last_folders} = $self->{fc_last_folders};
54    
55 elmex 1.17 $main::CFG->{open_pickers} = [];
56    
57     for (@{$self->{open_pick_windows}}) {
58    
59     next unless defined $_;
60    
61     push @{$main::CFG->{open_pickers}}, {
62     p_and_s => main::get_pos_and_size ($_),
63     selection => $_->{last_selection}
64     };
65     }
66    
67 elmex 1.59 $self->{attr_edit}->save_layout;
68    
69 root 1.26 main::write_cfg ("$Crossfire::VARDIR/gceconfig");
70 elmex 1.17 }
71    
72     sub load_layout {
73     my ($self) = @_;
74    
75 elmex 1.37 $self->{fc_last_folders} = $main::CFG->{last_folders};
76    
77 elmex 1.58 # $main::CFG->{attr_edit_on}
78     # and $self->show_attr_editor;
79 elmex 1.17
80     $main::CFG->{stack_view_on}
81     and $self->show_stack_view;
82    
83     for (@{$main::CFG->{open_pickers}}) {
84     $self->open_pick_window ($_);
85     }
86 elmex 1.59
87     $self->{attr_edit}->load_layout;
88 elmex 1.17 }
89    
90     sub open_map_editor {
91     my ($self, $mapfile) = @_;
92    
93 elmex 1.44 my $mapkey;
94 elmex 1.39 unless (ref $mapfile) {
95 elmex 1.58 # unless (File::Spec->file_name_is_absolute ($mapfile)) {
96     # $mapfile = File::Spec->rel2abs ($mapfile);
97     # }
98     $mapkey = abs_path ($mapfile);
99 elmex 1.76 # File::Spec->abs2rel ($mapfile, File::Spec->catfile ($::MAPDIR));
100 elmex 1.58 } else {
101     $mapkey = "$mapfile";
102 elmex 1.38 }
103    
104 elmex 1.17 # XXX: last_map_window is a dirty trick to get the position and size
105     # for save layout
106    
107 elmex 1.58 if (defined $self->{loaded_maps}->{$mapkey}) {
108     $self->{loaded_maps}->{$mapkey}->get_toplevel->present;
109     return;
110 elmex 1.38 }
111    
112 elmex 1.17 my $w = $self->{last_map_window} = GCE::MapEditor->new;
113 root 1.25
114 elmex 1.53 $self->{editors}->{$w} = $w;
115    
116     $w->signal_connect (destroy => sub {
117     my ($w) = @_;
118 elmex 1.67 $w->close_windows;
119 elmex 1.53 delete $self->{loaded_maps}->{$w->{mapkey}};
120     delete $self->{editors}->{$w};
121     0;
122     });
123    
124 elmex 1.58 $self->{loaded_maps}->{$mapkey} = $w;
125 elmex 1.38
126 elmex 1.72 eval { $w->open_map ($mapfile, $mapkey) };
127     if ($@) {
128     quick_msg ($self, "$@", 1);
129     $w->close_windows;
130     delete $self->{loaded_maps}->{$w->{mapkey}};
131     delete $self->{editors}->{$w};
132     $w->destroy;
133     return;
134     }
135 elmex 1.17
136 elmex 1.54 $w->set_edit_tool ($self->{sel_editaction});
137    
138 elmex 1.17 $w->show_all;
139     }
140    
141 elmex 1.47 sub show_help_window {
142     my ($self) = @_;
143    
144     return if defined $self->{help_win};
145 elmex 1.51 require Gtk2::Ex::PodViewer;
146 elmex 1.47 my $w = $self->{help_win} = Gtk2::Window->new;
147 elmex 1.66 $w->set_title ("gcrossedit - help");
148 elmex 1.47 $w->set_default_size (500, 300);
149 elmex 1.56 $w->signal_connect (destroy => sub {
150 elmex 1.53 $self->{help_win}->hide; $self->{help_win} = undef;
151     0
152     });
153 elmex 1.47 $w->add (my $sw = Gtk2::ScrolledWindow->new);
154 elmex 1.51 $sw->add (my $h = Gtk2::Ex::PodViewer->new);
155 elmex 1.47 $h->load_string ($::DOCUMENTATION);
156     $w->show_all;
157     }
158    
159 elmex 1.17 sub show_stack_view {
160 elmex 1.15 my ($self) = @_;
161    
162     return if defined $self->{sv};
163    
164 elmex 1.17 my $w = $self->{sv_win} = Gtk2::Window->new ('toplevel');
165 elmex 1.66 $w->set_title ('gcrossedit - stack view');
166 elmex 1.56 $w->signal_connect (destroy => sub { delete $self->{sv}; 0 });
167 elmex 1.15 $w->add ($self->{sv} = GCE::StackView->new);
168 elmex 1.17
169 elmex 1.30 main::set_pos_and_size ($w, $main::CFG->{stack_view}, 150, 250);
170 elmex 1.17
171 elmex 1.15 $w->show_all;
172     }
173    
174 elmex 1.46 sub show_editor_properties {
175     my ($self) = @_;
176    
177     return if $self->{prop_edit};
178    
179     my $w = $self->{prop_edit} = Gtk2::Window->new;
180 elmex 1.66 $w->set_title ("gcrossedit - preferences");
181 elmex 1.74 $w->add (my $t = Gtk2::Table->new (2, 5));
182 elmex 1.68 $t->attach_defaults (my $lbl1 = Gtk2::Label->new ("LIBDIR"), 0, 1, 0, 1);
183 elmex 1.46 $t->attach_defaults (my $lib = Gtk2::Entry->new, 1, 2, 0, 1);
184     $lib->set_text ($::CFG->{LIBDIR});
185 elmex 1.68 $t->attach_defaults (my $lbl2 = Gtk2::Label->new ("MAPDIR"), 0, 1, 1, 2);
186 elmex 1.46 $t->attach_defaults (my $map = Gtk2::Entry->new, 1, 2, 1, 2);
187     $map->set_text ($::CFG->{MAPDIR});
188 elmex 1.74 $t->attach_defaults (my $lbl1 = Gtk2::Label->new ("Username"), 0, 1, 2, 3);
189     $t->attach_defaults (my $usern = Gtk2::Entry->new, 1, 2, 2, 3);
190     $usern->set_text ($::CFG->{username});
191     $t->attach_defaults (my $save = Gtk2::Button->new ('save'), 0, 2, 3, 4);
192 elmex 1.46 $save->signal_connect (clicked => sub {
193 elmex 1.74 $::CFG->{LIBDIR} = $lib->get_text;
194     $::CFG->{MAPDIR} = $map->get_text;
195     $::LIBDIR = $::CFG->{LIBDIR} if $::CFG->{LIBDIR};
196     $::MAPDIR = $::CFG->{MAPDIR} if $::CFG->{MAPDIR};
197     $::CFG->{username} = $usern->get_text;
198     Crossfire::set_libdir ($::LIBDIR);
199 elmex 1.46 Crossfire::load_archetypes;
200     Crossfire::load_tilecache;
201     main::write_cfg ("$Crossfire::VARDIR/gceconfig");
202     $w->destroy;
203     });
204 elmex 1.74 $t->attach_defaults (my $close = Gtk2::Button->new ('close'), 0, 2, 4, 5);
205 elmex 1.46 $close->signal_connect (clicked => sub { $w->destroy });
206    
207 elmex 1.56 $w->signal_connect (destroy => sub { delete $self->{prop_edit}; 0 });
208 elmex 1.46
209     main::set_pos_and_size ($w, $main::CFG->{prop_edit}, 200, 200);
210    
211     $w->show_all;
212     }
213    
214 elmex 1.15 sub show_attr_editor {
215     my ($self) = @_;
216    
217 elmex 1.79 return if $self->{attr_edit_win};
218    
219 elmex 1.15 my $w = $self->{attr_edit_win} = Gtk2::Window->new;
220 elmex 1.66 $w->set_title ("gcrossedit - edit attrs");
221 elmex 1.15 $w->add ($self->{attr_edit} = GCE::AttrEdit->new);
222 elmex 1.79 $w->signal_connect (destroy => sub { delete $self->{attr_edit_win}; 0 });
223 elmex 1.17
224 elmex 1.64 main::set_pos_and_size ($w, $main::CFG->{attr_view}, 400, 300, 250, 0);
225 elmex 1.17
226 elmex 1.15 $w->show_all;
227     }
228    
229     sub update_attr_editor {
230 elmex 1.61 my ($self, $ar) = @_;
231    
232     if (ref ($ar) ne 'GCE::ArchRef') { require Carp; Carp::confess ("$ar no ARCHREF!") }
233 elmex 1.15
234 elmex 1.58 $self->{attr_edit}
235     or die "SERIOUS BUG: Couldn't find attribut editor!";
236 elmex 1.15
237 elmex 1.61 $self->{attr_edit}->set_arch ($ar, 1);
238 elmex 1.66 $self->{attr_edit_win}->set_title ("gcrossedit - edit " . $ar->longname);
239 elmex 1.15 }
240    
241     sub update_stack_view {
242 elmex 1.17 my ($self, $mapedit, $x, $y) = @_;
243 elmex 1.15
244     return unless $self->{sv};
245    
246 elmex 1.17 $self->{sv}->set_stack ($mapedit, $x, $y);
247 elmex 1.62
248 elmex 1.15 }
249    
250 elmex 1.17 sub open_pick_window {
251     my ($self, $layout) = @_;
252    
253 root 1.29 # XXX: Yes, also fix this, save _every_ pick window and their positions and their
254 elmex 1.17 # selection
255     my $p = GCE::PickWindow->new ();
256 elmex 1.15
257 elmex 1.17 push @{$self->{open_pick_windows}}, $p;
258    
259     my $idx = (@{$self->{open_pick_windows}}) - 1;
260 elmex 1.15
261 elmex 1.17 $p->signal_connect ('delete-event' => sub {
262     $self->{open_pick_windows}->[$idx] = undef;
263     });
264 elmex 1.10
265 elmex 1.17 if ($layout) {
266 elmex 1.30 main::set_pos_and_size ($p, $layout->{p_and_s}, 200, 200);
267 elmex 1.17 }
268 elmex 1.10
269 elmex 1.17 $p->show_all;
270 elmex 1.10
271 elmex 1.17 $p->set_selection ($layout->{selection});
272 elmex 1.10 }
273    
274 elmex 1.80 sub add_recent {
275     my ($self, $entry) = @_;
276     our @recent_entries;
277    
278     @recent_entries = grep { $_ ne $entry } @recent_entries;
279     unshift @recent_entries, $entry;
280     splice @recent_entries, 5;
281    
282     open my $fh, ">$recentfile" or die "Can't write to file $recentfile: $!";
283     binmode $fh;
284     local $/;
285     print $fh (join "\0", @recent_entries);
286     close $fh;
287    
288     $self->build_menu;
289     }
290    
291     sub escape_filename {
292     my $str = shift;
293    
294     $str = Glib::filename_to_unicode($str);
295    
296     # escape to prevent Gtk2::SimpleMenu parsing these especially
297     $str =~ s/\//\\\//g;
298     $str =~ s/_/__/g;
299    
300     $str;
301     }
302    
303     sub recent {
304     my ($self) = @_;
305     my @recent;
306    
307     our @recent_entries;
308    
309     foreach my $entry(@recent_entries) {
310     push @recent, escape_filename($entry) => {
311     callback => sub { $self->open_map_editor($entry);
312     $self->build_menu }
313     };
314     }
315    
316     push @recent, Empty => { callback => sub {} }
317     unless @recent;
318    
319     @recent;
320     }
321    
322 elmex 1.13 sub build_menu {
323 elmex 1.1 my ($self) = @_;
324    
325 elmex 1.2 my $menu_tree = [
326     _File => {
327     item_type => '<Branch>',
328     children => [
329     _New => {
330     callback => sub { $self->new_cb },
331     accelerator => '<ctrl>N'
332     },
333     _Open => {
334     callback => sub { $self->open_cb },
335     accelerator => '<ctrl>O'
336     },
337 elmex 1.71 'Open special' => {
338     item_type => '<Branch>',
339     children => [
340     "world map at"=> {
341     callback => sub { $self->open_worldmap_cb },
342     },
343 elmex 1.80 "recent files"=> {
344     item_type => '<Branch>',
345     children => [ $self->recent ],
346     },
347 elmex 1.71 ]
348     },
349 elmex 1.17 "_Save Layout" => {
350     callback => sub { $self->save_layout },
351     accelerator => '<ctrl>L'
352     },
353 elmex 1.52 "_Preferences" => {
354 elmex 1.46 callback => sub { $self->show_editor_properties },
355     accelerator => "<ctrl>T"
356     },
357 elmex 1.49 _Quit => {
358 elmex 1.2 callback => sub { Gtk2->main_quit },
359     accelerator => '<ctrl>Q'
360 elmex 1.47 },
361 elmex 1.2 ]
362     },
363 root 1.24 _Dialogs => {
364 elmex 1.2 item_type => '<Branch>',
365     children => [
366 elmex 1.17 "_Picker" => {
367     callback => sub { $self->open_pick_window },
368     accelerator => "<ctrl>P"
369     },
370     "_Stack View" => {
371     callback => sub { $self->show_stack_view },
372     accelerator => "<ctrl>V"
373     },
374 elmex 1.79 "_Attributes" => {
375     callback => sub { $self->show_attr_editor },
376     accelerator => "<ctrl>A"
377     },
378 elmex 1.2 ]
379 elmex 1.47 },
380 elmex 1.49 _Help => {
381     item_type => '<Branch>',
382     children => [
383 elmex 1.50 _Manual => {
384 elmex 1.49 callback => sub { $self->show_help_window },
385     accelerator => "<ctrl>H"
386     },
387     ]
388     },
389 elmex 1.2 ];
390    
391 elmex 1.13 my $men =
392     Gtk2::SimpleMenu->new (
393     menu_tree => $menu_tree,
394     default_callback => \&default_cb,
395     );
396 elmex 1.10
397 elmex 1.80 for ($self->{vb}->get_children) { # Rebuild menu
398     if ($_->isa ('Gtk2::MenuBar')) {
399     $_->hide;
400     $self->{vb}->remove($_);
401    
402     $self->{vb}->pack_start ($men->{widget}, 0, 1, 0);
403     $self->{vb}->reorder_child ($men->{widget}, 0);
404     $self->{vb}->show_all;
405     }
406     }
407    
408 elmex 1.2 $self->add_accel_group ($men->{accel_group});
409    
410 elmex 1.13 return $men->{widget};
411     }
412 elmex 1.10
413 elmex 1.17 sub add_button {
414     my ($self, $table, $plcinfo, $lbl, $cb) = @_;
415    
416     my ($lx, $ly) = @{$plcinfo->{next}};
417    
418     unless ($lx < $plcinfo->{width}) {
419    
420     $ly++;
421     $lx = 0;
422     }
423    
424     $ly < $plcinfo->{height}
425     or die "too many buttons, make table bigger!";
426    
427 elmex 1.42 $table->attach_defaults (my $btn = Gtk2::Button->new_with_mnemonic ($lbl), $lx, $lx + 1, $ly, $ly + 1);
428 elmex 1.17 $btn->signal_connect (clicked => $cb);
429    
430     $plcinfo->{next} = [$lx + 1, $ly];
431     }
432    
433     sub build_buttons {
434     my ($self) = @_;
435    
436 elmex 1.38 my $tbl = Gtk2::Table->new (2, 4);
437     my $plcinfo = { width => 2, height => 4, next => [0, 0] };
438 elmex 1.17
439 elmex 1.38 $self->{edit_collection}{pick} = GCE::EditAction::Pick->new;
440     $self->{edit_collection}{place} = GCE::EditAction::Place->new;
441     $self->{edit_collection}{erase} = GCE::EditAction::Erase->new;
442     $self->{edit_collection}{select} = GCE::EditAction::Select->new;
443     $self->{edit_collection}{perl} = GCE::EditAction::Perl->new;
444 elmex 1.63 $self->{edit_collection}{connect} = GCE::EditAction::Connect->new;
445 elmex 1.38 $self->{edit_collection}{followexit} = GCE::EditAction::FollowExit->new;
446 elmex 1.17
447 elmex 1.33 $self->set_edit_tool ('pick');
448 elmex 1.28
449 elmex 1.42 $self->add_button ($tbl, $plcinfo, "P_ick", sub { $self->set_edit_tool ('pick') });
450     $self->add_button ($tbl, $plcinfo, "_Place", sub { $self->set_edit_tool ('place') });
451     $self->add_button ($tbl, $plcinfo, "_Erase", sub { $self->set_edit_tool ('erase') });
452     $self->add_button ($tbl, $plcinfo, "_Select", sub { $self->set_edit_tool ('select') });
453     $self->add_button ($tbl, $plcinfo, "Eva_l", sub { $self->set_edit_tool ('perl') });
454 elmex 1.63 $self->add_button ($tbl, $plcinfo, "Connec_t", sub { $self->set_edit_tool ('connect') });
455 elmex 1.42 $self->add_button ($tbl, $plcinfo, "_Follow Exit", sub { $self->set_edit_tool ('followexit') });
456 elmex 1.33
457     return $tbl;
458     }
459    
460     sub set_edit_tool {
461     my ($self, $name) = @_;
462    
463     if ($name eq 'pick') {
464 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{pick}, "Pick");;
465 elmex 1.33 } elsif ($name eq 'place') {
466 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{place}, "Place");;
467 elmex 1.33 } elsif ($name eq 'erase') {
468 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{erase}, "Erase");;
469 elmex 1.34 } elsif ($name eq 'select') {
470     $self->update_edit_tool ($self->{edit_collection}{select}, "Select");;
471 elmex 1.57 $self->{edit_collection}{select}->update_overlay;
472 elmex 1.35 } elsif ($name eq 'perl') {
473     $self->update_edit_tool ($self->{edit_collection}{perl}, "Eval");;
474 elmex 1.63 } elsif ($name eq 'connect') {
475     $self->update_edit_tool ($self->{edit_collection}{connect}, "Connect");;
476 elmex 1.38 } elsif ($name eq 'followexit') {
477     $self->update_edit_tool ($self->{edit_collection}{followexit}, "Follow Exit");;
478 elmex 1.33 }
479 elmex 1.17 }
480 elmex 1.10
481 elmex 1.28 sub update_edit_tool {
482     my ($self, $tool, $name) = @_;
483    
484 elmex 1.57 for (values %{$self->{loaded_maps}}) {
485     $_->{map}->overlay ('selection')
486     }
487    
488 elmex 1.28 $self->{edit_tool}->set_text ($name);
489     $self->{sel_editaction} = $tool;
490    
491     my $widget = $tool->tool_widget;
492    
493     for ($self->{edit_tool_cont}->get_children) {
494     $_->hide;
495     $self->{edit_tool_cont}->remove ($_);
496     }
497    
498 elmex 1.53 $_->set_edit_tool ($self->{sel_editaction}) for (values %{$self->{editors}});
499    
500 elmex 1.28 defined $widget or return;
501    
502     $self->{edit_tool_cont}->add ($widget);
503     $widget->show_all;
504     }
505    
506     sub update_pick_view {
507     my ($self, $arch) = @_;
508    
509     defined $arch->{_face}
510     or $arch = $Crossfire::ARCH{$arch->{_name}};
511    
512     fill_pb_from_arch ($self->{pick_view_pb}, $arch);
513     $self->{pick_view_img}->set_from_pixbuf ($self->{pick_view_pb});
514    
515 elmex 1.33 $self->{pick_view_btn}->set_label ($arch->{_name});
516 elmex 1.28 }
517    
518 elmex 1.13 sub INIT_INSTANCE {
519     my ($self) = @_;
520 elmex 1.10
521 elmex 1.80 {
522     open my $fh, "<$recentfile";
523     binmode $fh;
524     local $/;
525     our @recent_entries = split /\0/, <$fh>;
526     close $fh;
527     }
528    
529 root 1.24 $::MAINWIN = $self;
530 elmex 1.15
531 elmex 1.66 $self->set_title ("gcrossedit - toolbox");
532 elmex 1.10
533 elmex 1.28 $self->{edit_tool} = Gtk2::Label->new;
534     $self->{edit_tool_cont} = Gtk2::VBox->new;
535    
536 elmex 1.80 $self->add (my $vb = $self->{vb} = Gtk2::VBox->new);
537 elmex 1.13 $vb->pack_start ($self->build_menu, 0, 1, 0);
538 elmex 1.28 $vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0);
539    
540     $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
541     $vb->pack_start ($self->{edit_tool}, 0, 1, 0);
542    
543     $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
544 elmex 1.35 $vb->pack_start ($self->{edit_tool_cont}, 1, 1, 0);
545 elmex 1.10
546 elmex 1.13 # XXX:load $ARGV _cleanly_?
547 root 1.27 $self->open_map_editor ($_)
548     for @ARGV;
549 root 1.11
550 elmex 1.13 $self->signal_connect ('delete-event' => sub {
551     Gtk2->main_quit;
552 elmex 1.10 });
553 elmex 1.17
554 elmex 1.30 ::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0);
555 elmex 1.58
556    
557     $self->show_attr_editor;
558 elmex 1.2 }
559    
560     sub new_cb {
561     my ($self) = @_;
562 elmex 1.32
563     my $w = Gtk2::Window->new ('toplevel');
564     my $width = [width => 20];
565     my $height = [height => 20];
566     $w->add (my $tbl = Gtk2::Table->new (2, 3));
567     add_table_widget ($tbl, 0, $width, 'string');
568     add_table_widget ($tbl, 1, $height, 'string');
569     add_table_widget ($tbl, 2, 'new', 'button', sub {
570     if ($width->[1] > 0 and $height->[1] > 0) {
571     my $map = Crossfire::Map->new ($width->[1], $height->[1]);
572 elmex 1.69 $map->{info}->{width} = $width->[1];
573     $map->{info}->{height} = $height->[1];
574 elmex 1.33 $map->resize ($width->[1], $height->[1]);
575 elmex 1.32 $self->open_map_editor ($map);
576     }
577     $w->destroy;
578     1;
579     });
580     add_table_widget ($tbl, 3, 'close', 'button', sub { $w->destroy });
581     $w->show_all;
582 elmex 1.2 }
583    
584 root 1.25 sub new_filechooser {
585 elmex 1.37 my ($self, $title, $save, $filename) = @_;
586 elmex 1.2
587 elmex 1.66 $title ||= 'gcrossedit - open map';
588 root 1.25 my $fc = new Gtk2::FileChooserDialog (
589 elmex 1.33 $title, undef, $save ? 'save' : 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok'
590 elmex 1.13 );
591    
592 elmex 1.78 my @shortcut_folders =
593     grep { $_ && ($_ ne '') && -e $_ } keys %{$self->{fc_last_folders}};
594 elmex 1.76
595 elmex 1.78 $fc->add_shortcut_folder ($_) for @shortcut_folders;
596    
597     unless (grep { $::MAPDIR eq $_ } @shortcut_folders) {
598     $fc->add_shortcut_folder ($::MAPDIR)
599     if -d $::MAPDIR;
600     }
601 elmex 1.76
602 elmex 1.55 $fc->set_current_folder (getcwd);
603 elmex 1.2
604 elmex 1.37 if ($filename) {
605     $fc->set_filename ($filename);
606     }
607    
608 root 1.25 $fc
609     }
610    
611 elmex 1.71 sub new_coord_query {
612 elmex 1.75 my ($self, $finishcb) = @_;
613 elmex 1.71
614 elmex 1.75 my $coordhash = { x => 105, y => 115, worldmap => 1, overlay => 0 };
615 elmex 1.71 my $diag = GCE::HashDialogue->new;
616 elmex 1.75 $self->{"worldmap_coord_query"} = $diag;
617 elmex 1.73 $diag->signal_connect (destroy => sub {
618 elmex 1.75 delete $self->{"worldmap_coord_query"};
619 elmex 1.73 });
620 elmex 1.71 $diag->init (
621 elmex 1.75 layout_name => 'worldmap_coord_query',
622     info => "Open worldmap at ...",
623 elmex 1.71 dialog_default_size => [ 200, 200, 200, 0 ],
624     title => 'Worldmap coordinate entry',
625     ref_hash => $coordhash,
626     dialog => [
627 elmex 1.77 [x => 'X Coordinate' => 'spin', sub { (0, 999, 1) }],
628     [y => 'Y Coordinate' => 'spin', sub { (0, 999, 1) }],
629 elmex 1.75 [worldmap => 'Open worldmap' => 'check'],
630     [overlay => 'Open overlay (CF+)' => 'check'],
631 elmex 1.71 ],
632     save_button_label => 'open',
633     save_cb => sub {
634 elmex 1.75 $finishcb->($_[0]);
635 elmex 1.71 }
636     );
637     $diag->show_all;
638     }
639    
640     sub open_worldmap_cb {
641 elmex 1.75 my ($self) = @_;
642 elmex 1.71
643 elmex 1.75 $self->new_coord_query (sub {
644     my ($info) = @_;
645     my ($x, $y) = ($info->{x}, $info->{y});
646     my ($worldmap, $overlay) = ($info->{worldmap}, $info->{overlay});
647 elmex 1.76 $self->open_map_editor ($::MAPDIR . "/world/world_$x\_$y")
648 elmex 1.75 if $worldmap;
649 elmex 1.76 $self->open_map_editor ($::MAPDIR . "/world-overlay/world_$x\_$y")
650 elmex 1.75 if $overlay;
651 elmex 1.71 });
652     }
653    
654 root 1.25 sub open_cb {
655     my ($self) = @_;
656    
657     my $fc = $self->new_filechooser;
658    
659 elmex 1.2 if ('ok' eq $fc->run) {
660 elmex 1.13
661 elmex 1.10 $self->{fc_last_folder} = $fc->get_current_folder;
662 elmex 1.13 $self->{fc_last_folders}->{$self->{fc_last_folder}}++;
663 elmex 1.17
664     $self->open_map_editor ($fc->get_filename);
665 elmex 1.2 }
666    
667     $fc->destroy;
668     }
669    
670 elmex 1.17 sub get_pick {
671     my ($self) = @_;
672    
673 elmex 1.58 $self->{attr_edit}
674     or die "Couldn't find attribute editor! SERIOUS BUG!";
675    
676 elmex 1.17 # XXX: This is just to make sure that this function always returns something
677 elmex 1.61
678     my $ar = $self->{attr_edit}->get_arch;
679     return { _name => 'platinacoin' } unless defined $ar;
680     return $ar->getarch || { _name => 'platinacoin' };
681 elmex 1.17 }
682    
683 elmex 1.1 =head1 AUTHOR
684    
685     Marc Lehmann <schmorp@schmorp.de>
686     http://home.schmorp.de/
687    
688     Robin Redeker <elmex@ta-sa.org>
689     http://www.ta-sa.org/
690    
691     =cut
692     1;
693