ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
(Generate patch)

Comparing deliantra/gde/GCE/MapEditor.pm (file contents):
Revision 1.29 by elmex, Mon Mar 20 04:11:41 2006 UTC vs.
Revision 1.31 by elmex, Sun Mar 26 15:41:59 2006 UTC

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 "Close" => { 39 "Close" => {
40 callback => sub { $self->delete; 1 }, 40 callback => sub { $self->destroy },
41 }, 41 },
42 ] 42 ]
43 }, 43 },
44 _Edit => { 44 _Edit => {
45 item_type => '<Branch>', 45 item_type => '<Branch>',
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
123sub 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
123sub ea { 133sub ea {
124 my ($self) = @_; 134 my ($self) = @_;
125 $self->{ea_alt} || $::MAINWIN->{sel_editaction}; 135 $self->{ea_alt} || $self->{etool};
126} 136}
127 137
128sub INIT_INSTANCE { 138sub 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); 202 my $as = $map->get ($x, $y);
195
196 if ((not $self->{draw_mode}) and $event->button != 2) {
197 203
198 my $ea = $self->ea; 204 my $ea = $self->ea;
199 205
200 $ea->begin ($map, $x, $y, $self) 206 $ea->begin ($map, $x, $y, $self)
201 if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height}; 207 if $x >= 0 and $y >= 0 and $x < $map->{map}{width} and $y < $map->{map}{height};
205 $ea->want_cursor 211 $ea->want_cursor
206 or $map->disable_tooltip; 212 or $map->disable_tooltip;
207 213
208 return 1; 214 return 1;
209 } 215 }
216
210 0 217 0
211 }); 218 });
212 219
213 $map->signal_connect_after (motion_notify_event => sub { 220 $map->signal_connect_after (motion_notify_event => sub {
214 my ($map, $event) = @_; 221 my ($map, $event) = @_;
235 @{$self->{draw_mode}}[0,1] = ($X, $Y); 242 @{$self->{draw_mode}}[0,1] = ($X, $Y);
236 243
237 1 244 1
238 }); 245 });
239 246
240 $map->signal_connect (button_release_event => sub { 247 $map->signal_connect_after (button_release_event => sub {
241 my ($map, $event) = @_; 248 my ($map, $event) = @_;
242 249
243 if ($self->{draw_mode}) { 250 if ($self->{draw_mode} and $event->button == 1) {
244 my ($x, $y) = $map->coord ($map->get_pointer); 251 my ($x, $y) = $map->coord ($map->get_pointer);
245 252
246 my $ea = $self->ea; 253 my $ea = $self->ea;
247 $ea->end ($map, $x, $y, $self); 254 $ea->end ($map, $x, $y, $self);
248 255
278 $map->{undo_stack} 285 $map->{undo_stack}
279 and $map->{undo_stack_pos} < @{$map->{undo_stack}} 286 and $map->{undo_stack_pos} < @{$map->{undo_stack}}
280 or return; 287 or return;
281 288
282 $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]); 289 $map->change_swap ($map->{undo_stack}[$map->{undo_stack_pos}++]);
283}
284
285sub 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} 290}
297 291
298sub open_map { 292sub open_map {
299 my ($self, $path, $key) = @_; 293 my ($self, $path, $key) = @_;
300 294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines