1 |
elmex |
1.1 |
|
2 |
|
|
package GCE::PickWindow; |
3 |
|
|
|
4 |
|
|
=head1 NAME |
5 |
|
|
|
6 |
|
|
GCE::PickWindow - the arch picker window class for gce |
7 |
|
|
|
8 |
|
|
=cut |
9 |
|
|
|
10 |
elmex |
1.2 |
use strict; |
11 |
elmex |
1.1 |
use Gtk2; |
12 |
|
|
use Gtk2::Gdk::Keysyms; |
13 |
|
|
|
14 |
elmex |
1.2 |
use Crossfire; |
15 |
|
|
use Crossfire::MapWidget; |
16 |
elmex |
1.1 |
|
17 |
elmex |
1.2 |
sub new { |
18 |
|
|
my $class = shift; |
19 |
|
|
my $self = { @_ }; |
20 |
|
|
bless $self, $class; |
21 |
|
|
return $self; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
sub init { |
25 |
elmex |
1.4 |
my ($self) = @_; |
26 |
elmex |
1.3 |
|
27 |
elmex |
1.4 |
$self->{earchs} = editor_archs (); |
28 |
elmex |
1.1 |
|
29 |
elmex |
1.2 |
for (keys %{$self->{earchs}}) { |
30 |
elmex |
1.4 |
|
31 |
elmex |
1.2 |
my @a = split /\//; |
32 |
|
|
push @{$self->{toplevel_archs}->{$a[0]}}, @{$self->{earchs}->{$_}}; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
my $w = $self->{w} = Gtk2::Window->new ('toplevel'); |
36 |
elmex |
1.3 |
$w->set_title ("gce - picker"); |
37 |
elmex |
1.2 |
|
38 |
|
|
$w->add (my $hb = Gtk2::VBox->new); |
39 |
elmex |
1.4 |
|
40 |
elmex |
1.2 |
$hb->pack_start (my $cb = Gtk2::ComboBox->new_text, 0, 1, 0); |
41 |
elmex |
1.4 |
|
42 |
elmex |
1.2 |
for (sort keys %{$self->{toplevel_archs}}) { |
43 |
elmex |
1.5 |
|
44 |
elmex |
1.2 |
$cb->append_text ($_); |
45 |
|
|
} |
46 |
elmex |
1.4 |
|
47 |
elmex |
1.2 |
$cb->signal_connect (changed => sub { |
48 |
elmex |
1.4 |
|
49 |
elmex |
1.2 |
my $arch = $cb->get_active_text; |
50 |
elmex |
1.4 |
$self->{map}->set_map ( |
51 |
|
|
arch2pickmap |
52 |
|
|
sort { |
53 |
|
|
${$a}->{_name} cmp ${$b}->{_name} |
54 |
|
|
} $self->{toplevel_archs}->{$arch} |
55 |
|
|
); |
56 |
elmex |
1.5 |
|
57 |
|
|
$self->{map}->enable_tooltip; |
58 |
elmex |
1.2 |
}); |
59 |
elmex |
1.3 |
|
60 |
elmex |
1.4 |
$hb->pack_start (my $map = $self->{map} = new Crossfire::MapWidget, 1, 1, 0); |
61 |
|
|
$map->signal_connect (button_press_event => sub { |
62 |
|
|
my ($f, $event) = @_; |
63 |
|
|
|
64 |
|
|
if ($event->button == 1 && $event->state & "shift-mask") { |
65 |
|
|
|
66 |
|
|
my ($mx, $my) = $map->coord ($event->x, $event->y); |
67 |
|
|
my $s = map_get_tile_stack ($map, $mx, $my); |
68 |
|
|
|
69 |
|
|
my $arch = $s->[-1] |
70 |
|
|
or return; |
71 |
|
|
|
72 |
|
|
$self->{arch_edit_cb} and $self->{arch_edit_cb}->($arch); |
73 |
|
|
|
74 |
|
|
} elsif ($event->button == 1) { |
75 |
|
|
|
76 |
|
|
my ($mx, $my) = $map->coord ($event->x, $event->y); |
77 |
|
|
my $s = map_get_tile_stack ($map, $mx, $my); |
78 |
|
|
|
79 |
|
|
my $arch = $s->[-1] |
80 |
|
|
or return; |
81 |
|
|
|
82 |
|
|
$self->{set_sel_cb} and $self->{set_sel_cb}->($arch); |
83 |
|
|
} |
84 |
elmex |
1.3 |
}); |
85 |
elmex |
1.2 |
|
86 |
|
|
|
87 |
|
|
$w->show_all; |
88 |
elmex |
1.1 |
} |
89 |
|
|
|
90 |
elmex |
1.2 |
|
91 |
elmex |
1.1 |
=head1 AUTHOR |
92 |
|
|
|
93 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
94 |
|
|
http://home.schmorp.de/ |
95 |
|
|
|
96 |
|
|
Robin Redeker <elmex@ta-sa.org> |
97 |
|
|
http://www.ta-sa.org/ |
98 |
|
|
|
99 |
|
|
=cut |
100 |
|
|
1; |