1 |
elmex |
1.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 |
elmex |
1.8 |
use Gtk2::SimpleMenu; |
12 |
elmex |
1.1 |
|
13 |
elmex |
1.2 |
use Crossfire; |
14 |
|
|
use Crossfire::MapWidget; |
15 |
elmex |
1.1 |
|
16 |
elmex |
1.8 |
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 |
elmex |
1.16 |
use GCE::DragHelper; |
25 |
|
|
|
26 |
elmex |
1.8 |
use Glib::Object::Subclass |
27 |
|
|
Gtk2::Window; |
28 |
|
|
|
29 |
|
|
use strict; |
30 |
elmex |
1.2 |
|
31 |
elmex |
1.8 |
sub INIT_INSTANCE { |
32 |
elmex |
1.4 |
my ($self) = @_; |
33 |
elmex |
1.3 |
|
34 |
elmex |
1.4 |
$self->{earchs} = editor_archs (); |
35 |
elmex |
1.1 |
|
36 |
elmex |
1.2 |
for (keys %{$self->{earchs}}) { |
37 |
elmex |
1.4 |
|
38 |
elmex |
1.2 |
my @a = split /\//; |
39 |
|
|
push @{$self->{toplevel_archs}->{$a[0]}}, @{$self->{earchs}->{$_}}; |
40 |
|
|
} |
41 |
|
|
|
42 |
elmex |
1.8 |
$self->set_title ("gce - picker"); |
43 |
elmex |
1.2 |
|
44 |
elmex |
1.8 |
$self->add (my $hb = Gtk2::VBox->new); |
45 |
elmex |
1.4 |
|
46 |
elmex |
1.13 |
$hb->pack_start (my $cb = $self->{combo} = Gtk2::ComboBox->new_text, 0, 1, 0); |
47 |
elmex |
1.4 |
|
48 |
elmex |
1.13 |
my $idx = 0; |
49 |
root |
1.6 |
for (sort keys %{$self->{toplevel_archs}}) { |
50 |
elmex |
1.5 |
|
51 |
root |
1.6 |
$cb->append_text ($_); |
52 |
elmex |
1.13 |
$self->{arch_txt_to_idx}->{$_} = $idx++; |
53 |
root |
1.6 |
} |
54 |
elmex |
1.4 |
|
55 |
root |
1.6 |
$cb->signal_connect (changed => sub { |
56 |
elmex |
1.4 |
|
57 |
root |
1.6 |
my $arch = $cb->get_active_text; |
58 |
elmex |
1.8 |
$self->set_selection ($arch); |
59 |
root |
1.6 |
}); |
60 |
elmex |
1.3 |
|
61 |
root |
1.6 |
$hb->pack_start (my $map = $self->{map} = new Crossfire::MapWidget, 1, 1, 0); |
62 |
elmex |
1.16 |
# XXX: Doesn't work yet beacuse of tooltips |
63 |
|
|
# GCE::DragHelper::set_drag_source ( |
64 |
|
|
# $map, arch => sub { { arch => $self->{last_pick} } } |
65 |
|
|
# ); |
66 |
elmex |
1.4 |
|
67 |
root |
1.6 |
$map->set_size_request (TILESIZE * 10, TILESIZE * 10); |
68 |
elmex |
1.4 |
|
69 |
root |
1.6 |
$map->signal_connect (button_press_event => sub { |
70 |
elmex |
1.16 |
my ($map, $event) = @_; |
71 |
elmex |
1.4 |
|
72 |
elmex |
1.8 |
if ($event->button == 3) { |
73 |
elmex |
1.4 |
|
74 |
root |
1.6 |
my ($mx, $my) = $map->coord ($event->x, $event->y); |
75 |
root |
1.7 |
my $as = $map->get ($mx, $my); |
76 |
elmex |
1.4 |
|
77 |
root |
1.7 |
my $arch = $as->[-1] |
78 |
root |
1.6 |
or return; |
79 |
elmex |
1.4 |
|
80 |
elmex |
1.15 |
$::MAINWIN->set_pick ($arch); |
81 |
|
|
$::MAINWIN->set_edit_tool ('place'); |
82 |
elmex |
1.4 |
|
83 |
root |
1.6 |
} elsif ($event->button == 1) { |
84 |
elmex |
1.4 |
|
85 |
root |
1.6 |
my ($mx, $my) = $map->coord ($event->x, $event->y); |
86 |
root |
1.7 |
my $as = $map->get ($mx, $my); |
87 |
elmex |
1.2 |
|
88 |
root |
1.7 |
my $arch = $as->[-1] |
89 |
root |
1.6 |
or return; |
90 |
|
|
|
91 |
elmex |
1.11 |
if ($arch->{_virtual}) { |
92 |
|
|
$arch = $arch->{_virtual}; |
93 |
|
|
} |
94 |
|
|
|
95 |
elmex |
1.16 |
$self->{last_pick} = $arch; |
96 |
root |
1.10 |
$::MAINWIN->set_pick ($arch); |
97 |
elmex |
1.15 |
$::MAINWIN->update_attr_editor ($arch); |
98 |
elmex |
1.12 |
$::MAINWIN->set_edit_tool ('place'); |
99 |
root |
1.6 |
} |
100 |
elmex |
1.16 |
|
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 |
root |
1.6 |
}); |
113 |
elmex |
1.16 |
|
114 |
elmex |
1.8 |
} |
115 |
|
|
|
116 |
|
|
sub set_selection { |
117 |
|
|
my ($self, $arch) = @_; |
118 |
|
|
|
119 |
|
|
return unless defined $arch; |
120 |
|
|
|
121 |
elmex |
1.18 |
return unless defined $self->{toplevel_archs}->{$arch}; |
122 |
|
|
|
123 |
elmex |
1.8 |
$self->{map}->set_map ( |
124 |
elmex |
1.18 |
new_pickmap Crossfire::Map ($self->{toplevel_archs}->{$arch}) |
125 |
elmex |
1.8 |
); |
126 |
elmex |
1.16 |
$self->{map}->enable_tooltip; |
127 |
elmex |
1.8 |
|
128 |
elmex |
1.13 |
$self->{combo}->set_active ($self->{arch_txt_to_idx}->{$arch}); |
129 |
|
|
|
130 |
elmex |
1.8 |
$self->{last_selection} = $arch; |
131 |
elmex |
1.1 |
} |
132 |
|
|
|
133 |
elmex |
1.2 |
|
134 |
elmex |
1.1 |
=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; |