ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.22
Committed: Tue Dec 5 15:00:32 2006 UTC (17 years, 6 months ago) by elmex
Branch: MAIN
Changes since 1.21: +0 -2 lines
Log Message:
Some cleanup of old unused files and a bugfix in layout saving when no
map window was open yet.

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