ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.23
Committed: Sun Feb 11 09:30:11 2007 UTC (17 years, 5 months ago) by elmex
Branch: MAIN
CVS Tags: rel-2_0, rel-2_1
Changes since 1.22: +0 -1 lines
Log Message:
no change

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