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.198 by root, Tue Jul 31 02:45:39 2007 UTC vs.
Revision 1.203 by root, Mon Aug 6 02:11:45 2007 UTC

144our $SETUP_KEYBOARD; 144our $SETUP_KEYBOARD;
145 145
146our $PL_NOTEBOOK; 146our $PL_NOTEBOOK;
147our $PL_WINDOW; 147our $PL_WINDOW;
148 148
149our $MUSIC_PLAYING_WIDGET;
150our $LICENSE_WIDGET;
151
149our $INVENTORY_PAGE; 152our $INVENTORY_PAGE;
150our $STATS_PAGE; 153our $STATS_PAGE;
151our $SKILL_PAGE; 154our $SKILL_PAGE;
152our $SPELL_PAGE; 155our $SPELL_PAGE;
153our $SPELL_LIST; 156our $SPELL_LIST;
211} 214}
212 215
213sub audio_sound_push($) { 216sub audio_sound_push($) {
214 my ($face) = @_; 217 my ($face) = @_;
215 218
219 $CFG->{effects_enable}
220 or return;
221
216 if (my $chunk = $AUDIO_CHUNK{$face}) { 222 if (my $chunk = $AUDIO_CHUNK{$face}) {
217 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
218 my (undef, $dx, $dy, $vol) = @$_; 224 my (undef, $dx, $dy, $vol) = @$_;
219 225
220 my $channel = CFPlus::Channel::find; 226 my $channel = CFPlus::Channel::find;
221 $channel->volume ($vol * 128 / 255); 227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
222 $dx = $dx / 10 * 255; 228 $dx = $dx / 10 * 255;
223 $channel->set_panning (255 - $dx, 255 + $dx); 229 $channel->set_panning (255 - $dx, 255 + $dx);
224 230
225# my $angle = $dx ? : $dx < 0 ? 231# my $angle = $dx ? : $dx < 0 ?
226# my $distance = -$vol; 232# my $distance = -$vol;
233 my $meta = $CONN->{sound_meta}{$face} 239 my $meta = $CONN->{sound_meta}{$face}
234 or return; 240 or return;
235 241
236 # if its a jingle, play it as ambient music 242 # if its a jingle, play it as ambient music
237 if ($meta->{meta}{jingle}) { 243 if ($meta->{meta}{jingle}) {
238 delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue 244 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
239 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 245 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
240 &audio_music_push ($face); 246 &audio_music_push ($face);
247 }
241 } else { 248 } else {
242 # fetch from database 249 # fetch from database
243 CFPlus::DB::get res_data => $meta->{name}, sub { 250 CFPlus::DB::get res_data => $meta->{name}, sub {
244 my $rwops = new CFPlus::RW $_[0]; 251 my $rwops = new CFPlus::RW $_[0];
245 my $chunk = new CFPlus::MixChunk $rwops; 252 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
246 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 254 $chunk->volume (($meta->{meta}{volume} || 1) * 128);
247 $AUDIO_CHUNK{$face} = $chunk; 255 $AUDIO_CHUNK{$face} = $chunk;
248 256
249 audio_sound_push ($face); 257 audio_sound_push ($face);
250 }; 258 };
255sub audio_sound_play { 263sub audio_sound_play {
256 my ($face, $dx, $dy, $vol) = @_; 264 my ($face, $dx, $dy, $vol) = @_;
257 265
258 $SDL_MIXER 266 $SDL_MIXER
259 or return; 267 or return;
268 $CFG->{effects_enable}
269 or return;
260 270
261 my $queue = $AUDIO_PLAY{$face} ||= []; 271 my $queue = $AUDIO_PLAY{$face} ||= [];
262 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 272 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
263 audio_sound_push $face 273 audio_sound_push $face
264 unless @$queue > 1; 274 unless @$queue > 1;
275}
276
277sub audio_music_set_meta {
278 my ($meta) = @_;
279
280 $MUSIC_PLAYING_META = $meta;
281 $MUSIC_PLAYING_WIDGET->set_markup (
282 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n"
283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n"
284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n"
285 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license})
286 );
265} 287}
266 288
267sub audio_music_update_volume { 289sub audio_music_update_volume {
268 return unless $MUSIC_PLAYING_META; 290 return unless $MUSIC_PLAYING_META;
269 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 291 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
288 my $rwops = $meta->{path} 310 my $rwops = $meta->{path}
289 ? new_from_file CFPlus::RW $meta->{path} 311 ? new_from_file CFPlus::RW $meta->{path}
290 : new CFPlus::RW $$MUSIC_PLAYING_DATA; 312 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
291 313
292 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops 314 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
293 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error 315 or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
294 316
295 my $NOW = time; 317 my $NOW = time;
296 318
297 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 319 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
298 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 320 my $pos = $MUSIC_PLAYING_META->{stop_pos};
301 } else { 323 } else {
302 $MUSIC_PLAYER->play (0); 324 $MUSIC_PLAYER->play (0);
303 $MUSIC_START = time; 325 $MUSIC_START = time;
304 } 326 }
305 327
306 delete $MUSIC_PLAYING_META->{stop_time}; 328 delete $meta->{stop_time};
307 delete $MUSIC_PLAYING_META->{stop_pos}; 329 delete $meta->{stop_pos};
308 } 330 }
309} 331}
310 332
311sub audio_music_push { 333sub audio_music_push {
312 return unless $SDL_MIXER; 334 return unless $SDL_MIXER;
331 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 353 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
332 $fade_out = 1000; 354 $fade_out = 1000;
333 } 355 }
334 356
335 # if the currently playing song is acceptable, let it continue 357 # if the currently playing song is acceptable, let it continue
336 return if $MUSIC_PLAYING_META
337 && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 358 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
338 359
339 my $NOW = time; 360 my $NOW = time;
340 361
341 if ($MUSIC_PLAYING_META) { 362 if ($MUSIC_PLAYING_META) {
342 $MUSIC_PLAYING_META->{stop_time} = $NOW; 363 $MUSIC_PLAYING_META->{stop_time} = $NOW;
346 # sort by stop time, oldest first 367 # sort by stop time, oldest first
347 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 368 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
348 369
349 # if the most recently-played piece played very recently, 370 # if the most recently-played piece played very recently,
350 # resume it, else choose the oldest piece for rotation. 371 # resume it, else choose the oldest piece for rotation.
351 $MUSIC_PLAYING_META = 372 audio_music_set_meta
352 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 373 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
353 ? $MUSIC_HAVE[-1] 374 ? $MUSIC_HAVE[-1]
354 : $MUSIC_HAVE[0]; 375 : $MUSIC_HAVE[0];
355 376
356 audio_music_start; 377 audio_music_start;
367sub audio_music_finished { 388sub audio_music_finished {
368 # we compress multiple jingles of the same type 389 # we compress multiple jingles of the same type
369 shift @MUSIC_JINGLE 390 shift @MUSIC_JINGLE
370 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 391 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
371 392
393 $MUSIC_PLAYING_WIDGET->clear;
394
372 undef $MUSIC_PLAYER; 395 undef $MUSIC_PLAYER;
373 undef $MUSIC_PLAYING_META; 396 undef $MUSIC_PLAYING_META;
374 undef $MUSIC_PLAYING_DATA; 397 undef $MUSIC_PLAYING_DATA;
375 398
376 audio_music_push; 399 audio_music_push;
396 419
397sub audio_shutdown { 420sub audio_shutdown {
398 undef $MUSIC_PLAYER; 421 undef $MUSIC_PLAYER;
399 undef $MUSIC_PLAYING_META; 422 undef $MUSIC_PLAYING_META;
400 undef $MUSIC_PLAYING_DATA; 423 undef $MUSIC_PLAYING_DATA;
424
425 audio_music_set_meta { };
401 426
402 $MUSIC_WANT = []; 427 $MUSIC_WANT = [];
403 @MUSIC_JINGLE = (); 428 @MUSIC_JINGLE = ();
404 %AUDIO_PLAY = (); 429 %AUDIO_PLAY = ();
405 %AUDIO_CHUNK = (); 430 %AUDIO_CHUNK = ();
839} 864}
840 865
841sub audio_setup { 866sub audio_setup {
842 my $vbox = new CFPlus::UI::VBox; 867 my $vbox = new CFPlus::UI::VBox;
843 868
844 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); 869 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]);
845 870
846 my $row = 0; 871 my $row = 0;
847 872
848 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); 873 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable");
849 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 874 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
853 ); 878 );
854# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 879# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
855# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 880# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
856# $CFG->{effects_volume} = $_[1]; 881# $CFG->{effects_volume} = $_[1];
857# }); 882# });
883
884 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
885 $table->add_at (1, $row, new CFPlus::UI::CheckBox
886 expand => 1, state => $CFG->{effects_enable},
887 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
888 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 }
889 );
890 $table->add_at (2, $row++, new CFPlus::UI::Slider
891 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
892 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
893 . "is set highest and you use your operating system volume setting. Changes are instant.",
894 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
895 );
896
858 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 897 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
859 $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox); 898 $table->add_at (1, $row, new CFPlus::UI::CheckBox
860 $hbox->add (new CFPlus::UI::CheckBox
861 expand => 1, state => $CFG->{bgm_enable}, 899 expand => 1, state => $CFG->{bgm_enable},
862 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 900 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
863 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 901 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
864 ); 902 );
865 $hbox->add (new CFPlus::UI::Slider 903 $table->add_at (2, $row++, new CFPlus::UI::Slider
866 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 904 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
867 tooltip => "The volume of the background music. Changes are instant.", 905 tooltip => "The volume of the background music. Changes are instant.",
868 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 906 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
869 ); 907 );
870 908
871 $table->add_at (1, $row++, new CFPlus::UI::Button 909 $table->add_at (1, $row++, new CFPlus::UI::Button
872 expand => 1, align => 0, text => "Apply", 910 c_colspan => 2, expand => 1, align => 0, text => "Apply",
873 tooltip => "Apply the audio settings", 911 tooltip => "Apply the audio settings",
874 on_activate => sub { 912 on_activate => sub {
875 audio_shutdown (); 913 audio_shutdown ();
876 audio_init (); 914 audio_init ();
877 0 915 0
948 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); 986 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
949 987
950 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# 988 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
951 989
952 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); 990 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
953 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2); 991 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2);
954 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1); 992 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1);
955 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2); 993 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2);
956 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1); 994 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1);
957 $t->add_at (1,1, new CFPlus::UI::Label text => "e"); 995 $t->add_at (1,1, new CFPlus::UI::Label text => "e");
958 996
959 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); 997 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
960 998
961 $c->add_items ({ 999 $c->add_items ({
1568 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); 1606 CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor");
1569 1607
1570 $hb 1608 $hb
1571} 1609}
1572 1610
1611sub media_window {
1612 my $vb = new CFPlus::UI::VBox;
1613
1614 $vb->add (new CFPlus::UI::FancyFrame
1615 label => "Currently playing music",
1616 child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
1617 child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8),
1618 );
1619
1620 $vb->add (new CFPlus::UI::FancyFrame
1621 label => "Other media used in this session",
1622 expand => 1,
1623 child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller
1624 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
1625 );
1626
1627 $vb
1628}
1629
1630sub add_license {
1631 my ($meta) = @_;
1632
1633 $meta = $meta->{meta}
1634 or return;
1635
1636 $meta->{license} || $meta->{author} || $meta->{source}
1637 or return;
1638
1639 $LICENSE_WIDGET->add_paragraph ({
1640 fg => [1, 1, 1, 1],
1641 markup => "<small>"
1642 . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n"
1643 . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n"
1644 . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n"
1645 . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n"
1646 . "</small>",
1647 });
1648 $LICENSE_WIDGET->scroll_to_bottom;
1649}
1650
1573sub toggle_player_page { 1651sub toggle_player_page {
1574 my ($widget) = @_; 1652 my ($widget) = @_;
1575 1653
1576 if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { 1654 if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) {
1577 $PL_WINDOW->hide; 1655 $PL_WINDOW->hide;
1614 $ntb->add_tab ( 1692 $ntb->add_tab (
1615 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1693 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1616 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1694 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1617 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1695 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1618 ); 1696 );
1619 $ntb->add_tab (Pickup => autopickup_setup, 1697 $ntb->add_tab (Pickup => autopickup_setup,
1620 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1698 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1699
1700 $ntb->add_tab (Media => media_window,
1701 "License, Author and Source info for media sent by the server.");
1621 1702
1622 $ntb->set_current_page ($INVENTORY_PAGE); 1703 $ntb->set_current_page ($INVENTORY_PAGE);
1623 1704
1624 $plwin->add ($ntb); 1705 $plwin->add ($ntb);
1625 $plwin 1706 $plwin
2113 gauge_fontsize => 1, 2194 gauge_fontsize => 1,
2114 gauge_size => 0.35, 2195 gauge_size => 0.35,
2115 stat_fontsize => 0.7, 2196 stat_fontsize => 0.7,
2116 mapsize => 100, 2197 mapsize => 100,
2117 audio_enable => 1, 2198 audio_enable => 1,
2199 effects_enable => 1,
2200 effects_volume => 1,
2118 bgm_enable => 1, 2201 bgm_enable => 1,
2119 bgm_volume => 0.25, 2202 bgm_volume => 0.5,
2120 output_sync => 1, 2203 output_sync => 1,
2121 output_count => 1, 2204 output_count => 1,
2122 output_rate => "", 2205 output_rate => "",
2123 pickup => 0, 2206 pickup => 0,
2124 inv_sort => "mtime", 2207 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines