1 |
elmex |
1.1 |
package GCE::MainWindow; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::MainWindow - the main window class for gce |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
elmex |
1.2 |
use Gtk2::SimpleMenu; |
12 |
root |
1.7 |
|
13 |
|
|
use Crossfire; |
14 |
|
|
use Crossfire::MapWidget; |
15 |
|
|
|
16 |
elmex |
1.2 |
use GCE::AttrEdit; |
17 |
elmex |
1.13 |
use GCE::MapEditor; |
18 |
elmex |
1.2 |
|
19 |
elmex |
1.14 |
use GCE::AttrTypemap; |
20 |
|
|
|
21 |
elmex |
1.2 |
use Glib::Object::Subclass |
22 |
elmex |
1.13 |
Gtk2::Window; |
23 |
elmex |
1.2 |
|
24 |
|
|
use strict; |
25 |
|
|
|
26 |
elmex |
1.13 |
sub open_pick_window { |
27 |
|
|
my ($self) = @_; |
28 |
elmex |
1.10 |
|
29 |
elmex |
1.13 |
my $p = GCE::PickWindow->new ( |
30 |
|
|
set_sel_cb => sub { |
31 |
elmex |
1.10 |
|
32 |
elmex |
1.13 |
$self->{mapedit}->update_pick ($_[0]) |
33 |
|
|
}, |
34 |
|
|
arch_edit_cb => sub { |
35 |
elmex |
1.10 |
|
36 |
elmex |
1.14 |
$self->{mapedit}->update_attr_editor ($_[0], 1) |
37 |
elmex |
1.13 |
} |
38 |
|
|
); |
39 |
|
|
$p->init; |
40 |
elmex |
1.10 |
} |
41 |
|
|
|
42 |
elmex |
1.13 |
sub build_menu { |
43 |
elmex |
1.1 |
my ($self) = @_; |
44 |
|
|
|
45 |
elmex |
1.2 |
my $menu_tree = [ |
46 |
|
|
_File => { |
47 |
|
|
item_type => '<Branch>', |
48 |
|
|
children => [ |
49 |
|
|
_New => { |
50 |
|
|
callback => sub { $self->new_cb }, |
51 |
|
|
accelerator => '<ctrl>N' |
52 |
|
|
}, |
53 |
|
|
_Open => { |
54 |
|
|
callback => sub { $self->open_cb }, |
55 |
|
|
accelerator => '<ctrl>O' |
56 |
|
|
}, |
57 |
|
|
_Quit => { |
58 |
|
|
callback => sub { Gtk2->main_quit }, |
59 |
|
|
accelerator => '<ctrl>Q' |
60 |
|
|
} |
61 |
|
|
] |
62 |
|
|
}, |
63 |
|
|
_Edit => { |
64 |
|
|
item_type => '<Branch>', |
65 |
|
|
children => [ |
66 |
elmex |
1.13 |
_Fill => { |
67 |
|
|
callback => sub { die "NO IMPL" }, |
68 |
|
|
accelerator => "<ctrl>F" |
69 |
|
|
}, |
70 |
|
|
"Clear _Top" => { |
71 |
|
|
callback => sub { die "NO IMPL" }, |
72 |
|
|
accelerator => "<ctrl>T" |
73 |
elmex |
1.2 |
}, |
74 |
|
|
"_Clear All" => { |
75 |
elmex |
1.13 |
callback => sub { die "NO IMPL" }, |
76 |
|
|
accelerator => "<ctrl>X" |
77 |
elmex |
1.2 |
}, |
78 |
elmex |
1.9 |
"Open _Picker" => { |
79 |
elmex |
1.13 |
callback => sub { $self->open_pick_window }, |
80 |
|
|
accelerator => "<ctrl>P" |
81 |
elmex |
1.9 |
}, |
82 |
elmex |
1.2 |
] |
83 |
elmex |
1.9 |
} |
84 |
elmex |
1.2 |
]; |
85 |
|
|
|
86 |
elmex |
1.13 |
my $men = |
87 |
|
|
Gtk2::SimpleMenu->new ( |
88 |
|
|
menu_tree => $menu_tree, |
89 |
|
|
default_callback => \&default_cb, |
90 |
|
|
); |
91 |
elmex |
1.10 |
|
92 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
93 |
|
|
|
94 |
elmex |
1.13 |
return $men->{widget}; |
95 |
|
|
} |
96 |
elmex |
1.10 |
|
97 |
|
|
|
98 |
root |
1.11 |
|
99 |
elmex |
1.13 |
sub INIT_INSTANCE { |
100 |
|
|
my ($self) = @_; |
101 |
elmex |
1.10 |
|
102 |
elmex |
1.13 |
$self->set_title ("gce - main window"); |
103 |
elmex |
1.10 |
|
104 |
elmex |
1.13 |
$self->add (my $vb = Gtk2::VBox->new); |
105 |
|
|
$vb->pack_start ($self->build_menu, 0, 1, 0); |
106 |
|
|
$vb->pack_start (my $mapedit = $self->{mapedit} = new GCE::MapEditor, 1, 1, 0); |
107 |
elmex |
1.10 |
|
108 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
109 |
|
|
$mapedit->open_map ($ARGV[0] || "$Crossfire::LIB/maps/dragonisland/advguild3"); |
110 |
root |
1.11 |
|
111 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
112 |
|
|
Gtk2->main_quit; |
113 |
elmex |
1.10 |
}); |
114 |
elmex |
1.2 |
} |
115 |
|
|
|
116 |
|
|
sub new_cb { |
117 |
|
|
my ($self) = @_; |
118 |
|
|
die "NOT IMPLEMENTED YET"; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
sub open_cb { |
122 |
|
|
my ($self) = @_; |
123 |
|
|
|
124 |
elmex |
1.13 |
my $fc = |
125 |
|
|
Gtk2::FileChooserDialog->new ( |
126 |
|
|
'gce - open map', undef, 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
127 |
|
|
); |
128 |
|
|
|
129 |
elmex |
1.2 |
$fc->add_shortcut_folder ("$Crossfire::LIB/maps"); |
130 |
elmex |
1.13 |
$fc->add_shortcut_folder ($_) for keys %{$self->{fc_last_folders}}; |
131 |
elmex |
1.10 |
$fc->set_current_folder ($self->{fc_last_folder} || "$Crossfire::LIB/maps"); |
132 |
elmex |
1.2 |
|
133 |
|
|
if ('ok' eq $fc->run) { |
134 |
elmex |
1.13 |
|
135 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
136 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
137 |
|
|
$self->{mapedit}->open_map ($fc->get_filename); |
138 |
elmex |
1.2 |
} |
139 |
|
|
|
140 |
|
|
$fc->destroy; |
141 |
|
|
} |
142 |
|
|
|
143 |
elmex |
1.1 |
=head1 AUTHOR |
144 |
|
|
|
145 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
146 |
|
|
http://home.schmorp.de/ |
147 |
|
|
|
148 |
|
|
Robin Redeker <elmex@ta-sa.org> |
149 |
|
|
http://www.ta-sa.org/ |
150 |
|
|
|
151 |
|
|
=cut |
152 |
|
|
1; |
153 |
|
|
|