ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/cfplus
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.122 by root, Sun Oct 8 21:22:30 2006 UTC vs.
Revision 1.133 by root, Sun Dec 3 01:03:49 2006 UTC

2 2
3my $startup_done = sub { }; 3my $startup_done = sub { };
4 4
5# do splash-screen thingy on win32 5# do splash-screen thingy on win32
6BEGIN { 6BEGIN {
7 if ($^O eq "MSWin32") { 7 if (%PAR::LibCache && $^O eq "MSWin32") {
8 while (my ($filename, $zip) = each %PAR::LibCache) { 8 while (my ($filename, $zip) = each %PAR::LibCache) {
9 $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp"); 9 $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp");
10 } 10 }
11 11
12 require Win32::GUI::SplashScreen; 12 require Win32::GUI::SplashScreen;
21 } 21 }
22} 22}
23 23
24use strict; 24use strict;
25use utf8; 25use utf8;
26
27use Carp 'verbose';
26 28
27# do things only needed for single-binary version (par) 29# do things only needed for single-binary version (par)
28BEGIN { 30BEGIN {
29 if (%PAR::LibCache) { 31 if (%PAR::LibCache) {
30 @INC = grep ref, @INC; # weed out all paths except pars loader refs 32 @INC = grep ref, @INC; # weed out all paths except pars loader refs
66$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 68$SIG{QUIT} = sub { Carp::cluck "QUIT" };
67$SIG{PIPE} = 'IGNORE'; 69$SIG{PIPE} = 'IGNORE';
68 70
69$Event::Eval = 0; 71$Event::Eval = 0;
70$Event::DIED = sub { 72$Event::DIED = sub {
71 # TODO: display dialog box or so 73 CFPlus::fatal Carp::longmess $_[1]
72 Carp::cluck $_[1];#d#TODO: remove when stable
73 return;#d#
74 CFPlus::fatal ($_[1]);
75}; 74};
76 75
77my $MAX_FPS = 60; 76my $MAX_FPS = 60;
78my $MIN_FPS = 5; # unused as of yet 77my $MIN_FPS = 5; # unused as of yet
79 78
80our $META_SERVER = "crossfire.real-time.com:13326"; 79our $META_SERVER = "http://metaserver.schmorp.de/current.json";
81 80
82our $LAST_REFRESH; 81our $LAST_REFRESH;
83our $NOW; 82our $NOW;
84 83
85our $CFG; 84our $CFG;
123 122
124our $INVENTORY_PAGE; 123our $INVENTORY_PAGE;
125our $STATS_PAGE; 124our $STATS_PAGE;
126our $SKILL_PAGE; 125our $SKILL_PAGE;
127our $SPELL_PAGE; 126our $SPELL_PAGE;
127our $SPELL_LIST;
128 128
129our $HELP_WINDOW; 129our $HELP_WINDOW;
130our $MESSAGE_WINDOW; 130our $MESSAGE_WINDOW;
131our $FLOORBOX; 131our $FLOORBOX;
132our $GAUGES; 132our $GAUGES;
381 381
382 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 382 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
383 383
384 my ($host, $port) = split /:/, $PROFILE->{host}; 384 my ($host, $port) = split /:/, $PROFILE->{host};
385 385
386 $MAP = new CFPlus::Map $mapsize, $mapsize; 386 $MAP = new CFPlus::Map;
387 387
388 $CONN = eval { 388 $CONN = eval {
389 new CFPlus::Protocol 389 new CFPlus::Protocol
390 host => $host, 390 host => $host,
391 port => $port || 13327, 391 port => $port || 13327,
429sub stop_game { 429sub stop_game {
430 $LOGIN_BUTTON->set_text ("Login"); 430 $LOGIN_BUTTON->set_text ("Login");
431 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); 431 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
432 $SETUP_DIALOG->show; 432 $SETUP_DIALOG->show;
433 $PL_WINDOW->hide; 433 $PL_WINDOW->hide;
434 $SPELL_PAGE->clear_spells; 434 $SPELL_LIST->clear_spells;
435 435
436 return unless $CONN; 436 return unless $CONN;
437 437
438 status "connection closed"; 438 status "connection closed";
439 439
666 $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 }); 666 $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 });
667 $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS"); 667 $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS");
668 $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 }); 668 $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 });
669 $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips"); 669 $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips");
670 $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); 670 $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
671 $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { die "violator" } );
671 672
672 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05); 673 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05);
673 674
674 for my $x (0..2) { 675 for my $x (0..2) {
675 for my $y (0 .. 2) { 676 for my $y (0 .. 2) {
857 858
858 my $table = $METASERVER->{table}; 859 my $table = $METASERVER->{table};
859 $table->clear; 860 $table->clear;
860 $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list..."); 861 $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
861 862
862 my $buf; 863 my $ok = 0;
863 864
864 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; 865 CFPlus::background {
866 my $ua = CFPlus::lwp_useragent;
865 867
866 unless ($fh) { 868 CFPlus::background_msg CFPlus::from_json +(CFPlus::lwp_check $ua->get ($META_SERVER))->decoded_content;
867 $label->set_text ("unable to contact metaserver: $!"); 869 } sub {
868 return; 870 my ($msg) = @_;
869 } 871 if ($msg) {
870
871 Event->io (fd => $fh, poll => 'r', cb => sub {
872 my $res = sysread $fh, $buf, 8192, length $buf;
873
874 if (!defined $res) {
875 $_[0]->w->cancel;
876 $label->set_text ("error while retrieving server list: $!");
877 } elsif ($res == 0) {
878 $_[0]->w->cancel;
879 status "server list retrieved";
880
881 utf8::decode $buf if utf8::valid $buf;
882
883 $table->clear; 872 $table->clear;
884 873
885 my @tip = ( 874 my @tip = (
886 "The current number of users logged in on the server.", 875 "The current number of users logged in on the server.",
887 "The hostname of the server.", 876 "The hostname of the server.",
897 for 0 .. $#col; 886 for 0 .. $#col;
898 887
899 my @align = qw(1 0 1 1 -1); 888 my @align = qw(1 0 1 1 -1);
900 889
901 my $y = 0; 890 my $y = 0;
902 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { 891 for my $m (
892 sort {
893 $b->{version} <=> $a->{version}
894 or $b->{users} <=> $a->{users}
895 }
896 @{ $msg->{servers} }
897 ) {
903 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; 898 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) =
899 @$m{qw(ip age hostname users version description ibytes obytes uptime)};
904 900
905 for ($desc) { 901 for ($desc) {
906 s/<br>/\n/gi; 902 s/<br>/\n/gi;
907 s/<li>/\n· /gi; 903 s/<li>/\n· /gi;
908 s/<.*?>//sgi; 904 s/<.*?>//sgi;
909 s/&/&amp;/g; 905 s/&amp;/&/g;
910 s/</&lt;/g; 906 s/&lt;/</g;
911 s/>/&gt;/g; 907 s/&gt;/>/g;
912 } 908 }
913 909
914 $uptime = sprintf "%dd %02d:%02d:%02d", 910 $uptime = sprintf "%dd %02d:%02d:%02d",
915 (int $m->[8] / 86400), 911 (int $uptime / 86400),
916 (int $m->[8] / 3600) % 24, 912 (int $uptime / 3600) % 24,
917 (int $m->[8] / 60) % 60, 913 (int $uptime / 60) % 60,
918 $m->[8] % 60; 914 $uptime % 60;
919 915
920 $m = [$users, $host, $uptime, $version, $desc]; 916 $m = [$users, $host, $uptime, $version, $desc];
921 917
922 $y++; 918 $y++;
923 919
933 ), 929 ),
934 (new CFPlus::UI::Empty expand => 1), 930 (new CFPlus::UI::Empty expand => 1),
935 ]); 931 ]);
936 932
937 $table->add ($_, $y, new CFPlus::UI::Label 933 $table->add ($_, $y, new CFPlus::UI::Label
934 max_w => $::WIDTH * 0.4,
938 ellipsise => 0, 935 ellipsise => 0,
939 align => $align[$_], 936 align => $align[$_],
940 text => $m->[$_], 937 text => $m->[$_],
941 tooltip => $tip[$_], 938 tooltip => $tip[$_],
939 fg => ($m->[3] =~ /\+$/ ? [1, 1, 1] : [.7, .7, .7]),
942 can_hover => 1, 940 can_hover => 1,
943 can_events => 1, 941 can_events => 1,
944 fontsize => 0.8) 942 fontsize => 0.8)
945 for 0 .. $#$m; 943 for 0 .. $#$m;
946 } 944 }
945 } else {
946 $ok or $label->set_text ("error while contacting metaserver");
947 } 947 }
948 }); 948 };
949
949} 950}
950 951
951sub metaserver_dialog { 952sub metaserver_dialog {
952 my $vbox = new CFPlus::UI::VBox; 953 my $vbox = new CFPlus::UI::VBox;
953 my $table = new CFPlus::UI::Table; 954 my $table = new CFPlus::UI::Table;
957 title => "Server List", 958 title => "Server List",
958 name => 'metaserver_dialog', 959 name => 'metaserver_dialog',
959 x => 'center', 960 x => 'center',
960 y => 'center', 961 y => 'center',
961 z => 3, 962 z => 3,
963 force_w => $::WIDTH * 0.9,
962 force_h => $::HEIGHT * 0.4, 964 force_h => $::HEIGHT * 0.7,
963 child => $vbox, 965 child => $vbox,
964 has_close_button => 1, 966 has_close_button => 1,
965 table => $table, 967 table => $table,
966 on_visibility_change => sub { 968 on_visibility_change => sub {
967 update_metaserver ($_[0]) if $_[1]; 969 update_metaserver ($_[0]) if $_[1];
1188 ["Boots" => PICKUP_BOOTS], 1190 ["Boots" => PICKUP_BOOTS],
1189 ["Gloves" => PICKUP_GLOVES], 1191 ["Gloves" => PICKUP_GLOVES],
1190 ["Cloaks" => PICKUP_CLOAK], 1192 ["Cloaks" => PICKUP_CLOAK],
1191 ], 1193 ],
1192 1194
1193 ["Readables", 2, 2, 1195 ["Readables", 2, 0,
1194 ["Spellbooks" => PICKUP_SPELLBOOK], 1196 ["Spellbooks" => PICKUP_SPELLBOOK],
1195 ["Skillscrolls" => PICKUP_SKILLSCROLL], 1197 ["Skillscrolls" => PICKUP_SKILLSCROLL],
1196 ["Normal Books/Scrolls" => PICKUP_READABLES], 1198 ["Normal Books/Scrolls" => PICKUP_READABLES],
1197 ], 1199 ],
1198 ["Misc", 2, 7, 1200 ["Misc", 2, 5,
1199 ["Food" => PICKUP_FOOD], 1201 ["Food" => PICKUP_FOOD],
1200 ["Drinks" => PICKUP_DRINK], 1202 ["Drinks" => PICKUP_DRINK],
1201 ["Valuables (Money, Gems)" => PICKUP_VALUABLES], 1203 ["Valuables (Money, Gems)" => PICKUP_VALUABLES],
1202 ["Keys" => PICKUP_KEY], 1204 ["Keys" => PICKUP_KEY],
1203 ["Magical Items" => PICKUP_MAGICAL], 1205 ["Magical Items" => PICKUP_MAGICAL],
1204 ["Potions" => PICKUP_POTION], 1206 ["Potions" => PICKUP_POTION],
1205 ["Magic Devices" => PICKUP_MAGIC_DEVICE], 1207 ["Magic Devices" => PICKUP_MAGIC_DEVICE],
1206 ["Ignore cursed" => PICKUP_NOT_CURSED], 1208 ["Ignore cursed" => PICKUP_NOT_CURSED],
1207 ["Jewelery" => PICKUP_JEWELS], 1209 ["Jewelery" => PICKUP_JEWELS],
1210 ["Flesh" => PICKUP_FLESH],
1208 ], 1211 ],
1209 ["Weight/Value ratio", 2, 17] 1212 ["Weight/Value ratio", 2, 17]
1210 ) 1213 )
1211 { 1214 {
1212 my ($title, $x, $y, @bits) = @$_; 1215 my ($title, $x, $y, @bits) = @$_;
1262 $table 1265 $table
1263} 1266}
1264 1267
1265my %SORT_ORDER = ( 1268my %SORT_ORDER = (
1266 type => undef, 1269 type => undef,
1267 mtime => sub { sort { 1270 mtime => sub {
1271 my $NOW = time;
1272 sort {
1273 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6;
1274 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
1275
1268 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED) 1276 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED)
1269 or $b->{mtime} <=> $a->{mtime} 1277 or $btime <=> $atime
1270 or $a->{type} <=> $b->{type} 1278 or $a->{type} <=> $b->{type}
1279 } @_
1271 } @_ }, 1280 },
1272 weight => sub { sort { 1281 weight => sub { sort {
1273 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) 1282 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1274 or $a->{type} <=> $b->{type} 1283 or $a->{type} <=> $b->{type}
1275 } @_ }, 1284 } @_ },
1276); 1285);
1301 #TODO# update to weigh/maxweight 1310 #TODO# update to weigh/maxweight
1302 $hb1->add ($STATWIDS->{i_weight} = new CFPlus::UI::Label align => -1); 1311 $hb1->add ($STATWIDS->{i_weight} = new CFPlus::UI::Label align => -1);
1303 1312
1304 $vb1->add (my $sw1 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1313 $vb1->add (my $sw1 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1305 $sw1->add ($INV = new CFPlus::UI::Inventory); 1314 $sw1->add ($INV = new CFPlus::UI::Inventory);
1315 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1306 1316
1307 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1317 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1308 1318
1309 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1319 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox);
1310 1320
1350 $ntb->add ( 1360 $ntb->add (
1351 "Skills (F3)" => $SKILL_PAGE = skill_window, 1361 "Skills (F3)" => $SKILL_PAGE = skill_window,
1352 "Shows all your Skills." 1362 "Shows all your Skills."
1353 ); 1363 );
1354 1364
1355 my $spellsw = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); 1365 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1);
1356 $spellsw->add ($SPELL_PAGE = new CFPlus::UI::SpellList); 1366 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList);
1357 $ntb->add ( 1367 $ntb->add (
1358 "Spellbook (F4)" => $spellsw, 1368 "Spellbook (F4)" => $spellsw,
1359 "Displays all spells you have and lets you edit keyboard shortcuts for them." 1369 "Displays all spells you have and lets you edit keyboard shortcuts for them."
1360 ); 1370 );
1361 $ntb->add ( 1371 $ntb->add (
1912 CFPlus::Mix_AllocateChannels 8; 1922 CFPlus::Mix_AllocateChannels 8;
1913 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128; 1923 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1914 1924
1915 audio_music_finished; 1925 audio_music_finished;
1916 1926
1927 local $_;
1917 while (<$fh>) { 1928 while (<$fh>) {
1918 next if /^\s*#/; 1929 next if /^\s*#/;
1919 next if /^\s*$/; 1930 next if /^\s*$/;
1920 1931
1921 my ($file, $volume, $event) = split /\s+/, $_, 3; 1932 my ($file, $volume, $event) = split /\s+/, $_, 3;
2055 log_fontsize => 0.7, 2066 log_fontsize => 0.7,
2056 gauge_fontsize => 1, 2067 gauge_fontsize => 1,
2057 gauge_size => 0.35, 2068 gauge_size => 0.35,
2058 stat_fontsize => 0.7, 2069 stat_fontsize => 0.7,
2059 mapsize => 100, 2070 mapsize => 100,
2060 say_command => 'say', 2071 say_command => 'chat',
2061 audio_enable => 1, 2072 audio_enable => 1,
2062 bgm_enable => 1, 2073 bgm_enable => 1,
2063 bgm_volume => 0.25, 2074 bgm_volume => 0.25,
2064 face_prefetch => 0, 2075 face_prefetch => 0,
2065 output_sync => 1, 2076 output_sync => 1,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines