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

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 elmex 1.2 use GCE::Util;
98    
99 elmex 1.1 our @ISA = qw/GCE::EditAction/;
100    
101     sub want_cursor { 0 }
102    
103     sub begin {
104     my ($self, $map, $x, $y, $btn) = @_;
105    
106     $self->edit ($map, $x, $y, $btn);
107     }
108    
109     sub edit {
110     my ($self, $map, $x, $y, $btn) = @_;
111    
112     if ($btn == 3) { # btn 3 does pick
113    
114     my $cstack = $map->get ($x, $y) or return;
115     my $arch = $cstack->[-1];
116    
117     $arch->{_virtual}
118     and $arch = $arch->{_virtual};
119    
120     $GCE::MainWindow::MAINWIN->set_pick ($arch)
121     if @$cstack;;
122    
123     } else {
124    
125     my $pick = $GCE::MainWindow::MAINWIN->get_pick;
126     my $as = $map->get ($x, $y);
127    
128     my $arch = { _name => $pick->{_name} };
129    
130 elmex 1.2 $map->set ($x, $y, insert_arch_stack_layer ($as, $arch));
131     # push @$as, $arch
132     # unless @$as && $as->[-1]->{_name} eq $arch->{_name};
133 elmex 1.1
134 elmex 1.2 #$map->set ($x, $y, $as);
135 elmex 1.1 }
136     }
137    
138     package GCE::EditAction::Erase;
139    
140     our @ISA = qw/GCE::EditAction/;
141    
142     sub want_cursor { 0 }
143    
144     sub begin {
145     my ($self, $map, $x, $y, $btn) = @_;
146    
147     $self->edit ($map, $x, $y, $btn);
148     }
149    
150     sub edit {
151     my ($self, $map, $x, $y, $btn) = @_;
152    
153     my $as = $map->get ($x, $y);
154     pop @$as;
155     $map->set ($x, $y, $as);
156     }
157    
158     =head1 AUTHOR
159    
160     Marc Lehmann <schmorp@schmorp.de>
161     http://home.schmorp.de/
162    
163     Robin Redeker <elmex@ta-sa.org>
164     http://www.ta-sa.org/
165    
166     =cut
167     1;
168