ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.18
Committed: Sun Apr 2 10:58:52 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.17: +3 -1 lines
Log Message:
changed map navigation to cursor keys and made active tab stay the same on object switch in attreditor

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 == 3) {
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 $::MAINWIN->set_pick ($arch);
81 $::MAINWIN->set_edit_tool ('place');
82
83 } elsif ($event->button == 1) {
84
85 my ($mx, $my) = $map->coord ($event->x, $event->y);
86 my $as = $map->get ($mx, $my);
87
88 my $arch = $as->[-1]
89 or return;
90
91 if ($arch->{_virtual}) {
92 $arch = $arch->{_virtual};
93 }
94
95 $self->{last_pick} = $arch;
96 $::MAINWIN->set_pick ($arch);
97 $::MAINWIN->update_attr_editor ($arch);
98 $::MAINWIN->set_edit_tool ('place');
99 }
100
101 #my $d = $map->disable_tooltip;
102
103 1
104 });
105
106 $map->signal_connect (button_release_event => sub {
107 my ($map, $event) = @_;
108
109 # $map->enable_tooltip;
110
111 1
112 });
113
114 }
115
116 sub set_selection {
117 my ($self, $arch) = @_;
118
119 return unless defined $arch;
120
121 return unless defined $self->{toplevel_archs}->{$arch};
122
123 $self->{map}->set_map (
124 new_pickmap Crossfire::Map ($self->{toplevel_archs}->{$arch})
125 );
126 $self->{map}->enable_tooltip;
127
128 $self->{combo}->set_active ($self->{arch_txt_to_idx}->{$arch});
129
130 $self->{last_selection} = $arch;
131 }
132
133
134 =head1 AUTHOR
135
136 Marc Lehmann <schmorp@schmorp.de>
137 http://home.schmorp.de/
138
139 Robin Redeker <elmex@ta-sa.org>
140 http://www.ta-sa.org/
141
142 =cut
143 1;