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.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.71 |
'Open special' => { |
268 |
|
|
item_type => '<Branch>', |
269 |
|
|
children => [ |
270 |
|
|
"world map at"=> { |
271 |
|
|
callback => sub { $self->open_worldmap_cb }, |
272 |
|
|
}, |
273 |
|
|
"world overlay map at (CF+);"=> { |
274 |
|
|
callback => sub { $self->open_worldmap_cb ('overlay') }, |
275 |
|
|
}, |
276 |
|
|
] |
277 |
|
|
}, |
278 |
elmex |
1.17 |
"_Save Layout" => { |
279 |
|
|
callback => sub { $self->save_layout }, |
280 |
|
|
accelerator => '<ctrl>L' |
281 |
|
|
}, |
282 |
elmex |
1.52 |
"_Preferences" => { |
283 |
elmex |
1.46 |
callback => sub { $self->show_editor_properties }, |
284 |
|
|
accelerator => "<ctrl>T" |
285 |
|
|
}, |
286 |
elmex |
1.49 |
_Quit => { |
287 |
elmex |
1.2 |
callback => sub { Gtk2->main_quit }, |
288 |
|
|
accelerator => '<ctrl>Q' |
289 |
elmex |
1.47 |
}, |
290 |
elmex |
1.2 |
] |
291 |
|
|
}, |
292 |
root |
1.24 |
_Dialogs => { |
293 |
elmex |
1.2 |
item_type => '<Branch>', |
294 |
|
|
children => [ |
295 |
elmex |
1.17 |
"_Picker" => { |
296 |
|
|
callback => sub { $self->open_pick_window }, |
297 |
|
|
accelerator => "<ctrl>P" |
298 |
|
|
}, |
299 |
|
|
"_Stack View" => { |
300 |
|
|
callback => sub { $self->show_stack_view }, |
301 |
|
|
accelerator => "<ctrl>V" |
302 |
|
|
}, |
303 |
elmex |
1.2 |
] |
304 |
elmex |
1.47 |
}, |
305 |
elmex |
1.49 |
_Help => { |
306 |
|
|
item_type => '<Branch>', |
307 |
|
|
children => [ |
308 |
elmex |
1.50 |
_Manual => { |
309 |
elmex |
1.49 |
callback => sub { $self->show_help_window }, |
310 |
|
|
accelerator => "<ctrl>H" |
311 |
|
|
}, |
312 |
|
|
] |
313 |
|
|
}, |
314 |
elmex |
1.2 |
]; |
315 |
|
|
|
316 |
elmex |
1.13 |
my $men = |
317 |
|
|
Gtk2::SimpleMenu->new ( |
318 |
|
|
menu_tree => $menu_tree, |
319 |
|
|
default_callback => \&default_cb, |
320 |
|
|
); |
321 |
elmex |
1.10 |
|
322 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
323 |
|
|
|
324 |
elmex |
1.13 |
return $men->{widget}; |
325 |
|
|
} |
326 |
elmex |
1.10 |
|
327 |
elmex |
1.17 |
sub add_button { |
328 |
|
|
my ($self, $table, $plcinfo, $lbl, $cb) = @_; |
329 |
|
|
|
330 |
|
|
my ($lx, $ly) = @{$plcinfo->{next}}; |
331 |
|
|
|
332 |
|
|
unless ($lx < $plcinfo->{width}) { |
333 |
|
|
|
334 |
|
|
$ly++; |
335 |
|
|
$lx = 0; |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
$ly < $plcinfo->{height} |
339 |
|
|
or die "too many buttons, make table bigger!"; |
340 |
|
|
|
341 |
elmex |
1.42 |
$table->attach_defaults (my $btn = Gtk2::Button->new_with_mnemonic ($lbl), $lx, $lx + 1, $ly, $ly + 1); |
342 |
elmex |
1.17 |
$btn->signal_connect (clicked => $cb); |
343 |
|
|
|
344 |
|
|
$plcinfo->{next} = [$lx + 1, $ly]; |
345 |
|
|
} |
346 |
|
|
|
347 |
|
|
sub build_buttons { |
348 |
|
|
my ($self) = @_; |
349 |
|
|
|
350 |
elmex |
1.38 |
my $tbl = Gtk2::Table->new (2, 4); |
351 |
|
|
my $plcinfo = { width => 2, height => 4, next => [0, 0] }; |
352 |
elmex |
1.17 |
|
353 |
elmex |
1.38 |
$self->{edit_collection}{pick} = GCE::EditAction::Pick->new; |
354 |
|
|
$self->{edit_collection}{place} = GCE::EditAction::Place->new; |
355 |
|
|
$self->{edit_collection}{erase} = GCE::EditAction::Erase->new; |
356 |
|
|
$self->{edit_collection}{select} = GCE::EditAction::Select->new; |
357 |
|
|
$self->{edit_collection}{perl} = GCE::EditAction::Perl->new; |
358 |
elmex |
1.63 |
$self->{edit_collection}{connect} = GCE::EditAction::Connect->new; |
359 |
elmex |
1.38 |
$self->{edit_collection}{followexit} = GCE::EditAction::FollowExit->new; |
360 |
elmex |
1.17 |
|
361 |
elmex |
1.33 |
$self->set_edit_tool ('pick'); |
362 |
elmex |
1.28 |
|
363 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "P_ick", sub { $self->set_edit_tool ('pick') }); |
364 |
|
|
$self->add_button ($tbl, $plcinfo, "_Place", sub { $self->set_edit_tool ('place') }); |
365 |
|
|
$self->add_button ($tbl, $plcinfo, "_Erase", sub { $self->set_edit_tool ('erase') }); |
366 |
|
|
$self->add_button ($tbl, $plcinfo, "_Select", sub { $self->set_edit_tool ('select') }); |
367 |
|
|
$self->add_button ($tbl, $plcinfo, "Eva_l", sub { $self->set_edit_tool ('perl') }); |
368 |
elmex |
1.63 |
$self->add_button ($tbl, $plcinfo, "Connec_t", sub { $self->set_edit_tool ('connect') }); |
369 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "_Follow Exit", sub { $self->set_edit_tool ('followexit') }); |
370 |
elmex |
1.33 |
|
371 |
|
|
return $tbl; |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
sub set_edit_tool { |
375 |
|
|
my ($self, $name) = @_; |
376 |
|
|
|
377 |
|
|
if ($name eq 'pick') { |
378 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{pick}, "Pick");; |
379 |
elmex |
1.33 |
} elsif ($name eq 'place') { |
380 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{place}, "Place");; |
381 |
elmex |
1.33 |
} elsif ($name eq 'erase') { |
382 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{erase}, "Erase");; |
383 |
elmex |
1.34 |
} elsif ($name eq 'select') { |
384 |
|
|
$self->update_edit_tool ($self->{edit_collection}{select}, "Select");; |
385 |
elmex |
1.57 |
$self->{edit_collection}{select}->update_overlay; |
386 |
elmex |
1.35 |
} elsif ($name eq 'perl') { |
387 |
|
|
$self->update_edit_tool ($self->{edit_collection}{perl}, "Eval");; |
388 |
elmex |
1.63 |
} elsif ($name eq 'connect') { |
389 |
|
|
$self->update_edit_tool ($self->{edit_collection}{connect}, "Connect");; |
390 |
elmex |
1.38 |
} elsif ($name eq 'followexit') { |
391 |
|
|
$self->update_edit_tool ($self->{edit_collection}{followexit}, "Follow Exit");; |
392 |
elmex |
1.33 |
} |
393 |
elmex |
1.17 |
} |
394 |
elmex |
1.10 |
|
395 |
elmex |
1.28 |
sub update_edit_tool { |
396 |
|
|
my ($self, $tool, $name) = @_; |
397 |
|
|
|
398 |
elmex |
1.57 |
for (values %{$self->{loaded_maps}}) { |
399 |
|
|
$_->{map}->overlay ('selection') |
400 |
|
|
} |
401 |
|
|
|
402 |
elmex |
1.28 |
$self->{edit_tool}->set_text ($name); |
403 |
|
|
$self->{sel_editaction} = $tool; |
404 |
|
|
|
405 |
|
|
my $widget = $tool->tool_widget; |
406 |
|
|
|
407 |
|
|
for ($self->{edit_tool_cont}->get_children) { |
408 |
|
|
$_->hide; |
409 |
|
|
$self->{edit_tool_cont}->remove ($_); |
410 |
|
|
} |
411 |
|
|
|
412 |
elmex |
1.53 |
$_->set_edit_tool ($self->{sel_editaction}) for (values %{$self->{editors}}); |
413 |
|
|
|
414 |
elmex |
1.28 |
defined $widget or return; |
415 |
|
|
|
416 |
|
|
$self->{edit_tool_cont}->add ($widget); |
417 |
|
|
$widget->show_all; |
418 |
|
|
} |
419 |
|
|
|
420 |
|
|
sub update_pick_view { |
421 |
|
|
my ($self, $arch) = @_; |
422 |
|
|
|
423 |
|
|
defined $arch->{_face} |
424 |
|
|
or $arch = $Crossfire::ARCH{$arch->{_name}}; |
425 |
|
|
|
426 |
|
|
fill_pb_from_arch ($self->{pick_view_pb}, $arch); |
427 |
|
|
$self->{pick_view_img}->set_from_pixbuf ($self->{pick_view_pb}); |
428 |
|
|
|
429 |
elmex |
1.33 |
$self->{pick_view_btn}->set_label ($arch->{_name}); |
430 |
elmex |
1.28 |
} |
431 |
|
|
|
432 |
elmex |
1.13 |
sub INIT_INSTANCE { |
433 |
|
|
my ($self) = @_; |
434 |
elmex |
1.10 |
|
435 |
root |
1.24 |
$::MAINWIN = $self; |
436 |
elmex |
1.15 |
|
437 |
elmex |
1.66 |
$self->set_title ("gcrossedit - toolbox"); |
438 |
elmex |
1.10 |
|
439 |
elmex |
1.28 |
$self->{edit_tool} = Gtk2::Label->new; |
440 |
|
|
$self->{edit_tool_cont} = Gtk2::VBox->new; |
441 |
|
|
|
442 |
elmex |
1.13 |
$self->add (my $vb = Gtk2::VBox->new); |
443 |
|
|
$vb->pack_start ($self->build_menu, 0, 1, 0); |
444 |
elmex |
1.28 |
$vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0); |
445 |
|
|
|
446 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
447 |
|
|
$vb->pack_start ($self->{edit_tool}, 0, 1, 0); |
448 |
|
|
|
449 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
450 |
elmex |
1.35 |
$vb->pack_start ($self->{edit_tool_cont}, 1, 1, 0); |
451 |
elmex |
1.10 |
|
452 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
453 |
root |
1.27 |
$self->open_map_editor ($_) |
454 |
|
|
for @ARGV; |
455 |
root |
1.11 |
|
456 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
457 |
|
|
Gtk2->main_quit; |
458 |
elmex |
1.10 |
}); |
459 |
elmex |
1.17 |
|
460 |
elmex |
1.30 |
::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0); |
461 |
elmex |
1.58 |
|
462 |
|
|
|
463 |
|
|
$self->show_attr_editor; |
464 |
elmex |
1.2 |
} |
465 |
|
|
|
466 |
|
|
sub new_cb { |
467 |
|
|
my ($self) = @_; |
468 |
elmex |
1.32 |
|
469 |
|
|
my $w = Gtk2::Window->new ('toplevel'); |
470 |
|
|
my $width = [width => 20]; |
471 |
|
|
my $height = [height => 20]; |
472 |
|
|
$w->add (my $tbl = Gtk2::Table->new (2, 3)); |
473 |
|
|
add_table_widget ($tbl, 0, $width, 'string'); |
474 |
|
|
add_table_widget ($tbl, 1, $height, 'string'); |
475 |
|
|
add_table_widget ($tbl, 2, 'new', 'button', sub { |
476 |
|
|
if ($width->[1] > 0 and $height->[1] > 0) { |
477 |
|
|
my $map = Crossfire::Map->new ($width->[1], $height->[1]); |
478 |
elmex |
1.69 |
$map->{info}->{width} = $width->[1]; |
479 |
|
|
$map->{info}->{height} = $height->[1]; |
480 |
elmex |
1.33 |
$map->resize ($width->[1], $height->[1]); |
481 |
elmex |
1.32 |
$self->open_map_editor ($map); |
482 |
|
|
} |
483 |
|
|
$w->destroy; |
484 |
|
|
1; |
485 |
|
|
}); |
486 |
|
|
add_table_widget ($tbl, 3, 'close', 'button', sub { $w->destroy }); |
487 |
|
|
$w->show_all; |
488 |
elmex |
1.2 |
} |
489 |
|
|
|
490 |
root |
1.25 |
sub new_filechooser { |
491 |
elmex |
1.37 |
my ($self, $title, $save, $filename) = @_; |
492 |
elmex |
1.2 |
|
493 |
elmex |
1.66 |
$title ||= 'gcrossedit - open map'; |
494 |
root |
1.25 |
my $fc = new Gtk2::FileChooserDialog ( |
495 |
elmex |
1.33 |
$title, undef, $save ? 'save' : 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
496 |
elmex |
1.13 |
); |
497 |
|
|
|
498 |
elmex |
1.46 |
$fc->add_shortcut_folder ($::CFG->{MAPDIR}) if -d $::CFG->{MAPDIR}; |
499 |
elmex |
1.45 |
$fc->add_shortcut_folder ($_) for grep { $_ && ($_ ne '') } keys %{$self->{fc_last_folders}}; |
500 |
elmex |
1.55 |
$fc->set_current_folder (getcwd); |
501 |
elmex |
1.2 |
|
502 |
elmex |
1.37 |
if ($filename) { |
503 |
|
|
$fc->set_filename ($filename); |
504 |
|
|
} |
505 |
|
|
|
506 |
root |
1.25 |
$fc |
507 |
|
|
} |
508 |
|
|
|
509 |
elmex |
1.71 |
sub new_coord_query { |
510 |
|
|
my ($self, $mode, $finishcb) = @_; |
511 |
|
|
|
512 |
|
|
my $coordhash = { x => 105, y => 115 }; |
513 |
|
|
my $diag = GCE::HashDialogue->new; |
514 |
|
|
$diag->init ( |
515 |
|
|
layout_name => 'worldmap_coord_query_'.$mode, |
516 |
|
|
info => "Open $mode worldmap at ...", |
517 |
|
|
dialog_default_size => [ 200, 200, 200, 0 ], |
518 |
|
|
title => 'Worldmap coordinate entry', |
519 |
|
|
ref_hash => $coordhash, |
520 |
|
|
dialog => [ |
521 |
|
|
[x => 'X Coordinate' => 'string'], |
522 |
|
|
[y => 'Y Coordinate' => 'string'], |
523 |
|
|
], |
524 |
|
|
save_button_label => 'open', |
525 |
|
|
save_cb => sub { |
526 |
|
|
$finishcb->($mode, $_[0]->{x}, $_[0]->{y}); |
527 |
|
|
} |
528 |
|
|
); |
529 |
|
|
$diag->show_all; |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
sub open_worldmap_cb { |
533 |
|
|
my ($self, $mode) = @_; |
534 |
|
|
|
535 |
|
|
$self->new_coord_query ($mode, sub { |
536 |
|
|
my ($mode, $x, $y) = @_; |
537 |
|
|
my $map = $::CFG->{MAPDIR} |
538 |
|
|
. "/world" . ($mode eq 'overlay' ? '-overlay' : '') |
539 |
|
|
. "/world_$x\_$y"; |
540 |
|
|
$self->open_map_editor ($map); |
541 |
|
|
}); |
542 |
|
|
} |
543 |
|
|
|
544 |
root |
1.25 |
sub open_cb { |
545 |
|
|
my ($self) = @_; |
546 |
|
|
|
547 |
|
|
my $fc = $self->new_filechooser; |
548 |
|
|
|
549 |
elmex |
1.2 |
if ('ok' eq $fc->run) { |
550 |
elmex |
1.13 |
|
551 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
552 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
553 |
elmex |
1.17 |
|
554 |
|
|
$self->open_map_editor ($fc->get_filename); |
555 |
elmex |
1.2 |
} |
556 |
|
|
|
557 |
|
|
$fc->destroy; |
558 |
|
|
} |
559 |
|
|
|
560 |
elmex |
1.17 |
sub get_pick { |
561 |
|
|
my ($self) = @_; |
562 |
|
|
|
563 |
elmex |
1.58 |
$self->{attr_edit} |
564 |
|
|
or die "Couldn't find attribute editor! SERIOUS BUG!"; |
565 |
|
|
|
566 |
elmex |
1.17 |
# XXX: This is just to make sure that this function always returns something |
567 |
elmex |
1.61 |
|
568 |
|
|
my $ar = $self->{attr_edit}->get_arch; |
569 |
|
|
return { _name => 'platinacoin' } unless defined $ar; |
570 |
|
|
return $ar->getarch || { _name => 'platinacoin' }; |
571 |
elmex |
1.17 |
} |
572 |
|
|
|
573 |
elmex |
1.1 |
=head1 AUTHOR |
574 |
|
|
|
575 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
576 |
|
|
http://home.schmorp.de/ |
577 |
|
|
|
578 |
|
|
Robin Redeker <elmex@ta-sa.org> |
579 |
|
|
http://www.ta-sa.org/ |
580 |
|
|
|
581 |
|
|
=cut |
582 |
|
|
1; |
583 |
|
|
|