… | |
… | |
34 | accelerator => '<ctrl>S' |
34 | accelerator => '<ctrl>S' |
35 | }, |
35 | }, |
36 | "Save As" => { |
36 | "Save As" => { |
37 | callback => sub { $self->save_map_as }, |
37 | callback => sub { $self->save_map_as }, |
38 | }, |
38 | }, |
|
|
39 | "_Map Properties" => { |
|
|
40 | callback => sub { $self->open_map_prop }, |
|
|
41 | accelerator => "<ctrl>P" |
|
|
42 | }, |
|
|
43 | "_Map Resize" => { |
|
|
44 | callback => sub { $self->open_resize_map }, |
|
|
45 | accelerator => "<ctrl>R" |
|
|
46 | }, |
39 | "Close" => { |
47 | "Close" => { |
40 | callback => sub { $self->delete; 1 }, |
48 | callback => sub { $self->destroy }, |
41 | }, |
49 | }, |
42 | ] |
50 | ] |
43 | }, |
51 | }, |
44 | _Edit => { |
52 | _Edit => { |
45 | item_type => '<Branch>', |
53 | item_type => '<Branch>', |
… | |
… | |
50 | }, |
58 | }, |
51 | "_Redo" => { |
59 | "_Redo" => { |
52 | callback => sub { $self->redo }, |
60 | callback => sub { $self->redo }, |
53 | accelerator => "<ctrl>Y" |
61 | accelerator => "<ctrl>Y" |
54 | }, |
62 | }, |
55 | "_Map Properties" => { |
|
|
56 | callback => sub { $self->open_map_prop }, |
|
|
57 | accelerator => "<ctrl>P" |
|
|
58 | }, |
|
|
59 | "_Map Resize" => { |
|
|
60 | callback => sub { $self->open_resize_map }, |
|
|
61 | accelerator => "<ctrl>R" |
|
|
62 | }, |
|
|
63 | ] |
63 | ] |
64 | }, |
64 | }, |
65 | _Go => { |
65 | _Go => { |
66 | item_type => '<Branch>', |
66 | item_type => '<Branch>', |
67 | children => [ |
67 | children => [ |
… | |
… | |
84 | ] |
84 | ] |
85 | }, |
85 | }, |
86 | _Help => { |
86 | _Help => { |
87 | item_type => '<Branch>', |
87 | item_type => '<Branch>', |
88 | children => [ |
88 | children => [ |
89 | _Help => { |
89 | _Manual => { |
90 | callback => sub { $::MAINWIN->show_help_window }, |
90 | callback => sub { $::MAINWIN->show_help_window }, |
91 | accelerator => "<ctrl>H" |
91 | accelerator => "<ctrl>H" |
92 | }, |
92 | }, |
93 | ] |
93 | ] |
94 | }, |
94 | }, |
… | |
… | |
118 | $self->add_accel_group ($men->{accel_group}); |
118 | $self->add_accel_group ($men->{accel_group}); |
119 | |
119 | |
120 | return $men->{widget}; |
120 | return $men->{widget}; |
121 | } |
121 | } |
122 | |
122 | |
|
|
123 | sub set_edit_tool { |
|
|
124 | my ($self, $tool) = @_; |
|
|
125 | |
|
|
126 | $self->{etool} = $tool; |
|
|
127 | |
|
|
128 | if ($self->ea->special_arrow) { |
|
|
129 | $self->{map}{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
|
|
130 | } |
|
|
131 | } |
|
|
132 | |
123 | sub ea { |
133 | sub ea { |
124 | my ($self) = @_; |
134 | my ($self) = @_; |
125 | $self->{ea_alt} || $::MAINWIN->{sel_editaction}; |
135 | $self->{ea_alt} || $self->{etool}; |
126 | } |
136 | } |
127 | |
137 | |
128 | sub INIT_INSTANCE { |
138 | sub INIT_INSTANCE { |
129 | my ($self) = @_; |
139 | my ($self) = @_; |
130 | |
140 | |
131 | $self->set_title ('gce - map editor'); |
141 | $self->set_title ('gce - map editor'); |
132 | $self->add (my $vb = Gtk2::VBox->new); |
142 | $self->add (my $vb = Gtk2::VBox->new); |
133 | |
143 | |
134 | $self->signal_connect (delete_event => sub { $self->delete; 1 }); |
|
|
135 | |
|
|
136 | $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); |
144 | $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); |
137 | |
145 | |
138 | $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0); |
146 | $vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0); |
139 | |
147 | |
140 | $self->signal_connect (focus_in_event => sub { |
|
|
141 | my $ea = $::MAINWIN->{sel_editaction}; |
|
|
142 | if ($ea->special_arrow) { |
|
|
143 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($ea->special_arrow)); |
|
|
144 | } else { |
|
|
145 | $self->{map}->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
|
|
146 | } |
|
|
147 | delete $self->{ea_alt}; |
|
|
148 | }); |
|
|
149 | |
|
|
150 | $map->signal_connect (key_press_event => sub { |
148 | $map->signal_connect_after (key_press_event => sub { |
151 | my ($map, $event) = @_; |
149 | my ($map, $event) = @_; |
152 | |
150 | |
153 | my $kv = $event->keyval; |
151 | my $kv = $event->keyval; |
|
|
152 | |
|
|
153 | my $ret = 0; |
154 | |
154 | |
155 | my ($x, $y) = $map->coord ($map->get_pointer); |
155 | my ($x, $y) = $map->coord ($map->get_pointer); |
156 | for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }], |
156 | for ([Control_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{erase} }], |
157 | [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }], |
157 | [Alt_L => sub { $self->{ea_alt} = $::MAINWIN->{edit_collection}{pick} }], |
158 | [c => sub { $::MAINWIN->{edit_collection}{select}->copy }], |
158 | [c => sub { $::MAINWIN->{edit_collection}{select}->copy }], |
… | |
… | |
160 | [n => sub { $::MAINWIN->{edit_collection}{select}->invoke }], |
160 | [n => sub { $::MAINWIN->{edit_collection}{select}->invoke }], |
161 | ) |
161 | ) |
162 | { |
162 | { |
163 | if ($kv == $Gtk2::Gdk::Keysyms{$_->[0]}) { |
163 | if ($kv == $Gtk2::Gdk::Keysyms{$_->[0]}) { |
164 | $_->[1]->(); |
164 | $_->[1]->(); |
|
|
165 | $ret = 1; |
165 | } |
166 | } |
166 | } |
167 | } |
167 | |
168 | |
168 | if ($self->ea->special_arrow) { |
169 | if ($self->ea->special_arrow) { |
169 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
170 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
170 | } |
171 | } |
171 | 1; |
172 | |
|
|
173 | $ret |
172 | }); |
174 | }); |
|
|
175 | |
173 | $map->signal_connect (key_release_event => sub { |
176 | $map->signal_connect_after (key_release_event => sub { |
174 | my ($map, $event) = @_; |
177 | my ($map, $event) = @_; |
|
|
178 | |
|
|
179 | my $ret = 0; |
175 | |
180 | |
176 | if ($event->keyval == $Gtk2::Gdk::Keysyms{Control_L} |
181 | if ($event->keyval == $Gtk2::Gdk::Keysyms{Control_L} |
177 | or $event->keyval == $Gtk2::Gdk::Keysyms{Alt_L}) |
182 | or $event->keyval == $Gtk2::Gdk::Keysyms{Alt_L}) |
178 | { |
183 | { |
179 | delete $self->{ea_alt}; |
184 | delete $self->{ea_alt}; |
|
|
185 | $ret = 1; |
180 | } |
186 | } |
181 | |
187 | |
182 | if ($self->ea->special_arrow) { |
188 | if ($self->ea->special_arrow) { |
183 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
189 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($self->ea->special_arrow)); |
184 | } else { |
190 | } else { |
185 | # XXX: Get the original cursor and insert it here |
191 | # FIXME: Get the original cursor and insert it here |
186 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
192 | $map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
187 | } |
193 | } |
188 | 1; |
194 | |
|
|
195 | $ret |
189 | }); |
196 | }); |
190 | $map->signal_connect (button_press_event => sub { |
197 | $map->signal_connect_after (button_press_event => sub { |
191 | my ($map, $event) = @_; |
198 | my ($map, $event) = @_; |
192 | |
199 | |
|
|
200 | if ((not $self->{draw_mode}) and $event->button == 1) { |
193 | my ($x, $y) = $map->coord ($event->x, $event->y); |
201 | my ($x, $y) = $map->coord ($event->x, $event->y); |
194 | my $as = $map->get ($x, $y); |
|
|
195 | |
|
|
196 | if ((not $self->{draw_mode}) and $event->button != 2) { |
|
|
197 | |
202 | |
198 | my $ea = $self->ea; |
203 | my $ea = $self->ea; |
199 | |
204 | |
200 | $ea->begin ($map, $x, $y, $self) |
205 | $ea->begin ($map, $x, $y, $self) |
201 | if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; |
206 | if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; |
… | |
… | |
205 | $ea->want_cursor |
210 | $ea->want_cursor |
206 | or $map->disable_tooltip; |
211 | or $map->disable_tooltip; |
207 | |
212 | |
208 | return 1; |
213 | return 1; |
209 | } |
214 | } |
|
|
215 | |
210 | 0 |
216 | 0 |
211 | }); |
217 | }); |
212 | |
218 | |
213 | $map->signal_connect_after (motion_notify_event => sub { |
219 | $map->signal_connect_after (motion_notify_event => sub { |
214 | my ($map, $event) = @_; |
220 | my ($map, $event) = @_; |
… | |
… | |
235 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
241 | @{$self->{draw_mode}}[0,1] = ($X, $Y); |
236 | |
242 | |
237 | 1 |
243 | 1 |
238 | }); |
244 | }); |
239 | |
245 | |
240 | $map->signal_connect (button_release_event => sub { |
246 | $map->signal_connect_after (button_release_event => sub { |
241 | my ($map, $event) = @_; |
247 | my ($map, $event) = @_; |
242 | |
248 | |
243 | if ($self->{draw_mode}) { |
249 | if ($self->{draw_mode} and $event->button == 1) { |
244 | my ($x, $y) = $map->coord ($map->get_pointer); |
250 | my ($x, $y) = $map->coord ($map->get_pointer); |
245 | |
251 | |
246 | my $ea = $self->ea; |
252 | my $ea = $self->ea; |
247 | $ea->end ($map, $x, $y, $self); |
253 | $ea->end ($map, $x, $y, $self); |
248 | |
254 | |
… | |
… | |
278 | $map->{undo_stack} |
284 | $map->{undo_stack} |
279 | and $map->{undo_stack_pos} < @{$map->{undo_stack}} |
285 | and $map->{undo_stack_pos} < @{$map->{undo_stack}} |
280 | or return; |
286 | or return; |
281 | |
287 | |
282 | $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]); |
288 | $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]); |
283 | } |
|
|
284 | |
|
|
285 | sub delete { |
|
|
286 | my ($self) = @_; |
|
|
287 | |
|
|
288 | # check and modla dialog if "dirty" |
|
|
289 | |
|
|
290 | if ($self->{mapkey}) { |
|
|
291 | # XXX: This should be in a delete event handler in the MainWindow.pm... but it doesnt work |
|
|
292 | delete $::MAINWIN->{loaded_maps}->{$self->{mapkey}}; |
|
|
293 | } |
|
|
294 | |
|
|
295 | $self->destroy; |
|
|
296 | } |
289 | } |
297 | |
290 | |
298 | sub open_map { |
291 | sub open_map { |
299 | my ($self, $path, $key) = @_; |
292 | my ($self, $path, $key) = @_; |
300 | |
293 | |