--- deliantra/Deliantra-Client/bin/cfplus 2006/08/13 18:48:57 1.110
+++ deliantra/Deliantra-Client/bin/cfplus 2007/08/01 14:27:21 1.199
@@ -1,24 +1,69 @@
#!/opt/bin/perl
+my $startup_done = sub { };
+our $PANGO = "1.5.0";
+
+# do splash-screen thingy on win32
+BEGIN {
+ if (%PAR::LibCache && $^O eq "MSWin32") {
+ while (my ($filename, $zip) = each %PAR::LibCache) {
+ $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp");
+ }
+
+ require Win32::GUI::SplashScreen;
+
+ Win32::GUI::SplashScreen::Show (
+ -file => "$ENV{PAR_TEMP}/SPLASH.bmp",
+ );
+
+ $startup_done = sub {
+ Win32::GUI::SplashScreen::Done (1);
+ };
+ }
+}
+
use strict;
use utf8;
+use Carp 'verbose';
+
# do things only needed for single-binary version (par)
BEGIN {
if (%PAR::LibCache) {
@INC = grep ref, @INC; # weed out all paths except pars loader refs
+ my $tmp = $ENV{PAR_TEMP};
+
while (my ($filename, $zip) = each %PAR::LibCache) {
for ($zip->memberNames) {
- next unless /^\/root\/(.*)/;
- $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1")
- unless -e "$ENV{PAR_TEMP}/$1";
+ next unless /^root\/(.*)/;
+ $zip->extractMember ($_, "$tmp/$1")
+ unless -e "$tmp/$1";
}
}
- # TODO: pango-rc file, anybody?
+ if ($^O eq "MSWin32") {
+ # relocatable
+ } else {
+ # unix, need to patch pango rc file
+ open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules"
+ or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!";
+ local $/;
+ my $rc = <$fh>;
+ $rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones
+
+ mkdir "$tmp/pango-modules";
+ open my $fh, ">:perlio", "$tmp/pango-modules/pango.modules"
+ or die "$tmp/pango-modules/pango.modules: $!";
+ print $fh $rc;
+
+ $ENV{PANGO_RC_FILE} = "$tmp/pango.rc";
+ open my $fh, ">:perlio", $ENV{PANGO_RC_FILE}
+ or die "$ENV{PANGO_RC_FILE}: $!";
+ print $fh "[Pango]\nModuleFiles = $tmp/pango-modules\n";
+ }
- unshift @INC, $ENV{PAR_TEMP};
+ unshift @INC, $tmp;
}
}
@@ -28,6 +73,7 @@
use Time::HiRes 'time';
use Event;
+use List::Util qw(max min);
use Crossfire;
use Crossfire::Protocol::Constants;
@@ -37,42 +83,35 @@
use CFPlus;
use CFPlus::OpenGL ();
use CFPlus::Protocol;
+use CFPlus::DB;
use CFPlus::UI;
+use CFPlus::UI::Canvas;
+use CFPlus::UI::Inventory;
+use CFPlus::UI::SpellList;
+use CFPlus::UI::MessageWindow;
use CFPlus::Pod;
-use CFPlus::BindingEditor;
use CFPlus::MapWidget;
+use CFPlus::Macro;
$SIG{QUIT} = sub { Carp::cluck "QUIT" };
$SIG{PIPE} = 'IGNORE';
-$Event::Eval = 0;
+$Event::Eval = 1;
$Event::DIED = sub {
- # TODO: display dialog box or so
- Carp::cluck $_[1];#d#TODO: remove when stable
- CFPlus::error $_[1];
+ CFPlus::fatal Carp::longmess $_[1]
};
-$SIG{__DIE__} = sub {
- return if CFPlus::in_destruct;
- Carp::cluck $_[0];
- CFPlus::error $_[0];
- return;#d#
- #return unless defined $^S && !$^S;
- $Event::DIED->(undef, $_[0]);
-};
-
-our $VERSION = '0.1';
-
my $MAX_FPS = 60;
my $MIN_FPS = 5; # unused as of yet
-our $META_SERVER = "crossfire.real-time.com:13326";
+our $META_SERVER = "http://metaserver.schmorp.de/current.json";
our $LAST_REFRESH;
our $NOW;
our $CFG;
our $CONN;
+our $PROFILE; # current profile
our $FAST; # fast, low-quality mode, possibly useful for software-rendering
our $WANT_REFRESH;
@@ -91,8 +130,6 @@
our $MAPMAP;
our $MAPWIDGET;
our $BUTTONBAR;
-our $LOGVIEW;
-our $CONSOLE;
our $METASERVER;
our $LOGIN_BUTTON;
our $QUIT_DIALOG;
@@ -113,6 +150,7 @@
our $STATS_PAGE;
our $SKILL_PAGE;
our $SPELL_PAGE;
+our $SPELL_LIST;
our $HELP_WINDOW;
our $MESSAGE_WINDOW;
@@ -123,10 +161,6 @@
our $SDL_ACTIVE;
our %SDL_CB;
-our $SDL_MIXER;
-our @SOUNDS; # event => file mapping
-our %AUDIO_CHUNKS; # audio files
-
our $ALT_ENTER_MESSAGE;
our $STATUSBOX;
our $DEBUG_STATUS;
@@ -135,11 +169,10 @@
our $INVR;
our $INV_RIGHT_HB;
-our $BIND_EDITOR;
-our $BIND_UPD_CB;
-
our $PICKUP_CFG;
+#############################################################################
+
sub status {
$STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
}
@@ -148,16 +181,268 @@
$DEBUG_STATUS->set_text ($_[0]);
}
+sub message {
+ my ($para) = @_;
+ $MESSAGE_WINDOW->message ($para);
+}
+
+#############################################################################
+#TODO: maybe move into own audio module...
+
+our $SDL_MIXER;
+
+our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
+our $MUSIC_WANT; # arryref of ambient music we want to play
+our @MUSIC_HAVE; # ambient music we have on disk
+our $MUSIC_START;
+our @MUSIC_JINGLE; # which jingles to play next
+our $MUSIC_PLAYING_DATA;
+our $MUSIC_PLAYING_META;
+our $MUSIC_PLAYER;
+our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before
+
+our %AUDIO_CHUNK; # audio "files"
+our %AUDIO_PLAY; # which audio faces should be played
+
+sub audio_channel_finished {
+ my ($channel) = @_;
+
+# warn "channel $channel finished\n";#d#
+}
+
+sub audio_sound_push($) {
+ my ($face) = @_;
+
+ $CFG->{effects_enable}
+ or return;
+
+ if (my $chunk = $AUDIO_CHUNK{$face}) {
+ for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
+ my (undef, $dx, $dy, $vol) = @$_;
+
+ my $channel = CFPlus::Channel::find;
+ $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
+ $dx = $dx / 10 * 255;
+ $channel->set_panning (255 - $dx, 255 + $dx);
+
+# my $angle = $dx ? : $dx < 0 ?
+# my $distance = -$vol;
+# $channel->set_position ($angle, $distance);
+
+ $chunk->play ($channel);
+ }
+ } else {
+ # sound_meta not set means data is in flight either way
+ my $meta = $CONN->{sound_meta}{$face}
+ or return;
+
+ # if its a jingle, play it as ambient music
+ if ($meta->{meta}{jingle}) {
+ delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue
+ push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
+ &audio_music_push ($face);
+ } else {
+ # fetch from database
+ CFPlus::DB::get res_data => $meta->{name}, sub {
+ my $rwops = new CFPlus::RW $_[0];
+ my $chunk = new CFPlus::MixChunk $rwops;
+ $chunk->volume (($meta->{meta}{volume} || 1) * 128);
+ $AUDIO_CHUNK{$face} = $chunk;
+
+ audio_sound_push ($face);
+ };
+ }
+ }
+}
+
+sub audio_sound_play {
+ my ($face, $dx, $dy, $vol) = @_;
+
+ $SDL_MIXER
+ or return;
+ $CFG->{effects_enable}
+ or return;
+
+ my $queue = $AUDIO_PLAY{$face} ||= [];
+ push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
+ audio_sound_push $face
+ unless @$queue > 1;
+}
+
+sub audio_music_update_volume {
+ return unless $MUSIC_PLAYING_META;
+ my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1;
+ my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume};
+ CFPlus::MixMusic::volume $base * $volume * 128;
+}
+
+sub audio_music_start {
+ my $meta = $MUSIC_PLAYING_META;
+
+ CFPlus::DB::get res_data => $meta->{name}, sub {
+ return unless $SDL_MIXER;
+
+ # music might have changed...
+ $meta eq $MUSIC_PLAYING_META
+ or return &audio_music_start ();
+
+ audio_music_update_volume;
+
+ $MUSIC_PLAYING_DATA = \$_[0];
+
+ my $rwops = $meta->{path}
+ ? new_from_file CFPlus::RW $meta->{path}
+ : new CFPlus::RW $$MUSIC_PLAYING_DATA;
+
+ $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
+ or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
+
+ my $NOW = time;
+
+ if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
+ my $pos = $MUSIC_PLAYING_META->{stop_pos};
+ $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
+ $MUSIC_START = time - $pos;
+ } else {
+ $MUSIC_PLAYER->play (0);
+ $MUSIC_START = time;
+ }
+
+ delete $MUSIC_PLAYING_META->{stop_time};
+ delete $MUSIC_PLAYING_META->{stop_pos};
+ }
+}
+
+sub audio_music_push {
+ return unless $SDL_MIXER;
+
+ my $fade_out;
+
+ if (@MUSIC_JINGLE) {
+ @MUSIC_HAVE = $MUSIC_JINGLE[0];
+ $fade_out = 333;
+ } else {
+ return unless $CFG->{bgm_enable};
+
+ my @have =
+ grep $_,
+ map $CONN->{music_meta}{$_},
+ @$MUSIC_WANT;
+
+ @MUSIC_HAVE = @have
+ if @have;
+
+ # default MUSIC_HAVE == MUSIC_DEFAULT
+ @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
+ $fade_out = 1000;
+ }
+
+ # if the currently playing song is acceptable, let it continue
+ return if $MUSIC_PLAYING_META
+ && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
+
+ my $NOW = time;
+
+ if ($MUSIC_PLAYING_META) {
+ $MUSIC_PLAYING_META->{stop_time} = $NOW;
+ $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
+ CFPlus::MixMusic::fade_out $fade_out;
+ } else {
+ # sort by stop time, oldest first
+ @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
+
+ # if the most recently-played piece played very recently,
+ # resume it, else choose the oldest piece for rotation.
+ $MUSIC_PLAYING_META =
+ $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
+ ? $MUSIC_HAVE[-1]
+ : $MUSIC_HAVE[0];
+
+ audio_music_start;
+ }
+}
+
+sub audio_music_set_ambient {
+ my ($songs) = @_;
+
+ $MUSIC_WANT = $songs;
+ audio_music_push;
+}
+
+sub audio_music_finished {
+ # we compress multiple jingles of the same type
+ shift @MUSIC_JINGLE
+ while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
+
+ undef $MUSIC_PLAYER;
+ undef $MUSIC_PLAYING_META;
+ undef $MUSIC_PLAYING_DATA;
+
+ audio_music_push;
+}
+
+sub audio_init {
+ if ($CFG->{audio_enable}) {
+ $ENV{MIX_EFFECTSMAXSPEED} = 1;
+ $SDL_MIXER = !CFPlus::Mix_OpenAudio;
+
+ unless ($SDL_MIXER) {
+ status "Unable to open sound device: there will be no sound";
+ return;
+ }
+
+ CFPlus::Mix_AllocateChannels 16;
+
+ audio_music_finished;
+ } else {
+ undef $SDL_MIXER;
+ }
+}
+
+sub audio_shutdown {
+ undef $MUSIC_PLAYER;
+ undef $MUSIC_PLAYING_META;
+ undef $MUSIC_PLAYING_DATA;
+
+ $MUSIC_WANT = [];
+ @MUSIC_JINGLE = ();
+ %AUDIO_PLAY = ();
+ %AUDIO_CHUNK = ();
+
+ CFPlus::Mix_CloseAudio if $SDL_MIXER;
+ undef $SDL_MIXER;
+}
+
+#############################################################################
+
sub destroy_query_dialog {
(delete $_[0]{query_dialog})->destroy
if $_[0]{query_dialog};
}
+# FIXME: a very ugly hack to wait for stat update look below! #d#
+our $QUERY_TIMER; #d#
+
# server query dialog
sub server_query {
my ($conn, $flags, $prompt) = @_;
- $conn->{query_dialog} = my $dialog = new CFPlus::UI::FancyFrame
+ # FIXME: a very ugly hack to wait for stat update #d#
+ if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) {
+ unless ($QUERY_TIMER) {
+ $QUERY_TIMER =
+ Event->timer (
+ after => 1,
+ cb => sub {
+ server_query ($conn, $flags, $prompt, 1);
+ $QUERY_TIMER = undef
+ }
+ );
+ return;
+ }
+ }
+
+ $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel
x => "center",
y => "center",
title => "Server Query",
@@ -165,7 +450,7 @@
;
my @dialog = my $label = new CFPlus::UI::Label
- max_w => $::WIDTH * 0.4,
+ max_w => $::WIDTH * 0.8,
ellipsise => 0,
text => $prompt;
@@ -192,19 +477,17 @@
$dialog->grab_focus;
} elsif ($flags & CS_QUERY_SINGLECHAR) {
- $dialog->{tooltip} = "#charcreation_focus";
-
if ($prompt =~ /Now choose a character|Press any key for the next race/i) {
- $MESSAGE_WINDOW->show;
+ $dialog->{tooltip} = "#charcreation_focus";
unshift @dialog, new CFPlus::UI::Label
- max_w => $::WIDTH * 0.4,
+ max_w => $::WIDTH * 0.8,
ellipsise => 0,
markup => "\nOr use your keyboard and the text entry below:\n";
unshift @dialog, my $table = new CFPlus::UI::Table;
- $table->add (0, 0, new CFPlus::UI::Button
+ $table->add_at (0, 0, new CFPlus::UI::Button
text => "Next Race",
on_activate => sub {
$conn->send ("reply n");
@@ -212,7 +495,7 @@
0
},
);
- $table->add (2, 0, new CFPlus::UI::Button
+ $table->add_at (2, 0, new CFPlus::UI::Button
text => "Accept",
on_activate => sub {
$conn->send ("reply d");
@@ -221,6 +504,29 @@
},
);
+ if ($conn->{chargen_race_description}) {
+ unshift @dialog, new CFPlus::UI::Label
+ max_w => $::WIDTH * 0.8,
+ ellipsise => 0,
+ markup => "$conn->{chargen_race_description}",
+ ;
+ }
+
+ unshift @dialog, new CFPlus::UI::Face
+ face => $conn->{player}{face},
+ bg => [.2, .2, .2, 1],
+ min_w => 64,
+ min_h => 64,
+ ;
+
+ if ($conn->{chargen_race_title}) {
+ unshift @dialog, new CFPlus::UI::Label
+ allign => 1,
+ ellipsise => 0,
+ markup => "Race: $conn->{chargen_race_title}",
+ ;
+ }
+
unshift @dialog, new CFPlus::UI::Label
max_w => $::WIDTH * 0.4,
ellipsise => 0,
@@ -234,9 +540,6 @@
return;
}
- $STATS_PAGE->show;
- $MESSAGE_WINDOW->hide;
-
unshift @dialog, new CFPlus::UI::Label
max_w => $::WIDTH * 0.4,
ellipsise => 0,
@@ -245,7 +548,7 @@
unshift @dialog, my $table = new CFPlus::UI::Table;
# left: re-roll
- $table->add (0, 0, new CFPlus::UI::Button
+ $table->add_at (0, 0, new CFPlus::UI::Button
text => "Roll Again",
on_activate => sub {
$conn->send ("reply y");
@@ -269,7 +572,7 @@
],
), 1 .. 2;
- $table->add (2, 0, new CFPlus::UI::Button
+ $table->add_at (2, 0, new CFPlus::UI::Button
text => "Swap Stats",
on_activate => sub {
$conn->{stat_change_with} = $sw2->{value};
@@ -278,10 +581,10 @@
0
},
);
- $table->add (2, 1, new CFPlus::UI::HBox children => [$sw1, $sw2]);
+ $table->add_at (2, 1, new CFPlus::UI::HBox children => [$sw1, $sw2]);
# right: accept
- $table->add (4, 0, new CFPlus::UI::Button
+ $table->add_at (4, 0, new CFPlus::UI::Button
text => "Accept",
on_activate => sub {
$conn->send ("reply n");
@@ -356,36 +659,29 @@
my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
- my ($host, $port) = split /:/, $CFG->{profile}{default}{host};
+ my ($host, $port) = split /:/, $PROFILE->{host};
- $MAP = new CFPlus::Map $mapsize, $mapsize;
+ $MAP = new CFPlus::Map;
$CONN = eval {
new CFPlus::Protocol
host => $host,
port => $port || 13327,
- user => $CFG->{profile}{default}{user},
- pass => $CFG->{profile}{default}{password},
+ user => $PROFILE->{user},
+ pass => $PROFILE->{password},
mapw => $mapsize,
maph => $mapsize,
+ client => "cfplus $CFPlus::VERSION $] $^O",
+
map_widget => $MAPWIDGET,
- logview => $LOGVIEW,
statusbox => $STATUSBOX,
map => $MAP,
mapmap => $MAPMAP,
query => \&server_query,
- sound_play => sub {
- my ($x, $y, $soundnum, $type) = @_;
-
- $SDL_MIXER
- or return;
-
- my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
- or return;
-
- $chunk->play;
+ setup_req => {
+ smoothing => $CFG->{map_smoothing}*1,
},
};
@@ -404,7 +700,10 @@
$SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
$SETUP_DIALOG->show;
$PL_WINDOW->hide;
- $SPELL_PAGE->clear_spells;
+ $SPELL_LIST->clear_spells;
+ $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
+
+ &audio_music_set_ambient ([]);
return unless $CONN;
@@ -422,85 +721,105 @@
$vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]);
- $table->add (0, 0, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode");
- $table->add (1, 0, my $hbox = new CFPlus::UI::HBox);
+ my $row = 0;
- $hbox->add (my $mode_slider = new CFPlus::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]);
- $hbox->add (my $mode_label = new CFPlus::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "OpenGL Info");
+ $table->add_at (1, $row++, new CFPlus::UI::Label valign => 0, fontsize => 0.8, text => CFPlus::OpenGL::gl_vendor . ", " . CFPlus::OpenGL::gl_version,
+ can_events => 1,
+ tooltip => "" . (CFPlus::OpenGL::gl_extensions) . "");
+
+ my $vidmode_tooltip =
+ "Video Mode. The video mode to use for fullscreen (and the window size for windowed operation). "
+ . "The format is width x height \@ depth-per-channel + alpha-channel.";
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode");
+ $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox);
+
+ $hbox->add (my $mode_slider = new CFPlus::UI::Slider
+ force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1],
+ tooltip => $vidmode_tooltip);
+ $hbox->add (my $mode_label = new CFPlus::UI::Label
+ align => 0, valign => 0, height => 0.8, template => "9999x9999@9+9",
+ can_events => 1, tooltip => $vidmode_tooltip);
$mode_slider->connect (changed => sub {
my ($self, $value) = @_;
$CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
- $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
+ $mode_label->set_text (sprintf '%dx%d@%d+%d', @{$SDL_MODES[$value]});
});
$mode_slider->emit (changed => $mode_slider->{range}[0]);
- my $row = 1;
-
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fullscreen");
- $table->add (1, $row++, $FULLSCREEN_ENABLE = new CFPlus::UI::CheckBox
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fullscreen");
+ $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new CFPlus::UI::CheckBox
state => $CFG->{fullscreen},
tooltip => "Bring the client into fullscreen mode.",
on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
- $table->add (1, $row++, new CFPlus::UI::CheckBox
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{fast},
tooltip => "Lower the visual quality considerably to speed up rendering.",
on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Scale");
- $table->add (1, $row++, new CFPlus::UI::Slider
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
+ range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1],
+ tooltip => "The base font size used by most GUI elements that do not have their own setting.",
+ on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 },
+ );
+
+ $table->add_at (1, $row++, new CFPlus::UI::Button
+ expand => 1, align => 0, text => "Apply",
+ tooltip => "Apply the video settings above.",
+ on_activate => sub {
+ video_shutdown ();
+ video_init ();
+ 0
+ }
+ );
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Scale");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
range => [(log $CFG->{map_scale}) / (log 2), -3, 1, 0, 1],
tooltip => "Enlarge or shrink the displayed map. Changes are instant.",
on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
- $table->add (1, $row++, new CFPlus::UI::CheckBox
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
+ state => $CFG->{map_smoothing},
+ tooltip => "Map Smoothing tries to make tile borders less square. "
+ . "This increases load on the graphics subsystem and works only with 2.x servers. "
+ . "Changes take effect at next connection only.",
+ on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
+ );
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{fow_enable},
tooltip => "Fog-of-War marks areas that cannot be seen by the player. Changes are instant.",
on_changed => sub { my ($self, $value) = @_; $CFG->{fow_enable} = $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Intensity");
- $table->add (1, $row++, new CFPlus::UI::Slider
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Intensity");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{fow_intensity}, 0, 1, 0, 1 / 256],
tooltip => "Fog of War Lightness. The higher the intensity, the lighter the Fog-of-War color. Changes are instant.",
on_changed => sub { my ($self, $value) = @_; $CFG->{fow_intensity} = $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Smooth");
- $table->add (1, $row++, new CFPlus::UI::CheckBox
- state => $CFG->{fow_smooth},
- tooltip => "Smooth the Fog-of-War a bit to make it more realistic. Changes are instant.",
- on_changed => sub {
- my ($self, $value) = @_;
- $CFG->{fow_smooth} = $value;
- status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFPlus::OpenGL::GL_VERSION < 1.2;
- 0
- }
- );
-
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
- $table->add (1, $row++, new CFPlus::UI::Slider
- range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1],
- tooltip => "The base font size used by most GUI elements that do not have their own setting.",
- on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 },
- );
-
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
- $table->add (1, $row++, new CFPlus::UI::Slider
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
tooltip => "The font size used by the message/server log window only. Changes are instant.",
- on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
+ on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
- $table->add (1, $row++, new CFPlus::UI::Slider
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1],
tooltip => "Adjusts the fontsize of the gauges at the bottom right. Changes are instant.",
on_changed => sub {
@@ -510,8 +829,8 @@
}
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge size");
- $table->add (1, $row++, new CFPlus::UI::Slider
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge size");
+ $table->add_at (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{gauge_size}, 0.2, 0.8],
tooltip => "Adjust the size of the stats gauges at the bottom right. Changes are instant.",
on_changed => sub {
@@ -521,51 +840,54 @@
}
);
- $table->add (1, $row++, new CFPlus::UI::Button
- expand => 1, align => 0, text => "Apply",
- tooltip => "Apply the video settings",
- on_activate => sub {
- video_shutdown ();
- video_init ();
- 0
- }
- );
-
$vbox
}
sub audio_setup {
my $vbox = new CFPlus::UI::VBox;
- $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]);
+ $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]);
my $row = 0;
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable");
- $table->add (1, $row++, new CFPlus::UI::CheckBox
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{audio_enable},
tooltip => "Master Audio Enable. If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.",
on_changed => sub { $CFG->{audio_enable} = $_[1]; 0 }
);
-# $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
-# $table->add (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
+# $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
+# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
# $CFG->{effects_volume} = $_[1];
# });
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
- $table->add (1, $row++, my $hbox = new CFPlus::UI::HBox);
- $hbox->add (new CFPlus::UI::CheckBox
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume");
+ $table->add_at (1, $row, new CFPlus::UI::CheckBox
+ expand => 1, state => $CFG->{effects_enable},
+ tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
+ on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 }
+ );
+ $table->add_at (2, $row++, new CFPlus::UI::Slider
+ expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
+ tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
+ . "is set highest and you use your operating system volume setting. Changes are instant.",
+ on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
+ );
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
+ $table->add_at (1, $row, new CFPlus::UI::CheckBox
expand => 1, state => $CFG->{bgm_enable},
tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
);
- $hbox->add (new CFPlus::UI::Slider
+ $table->add_at (2, $row++, new CFPlus::UI::Slider
expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
tooltip => "The volume of the background music. Changes are instant.",
- on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 }
+ on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
);
- $table->add (1, $row++, new CFPlus::UI::Button
- expand => 1, align => 0, text => "Apply",
+ $table->add_at (1, $row++, new CFPlus::UI::Button
+ c_colspan => 2, expand => 1, align => 0, text => "Apply",
tooltip => "Apply the audio settings",
on_activate => sub {
audio_shutdown ();
@@ -633,27 +955,50 @@
sub debug_setup {
my $table = new CFPlus::UI::Table;
- $table->add (0, 0, new CFPlus::UI::Label text => "Widget Borders");
- $table->add (1, 0, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 1; 0 });
- $table->add (0, 1, new CFPlus::UI::Label text => "Tooltip Widget Info");
- $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 });
- $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS");
- $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 });
- $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips");
- $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
-
- my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05);
-
- for my $x (0..2) {
- for my $y (0 .. 2) {
- $table->add ($x + 3, $y,
- new CFPlus::UI::Entry
- text => $default_smooth[$x * 3 + $y],
- on_changed => sub { $MAP->{smooth_matrix}[$x * 3 + $y] = $_[1] if $MAP; 0 },
- );
- }
- }
+ $table->add_at (0, 0, new CFPlus::UI::Label text => "Widget Borders");
+ $table->add_at (1, 0, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 1; 0 });
+ $table->add_at (0, 1, new CFPlus::UI::Label text => "Tooltip Widget Info");
+ $table->add_at (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 });
+ $table->add_at (0, 2, new CFPlus::UI::Label text => "Show FPS");
+ $table->add_at (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 });
+ $table->add_at (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips");
+ $table->add_at (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
+ $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
+
+ $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
+
+ $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
+ $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2);
+ $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1);
+ $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2);
+ $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1);
+ $t->add_at (1,1, new CFPlus::UI::Label text => "e");
+
+ $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
+
+ $c->add_items ({
+ type => "line_loop",
+ color => [0, 1, 0],
+ width => 9,
+ coord_mode => "abs",
+ coord => [[10, 5], [5, 50], [20, 5], [5, 60]],
+ });
+
+ $c->add_items ({
+ type => "lines",
+ color => [1, 1, 0],
+ width => 2,
+ coord_mode => "rel",
+ coord => [[0,0], [1,1], [1,0], [0,1]],
+ });
+ $c->add_items ({
+ type => "polygon",
+ color => [0, 0.43, 0],
+ width => 2,
+ coord_mode => "rel",
+ coord => [[0,0.2], [1,.4], [1,.6], [0,.8]],
+ });
$table
}
@@ -665,14 +1010,19 @@
);
$r->add (my $vb = new CFPlus::UI::VBox);
- $vb->add ($STATWIDS->{title} = new CFPlus::UI::Label valign => 0, align => -1, text => "Title:", expand => 1,
+ $vb->add (new CFPlus::UI::FancyFrame
+ label => "Player",
+ child => (my $pi = new CFPlus::UI::VBox),
+ );
+
+ $pi->add ($STATWIDS->{title} = new CFPlus::UI::Label valign => 0, align => -1, text => "Title:", expand => 1,
can_hover => 1, can_events => 1,
tooltip => "Your name and title. You can change your title by using the title command, if supported by the server.");
- $vb->add ($STATWIDS->{map} = new CFPlus::UI::Label valign => 0, align => -1, text => "Map:", expand => 1,
+ $pi->add ($STATWIDS->{map} = new CFPlus::UI::Label valign => 0, align => -1, text => "Map:", expand => 1,
can_hover => 1, can_events => 1,
tooltip => "The map you are currently on (if supported by the server).");
- $vb->add (my $hb0 = new CFPlus::UI::HBox);
+ $pi->add (my $hb0 = new CFPlus::UI::HBox);
$hb0->add ($STATWIDS->{weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1,
can_hover => 1, can_events => 1,
tooltip => "The weight of the player including all inventory items.");
@@ -680,7 +1030,10 @@
can_hover => 1, can_events => 1,
tooltip => "The weight limit: you cannot carry more than this.");
- $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
+ $vb->add (new CFPlus::UI::FancyFrame
+ label => "Primary/Secondary Statistics",
+ child => (my $hb = new CFPlus::UI::HBox expand => 1),
+ );
$hb->add (my $tbl = new CFPlus::UI::Table expand => 1);
my $color2 = [1, 1, 0];
@@ -703,15 +1056,18 @@
) {
my ($col, $row, $id, $label, $template) = @$_;
- $tbl->add ($col , $row, $STATWIDS->{$id} = new CFPlus::UI::Label
+ $tbl->add_at ($col , $row, $STATWIDS->{$id} = new CFPlus::UI::Label
font => $FONT_FIXED, can_hover => 1, can_events => 1, valign => 0,
align => +1, template => $template, tooltip => "#stat_$label");
- $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFPlus::UI::Label
+ $tbl->add_at ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFPlus::UI::Label
font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2, valign => 0,
align => -1, text => $label, tooltip => "#stat_$label");
}
- $vb->add (my $tbl2 = new CFPlus::UI::Table expand => 1);
+ $vb->add (new CFPlus::UI::FancyFrame
+ label => "Resistancies",
+ child => (my $tbl2 = new CFPlus::UI::Table expand => 1),
+ );
my $row = 0;
my $col = 0;
@@ -754,11 +1110,12 @@
ghit => ["Ghost hit",
"Ghost hit (special attack used by ghosts and ghost-like beings)"],
);
+
for (qw/slow holyw conf fire depl magic
drain acid pois para deat phys
blind fear tund elec cold ghit/)
{
- $tbl2->add ($col, $row,
+ $tbl2->add_at ($col, $row,
$STATWIDS->{"res_$_"} =
new CFPlus::UI::Label
font => $FONT_FIXED,
@@ -769,14 +1126,14 @@
can_hover => 1,
tooltip => $resist_names{$_}->[1],
);
- $tbl2->add ($col + 1, $row, new CFPlus::UI::Image
+ $tbl2->add_at ($col + 1, $row, new CFPlus::UI::Image
font => $FONT_FIXED,
can_hover => 1,
can_events => 1,
path => "ui/resist/resist_$_.png",
tooltip => $resist_names{$_}->[1],
);
- $tbl2->add ($col + 2, $row, new CFPlus::UI::Label
+ $tbl2->add_at ($col + 2, $row, new CFPlus::UI::Label
text => $resist_names{$_}->[0],
font => $FONT_FIXED,
can_hover => 1,
@@ -819,29 +1176,17 @@
my $table = $METASERVER->{table};
$table->clear;
- $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
+ $table->add_at (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
- my $buf;
+ my $ok = 0;
- my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
-
- unless ($fh) {
- $label->set_text ("unable to contact metaserver: $!");
- return;
- }
-
- Event->io (fd => $fh, poll => 'r', cb => sub {
- my $res = sysread $fh, $buf, 8192, length $buf;
-
- if (!defined $res) {
- $_[0]->w->cancel;
- $label->set_text ("error while retrieving server list: $!");
- } elsif ($res == 0) {
- $_[0]->w->cancel;
- status "server list retrieved";
-
- utf8::decode $buf if utf8::valid $buf;
+ CFPlus::background {
+ my $ua = CFPlus::lwp_useragent;
+ CFPlus::background_msg CFPlus::from_json +(CFPlus::lwp_check $ua->get ($META_SERVER))->decoded_content;
+ } sub {
+ my ($msg) = @_;
+ if ($msg) {
$table->clear;
my @tip = (
@@ -852,7 +1197,7 @@
"Short information about this server provided by its admins.",
);
my @col = qw(#Users Host Uptime Version Description);
- $table->add ($_, 0, new CFPlus::UI::Label
+ $table->add_at ($_, 0, new CFPlus::UI::Label
can_hover => 1, can_events => 1,
align => 0, fg => [1, 1, 0],
text => $col[$_], tooltip => $tip[$_])
@@ -861,29 +1206,30 @@
my @align = qw(1 0 1 1 -1);
my $y = 0;
- for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) {
- my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m;
+ for my $m (@{ $msg->{servers} }) {
+ my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime, $highlight) =
+ @$m{qw(ip age hostname users version description ibytes obytes uptime highlight)};
for ($desc) {
s/
/\n/gi;
s/