ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.4
Committed: Wed Feb 8 16:46:16 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.3: +37 -24 lines
Log Message:
reworked/restructured the code a little bit

File Contents

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