ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MainWindow.pm
Revision: 1.79
Committed: Sat Aug 18 10:04:11 2007 UTC (16 years, 10 months ago) by elmex
Branch: MAIN
Changes since 1.78: +7 -0 lines
Log Message:
applied irwiss' patch to bring back the attribute editor once it was closed, thanks!

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