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.204 by root, Mon Aug 6 05:06:33 2007 UTC vs.
Revision 1.225 by root, Fri Aug 31 08:03:10 2007 UTC

113our $CONN; 113our $CONN;
114our $PROFILE; # current profile 114our $PROFILE; # current profile
115our $FAST; # fast, low-quality mode, possibly useful for software-rendering 115our $FAST; # fast, low-quality mode, possibly useful for software-rendering
116 116
117our $WANT_REFRESH; 117our $WANT_REFRESH;
118our $CAN_REFRESH;
119 118
120our @SDL_MODES; 119our @SDL_MODES;
121our $WIDTH; 120our $WIDTH;
122our $HEIGHT; 121our $HEIGHT;
123our $FULLSCREEN; 122our $FULLSCREEN;
127our $FONT_FIXED; 126our $FONT_FIXED;
128 127
129our $MAP; 128our $MAP;
130our $MAPMAP; 129our $MAPMAP;
131our $MAPWIDGET; 130our $MAPWIDGET;
131our $COMPLETER;
132our $BUTTONBAR; 132our $BUTTONBAR;
133our $METASERVER; 133our $METASERVER;
134our $LOGIN_BUTTON; 134our $LOGIN_BUTTON;
135our $QUIT_DIALOG; 135our $QUIT_DIALOG;
136our $HOST_ENTRY; 136our $HOST_ENTRY;
147our $PL_WINDOW; 147our $PL_WINDOW;
148 148
149our $MUSIC_PLAYING_WIDGET; 149our $MUSIC_PLAYING_WIDGET;
150our $LICENSE_WIDGET; 150our $LICENSE_WIDGET;
151 151
152our $PICKUP_PAGE;
152our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
153our $STATS_PAGE; 154our $STATS_PAGE;
154our $SKILL_PAGE; 155our $SKILL_PAGE;
155our $SPELL_PAGE; 156our $SPELL_PAGE;
156our $SPELL_LIST; 157our $SPELL_LIST;
168our $STATUSBOX; 169our $STATUSBOX;
169our $DEBUG_STATUS; 170our $DEBUG_STATUS;
170 171
171our $INV; 172our $INV;
172our $INVR; 173our $INVR;
173our $INV_RIGHT_HB; 174our $INVR_HB;
174
175our $PICKUP_CFG;
176 175
177############################################################################# 176#############################################################################
178 177
179sub status { 178sub status {
180 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 179 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
183sub debug { 182sub debug {
184 $DEBUG_STATUS->set_text ($_[0]); 183 $DEBUG_STATUS->set_text ($_[0]);
185} 184}
186 185
187sub message { 186sub message {
188 my ($para) = @_;
189 $MESSAGE_WINDOW->message ($para); 187 $MESSAGE_WINDOW->message (@_);
190} 188}
191 189
192############################################################################# 190#############################################################################
193#TODO: maybe move into own audio module... 191#TODO: maybe move into own audio module...
194 192
217 my ($face) = @_; 215 my ($face) = @_;
218 216
219 $CFG->{effects_enable} 217 $CFG->{effects_enable}
220 or return; 218 or return;
221 219
220 $AUDIO_PLAY{$face}
221 or return;
222
222 if (my $chunk = $AUDIO_CHUNK{$face}) { 223 if (my $chunk = $AUDIO_CHUNK{$face}) {
223 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 224 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
224 my (undef, $dx, $dy, $vol) = @$_; 225 my (undef, $dx, $dy, $vol) = @$_;
225 226
226 my $channel = CFPlus::Channel::find; 227 my $channel = CFPlus::Channel::find;
227 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 228 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
228 $dx = $dx / 10 * 255;
229 $channel->set_panning (255 - $dx, 255 + $dx);
230
231# my $angle = $dx ? : $dx < 0 ?
232# my $distance = -$vol;
233# $channel->set_position ($angle, $distance); 229 $channel->set_position_r ($dx, $dy, 20);
234
235 $chunk->play ($channel); 230 $chunk->play ($channel);
236 } 231 }
237 } else { 232 } else {
238 # sound_meta not set means data is in flight either way 233 # sound_meta not set means data is in flight either way
239 my $meta = $CONN->{sound_meta}{$face} 234 my $meta = $CONN->{face}[$face]
240 or return; 235 or return;
241 236
237 $meta->{data}
238 or return;
239
242 # if its a jingle, play it as ambient music 240 # if its a jingle, play it as ambient music
243 if ($meta->{meta}{jingle}) { 241 if ($meta->{data}{jingle}) {
244 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue 242 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
245 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 243 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
246 &audio_music_push ($face); 244 &audio_music_push ($face);
247 } 245 }
248 } else { 246 } else {
249 # fetch from database 247 # fetch from database
250 CFPlus::DB::get res_data => $meta->{name}, sub { 248 CFPlus::DB::get res_data => $meta->{name}, sub {
251 my $rwops = new CFPlus::RW $_[0]; 249 my $rwops = new CFPlus::RW $_[0];
252 my $chunk = new CFPlus::MixChunk $rwops 250 my $chunk = new CFPlus::MixChunk $rwops
253 or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; 251 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
254 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 252 $chunk->volume (($meta->{data}{volume} || 1) * 128);
255 $AUDIO_CHUNK{$face} = $chunk; 253 $AUDIO_CHUNK{$face} = $chunk;
256 254
257 audio_sound_push ($face); 255 audio_sound_push ($face);
258 }; 256 };
259 } 257 }
267 or return; 265 or return;
268 $CFG->{effects_enable} 266 $CFG->{effects_enable}
269 or return; 267 or return;
270 268
271 my $queue = $AUDIO_PLAY{$face} ||= []; 269 my $queue = $AUDIO_PLAY{$face} ||= [];
272 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s 270 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
273 audio_sound_push $face 271 audio_sound_push $face
274 unless @$queue > 1; 272 unless @$queue > 1;
275} 273}
276 274
277sub audio_music_set_meta { 275sub audio_music_set_meta {
278 my ($meta) = @_; 276 my ($meta) = @_;
279 277
280 $MUSIC_PLAYING_META = $meta; 278 $MUSIC_PLAYING_META = $meta;
281 $MUSIC_PLAYING_WIDGET->set_markup ( 279 $MUSIC_PLAYING_WIDGET->set_markup (
282 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 280 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
283 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 281 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
284 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 282 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
285 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 283 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
286 ); 284 );
287} 285}
288 286
289sub audio_music_update_volume { 287sub audio_music_update_volume {
290 return unless $MUSIC_PLAYING_META; 288 return unless $MUSIC_PLAYING_META;
291 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 289 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
292 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 290 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
293 CFPlus::MixMusic::volume $base * $volume * 128; 291 CFPlus::MixMusic::volume $base * $volume * 128;
294} 292}
295 293
296sub audio_music_start { 294sub audio_music_start {
297 my $meta = $MUSIC_PLAYING_META; 295 my $meta = $MUSIC_PLAYING_META;
316 314
317 my $NOW = time; 315 my $NOW = time;
318 316
319 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 317 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
320 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 318 my $pos = $MUSIC_PLAYING_META->{stop_pos};
321 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 319 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
322 $MUSIC_START = time - $pos; 320 $MUSIC_START = time - $pos;
323 } else { 321 } else {
324 $MUSIC_PLAYER->play (0); 322 $MUSIC_PLAYER->play (0);
325 $MUSIC_START = time; 323 $MUSIC_START = time;
326 } 324 }
340 $fade_out = 333; 338 $fade_out = 333;
341 } else { 339 } else {
342 return unless $CFG->{bgm_enable}; 340 return unless $CFG->{bgm_enable};
343 341
344 my @have = 342 my @have =
345 grep $_, 343 grep $_ && $_->{data},
346 map $CONN->{music_meta}{$_}, 344 map $CONN->{face}[$_],
347 @$MUSIC_WANT; 345 @$MUSIC_WANT;
346
347 # randomize music a bit so that the order is not always the same
348 $_->{stop_time} ||= rand for @have;
348 349
349 @MUSIC_HAVE = @have 350 @MUSIC_HAVE = @have
350 if @have; 351 if @have;
351 352
352 # default MUSIC_HAVE == MUSIC_DEFAULT 353 # default MUSIC_HAVE == MUSIC_DEFAULT
353 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 354 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
354 $fade_out = 1000; 355 $fade_out = 700;
355 } 356 }
356 357
357 # if the currently playing song is acceptable, let it continue 358 # if the currently playing song is acceptable, let it continue
358 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 359 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
359 360
368 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 369 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
369 370
370 # if the most recently-played piece played very recently, 371 # if the most recently-played piece played very recently,
371 # resume it, else choose the oldest piece for rotation. 372 # resume it, else choose the oldest piece for rotation.
372 audio_music_set_meta 373 audio_music_set_meta
373 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 374 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
374 ? $MUSIC_HAVE[-1] 375 ? $MUSIC_HAVE[-1]
375 : $MUSIC_HAVE[0]; 376 : $MUSIC_HAVE[0];
376 377
377 audio_music_start; 378 audio_music_start;
378 } 379 }
384 $MUSIC_WANT = $songs; 385 $MUSIC_WANT = $songs;
385 audio_music_push; 386 audio_music_push;
386} 387}
387 388
388sub audio_music_finished { 389sub audio_music_finished {
390 if ($MUSIC_PLAYING_META) {
391 $MUSIC_PLAYING_META->{stop_time} = time;
392 }
393
389 # we compress multiple jingles of the same type 394 # we compress multiple jingles of the same type
390 shift @MUSIC_JINGLE 395 shift @MUSIC_JINGLE
391 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 396 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
392 397
393 $MUSIC_PLAYING_WIDGET->clear; 398 $MUSIC_PLAYING_WIDGET->clear;
773 state => $CFG->{fullscreen}, 778 state => $CFG->{fullscreen},
774 tooltip => "Bring the client into fullscreen mode.", 779 tooltip => "Bring the client into fullscreen mode.",
775 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } 780 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
776 ); 781 );
777 782
783 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
784 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
785 state => $CFG->{force_opengl11},
786 tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
787 . "higher memory usage and slower performance. It will, however, help tremendously on "
788 . "cards that claim to support a feature but fall back to software rendering. "
789 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
790 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you "
791 . "experience extremely low framerates and your card should do better, try this option.</b>",
792 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
793 );
794
795 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
796 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
797 state => $CFG->{texture_compression},
798 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
799 . "will save a lot of memory and increase performance. The compression algorithm "
800 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
801 . "forced OpenGL 1.1 mode.",
802 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
803 );
804
778 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 805 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
779 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 806 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
780 state => $CFG->{fast}, 807 state => $CFG->{fast},
781 tooltip => "Lower the visual quality considerably to speed up rendering.", 808 tooltip => "Lower the visual quality considerably to speed up rendering.",
782 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 809 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
808 835
809 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); 836 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
810 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 837 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
811 state => $CFG->{map_smoothing}, 838 state => $CFG->{map_smoothing},
812 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " 839 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
813 . "This increases load on the graphics subsystem and works only with 2.x servers. " 840 . "This increases load on the graphics subsystem and works only with TRT servers. "
814 . "Changes take effect at next connection only.", 841 . "Changes take effect at next login only.",
815 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } 842 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
816 ); 843 );
817 844
818 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 845 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
819 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 846 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
830 ); 857 );
831 858
832 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 859 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
833 $table->add_at (1, $row++, new CFPlus::UI::Slider 860 $table->add_at (1, $row++, new CFPlus::UI::Slider
834 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 861 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
835 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 862 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
863 . "but you still need to press apply to correctly re-layout the widget.",
836 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 864 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
837 ); 865 );
838 866
839 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 867 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
840 $table->add_at (1, $row++, new CFPlus::UI::Slider 868 $table->add_at (1, $row++, new CFPlus::UI::Slider
877# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 905# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
878# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { 906# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
879# $CFG->{effects_volume} = $_[1]; 907# $CFG->{effects_volume} = $_[1];
880# }); 908# });
881 909
882 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); 910 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
883 $table->add_at (1, $row, new CFPlus::UI::CheckBox 911 $table->add_at (1, $row, new CFPlus::UI::CheckBox
884 expand => 1, state => $CFG->{effects_enable}, 912 expand => 1, state => $CFG->{effects_enable},
885 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", 913 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
914 on_changed => sub {
886 on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } 915 $CFG->{effects_enable} = $_[1];
916 $CONN->update_fx_want if $CONN;
917 0
918 }
887 ); 919 );
888 $table->add_at (2, $row++, new CFPlus::UI::Slider 920 $table->add_at (2, $row++, new CFPlus::UI::Slider
889 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], 921 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
890 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " 922 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
891 . "is set highest and you use your operating system volume setting. Changes are instant.", 923 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
892 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } 924 on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
893 ); 925 );
894 926
895 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); 927 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
896 $table->add_at (1, $row, new CFPlus::UI::CheckBox 928 $table->add_at (1, $row, new CFPlus::UI::CheckBox
897 expand => 1, state => $CFG->{bgm_enable}, 929 expand => 1, state => $CFG->{bgm_enable},
898 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 930 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
899 on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } 931 on_changed => sub {
932 $CFG->{bgm_enable} = $_[1];
933 $CONN->update_fx_want if $CONN;
934 audio_music_push;
935 0
936 }
900 ); 937 );
901 $table->add_at (2, $row++, new CFPlus::UI::Slider 938 $table->add_at (2, $row++, new CFPlus::UI::Slider
902 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 939 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
903 tooltip => "The volume of the background music. Changes are instant.", 940 tooltip => "The volume of the background music. Changes are instant.",
904 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } 941 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
955 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 992 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
956 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 993 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
957 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 994 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
958 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 995 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
959 996
960 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 997 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
998 $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
999 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
961 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 1000 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
962 1001
963 $GAUGES = { 1002 $GAUGES = {
1003 exp => $exp, prg => $prg, sklprg => $sklprg,
964 exp => $exp, win => $win, range => $rng, 1004 win => $win, range => $rng,
965 food => $fg, mana => $mg, hp => $hg, grace => $gg 1005 hp => $hg, mana => $mg, grace => $gg, food => $fg,
966 }; 1006 };
967 1007
968 &set_gauge_window_fontsize; 1008 &set_gauge_window_fontsize;
969 1009
970 $win 1010 $win
1171 $r 1211 $r
1172} 1212}
1173 1213
1174sub skill_window { 1214sub skill_window {
1175 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1215 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1216
1176 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1217 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1218
1177 $sw 1219 $sw
1178} 1220}
1179 1221
1180sub formsep($) { 1222sub formsep($) {
1181 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1223 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1593 $sw1->add ($INV = new CFPlus::UI::Inventory); 1635 $sw1->add ($INV = new CFPlus::UI::Inventory);
1594 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); 1636 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1595 1637
1596 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1638 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1597 1639
1598 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1640 $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
1599 1641
1600 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1642 $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1601 $sw2->add ($INVR = new CFPlus::UI::Inventory); 1643 $sw2->add ($INVR = new CFPlus::UI::Inventory);
1602 1644
1603 # XXX: Call after $INVR = ... because set_opencont sets the items 1645 # XXX: Call after $INVR = ... because set_opencont sets the items
1626} 1668}
1627 1669
1628sub add_license { 1670sub add_license {
1629 my ($meta) = @_; 1671 my ($meta) = @_;
1630 1672
1631 $meta = $meta->{meta} 1673 $meta = $meta->{data}
1632 or return; 1674 or return;
1633 1675
1634 $meta->{license} || $meta->{author} || $meta->{source} 1676 $meta->{license} || $meta->{author} || $meta->{source}
1635 or return; 1677 or return;
1636 1678
1690 $ntb->add_tab ( 1732 $ntb->add_tab (
1691 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1733 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1692 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1734 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1693 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1735 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1694 ); 1736 );
1695 $ntb->add_tab (Pickup => autopickup_setup, 1737 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1696 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1738 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1697 1739
1698 $ntb->add_tab (Media => media_window, 1740 $ntb->add_tab (Media => media_window,
1699 "License, Author and Source info for media sent by the server."); 1741 "License, Author and Source info for media sent by the server.");
1700 1742
1858 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 1900 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1859 ); 1901 );
1860 $hb->add (new CFPlus::UI::Button 1902 $hb->add (new CFPlus::UI::Button
1861 text => "Quit anyway", 1903 text => "Quit anyway",
1862 expand => 1, 1904 expand => 1,
1863 on_activate => sub { exit }, 1905 on_activate => sub { Event::unloop_all },
1864 ); 1906 );
1865 } 1907 }
1866 1908
1867 $QUIT_DIALOG->show; 1909 $QUIT_DIALOG->show;
1868 $QUIT_DIALOG->grab_focus; 1910 $QUIT_DIALOG->grab_focus;
1941 1983
1942 $SDL_ACTIVE = 1; 1984 $SDL_ACTIVE = 1;
1943 $LAST_REFRESH = time - 0.01; 1985 $LAST_REFRESH = time - 0.01;
1944 1986
1945 CFPlus::OpenGL::init; 1987 CFPlus::OpenGL::init;
1988 CFPlus::Macro::init;
1946 1989
1947 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1990 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1948 1991
1949 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1992 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1950 1993
1951 ############################################################################# 1994 #############################################################################
1952 1995
1953 if ($DEBUG_STATUS) { 1996 if ($DEBUG_STATUS) {
1954 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1997 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1955 } else { 1998 } else {
1956 # create the widgets 1999 # create/configure the widgets
2000
2001 $CFPlus::UI::ROOT->connect (key_down => sub {
2002 my (undef, $ev) = @_;
2003
2004 if (my @macros = CFPlus::Macro::find $ev) {
2005 CFPlus::Macro::execute $_ for @macros;
2006
2007 return 1;
2008 }
2009
2010 0
2011 });
1957 2012
1958 $DEBUG_STATUS = new CFPlus::UI::Label 2013 $DEBUG_STATUS = new CFPlus::UI::Label
1959 padding => 0, 2014 padding => 0,
1960 z => 100, 2015 z => 100,
1961 force_x => "max", 2016 force_x => "max",
1991 $MESSAGE_WINDOW->activate_console ($preset) 2046 $MESSAGE_WINDOW->activate_console ($preset)
1992 if $MESSAGE_WINDOW; 2047 if $MESSAGE_WINDOW;
1993 }); 2048 });
1994 $MAPWIDGET->show; 2049 $MAPWIDGET->show;
1995 $MAPWIDGET->grab_focus; 2050 $MAPWIDGET->grab_focus;
2051
2052 $COMPLETER = new CFPlus::MapWidget::Command::
2053 command => { },
2054 tooltip => "#completer_help",
2055 ;
1996 2056
1997 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2057 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1998 title => "Setup", 2058 title => "Setup",
1999 name => "setup_dialog", 2059 name => "setup_dialog",
2000 x => 'center', 2060 x => 'center',
2062 tooltip => "Terminates the program", 2122 tooltip => "Terminates the program",
2063 on_activate => sub { 2123 on_activate => sub {
2064 if ($CONN) { 2124 if ($CONN) {
2065 open_quit_dialog; 2125 open_quit_dialog;
2066 } else { 2126 } else {
2067 exit; 2127 Event::unloop_all;
2068 } 2128 }
2069 0 2129 0
2070 }, 2130 },
2071 ); 2131 );
2072 2132
2073 $BUTTONBAR->show; 2133 $BUTTONBAR->show;
2074 $SETUP_DIALOG->show; 2134 $SETUP_DIALOG->show;
2135 $MESSAGE_WINDOW->show;
2075 } 2136 }
2076 2137
2077 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2138 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2078} 2139}
2079 2140
2087my $animate_timer; 2148my $animate_timer;
2088 2149
2089my $fps = 9; 2150my $fps = 9;
2090 2151
2091sub force_refresh { 2152sub force_refresh {
2153 if ($ENV{CFPLUS_DEBUG} & 4) {
2092 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; 2154 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2093 debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; 2155 debug sprintf "%3.2f", $fps;
2156 }
2094 2157
2095 $CFPlus::UI::ROOT->draw; 2158 $CFPlus::UI::ROOT->draw;
2096 2159 CFPlus::SDL_GL_SwapBuffers;
2097 $WANT_REFRESH = 0;
2098 $CAN_REFRESH = 0;
2099 $LAST_REFRESH = $NOW; 2160 $LAST_REFRESH = $NOW;
2100 2161 $WANT_REFRESH->stop;
2101 CFPlus::SDL_GL_SwapBuffers;
2102} 2162}
2103 2163
2164$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
2165
2104my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2166my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
2105 $NOW = time; 2167 $NOW = time;
2106 2168
2107 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2169 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2108 for CFPlus::poll_events; 2170 for CFPlus::poll_events;
2109 2171
2110 if (%animate_object) { 2172 if (%animate_object) {
2111 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2173 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2112 ++$WANT_REFRESH; 2174 $WANT_REFRESH->start;
2113 }
2114
2115 if ($WANT_REFRESH) {
2116 force_refresh;
2117 } else {
2118 $CAN_REFRESH = 1;
2119 } 2175 }
2120}); 2176});
2121 2177
2122sub animation_start { 2178sub animation_start {
2123 my ($widget) = @_; 2179 my ($widget) = @_;
2129 delete $animate_object{$widget}; 2185 delete $animate_object{$widget};
2130} 2186}
2131 2187
2132%SDL_CB = ( 2188%SDL_CB = (
2133 CFPlus::SDL_QUIT => sub { 2189 CFPlus::SDL_QUIT => sub {
2134 exit; 2190 Event::unloop_all;
2135 }, 2191 },
2136 CFPlus::SDL_VIDEORESIZE => sub { 2192 CFPlus::SDL_VIDEORESIZE => sub {
2137 }, 2193 },
2138 CFPlus::SDL_VIDEOEXPOSE => sub { 2194 CFPlus::SDL_VIDEOEXPOSE => sub {
2139 CFPlus::UI::full_refresh; 2195 CFPlus::UI::full_refresh;
2178 CFPlus::DB::Server::run; 2234 CFPlus::DB::Server::run;
2179 2235
2180 CFPlus::UI::set_layout ($::CFG->{layout}); 2236 CFPlus::UI::set_layout ($::CFG->{layout});
2181 2237
2182 my %DEF_CFG = ( 2238 my %DEF_CFG = (
2183 sdl_mode => 0, 2239 sdl_mode => 0,
2184 fullscreen => 0, 2240 fullscreen => 0,
2185 fast => 0, 2241 fast => 0,
2242 force_opengl11 => undef,
2243 texture_compression => 1,
2186 map_scale => 1, 2244 map_scale => 1,
2187 fow_enable => 1, 2245 fow_enable => 1,
2188 fow_intensity => 0, 2246 fow_intensity => 0,
2189 map_smoothing => 1, 2247 map_smoothing => 1,
2190 gui_fontsize => 1, 2248 gui_fontsize => 1,
2191 log_fontsize => 0.7, 2249 log_fontsize => 0.7,
2192 gauge_fontsize => 1, 2250 gauge_fontsize => 1,
2193 gauge_size => 0.35, 2251 gauge_size => 0.35,
2194 stat_fontsize => 0.7, 2252 stat_fontsize => 0.7,
2195 mapsize => 100, 2253 mapsize => 100,
2196 audio_enable => 1, 2254 audio_enable => 1,
2197 effects_enable => 1, 2255 effects_enable => 1,
2198 effects_volume => 1, 2256 effects_volume => 1,
2199 bgm_enable => 1, 2257 bgm_enable => 1,
2200 bgm_volume => 0.5, 2258 bgm_volume => 0.5,
2201 output_sync => 1, 2259 output_sync => 1,
2202 output_count => 1, 2260 output_count => 1,
2203 output_rate => "", 2261 output_rate => "",
2204 pickup => 0, 2262 pickup => 0,
2205 inv_sort => "mtime", 2263 inv_sort => "mtime",
2206 default => "profile", # default profile 2264 default => "profile", # default profile
2207 show_tips => 1, 2265 show_tips => 1,
2208 logview_max_par => 1000, 2266 logview_max_par => 1000,
2209 ); 2267 );
2210 2268
2211 while (my ($k, $v) = each %DEF_CFG) { 2269 while (my ($k, $v) = each %DEF_CFG) {
2212 $CFG->{$k} = $v unless exists $CFG->{$k}; 2270 $CFG->{$k} = $v unless exists $CFG->{$k};
2213 } 2271 }
2270# } 2328# }
2271# my $t2 = Time::HiRes::time; 2329# my $t2 = Time::HiRes::time;
2272# warn $t2-$t1; 2330# warn $t2-$t1;
2273# } 2331# }
2274 2332
2275 $startup_done->();
2276
2277 video_init; 2333 video_init;
2278 audio_init; 2334 audio_init;
2279} 2335}
2280 2336
2281show_tip_of_the_day if $CFG->{show_tips}; 2337show_tip_of_the_day if $CFG->{show_tips};
2282 2338
2339Event->idle (cb => sub {
2340 $_[0]->w->cancel;
2341 $startup_done->();
2342});
2343
2283Event::loop; 2344Event::loop;
2345
2346#video_shutdown;
2347#audio_shutdown;
2284#CFPlus::SDL_Quit; 2348CFPlus::SDL_Quit;
2285#CFPlus::_exit 0;
2286
2287END {
2288 video_shutdown;
2289 audio_shutdown;
2290 CFPlus::SDL_Quit;
2291 CFPlus::DB::Server::stop; 2349CFPlus::DB::Server::stop;
2292}
2293 2350
2294=head1 NAME 2351=head1 NAME
2295 2352
2296cfplus - A Crossfire TRT and Crossfire game client 2353cfplus - A Crossfire TRT and Crossfire game client
2297 2354

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines