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