ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.21
Committed: Tue Apr 4 21:12:08 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.20: +4 -7 lines
Log Message:
Changed updating of attribute editor and inventory editor in a major manner.
We have now an abstraction layer between attribute editor and arch/object that
handles updating of the map and calling change_begin/set/end.

Works fine after testing, please watchout for bugs in attribute editor,
inventory editor and updating of these.

File Contents

# Content
1 package GCE::PickWindow;
2
3 =head1 NAME
4
5 GCE::PickWindow - the arch picker window class for gce
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 GCE::AttrEdit;
17 use GCE::MapEditor;
18 use GCE::StackView;
19 use GCE::EditAction;
20 use GCE::PickWindow;
21
22 use GCE::AttrTypemap;
23
24 use GCE::DragHelper;
25
26 use Glib::Object::Subclass
27 Gtk2::Window;
28
29 use strict;
30
31 sub INIT_INSTANCE {
32 my ($self) = @_;
33
34 $self->{earchs} = editor_archs ();
35
36 for (keys %{$self->{earchs}}) {
37
38 my @a = split /\//;
39 push @{$self->{toplevel_archs}->{$a[0]}}, @{$self->{earchs}->{$_}};
40 }
41
42 $self->set_title ("gce - picker");
43
44 $self->add (my $hb = Gtk2::VBox->new);
45
46 $hb->pack_start (my $cb = $self->{combo} = Gtk2::ComboBox->new_text, 0, 1, 0);
47
48 my $idx = 0;
49 for (sort keys %{$self->{toplevel_archs}}) {
50
51 $cb->append_text ($_);
52 $self->{arch_txt_to_idx}->{$_} = $idx++;
53 }
54
55 $cb->signal_connect (changed => sub {
56
57 my $arch = $cb->get_active_text;
58 $self->set_selection ($arch);
59 });
60
61 $hb->pack_start (my $map = $self->{map} = new Crossfire::MapWidget, 1, 1, 0);
62 # XXX: Doesn't work yet beacuse of tooltips
63 # GCE::DragHelper::set_drag_source (
64 # $map, arch => sub { { arch => $self->{last_pick} } }
65 # );
66
67 $map->set_size_request (TILESIZE * 10, TILESIZE * 10);
68
69 $map->signal_connect (button_press_event => sub {
70 my ($map, $event) = @_;
71
72 if ($event->button == 1) {
73
74 my ($mx, $my) = $map->coord ($event->x, $event->y);
75 my $as = $map->get ($mx, $my);
76
77 my $arch = $as->[-1]
78 or return;
79
80 if ($arch->{_virtual}) {
81 $arch = $arch->{_virtual};
82 }
83
84 $self->{last_pick} = $arch;
85
86 my $ar = GCE::ArchRef->new (arch => $arch);
87 $::MAINWIN->update_attr_editor ($ar);
88 $::MAINWIN->set_edit_tool ('place');
89
90 } elsif ($event->button == 3) {
91
92 my ($mx, $my) = $map->coord ($event->x, $event->y);
93 my $as = $map->get ($mx, $my);
94
95 my $arch = $as->[-1]
96 or return;
97
98 if ($arch->{_virtual}) {
99 $arch = $arch->{_virtual};
100 }
101
102 $self->do_context_menu ($map, $event, $arch);
103 }
104
105 #my $d = $map->disable_tooltip;
106
107 1
108 });
109
110 $map->signal_connect (button_release_event => sub {
111 my ($map, $event) = @_;
112
113 # $map->enable_tooltip;
114
115 1
116 });
117
118 }
119
120 sub do_context_menu {
121 my ($self, $map, $event, $arch) = @_;
122
123 my ($x, $y) = $map->coord ($event->x, $event->y);
124
125 my $menu = Gtk2::Menu->new;
126 foreach my $cm (
127 [
128 "Add to inventory" => sub {
129 my $pa = $::MAINWIN->{attr_edit}->get_arch;
130 $pa->add_inv ({ _name => $arch->{_name} }) if $pa;
131 }
132 ]
133 ) {
134 my $item = Gtk2::MenuItem->new ($cm->[0]);
135 $menu->append ($item);
136 $item->show;
137 $item->signal_connect (activate => $cm->[1]);
138 }
139 $menu->popup (undef, undef, undef, undef, $event->button, $event->time);
140 }
141
142 sub set_selection {
143 my ($self, $arch) = @_;
144
145 return unless defined $arch;
146
147 return unless defined $self->{toplevel_archs}->{$arch};
148
149 $self->{map}->set_map (
150 new_pickmap Crossfire::Map ($self->{toplevel_archs}->{$arch})
151 );
152 $self->{map}->enable_tooltip;
153
154 $self->{combo}->set_active ($self->{arch_txt_to_idx}->{$arch});
155
156 $self->{last_selection} = $arch;
157 }
158
159
160 =head1 AUTHOR
161
162 Marc Lehmann <schmorp@schmorp.de>
163 http://home.schmorp.de/
164
165 Robin Redeker <elmex@ta-sa.org>
166 http://www.ta-sa.org/
167
168 =cut
169 1;