| 1 |
elmex |
1.1 |
package GCE::MapEditor; |
| 2 |
|
|
|
| 3 |
|
|
=head1 NAME |
| 4 |
|
|
|
| 5 |
|
|
GCE::MapEditor - the map editing widget |
| 6 |
|
|
|
| 7 |
|
|
=cut |
| 8 |
|
|
|
| 9 |
|
|
use Gtk2; |
| 10 |
|
|
use Gtk2::Gdk::Keysyms; |
| 11 |
|
|
use Gtk2::SimpleMenu; |
| 12 |
|
|
|
| 13 |
|
|
use Crossfire; |
| 14 |
root |
1.3 |
use Crossfire::Map; |
| 15 |
elmex |
1.1 |
use Crossfire::MapWidget; |
| 16 |
|
|
|
| 17 |
|
|
use GCE::AttrEdit; |
| 18 |
|
|
|
| 19 |
elmex |
1.4 |
use Glib::Object::Subclass |
| 20 |
elmex |
1.6 |
Gtk2::Window; |
| 21 |
elmex |
1.1 |
|
| 22 |
|
|
use strict; |
| 23 |
|
|
|
| 24 |
|
|
sub INIT_INSTANCE { |
| 25 |
|
|
my ($self) = @_; |
| 26 |
|
|
|
| 27 |
elmex |
1.6 |
$self->set_title ('gce - map editor'); |
| 28 |
|
|
$self->add (my $vb = Gtk2::VBox->new); |
| 29 |
|
|
$vb->pack_start (my $map = $self->{map} = Crossfire::MapWidget->new, 1, 1, 0); |
| 30 |
|
|
$map->signal_connect (button_press_event => sub { |
| 31 |
|
|
my ($map, $event) = @_; |
| 32 |
elmex |
1.1 |
|
| 33 |
elmex |
1.6 |
my ($x, $y) = $map->coord ($event->x, $event->y); |
| 34 |
|
|
my $as = $map->get ($x, $y); |
| 35 |
elmex |
1.1 |
|
| 36 |
elmex |
1.6 |
my $btn = $event->button; |
| 37 |
elmex |
1.1 |
|
| 38 |
elmex |
1.7 |
if ((not $self->{draw_mode}) |
| 39 |
|
|
and $btn != 2 |
| 40 |
|
|
and my $ea = $GCE::MainWindow::MAINWIN->{sel_editaction}) { |
| 41 |
elmex |
1.4 |
|
| 42 |
elmex |
1.6 |
$ea->begin ($map, $x, $y, $btn); |
| 43 |
elmex |
1.4 |
|
| 44 |
elmex |
1.6 |
$self->{draw_mode} = [$ea, $x, $y, $btn]; |
| 45 |
elmex |
1.4 |
|
| 46 |
elmex |
1.6 |
$ea->want_cursor |
| 47 |
|
|
or $map->disable_tooltip; |
| 48 |
elmex |
1.4 |
|
| 49 |
elmex |
1.6 |
if ($ea->special_arrow) { |
| 50 |
elmex |
1.4 |
|
| 51 |
elmex |
1.6 |
$map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ($ea->special_arrow)); |
| 52 |
|
|
#'GDK_QUESTION_ARROW')); |
| 53 |
|
|
} |
| 54 |
elmex |
1.4 |
|
| 55 |
elmex |
1.6 |
return 1; |
| 56 |
elmex |
1.7 |
} |
| 57 |
elmex |
1.1 |
|
| 58 |
elmex |
1.6 |
0 |
| 59 |
|
|
}); |
| 60 |
elmex |
1.1 |
|
| 61 |
elmex |
1.6 |
$map->signal_connect_after (motion_notify_event => sub { |
| 62 |
|
|
my ($map, $event) = @_; |
| 63 |
elmex |
1.1 |
|
| 64 |
elmex |
1.6 |
$self->{draw_mode} |
| 65 |
|
|
or return; |
| 66 |
elmex |
1.1 |
|
| 67 |
elmex |
1.6 |
my ($X, $Y) = @{$self->{draw_mode}}[1,2]; |
| 68 |
|
|
my ($x, $y) = $map->coord ($map->get_pointer); |
| 69 |
elmex |
1.4 |
|
| 70 |
elmex |
1.6 |
while ($x != $X || $y != $Y) { |
| 71 |
elmex |
1.1 |
|
| 72 |
elmex |
1.6 |
$X++ if $X < $x; |
| 73 |
|
|
$X-- if $X > $x; |
| 74 |
|
|
$Y++ if $Y < $y; |
| 75 |
|
|
$Y-- if $Y > $y; |
| 76 |
elmex |
1.1 |
|
| 77 |
elmex |
1.6 |
$self->{draw_mode}[0]->edit ($map, $X, $Y, $self->{draw_mode}[3]); |
| 78 |
|
|
} |
| 79 |
elmex |
1.1 |
|
| 80 |
elmex |
1.6 |
@{$self->{draw_mode}}[1,2] = ($X, $Y); |
| 81 |
elmex |
1.4 |
|
| 82 |
elmex |
1.6 |
1 |
| 83 |
|
|
}); |
| 84 |
elmex |
1.1 |
|
| 85 |
elmex |
1.6 |
$map->signal_connect (button_release_event => sub { |
| 86 |
|
|
my ($map, $event) = @_; |
| 87 |
elmex |
1.1 |
|
| 88 |
elmex |
1.7 |
if ($self->{draw_mode} |
| 89 |
|
|
and my $ea = $self->{draw_mode}[0] |
| 90 |
|
|
and $self->{draw_mode}[3] == $event->button) { |
| 91 |
elmex |
1.8 |
|
| 92 |
|
|
my ($x, $y) = $map->coord ($map->get_pointer); |
| 93 |
|
|
|
| 94 |
|
|
$ea->end ($map, $x, $y, $event->button); |
| 95 |
elmex |
1.1 |
|
| 96 |
elmex |
1.6 |
if ($ea->special_arrow) { |
| 97 |
elmex |
1.1 |
|
| 98 |
elmex |
1.6 |
# XXX: Get the original cursor and insert it here |
| 99 |
|
|
$map->{window}->set_cursor (Gtk2::Gdk::Cursor->new ('GDK_LEFT_PTR')); |
| 100 |
|
|
} |
| 101 |
elmex |
1.1 |
|
| 102 |
elmex |
1.6 |
delete $self->{draw_mode}; |
| 103 |
elmex |
1.7 |
|
| 104 |
|
|
$ea->want_cursor |
| 105 |
|
|
or $map->enable_tooltip; |
| 106 |
|
|
|
| 107 |
|
|
return 1; |
| 108 |
elmex |
1.6 |
} |
| 109 |
elmex |
1.1 |
|
| 110 |
elmex |
1.6 |
0 |
| 111 |
|
|
}); |
| 112 |
root |
1.3 |
} |
| 113 |
|
|
|
| 114 |
|
|
sub delete_arch { |
| 115 |
|
|
my ($self, $x, $y) = @_; |
| 116 |
|
|
|
| 117 |
|
|
defined $self->{map} |
| 118 |
|
|
or return 0; |
| 119 |
|
|
|
| 120 |
root |
1.5 |
my $as = $self->{map}->get ($x, $y); |
| 121 |
|
|
pop @$as; |
| 122 |
|
|
$self->{map}->set ($x, $y, $as); |
| 123 |
root |
1.3 |
} |
| 124 |
|
|
|
| 125 |
|
|
sub place_pick { |
| 126 |
|
|
my ($self, $x, $y) = @_; |
| 127 |
|
|
|
| 128 |
elmex |
1.6 |
my $pick = $GCE::MainWindow::MAINWIN->get_pick; |
| 129 |
root |
1.5 |
my $as = $self->{map}->get ($x, $y); |
| 130 |
root |
1.3 |
|
| 131 |
elmex |
1.6 |
my $arch = { _name => $pick->{_name} }; |
| 132 |
root |
1.3 |
|
| 133 |
root |
1.5 |
push @$as, $arch |
| 134 |
|
|
unless @$as && $as->[-1]->{_name} eq $arch->{_name}; |
| 135 |
root |
1.3 |
|
| 136 |
root |
1.5 |
$self->{map}->set ($x, $y, $as); |
| 137 |
root |
1.3 |
} |
| 138 |
|
|
|
| 139 |
|
|
sub open_map { |
| 140 |
|
|
my ($self, $path) = @_; |
| 141 |
|
|
|
| 142 |
|
|
$self->{map}->set_map (new_from_file Crossfire::Map $path); |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
elmex |
1.1 |
=head1 AUTHOR |
| 146 |
|
|
|
| 147 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
| 148 |
|
|
http://home.schmorp.de/ |
| 149 |
|
|
|
| 150 |
|
|
Robin Redeker <elmex@ta-sa.org> |
| 151 |
|
|
http://www.ta-sa.org/ |
| 152 |
|
|
|
| 153 |
|
|
=cut |
| 154 |
|
|
1; |
| 155 |
|
|
|