1 |
elmex |
1.1 |
package GCE::MainWindow; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
elmex |
1.85 |
GCE::MainWindow - the main window class for gde |
6 |
elmex |
1.1 |
|
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 |
root |
1.83 |
use Deliantra; |
15 |
|
|
use Deliantra::Map; |
16 |
|
|
use Deliantra::MapWidget; |
17 |
root |
1.7 |
|
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.85.2.1 |
use base qw/Object::Event/; |
31 |
|
|
|
32 |
elmex |
1.2 |
use strict; |
33 |
|
|
|
34 |
elmex |
1.85 |
my $recentfile = "$Deliantra::VARDIR/gderecent"; |
35 |
elmex |
1.80 |
|
36 |
elmex |
1.18 |
# XXX: make a recursive call from save_layout to all (interesting) sub-widgets |
37 |
elmex |
1.17 |
sub save_layout { |
38 |
|
|
my ($self) = @_; |
39 |
|
|
|
40 |
elmex |
1.58 |
# $main::CFG->{attr_edit_on} = exists $self->{attr_edit} ? 1 : 0; |
41 |
elmex |
1.17 |
$main::CFG->{stack_view_on} = exists $self->{sv} ? 1 : 0; |
42 |
|
|
$main::CFG->{picker_on} = exists $self->{last_pick_window} ? 1 : 0; |
43 |
|
|
$main::CFG->{main_window} = main::get_pos_and_size ($self); |
44 |
|
|
$main::CFG->{stack_view} = main::get_pos_and_size ($self->{sv_win}) if $self->{sv_win}; |
45 |
|
|
$main::CFG->{attr_view} = main::get_pos_and_size ($self->{attr_edit_win}) if $self->{attr_edit_win}; |
46 |
|
|
|
47 |
elmex |
1.70 |
if ($self->{last_map_window}) { |
48 |
|
|
$main::CFG->{map_window} = main::get_pos_and_size ($self->{last_map_window}); |
49 |
|
|
$self->{last_map_window}->save_layout (); |
50 |
|
|
} |
51 |
elmex |
1.69 |
|
52 |
elmex |
1.75 |
$self->{worldmap_coord_query}->save_layout () |
53 |
|
|
if $self->{worldmap_coord_query}; |
54 |
elmex |
1.73 |
|
55 |
elmex |
1.37 |
$main::CFG->{last_folders} = $self->{fc_last_folders}; |
56 |
|
|
|
57 |
elmex |
1.17 |
$main::CFG->{open_pickers} = []; |
58 |
|
|
|
59 |
|
|
for (@{$self->{open_pick_windows}}) { |
60 |
|
|
|
61 |
|
|
next unless defined $_; |
62 |
|
|
|
63 |
|
|
push @{$main::CFG->{open_pickers}}, { |
64 |
|
|
p_and_s => main::get_pos_and_size ($_), |
65 |
|
|
selection => $_->{last_selection} |
66 |
|
|
}; |
67 |
|
|
} |
68 |
|
|
|
69 |
elmex |
1.59 |
$self->{attr_edit}->save_layout; |
70 |
|
|
|
71 |
root |
1.83 |
main::write_cfg ("$Deliantra::VARDIR/gdeconfig"); |
72 |
elmex |
1.17 |
} |
73 |
|
|
|
74 |
|
|
sub load_layout { |
75 |
|
|
my ($self) = @_; |
76 |
|
|
|
77 |
elmex |
1.37 |
$self->{fc_last_folders} = $main::CFG->{last_folders}; |
78 |
|
|
|
79 |
elmex |
1.58 |
# $main::CFG->{attr_edit_on} |
80 |
|
|
# and $self->show_attr_editor; |
81 |
elmex |
1.17 |
|
82 |
|
|
$main::CFG->{stack_view_on} |
83 |
|
|
and $self->show_stack_view; |
84 |
|
|
|
85 |
|
|
for (@{$main::CFG->{open_pickers}}) { |
86 |
|
|
$self->open_pick_window ($_); |
87 |
|
|
} |
88 |
elmex |
1.59 |
|
89 |
|
|
$self->{attr_edit}->load_layout; |
90 |
elmex |
1.17 |
} |
91 |
|
|
|
92 |
|
|
sub open_map_editor { |
93 |
|
|
my ($self, $mapfile) = @_; |
94 |
|
|
|
95 |
elmex |
1.44 |
my $mapkey; |
96 |
elmex |
1.39 |
unless (ref $mapfile) { |
97 |
elmex |
1.58 |
# unless (File::Spec->file_name_is_absolute ($mapfile)) { |
98 |
|
|
# $mapfile = File::Spec->rel2abs ($mapfile); |
99 |
|
|
# } |
100 |
|
|
$mapkey = abs_path ($mapfile); |
101 |
elmex |
1.76 |
# File::Spec->abs2rel ($mapfile, File::Spec->catfile ($::MAPDIR)); |
102 |
elmex |
1.58 |
} else { |
103 |
|
|
$mapkey = "$mapfile"; |
104 |
elmex |
1.38 |
} |
105 |
|
|
|
106 |
elmex |
1.17 |
# XXX: last_map_window is a dirty trick to get the position and size |
107 |
|
|
# for save layout |
108 |
|
|
|
109 |
elmex |
1.58 |
if (defined $self->{loaded_maps}->{$mapkey}) { |
110 |
|
|
$self->{loaded_maps}->{$mapkey}->get_toplevel->present; |
111 |
|
|
return; |
112 |
elmex |
1.38 |
} |
113 |
|
|
|
114 |
elmex |
1.17 |
my $w = $self->{last_map_window} = GCE::MapEditor->new; |
115 |
root |
1.25 |
|
116 |
elmex |
1.53 |
$self->{editors}->{$w} = $w; |
117 |
|
|
|
118 |
|
|
$w->signal_connect (destroy => sub { |
119 |
|
|
my ($w) = @_; |
120 |
elmex |
1.67 |
$w->close_windows; |
121 |
elmex |
1.53 |
delete $self->{loaded_maps}->{$w->{mapkey}}; |
122 |
|
|
delete $self->{editors}->{$w}; |
123 |
|
|
0; |
124 |
|
|
}); |
125 |
|
|
|
126 |
elmex |
1.58 |
$self->{loaded_maps}->{$mapkey} = $w; |
127 |
elmex |
1.38 |
|
128 |
elmex |
1.72 |
eval { $w->open_map ($mapfile, $mapkey) }; |
129 |
|
|
if ($@) { |
130 |
|
|
quick_msg ($self, "$@", 1); |
131 |
|
|
$w->close_windows; |
132 |
|
|
delete $self->{loaded_maps}->{$w->{mapkey}}; |
133 |
|
|
delete $self->{editors}->{$w}; |
134 |
|
|
$w->destroy; |
135 |
|
|
return; |
136 |
|
|
} |
137 |
elmex |
1.17 |
|
138 |
elmex |
1.54 |
$w->set_edit_tool ($self->{sel_editaction}); |
139 |
|
|
|
140 |
elmex |
1.17 |
$w->show_all; |
141 |
|
|
} |
142 |
|
|
|
143 |
elmex |
1.47 |
sub show_help_window { |
144 |
|
|
my ($self) = @_; |
145 |
|
|
|
146 |
|
|
return if defined $self->{help_win}; |
147 |
elmex |
1.51 |
require Gtk2::Ex::PodViewer; |
148 |
elmex |
1.47 |
my $w = $self->{help_win} = Gtk2::Window->new; |
149 |
elmex |
1.82 |
$w->set_title ("deliantra editor - help"); |
150 |
elmex |
1.47 |
$w->set_default_size (500, 300); |
151 |
elmex |
1.56 |
$w->signal_connect (destroy => sub { |
152 |
elmex |
1.53 |
$self->{help_win}->hide; $self->{help_win} = undef; |
153 |
|
|
0 |
154 |
|
|
}); |
155 |
elmex |
1.47 |
$w->add (my $sw = Gtk2::ScrolledWindow->new); |
156 |
elmex |
1.51 |
$sw->add (my $h = Gtk2::Ex::PodViewer->new); |
157 |
elmex |
1.47 |
$h->load_string ($::DOCUMENTATION); |
158 |
|
|
$w->show_all; |
159 |
|
|
} |
160 |
|
|
|
161 |
elmex |
1.17 |
sub show_stack_view { |
162 |
elmex |
1.15 |
my ($self) = @_; |
163 |
|
|
|
164 |
|
|
return if defined $self->{sv}; |
165 |
|
|
|
166 |
elmex |
1.17 |
my $w = $self->{sv_win} = Gtk2::Window->new ('toplevel'); |
167 |
elmex |
1.82 |
$w->set_title ('deliantra editor - stack view'); |
168 |
elmex |
1.56 |
$w->signal_connect (destroy => sub { delete $self->{sv}; 0 }); |
169 |
elmex |
1.15 |
$w->add ($self->{sv} = GCE::StackView->new); |
170 |
elmex |
1.17 |
|
171 |
elmex |
1.30 |
main::set_pos_and_size ($w, $main::CFG->{stack_view}, 150, 250); |
172 |
elmex |
1.17 |
|
173 |
elmex |
1.15 |
$w->show_all; |
174 |
|
|
} |
175 |
|
|
|
176 |
elmex |
1.46 |
sub show_editor_properties { |
177 |
|
|
my ($self) = @_; |
178 |
|
|
|
179 |
|
|
return if $self->{prop_edit}; |
180 |
|
|
|
181 |
|
|
my $w = $self->{prop_edit} = Gtk2::Window->new; |
182 |
elmex |
1.82 |
$w->set_title ("deliantra editor - preferences"); |
183 |
elmex |
1.74 |
$w->add (my $t = Gtk2::Table->new (2, 5)); |
184 |
elmex |
1.68 |
$t->attach_defaults (my $lbl1 = Gtk2::Label->new ("LIBDIR"), 0, 1, 0, 1); |
185 |
elmex |
1.46 |
$t->attach_defaults (my $lib = Gtk2::Entry->new, 1, 2, 0, 1); |
186 |
|
|
$lib->set_text ($::CFG->{LIBDIR}); |
187 |
elmex |
1.68 |
$t->attach_defaults (my $lbl2 = Gtk2::Label->new ("MAPDIR"), 0, 1, 1, 2); |
188 |
elmex |
1.46 |
$t->attach_defaults (my $map = Gtk2::Entry->new, 1, 2, 1, 2); |
189 |
|
|
$map->set_text ($::CFG->{MAPDIR}); |
190 |
elmex |
1.74 |
$t->attach_defaults (my $lbl1 = Gtk2::Label->new ("Username"), 0, 1, 2, 3); |
191 |
|
|
$t->attach_defaults (my $usern = Gtk2::Entry->new, 1, 2, 2, 3); |
192 |
|
|
$usern->set_text ($::CFG->{username}); |
193 |
|
|
$t->attach_defaults (my $save = Gtk2::Button->new ('save'), 0, 2, 3, 4); |
194 |
elmex |
1.46 |
$save->signal_connect (clicked => sub { |
195 |
elmex |
1.74 |
$::CFG->{LIBDIR} = $lib->get_text; |
196 |
|
|
$::CFG->{MAPDIR} = $map->get_text; |
197 |
|
|
$::LIBDIR = $::CFG->{LIBDIR} if $::CFG->{LIBDIR}; |
198 |
|
|
$::MAPDIR = $::CFG->{MAPDIR} if $::CFG->{MAPDIR}; |
199 |
|
|
$::CFG->{username} = $usern->get_text; |
200 |
root |
1.83 |
Deliantra::set_libdir ($::LIBDIR); |
201 |
|
|
Deliantra::load_archetypes; |
202 |
|
|
Deliantra::load_tilecache; |
203 |
|
|
main::write_cfg ("$Deliantra::VARDIR/gdeconfig"); |
204 |
elmex |
1.46 |
$w->destroy; |
205 |
|
|
}); |
206 |
elmex |
1.74 |
$t->attach_defaults (my $close = Gtk2::Button->new ('close'), 0, 2, 4, 5); |
207 |
elmex |
1.46 |
$close->signal_connect (clicked => sub { $w->destroy }); |
208 |
|
|
|
209 |
elmex |
1.56 |
$w->signal_connect (destroy => sub { delete $self->{prop_edit}; 0 }); |
210 |
elmex |
1.46 |
|
211 |
|
|
main::set_pos_and_size ($w, $main::CFG->{prop_edit}, 200, 200); |
212 |
|
|
|
213 |
|
|
$w->show_all; |
214 |
|
|
} |
215 |
|
|
|
216 |
elmex |
1.15 |
sub show_attr_editor { |
217 |
|
|
my ($self) = @_; |
218 |
|
|
|
219 |
elmex |
1.79 |
return if $self->{attr_edit_win}; |
220 |
|
|
|
221 |
elmex |
1.15 |
my $w = $self->{attr_edit_win} = Gtk2::Window->new; |
222 |
elmex |
1.82 |
$w->set_title ("deliantra editor - edit attrs"); |
223 |
elmex |
1.15 |
$w->add ($self->{attr_edit} = GCE::AttrEdit->new); |
224 |
elmex |
1.79 |
$w->signal_connect (destroy => sub { delete $self->{attr_edit_win}; 0 }); |
225 |
elmex |
1.17 |
|
226 |
elmex |
1.64 |
main::set_pos_and_size ($w, $main::CFG->{attr_view}, 400, 300, 250, 0); |
227 |
elmex |
1.17 |
|
228 |
elmex |
1.15 |
$w->show_all; |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
sub update_attr_editor { |
232 |
elmex |
1.85.2.2 |
my ($self, $map, $x, $y, $z) = @_; |
233 |
elmex |
1.61 |
|
234 |
elmex |
1.85.2.2 |
# if (ref ($ar) ne 'GCE::ArchRef') { require Carp; Carp::confess ("$ar no ARCHREF!") } |
235 |
elmex |
1.15 |
|
236 |
elmex |
1.58 |
$self->{attr_edit} |
237 |
elmex |
1.81 |
or return; |
238 |
elmex |
1.15 |
|
239 |
elmex |
1.85.2.2 |
my $ar = $self->{attr_edit}->set_from_map ($map, $x, $y, $z); |
240 |
elmex |
1.82 |
$self->{attr_edit_win}->set_title ("deliantra editor - edit " . $ar->longname); |
241 |
elmex |
1.15 |
} |
242 |
|
|
|
243 |
elmex |
1.85.2.2 |
#sub update_map_pos { |
244 |
|
|
# my ($self, $mapedit, $x, $y) = @_; |
245 |
|
|
# $self->{sv}->maybe_update_stack_for ($mapedit, $x, $y) |
246 |
|
|
# if $self->{sv}; |
247 |
|
|
#} |
248 |
elmex |
1.81 |
|
249 |
elmex |
1.15 |
sub update_stack_view { |
250 |
elmex |
1.17 |
my ($self, $mapedit, $x, $y) = @_; |
251 |
elmex |
1.15 |
|
252 |
|
|
return unless $self->{sv}; |
253 |
|
|
|
254 |
elmex |
1.17 |
$self->{sv}->set_stack ($mapedit, $x, $y); |
255 |
elmex |
1.15 |
} |
256 |
|
|
|
257 |
elmex |
1.17 |
sub open_pick_window { |
258 |
|
|
my ($self, $layout) = @_; |
259 |
|
|
|
260 |
root |
1.29 |
# XXX: Yes, also fix this, save _every_ pick window and their positions and their |
261 |
elmex |
1.17 |
# selection |
262 |
|
|
my $p = GCE::PickWindow->new (); |
263 |
elmex |
1.15 |
|
264 |
elmex |
1.17 |
push @{$self->{open_pick_windows}}, $p; |
265 |
|
|
|
266 |
|
|
my $idx = (@{$self->{open_pick_windows}}) - 1; |
267 |
elmex |
1.15 |
|
268 |
elmex |
1.17 |
$p->signal_connect ('delete-event' => sub { |
269 |
|
|
$self->{open_pick_windows}->[$idx] = undef; |
270 |
|
|
}); |
271 |
elmex |
1.10 |
|
272 |
elmex |
1.17 |
if ($layout) { |
273 |
elmex |
1.30 |
main::set_pos_and_size ($p, $layout->{p_and_s}, 200, 200); |
274 |
elmex |
1.17 |
} |
275 |
elmex |
1.10 |
|
276 |
elmex |
1.17 |
$p->show_all; |
277 |
elmex |
1.10 |
|
278 |
elmex |
1.17 |
$p->set_selection ($layout->{selection}); |
279 |
elmex |
1.10 |
} |
280 |
|
|
|
281 |
elmex |
1.80 |
sub add_recent { |
282 |
|
|
my ($self, $entry) = @_; |
283 |
|
|
our @recent_entries; |
284 |
|
|
|
285 |
|
|
@recent_entries = grep { $_ ne $entry } @recent_entries; |
286 |
|
|
unshift @recent_entries, $entry; |
287 |
|
|
splice @recent_entries, 5; |
288 |
|
|
|
289 |
|
|
open my $fh, ">$recentfile" or die "Can't write to file $recentfile: $!"; |
290 |
|
|
binmode $fh; |
291 |
|
|
local $/; |
292 |
|
|
print $fh (join "\0", @recent_entries); |
293 |
|
|
close $fh; |
294 |
|
|
|
295 |
|
|
$self->build_menu; |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
sub escape_filename { |
299 |
|
|
my $str = shift; |
300 |
|
|
|
301 |
|
|
$str = Glib::filename_to_unicode($str); |
302 |
|
|
|
303 |
|
|
# escape to prevent Gtk2::SimpleMenu parsing these especially |
304 |
|
|
$str =~ s/\//\\\//g; |
305 |
elmex |
1.84 |
$str =~ s/_/-/g; |
306 |
elmex |
1.80 |
|
307 |
|
|
$str; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
sub recent { |
311 |
|
|
my ($self) = @_; |
312 |
|
|
my @recent; |
313 |
|
|
|
314 |
|
|
our @recent_entries; |
315 |
|
|
|
316 |
elmex |
1.84 |
foreach my $entry (@recent_entries) { |
317 |
elmex |
1.80 |
push @recent, escape_filename($entry) => { |
318 |
elmex |
1.84 |
callback => sub { |
319 |
|
|
$self->open_map_editor($entry); |
320 |
|
|
$self->build_menu |
321 |
|
|
} |
322 |
elmex |
1.80 |
}; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
push @recent, Empty => { callback => sub {} } |
326 |
|
|
unless @recent; |
327 |
|
|
|
328 |
|
|
@recent; |
329 |
|
|
} |
330 |
|
|
|
331 |
elmex |
1.13 |
sub build_menu { |
332 |
elmex |
1.1 |
my ($self) = @_; |
333 |
|
|
|
334 |
elmex |
1.2 |
my $menu_tree = [ |
335 |
|
|
_File => { |
336 |
|
|
item_type => '<Branch>', |
337 |
|
|
children => [ |
338 |
|
|
_New => { |
339 |
|
|
callback => sub { $self->new_cb }, |
340 |
|
|
accelerator => '<ctrl>N' |
341 |
|
|
}, |
342 |
|
|
_Open => { |
343 |
|
|
callback => sub { $self->open_cb }, |
344 |
|
|
accelerator => '<ctrl>O' |
345 |
|
|
}, |
346 |
elmex |
1.71 |
'Open special' => { |
347 |
|
|
item_type => '<Branch>', |
348 |
|
|
children => [ |
349 |
|
|
"world map at"=> { |
350 |
|
|
callback => sub { $self->open_worldmap_cb }, |
351 |
|
|
}, |
352 |
elmex |
1.80 |
"recent files"=> { |
353 |
|
|
item_type => '<Branch>', |
354 |
|
|
children => [ $self->recent ], |
355 |
|
|
}, |
356 |
elmex |
1.71 |
] |
357 |
|
|
}, |
358 |
elmex |
1.17 |
"_Save Layout" => { |
359 |
|
|
callback => sub { $self->save_layout }, |
360 |
|
|
accelerator => '<ctrl>L' |
361 |
|
|
}, |
362 |
elmex |
1.52 |
"_Preferences" => { |
363 |
elmex |
1.46 |
callback => sub { $self->show_editor_properties }, |
364 |
|
|
accelerator => "<ctrl>T" |
365 |
|
|
}, |
366 |
elmex |
1.49 |
_Quit => { |
367 |
elmex |
1.2 |
callback => sub { Gtk2->main_quit }, |
368 |
|
|
accelerator => '<ctrl>Q' |
369 |
elmex |
1.47 |
}, |
370 |
elmex |
1.2 |
] |
371 |
|
|
}, |
372 |
root |
1.24 |
_Dialogs => { |
373 |
elmex |
1.2 |
item_type => '<Branch>', |
374 |
|
|
children => [ |
375 |
elmex |
1.17 |
"_Picker" => { |
376 |
|
|
callback => sub { $self->open_pick_window }, |
377 |
|
|
accelerator => "<ctrl>P" |
378 |
|
|
}, |
379 |
|
|
"_Stack View" => { |
380 |
|
|
callback => sub { $self->show_stack_view }, |
381 |
|
|
accelerator => "<ctrl>V" |
382 |
|
|
}, |
383 |
elmex |
1.79 |
"_Attributes" => { |
384 |
|
|
callback => sub { $self->show_attr_editor }, |
385 |
|
|
accelerator => "<ctrl>A" |
386 |
|
|
}, |
387 |
elmex |
1.2 |
] |
388 |
elmex |
1.47 |
}, |
389 |
elmex |
1.49 |
_Help => { |
390 |
|
|
item_type => '<Branch>', |
391 |
|
|
children => [ |
392 |
elmex |
1.50 |
_Manual => { |
393 |
elmex |
1.49 |
callback => sub { $self->show_help_window }, |
394 |
|
|
accelerator => "<ctrl>H" |
395 |
|
|
}, |
396 |
|
|
] |
397 |
|
|
}, |
398 |
elmex |
1.2 |
]; |
399 |
|
|
|
400 |
elmex |
1.13 |
my $men = |
401 |
|
|
Gtk2::SimpleMenu->new ( |
402 |
|
|
menu_tree => $menu_tree, |
403 |
|
|
default_callback => \&default_cb, |
404 |
|
|
); |
405 |
elmex |
1.10 |
|
406 |
elmex |
1.80 |
for ($self->{vb}->get_children) { # Rebuild menu |
407 |
|
|
if ($_->isa ('Gtk2::MenuBar')) { |
408 |
|
|
$_->hide; |
409 |
|
|
$self->{vb}->remove($_); |
410 |
|
|
|
411 |
|
|
$self->{vb}->pack_start ($men->{widget}, 0, 1, 0); |
412 |
|
|
$self->{vb}->reorder_child ($men->{widget}, 0); |
413 |
|
|
$self->{vb}->show_all; |
414 |
|
|
} |
415 |
|
|
} |
416 |
|
|
|
417 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
418 |
|
|
|
419 |
elmex |
1.13 |
return $men->{widget}; |
420 |
|
|
} |
421 |
elmex |
1.10 |
|
422 |
elmex |
1.17 |
sub add_button { |
423 |
|
|
my ($self, $table, $plcinfo, $lbl, $cb) = @_; |
424 |
|
|
|
425 |
|
|
my ($lx, $ly) = @{$plcinfo->{next}}; |
426 |
|
|
|
427 |
|
|
unless ($lx < $plcinfo->{width}) { |
428 |
|
|
|
429 |
|
|
$ly++; |
430 |
|
|
$lx = 0; |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
$ly < $plcinfo->{height} |
434 |
|
|
or die "too many buttons, make table bigger!"; |
435 |
|
|
|
436 |
elmex |
1.42 |
$table->attach_defaults (my $btn = Gtk2::Button->new_with_mnemonic ($lbl), $lx, $lx + 1, $ly, $ly + 1); |
437 |
elmex |
1.17 |
$btn->signal_connect (clicked => $cb); |
438 |
|
|
|
439 |
|
|
$plcinfo->{next} = [$lx + 1, $ly]; |
440 |
|
|
} |
441 |
|
|
|
442 |
|
|
sub build_buttons { |
443 |
|
|
my ($self) = @_; |
444 |
|
|
|
445 |
elmex |
1.38 |
my $tbl = Gtk2::Table->new (2, 4); |
446 |
|
|
my $plcinfo = { width => 2, height => 4, next => [0, 0] }; |
447 |
elmex |
1.17 |
|
448 |
elmex |
1.38 |
$self->{edit_collection}{pick} = GCE::EditAction::Pick->new; |
449 |
|
|
$self->{edit_collection}{place} = GCE::EditAction::Place->new; |
450 |
|
|
$self->{edit_collection}{erase} = GCE::EditAction::Erase->new; |
451 |
|
|
$self->{edit_collection}{select} = GCE::EditAction::Select->new; |
452 |
|
|
$self->{edit_collection}{perl} = GCE::EditAction::Perl->new; |
453 |
elmex |
1.63 |
$self->{edit_collection}{connect} = GCE::EditAction::Connect->new; |
454 |
elmex |
1.38 |
$self->{edit_collection}{followexit} = GCE::EditAction::FollowExit->new; |
455 |
elmex |
1.17 |
|
456 |
elmex |
1.33 |
$self->set_edit_tool ('pick'); |
457 |
elmex |
1.28 |
|
458 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "P_ick", sub { $self->set_edit_tool ('pick') }); |
459 |
|
|
$self->add_button ($tbl, $plcinfo, "_Place", sub { $self->set_edit_tool ('place') }); |
460 |
|
|
$self->add_button ($tbl, $plcinfo, "_Erase", sub { $self->set_edit_tool ('erase') }); |
461 |
|
|
$self->add_button ($tbl, $plcinfo, "_Select", sub { $self->set_edit_tool ('select') }); |
462 |
|
|
$self->add_button ($tbl, $plcinfo, "Eva_l", sub { $self->set_edit_tool ('perl') }); |
463 |
elmex |
1.63 |
$self->add_button ($tbl, $plcinfo, "Connec_t", sub { $self->set_edit_tool ('connect') }); |
464 |
elmex |
1.42 |
$self->add_button ($tbl, $plcinfo, "_Follow Exit", sub { $self->set_edit_tool ('followexit') }); |
465 |
elmex |
1.33 |
|
466 |
|
|
return $tbl; |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
sub set_edit_tool { |
470 |
|
|
my ($self, $name) = @_; |
471 |
|
|
|
472 |
|
|
if ($name eq 'pick') { |
473 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{pick}, "Pick");; |
474 |
elmex |
1.33 |
} elsif ($name eq 'place') { |
475 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{place}, "Place");; |
476 |
elmex |
1.33 |
} elsif ($name eq 'erase') { |
477 |
elmex |
1.28 |
$self->update_edit_tool ($self->{edit_collection}{erase}, "Erase");; |
478 |
elmex |
1.34 |
} elsif ($name eq 'select') { |
479 |
|
|
$self->update_edit_tool ($self->{edit_collection}{select}, "Select");; |
480 |
elmex |
1.57 |
$self->{edit_collection}{select}->update_overlay; |
481 |
elmex |
1.35 |
} elsif ($name eq 'perl') { |
482 |
|
|
$self->update_edit_tool ($self->{edit_collection}{perl}, "Eval");; |
483 |
elmex |
1.63 |
} elsif ($name eq 'connect') { |
484 |
|
|
$self->update_edit_tool ($self->{edit_collection}{connect}, "Connect");; |
485 |
elmex |
1.38 |
} elsif ($name eq 'followexit') { |
486 |
|
|
$self->update_edit_tool ($self->{edit_collection}{followexit}, "Follow Exit");; |
487 |
elmex |
1.33 |
} |
488 |
elmex |
1.17 |
} |
489 |
elmex |
1.10 |
|
490 |
elmex |
1.28 |
sub update_edit_tool { |
491 |
|
|
my ($self, $tool, $name) = @_; |
492 |
|
|
|
493 |
elmex |
1.57 |
for (values %{$self->{loaded_maps}}) { |
494 |
|
|
$_->{map}->overlay ('selection') |
495 |
|
|
} |
496 |
|
|
|
497 |
elmex |
1.28 |
$self->{edit_tool}->set_text ($name); |
498 |
|
|
$self->{sel_editaction} = $tool; |
499 |
|
|
|
500 |
|
|
my $widget = $tool->tool_widget; |
501 |
|
|
|
502 |
|
|
for ($self->{edit_tool_cont}->get_children) { |
503 |
|
|
$_->hide; |
504 |
|
|
$self->{edit_tool_cont}->remove ($_); |
505 |
|
|
} |
506 |
|
|
|
507 |
elmex |
1.53 |
$_->set_edit_tool ($self->{sel_editaction}) for (values %{$self->{editors}}); |
508 |
|
|
|
509 |
elmex |
1.28 |
defined $widget or return; |
510 |
|
|
|
511 |
|
|
$self->{edit_tool_cont}->add ($widget); |
512 |
|
|
$widget->show_all; |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
sub update_pick_view { |
516 |
|
|
my ($self, $arch) = @_; |
517 |
|
|
|
518 |
|
|
defined $arch->{_face} |
519 |
root |
1.83 |
or $arch = $Deliantra::ARCH{$arch->{_name}}; |
520 |
elmex |
1.28 |
|
521 |
|
|
fill_pb_from_arch ($self->{pick_view_pb}, $arch); |
522 |
|
|
$self->{pick_view_img}->set_from_pixbuf ($self->{pick_view_pb}); |
523 |
|
|
|
524 |
elmex |
1.33 |
$self->{pick_view_btn}->set_label ($arch->{_name}); |
525 |
elmex |
1.28 |
} |
526 |
|
|
|
527 |
elmex |
1.13 |
sub INIT_INSTANCE { |
528 |
|
|
my ($self) = @_; |
529 |
elmex |
1.10 |
|
530 |
elmex |
1.80 |
{ |
531 |
|
|
open my $fh, "<$recentfile"; |
532 |
|
|
binmode $fh; |
533 |
|
|
local $/; |
534 |
|
|
our @recent_entries = split /\0/, <$fh>; |
535 |
|
|
close $fh; |
536 |
|
|
} |
537 |
|
|
|
538 |
root |
1.24 |
$::MAINWIN = $self; |
539 |
elmex |
1.15 |
|
540 |
elmex |
1.85.2.2 |
$self->Object::Event::init_object_events; |
541 |
elmex |
1.85.2.1 |
|
542 |
elmex |
1.82 |
$self->set_title ("deliantra editor - toolbox"); |
543 |
elmex |
1.10 |
|
544 |
elmex |
1.28 |
$self->{edit_tool} = Gtk2::Label->new; |
545 |
|
|
$self->{edit_tool_cont} = Gtk2::VBox->new; |
546 |
|
|
|
547 |
elmex |
1.80 |
$self->add (my $vb = $self->{vb} = Gtk2::VBox->new); |
548 |
elmex |
1.13 |
$vb->pack_start ($self->build_menu, 0, 1, 0); |
549 |
elmex |
1.28 |
$vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0); |
550 |
|
|
|
551 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
552 |
|
|
$vb->pack_start ($self->{edit_tool}, 0, 1, 0); |
553 |
|
|
|
554 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
555 |
elmex |
1.35 |
$vb->pack_start ($self->{edit_tool_cont}, 1, 1, 0); |
556 |
elmex |
1.10 |
|
557 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
558 |
root |
1.27 |
$self->open_map_editor ($_) |
559 |
|
|
for @ARGV; |
560 |
root |
1.11 |
|
561 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
562 |
|
|
Gtk2->main_quit; |
563 |
elmex |
1.10 |
}); |
564 |
elmex |
1.17 |
|
565 |
elmex |
1.30 |
::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0); |
566 |
elmex |
1.58 |
|
567 |
|
|
|
568 |
|
|
$self->show_attr_editor; |
569 |
elmex |
1.2 |
} |
570 |
|
|
|
571 |
|
|
sub new_cb { |
572 |
|
|
my ($self) = @_; |
573 |
elmex |
1.32 |
|
574 |
|
|
my $w = Gtk2::Window->new ('toplevel'); |
575 |
|
|
my $width = [width => 20]; |
576 |
|
|
my $height = [height => 20]; |
577 |
|
|
$w->add (my $tbl = Gtk2::Table->new (2, 3)); |
578 |
|
|
add_table_widget ($tbl, 0, $width, 'string'); |
579 |
|
|
add_table_widget ($tbl, 1, $height, 'string'); |
580 |
|
|
add_table_widget ($tbl, 2, 'new', 'button', sub { |
581 |
|
|
if ($width->[1] > 0 and $height->[1] > 0) { |
582 |
root |
1.83 |
my $map = Deliantra::Map->new ($width->[1], $height->[1]); |
583 |
elmex |
1.69 |
$map->{info}->{width} = $width->[1]; |
584 |
|
|
$map->{info}->{height} = $height->[1]; |
585 |
elmex |
1.33 |
$map->resize ($width->[1], $height->[1]); |
586 |
elmex |
1.32 |
$self->open_map_editor ($map); |
587 |
|
|
} |
588 |
|
|
$w->destroy; |
589 |
|
|
1; |
590 |
|
|
}); |
591 |
|
|
add_table_widget ($tbl, 3, 'close', 'button', sub { $w->destroy }); |
592 |
|
|
$w->show_all; |
593 |
elmex |
1.2 |
} |
594 |
|
|
|
595 |
root |
1.25 |
sub new_filechooser { |
596 |
elmex |
1.37 |
my ($self, $title, $save, $filename) = @_; |
597 |
elmex |
1.2 |
|
598 |
elmex |
1.82 |
$title ||= 'deliantra editor - open map'; |
599 |
root |
1.25 |
my $fc = new Gtk2::FileChooserDialog ( |
600 |
elmex |
1.33 |
$title, undef, $save ? 'save' : 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
601 |
elmex |
1.13 |
); |
602 |
|
|
|
603 |
elmex |
1.78 |
my @shortcut_folders = |
604 |
|
|
grep { $_ && ($_ ne '') && -e $_ } keys %{$self->{fc_last_folders}}; |
605 |
elmex |
1.76 |
|
606 |
elmex |
1.78 |
$fc->add_shortcut_folder ($_) for @shortcut_folders; |
607 |
|
|
|
608 |
|
|
unless (grep { $::MAPDIR eq $_ } @shortcut_folders) { |
609 |
|
|
$fc->add_shortcut_folder ($::MAPDIR) |
610 |
|
|
if -d $::MAPDIR; |
611 |
|
|
} |
612 |
elmex |
1.76 |
|
613 |
elmex |
1.55 |
$fc->set_current_folder (getcwd); |
614 |
elmex |
1.2 |
|
615 |
elmex |
1.37 |
if ($filename) { |
616 |
|
|
$fc->set_filename ($filename); |
617 |
|
|
} |
618 |
|
|
|
619 |
root |
1.25 |
$fc |
620 |
|
|
} |
621 |
|
|
|
622 |
elmex |
1.71 |
sub new_coord_query { |
623 |
elmex |
1.75 |
my ($self, $finishcb) = @_; |
624 |
elmex |
1.71 |
|
625 |
elmex |
1.75 |
my $coordhash = { x => 105, y => 115, worldmap => 1, overlay => 0 }; |
626 |
elmex |
1.71 |
my $diag = GCE::HashDialogue->new; |
627 |
elmex |
1.75 |
$self->{"worldmap_coord_query"} = $diag; |
628 |
elmex |
1.73 |
$diag->signal_connect (destroy => sub { |
629 |
elmex |
1.75 |
delete $self->{"worldmap_coord_query"}; |
630 |
elmex |
1.73 |
}); |
631 |
elmex |
1.71 |
$diag->init ( |
632 |
elmex |
1.75 |
layout_name => 'worldmap_coord_query', |
633 |
|
|
info => "Open worldmap at ...", |
634 |
elmex |
1.71 |
dialog_default_size => [ 200, 200, 200, 0 ], |
635 |
|
|
title => 'Worldmap coordinate entry', |
636 |
|
|
ref_hash => $coordhash, |
637 |
|
|
dialog => [ |
638 |
elmex |
1.77 |
[x => 'X Coordinate' => 'spin', sub { (0, 999, 1) }], |
639 |
|
|
[y => 'Y Coordinate' => 'spin', sub { (0, 999, 1) }], |
640 |
elmex |
1.75 |
[worldmap => 'Open worldmap' => 'check'], |
641 |
|
|
[overlay => 'Open overlay (CF+)' => 'check'], |
642 |
elmex |
1.71 |
], |
643 |
|
|
save_button_label => 'open', |
644 |
|
|
save_cb => sub { |
645 |
elmex |
1.75 |
$finishcb->($_[0]); |
646 |
elmex |
1.71 |
} |
647 |
|
|
); |
648 |
|
|
$diag->show_all; |
649 |
|
|
} |
650 |
|
|
|
651 |
|
|
sub open_worldmap_cb { |
652 |
elmex |
1.75 |
my ($self) = @_; |
653 |
elmex |
1.71 |
|
654 |
elmex |
1.75 |
$self->new_coord_query (sub { |
655 |
|
|
my ($info) = @_; |
656 |
|
|
my ($x, $y) = ($info->{x}, $info->{y}); |
657 |
|
|
my ($worldmap, $overlay) = ($info->{worldmap}, $info->{overlay}); |
658 |
elmex |
1.76 |
$self->open_map_editor ($::MAPDIR . "/world/world_$x\_$y") |
659 |
elmex |
1.75 |
if $worldmap; |
660 |
elmex |
1.76 |
$self->open_map_editor ($::MAPDIR . "/world-overlay/world_$x\_$y") |
661 |
elmex |
1.75 |
if $overlay; |
662 |
elmex |
1.71 |
}); |
663 |
|
|
} |
664 |
|
|
|
665 |
root |
1.25 |
sub open_cb { |
666 |
|
|
my ($self) = @_; |
667 |
|
|
|
668 |
|
|
my $fc = $self->new_filechooser; |
669 |
|
|
|
670 |
elmex |
1.2 |
if ('ok' eq $fc->run) { |
671 |
elmex |
1.13 |
|
672 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
673 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
674 |
elmex |
1.17 |
|
675 |
|
|
$self->open_map_editor ($fc->get_filename); |
676 |
elmex |
1.2 |
} |
677 |
|
|
|
678 |
|
|
$fc->destroy; |
679 |
|
|
} |
680 |
|
|
|
681 |
elmex |
1.17 |
sub get_pick { |
682 |
|
|
my ($self) = @_; |
683 |
|
|
|
684 |
elmex |
1.58 |
$self->{attr_edit} |
685 |
|
|
or die "Couldn't find attribute editor! SERIOUS BUG!"; |
686 |
|
|
|
687 |
elmex |
1.17 |
# XXX: This is just to make sure that this function always returns something |
688 |
elmex |
1.61 |
|
689 |
|
|
my $ar = $self->{attr_edit}->get_arch; |
690 |
|
|
return { _name => 'platinacoin' } unless defined $ar; |
691 |
|
|
return $ar->getarch || { _name => 'platinacoin' }; |
692 |
elmex |
1.17 |
} |
693 |
|
|
|
694 |
elmex |
1.85.2.1 |
# |
695 |
|
|
# Map/Cursor interface |
696 |
|
|
# |
697 |
|
|
|
698 |
|
|
sub cursor { |
699 |
|
|
my ($self, $map, @a) = @_; |
700 |
|
|
$map->cursor (@a) |
701 |
|
|
} |
702 |
|
|
|
703 |
elmex |
1.85.2.2 |
sub broadcast_cursor_changes { |
704 |
|
|
my ($self, $map, $x, $y) = @_; |
705 |
|
|
my $cursors = $map->cursors_at ($x, $y); |
706 |
|
|
warn "CURSOR UPDTEAD! " |
707 |
|
|
. join (',', map { "$_: $_->{owner}" } @$cursors) |
708 |
|
|
. "\n"; |
709 |
|
|
$self->Object::Event::event (cursor_updates => $cursors); |
710 |
|
|
} |
711 |
elmex |
1.85.2.1 |
|
712 |
elmex |
1.1 |
=head1 AUTHOR |
713 |
|
|
|
714 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
715 |
|
|
http://home.schmorp.de/ |
716 |
|
|
|
717 |
|
|
Robin Redeker <elmex@ta-sa.org> |
718 |
|
|
http://www.ta-sa.org/ |
719 |
|
|
|
720 |
|
|
=cut |
721 |
|
|
1; |
722 |
|
|
|