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 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
elmex |
1.2 |
use Gtk2::SimpleMenu; |
12 |
root |
1.7 |
|
13 |
|
|
use Crossfire; |
14 |
|
|
use Crossfire::MapWidget; |
15 |
|
|
|
16 |
elmex |
1.2 |
use GCE::AttrEdit; |
17 |
elmex |
1.13 |
use GCE::MapEditor; |
18 |
elmex |
1.2 |
|
19 |
|
|
use Glib::Object::Subclass |
20 |
elmex |
1.13 |
Gtk2::Window; |
21 |
elmex |
1.2 |
|
22 |
|
|
use strict; |
23 |
|
|
|
24 |
elmex |
1.13 |
sub open_pick_window { |
25 |
|
|
my ($self) = @_; |
26 |
elmex |
1.10 |
|
27 |
elmex |
1.13 |
my $p = GCE::PickWindow->new ( |
28 |
|
|
set_sel_cb => sub { |
29 |
elmex |
1.10 |
|
30 |
elmex |
1.13 |
$self->{mapedit}->update_pick ($_[0]) |
31 |
|
|
}, |
32 |
|
|
arch_edit_cb => sub { |
33 |
elmex |
1.10 |
|
34 |
elmex |
1.13 |
$self->{mapedit}->update_attr_editor ($_[0]) |
35 |
|
|
} |
36 |
|
|
); |
37 |
|
|
$p->init; |
38 |
elmex |
1.10 |
} |
39 |
|
|
|
40 |
elmex |
1.8 |
|
41 |
elmex |
1.13 |
sub build_menu { |
42 |
elmex |
1.1 |
my ($self) = @_; |
43 |
|
|
|
44 |
elmex |
1.2 |
my $menu_tree = [ |
45 |
|
|
_File => { |
46 |
|
|
item_type => '<Branch>', |
47 |
|
|
children => [ |
48 |
|
|
_New => { |
49 |
|
|
callback => sub { $self->new_cb }, |
50 |
|
|
accelerator => '<ctrl>N' |
51 |
|
|
}, |
52 |
|
|
_Open => { |
53 |
|
|
callback => sub { $self->open_cb }, |
54 |
|
|
accelerator => '<ctrl>O' |
55 |
|
|
}, |
56 |
|
|
_Quit => { |
57 |
|
|
callback => sub { Gtk2->main_quit }, |
58 |
|
|
accelerator => '<ctrl>Q' |
59 |
|
|
} |
60 |
|
|
] |
61 |
|
|
}, |
62 |
|
|
_Edit => { |
63 |
|
|
item_type => '<Branch>', |
64 |
|
|
children => [ |
65 |
elmex |
1.13 |
_Fill => { |
66 |
|
|
callback => sub { die "NO IMPL" }, |
67 |
|
|
accelerator => "<ctrl>F" |
68 |
|
|
}, |
69 |
|
|
"Clear _Top" => { |
70 |
|
|
callback => sub { die "NO IMPL" }, |
71 |
|
|
accelerator => "<ctrl>T" |
72 |
elmex |
1.2 |
}, |
73 |
|
|
"_Clear All" => { |
74 |
elmex |
1.13 |
callback => sub { die "NO IMPL" }, |
75 |
|
|
accelerator => "<ctrl>X" |
76 |
elmex |
1.2 |
}, |
77 |
elmex |
1.9 |
"Open _Picker" => { |
78 |
elmex |
1.13 |
callback => sub { $self->open_pick_window }, |
79 |
|
|
accelerator => "<ctrl>P" |
80 |
elmex |
1.9 |
}, |
81 |
elmex |
1.2 |
] |
82 |
elmex |
1.9 |
} |
83 |
elmex |
1.2 |
]; |
84 |
|
|
|
85 |
elmex |
1.13 |
my $men = |
86 |
|
|
Gtk2::SimpleMenu->new ( |
87 |
|
|
menu_tree => $menu_tree, |
88 |
|
|
default_callback => \&default_cb, |
89 |
|
|
); |
90 |
elmex |
1.10 |
|
91 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
92 |
|
|
|
93 |
elmex |
1.13 |
return $men->{widget}; |
94 |
|
|
} |
95 |
elmex |
1.10 |
|
96 |
|
|
|
97 |
root |
1.11 |
|
98 |
elmex |
1.13 |
sub INIT_INSTANCE { |
99 |
|
|
my ($self) = @_; |
100 |
elmex |
1.10 |
|
101 |
elmex |
1.13 |
$self->set_title ("gce - main window"); |
102 |
elmex |
1.10 |
|
103 |
elmex |
1.13 |
$self->add (my $vb = Gtk2::VBox->new); |
104 |
|
|
$vb->pack_start ($self->build_menu, 0, 1, 0); |
105 |
|
|
$vb->pack_start (my $mapedit = $self->{mapedit} = new GCE::MapEditor, 1, 1, 0); |
106 |
elmex |
1.10 |
|
107 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
108 |
|
|
$mapedit->open_map ($ARGV[0] || "$Crossfire::LIB/maps/dragonisland/advguild3"); |
109 |
root |
1.11 |
|
110 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
111 |
|
|
Gtk2->main_quit; |
112 |
elmex |
1.10 |
}); |
113 |
elmex |
1.2 |
} |
114 |
|
|
|
115 |
|
|
sub new_cb { |
116 |
|
|
my ($self) = @_; |
117 |
|
|
die "NOT IMPLEMENTED YET"; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
sub open_cb { |
121 |
|
|
my ($self) = @_; |
122 |
|
|
|
123 |
elmex |
1.13 |
my $fc = |
124 |
|
|
Gtk2::FileChooserDialog->new ( |
125 |
|
|
'gce - open map', undef, 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
126 |
|
|
); |
127 |
|
|
|
128 |
elmex |
1.2 |
$fc->add_shortcut_folder ("$Crossfire::LIB/maps"); |
129 |
elmex |
1.13 |
$fc->add_shortcut_folder ($_) for keys %{$self->{fc_last_folders}}; |
130 |
elmex |
1.10 |
$fc->set_current_folder ($self->{fc_last_folder} || "$Crossfire::LIB/maps"); |
131 |
elmex |
1.2 |
|
132 |
|
|
if ('ok' eq $fc->run) { |
133 |
elmex |
1.13 |
|
134 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
135 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
136 |
|
|
$self->{mapedit}->open_map ($fc->get_filename); |
137 |
elmex |
1.2 |
} |
138 |
|
|
|
139 |
|
|
$fc->destroy; |
140 |
|
|
} |
141 |
|
|
|
142 |
elmex |
1.1 |
=head1 AUTHOR |
143 |
|
|
|
144 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
145 |
|
|
http://home.schmorp.de/ |
146 |
|
|
|
147 |
|
|
Robin Redeker <elmex@ta-sa.org> |
148 |
|
|
http://www.ta-sa.org/ |
149 |
|
|
|
150 |
|
|
=cut |
151 |
|
|
1; |
152 |
|
|
|