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.190 by elmex, Thu Apr 27 08:55:35 2006 UTC vs.
Revision 1.200 by root, Mon May 8 17:23:08 2006 UTC

76our $MAPWIDGET; 76our $MAPWIDGET;
77our $BUTTONBAR; 77our $BUTTONBAR;
78our $LOGVIEW; 78our $LOGVIEW;
79our $CONSOLE; 79our $CONSOLE;
80our $METASERVER; 80our $METASERVER;
81our $LOGIN_BUTTON;
81 82
82our $FLOORBOX; 83our $FLOORBOX;
83our $GAUGES; 84our $GAUGES;
84our $STATWIDS; 85our $STATWIDS;
85 86
92 93
93our $ALT_ENTER_MESSAGE; 94our $ALT_ENTER_MESSAGE;
94our $STATUS_LINE; 95our $STATUS_LINE;
95our $DEBUG_STATUS; 96our $DEBUG_STATUS;
96 97
98our $INVWIN;
99our $INV;
100
97sub status { 101sub status {
98 $STATUS_LINE->set_text ($_[0]); 102 $STATUS_LINE->set_text ($_[0]);
99 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 103 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
100} 104}
101 105
108 status "logging in..."; 112 status "logging in...";
109 113
110 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 114 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
111 115
112 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 116 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
113
114 $MAP = new CFClient::Map $mapsize, $mapsize; 117 $MAP = new CFClient::Map $mapsize, $mapsize;
115 118
116 my ($host, $port) = split /:/, $CFG->{host}; 119 my ($host, $port) = split /:/, $CFG->{host};
117 120
118 $CONN = new conn 121 $CONN = eval {
122 new conn
119 host => $host, 123 host => $host,
120 port => $port || 13327, 124 port => $port || 13327,
121 user => $CFG->{user}, 125 user => $CFG->{user},
122 pass => $CFG->{password}, 126 pass => $CFG->{password},
123 mapw => $mapsize, 127 mapw => $mapsize,
124 maph => $mapsize, 128 maph => $mapsize,
129 ;
125 ; 130 };
126 131
132 if ($CONN) {
133 $LOGIN_BUTTON->set_text ("Logout");
134
127 status "login successful"; 135 status "login successful";
128 136
129 CFClient::lowdelay fileno $CONN->{fh}; 137 CFClient::lowdelay fileno $CONN->{fh};
138 } else {
139 status "unable to connect";
140 stop_game();
141 }
130} 142}
131 143
132sub stop_game { 144sub stop_game {
145 return unless $CONN;
146
147 status "connection closed";
148 $LOGIN_BUTTON->set_text ("Login");
149 $CONN->destroy;
150 $CONN = 0; # false, does not autovivify
151
152 undef $MAPCACHE;
133 undef $CONN; 153 undef $MAP;
134} 154}
135 155
136sub client_setup { 156sub client_setup {
137 my $dialog = new CFClient::UI::FancyFrame 157 my $dialog = new CFClient::UI::FancyFrame
138 title => "Client Setup", 158 title => "Client Setup",
562 582
563} 583}
564 584
565sub metaserver_dialog { 585sub metaserver_dialog {
566 my $dialog = new CFClient::UI::FancyFrame 586 my $dialog = new CFClient::UI::FancyFrame
567 title => "Metaserver", 587 title => "Server List",
568 child => (my $vbox = new CFClient::UI::VBox); 588 child => (my $vbox = new CFClient::UI::VBox);
569 589
570 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 590 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
571 591
572 $dialog 592 $dialog
674 694
675 $METASERVER = metaserver_dialog; 695 $METASERVER = metaserver_dialog;
676 696
677 $vbox->add (new CFClient::UI::Flopper 697 $vbox->add (new CFClient::UI::Flopper
678 expand => 1, 698 expand => 1,
679 text => "Metaserver", 699 text => "Server List",
680 other => $METASERVER, 700 other => $METASERVER,
681 tooltip => "Show a list of avaible crossfire servers", 701 tooltip => "Show a list of available crossfire servers",
682 connect_open => sub { 702 connect_open => sub {
683 update_metaserver $HOST; 703 update_metaserver $HOST;
684 } 704 }
685 ); 705 );
686 } 706 }
717 737
718 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 738 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
719 }, 739 },
720 ); 740 );
721 741
722 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 742 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
743 expand => 1,
744 align => 0,
745 text => "Login",
746 connect_activate => sub {
747 $CONN ? stop_game
723 start_game; 748 : start_game;
749 },
724 }); 750 );
725 751
726 $dialog 752 $dialog
727} 753}
728 754
729sub message_window { 755sub message_window {
778 }; 804 };
779 805
780 $window 806 $window
781} 807}
782 808
809sub make_inventory_window {
810 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
811 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
812 $invwin
813}
814
783sub sdl_init { 815sub sdl_init {
784 CFClient::SDL_Init 816 CFClient::SDL_Init
785 and die "SDL::Init failed!\n"; 817 and die "SDL::Init failed!\n";
786} 818}
787 819
788sub video_init { 820sub video_init {
789 sdl_init; 821 sdl_init;
822
823 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
790 824
791 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 825 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
792 $FULLSCREEN = $CFG->{fullscreen}; 826 $FULLSCREEN = $CFG->{fullscreen};
793 $FAST = $CFG->{fast}; 827 $FAST = $CFG->{fast};
794 828
846 880
847 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 881 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
848 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 882 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
849 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 883 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
850 884
851 $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 885 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
886
852 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 887 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
888 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
853 889
854 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 890 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
855 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 891 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
856 status "Configuration Saved"; 892 status "Configuration Saved";
857 }); 893 });
869} 905}
870 906
871my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 907my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
872my $bgmusic;#TODO#hack#d# 908my $bgmusic;#TODO#hack#d#
873 909
910sub audio_channel_finished {
911 my ($channel) = @_;
912
913 warn "channel $channel finished\n";#d#
914}
915
874sub audio_music_finished { 916sub audio_music_finished {
875 return unless $CFG->{bgm_enable}; 917 return unless $CFG->{bgm_enable};
876 918
877 # TODO: hack, do play loop and mood music 919 # TODO: hack, do play loop and mood music
878 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; 920 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
881 push @bgmusic, shift @bgmusic; 923 push @bgmusic, shift @bgmusic;
882} 924}
883 925
884sub audio_init { 926sub audio_init {
885 if ($CFG->{audio_enable}) { 927 if ($CFG->{audio_enable}) {
886 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 928 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
887 $SDL_MIXER = !CFClient::Mix_OpenAudio; 929 $SDL_MIXER = !CFClient::Mix_OpenAudio;
888 CFClient::Mix_AllocateChannels 8; 930 CFClient::Mix_AllocateChannels 8;
889 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 931 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
890 932
891 audio_music_finished; 933 audio_music_finished;
1153 } 1195 }
1154 1196
1155gotid: 1197gotid:
1156 $face->{id} = $id; 1198 $face->{id} = $id;
1157 $MAP->set_face ($facenum => $id); 1199 $MAP->set_face ($facenum => $id);
1158 $self->{faceid}[$facenum] = $id;#d#
1159 $TILECACHE->get ($id) 1200 $TILECACHE->get ($id)
1160} 1201}
1161 1202
1162sub conn::face_update { 1203sub conn::face_update {
1163 my ($self, $facenum, $face) = @_; 1204 my ($self, $facenum, $face) = @_;
1302 1343
1303 for my $skill (values %{$self->{skill_info}}) { 1344 for my $skill (values %{$self->{skill_info}}) {
1304 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1345 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1305 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1346 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1306 } 1347 }
1348
1349 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1350 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1351 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1352 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1353}
1354
1355sub conn::eof {
1356 stop_game;
1307} 1357}
1308 1358
1309sub update_floorbox { 1359sub update_floorbox {
1310 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1360 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1361 return unless $CONN;
1362
1311 $FLOORBOX->clear; 1363 $FLOORBOX->clear;
1312 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1364 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1313 1365
1314 my @items = values %{ $CONN->{container}{0} };
1315
1316 # we basically have to use the same sorting as everybody else 1366 # we basically have to use the same sorting as everybody else
1317 @items = sort { $a->{type} <=> $b->{type} } @items; 1367 for my $item (@{ $CONN->{container}{0} }) {
1318 1368 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item);
1319 for my $item (reverse @items) {
1320 my $desc = $item->{nrof} < 2
1321 ? $item->{name}
1322 : "$item->{nrof} $item->{name_pl}";
1323 # todo: animation widget, face widget, weight(?) etc.
1324 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1325 tooltip => (CFClient::UI::Label->escape ($desc)
1326 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1327 can_hover => 1,
1328 can_events => 1,
1329 connect_button_down => sub {
1330 my ($self, $ev, $x, $y) = @_;
1331
1332 # todo: maybe put examine on 1? but should just be a tooltip :(
1333 if ($ev->{button} == 1) {
1334 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1335 } elsif ($ev->{button} == 2) {
1336 $CONN->send ("apply $item->{tag}");
1337 } elsif ($ev->{button} == 3) {
1338 CFClient::UI::Menu->new (
1339 items => [
1340 ["examine", sub { $CONN->send ("examine $item->{tag}") }],
1341 [
1342 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
1343 sub { $CONN->send ("lock $item->{tag}") },
1344 ],
1345 ["mark", sub { $CONN->send ("mark $item->{tag}") }],
1346 ["apply", sub { $CONN->send ("apply $item->{tag}") }],
1347 ],
1348 )->popup ($ev);
1349 }
1350
1351 1
1352 },
1353 );
1354
1355 $hbox->add (new CFClient::UI::Face
1356 can_events => 0,
1357 face => $item->{face},
1358 anim => $item->{anim},
1359 animspeed => $item->{animspeed},
1360 );
1361
1362 $hbox->add (new CFClient::UI::Label
1363 can_events => 0,
1364 text => $desc,
1365 );
1366 } 1369 }
1367 }); 1370 });
1368 refresh; 1371 refresh;
1369} 1372}
1370 1373
1371sub conn::container_add { 1374sub conn::container_add {
1372 my ($self, $id, $items) = @_; 1375 my ($self, $id, $items) = @_;
1373 1376
1374 update_floorbox if $id == 0; 1377 update_floorbox if $id == 0;
1378 if ($self->{player}{tag} == $id) {
1379 $INV->set_items ($self->{container}{$self->{player}{tag}});
1380 }
1375 # $self-<{player}{tag} => player inv 1381 # $self-<{player}{tag} => player inv
1376 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1382 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1377} 1383}
1378 1384
1379sub conn::container_clear { 1385sub conn::container_clear {
1380 my ($self, $id) = @_; 1386 my ($self, $id) = @_;
1381 1387
1382 update_floorbox if $id == 0; 1388 update_floorbox if $id == 0;
1389 if ($self->{player}{tag} == $id) {
1390 $INV->set_items ($self->{container}{$id});
1391 }
1392
1383# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1393# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1384} 1394}
1385 1395
1386sub conn::item_delete { 1396sub conn::item_delete {
1387 my ($self, @items) = @_; 1397 my ($self, @items) = @_;
1388 1398
1389 for (@items) { 1399 for (@items) {
1390 update_floorbox if $_->{container} == 0; 1400 update_floorbox if $_->{container} == 0;
1401 if ($self->{player}{tag} == $_->{container}) {
1402 $INV->set_items ($self->{container}{$_->{container}});
1403 }
1391 } 1404 }
1392} 1405}
1393 1406
1394sub conn::item_update { 1407sub conn::item_update {
1395 my ($self, $item) = @_; 1408 my ($self, $item) = @_;
1396 1409
1397 update_floorbox if $item->{container} == 0; 1410 update_floorbox if $item->{container} == 0;
1411 if ($self->{player}{tag} == $item->{container}) {
1412 $INV->set_items ($self->{container}{$item->{container}});
1413 }
1398} 1414}
1399 1415
1400%SDL_CB = ( 1416%SDL_CB = (
1401 CFClient::SDL_QUIT => sub { 1417 CFClient::SDL_QUIT => sub {
1402 Event::unloop -1; 1418 Event::unloop -1;
1415 video_init; 1431 video_init;
1416 } else { 1432 } else {
1417 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1433 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1418 } 1434 }
1419 }, 1435 },
1420 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1436 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1421 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1437 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1422 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1438 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1423 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1439 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1424 CFClient::SDL_USEREVENT => \&audio_music_finished, 1440 CFClient::SDL_USEREVENT => sub {
1441 if ($_[0]{code} == 1) {
1442 audio_channel_finished $_[0]{data1};
1443 } elsif ($_[0]{code} == 0) {
1444 audio_music_finished;
1445 }
1446 },
1425); 1447);
1426 1448
1427############################################################################# 1449#############################################################################
1428 1450
1429$SIG{INT} = $SIG{TERM} = sub { exit }; 1451$SIG{INT} = $SIG{TERM} = sub { exit };
1452
1453CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1430 1454
1431$TILECACHE = CFClient::db_table "tilecache"; 1455$TILECACHE = CFClient::db_table "tilecache";
1432$FACEMAP = CFClient::db_table "facemap"; 1456$FACEMAP = CFClient::db_table "facemap";
1433
1434CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1435 1457
1436my %DEF_CFG = ( 1458my %DEF_CFG = (
1437 sdl_mode => 0, 1459 sdl_mode => 0,
1438 width => 640, 1460 width => 640,
1439 height => 480, 1461 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines