ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/EditAction.pm
Revision: 1.1
Committed: Mon Feb 20 13:30:28 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Log Message:
implemented edit actions and layout saving

File Contents

# User Rev Content
1 elmex 1.1 package GCE::EditAction;
2    
3     =head1 NAME
4    
5     GCE::EditActions - this is the abstraction of edit actions (placing, deleting, etc.)
6    
7     =cut
8    
9     use Gtk2;
10     use Gtk2::Gdk::Keysyms;
11     use Gtk2::SimpleMenu;
12    
13     use Crossfire;
14     use Crossfire::MapWidget;
15    
16     use strict;
17    
18     sub new {
19     my $class = shift;
20     my $self = { @_ };
21     bless $self, $class;
22     return $self;
23     }
24    
25     sub want_cursor { 1 }
26    
27     sub special_arrow { }
28    
29     # edits one tile of the map
30     sub edit_one {
31     my ($self, $x, $y) = @_;
32     # do one edition
33     }
34    
35     # edits a selection
36     sub edit_selection {
37     }
38    
39     # abstraction for edit_one and edit_selection ?
40     # takes selection if present
41     sub edit {
42     my ($self, $map, $x, $y, $btn) = @_;
43     }
44    
45     sub begin {
46     my ($self, $map, $x, $y, $btn) = @_;
47     # prepare undo stack element
48     }
49     sub end {
50     # push undo stack
51     }
52    
53    
54     package GCE::EditAction::Pick;
55    
56     our @ISA = qw/GCE::EditAction/;
57    
58     sub special_arrow { 'GDK_HAND2' }
59    
60     sub begin {
61     my ($self, $map, $x, $y, $btn) = @_;
62    
63     $self->edit ($map, $x, $y, $btn);
64     }
65    
66     sub edit {
67     my ($self, $map, $x, $y, $btn) = @_;
68    
69     my $cstack = $map->get ($x, $y);
70    
71     my $arch = $cstack->[-1];
72    
73     # virtual... grmbl....
74     # FIXME: I have to patch the stack of the real arch??? argl.. how??
75     if ($arch->{_virtual}) {
76    
77     $x = $arch->{virtual_x};
78     $y = $arch->{virtual_y};
79     $arch = $arch->{_virtual};
80     }
81    
82     if ($btn == 1) {
83    
84     $GCE::MainWindow::MAINWIN->set_pick ($arch)
85     if @$cstack;
86     }
87    
88     $GCE::MainWindow::MAINWIN->update_attr_editor ($arch, sub {
89     $map->set ($x, $y, $cstack);
90     });
91    
92     $GCE::MainWindow::MAINWIN->update_stack_view ($map, $x, $y);
93     }
94    
95     package GCE::EditAction::Place;
96    
97     our @ISA = qw/GCE::EditAction/;
98    
99     sub want_cursor { 0 }
100    
101     sub begin {
102     my ($self, $map, $x, $y, $btn) = @_;
103    
104     $self->edit ($map, $x, $y, $btn);
105     }
106    
107     sub edit {
108     my ($self, $map, $x, $y, $btn) = @_;
109    
110     if ($btn == 3) { # btn 3 does pick
111    
112     my $cstack = $map->get ($x, $y) or return;
113     my $arch = $cstack->[-1];
114    
115     $arch->{_virtual}
116     and $arch = $arch->{_virtual};
117    
118     $GCE::MainWindow::MAINWIN->set_pick ($arch)
119     if @$cstack;;
120    
121     } else {
122    
123     my $pick = $GCE::MainWindow::MAINWIN->get_pick;
124     my $as = $map->get ($x, $y);
125    
126     my $arch = { _name => $pick->{_name} };
127    
128     push @$as, $arch
129     unless @$as && $as->[-1]->{_name} eq $arch->{_name};
130    
131     $map->set ($x, $y, $as);
132     }
133     }
134    
135     package GCE::EditAction::Erase;
136    
137     our @ISA = qw/GCE::EditAction/;
138    
139     sub want_cursor { 0 }
140    
141     sub begin {
142     my ($self, $map, $x, $y, $btn) = @_;
143    
144     $self->edit ($map, $x, $y, $btn);
145     }
146    
147     sub edit {
148     my ($self, $map, $x, $y, $btn) = @_;
149    
150     my $as = $map->get ($x, $y);
151     pop @$as;
152     $map->set ($x, $y, $as);
153     }
154    
155     =head1 AUTHOR
156    
157     Marc Lehmann <schmorp@schmorp.de>
158     http://home.schmorp.de/
159    
160     Robin Redeker <elmex@ta-sa.org>
161     http://www.ta-sa.org/
162    
163     =cut
164     1;
165