--- deliantra/Deliantra-Client/bin/cfplus 2006/08/14 04:15:04 1.116
+++ deliantra/Deliantra-Client/bin/cfplus 2007/07/29 03:58:26 1.188
@@ -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;
}
}
@@ -37,42 +82,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];
-};
-
-$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]);
+ CFPlus::fatal Carp::longmess $_[1]
};
-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 +129,6 @@
our $MAPMAP;
our $MAPWIDGET;
our $BUTTONBAR;
-our $LOGVIEW;
-our $CONSOLE;
our $METASERVER;
our $LOGIN_BUTTON;
our $QUIT_DIALOG;
@@ -113,6 +149,7 @@
our $STATS_PAGE;
our $SKILL_PAGE;
our $SPELL_PAGE;
+our $SPELL_LIST;
our $HELP_WINDOW;
our $MESSAGE_WINDOW;
@@ -124,6 +161,12 @@
our %SDL_CB;
our $SDL_MIXER;
+our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
+our @MUSIC_WANT;
+our $MUSIC_START;
+our $MUSIC_PLAYING;
+our $MUSIC_PLAYER;
+our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
our @SOUNDS; # event => file mapping
our %AUDIO_CHUNKS; # audio files
@@ -135,9 +178,6 @@
our $INVR;
our $INV_RIGHT_HB;
-our $BIND_EDITOR;
-our $BIND_UPD_CB;
-
our $PICKUP_CFG;
sub status {
@@ -148,15 +188,38 @@
$DEBUG_STATUS->set_text ($_[0]);
}
+sub message {
+ my ($para) = @_;
+ $MESSAGE_WINDOW->message ($para);
+}
+
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) = @_;
+ # 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",
@@ -165,7 +228,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 +255,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 +273,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 +282,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 +318,6 @@
return;
}
- $STATS_PAGE->show;
- $MESSAGE_WINDOW->hide;
-
unshift @dialog, new CFPlus::UI::Label
max_w => $::WIDTH * 0.4,
ellipsise => 0,
@@ -245,7 +326,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 +350,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 +359,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,26 +437,31 @@
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,
+ setup_req => {
+ smoothing => $CFG->{map_smoothing}*1,
+ },
+
sound_play => sub {
my ($x, $y, $soundnum, $type) = @_;
@@ -404,7 +490,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 ([]);
return unless $CONN;
@@ -422,85 +511,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 +619,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,16 +630,6 @@
}
);
- $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
}
@@ -541,18 +640,18 @@
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);
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
+ $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox);
$hbox->add (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.",
@@ -564,7 +663,7 @@
on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 }
);
- $table->add (1, $row++, new CFPlus::UI::Button
+ $table->add_at (1, $row++, new CFPlus::UI::Button
expand => 1, align => 0, text => "Apply",
tooltip => "Apply the audio settings",
on_activate => sub {
@@ -633,27 +732,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", rowspan => 1, colspan => 2);
+ $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1);
+ $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2);
+ $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, 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
}
@@ -711,10 +833,10 @@
) {
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");
}
@@ -765,11 +887,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,
@@ -780,14 +903,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,
@@ -830,29 +953,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 = (
@@ -863,7 +974,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[$_])
@@ -872,29 +983,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/