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 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 |
|
61 |
$map->set_size_request (TILESIZE * 10, TILESIZE * 10); |
62 |
|
63 |
$map->signal_connect (button_press_event => sub { |
64 |
my ($f, $event) = @_; |
65 |
|
66 |
if ($event->button == 3) { |
67 |
|
68 |
my ($mx, $my) = $map->coord ($event->x, $event->y); |
69 |
my $as = $map->get ($mx, $my); |
70 |
|
71 |
my $arch = $as->[-1] |
72 |
or return; |
73 |
|
74 |
$::MAINWIN->update_attr_editor ($arch); |
75 |
|
76 |
} elsif ($event->button == 1) { |
77 |
|
78 |
my ($mx, $my) = $map->coord ($event->x, $event->y); |
79 |
my $as = $map->get ($mx, $my); |
80 |
|
81 |
my $arch = $as->[-1] |
82 |
or return; |
83 |
|
84 |
if ($arch->{_virtual}) { |
85 |
$arch = $arch->{_virtual}; |
86 |
} |
87 |
|
88 |
$::MAINWIN->set_pick ($arch); |
89 |
$::MAINWIN->set_edit_tool ('place'); |
90 |
} |
91 |
}); |
92 |
} |
93 |
|
94 |
sub set_selection { |
95 |
my ($self, $arch) = @_; |
96 |
|
97 |
return unless defined $arch; |
98 |
|
99 |
$self->{map}->set_map ( |
100 |
new_pickmap Crossfire::Map $self->{toplevel_archs}->{$arch} |
101 |
); |
102 |
|
103 |
$self->{combo}->set_active ($self->{arch_txt_to_idx}->{$arch}); |
104 |
|
105 |
$self->{last_selection} = $arch; |
106 |
|
107 |
$self->{map}->enable_tooltip; |
108 |
|
109 |
} |
110 |
|
111 |
|
112 |
=head1 AUTHOR |
113 |
|
114 |
Marc Lehmann <schmorp@schmorp.de> |
115 |
http://home.schmorp.de/ |
116 |
|
117 |
Robin Redeker <elmex@ta-sa.org> |
118 |
http://www.ta-sa.org/ |
119 |
|
120 |
=cut |
121 |
1; |