ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/cfplus
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.149 by root, Thu Apr 12 07:53:31 2007 UTC vs.
Revision 1.167 by root, Fri Jul 13 05:31:32 2007 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3my $startup_done = sub { }; 3my $startup_done = sub { };
4our $PANGO = "1.5.0";
4 5
5# do splash-screen thingy on win32 6# do splash-screen thingy on win32
6BEGIN { 7BEGIN {
7 if (%PAR::LibCache && $^O eq "MSWin32") { 8 if (%PAR::LibCache && $^O eq "MSWin32") {
8 while (my ($filename, $zip) = each %PAR::LibCache) { 9 while (my ($filename, $zip) = each %PAR::LibCache) {
29# do things only needed for single-binary version (par) 30# do things only needed for single-binary version (par)
30BEGIN { 31BEGIN {
31 if (%PAR::LibCache) { 32 if (%PAR::LibCache) {
32 @INC = grep ref, @INC; # weed out all paths except pars loader refs 33 @INC = grep ref, @INC; # weed out all paths except pars loader refs
33 34
35 my $tmp = $ENV{PAR_TEMP};
36
34 while (my ($filename, $zip) = each %PAR::LibCache) { 37 while (my ($filename, $zip) = each %PAR::LibCache) {
35 for ($zip->memberNames) { 38 for ($zip->memberNames) {
36 next unless /^root\/(.*)/; 39 next unless /^root\/(.*)/;
37 $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1") 40 $zip->extractMember ($_, "$tmp/$1")
38 unless -e "$ENV{PAR_TEMP}/$1"; 41 unless -e "$tmp/$1";
39 } 42 }
40 } 43 }
41 44
42 # TODO: pango-rc file, anybody? 45 if ($^O eq "MSWin32") {
46 # relocatable
47 } else {
48 # unix, need to patch pango rc file
49 open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules"
50 or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!";
51 local $/;
52 my $rc = <$fh>;
53 $rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones
43 54
44 unshift @INC, $ENV{PAR_TEMP}; 55 mkdir "$tmp/pango-modules";
56 open my $fh, ">:perlio", "$tmp/pango-modules/pango.modules"
57 or die "$tmp/pango-modules/pango.modules: $!";
58 print $fh $rc;
59
60 $ENV{PANGO_RC_FILE} = "$tmp/pango.rc";
61 open my $fh, ">:perlio", $ENV{PANGO_RC_FILE}
62 or die "$ENV{PANGO_RC_FILE}: $!";
63 print $fh "[Pango]\nModuleFiles = $tmp/pango-modules\n";
64 }
65
66 unshift @INC, $tmp;
45 } 67 }
46} 68}
47 69
48# need to do it again because that pile of garbage called PAR nukes it before main 70# need to do it again because that pile of garbage called PAR nukes it before main
49unshift @INC, $ENV{PAR_TEMP} 71unshift @INC, $ENV{PAR_TEMP}
137 159
138our $SDL_ACTIVE; 160our $SDL_ACTIVE;
139our %SDL_CB; 161our %SDL_CB;
140 162
141our $SDL_MIXER; 163our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT;
166our $MUSIC_PLAYING;
167our $MUSIC_PLAYER;
142our @SOUNDS; # event => file mapping 168our @SOUNDS; # event => file mapping
143our %AUDIO_CHUNKS; # audio files 169our %AUDIO_CHUNKS; # audio files
144 170
145our $ALT_ENTER_MESSAGE; 171our $ALT_ENTER_MESSAGE;
146our $STATUSBOX; 172our $STATUSBOX;
207 title => "Server Query", 233 title => "Server Query",
208 child => my $vbox = new CFPlus::UI::VBox, 234 child => my $vbox = new CFPlus::UI::VBox,
209 ; 235 ;
210 236
211 my @dialog = my $label = new CFPlus::UI::Label 237 my @dialog = my $label = new CFPlus::UI::Label
212 max_w => $::WIDTH * 0.4, 238 max_w => $::WIDTH * 0.8,
213 ellipsise => 0, 239 ellipsise => 0,
214 text => $prompt; 240 text => $prompt;
215 241
216 if ($flags & CS_QUERY_YESNO) { 242 if ($flags & CS_QUERY_YESNO) {
217 push @dialog, my $hbox = new CFPlus::UI::HBox; 243 push @dialog, my $hbox = new CFPlus::UI::HBox;
234 ); 260 );
235 261
236 $dialog->grab_focus; 262 $dialog->grab_focus;
237 263
238 } elsif ($flags & CS_QUERY_SINGLECHAR) { 264 } elsif ($flags & CS_QUERY_SINGLECHAR) {
239 $dialog->{tooltip} = "#charcreation_focus";
240
241 if ($prompt =~ /Now choose a character|Press any key for the next race/i) { 265 if ($prompt =~ /Now choose a character|Press any key for the next race/i) {
242 $MESSAGE_WINDOW->show; 266 $dialog->{tooltip} = "#charcreation_focus";
243 267
244 unshift @dialog, new CFPlus::UI::Label 268 unshift @dialog, new CFPlus::UI::Label
245 max_w => $::WIDTH * 0.4, 269 max_w => $::WIDTH * 0.8,
246 ellipsise => 0, 270 ellipsise => 0,
247 markup => "\nOr use your keyboard and the text entry below:\n"; 271 markup => "\nOr use your keyboard and the text entry below:\n";
248 272
249 unshift @dialog, my $table = new CFPlus::UI::Table; 273 unshift @dialog, my $table = new CFPlus::UI::Table;
250 274
262 $conn->send ("reply d"); 286 $conn->send ("reply d");
263 destroy_query_dialog $conn; 287 destroy_query_dialog $conn;
264 0 288 0
265 }, 289 },
266 ); 290 );
291
292 if ($conn->{chargen_race_description}) {
293 unshift @dialog, new CFPlus::UI::Label
294 max_w => $::WIDTH * 0.8,
295 ellipsise => 0,
296 markup => "<span foreground='#ccccff'>$conn->{chargen_race_description}</span>",
297 ;
298 }
299
300 unshift @dialog, new CFPlus::UI::Face
301 face => $conn->{player}{face},
302 bg => [.2, .2, .2, 1],
303 min_w => 64,
304 min_h => 64,
305 ;
306
307 if ($conn->{chargen_race_title}) {
308 unshift @dialog, new CFPlus::UI::Label
309 allign => 1,
310 ellipsise => 0,
311 markup => "<span foreground='#ccccff' size='large'>Race: $conn->{chargen_race_title}</span>",
312 ;
313 }
267 314
268 unshift @dialog, new CFPlus::UI::Label 315 unshift @dialog, new CFPlus::UI::Label
269 max_w => $::WIDTH * 0.4, 316 max_w => $::WIDTH * 0.4,
270 ellipsise => 0, 317 ellipsise => 0,
271 markup => (CFPlus::Pod::section_label ui => "chargen_race"), 318 markup => (CFPlus::Pod::section_label ui => "chargen_race"),
453 $LOGIN_BUTTON->set_text ("Login"); 500 $LOGIN_BUTTON->set_text ("Login");
454 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); 501 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
455 $SETUP_DIALOG->show; 502 $SETUP_DIALOG->show;
456 $PL_WINDOW->hide; 503 $PL_WINDOW->hide;
457 $SPELL_LIST->clear_spells; 504 $SPELL_LIST->clear_spells;
505 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
506
507 &audio_music_set ([]);
458 508
459 return unless $CONN; 509 return unless $CONN;
460 510
461 status "connection closed"; 511 status "connection closed";
462 512
703 $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 }); 753 $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 });
704 $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS"); 754 $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS");
705 $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 }); 755 $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 });
706 $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips"); 756 $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips");
707 $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); 757 $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
708 $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { die "violator" } ); 758 $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
709 759
710 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05); 760 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05);
711 761
712 for my $x (0..2) { 762 for my $x (0..2) {
713 for my $y (0 .. 2) { 763 for my $y (0 .. 2) {
1411 has_close_button => 1 1461 has_close_button => 1
1412 ; 1462 ;
1413 1463
1414 my $ntb = 1464 my $ntb =
1415 $PL_NOTEBOOK = 1465 $PL_NOTEBOOK =
1416 new CFPlus::UI::Notebook expand => 1, debug => 1; 1466 new CFPlus::UI::Notebook expand => 1;
1417 1467
1418 $ntb->add ( 1468 $ntb->add (
1419 "Statistics (F2)" => $STATS_PAGE = stats_window, 1469 "Statistics (F2)" => $STATS_PAGE = stats_window,
1420 "Shows statistics, where all your Stats and Resistances are shown." 1470 "Shows statistics, where all your Stats and Resistances are shown."
1421 ); 1471 );
1433 $ntb->add ( 1483 $ntb->add (
1434 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1484 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1435 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1485 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1436 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1486 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1437 ); 1487 );
1488 $ntb->add (Pickup => autopickup_setup,
1489 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1438 1490
1439 $ntb->set_current_page ($INVENTORY_PAGE); 1491 $ntb->set_current_page ($INVENTORY_PAGE);
1440 1492
1441 $plwin->add ($ntb); 1493 $plwin->add ($ntb);
1442 $plwin 1494 $plwin
1769 1821
1770 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, 1822 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup,
1771 "Configure the server to play on, your username, password and other server-related options."); 1823 "Configure the server to play on, your username, password and other server-related options.");
1772 $SETUP_NOTEBOOK->add (Client => client_setup, 1824 $SETUP_NOTEBOOK->add (Client => client_setup,
1773 "Configure various client-specific settings."); 1825 "Configure various client-specific settings.");
1774 $SETUP_NOTEBOOK->add (Pickup => autopickup_setup,
1775 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1776 $SETUP_NOTEBOOK->add (Graphics => graphics_setup, 1826 $SETUP_NOTEBOOK->add (Graphics => graphics_setup,
1777 "Configure the video mode, performance, fonts and other graphical aspects of the game."); 1827 "Configure the video mode, performance, fonts and other graphical aspects of the game.");
1778 $SETUP_NOTEBOOK->add (Audio => audio_setup, 1828 $SETUP_NOTEBOOK->add (Audio => audio_setup,
1779 "Configure the use of audio, sound effects and background music."); 1829 "Configure the use of audio, sound effects and background music.");
1780 $SETUP_NOTEBOOK->add (Keyboard => $SETUP_KEYBOARD = keyboard_setup, 1830 $SETUP_NOTEBOOK->add (Keyboard => $SETUP_KEYBOARD = keyboard_setup,
1958 CFPlus::OpenGL::shutdown; 2008 CFPlus::OpenGL::shutdown;
1959 2009
1960 undef $SDL_ACTIVE; 2010 undef $SDL_ACTIVE;
1961} 2011}
1962 2012
1963my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
1964my $bgmusic;#TODO#hack#d#
1965
1966sub audio_channel_finished { 2013sub audio_channel_finished {
1967 my ($channel) = @_; 2014 my ($channel) = @_;
1968 2015
1969 #warn "channel $channel finished\n";#d# 2016 #warn "channel $channel finished\n";#d#
1970} 2017}
1971 2018
2019sub audio_music_set {
2020 my ($songs) = @_;
2021
2022 my $count = @$songs;
2023 my @meta;
2024
2025 for my $name (@$songs) {
2026 CFPlus::DB::get "res-metadata" => $name, sub {
2027 my ($data) = @_;
2028
2029 if ($data) {
2030 $data = JSON::XS->new->utf8->decode ($data);
2031 $data->{path} = CFPlus::DB::path_of $name;
2032 push @meta, $data;
2033 }
2034
2035 unless (--$count) {
2036 if (@meta) {
2037 @MUSIC_WANT = @meta;
2038 &audio_music_changed ();
2039 }
2040 }
2041 };
2042 }
2043}
2044
2045sub audio_music_changed {
2046 return unless $CFG->{bgm_enable};
2047
2048 # default MUSIC_WANT == MUSIC_DEFAULT
2049 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
2050
2051 # if the currently playing song is acceptable, let it continue
2052 return if $MUSIC_PLAYING
2053 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT;
2054
2055 if ($MUSIC_PLAYING) {
2056 CFPlus::MixMusic::fade_out 1000;
2057 } else {
2058 my $music = $MUSIC_WANT [rand @MUSIC_WANT];
2059
2060 $MUSIC_PLAYING = $music;
2061
2062 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $music->{path};
2063 $MUSIC_PLAYER->play (0);
2064 }
2065}
2066
1972sub audio_music_finished { 2067sub audio_music_finished {
1973 return unless $CFG->{bgm_enable}; 2068 $MUSIC_PLAYING = undef;
2069 undef $MUSIC_PLAYER;
1974 2070
1975 # TODO: hack, do play loop and mood music 2071 audio_music_changed;
1976 $bgmusic = new_from_file CFPlus::MixMusic CFPlus::find_rcfile "music/$bgmusic[0]";
1977 $bgmusic->play (0);
1978
1979 push @bgmusic, shift @bgmusic;
1980} 2072}
1981 2073
1982sub audio_init { 2074sub audio_init {
1983 if ($CFG->{audio_enable}) { 2075 if ($CFG->{audio_enable}) {
1984 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 2076 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
2079 if $CONN; 2171 if $CONN;
2080}); 2172});
2081 2173
2082%SDL_CB = ( 2174%SDL_CB = (
2083 CFPlus::SDL_QUIT => sub { 2175 CFPlus::SDL_QUIT => sub {
2084 Event::unloop -1; 2176 exit;
2085 }, 2177 },
2086 CFPlus::SDL_VIDEORESIZE => sub { 2178 CFPlus::SDL_VIDEORESIZE => sub {
2087 }, 2179 },
2088 CFPlus::SDL_VIDEOEXPOSE => sub { 2180 CFPlus::SDL_VIDEOEXPOSE => sub {
2089 CFPlus::UI::full_refresh; 2181 CFPlus::UI::full_refresh;
2234 2326
2235Event::loop; 2327Event::loop;
2236#CFPlus::SDL_Quit; 2328#CFPlus::SDL_Quit;
2237#CFPlus::_exit 0; 2329#CFPlus::_exit 0;
2238 2330
2331END {
2239END { CFPlus::SDL_Quit } 2332 CFPlus::SDL_Quit;
2333 CFPlus::DB::Server::stop;
2334}
2240 2335
2241=head1 NAME 2336=head1 NAME
2242 2337
2243cfplus - A Crossfire+ and Crossfire game client 2338cfplus - A Crossfire+ and Crossfire game client
2244 2339

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines