ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
Revision: 1.7
Committed: Mon Feb 20 18:21:04 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.6: +12 -7 lines
Log Message:
implemented layer insertion

File Contents

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