… | |
… | |
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; |
… | |
… | |
144 | our $SETUP_KEYBOARD; |
143 | our $SETUP_KEYBOARD; |
145 | |
144 | |
146 | our $PL_NOTEBOOK; |
145 | our $PL_NOTEBOOK; |
147 | our $PL_WINDOW; |
146 | our $PL_WINDOW; |
148 | |
147 | |
|
|
148 | our $MUSIC_PLAYING_WIDGET; |
|
|
149 | our $LICENSE_WIDGET; |
|
|
150 | |
149 | our $INVENTORY_PAGE; |
151 | our $INVENTORY_PAGE; |
150 | our $STATS_PAGE; |
152 | our $STATS_PAGE; |
151 | our $SKILL_PAGE; |
153 | our $SKILL_PAGE; |
152 | our $SPELL_PAGE; |
154 | our $SPELL_PAGE; |
153 | our $SPELL_LIST; |
155 | our $SPELL_LIST; |
… | |
… | |
159 | our $STATWIDS; |
161 | our $STATWIDS; |
160 | |
162 | |
161 | our $SDL_ACTIVE; |
163 | our $SDL_ACTIVE; |
162 | our %SDL_CB; |
164 | our %SDL_CB; |
163 | |
165 | |
|
|
166 | our $ALT_ENTER_MESSAGE; |
|
|
167 | our $STATUSBOX; |
|
|
168 | our $DEBUG_STATUS; |
|
|
169 | |
|
|
170 | our $INV; |
|
|
171 | our $INVR; |
|
|
172 | our $INVR_HB; |
|
|
173 | |
|
|
174 | ############################################################################# |
|
|
175 | |
|
|
176 | sub status { |
|
|
177 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
|
|
178 | } |
|
|
179 | |
|
|
180 | sub debug { |
|
|
181 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
182 | } |
|
|
183 | |
|
|
184 | sub message { |
|
|
185 | my ($para) = @_; |
|
|
186 | $MESSAGE_WINDOW->message ($para); |
|
|
187 | } |
|
|
188 | |
|
|
189 | ############################################################################# |
|
|
190 | #TODO: maybe move into own audio module... |
|
|
191 | |
164 | our $SDL_MIXER; |
192 | our $SDL_MIXER; |
|
|
193 | |
165 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
194 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
166 | our $MUSIC_WANT; # arryref of ambient music |
195 | our $MUSIC_WANT; # arryref of ambient music we want to play |
167 | our @MUSIC_HAVE; # ambient music we want now |
196 | our @MUSIC_HAVE; # ambient music we have on disk |
168 | our $MUSIC_START; |
197 | our $MUSIC_START; |
169 | our @MUSIC_JINGLE; # which jingles to play |
198 | our @MUSIC_JINGLE; # which jingles to play next |
170 | our $MUSIC_PLAYING_DATA; |
199 | our $MUSIC_PLAYING_DATA; |
171 | our $MUSIC_PLAYING_META; |
200 | our $MUSIC_PLAYING_META; |
172 | our $MUSIC_PLAYER; |
201 | our $MUSIC_PLAYER; |
173 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
202 | our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before |
174 | our @SOUNDS; # event => file mapping |
203 | |
175 | our %AUDIO_CHUNK; # audio files |
204 | our %AUDIO_CHUNK; # audio "files" |
176 | |
205 | our %AUDIO_PLAY; # which audio faces should be played |
177 | our $ALT_ENTER_MESSAGE; |
|
|
178 | our $STATUSBOX; |
|
|
179 | our $DEBUG_STATUS; |
|
|
180 | |
|
|
181 | our $INV; |
|
|
182 | our $INVR; |
|
|
183 | our $INV_RIGHT_HB; |
|
|
184 | |
|
|
185 | our $PICKUP_CFG; |
|
|
186 | |
|
|
187 | ############################################################################# |
|
|
188 | #TODO: maybe move into own audio module... |
|
|
189 | |
206 | |
190 | sub audio_channel_finished { |
207 | sub audio_channel_finished { |
191 | my ($channel) = @_; |
208 | my ($channel) = @_; |
192 | |
209 | |
193 | # warn "channel $channel finished\n";#d# |
210 | # warn "channel $channel finished\n";#d# |
194 | } |
211 | } |
195 | |
212 | |
196 | our %AUDIO_PLAY; |
|
|
197 | our %AUDIO_CHUNK; |
|
|
198 | |
|
|
199 | sub audio_sound_push($) { |
213 | sub audio_sound_push($) { |
200 | my ($face) = @_; |
214 | my ($face) = @_; |
|
|
215 | |
|
|
216 | $CFG->{effects_enable} |
|
|
217 | or return; |
|
|
218 | |
|
|
219 | $AUDIO_PLAY{$face} |
|
|
220 | or return; |
201 | |
221 | |
202 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
222 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
203 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
223 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
204 | my (undef, $dx, $dy, $vol) = @$_; |
224 | my (undef, $dx, $dy, $vol) = @$_; |
205 | |
225 | |
206 | my $channel = CFPlus::Channel::find; |
226 | my $channel = CFPlus::Channel::find; |
207 | $channel->volume ($vol * 128 / 255); |
227 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
208 | $dx = $dx / 10 * 255; |
|
|
209 | $channel->set_panning (255 - $dx, 255 + $dx); |
|
|
210 | |
|
|
211 | # my $angle = $dx ? : $dx < 0 ? |
|
|
212 | # my $distance = -$vol; |
|
|
213 | # $channel->set_position ($angle, $distance); |
228 | $channel->set_position_r ($dx, $dy, 20); |
214 | |
|
|
215 | $chunk->play ($channel); |
229 | $chunk->play ($channel); |
216 | } |
230 | } |
217 | } else { |
231 | } else { |
218 | # sound_meta not set means data is in flight either way |
232 | # sound_meta not set means data is in flight either way |
219 | my $meta = $CONN->{sound_meta}{$face} |
233 | my $meta = $CONN->{sound_meta}{$face} |
220 | or return; |
234 | or return; |
221 | |
235 | |
222 | # if its a jingle, play it as ambient music |
236 | # if its a jingle, play it as ambient music |
223 | if ($meta->{meta}{jingle}) { |
237 | if ($meta->{meta}{jingle}) { |
224 | push @MUSIC_JINGLE, $meta; |
238 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
225 | delete $AUDIO_PLAY{$face}; |
239 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
226 | &audio_music_push ($face); |
240 | &audio_music_push ($face); |
|
|
241 | } |
227 | } else { |
242 | } else { |
228 | # fetch from database |
243 | # fetch from database |
229 | CFPlus::DB::get res_data => $meta->{name}, sub { |
244 | CFPlus::DB::get res_data => $meta->{name}, sub { |
230 | my $rwops = new CFPlus::RW $_[0]; |
245 | my $rwops = new CFPlus::RW $_[0]; |
231 | my $chunk = new CFPlus::MixChunk $rwops; |
246 | my $chunk = new CFPlus::MixChunk $rwops |
|
|
247 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
232 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
248 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
233 | $AUDIO_CHUNK{$face} = $chunk; |
249 | $AUDIO_CHUNK{$face} = $chunk; |
234 | |
250 | |
235 | audio_sound_push ($face); |
251 | audio_sound_push ($face); |
236 | }; |
252 | }; |
… | |
… | |
241 | sub audio_sound_play { |
257 | sub audio_sound_play { |
242 | my ($face, $dx, $dy, $vol) = @_; |
258 | my ($face, $dx, $dy, $vol) = @_; |
243 | |
259 | |
244 | $SDL_MIXER |
260 | $SDL_MIXER |
245 | or return; |
261 | or return; |
|
|
262 | $CFG->{effects_enable} |
|
|
263 | or return; |
246 | |
264 | |
247 | my $queue = $AUDIO_PLAY{$face} ||= []; |
265 | my $queue = $AUDIO_PLAY{$face} ||= []; |
248 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
266 | push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events |
249 | audio_sound_push $face |
267 | audio_sound_push $face |
250 | unless @$queue > 1; |
268 | unless @$queue > 1; |
|
|
269 | } |
|
|
270 | |
|
|
271 | sub audio_music_set_meta { |
|
|
272 | my ($meta) = @_; |
|
|
273 | |
|
|
274 | $MUSIC_PLAYING_META = $meta; |
|
|
275 | $MUSIC_PLAYING_WIDGET->set_markup ( |
|
|
276 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
|
|
277 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
|
|
278 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
|
|
279 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
|
|
280 | ); |
251 | } |
281 | } |
252 | |
282 | |
253 | sub audio_music_update_volume { |
283 | sub audio_music_update_volume { |
254 | return unless $MUSIC_PLAYING_META; |
284 | return unless $MUSIC_PLAYING_META; |
255 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
285 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
… | |
… | |
274 | my $rwops = $meta->{path} |
304 | my $rwops = $meta->{path} |
275 | ? new_from_file CFPlus::RW $meta->{path} |
305 | ? new_from_file CFPlus::RW $meta->{path} |
276 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
306 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
277 | |
307 | |
278 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
308 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
279 | or ((warn CFPlus::Mix_GetError), return); # pretty fatal error |
309 | or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError; |
280 | |
310 | |
281 | my $NOW = time; |
311 | my $NOW = time; |
282 | |
312 | |
283 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
313 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
284 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
314 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
… | |
… | |
287 | } else { |
317 | } else { |
288 | $MUSIC_PLAYER->play (0); |
318 | $MUSIC_PLAYER->play (0); |
289 | $MUSIC_START = time; |
319 | $MUSIC_START = time; |
290 | } |
320 | } |
291 | |
321 | |
292 | delete $MUSIC_PLAYING_META->{stop_time}; |
322 | delete $meta->{stop_time}; |
293 | delete $MUSIC_PLAYING_META->{stop_pos}; |
323 | delete $meta->{stop_pos}; |
294 | } |
324 | } |
295 | } |
325 | } |
296 | |
326 | |
297 | sub audio_music_push { |
327 | sub audio_music_push { |
298 | return unless $SDL_MIXER; |
328 | return unless $SDL_MIXER; |
… | |
… | |
317 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
347 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
318 | $fade_out = 1000; |
348 | $fade_out = 1000; |
319 | } |
349 | } |
320 | |
350 | |
321 | # if the currently playing song is acceptable, let it continue |
351 | # if the currently playing song is acceptable, let it continue |
322 | return if $MUSIC_PLAYING_META |
|
|
323 | && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
352 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
324 | |
353 | |
325 | my $NOW = time; |
354 | my $NOW = time; |
326 | |
355 | |
327 | if ($MUSIC_PLAYING_META) { |
356 | if ($MUSIC_PLAYING_META) { |
328 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
357 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
… | |
… | |
332 | # sort by stop time, oldest first |
361 | # sort by stop time, oldest first |
333 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
362 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
334 | |
363 | |
335 | # if the most recently-played piece played very recently, |
364 | # if the most recently-played piece played very recently, |
336 | # resume it, else choose the oldest piece for rotation. |
365 | # resume it, else choose the oldest piece for rotation. |
337 | $MUSIC_PLAYING_META = |
366 | audio_music_set_meta |
338 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
367 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
339 | ? $MUSIC_HAVE[-1] |
368 | ? $MUSIC_HAVE[-1] |
340 | : $MUSIC_HAVE[0]; |
369 | : $MUSIC_HAVE[0]; |
341 | |
370 | |
342 | audio_music_start; |
371 | audio_music_start; |
… | |
… | |
349 | $MUSIC_WANT = $songs; |
378 | $MUSIC_WANT = $songs; |
350 | audio_music_push; |
379 | audio_music_push; |
351 | } |
380 | } |
352 | |
381 | |
353 | sub audio_music_finished { |
382 | sub audio_music_finished { |
|
|
383 | # we compress multiple jingles of the same type |
354 | shift @MUSIC_JINGLE |
384 | shift @MUSIC_JINGLE |
355 | if $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
385 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
|
|
386 | |
|
|
387 | $MUSIC_PLAYING_WIDGET->clear; |
356 | |
388 | |
357 | undef $MUSIC_PLAYER; |
389 | undef $MUSIC_PLAYER; |
358 | undef $MUSIC_PLAYING_META; |
390 | undef $MUSIC_PLAYING_META; |
359 | undef $MUSIC_PLAYING_DATA; |
391 | undef $MUSIC_PLAYING_DATA; |
360 | |
392 | |
361 | audio_music_push; |
393 | audio_music_push; |
362 | } |
394 | } |
363 | |
395 | |
|
|
396 | sub audio_init { |
|
|
397 | if ($CFG->{audio_enable}) { |
|
|
398 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
399 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
|
|
400 | |
|
|
401 | unless ($SDL_MIXER) { |
|
|
402 | status "Unable to open sound device: there will be no sound"; |
|
|
403 | return; |
|
|
404 | } |
|
|
405 | |
|
|
406 | CFPlus::Mix_AllocateChannels 16; |
|
|
407 | |
|
|
408 | audio_music_finished; |
|
|
409 | } else { |
|
|
410 | undef $SDL_MIXER; |
|
|
411 | } |
|
|
412 | } |
|
|
413 | |
|
|
414 | sub audio_shutdown { |
|
|
415 | undef $MUSIC_PLAYER; |
|
|
416 | undef $MUSIC_PLAYING_META; |
|
|
417 | undef $MUSIC_PLAYING_DATA; |
|
|
418 | |
|
|
419 | $MUSIC_WANT = []; |
|
|
420 | @MUSIC_JINGLE = (); |
|
|
421 | %AUDIO_PLAY = (); |
|
|
422 | %AUDIO_CHUNK = (); |
|
|
423 | |
|
|
424 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
|
|
425 | undef $SDL_MIXER; |
|
|
426 | } |
|
|
427 | |
364 | ############################################################################# |
428 | ############################################################################# |
365 | |
|
|
366 | sub status { |
|
|
367 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
|
|
368 | } |
|
|
369 | |
|
|
370 | sub debug { |
|
|
371 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
372 | } |
|
|
373 | |
|
|
374 | sub message { |
|
|
375 | my ($para) = @_; |
|
|
376 | $MESSAGE_WINDOW->message ($para); |
|
|
377 | } |
|
|
378 | |
429 | |
379 | sub destroy_query_dialog { |
430 | sub destroy_query_dialog { |
380 | (delete $_[0]{query_dialog})->destroy |
431 | (delete $_[0]{query_dialog})->destroy |
381 | if $_[0]{query_dialog}; |
432 | if $_[0]{query_dialog}; |
382 | } |
433 | } |
… | |
… | |
716 | state => $CFG->{fullscreen}, |
767 | state => $CFG->{fullscreen}, |
717 | tooltip => "Bring the client into fullscreen mode.", |
768 | tooltip => "Bring the client into fullscreen mode.", |
718 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
769 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
719 | ); |
770 | ); |
720 | |
771 | |
|
|
772 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
|
|
773 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
774 | state => $CFG->{opengl11}, |
|
|
775 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
|
|
776 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
|
|
777 | . "cards that claim to support a feature but fall back to software rendering. " |
|
|
778 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
|
|
779 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
|
|
780 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
781 | on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 } |
|
|
782 | ); |
|
|
783 | |
721 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
784 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
722 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
785 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
723 | state => $CFG->{fast}, |
786 | state => $CFG->{fast}, |
724 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
787 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
725 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
788 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
… | |
… | |
751 | |
814 | |
752 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
815 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
753 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
816 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
754 | state => $CFG->{map_smoothing}, |
817 | state => $CFG->{map_smoothing}, |
755 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
818 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
756 | . "This increases load on the graphics subsystem and works only with 2.x servers. " |
819 | . "This increases load on the graphics subsystem and works only with TRT servers. " |
757 | . "Changes take effect at next connection only.", |
820 | . "Changes take effect at next login only.", |
758 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
821 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
759 | ); |
822 | ); |
760 | |
823 | |
761 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
824 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
762 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
825 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
773 | ); |
836 | ); |
774 | |
837 | |
775 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
838 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
776 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
839 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
777 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
840 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
778 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", |
841 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, " |
|
|
842 | . "but you still need to press apply to correctly re-layout the widget.", |
779 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
843 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
780 | ); |
844 | ); |
781 | |
845 | |
782 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
846 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
783 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
847 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
… | |
… | |
805 | } |
869 | } |
806 | |
870 | |
807 | sub audio_setup { |
871 | sub audio_setup { |
808 | my $vbox = new CFPlus::UI::VBox; |
872 | my $vbox = new CFPlus::UI::VBox; |
809 | |
873 | |
810 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); |
874 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]); |
811 | |
875 | |
812 | my $row = 0; |
876 | my $row = 0; |
813 | |
877 | |
814 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
878 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
815 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
879 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
819 | ); |
883 | ); |
820 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
884 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
821 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
885 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
822 | # $CFG->{effects_volume} = $_[1]; |
886 | # $CFG->{effects_volume} = $_[1]; |
823 | # }); |
887 | # }); |
|
|
888 | |
|
|
889 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); |
|
|
890 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
|
|
891 | expand => 1, state => $CFG->{effects_enable}, |
|
|
892 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
|
|
893 | on_changed => sub { |
|
|
894 | $CFG->{effects_enable} = $_[1]; |
|
|
895 | $CONN->update_fx_want if $CONN; |
|
|
896 | 0 |
|
|
897 | } |
|
|
898 | ); |
|
|
899 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
|
|
900 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
|
|
901 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
|
|
902 | . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", |
|
|
903 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
|
|
904 | ); |
|
|
905 | |
824 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
906 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
825 | $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox); |
907 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
826 | $hbox->add (new CFPlus::UI::CheckBox |
|
|
827 | expand => 1, state => $CFG->{bgm_enable}, |
908 | expand => 1, state => $CFG->{bgm_enable}, |
828 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
909 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
829 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
910 | on_changed => sub { |
|
|
911 | $CFG->{bgm_enable} = $_[1]; |
|
|
912 | $CONN->update_fx_want if $CONN; |
|
|
913 | 0 |
|
|
914 | } |
830 | ); |
915 | ); |
831 | $hbox->add (new CFPlus::UI::Slider |
916 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
832 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
917 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
833 | tooltip => "The volume of the background music. Changes are instant.", |
918 | tooltip => "The volume of the background music. Changes are instant.", |
834 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
919 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
835 | ); |
920 | ); |
836 | |
921 | |
837 | $table->add_at (1, $row++, new CFPlus::UI::Button |
922 | $table->add_at (1, $row++, new CFPlus::UI::Button |
838 | expand => 1, align => 0, text => "Apply", |
923 | c_colspan => 2, expand => 1, align => 0, text => "Apply", |
839 | tooltip => "Apply the audio settings", |
924 | tooltip => "Apply the audio settings", |
840 | on_activate => sub { |
925 | on_activate => sub { |
841 | audio_shutdown (); |
926 | audio_shutdown (); |
842 | audio_init (); |
927 | audio_init (); |
843 | 0 |
928 | 0 |
… | |
… | |
914 | $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); |
999 | $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); |
915 | |
1000 | |
916 | $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# |
1001 | $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# |
917 | |
1002 | |
918 | $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); |
1003 | $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); |
919 | $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2); |
1004 | $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2); |
920 | $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1); |
1005 | $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1); |
921 | $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2); |
1006 | $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2); |
922 | $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1); |
1007 | $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1); |
923 | $t->add_at (1,1, new CFPlus::UI::Label text => "e"); |
1008 | $t->add_at (1,1, new CFPlus::UI::Label text => "e"); |
924 | |
1009 | |
925 | $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); |
1010 | $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); |
926 | |
1011 | |
927 | $c->add_items ({ |
1012 | $c->add_items ({ |
… | |
… | |
1523 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1608 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1524 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1609 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1525 | |
1610 | |
1526 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1611 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1527 | |
1612 | |
1528 | $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); |
1613 | $vb2->add ($INVR_HB = new CFPlus::UI::HBox); |
1529 | |
1614 | |
1530 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1615 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1531 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1616 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1532 | |
1617 | |
1533 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1618 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1534 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1619 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1535 | |
1620 | |
1536 | $hb |
1621 | $hb |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | sub media_window { |
|
|
1625 | my $vb = new CFPlus::UI::VBox; |
|
|
1626 | |
|
|
1627 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1628 | label => "Currently playing music", |
|
|
1629 | child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
|
|
1630 | child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8), |
|
|
1631 | ); |
|
|
1632 | |
|
|
1633 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1634 | label => "Other media used in this session", |
|
|
1635 | expand => 1, |
|
|
1636 | child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller |
|
|
1637 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
|
|
1638 | ); |
|
|
1639 | |
|
|
1640 | $vb |
|
|
1641 | } |
|
|
1642 | |
|
|
1643 | sub add_license { |
|
|
1644 | my ($meta) = @_; |
|
|
1645 | |
|
|
1646 | $meta = $meta->{meta} |
|
|
1647 | or return; |
|
|
1648 | |
|
|
1649 | $meta->{license} || $meta->{author} || $meta->{source} |
|
|
1650 | or return; |
|
|
1651 | |
|
|
1652 | $LICENSE_WIDGET->add_paragraph ({ |
|
|
1653 | fg => [1, 1, 1, 1], |
|
|
1654 | markup => "<small>" |
|
|
1655 | . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n" |
|
|
1656 | . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n" |
|
|
1657 | . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n" |
|
|
1658 | . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n" |
|
|
1659 | . "</small>", |
|
|
1660 | }); |
|
|
1661 | $LICENSE_WIDGET->scroll_to_bottom; |
1537 | } |
1662 | } |
1538 | |
1663 | |
1539 | sub toggle_player_page { |
1664 | sub toggle_player_page { |
1540 | my ($widget) = @_; |
1665 | my ($widget) = @_; |
1541 | |
1666 | |
… | |
… | |
1580 | $ntb->add_tab ( |
1705 | $ntb->add_tab ( |
1581 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1706 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1582 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1707 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1583 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1708 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1584 | ); |
1709 | ); |
1585 | $ntb->add_tab (Pickup => autopickup_setup, |
1710 | $ntb->add_tab (Pickup => autopickup_setup, |
1586 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1711 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
|
|
1712 | |
|
|
1713 | $ntb->add_tab (Media => media_window, |
|
|
1714 | "License, Author and Source info for media sent by the server."); |
1587 | |
1715 | |
1588 | $ntb->set_current_page ($INVENTORY_PAGE); |
1716 | $ntb->set_current_page ($INVENTORY_PAGE); |
1589 | |
1717 | |
1590 | $plwin->add ($ntb); |
1718 | $plwin->add ($ntb); |
1591 | $plwin |
1719 | $plwin |
… | |
… | |
1745 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1873 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1746 | ); |
1874 | ); |
1747 | $hb->add (new CFPlus::UI::Button |
1875 | $hb->add (new CFPlus::UI::Button |
1748 | text => "Quit anyway", |
1876 | text => "Quit anyway", |
1749 | expand => 1, |
1877 | expand => 1, |
1750 | on_activate => sub { exit }, |
1878 | on_activate => sub { Event::unloop_all }, |
1751 | ); |
1879 | ); |
1752 | } |
1880 | } |
1753 | |
1881 | |
1754 | $QUIT_DIALOG->show; |
1882 | $QUIT_DIALOG->show; |
1755 | $QUIT_DIALOG->grab_focus; |
1883 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
1949 | tooltip => "Terminates the program", |
2077 | tooltip => "Terminates the program", |
1950 | on_activate => sub { |
2078 | on_activate => sub { |
1951 | if ($CONN) { |
2079 | if ($CONN) { |
1952 | open_quit_dialog; |
2080 | open_quit_dialog; |
1953 | } else { |
2081 | } else { |
1954 | exit; |
2082 | Event::unloop_all; |
1955 | } |
2083 | } |
1956 | 0 |
2084 | 0 |
1957 | }, |
2085 | }, |
1958 | ); |
2086 | ); |
1959 | |
2087 | |
1960 | $BUTTONBAR->show; |
2088 | $BUTTONBAR->show; |
1961 | $SETUP_DIALOG->show; |
2089 | $SETUP_DIALOG->show; |
|
|
2090 | $MESSAGE_WINDOW->show; |
1962 | } |
2091 | } |
1963 | |
2092 | |
1964 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2093 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
1965 | } |
2094 | } |
1966 | |
2095 | |
… | |
… | |
1968 | CFPlus::OpenGL::shutdown; |
2097 | CFPlus::OpenGL::shutdown; |
1969 | |
2098 | |
1970 | undef $SDL_ACTIVE; |
2099 | undef $SDL_ACTIVE; |
1971 | } |
2100 | } |
1972 | |
2101 | |
1973 | sub audio_init { |
|
|
1974 | if ($CFG->{audio_enable}) { |
|
|
1975 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
1976 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
|
|
1977 | |
|
|
1978 | unless ($SDL_MIXER) { |
|
|
1979 | status "Unable to open sound device: there will be no sound"; |
|
|
1980 | return; |
|
|
1981 | } |
|
|
1982 | |
|
|
1983 | CFPlus::Mix_AllocateChannels 16; |
|
|
1984 | |
|
|
1985 | audio_music_finished; |
|
|
1986 | } else { |
|
|
1987 | undef $SDL_MIXER; |
|
|
1988 | } |
|
|
1989 | } |
|
|
1990 | |
|
|
1991 | sub audio_shutdown { |
|
|
1992 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
|
|
1993 | undef $SDL_MIXER; |
|
|
1994 | @SOUNDS = (); |
|
|
1995 | %AUDIO_CHUNK = (); |
|
|
1996 | } |
|
|
1997 | |
|
|
1998 | my %animate_object; |
2102 | my %animate_object; |
1999 | my $animate_timer; |
2103 | my $animate_timer; |
2000 | |
2104 | |
2001 | my $fps = 9; |
2105 | my $fps = 9; |
2002 | |
2106 | |
2003 | sub force_refresh { |
2107 | sub force_refresh { |
|
|
2108 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2004 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
2109 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2005 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2110 | debug sprintf "%3.2f", $fps; |
|
|
2111 | } |
2006 | |
2112 | |
2007 | $CFPlus::UI::ROOT->draw; |
2113 | $CFPlus::UI::ROOT->draw; |
2008 | |
2114 | CFPlus::SDL_GL_SwapBuffers; |
2009 | $WANT_REFRESH = 0; |
|
|
2010 | $CAN_REFRESH = 0; |
|
|
2011 | $LAST_REFRESH = $NOW; |
2115 | $LAST_REFRESH = $NOW; |
2012 | |
2116 | $WANT_REFRESH->stop; |
2013 | CFPlus::SDL_GL_SwapBuffers; |
|
|
2014 | } |
2117 | } |
2015 | |
2118 | |
|
|
2119 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
|
|
2120 | |
2016 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2121 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2017 | $NOW = time; |
2122 | $NOW = time; |
2018 | |
2123 | |
2019 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2124 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2020 | for CFPlus::poll_events; |
2125 | for CFPlus::poll_events; |
2021 | |
2126 | |
2022 | if (%animate_object) { |
2127 | if (%animate_object) { |
2023 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2128 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2024 | ++$WANT_REFRESH; |
2129 | $WANT_REFRESH->start; |
2025 | } |
|
|
2026 | |
|
|
2027 | if ($WANT_REFRESH) { |
|
|
2028 | force_refresh; |
|
|
2029 | } else { |
|
|
2030 | $CAN_REFRESH = 1; |
|
|
2031 | } |
2130 | } |
2032 | }); |
2131 | }); |
2033 | |
2132 | |
2034 | sub animation_start { |
2133 | sub animation_start { |
2035 | my ($widget) = @_; |
2134 | my ($widget) = @_; |
… | |
… | |
2093 | |
2192 | |
2094 | my %DEF_CFG = ( |
2193 | my %DEF_CFG = ( |
2095 | sdl_mode => 0, |
2194 | sdl_mode => 0, |
2096 | fullscreen => 0, |
2195 | fullscreen => 0, |
2097 | fast => 0, |
2196 | fast => 0, |
|
|
2197 | opengl11 => 0, |
2098 | map_scale => 1, |
2198 | map_scale => 1, |
2099 | fow_enable => 1, |
2199 | fow_enable => 1, |
2100 | fow_intensity => 0, |
2200 | fow_intensity => 0, |
2101 | map_smoothing => 1, |
2201 | map_smoothing => 1, |
2102 | gui_fontsize => 1, |
2202 | gui_fontsize => 1, |
… | |
… | |
2104 | gauge_fontsize => 1, |
2204 | gauge_fontsize => 1, |
2105 | gauge_size => 0.35, |
2205 | gauge_size => 0.35, |
2106 | stat_fontsize => 0.7, |
2206 | stat_fontsize => 0.7, |
2107 | mapsize => 100, |
2207 | mapsize => 100, |
2108 | audio_enable => 1, |
2208 | audio_enable => 1, |
|
|
2209 | effects_enable => 1, |
|
|
2210 | effects_volume => 1, |
2109 | bgm_enable => 1, |
2211 | bgm_enable => 1, |
2110 | bgm_volume => 0.25, |
2212 | bgm_volume => 0.5, |
2111 | output_sync => 1, |
2213 | output_sync => 1, |
2112 | output_count => 1, |
2214 | output_count => 1, |
2113 | output_rate => "", |
2215 | output_rate => "", |
2114 | pickup => 0, |
2216 | pickup => 0, |
2115 | inv_sort => "mtime", |
2217 | inv_sort => "mtime", |
… | |
… | |
2189 | } |
2291 | } |
2190 | |
2292 | |
2191 | show_tip_of_the_day if $CFG->{show_tips}; |
2293 | show_tip_of_the_day if $CFG->{show_tips}; |
2192 | |
2294 | |
2193 | Event::loop; |
2295 | Event::loop; |
|
|
2296 | |
|
|
2297 | #video_shutdown; |
|
|
2298 | #audio_shutdown; |
2194 | #CFPlus::SDL_Quit; |
2299 | CFPlus::SDL_Quit; |
2195 | #CFPlus::_exit 0; |
|
|
2196 | |
|
|
2197 | END { |
|
|
2198 | CFPlus::SDL_Quit; |
|
|
2199 | CFPlus::DB::Server::stop; |
2300 | CFPlus::DB::Server::stop; |
2200 | } |
|
|
2201 | |
2301 | |
2202 | =head1 NAME |
2302 | =head1 NAME |
2203 | |
2303 | |
2204 | cfplus - A Crossfire+ and Crossfire game client |
2304 | cfplus - A Crossfire TRT and Crossfire game client |
2205 | |
2305 | |
2206 | =head1 SYNOPSIS |
2306 | =head1 SYNOPSIS |
2207 | |
2307 | |
2208 | Just run it - no commandline arguments are supported. |
2308 | Just run it - no commandline arguments are supported. |
2209 | |
2309 | |
2210 | =head1 USAGE |
2310 | =head1 USAGE |
2211 | |
2311 | |
2212 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used |
2312 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to |
2213 | fullscreen and interactively. |
2313 | be used in fullscreen mode and interactively. |
2214 | |
2314 | |
2215 | =head1 DEBUGGING |
2315 | =head1 DEBUGGING |
2216 | |
2316 | |
2217 | |
2317 | |
2218 | CFPLUS_DEBUG - environment variable |
2318 | CFPLUS_DEBUG - environment variable |