ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MainWindow.pm
Revision: 1.81
Committed: Tue Sep 11 10:24:23 2007 UTC (16 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.80: +8 -3 lines
Log Message:
the stack view is now better updated on undo, but the whole event handling
has to be rewritten anyways...

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.81 my ($self, $ar, $map, $x, $y) = @_;
231 elmex 1.61
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 elmex 1.81 or return;
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 elmex 1.81 sub update_map_pos {
242     my ($self, $mapedit, $x, $y) = @_;
243     $self->{sv}->maybe_update_stack_for ($mapedit, $x, $y)
244     if $self->{sv};
245     }
246    
247 elmex 1.15 sub update_stack_view {
248 elmex 1.17 my ($self, $mapedit, $x, $y) = @_;
249 elmex 1.15
250     return unless $self->{sv};
251    
252 elmex 1.17 $self->{sv}->set_stack ($mapedit, $x, $y);
253 elmex 1.15 }
254    
255 elmex 1.17 sub open_pick_window {
256     my ($self, $layout) = @_;
257    
258 root 1.29 # XXX: Yes, also fix this, save _every_ pick window and their positions and their
259 elmex 1.17 # selection
260     my $p = GCE::PickWindow->new ();
261 elmex 1.15
262 elmex 1.17 push @{$self->{open_pick_windows}}, $p;
263    
264     my $idx = (@{$self->{open_pick_windows}}) - 1;
265 elmex 1.15
266 elmex 1.17 $p->signal_connect ('delete-event' => sub {
267     $self->{open_pick_windows}->[$idx] = undef;
268     });
269 elmex 1.10
270 elmex 1.17 if ($layout) {
271 elmex 1.30 main::set_pos_and_size ($p, $layout->{p_and_s}, 200, 200);
272 elmex 1.17 }
273 elmex 1.10
274 elmex 1.17 $p->show_all;
275 elmex 1.10
276 elmex 1.17 $p->set_selection ($layout->{selection});
277 elmex 1.10 }
278    
279 elmex 1.80 sub add_recent {
280     my ($self, $entry) = @_;
281     our @recent_entries;
282    
283     @recent_entries = grep { $_ ne $entry } @recent_entries;
284     unshift @recent_entries, $entry;
285     splice @recent_entries, 5;
286    
287     open my $fh, ">$recentfile" or die "Can't write to file $recentfile: $!";
288     binmode $fh;
289     local $/;
290     print $fh (join "\0", @recent_entries);
291     close $fh;
292    
293     $self->build_menu;
294     }
295    
296     sub escape_filename {
297     my $str = shift;
298    
299     $str = Glib::filename_to_unicode($str);
300    
301     # escape to prevent Gtk2::SimpleMenu parsing these especially
302     $str =~ s/\//\\\//g;
303     $str =~ s/_/__/g;
304    
305     $str;
306     }
307    
308     sub recent {
309     my ($self) = @_;
310     my @recent;
311    
312     our @recent_entries;
313    
314     foreach my $entry(@recent_entries) {
315     push @recent, escape_filename($entry) => {
316     callback => sub { $self->open_map_editor($entry);
317     $self->build_menu }
318     };
319     }
320    
321     push @recent, Empty => { callback => sub {} }
322     unless @recent;
323    
324     @recent;
325     }
326    
327 elmex 1.13 sub build_menu {
328 elmex 1.1 my ($self) = @_;
329    
330 elmex 1.2 my $menu_tree = [
331     _File => {
332     item_type => '<Branch>',
333     children => [
334     _New => {
335     callback => sub { $self->new_cb },
336     accelerator => '<ctrl>N'
337     },
338     _Open => {
339     callback => sub { $self->open_cb },
340     accelerator => '<ctrl>O'
341     },
342 elmex 1.71 'Open special' => {
343     item_type => '<Branch>',
344     children => [
345     "world map at"=> {
346     callback => sub { $self->open_worldmap_cb },
347     },
348 elmex 1.80 "recent files"=> {
349     item_type => '<Branch>',
350     children => [ $self->recent ],
351     },
352 elmex 1.71 ]
353     },
354 elmex 1.17 "_Save Layout" => {
355     callback => sub { $self->save_layout },
356     accelerator => '<ctrl>L'
357     },
358 elmex 1.52 "_Preferences" => {
359 elmex 1.46 callback => sub { $self->show_editor_properties },
360     accelerator => "<ctrl>T"
361     },
362 elmex 1.49 _Quit => {
363 elmex 1.2 callback => sub { Gtk2->main_quit },
364     accelerator => '<ctrl>Q'
365 elmex 1.47 },
366 elmex 1.2 ]
367     },
368 root 1.24 _Dialogs => {
369 elmex 1.2 item_type => '<Branch>',
370     children => [
371 elmex 1.17 "_Picker" => {
372     callback => sub { $self->open_pick_window },
373     accelerator => "<ctrl>P"
374     },
375     "_Stack View" => {
376     callback => sub { $self->show_stack_view },
377     accelerator => "<ctrl>V"
378     },
379 elmex 1.79 "_Attributes" => {
380     callback => sub { $self->show_attr_editor },
381     accelerator => "<ctrl>A"
382     },
383 elmex 1.2 ]
384 elmex 1.47 },
385 elmex 1.49 _Help => {
386     item_type => '<Branch>',
387     children => [
388 elmex 1.50 _Manual => {
389 elmex 1.49 callback => sub { $self->show_help_window },
390     accelerator => "<ctrl>H"
391     },
392     ]
393     },
394 elmex 1.2 ];
395    
396 elmex 1.13 my $men =
397     Gtk2::SimpleMenu->new (
398     menu_tree => $menu_tree,
399     default_callback => \&default_cb,
400     );
401 elmex 1.10
402 elmex 1.80 for ($self->{vb}->get_children) { # Rebuild menu
403     if ($_->isa ('Gtk2::MenuBar')) {
404     $_->hide;
405     $self->{vb}->remove($_);
406    
407     $self->{vb}->pack_start ($men->{widget}, 0, 1, 0);
408     $self->{vb}->reorder_child ($men->{widget}, 0);
409     $self->{vb}->show_all;
410     }
411     }
412    
413 elmex 1.2 $self->add_accel_group ($men->{accel_group});
414    
415 elmex 1.13 return $men->{widget};
416     }
417 elmex 1.10
418 elmex 1.17 sub add_button {
419     my ($self, $table, $plcinfo, $lbl, $cb) = @_;
420    
421     my ($lx, $ly) = @{$plcinfo->{next}};
422    
423     unless ($lx < $plcinfo->{width}) {
424    
425     $ly++;
426     $lx = 0;
427     }
428    
429     $ly < $plcinfo->{height}
430     or die "too many buttons, make table bigger!";
431    
432 elmex 1.42 $table->attach_defaults (my $btn = Gtk2::Button->new_with_mnemonic ($lbl), $lx, $lx + 1, $ly, $ly + 1);
433 elmex 1.17 $btn->signal_connect (clicked => $cb);
434    
435     $plcinfo->{next} = [$lx + 1, $ly];
436     }
437    
438     sub build_buttons {
439     my ($self) = @_;
440    
441 elmex 1.38 my $tbl = Gtk2::Table->new (2, 4);
442     my $plcinfo = { width => 2, height => 4, next => [0, 0] };
443 elmex 1.17
444 elmex 1.38 $self->{edit_collection}{pick} = GCE::EditAction::Pick->new;
445     $self->{edit_collection}{place} = GCE::EditAction::Place->new;
446     $self->{edit_collection}{erase} = GCE::EditAction::Erase->new;
447     $self->{edit_collection}{select} = GCE::EditAction::Select->new;
448     $self->{edit_collection}{perl} = GCE::EditAction::Perl->new;
449 elmex 1.63 $self->{edit_collection}{connect} = GCE::EditAction::Connect->new;
450 elmex 1.38 $self->{edit_collection}{followexit} = GCE::EditAction::FollowExit->new;
451 elmex 1.17
452 elmex 1.33 $self->set_edit_tool ('pick');
453 elmex 1.28
454 elmex 1.42 $self->add_button ($tbl, $plcinfo, "P_ick", sub { $self->set_edit_tool ('pick') });
455     $self->add_button ($tbl, $plcinfo, "_Place", sub { $self->set_edit_tool ('place') });
456     $self->add_button ($tbl, $plcinfo, "_Erase", sub { $self->set_edit_tool ('erase') });
457     $self->add_button ($tbl, $plcinfo, "_Select", sub { $self->set_edit_tool ('select') });
458     $self->add_button ($tbl, $plcinfo, "Eva_l", sub { $self->set_edit_tool ('perl') });
459 elmex 1.63 $self->add_button ($tbl, $plcinfo, "Connec_t", sub { $self->set_edit_tool ('connect') });
460 elmex 1.42 $self->add_button ($tbl, $plcinfo, "_Follow Exit", sub { $self->set_edit_tool ('followexit') });
461 elmex 1.33
462     return $tbl;
463     }
464    
465     sub set_edit_tool {
466     my ($self, $name) = @_;
467    
468     if ($name eq 'pick') {
469 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{pick}, "Pick");;
470 elmex 1.33 } elsif ($name eq 'place') {
471 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{place}, "Place");;
472 elmex 1.33 } elsif ($name eq 'erase') {
473 elmex 1.28 $self->update_edit_tool ($self->{edit_collection}{erase}, "Erase");;
474 elmex 1.34 } elsif ($name eq 'select') {
475     $self->update_edit_tool ($self->{edit_collection}{select}, "Select");;
476 elmex 1.57 $self->{edit_collection}{select}->update_overlay;
477 elmex 1.35 } elsif ($name eq 'perl') {
478     $self->update_edit_tool ($self->{edit_collection}{perl}, "Eval");;
479 elmex 1.63 } elsif ($name eq 'connect') {
480     $self->update_edit_tool ($self->{edit_collection}{connect}, "Connect");;
481 elmex 1.38 } elsif ($name eq 'followexit') {
482     $self->update_edit_tool ($self->{edit_collection}{followexit}, "Follow Exit");;
483 elmex 1.33 }
484 elmex 1.17 }
485 elmex 1.10
486 elmex 1.28 sub update_edit_tool {
487     my ($self, $tool, $name) = @_;
488    
489 elmex 1.57 for (values %{$self->{loaded_maps}}) {
490     $_->{map}->overlay ('selection')
491     }
492    
493 elmex 1.28 $self->{edit_tool}->set_text ($name);
494     $self->{sel_editaction} = $tool;
495    
496     my $widget = $tool->tool_widget;
497    
498     for ($self->{edit_tool_cont}->get_children) {
499     $_->hide;
500     $self->{edit_tool_cont}->remove ($_);
501     }
502    
503 elmex 1.53 $_->set_edit_tool ($self->{sel_editaction}) for (values %{$self->{editors}});
504    
505 elmex 1.28 defined $widget or return;
506    
507     $self->{edit_tool_cont}->add ($widget);
508     $widget->show_all;
509     }
510    
511     sub update_pick_view {
512     my ($self, $arch) = @_;
513    
514     defined $arch->{_face}
515     or $arch = $Crossfire::ARCH{$arch->{_name}};
516    
517     fill_pb_from_arch ($self->{pick_view_pb}, $arch);
518     $self->{pick_view_img}->set_from_pixbuf ($self->{pick_view_pb});
519    
520 elmex 1.33 $self->{pick_view_btn}->set_label ($arch->{_name});
521 elmex 1.28 }
522    
523 elmex 1.13 sub INIT_INSTANCE {
524     my ($self) = @_;
525 elmex 1.10
526 elmex 1.80 {
527     open my $fh, "<$recentfile";
528     binmode $fh;
529     local $/;
530     our @recent_entries = split /\0/, <$fh>;
531     close $fh;
532     }
533    
534 root 1.24 $::MAINWIN = $self;
535 elmex 1.15
536 elmex 1.66 $self->set_title ("gcrossedit - toolbox");
537 elmex 1.10
538 elmex 1.28 $self->{edit_tool} = Gtk2::Label->new;
539     $self->{edit_tool_cont} = Gtk2::VBox->new;
540    
541 elmex 1.80 $self->add (my $vb = $self->{vb} = Gtk2::VBox->new);
542 elmex 1.13 $vb->pack_start ($self->build_menu, 0, 1, 0);
543 elmex 1.28 $vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0);
544    
545     $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
546     $vb->pack_start ($self->{edit_tool}, 0, 1, 0);
547    
548     $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
549 elmex 1.35 $vb->pack_start ($self->{edit_tool_cont}, 1, 1, 0);
550 elmex 1.10
551 elmex 1.13 # XXX:load $ARGV _cleanly_?
552 root 1.27 $self->open_map_editor ($_)
553     for @ARGV;
554 root 1.11
555 elmex 1.13 $self->signal_connect ('delete-event' => sub {
556     Gtk2->main_quit;
557 elmex 1.10 });
558 elmex 1.17
559 elmex 1.30 ::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0);
560 elmex 1.58
561    
562     $self->show_attr_editor;
563 elmex 1.2 }
564    
565     sub new_cb {
566     my ($self) = @_;
567 elmex 1.32
568     my $w = Gtk2::Window->new ('toplevel');
569     my $width = [width => 20];
570     my $height = [height => 20];
571     $w->add (my $tbl = Gtk2::Table->new (2, 3));
572     add_table_widget ($tbl, 0, $width, 'string');
573     add_table_widget ($tbl, 1, $height, 'string');
574     add_table_widget ($tbl, 2, 'new', 'button', sub {
575     if ($width->[1] > 0 and $height->[1] > 0) {
576     my $map = Crossfire::Map->new ($width->[1], $height->[1]);
577 elmex 1.69 $map->{info}->{width} = $width->[1];
578     $map->{info}->{height} = $height->[1];
579 elmex 1.33 $map->resize ($width->[1], $height->[1]);
580 elmex 1.32 $self->open_map_editor ($map);
581     }
582     $w->destroy;
583     1;
584     });
585     add_table_widget ($tbl, 3, 'close', 'button', sub { $w->destroy });
586     $w->show_all;
587 elmex 1.2 }
588    
589 root 1.25 sub new_filechooser {
590 elmex 1.37 my ($self, $title, $save, $filename) = @_;
591 elmex 1.2
592 elmex 1.66 $title ||= 'gcrossedit - open map';
593 root 1.25 my $fc = new Gtk2::FileChooserDialog (
594 elmex 1.33 $title, undef, $save ? 'save' : 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok'
595 elmex 1.13 );
596    
597 elmex 1.78 my @shortcut_folders =
598     grep { $_ && ($_ ne '') && -e $_ } keys %{$self->{fc_last_folders}};
599 elmex 1.76
600 elmex 1.78 $fc->add_shortcut_folder ($_) for @shortcut_folders;
601    
602     unless (grep { $::MAPDIR eq $_ } @shortcut_folders) {
603     $fc->add_shortcut_folder ($::MAPDIR)
604     if -d $::MAPDIR;
605     }
606 elmex 1.76
607 elmex 1.55 $fc->set_current_folder (getcwd);
608 elmex 1.2
609 elmex 1.37 if ($filename) {
610     $fc->set_filename ($filename);
611     }
612    
613 root 1.25 $fc
614     }
615    
616 elmex 1.71 sub new_coord_query {
617 elmex 1.75 my ($self, $finishcb) = @_;
618 elmex 1.71
619 elmex 1.75 my $coordhash = { x => 105, y => 115, worldmap => 1, overlay => 0 };
620 elmex 1.71 my $diag = GCE::HashDialogue->new;
621 elmex 1.75 $self->{"worldmap_coord_query"} = $diag;
622 elmex 1.73 $diag->signal_connect (destroy => sub {
623 elmex 1.75 delete $self->{"worldmap_coord_query"};
624 elmex 1.73 });
625 elmex 1.71 $diag->init (
626 elmex 1.75 layout_name => 'worldmap_coord_query',
627     info => "Open worldmap at ...",
628 elmex 1.71 dialog_default_size => [ 200, 200, 200, 0 ],
629     title => 'Worldmap coordinate entry',
630     ref_hash => $coordhash,
631     dialog => [
632 elmex 1.77 [x => 'X Coordinate' => 'spin', sub { (0, 999, 1) }],
633     [y => 'Y Coordinate' => 'spin', sub { (0, 999, 1) }],
634 elmex 1.75 [worldmap => 'Open worldmap' => 'check'],
635     [overlay => 'Open overlay (CF+)' => 'check'],
636 elmex 1.71 ],
637     save_button_label => 'open',
638     save_cb => sub {
639 elmex 1.75 $finishcb->($_[0]);
640 elmex 1.71 }
641     );
642     $diag->show_all;
643     }
644    
645     sub open_worldmap_cb {
646 elmex 1.75 my ($self) = @_;
647 elmex 1.71
648 elmex 1.75 $self->new_coord_query (sub {
649     my ($info) = @_;
650     my ($x, $y) = ($info->{x}, $info->{y});
651     my ($worldmap, $overlay) = ($info->{worldmap}, $info->{overlay});
652 elmex 1.76 $self->open_map_editor ($::MAPDIR . "/world/world_$x\_$y")
653 elmex 1.75 if $worldmap;
654 elmex 1.76 $self->open_map_editor ($::MAPDIR . "/world-overlay/world_$x\_$y")
655 elmex 1.75 if $overlay;
656 elmex 1.71 });
657     }
658    
659 root 1.25 sub open_cb {
660     my ($self) = @_;
661    
662     my $fc = $self->new_filechooser;
663    
664 elmex 1.2 if ('ok' eq $fc->run) {
665 elmex 1.13
666 elmex 1.10 $self->{fc_last_folder} = $fc->get_current_folder;
667 elmex 1.13 $self->{fc_last_folders}->{$self->{fc_last_folder}}++;
668 elmex 1.17
669     $self->open_map_editor ($fc->get_filename);
670 elmex 1.2 }
671    
672     $fc->destroy;
673     }
674    
675 elmex 1.17 sub get_pick {
676     my ($self) = @_;
677    
678 elmex 1.58 $self->{attr_edit}
679     or die "Couldn't find attribute editor! SERIOUS BUG!";
680    
681 elmex 1.17 # XXX: This is just to make sure that this function always returns something
682 elmex 1.61
683     my $ar = $self->{attr_edit}->get_arch;
684     return { _name => 'platinacoin' } unless defined $ar;
685     return $ar->getarch || { _name => 'platinacoin' };
686 elmex 1.17 }
687    
688 elmex 1.1 =head1 AUTHOR
689    
690     Marc Lehmann <schmorp@schmorp.de>
691     http://home.schmorp.de/
692    
693     Robin Redeker <elmex@ta-sa.org>
694     http://www.ta-sa.org/
695    
696     =cut
697     1;
698