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

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.184 by root, Tue Apr 25 11:25:20 2006 UTC vs.
Revision 1.195 by root, Sun Apr 30 11:17:09 2006 UTC

70 70
71our $FONT_PROP; 71our $FONT_PROP;
72our $FONT_FIXED; 72our $FONT_FIXED;
73 73
74our $MAP; 74our $MAP;
75our $MAPMAP;
75our $MAPWIDGET; 76our $MAPWIDGET;
76our $BUTTONBAR; 77our $BUTTONBAR;
77our $LOGVIEW; 78our $LOGVIEW;
78our $CONSOLE; 79our $CONSOLE;
79our $METASERVER; 80our $METASERVER;
91 92
92our $ALT_ENTER_MESSAGE; 93our $ALT_ENTER_MESSAGE;
93our $STATUS_LINE; 94our $STATUS_LINE;
94our $DEBUG_STATUS; 95our $DEBUG_STATUS;
95 96
97our $INVWIN;
98our $INV;
99
96sub status { 100sub status {
97 $STATUS_LINE->set_text ($_[0]); 101 $STATUS_LINE->set_text ($_[0]);
98 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 102 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
99} 103}
100 104
112 116
113 $MAP = new CFClient::Map $mapsize, $mapsize; 117 $MAP = new CFClient::Map $mapsize, $mapsize;
114 118
115 my ($host, $port) = split /:/, $CFG->{host}; 119 my ($host, $port) = split /:/, $CFG->{host};
116 120
117 $CONN = new conn 121 $CONN = eval {
122 new conn
118 host => $host, 123 host => $host,
119 port => $port || 13327, 124 port => $port || 13327,
120 user => $CFG->{user}, 125 user => $CFG->{user},
121 pass => $CFG->{password}, 126 pass => $CFG->{password},
122 mapw => $mapsize, 127 mapw => $mapsize,
123 maph => $mapsize, 128 maph => $mapsize,
129 ;
124 ; 130 };
125 131
132 if ($CONN) {
126 status "login successful"; 133 status "login successful";
127 134
128 CFClient::lowdelay fileno $CONN->{fh}; 135 CFClient::lowdelay fileno $CONN->{fh};
136 } else {
137 status "unable to connect";
138 }
129} 139}
130 140
131sub stop_game { 141sub stop_game {
132 undef $CONN; 142 undef $CONN;
133} 143}
313 audio_shutdown (); 323 audio_shutdown ();
314 audio_init (); 324 audio_init ();
315 } 325 }
316 ); 326 );
317 327
328 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Communication cmd");
329 $table->add (1, $row++, my $saycmd = new CFClient::UI::Entry
330 text => $CFG->{say_command},
331 tooltip => "This is the command that will be used if you write a line in the message window entry. "
332 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
333 ."But you could also set it to 'tell <playername>' to only chat with that user.",
334 connect_changed => sub {
335 my ($self, $value) = @_;
336 $CFG->{say_command} = $value;
337 }
338 );
339
318 $dialog 340 $dialog
319} 341}
320 342
321sub set_stats_window_fontsize { 343sub set_stats_window_fontsize {
322 for (values %{$STATWIDS}) { 344 for (values %{$STATWIDS}) {
381} 403}
382 404
383sub make_stats_window { 405sub make_stats_window {
384 my $tgw = new CFClient::UI::FancyFrame x => $WIDTH * 2/5, y => 0, title => "Stats"; 406 my $tgw = new CFClient::UI::FancyFrame x => $WIDTH * 2/5, y => 0, title => "Stats";
385 407
386 $tgw->add (my $vb = new CFClient::UI::VBox); 408 $tgw->add (new CFClient::UI::Window child => my $vb = new CFClient::UI::VBox);
387 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); 409 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
388 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); 410 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
389 411
390 $vb->add (my $hb = new CFClient::UI::HBox expand => 1); 412 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
391 413
421 443
422 my $row = 0; 444 my $row = 0;
423 my $col = 0; 445 my $col = 0;
424 446
425 my %resist_names = ( 447 my %resist_names = (
426 slow => "Slow", 448 slow => "Slow (slows you down when you are hit by the spell. Monsters will have an opportunity to come near you faster and hit you more often.)",
427 holyw => "Holy Word", 449 holyw => "Holy Word (resistance you against getting the fear when someone whose god doesn't like you spells the holy word on you.)",
428 conf => "Confusion", 450 conf => "Confusion (If you are hit by confusion you will move into random directions, and likely into monsters.)",
429 fire => "Fire", 451 fire => "Fire (just your resistance to fire spells like burning hands, dragonbreath, meteor swarm fire, ...)",
430 depl => "Depletion (some monsters and other effects can cause stats depletion)", 452 depl => "Depletion (some monsters and other effects can cause stats depletion)",
431 magic => "Magic", 453 magic => "Magic (resistance to magic spells like magic missile or similar)",
432 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)", 454 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)",
433 acid => "Acid", 455 acid => "Acid (resistance to acid, acid hurts pretty much and also corrodes your weapons)",
434 pois => "Poison", 456 pois => "Poison (resistance to getting poisoned)",
435 para => "Paralysation", 457 para => "Paralysation (this resistance affects the chance you get paralysed)",
436 deat => "Death (resistance against death spells)", 458 deat => "Death (resistance against death spells)",
437 phys => "Physical", 459 phys => "Physical (this is the resistance against physical attacks, like when a monster hit you in melee combat)",
438 blind => "Blind", 460 blind => "Blind (blind resistance affects the chance of a successful blinding attack)",
439 fear => "Fear", 461 fear => "Fear (this attack will drive you away from monsters who cast this and hit you successfully, being resistant to this helps a lot when fighting those monsters)",
440 tund => "Turn undead", 462 tund => "Turn undead",
441 elec => "Electricity", 463 elec => "Electricity (resistance againt electricity, spells like large lightning, small lightning, ...)",
442 cold => "Cold", 464 cold => "Cold (this is your resistance against cold spells like icestorm, snowstorm, ...)",
443 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)", 465 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)",
444 ); 466 );
445 for (qw/slow holyw conf fire depl magic 467 for (qw/slow holyw conf fire depl magic
446 drain acid pois para deat phys 468 drain acid pois para deat phys
447 blind fear tund elec cold ghit/) 469 blind fear tund elec cold ghit/)
456 can_events => 1, 478 can_events => 1,
457 can_hover => 1, 479 can_hover => 1,
458 tooltip => $resist_names{$_}, 480 tooltip => $resist_names{$_},
459 ); 481 );
460 $tbl2->add ($col + 1, $row, new CFClient::UI::Image 482 $tbl2->add ($col + 1, $row, new CFClient::UI::Image
483 font => $FONT_FIXED,
461 can_hover => 1, 484 can_hover => 1,
462 can_events => 1, 485 can_events => 1,
463 image => "ui/resist/resist_$_.png", 486 image => "ui/resist/resist_$_.png",
464 tooltip => $resist_names{$_}, 487 tooltip => $resist_names{$_},
465 ); 488 );
690 my ($self, $value) = @_; 713 my ($self, $value) = @_;
691 $CFG->{password} = $value; 714 $CFG->{password} = $value;
692 } 715 }
693 ); 716 );
694 717
695 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
696 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
697 text => $CFG->{say_command},
698 tooltip => "This is the command that will be used if you write a line in the message window entry. "
699 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
700 ."But you could also set it to 'tell <playername>' to only chat with that user.",
701 connect_changed => sub {
702 my ($self, $value) = @_;
703 $CFG->{say_command} = $value;
704 }
705 );
706
707 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); 718 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
708 $table->add (1, 7, new CFClient::UI::Slider 719 $table->add (1, 7, new CFClient::UI::Slider
709 req_w => 100, 720 req_w => 100,
710 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 721 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
711 tooltip => "This is the size of the portion of the map update the server sends you. " 722 tooltip => "This is the size of the portion of the map update the server sends you. "
725} 736}
726 737
727sub message_window { 738sub message_window {
728 my $window = new CFClient::UI::FancyFrame 739 my $window = new CFClient::UI::FancyFrame
729 title => "Messages", 740 title => "Messages",
730 border_bg => [1, 1, 1, 0.5], 741 border_bg => [1, 1, 1, 1],
731 bg => [0.3, 0.3, 0.3, 0.8], 742 bg => [0, 0, 0, 0.5],
732 user_w => int $::WIDTH / 3, 743 user_w => int $::WIDTH / 3,
733 user_h => int $::HEIGHT / 5, 744 user_h => int $::HEIGHT / 5,
734 child => (my $vbox = new CFClient::UI::VBox); 745 child => (my $vbox = new CFClient::UI::VBox);
735 746
736 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 747 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
776 }; 787 };
777 788
778 $window 789 $window
779} 790}
780 791
792sub make_inventory_window {
793 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
794 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
795 $invwin
796}
797
781sub sdl_init { 798sub sdl_init {
782 CFClient::SDL_Init 799 CFClient::SDL_Init
783 and die "SDL::Init failed!\n"; 800 and die "SDL::Init failed!\n";
784} 801}
785 802
816 fontsize => 0.8, 833 fontsize => 0.8,
817 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 834 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
818 $ALT_ENTER_MESSAGE->show; 835 $ALT_ENTER_MESSAGE->show;
819 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 836 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
820 837
821 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); 838 CFClient::UI::FancyFrame->new (
822 $MAPWIDGET->focus_in; 839 border_bg => [1, 1, 1, 192/255],
840 bg => [1, 1, 1, 0],
841 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
842 )->show;
843
844 $MAPWIDGET = new CFClient::MapWidget;
823 $MAPWIDGET->connect (activate_console => sub { 845 $MAPWIDGET->connect (activate_console => sub {
824 my ($mapwidget, $preset) = @_; 846 my ($mapwidget, $preset) = @_;
825 847
826 if ($CONSOLE) { 848 if ($CONSOLE) {
827 $CONSOLE->{input}->{auto_activated} = 1; 849 $CONSOLE->{input}->{auto_activated} = 1;
830 if ($preset && $CONSOLE->{input}->get_text eq '') { 852 if ($preset && $CONSOLE->{input}->get_text eq '') {
831 $CONSOLE->{input}->set_text ($preset); 853 $CONSOLE->{input}->set_text ($preset);
832 } 854 }
833 } 855 }
834 }); 856 });
857 $MAPWIDGET->show;
858 $MAPWIDGET->focus_in;
835 859
836 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 860 $BUTTONBAR = new CFClient::UI::HBox;
837 861
838 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 862 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
839 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 863 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
840 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 864 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
841 865
842 $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 866 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
867
843 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 868 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
869 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
844 870
845 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 871 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
846 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 872 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
847 status "Configuration Saved"; 873 status "Configuration Saved";
848 }); 874 });
875
876 $BUTTONBAR->show;
849 877
850 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 878 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
851} 879}
852 880
853sub video_shutdown { 881sub video_shutdown {
870 push @bgmusic, shift @bgmusic; 898 push @bgmusic, shift @bgmusic;
871} 899}
872 900
873sub audio_init { 901sub audio_init {
874 if ($CFG->{audio_enable}) { 902 if ($CFG->{audio_enable}) {
875 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 903 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
876 $SDL_MIXER = !CFClient::Mix_OpenAudio; 904 $SDL_MIXER = !CFClient::Mix_OpenAudio;
877 CFClient::Mix_AllocateChannels 8; 905 CFClient::Mix_AllocateChannels 8;
878 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 906 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
879 907
880 audio_music_finished; 908 audio_music_finished;
1035# at worst. 1063# at worst.
1036sub conn::flood_fill { 1064sub conn::flood_fill {
1037 my ($self, $gx, $gy, $path, $hash, $flags) = @_; 1065 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
1038 1066
1039 # the server does not allow map paths > 6 1067 # the server does not allow map paths > 6
1040 return if 6 <= length $path; 1068 return if 7 <= length $path;
1041 1069
1042 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; 1070 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
1043 1071
1044 for ( 1072 for (
1045 [1, 0, -1], 1073 [1, 0, -1],
1088 1116
1089 $self->flush_map; 1117 $self->flush_map;
1090 1118
1091 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1119 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1092 1120
1093 my $mapmapw = 250; 1121 my $mapmapw = $MAPMAP->{w};
1094 my $mapmaph = 250; 1122 my $mapmaph = $MAPMAP->{h};
1095 1123
1096 $self->{neigh_rect} = [ 1124 $self->{neigh_rect} = [
1097 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, 1125 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1098 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, 1126 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1099 ]; 1127 ];
1298sub update_floorbox { 1326sub update_floorbox {
1299 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1327 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1300 $FLOORBOX->clear; 1328 $FLOORBOX->clear;
1301 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1329 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1302 1330
1303 my @items = values %{ $CONN->{container}{0} };
1304
1305 # we basically have to use the same sorting as everybody else 1331 # we basically have to use the same sorting as everybody else
1306 @items = sort { $a->{type} <=> $b->{type} } @items; 1332 for my $item (@{ $CONN->{container}{0} }) {
1307
1308 for my $item (reverse @items) {
1309 my $desc = $item->{nrof} < 2 1333 my $desc = $item->{nrof} < 2
1310 ? $item->{name} 1334 ? $item->{name}
1311 : "$item->{nrof} $item->{name_pl}"; 1335 : "$item->{nrof} $item->{name_pl}";
1312 # todo: animation widget, face widget, weight(?) etc. 1336 # todo: animation widget, face widget, weight(?) etc.
1313 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox 1337 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1322 if ($ev->{button} == 1) { 1346 if ($ev->{button} == 1) {
1323 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0"); 1347 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1324 } elsif ($ev->{button} == 2) { 1348 } elsif ($ev->{button} == 2) {
1325 $CONN->send ("apply $item->{tag}"); 1349 $CONN->send ("apply $item->{tag}");
1326 } elsif ($ev->{button} == 3) { 1350 } elsif ($ev->{button} == 3) {
1327 # examine, lock, mark, maybe other things 1351 CFClient::UI::Menu->new (
1328 warn "MENU not implemented yet\n"; 1352 items => [
1353 ["examine", sub { $CONN->send ("examine $item->{tag}") }],
1354 [
1355 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
1356 sub { $CONN->send ("lock $item->{tag}") },
1357 ],
1358 ["mark", sub { $CONN->send ("mark $item->{tag}") }],
1359 ["apply", sub { $CONN->send ("apply $item->{tag}") }],
1360 ],
1361 )->popup ($ev);
1329 } 1362 }
1330 1363
1331 1 1364 1
1332 }, 1365 },
1333 ); 1366 );
1350 1383
1351sub conn::container_add { 1384sub conn::container_add {
1352 my ($self, $id, $items) = @_; 1385 my ($self, $id, $items) = @_;
1353 1386
1354 update_floorbox if $id == 0; 1387 update_floorbox if $id == 0;
1388 if ($self->{player}{tag} == $id) {
1389 $INV->set_items ($self->{container}{$self->{player}{tag}});
1390 }
1355 # $self-<{player}{tag} => player inv 1391 # $self-<{player}{tag} => player inv
1356 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1392 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1357} 1393}
1358 1394
1359sub conn::container_clear { 1395sub conn::container_clear {
1360 my ($self, $id) = @_; 1396 my ($self, $id) = @_;
1361 1397
1362 update_floorbox if $id == 0; 1398 update_floorbox if $id == 0;
1399 if ($self->{player}{tag} == $id) {
1400 $INV->set_items ($self->{container}{$id});
1401 }
1402
1363# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1403# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1364} 1404}
1365 1405
1366sub conn::item_delete { 1406sub conn::item_delete {
1367 my ($self, @items) = @_; 1407 my ($self, @items) = @_;
1368 1408
1369 for (@items) { 1409 for (@items) {
1370 update_floorbox if $_->{container} == 0; 1410 update_floorbox if $_->{container} == 0;
1411 if ($self->{player}{tag} == $_->{container}) {
1412 $INV->set_items ($self->{container}{$_->{container}});
1413 }
1371 } 1414 }
1372} 1415}
1373 1416
1374sub conn::item_update { 1417sub conn::item_update {
1375 my ($self, $item) = @_; 1418 my ($self, $item) = @_;
1376 1419
1377 update_floorbox if $item->{container} == 0; 1420 update_floorbox if $item->{container} == 0;
1421 if ($self->{player}{tag} == $item->{container}) {
1422 $INV->set_items ($self->{container}{$item->{container}});
1423 }
1378} 1424}
1379 1425
1380%SDL_CB = ( 1426%SDL_CB = (
1381 CFClient::SDL_QUIT => sub { 1427 CFClient::SDL_QUIT => sub {
1382 Event::unloop -1; 1428 Event::unloop -1;
1406 1452
1407############################################################################# 1453#############################################################################
1408 1454
1409$SIG{INT} = $SIG{TERM} = sub { exit }; 1455$SIG{INT} = $SIG{TERM} = sub { exit };
1410 1456
1457CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1458
1411$TILECACHE = CFClient::db_table "tilecache"; 1459$TILECACHE = CFClient::db_table "tilecache";
1412$FACEMAP = CFClient::db_table "facemap"; 1460$FACEMAP = CFClient::db_table "facemap";
1413
1414CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1415 1461
1416my %DEF_CFG = ( 1462my %DEF_CFG = (
1417 sdl_mode => 0, 1463 sdl_mode => 0,
1418 width => 640, 1464 width => 640,
1419 height => 480, 1465 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines