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.134 by elmex, Mon Dec 4 15:17:14 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;
149 149
150our $BIND_EDITOR; 150our $BIND_EDITOR;
151our $BIND_UPD_CB; 151our $BIND_UPD_CB;
152 152
153our $PICKUP_CFG; 153our $PICKUP_CFG;
154
155our $IN_BUILD_MODE;
156our $BUILD_BUTTON;
154 157
155sub status { 158sub status {
156 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 159 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
157} 160}
158 161
381 384
382 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 385 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
383 386
384 my ($host, $port) = split /:/, $PROFILE->{host}; 387 my ($host, $port) = split /:/, $PROFILE->{host};
385 388
386 $MAP = new CFPlus::Map $mapsize, $mapsize; 389 $MAP = new CFPlus::Map;
387 390
388 $CONN = eval { 391 $CONN = eval {
389 new CFPlus::Protocol 392 new CFPlus::Protocol
390 host => $host, 393 host => $host,
391 port => $port || 13327, 394 port => $port || 13327,
429sub stop_game { 432sub stop_game {
430 $LOGIN_BUTTON->set_text ("Login"); 433 $LOGIN_BUTTON->set_text ("Login");
431 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); 434 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
432 $SETUP_DIALOG->show; 435 $SETUP_DIALOG->show;
433 $PL_WINDOW->hide; 436 $PL_WINDOW->hide;
434 $SPELL_PAGE->clear_spells; 437 $SPELL_LIST->clear_spells;
435 438
436 return unless $CONN; 439 return unless $CONN;
437 440
438 status "connection closed"; 441 status "connection closed";
439 442
666 $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 }); 669 $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"); 670 $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 }); 671 $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"); 672 $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 }); 673 $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
674 $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { die "violator" } );
671 675
672 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05); 676 my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05);
673 677
674 for my $x (0..2) { 678 for my $x (0..2) {
675 for my $y (0 .. 2) { 679 for my $y (0 .. 2) {
857 861
858 my $table = $METASERVER->{table}; 862 my $table = $METASERVER->{table};
859 $table->clear; 863 $table->clear;
860 $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list..."); 864 $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
861 865
862 my $buf; 866 my $ok = 0;
863 867
864 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; 868 CFPlus::background {
869 my $ua = CFPlus::lwp_useragent;
865 870
866 unless ($fh) { 871 CFPlus::background_msg CFPlus::from_json +(CFPlus::lwp_check $ua->get ($META_SERVER))->decoded_content;
867 $label->set_text ("unable to contact metaserver: $!"); 872 } sub {
868 return; 873 my ($msg) = @_;
869 } 874 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; 875 $table->clear;
884 876
885 my @tip = ( 877 my @tip = (
886 "The current number of users logged in on the server.", 878 "The current number of users logged in on the server.",
887 "The hostname of the server.", 879 "The hostname of the server.",
897 for 0 .. $#col; 889 for 0 .. $#col;
898 890
899 my @align = qw(1 0 1 1 -1); 891 my @align = qw(1 0 1 1 -1);
900 892
901 my $y = 0; 893 my $y = 0;
902 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { 894 for my $m (
895 sort {
896 $b->{version} <=> $a->{version}
897 or $b->{users} <=> $a->{users}
898 }
899 @{ $msg->{servers} }
900 ) {
903 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; 901 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) =
902 @$m{qw(ip age hostname users version description ibytes obytes uptime)};
904 903
905 for ($desc) { 904 for ($desc) {
906 s/<br>/\n/gi; 905 s/<br>/\n/gi;
907 s/<li>/\n· /gi; 906 s/<li>/\n· /gi;
908 s/<.*?>//sgi; 907 s/<.*?>//sgi;
909 s/&/&amp;/g; 908 s/&amp;/&/g;
910 s/</&lt;/g; 909 s/&lt;/</g;
911 s/>/&gt;/g; 910 s/&gt;/>/g;
912 } 911 }
913 912
914 $uptime = sprintf "%dd %02d:%02d:%02d", 913 $uptime = sprintf "%dd %02d:%02d:%02d",
915 (int $m->[8] / 86400), 914 (int $uptime / 86400),
916 (int $m->[8] / 3600) % 24, 915 (int $uptime / 3600) % 24,
917 (int $m->[8] / 60) % 60, 916 (int $uptime / 60) % 60,
918 $m->[8] % 60; 917 $uptime % 60;
919 918
920 $m = [$users, $host, $uptime, $version, $desc]; 919 $m = [$users, $host, $uptime, $version, $desc];
921 920
922 $y++; 921 $y++;
923 922
933 ), 932 ),
934 (new CFPlus::UI::Empty expand => 1), 933 (new CFPlus::UI::Empty expand => 1),
935 ]); 934 ]);
936 935
937 $table->add ($_, $y, new CFPlus::UI::Label 936 $table->add ($_, $y, new CFPlus::UI::Label
937 max_w => $::WIDTH * 0.4,
938 ellipsise => 0, 938 ellipsise => 0,
939 align => $align[$_], 939 align => $align[$_],
940 text => $m->[$_], 940 text => $m->[$_],
941 tooltip => $tip[$_], 941 tooltip => $tip[$_],
942 fg => ($m->[3] =~ /\+$/ ? [1, 1, 1] : [.7, .7, .7]),
942 can_hover => 1, 943 can_hover => 1,
943 can_events => 1, 944 can_events => 1,
944 fontsize => 0.8) 945 fontsize => 0.8)
945 for 0 .. $#$m; 946 for 0 .. $#$m;
946 } 947 }
948 } else {
949 $ok or $label->set_text ("error while contacting metaserver");
947 } 950 }
948 }); 951 };
952
949} 953}
950 954
951sub metaserver_dialog { 955sub metaserver_dialog {
952 my $vbox = new CFPlus::UI::VBox; 956 my $vbox = new CFPlus::UI::VBox;
953 my $table = new CFPlus::UI::Table; 957 my $table = new CFPlus::UI::Table;
957 title => "Server List", 961 title => "Server List",
958 name => 'metaserver_dialog', 962 name => 'metaserver_dialog',
959 x => 'center', 963 x => 'center',
960 y => 'center', 964 y => 'center',
961 z => 3, 965 z => 3,
966 force_w => $::WIDTH * 0.9,
962 force_h => $::HEIGHT * 0.4, 967 force_h => $::HEIGHT * 0.7,
963 child => $vbox, 968 child => $vbox,
964 has_close_button => 1, 969 has_close_button => 1,
965 table => $table, 970 table => $table,
966 on_visibility_change => sub { 971 on_visibility_change => sub {
967 update_metaserver ($_[0]) if $_[1]; 972 update_metaserver ($_[0]) if $_[1];
1188 ["Boots" => PICKUP_BOOTS], 1193 ["Boots" => PICKUP_BOOTS],
1189 ["Gloves" => PICKUP_GLOVES], 1194 ["Gloves" => PICKUP_GLOVES],
1190 ["Cloaks" => PICKUP_CLOAK], 1195 ["Cloaks" => PICKUP_CLOAK],
1191 ], 1196 ],
1192 1197
1193 ["Readables", 2, 2, 1198 ["Readables", 2, 0,
1194 ["Spellbooks" => PICKUP_SPELLBOOK], 1199 ["Spellbooks" => PICKUP_SPELLBOOK],
1195 ["Skillscrolls" => PICKUP_SKILLSCROLL], 1200 ["Skillscrolls" => PICKUP_SKILLSCROLL],
1196 ["Normal Books/Scrolls" => PICKUP_READABLES], 1201 ["Normal Books/Scrolls" => PICKUP_READABLES],
1197 ], 1202 ],
1198 ["Misc", 2, 7, 1203 ["Misc", 2, 5,
1199 ["Food" => PICKUP_FOOD], 1204 ["Food" => PICKUP_FOOD],
1200 ["Drinks" => PICKUP_DRINK], 1205 ["Drinks" => PICKUP_DRINK],
1201 ["Valuables (Money, Gems)" => PICKUP_VALUABLES], 1206 ["Valuables (Money, Gems)" => PICKUP_VALUABLES],
1202 ["Keys" => PICKUP_KEY], 1207 ["Keys" => PICKUP_KEY],
1203 ["Magical Items" => PICKUP_MAGICAL], 1208 ["Magical Items" => PICKUP_MAGICAL],
1204 ["Potions" => PICKUP_POTION], 1209 ["Potions" => PICKUP_POTION],
1205 ["Magic Devices" => PICKUP_MAGIC_DEVICE], 1210 ["Magic Devices" => PICKUP_MAGIC_DEVICE],
1206 ["Ignore cursed" => PICKUP_NOT_CURSED], 1211 ["Ignore cursed" => PICKUP_NOT_CURSED],
1207 ["Jewelery" => PICKUP_JEWELS], 1212 ["Jewelery" => PICKUP_JEWELS],
1213 ["Flesh" => PICKUP_FLESH],
1208 ], 1214 ],
1209 ["Weight/Value ratio", 2, 17] 1215 ["Weight/Value ratio", 2, 17]
1210 ) 1216 )
1211 { 1217 {
1212 my ($title, $x, $y, @bits) = @$_; 1218 my ($title, $x, $y, @bits) = @$_;
1262 $table 1268 $table
1263} 1269}
1264 1270
1265my %SORT_ORDER = ( 1271my %SORT_ORDER = (
1266 type => undef, 1272 type => undef,
1267 mtime => sub { sort { 1273 mtime => sub {
1274 my $NOW = time;
1275 sort {
1276 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6;
1277 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
1278
1268 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED) 1279 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED)
1269 or $b->{mtime} <=> $a->{mtime} 1280 or $btime <=> $atime
1270 or $a->{type} <=> $b->{type} 1281 or $a->{type} <=> $b->{type}
1282 } @_
1271 } @_ }, 1283 },
1272 weight => sub { sort { 1284 weight => sub { sort {
1273 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) 1285 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1274 or $a->{type} <=> $b->{type} 1286 or $a->{type} <=> $b->{type}
1275 } @_ }, 1287 } @_ },
1276); 1288);
1301 #TODO# update to weigh/maxweight 1313 #TODO# update to weigh/maxweight
1302 $hb1->add ($STATWIDS->{i_weight} = new CFPlus::UI::Label align => -1); 1314 $hb1->add ($STATWIDS->{i_weight} = new CFPlus::UI::Label align => -1);
1303 1315
1304 $vb1->add (my $sw1 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1316 $vb1->add (my $sw1 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1305 $sw1->add ($INV = new CFPlus::UI::Inventory); 1317 $sw1->add ($INV = new CFPlus::UI::Inventory);
1318 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1306 1319
1307 $hb->add (my $vb2 = new CFPlus::UI::VBox); 1320 $hb->add (my $vb2 = new CFPlus::UI::VBox);
1308 1321
1309 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); 1322 $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox);
1310 1323
1350 $ntb->add ( 1363 $ntb->add (
1351 "Skills (F3)" => $SKILL_PAGE = skill_window, 1364 "Skills (F3)" => $SKILL_PAGE = skill_window,
1352 "Shows all your Skills." 1365 "Shows all your Skills."
1353 ); 1366 );
1354 1367
1355 my $spellsw = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); 1368 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1);
1356 $spellsw->add ($SPELL_PAGE = new CFPlus::UI::SpellList); 1369 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList);
1357 $ntb->add ( 1370 $ntb->add (
1358 "Spellbook (F4)" => $spellsw, 1371 "Spellbook (F4)" => $spellsw,
1359 "Displays all spells you have and lets you edit keyboard shortcuts for them." 1372 "Displays all spells you have and lets you edit keyboard shortcuts for them."
1360 ); 1373 );
1361 $ntb->add ( 1374 $ntb->add (
1852 ); 1865 );
1853 1866
1854 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, 1867 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window,
1855 tooltip => "View Documentation"); 1868 tooltip => "View Documentation");
1856 1869
1870
1857 $BUTTONBAR->add (new CFPlus::UI::Button 1871 $BUTTONBAR->add (new CFPlus::UI::Button
1858 text => "Quit", 1872 text => "Quit",
1859 tooltip => "Terminates the program", 1873 tooltip => "Terminates the program",
1860 on_activate => sub { 1874 on_activate => sub {
1861 if ($CONN) { 1875 if ($CONN) {
1872 } 1886 }
1873 1887
1874 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 1888 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
1875} 1889}
1876 1890
1891sub setup_build_button {
1892 my ($enabled) = @_;
1893 if ($enabled) {
1894 $BUILD_BUTTON ||= new CFPlus::UI::Button
1895 text => "Build",
1896 tooltip => "Opens the ingame builder",
1897 on_activate => sub {
1898 if ($CONN) {
1899 $CONN->send_ext_req (builder_player_items => sub {
1900 open_ingame_editor ($_[0]) if exists $_[0]->{items};
1901 });
1902 }
1903 0
1904 };
1905 $BUTTONBAR->add ($BUILD_BUTTON);
1906 } else {
1907 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1908 }
1909}
1910
1911sub open_ingame_editor {
1912 my ($msg) = @_;
1913
1914 my $win = new CFPlus::UI::Toplevel
1915 x => 0,
1916 y => 'center',
1917 z => 4,
1918 name => 'builder_window',
1919 force_w => int $WIDTH * 1/4,
1920 force_h => int $HEIGHT * 3/4,
1921 title => "In game builder",
1922 has_close_button => 1;
1923
1924 my $r = new CFPlus::UI::ScrolledWindow (
1925 expand => 1,
1926 scroll_y => 1
1927 );
1928 $r->add (my $vb = new CFPlus::UI::VBox);
1929 $win->add ($r);
1930
1931
1932 $vb->add (my $chk = new CFPlus::UI::Button text => "Disable build mode", on_activate => sub { $::IN_BUILD_MODE = undef });
1933 $vb->add (my $chk = new CFPlus::UI::Button text => "ERASE", on_activate => sub { $::IN_BUILD_MODE = { do_erase => 1 } });
1934
1935 for my $itemarchname (keys %{$msg->{items}}) {
1936 $vb->add (
1937 new CFPlus::UI::Button text => "$itemarchname",
1938 on_activate => sub {
1939 $::IN_BUILD_MODE = $itemarchname;
1940 }
1941 );
1942 }
1943
1944 $win->show;
1945}
1946
1877sub video_shutdown { 1947sub video_shutdown {
1878 CFPlus::OpenGL::shutdown; 1948 CFPlus::OpenGL::shutdown;
1879 1949
1880 undef $SDL_ACTIVE; 1950 undef $SDL_ACTIVE;
1881} 1951}
1912 CFPlus::Mix_AllocateChannels 8; 1982 CFPlus::Mix_AllocateChannels 8;
1913 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128; 1983 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1914 1984
1915 audio_music_finished; 1985 audio_music_finished;
1916 1986
1987 local $_;
1917 while (<$fh>) { 1988 while (<$fh>) {
1918 next if /^\s*#/; 1989 next if /^\s*#/;
1919 next if /^\s*$/; 1990 next if /^\s*$/;
1920 1991
1921 my ($file, $volume, $event) = split /\s+/, $_, 3; 1992 my ($file, $volume, $event) = split /\s+/, $_, 3;
2055 log_fontsize => 0.7, 2126 log_fontsize => 0.7,
2056 gauge_fontsize => 1, 2127 gauge_fontsize => 1,
2057 gauge_size => 0.35, 2128 gauge_size => 0.35,
2058 stat_fontsize => 0.7, 2129 stat_fontsize => 0.7,
2059 mapsize => 100, 2130 mapsize => 100,
2060 say_command => 'say', 2131 say_command => 'chat',
2061 audio_enable => 1, 2132 audio_enable => 1,
2062 bgm_enable => 1, 2133 bgm_enable => 1,
2063 bgm_volume => 0.25, 2134 bgm_volume => 0.25,
2064 face_prefetch => 0, 2135 face_prefetch => 0,
2065 output_sync => 1, 2136 output_sync => 1,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines