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.217 by root, Sun Aug 19 14:09:28 2007 UTC vs.
Revision 1.226 by root, Sat Sep 1 07:22:21 2007 UTC

86use CFPlus::DB; 86use CFPlus::DB;
87use CFPlus::UI; 87use CFPlus::UI;
88use CFPlus::UI::Canvas; 88use CFPlus::UI::Canvas;
89use CFPlus::UI::Inventory; 89use CFPlus::UI::Inventory;
90use CFPlus::UI::SpellList; 90use CFPlus::UI::SpellList;
91use CFPlus::UI::Dockable;
91use CFPlus::UI::MessageWindow; 92use CFPlus::UI::MessageWindow;
93use CFPlus::UI::ChatView;
92use CFPlus::Pod; 94use CFPlus::Pod;
93use CFPlus::MapWidget; 95use CFPlus::MapWidget;
94use CFPlus::Macro; 96use CFPlus::Macro;
95 97
96$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 98$SIG{QUIT} = sub { Carp::cluck "QUIT" };
126our $FONT_FIXED; 128our $FONT_FIXED;
127 129
128our $MAP; 130our $MAP;
129our $MAPMAP; 131our $MAPMAP;
130our $MAPWIDGET; 132our $MAPWIDGET;
133our $COMPLETER;
131our $BUTTONBAR; 134our $BUTTONBAR;
132our $METASERVER; 135our $METASERVER;
133our $LOGIN_BUTTON; 136our $LOGIN_BUTTON;
134our $QUIT_DIALOG; 137our $QUIT_DIALOG;
135our $HOST_ENTRY; 138our $HOST_ENTRY;
146our $PL_WINDOW; 149our $PL_WINDOW;
147 150
148our $MUSIC_PLAYING_WIDGET; 151our $MUSIC_PLAYING_WIDGET;
149our $LICENSE_WIDGET; 152our $LICENSE_WIDGET;
150 153
154our $PICKUP_PAGE;
151our $INVENTORY_PAGE; 155our $INVENTORY_PAGE;
152our $STATS_PAGE; 156our $STATS_PAGE;
153our $SKILL_PAGE; 157our $SKILL_PAGE;
154our $SPELL_PAGE; 158our $SPELL_PAGE;
155our $SPELL_LIST; 159our $SPELL_LIST;
180sub debug { 184sub debug {
181 $DEBUG_STATUS->set_text ($_[0]); 185 $DEBUG_STATUS->set_text ($_[0]);
182} 186}
183 187
184sub message { 188sub message {
185 my ($para) = @_;
186 $MESSAGE_WINDOW->message ($para); 189 $MESSAGE_WINDOW->message (@_);
187} 190}
188 191
189############################################################################# 192#############################################################################
190#TODO: maybe move into own audio module... 193#TODO: maybe move into own audio module...
191 194
228 $channel->set_position_r ($dx, $dy, 20); 231 $channel->set_position_r ($dx, $dy, 20);
229 $chunk->play ($channel); 232 $chunk->play ($channel);
230 } 233 }
231 } else { 234 } else {
232 # sound_meta not set means data is in flight either way 235 # sound_meta not set means data is in flight either way
233 my $meta = $CONN->{sound_meta}{$face} 236 my $meta = $CONN->{face}[$face]
234 or return; 237 or return;
235 238
239 $meta->{data}
240 or return;
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->{data}{jingle}) {
238 if (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);
241 } 247 }
242 } else { 248 } else {
243 # fetch from database 249 # fetch from database
244 CFPlus::DB::get res_data => $meta->{name}, sub { 250 CFPlus::DB::get res_data => $meta->{name}, sub {
245 my $rwops = new CFPlus::RW $_[0]; 251 my $rwops = new CFPlus::RW $_[0];
246 my $chunk = new CFPlus::MixChunk $rwops 252 my $chunk = new CFPlus::MixChunk $rwops
247 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; 253 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
248 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 254 $chunk->volume (($meta->{data}{volume} || 1) * 128);
249 $AUDIO_CHUNK{$face} = $chunk; 255 $AUDIO_CHUNK{$face} = $chunk;
250 256
251 audio_sound_push ($face); 257 audio_sound_push ($face);
252 }; 258 };
253 } 259 }
271sub audio_music_set_meta { 277sub audio_music_set_meta {
272 my ($meta) = @_; 278 my ($meta) = @_;
273 279
274 $MUSIC_PLAYING_META = $meta; 280 $MUSIC_PLAYING_META = $meta;
275 $MUSIC_PLAYING_WIDGET->set_markup ( 281 $MUSIC_PLAYING_WIDGET->set_markup (
276 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 282 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
277 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
278 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
279 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 285 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
280 ); 286 );
281} 287}
282 288
283sub audio_music_update_volume { 289sub audio_music_update_volume {
284 return unless $MUSIC_PLAYING_META; 290 return unless $MUSIC_PLAYING_META;
285 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 291 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
286 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 292 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
287 CFPlus::MixMusic::volume $base * $volume * 128; 293 CFPlus::MixMusic::volume $base * $volume * 128;
288} 294}
289 295
290sub audio_music_start { 296sub audio_music_start {
291 my $meta = $MUSIC_PLAYING_META; 297 my $meta = $MUSIC_PLAYING_META;
310 316
311 my $NOW = time; 317 my $NOW = time;
312 318
313 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 319 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
314 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 320 my $pos = $MUSIC_PLAYING_META->{stop_pos};
315 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 321 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
316 $MUSIC_START = time - $pos; 322 $MUSIC_START = time - $pos;
317 } else { 323 } else {
318 $MUSIC_PLAYER->play (0); 324 $MUSIC_PLAYER->play (0);
319 $MUSIC_START = time; 325 $MUSIC_START = time;
320 } 326 }
334 $fade_out = 333; 340 $fade_out = 333;
335 } else { 341 } else {
336 return unless $CFG->{bgm_enable}; 342 return unless $CFG->{bgm_enable};
337 343
338 my @have = 344 my @have =
339 grep $_, 345 grep $_ && $_->{data},
340 map $CONN->{music_meta}{$_}, 346 map $CONN->{face}[$_],
341 @$MUSIC_WANT; 347 @$MUSIC_WANT;
348
349 # randomize music a bit so that the order is not always the same
350 $_->{stop_time} ||= rand for @have;
342 351
343 @MUSIC_HAVE = @have 352 @MUSIC_HAVE = @have
344 if @have; 353 if @have;
345 354
346 # default MUSIC_HAVE == MUSIC_DEFAULT 355 # default MUSIC_HAVE == MUSIC_DEFAULT
347 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 356 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
348 $fade_out = 1000; 357 $fade_out = 700;
349 } 358 }
350 359
351 # if the currently playing song is acceptable, let it continue 360 # if the currently playing song is acceptable, let it continue
352 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 361 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
353 362
362 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 371 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
363 372
364 # if the most recently-played piece played very recently, 373 # if the most recently-played piece played very recently,
365 # resume it, else choose the oldest piece for rotation. 374 # resume it, else choose the oldest piece for rotation.
366 audio_music_set_meta 375 audio_music_set_meta
367 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 376 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
368 ? $MUSIC_HAVE[-1] 377 ? $MUSIC_HAVE[-1]
369 : $MUSIC_HAVE[0]; 378 : $MUSIC_HAVE[0];
370 379
371 audio_music_start; 380 audio_music_start;
372 } 381 }
378 $MUSIC_WANT = $songs; 387 $MUSIC_WANT = $songs;
379 audio_music_push; 388 audio_music_push;
380} 389}
381 390
382sub audio_music_finished { 391sub audio_music_finished {
392 if ($MUSIC_PLAYING_META) {
393 $MUSIC_PLAYING_META->{stop_time} = time;
394 }
395
383 # we compress multiple jingles of the same type 396 # we compress multiple jingles of the same type
384 shift @MUSIC_JINGLE 397 shift @MUSIC_JINGLE
385 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 398 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
386 399
387 $MUSIC_PLAYING_WIDGET->clear; 400 $MUSIC_PLAYING_WIDGET->clear;
784 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); 797 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 798 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
786 state => $CFG->{texture_compression}, 799 state => $CFG->{texture_compression},
787 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 800 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
788 . "will save a lot of memory and increase performance. The compression algorithm " 801 . "will save a lot of memory and increase performance. The compression algorithm "
789 . "can differ form card to card, so your mileage may vary.", 802 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
803 . "forced OpenGL 1.1 mode.",
790 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 804 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
791 ); 805 );
792 806
793 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 807 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
794 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 808 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
917 expand => 1, state => $CFG->{bgm_enable}, 931 expand => 1, state => $CFG->{bgm_enable},
918 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 932 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
919 on_changed => sub { 933 on_changed => sub {
920 $CFG->{bgm_enable} = $_[1]; 934 $CFG->{bgm_enable} = $_[1];
921 $CONN->update_fx_want if $CONN; 935 $CONN->update_fx_want if $CONN;
936 audio_music_push;
922 0 937 0
923 } 938 }
924 ); 939 );
925 $table->add_at (2, $row++, new CFPlus::UI::Slider 940 $table->add_at (2, $row++, new CFPlus::UI::Slider
926 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 941 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
979 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 994 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
980 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 995 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
981 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 996 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
982 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 997 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
983 998
984 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 999 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
1000 $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
1001 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
985 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 1002 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
986 1003
987 $GAUGES = { 1004 $GAUGES = {
1005 exp => $exp, prg => $prg, sklprg => $sklprg,
988 exp => $exp, win => $win, range => $rng, 1006 win => $win, range => $rng,
989 food => $fg, mana => $mg, hp => $hg, grace => $gg 1007 hp => $hg, mana => $mg, grace => $gg, food => $fg,
990 }; 1008 };
991 1009
992 &set_gauge_window_fontsize; 1010 &set_gauge_window_fontsize;
993 1011
994 $win 1012 $win
1195 $r 1213 $r
1196} 1214}
1197 1215
1198sub skill_window { 1216sub skill_window {
1199 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1217 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1218
1200 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1219 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1220
1201 $sw 1221 $sw
1202} 1222}
1203 1223
1204sub formsep($) { 1224sub formsep($) {
1205 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1225 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1650} 1670}
1651 1671
1652sub add_license { 1672sub add_license {
1653 my ($meta) = @_; 1673 my ($meta) = @_;
1654 1674
1655 $meta = $meta->{meta} 1675 $meta = $meta->{data}
1656 or return; 1676 or return;
1657 1677
1658 $meta->{license} || $meta->{author} || $meta->{source} 1678 $meta->{license} || $meta->{author} || $meta->{source}
1659 or return; 1679 or return;
1660 1680
1714 $ntb->add_tab ( 1734 $ntb->add_tab (
1715 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1735 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1716 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1736 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1717 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1737 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1718 ); 1738 );
1719 $ntb->add_tab (Pickup => autopickup_setup, 1739 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1720 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1740 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1721 1741
1722 $ntb->add_tab (Media => media_window, 1742 $ntb->add_tab (Media => media_window,
1723 "License, Author and Source info for media sent by the server."); 1743 "License, Author and Source info for media sent by the server.");
1724 1744
1965 1985
1966 $SDL_ACTIVE = 1; 1986 $SDL_ACTIVE = 1;
1967 $LAST_REFRESH = time - 0.01; 1987 $LAST_REFRESH = time - 0.01;
1968 1988
1969 CFPlus::OpenGL::init; 1989 CFPlus::OpenGL::init;
1990 CFPlus::Macro::init;
1970 1991
1971 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1992 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1972 1993
1973 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1994 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1974 1995
1975 ############################################################################# 1996 #############################################################################
1976 1997
1977 if ($DEBUG_STATUS) { 1998 if ($DEBUG_STATUS) {
1978 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1999 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1979 } else { 2000 } else {
1980 # create the widgets 2001 # create/configure the widgets
2002
2003 $CFPlus::UI::ROOT->connect (key_down => sub {
2004 my (undef, $ev) = @_;
2005
2006 if (my @macros = CFPlus::Macro::find $ev) {
2007 CFPlus::Macro::execute $_ for @macros;
2008
2009 return 1;
2010 }
2011
2012 0
2013 });
1981 2014
1982 $DEBUG_STATUS = new CFPlus::UI::Label 2015 $DEBUG_STATUS = new CFPlus::UI::Label
1983 padding => 0, 2016 padding => 0,
1984 z => 100, 2017 z => 100,
1985 force_x => "max", 2018 force_x => "max",
2015 $MESSAGE_WINDOW->activate_console ($preset) 2048 $MESSAGE_WINDOW->activate_console ($preset)
2016 if $MESSAGE_WINDOW; 2049 if $MESSAGE_WINDOW;
2017 }); 2050 });
2018 $MAPWIDGET->show; 2051 $MAPWIDGET->show;
2019 $MAPWIDGET->grab_focus; 2052 $MAPWIDGET->grab_focus;
2053
2054 $COMPLETER = new CFPlus::MapWidget::Command::
2055 command => { },
2056 tooltip => "#completer_help",
2057 ;
2020 2058
2021 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2059 $SETUP_DIALOG = new CFPlus::UI::Toplevel
2022 title => "Setup", 2060 title => "Setup",
2023 name => "setup_dialog", 2061 name => "setup_dialog",
2024 x => 'center', 2062 x => 'center',
2149 delete $animate_object{$widget}; 2187 delete $animate_object{$widget};
2150} 2188}
2151 2189
2152%SDL_CB = ( 2190%SDL_CB = (
2153 CFPlus::SDL_QUIT => sub { 2191 CFPlus::SDL_QUIT => sub {
2154 exit; 2192 Event::unloop_all;
2155 }, 2193 },
2156 CFPlus::SDL_VIDEORESIZE => sub { 2194 CFPlus::SDL_VIDEORESIZE => sub {
2157 }, 2195 },
2158 CFPlus::SDL_VIDEOEXPOSE => sub { 2196 CFPlus::SDL_VIDEOEXPOSE => sub {
2159 CFPlus::UI::full_refresh; 2197 CFPlus::UI::full_refresh;
2292# } 2330# }
2293# my $t2 = Time::HiRes::time; 2331# my $t2 = Time::HiRes::time;
2294# warn $t2-$t1; 2332# warn $t2-$t1;
2295# } 2333# }
2296 2334
2297 $startup_done->();
2298
2299 video_init; 2335 video_init;
2300 audio_init; 2336 audio_init;
2301} 2337}
2302 2338
2303show_tip_of_the_day if $CFG->{show_tips}; 2339show_tip_of_the_day if $CFG->{show_tips};
2340
2341Event->idle (cb => sub {
2342 $_[0]->w->cancel;
2343 $startup_done->();
2344});
2304 2345
2305Event::loop; 2346Event::loop;
2306 2347
2307#video_shutdown; 2348#video_shutdown;
2308#audio_shutdown; 2349#audio_shutdown;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines