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.73 |
$self->{worldmap_coord_query_}->save_layout () |
49 |
|
|
if $self->{worldmap_coord_query_}; |
50 |
|
|
$self->{worldmap_coord_query_overlay}->save_layout () |
51 |
|
|
if $self->{worldmap_coord_query_overlay}; |
52 |
|
|
|
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 |
|
|
# File::Spec->abs2rel ($mapfile, File::Spec->catfile ($::CFG->{MAPDIR})); |
100 |
|
|
} 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.46 |
$w->add (my $t = Gtk2::Table->new (2, 4)); |
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 |
|
|
$t->attach_defaults (my $save = Gtk2::Button->new ('save'), 0, 2, 2, 3); |
189 |
|
|
$save->signal_connect (clicked => sub { |
190 |
elmex |
1.68 |
$::LIBDIR = $::CFG->{LIBDIR} = $lib->get_text; |
191 |
|
|
$::MAPDIR = $::CFG->{MAPDIR} = $map->get_text; |
192 |
elmex |
1.46 |
Crossfire::set_libdir ($::CFG->{LIBDIR}); |
193 |
|
|
Crossfire::load_archetypes; |
194 |
|
|
Crossfire::load_tilecache; |
195 |
|
|
main::write_cfg ("$Crossfire::VARDIR/gceconfig"); |
196 |
|
|
$w->destroy; |
197 |
|
|
}); |
198 |
|
|
$t->attach_defaults (my $close = Gtk2::Button->new ('close'), 0, 2, 3, 4); |
199 |
|
|
$close->signal_connect (clicked => sub { $w->destroy }); |
200 |
|
|
|
201 |
elmex |
1.56 |
$w->signal_connect (destroy => sub { delete $self->{prop_edit}; 0 }); |
202 |
elmex |
1.46 |
|
203 |
|
|
main::set_pos_and_size ($w, $main::CFG->{prop_edit}, 200, 200); |
204 |
|
|
|
205 |
|
|
$w->show_all; |
206 |
|
|
} |
207 |
|
|
|
208 |
elmex |
1.15 |
sub show_attr_editor { |
209 |
|
|
my ($self) = @_; |
210 |
|
|
|
211 |
|
|
my $w = $self->{attr_edit_win} = Gtk2::Window->new; |
212 |
elmex |
1.66 |
$w->set_title ("gcrossedit - edit attrs"); |
213 |
elmex |
1.15 |
$w->add ($self->{attr_edit} = GCE::AttrEdit->new); |
214 |
elmex |
1.17 |
|
215 |
elmex |
1.64 |
main::set_pos_and_size ($w, $main::CFG->{attr_view}, 400, 300, 250, 0); |
216 |
elmex |
1.17 |
|
217 |
elmex |
1.15 |
$w->show_all; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
sub update_attr_editor { |
221 |
elmex |
1.61 |
my ($self, $ar) = @_; |
222 |
|
|
|
223 |
|
|
if (ref ($ar) ne 'GCE::ArchRef') { require Carp; Carp::confess ("$ar no ARCHREF!") } |
224 |
elmex |
1.15 |
|
225 |
elmex |
1.58 |
$self->{attr_edit} |
226 |
|
|
or die "SERIOUS BUG: Couldn't find attribut editor!"; |
227 |
elmex |
1.15 |
|
228 |
elmex |
1.61 |
$self->{attr_edit}->set_arch ($ar, 1); |
229 |
elmex |
1.66 |
$self->{attr_edit_win}->set_title ("gcrossedit - edit " . $ar->longname); |
230 |
elmex |
1.15 |
} |
231 |
|
|
|
232 |
|
|
sub update_stack_view { |
233 |
elmex |
1.17 |
my ($self, $mapedit, $x, $y) = @_; |
234 |
elmex |
1.15 |
|
235 |
|
|
return unless $self->{sv}; |
236 |
|
|
|
237 |
elmex |
1.17 |
$self->{sv}->set_stack ($mapedit, $x, $y); |
238 |
elmex |
1.62 |
|
239 |
elmex |
1.15 |
} |
240 |
|
|
|
241 |
elmex |
1.17 |
sub open_pick_window { |
242 |
|
|
my ($self, $layout) = @_; |
243 |
|
|
|
244 |
root |
1.29 |
# XXX: Yes, also fix this, save _every_ pick window and their positions and their |
245 |
elmex |
1.17 |
# selection |
246 |
|
|
my $p = GCE::PickWindow->new (); |
247 |
elmex |
1.15 |
|
248 |
elmex |
1.17 |
push @{$self->{open_pick_windows}}, $p; |
249 |
|
|
|
250 |
|
|
my $idx = (@{$self->{open_pick_windows}}) - 1; |
251 |
elmex |
1.15 |
|
252 |
elmex |
1.17 |
$p->signal_connect ('delete-event' => sub { |
253 |
|
|
$self->{open_pick_windows}->[$idx] = undef; |
254 |
|
|
}); |
255 |
elmex |
1.10 |
|
256 |
elmex |
1.17 |
if ($layout) { |
257 |
elmex |
1.30 |
main::set_pos_and_size ($p, $layout->{p_and_s}, 200, 200); |
258 |
elmex |
1.17 |
} |
259 |
elmex |
1.10 |
|
260 |
elmex |
1.17 |
$p->show_all; |
261 |
elmex |
1.10 |
|
262 |
elmex |
1.17 |
$p->set_selection ($layout->{selection}); |
263 |
elmex |
1.10 |
} |
264 |
|
|
|
265 |
elmex |
1.13 |
sub build_menu { |
266 |
elmex |
1.1 |
my ($self) = @_; |
267 |
|
|
|
268 |
elmex |
1.2 |
my $menu_tree = [ |
269 |
|
|
_File => { |
270 |
|
|
item_type => '<Branch>', |
271 |
|
|
children => [ |
272 |
|
|
_New => { |
273 |
|
|
callback => sub { $self->new_cb }, |
274 |
|
|
accelerator => '<ctrl>N' |
275 |
|
|
}, |
276 |
|
|
_Open => { |
277 |
|
|
callback => sub { $self->open_cb }, |
278 |
|
|
accelerator => '<ctrl>O' |
279 |
|
|
}, |
280 |
elmex |
1.71 |
'Open special' => { |
281 |
|
|
item_type => '<Branch>', |
282 |
|
|
children => [ |
283 |
|
|
"world map at"=> { |
284 |
|
|
callback => sub { $self->open_worldmap_cb }, |
285 |
|
|
}, |
286 |
|
|
"world overlay map at (CF+);"=> { |
287 |
|
|
callback => sub { $self->open_worldmap_cb ('overlay') }, |
288 |
|
|
}, |
289 |
|
|
] |
290 |
|
|
}, |
291 |
elmex |
1.17 |
"_Save Layout" => { |
292 |
|
|
callback => sub { $self->save_layout }, |
293 |
|
|
accelerator => '<ctrl>L' |
294 |
|
|
}, |
295 |
elmex |
1.52 |
"_Preferences" => { |
296 |
elmex |
1.46 |
callback => sub { $self->show_editor_properties }, |
297 |
|
|
accelerator => "<ctrl>T" |
298 |
|
|
}, |
299 |
elmex |
1.49 |
_Quit => { |
300 |
elmex |
1.2 |
callback => sub { Gtk2->main_quit }, |
301 |
|
|
accelerator => '<ctrl>Q' |
302 |
elmex |
1.47 |
}, |
303 |
elmex |
1.2 |
] |
304 |
|
|
}, |
305 |
root |
1.24 |
_Dialogs => { |
306 |
elmex |
1.2 |
item_type => '<Branch>', |
307 |
|
|
children => [ |
308 |
elmex |
1.17 |
"_Picker" => { |
309 |
|
|
callback => sub { $self->open_pick_window }, |
310 |
|
|
accelerator => "<ctrl>P" |
311 |
|
|
}, |
312 |
|
|
"_Stack View" => { |
313 |
|
|
callback => sub { $self->show_stack_view }, |
314 |
|
|
accelerator => "<ctrl>V" |
315 |
|
|
}, |
316 |
elmex |
1.2 |
] |
317 |
elmex |
1.47 |
}, |
318 |
elmex |
1.49 |
_Help => { |
319 |
|
|
item_type => '<Branch>', |
320 |
|
|
children => [ |
321 |
elmex |
1.50 |
_Manual => { |
322 |
elmex |
1.49 |
callback => sub { $self->show_help_window }, |
323 |
|
|
accelerator => "<ctrl>H" |
324 |
|
|
}, |
325 |
|
|
] |
326 |
|
|
}, |
327 |
elmex |
1.2 |
]; |
328 |
|
|
|
329 |
elmex |
1.13 |
my $men = |
330 |
|
|
Gtk2::SimpleMenu->new ( |
331 |
|
|
menu_tree => $menu_tree, |
332 |
|
|
default_callback => \&default_cb, |
333 |
|
|
); |
334 |
elmex |
1.10 |
|
335 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
336 |
|
|
|
337 |
elmex |
1.13 |
return $men->{widget}; |
338 |
|
|
} |
339 |
elmex |
1.10 |
|
340 |
elmex |
1.17 |
sub add_button { |
341 |
|
|
my ($self, $table, $plcinfo, $lbl, $cb) = @_; |
342 |
|
|
|
343 |
|
|
my ($lx, $ly) = @{$plcinfo->{next}}; |
344 |
|
|
|
345 |
|
|
unless ($lx < $plcinfo->{width}) { |
346 |
|
|
|
347 |
|
|
$ly++; |
348 |
|
|
$lx = 0; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
$ly < $plcinfo->{height} |
352 |
|
|
or die "too many buttons, make table bigger!"; |
353 |
|
|
|
354 |
elmex |
1.42 |
$table->attach_defaults (my $btn = Gtk2::Button->new_with_mnemonic ($lbl), $lx, $lx + 1, $ly, $ly + 1); |
355 |
elmex |
1.17 |
$btn->signal_connect (clicked => $cb); |
356 |
|
|
|
357 |
|
|
$plcinfo->{next} = [$lx + 1, $ly]; |
358 |
|
|
} |
359 |
|
|
|
360 |
|
|
sub build_buttons { |
361 |
|
|
my ($self) = @_; |
362 |
|
|
|
363 |
elmex |
1.38 |
my $tbl = Gtk2::Table->new (2, 4); |
364 |
|
|
my $plcinfo = { width => 2, height => 4, next => [0, 0] }; |
365 |
elmex |
1.17 |
|
366 |
elmex |
1.38 |
$self->{edit_collection}{pick} = GCE::EditAction::Pick->new; |
367 |
|
|
$self->{edit_collection}{place} = GCE::EditAction::Place->new; |
368 |
|
|
$self->{edit_collection}{erase} = GCE::EditAction::Erase->new; |
369 |
|
|
$self->{edit_collection}{select} = GCE::EditAction::Select->new; |
370 |
|
|
$self->{edit_collection}{perl} = GCE::EditAction::Perl->new; |
371 |
elmex |
1.63 |
$self->{edit_collection}{connect} = GCE::EditAction::Connect->new; |
372 |
elmex |
1.38 |
$self->{edit_collection}{followexit} = GCE::EditAction::FollowExit->new; |
373 |
elmex |
1.17 |
|
374 |
elmex |
1.33 |
$self->set_edit_tool ('pick'); |
375 |
elmex |
1.28 |
|
376 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "P_ick", sub { $self->set_edit_tool ('pick') }); |
377 |
|
|
$self->add_button ($tbl, $plcinfo, "_Place", sub { $self->set_edit_tool ('place') }); |
378 |
|
|
$self->add_button ($tbl, $plcinfo, "_Erase", sub { $self->set_edit_tool ('erase') }); |
379 |
|
|
$self->add_button ($tbl, $plcinfo, "_Select", sub { $self->set_edit_tool ('select') }); |
380 |
|
|
$self->add_button ($tbl, $plcinfo, "Eva_l", sub { $self->set_edit_tool ('perl') }); |
381 |
elmex |
1.63 |
$self->add_button ($tbl, $plcinfo, "Connec_t", sub { $self->set_edit_tool ('connect') }); |
382 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "_Follow Exit", sub { $self->set_edit_tool ('followexit') }); |
383 |
elmex |
1.33 |
|
384 |
|
|
return $tbl; |
385 |
|
|
} |
386 |
|
|
|
387 |
|
|
sub set_edit_tool { |
388 |
|
|
my ($self, $name) = @_; |
389 |
|
|
|
390 |
|
|
if ($name eq 'pick') { |
391 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{pick}, "Pick");; |
392 |
elmex |
1.33 |
} elsif ($name eq 'place') { |
393 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{place}, "Place");; |
394 |
elmex |
1.33 |
} elsif ($name eq 'erase') { |
395 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{erase}, "Erase");; |
396 |
elmex |
1.34 |
} elsif ($name eq 'select') { |
397 |
|
|
$self->update_edit_tool ($self->{edit_collection}{select}, "Select");; |
398 |
elmex |
1.57 |
$self->{edit_collection}{select}->update_overlay; |
399 |
elmex |
1.35 |
} elsif ($name eq 'perl') { |
400 |
|
|
$self->update_edit_tool ($self->{edit_collection}{perl}, "Eval");; |
401 |
elmex |
1.63 |
} elsif ($name eq 'connect') { |
402 |
|
|
$self->update_edit_tool ($self->{edit_collection}{connect}, "Connect");; |
403 |
elmex |
1.38 |
} elsif ($name eq 'followexit') { |
404 |
|
|
$self->update_edit_tool ($self->{edit_collection}{followexit}, "Follow Exit");; |
405 |
elmex |
1.33 |
} |
406 |
elmex |
1.17 |
} |
407 |
elmex |
1.10 |
|
408 |
elmex |
1.28 |
sub update_edit_tool { |
409 |
|
|
my ($self, $tool, $name) = @_; |
410 |
|
|
|
411 |
elmex |
1.57 |
for (values %{$self->{loaded_maps}}) { |
412 |
|
|
$_->{map}->overlay ('selection') |
413 |
|
|
} |
414 |
|
|
|
415 |
elmex |
1.28 |
$self->{edit_tool}->set_text ($name); |
416 |
|
|
$self->{sel_editaction} = $tool; |
417 |
|
|
|
418 |
|
|
my $widget = $tool->tool_widget; |
419 |
|
|
|
420 |
|
|
for ($self->{edit_tool_cont}->get_children) { |
421 |
|
|
$_->hide; |
422 |
|
|
$self->{edit_tool_cont}->remove ($_); |
423 |
|
|
} |
424 |
|
|
|
425 |
elmex |
1.53 |
$_->set_edit_tool ($self->{sel_editaction}) for (values %{$self->{editors}}); |
426 |
|
|
|
427 |
elmex |
1.28 |
defined $widget or return; |
428 |
|
|
|
429 |
|
|
$self->{edit_tool_cont}->add ($widget); |
430 |
|
|
$widget->show_all; |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
sub update_pick_view { |
434 |
|
|
my ($self, $arch) = @_; |
435 |
|
|
|
436 |
|
|
defined $arch->{_face} |
437 |
|
|
or $arch = $Crossfire::ARCH{$arch->{_name}}; |
438 |
|
|
|
439 |
|
|
fill_pb_from_arch ($self->{pick_view_pb}, $arch); |
440 |
|
|
$self->{pick_view_img}->set_from_pixbuf ($self->{pick_view_pb}); |
441 |
|
|
|
442 |
elmex |
1.33 |
$self->{pick_view_btn}->set_label ($arch->{_name}); |
443 |
elmex |
1.28 |
} |
444 |
|
|
|
445 |
elmex |
1.13 |
sub INIT_INSTANCE { |
446 |
|
|
my ($self) = @_; |
447 |
elmex |
1.10 |
|
448 |
root |
1.24 |
$::MAINWIN = $self; |
449 |
elmex |
1.15 |
|
450 |
elmex |
1.66 |
$self->set_title ("gcrossedit - toolbox"); |
451 |
elmex |
1.10 |
|
452 |
elmex |
1.28 |
$self->{edit_tool} = Gtk2::Label->new; |
453 |
|
|
$self->{edit_tool_cont} = Gtk2::VBox->new; |
454 |
|
|
|
455 |
elmex |
1.13 |
$self->add (my $vb = Gtk2::VBox->new); |
456 |
|
|
$vb->pack_start ($self->build_menu, 0, 1, 0); |
457 |
elmex |
1.28 |
$vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0); |
458 |
|
|
|
459 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
460 |
|
|
$vb->pack_start ($self->{edit_tool}, 0, 1, 0); |
461 |
|
|
|
462 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
463 |
elmex |
1.35 |
$vb->pack_start ($self->{edit_tool_cont}, 1, 1, 0); |
464 |
elmex |
1.10 |
|
465 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
466 |
root |
1.27 |
$self->open_map_editor ($_) |
467 |
|
|
for @ARGV; |
468 |
root |
1.11 |
|
469 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
470 |
|
|
Gtk2->main_quit; |
471 |
elmex |
1.10 |
}); |
472 |
elmex |
1.17 |
|
473 |
elmex |
1.30 |
::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0); |
474 |
elmex |
1.58 |
|
475 |
|
|
|
476 |
|
|
$self->show_attr_editor; |
477 |
elmex |
1.2 |
} |
478 |
|
|
|
479 |
|
|
sub new_cb { |
480 |
|
|
my ($self) = @_; |
481 |
elmex |
1.32 |
|
482 |
|
|
my $w = Gtk2::Window->new ('toplevel'); |
483 |
|
|
my $width = [width => 20]; |
484 |
|
|
my $height = [height => 20]; |
485 |
|
|
$w->add (my $tbl = Gtk2::Table->new (2, 3)); |
486 |
|
|
add_table_widget ($tbl, 0, $width, 'string'); |
487 |
|
|
add_table_widget ($tbl, 1, $height, 'string'); |
488 |
|
|
add_table_widget ($tbl, 2, 'new', 'button', sub { |
489 |
|
|
if ($width->[1] > 0 and $height->[1] > 0) { |
490 |
|
|
my $map = Crossfire::Map->new ($width->[1], $height->[1]); |
491 |
elmex |
1.69 |
$map->{info}->{width} = $width->[1]; |
492 |
|
|
$map->{info}->{height} = $height->[1]; |
493 |
elmex |
1.33 |
$map->resize ($width->[1], $height->[1]); |
494 |
elmex |
1.32 |
$self->open_map_editor ($map); |
495 |
|
|
} |
496 |
|
|
$w->destroy; |
497 |
|
|
1; |
498 |
|
|
}); |
499 |
|
|
add_table_widget ($tbl, 3, 'close', 'button', sub { $w->destroy }); |
500 |
|
|
$w->show_all; |
501 |
elmex |
1.2 |
} |
502 |
|
|
|
503 |
root |
1.25 |
sub new_filechooser { |
504 |
elmex |
1.37 |
my ($self, $title, $save, $filename) = @_; |
505 |
elmex |
1.2 |
|
506 |
elmex |
1.66 |
$title ||= 'gcrossedit - open map'; |
507 |
root |
1.25 |
my $fc = new Gtk2::FileChooserDialog ( |
508 |
elmex |
1.33 |
$title, undef, $save ? 'save' : 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
509 |
elmex |
1.13 |
); |
510 |
|
|
|
511 |
elmex |
1.46 |
$fc->add_shortcut_folder ($::CFG->{MAPDIR}) if -d $::CFG->{MAPDIR}; |
512 |
elmex |
1.45 |
$fc->add_shortcut_folder ($_) for grep { $_ && ($_ ne '') } keys %{$self->{fc_last_folders}}; |
513 |
elmex |
1.55 |
$fc->set_current_folder (getcwd); |
514 |
elmex |
1.2 |
|
515 |
elmex |
1.37 |
if ($filename) { |
516 |
|
|
$fc->set_filename ($filename); |
517 |
|
|
} |
518 |
|
|
|
519 |
root |
1.25 |
$fc |
520 |
|
|
} |
521 |
|
|
|
522 |
elmex |
1.71 |
sub new_coord_query { |
523 |
|
|
my ($self, $mode, $finishcb) = @_; |
524 |
|
|
|
525 |
|
|
my $coordhash = { x => 105, y => 115 }; |
526 |
|
|
my $diag = GCE::HashDialogue->new; |
527 |
elmex |
1.73 |
$self->{"worldmap_coord_query_$mode"} = $diag; |
528 |
|
|
$diag->signal_connect (destroy => sub { |
529 |
|
|
delete $self->{"worldmap_coord_query_$mode"}; |
530 |
|
|
}); |
531 |
elmex |
1.71 |
$diag->init ( |
532 |
|
|
layout_name => 'worldmap_coord_query_'.$mode, |
533 |
|
|
info => "Open $mode worldmap at ...", |
534 |
|
|
dialog_default_size => [ 200, 200, 200, 0 ], |
535 |
|
|
title => 'Worldmap coordinate entry', |
536 |
|
|
ref_hash => $coordhash, |
537 |
|
|
dialog => [ |
538 |
|
|
[x => 'X Coordinate' => 'string'], |
539 |
|
|
[y => 'Y Coordinate' => 'string'], |
540 |
|
|
], |
541 |
|
|
save_button_label => 'open', |
542 |
|
|
save_cb => sub { |
543 |
|
|
$finishcb->($mode, $_[0]->{x}, $_[0]->{y}); |
544 |
|
|
} |
545 |
|
|
); |
546 |
|
|
$diag->show_all; |
547 |
|
|
} |
548 |
|
|
|
549 |
|
|
sub open_worldmap_cb { |
550 |
|
|
my ($self, $mode) = @_; |
551 |
|
|
|
552 |
|
|
$self->new_coord_query ($mode, sub { |
553 |
|
|
my ($mode, $x, $y) = @_; |
554 |
|
|
my $map = $::CFG->{MAPDIR} |
555 |
|
|
. "/world" . ($mode eq 'overlay' ? '-overlay' : '') |
556 |
|
|
. "/world_$x\_$y"; |
557 |
|
|
$self->open_map_editor ($map); |
558 |
|
|
}); |
559 |
|
|
} |
560 |
|
|
|
561 |
root |
1.25 |
sub open_cb { |
562 |
|
|
my ($self) = @_; |
563 |
|
|
|
564 |
|
|
my $fc = $self->new_filechooser; |
565 |
|
|
|
566 |
elmex |
1.2 |
if ('ok' eq $fc->run) { |
567 |
elmex |
1.13 |
|
568 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
569 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
570 |
elmex |
1.17 |
|
571 |
|
|
$self->open_map_editor ($fc->get_filename); |
572 |
elmex |
1.2 |
} |
573 |
|
|
|
574 |
|
|
$fc->destroy; |
575 |
|
|
} |
576 |
|
|
|
577 |
elmex |
1.17 |
sub get_pick { |
578 |
|
|
my ($self) = @_; |
579 |
|
|
|
580 |
elmex |
1.58 |
$self->{attr_edit} |
581 |
|
|
or die "Couldn't find attribute editor! SERIOUS BUG!"; |
582 |
|
|
|
583 |
elmex |
1.17 |
# XXX: This is just to make sure that this function always returns something |
584 |
elmex |
1.61 |
|
585 |
|
|
my $ar = $self->{attr_edit}->get_arch; |
586 |
|
|
return { _name => 'platinacoin' } unless defined $ar; |
587 |
|
|
return $ar->getarch || { _name => 'platinacoin' }; |
588 |
elmex |
1.17 |
} |
589 |
|
|
|
590 |
elmex |
1.1 |
=head1 AUTHOR |
591 |
|
|
|
592 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
593 |
|
|
http://home.schmorp.de/ |
594 |
|
|
|
595 |
|
|
Robin Redeker <elmex@ta-sa.org> |
596 |
|
|
http://www.ta-sa.org/ |
597 |
|
|
|
598 |
|
|
=cut |
599 |
|
|
1; |
600 |
|
|
|