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