| 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.15 |
use GCE::StackView; |
| 19 |
elmex |
1.2 |
|
| 20 |
elmex |
1.14 |
use GCE::AttrTypemap; |
| 21 |
|
|
|
| 22 |
elmex |
1.2 |
use Glib::Object::Subclass |
| 23 |
elmex |
1.13 |
Gtk2::Window; |
| 24 |
elmex |
1.2 |
|
| 25 |
|
|
use strict; |
| 26 |
|
|
|
| 27 |
elmex |
1.15 |
our $MAINWIN; |
| 28 |
|
|
|
| 29 |
|
|
sub test_stack_view { |
| 30 |
|
|
my ($self) = @_; |
| 31 |
|
|
|
| 32 |
|
|
return if defined $self->{sv}; |
| 33 |
|
|
|
| 34 |
|
|
my $w = Gtk2::Window->new ('toplevel'); |
| 35 |
|
|
$w->set_title ('gce - stack view'); |
| 36 |
|
|
$w->signal_connect ('delete-event' => sub { $self->{sv} = undef; }); |
| 37 |
|
|
$w->add ($self->{sv} = GCE::StackView->new); |
| 38 |
|
|
$w->show_all; |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
sub show_attr_editor { |
| 42 |
|
|
my ($self) = @_; |
| 43 |
|
|
|
| 44 |
|
|
my $w = $self->{attr_edit_win} = Gtk2::Window->new; |
| 45 |
|
|
$w->set_title ("gce - edit attrs"); |
| 46 |
|
|
$w->add ($self->{attr_edit} = GCE::AttrEdit->new); |
| 47 |
|
|
$w->signal_connect ('delete-event' => sub { delete $self->{attr_edit}; 0 }); |
| 48 |
|
|
$w->show_all; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
sub update_attr_editor { |
| 52 |
|
|
my ($self, $arch, $ro) = @_; |
| 53 |
|
|
|
| 54 |
|
|
return unless $self->{attr_edit}; |
| 55 |
|
|
|
| 56 |
|
|
$self->{attr_edit}->set_arch ($arch, $ro); |
| 57 |
|
|
$self->{attr_edit_win}->set_title ("gce - edit $arch->{_name}"); |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
sub update_stack_view { |
| 61 |
|
|
my ($self, $mapedit, $stack, $x, $y) = @_; |
| 62 |
|
|
|
| 63 |
|
|
return unless $self->{sv}; |
| 64 |
|
|
|
| 65 |
|
|
$self->{sv}->set_stack ($mapedit, $stack, $x, $y); |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
|
#XXX: Soon we want to handle multiple maps! |
| 69 |
|
|
#XXX: Refactor this to MapEditor?? |
| 70 |
|
|
sub change_map_tile { |
| 71 |
|
|
my ($self, $mapedit, $x, $y, $newstack, $oldstack) = @_; |
| 72 |
|
|
|
| 73 |
root |
1.16 |
$mapedit->{map}->set ($x, $y, $newstack); |
| 74 |
elmex |
1.15 |
} |
| 75 |
|
|
|
| 76 |
elmex |
1.13 |
sub open_pick_window { |
| 77 |
|
|
my ($self) = @_; |
| 78 |
elmex |
1.10 |
|
| 79 |
elmex |
1.13 |
my $p = GCE::PickWindow->new ( |
| 80 |
|
|
set_sel_cb => sub { |
| 81 |
elmex |
1.10 |
|
| 82 |
elmex |
1.13 |
$self->{mapedit}->update_pick ($_[0]) |
| 83 |
|
|
}, |
| 84 |
|
|
arch_edit_cb => sub { |
| 85 |
elmex |
1.10 |
|
| 86 |
elmex |
1.15 |
$self->update_attr_editor ($_[0], 1) |
| 87 |
elmex |
1.13 |
} |
| 88 |
|
|
); |
| 89 |
|
|
$p->init; |
| 90 |
elmex |
1.10 |
} |
| 91 |
|
|
|
| 92 |
elmex |
1.13 |
sub build_menu { |
| 93 |
elmex |
1.1 |
my ($self) = @_; |
| 94 |
|
|
|
| 95 |
elmex |
1.2 |
my $menu_tree = [ |
| 96 |
|
|
_File => { |
| 97 |
|
|
item_type => '<Branch>', |
| 98 |
|
|
children => [ |
| 99 |
|
|
_New => { |
| 100 |
|
|
callback => sub { $self->new_cb }, |
| 101 |
|
|
accelerator => '<ctrl>N' |
| 102 |
|
|
}, |
| 103 |
|
|
_Open => { |
| 104 |
|
|
callback => sub { $self->open_cb }, |
| 105 |
|
|
accelerator => '<ctrl>O' |
| 106 |
|
|
}, |
| 107 |
|
|
_Quit => { |
| 108 |
|
|
callback => sub { Gtk2->main_quit }, |
| 109 |
|
|
accelerator => '<ctrl>Q' |
| 110 |
|
|
} |
| 111 |
|
|
] |
| 112 |
|
|
}, |
| 113 |
|
|
_Edit => { |
| 114 |
|
|
item_type => '<Branch>', |
| 115 |
|
|
children => [ |
| 116 |
elmex |
1.13 |
_Fill => { |
| 117 |
|
|
callback => sub { die "NO IMPL" }, |
| 118 |
|
|
accelerator => "<ctrl>F" |
| 119 |
|
|
}, |
| 120 |
|
|
"Clear _Top" => { |
| 121 |
|
|
callback => sub { die "NO IMPL" }, |
| 122 |
|
|
accelerator => "<ctrl>T" |
| 123 |
elmex |
1.2 |
}, |
| 124 |
|
|
"_Clear All" => { |
| 125 |
elmex |
1.13 |
callback => sub { die "NO IMPL" }, |
| 126 |
|
|
accelerator => "<ctrl>X" |
| 127 |
elmex |
1.2 |
}, |
| 128 |
elmex |
1.15 |
"Open _Attr Editor" => { |
| 129 |
|
|
callback => sub { $self->show_attr_editor }, |
| 130 |
|
|
accelerator => "<ctrl>A" |
| 131 |
|
|
}, |
| 132 |
elmex |
1.9 |
"Open _Picker" => { |
| 133 |
elmex |
1.13 |
callback => sub { $self->open_pick_window }, |
| 134 |
|
|
accelerator => "<ctrl>P" |
| 135 |
elmex |
1.9 |
}, |
| 136 |
elmex |
1.15 |
"Open _Stack View" => { |
| 137 |
|
|
callback => sub { $self->test_stack_view }, |
| 138 |
|
|
accelerator => "<ctrl>V" |
| 139 |
|
|
}, |
| 140 |
|
|
|
| 141 |
elmex |
1.2 |
] |
| 142 |
elmex |
1.9 |
} |
| 143 |
elmex |
1.2 |
]; |
| 144 |
|
|
|
| 145 |
elmex |
1.13 |
my $men = |
| 146 |
|
|
Gtk2::SimpleMenu->new ( |
| 147 |
|
|
menu_tree => $menu_tree, |
| 148 |
|
|
default_callback => \&default_cb, |
| 149 |
|
|
); |
| 150 |
elmex |
1.10 |
|
| 151 |
elmex |
1.2 |
$self->add_accel_group ($men->{accel_group}); |
| 152 |
|
|
|
| 153 |
elmex |
1.13 |
return $men->{widget}; |
| 154 |
|
|
} |
| 155 |
elmex |
1.10 |
|
| 156 |
|
|
|
| 157 |
root |
1.11 |
|
| 158 |
elmex |
1.13 |
sub INIT_INSTANCE { |
| 159 |
|
|
my ($self) = @_; |
| 160 |
elmex |
1.10 |
|
| 161 |
elmex |
1.15 |
$MAINWIN = $self; |
| 162 |
|
|
|
| 163 |
elmex |
1.13 |
$self->set_title ("gce - main window"); |
| 164 |
elmex |
1.10 |
|
| 165 |
elmex |
1.13 |
$self->add (my $vb = Gtk2::VBox->new); |
| 166 |
|
|
$vb->pack_start ($self->build_menu, 0, 1, 0); |
| 167 |
elmex |
1.15 |
|
| 168 |
elmex |
1.13 |
$vb->pack_start (my $mapedit = $self->{mapedit} = new GCE::MapEditor, 1, 1, 0); |
| 169 |
elmex |
1.10 |
|
| 170 |
elmex |
1.13 |
# XXX:load $ARGV _cleanly_? |
| 171 |
|
|
$mapedit->open_map ($ARGV[0] || "$Crossfire::LIB/maps/dragonisland/advguild3"); |
| 172 |
root |
1.11 |
|
| 173 |
elmex |
1.13 |
$self->signal_connect ('delete-event' => sub { |
| 174 |
|
|
Gtk2->main_quit; |
| 175 |
elmex |
1.10 |
}); |
| 176 |
elmex |
1.2 |
} |
| 177 |
|
|
|
| 178 |
|
|
sub new_cb { |
| 179 |
|
|
my ($self) = @_; |
| 180 |
|
|
die "NOT IMPLEMENTED YET"; |
| 181 |
|
|
} |
| 182 |
|
|
|
| 183 |
|
|
sub open_cb { |
| 184 |
|
|
my ($self) = @_; |
| 185 |
|
|
|
| 186 |
elmex |
1.13 |
my $fc = |
| 187 |
|
|
Gtk2::FileChooserDialog->new ( |
| 188 |
|
|
'gce - open map', undef, 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok' |
| 189 |
|
|
); |
| 190 |
|
|
|
| 191 |
elmex |
1.2 |
$fc->add_shortcut_folder ("$Crossfire::LIB/maps"); |
| 192 |
elmex |
1.13 |
$fc->add_shortcut_folder ($_) for keys %{$self->{fc_last_folders}}; |
| 193 |
elmex |
1.10 |
$fc->set_current_folder ($self->{fc_last_folder} || "$Crossfire::LIB/maps"); |
| 194 |
elmex |
1.2 |
|
| 195 |
|
|
if ('ok' eq $fc->run) { |
| 196 |
elmex |
1.13 |
|
| 197 |
elmex |
1.10 |
$self->{fc_last_folder} = $fc->get_current_folder; |
| 198 |
elmex |
1.13 |
$self->{fc_last_folders}->{$self->{fc_last_folder}}++; |
| 199 |
|
|
$self->{mapedit}->open_map ($fc->get_filename); |
| 200 |
elmex |
1.2 |
} |
| 201 |
|
|
|
| 202 |
|
|
$fc->destroy; |
| 203 |
|
|
} |
| 204 |
|
|
|
| 205 |
elmex |
1.1 |
=head1 AUTHOR |
| 206 |
|
|
|
| 207 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
| 208 |
|
|
http://home.schmorp.de/ |
| 209 |
|
|
|
| 210 |
|
|
Robin Redeker <elmex@ta-sa.org> |
| 211 |
|
|
http://www.ta-sa.org/ |
| 212 |
|
|
|
| 213 |
|
|
=cut |
| 214 |
|
|
1; |
| 215 |
|
|
|