… | |
… | |
92 | |
92 | |
93 | our $ALT_ENTER_MESSAGE; |
93 | our $ALT_ENTER_MESSAGE; |
94 | our $STATUS_LINE; |
94 | our $STATUS_LINE; |
95 | our $DEBUG_STATUS; |
95 | our $DEBUG_STATUS; |
96 | |
96 | |
|
|
97 | our $INVWIN; |
|
|
98 | our $INV; |
|
|
99 | |
97 | sub status { |
100 | sub status { |
98 | $STATUS_LINE->set_text ($_[0]); |
101 | $STATUS_LINE->set_text ($_[0]); |
99 | $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}); |
100 | } |
103 | } |
101 | |
104 | |
… | |
… | |
113 | |
116 | |
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) { |
127 | status "login successful"; |
133 | status "login successful"; |
128 | |
134 | |
129 | CFClient::lowdelay fileno $CONN->{fh}; |
135 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
136 | } else { |
|
|
137 | status "unable to connect"; |
|
|
138 | } |
130 | } |
139 | } |
131 | |
140 | |
132 | sub stop_game { |
141 | sub stop_game { |
133 | undef $CONN; |
142 | undef $CONN; |
134 | } |
143 | } |
… | |
… | |
778 | }; |
787 | }; |
779 | |
788 | |
780 | $window |
789 | $window |
781 | } |
790 | } |
782 | |
791 | |
|
|
792 | sub 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 | |
783 | sub sdl_init { |
798 | sub sdl_init { |
784 | CFClient::SDL_Init |
799 | CFClient::SDL_Init |
785 | and die "SDL::Init failed!\n"; |
800 | and die "SDL::Init failed!\n"; |
786 | } |
801 | } |
787 | |
802 | |
… | |
… | |
846 | |
861 | |
847 | $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); |
848 | $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); |
849 | $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); |
850 | |
865 | |
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 |
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 | |
852 | $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); |
853 | |
870 | |
854 | $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 { |
855 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
872 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
856 | status "Configuration Saved"; |
873 | status "Configuration Saved"; |
857 | }); |
874 | }); |
… | |
… | |
881 | push @bgmusic, shift @bgmusic; |
898 | push @bgmusic, shift @bgmusic; |
882 | } |
899 | } |
883 | |
900 | |
884 | sub audio_init { |
901 | sub audio_init { |
885 | if ($CFG->{audio_enable}) { |
902 | if ($CFG->{audio_enable}) { |
886 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
903 | if (open my $fh, "<", CFClient::find_rcfile "sounds/config") { |
887 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
904 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
888 | CFClient::Mix_AllocateChannels 8; |
905 | CFClient::Mix_AllocateChannels 8; |
889 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
906 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
890 | |
907 | |
891 | audio_music_finished; |
908 | audio_music_finished; |
… | |
… | |
1309 | sub update_floorbox { |
1326 | sub update_floorbox { |
1310 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1327 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1311 | $FLOORBOX->clear; |
1328 | $FLOORBOX->clear; |
1312 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1329 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1313 | |
1330 | |
1314 | my @items = values %{ $CONN->{container}{0} }; |
|
|
1315 | |
|
|
1316 | # we basically have to use the same sorting as everybody else |
1331 | # we basically have to use the same sorting as everybody else |
1317 | @items = sort { $a->{type} <=> $b->{type} } @items; |
1332 | for my $item (@{ $CONN->{container}{0} }) { |
1318 | |
1333 | $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 | } |
1334 | } |
1367 | }); |
1335 | }); |
1368 | refresh; |
1336 | refresh; |
1369 | } |
1337 | } |
1370 | |
1338 | |
1371 | sub conn::container_add { |
1339 | sub conn::container_add { |
1372 | my ($self, $id, $items) = @_; |
1340 | my ($self, $id, $items) = @_; |
1373 | |
1341 | |
1374 | update_floorbox if $id == 0; |
1342 | update_floorbox if $id == 0; |
|
|
1343 | if ($self->{player}{tag} == $id) { |
|
|
1344 | $INV->set_items ($self->{container}{$self->{player}{tag}}); |
|
|
1345 | } |
1375 | # $self-<{player}{tag} => player inv |
1346 | # $self-<{player}{tag} => player inv |
1376 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1347 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1377 | } |
1348 | } |
1378 | |
1349 | |
1379 | sub conn::container_clear { |
1350 | sub conn::container_clear { |
1380 | my ($self, $id) = @_; |
1351 | my ($self, $id) = @_; |
1381 | |
1352 | |
1382 | update_floorbox if $id == 0; |
1353 | update_floorbox if $id == 0; |
|
|
1354 | if ($self->{player}{tag} == $id) { |
|
|
1355 | $INV->set_items ($self->{container}{$id}); |
|
|
1356 | } |
|
|
1357 | |
1383 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1358 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1384 | } |
1359 | } |
1385 | |
1360 | |
1386 | sub conn::item_delete { |
1361 | sub conn::item_delete { |
1387 | my ($self, @items) = @_; |
1362 | my ($self, @items) = @_; |
1388 | |
1363 | |
1389 | for (@items) { |
1364 | for (@items) { |
1390 | update_floorbox if $_->{container} == 0; |
1365 | update_floorbox if $_->{container} == 0; |
|
|
1366 | if ($self->{player}{tag} == $_->{container}) { |
|
|
1367 | $INV->set_items ($self->{container}{$_->{container}}); |
|
|
1368 | } |
1391 | } |
1369 | } |
1392 | } |
1370 | } |
1393 | |
1371 | |
1394 | sub conn::item_update { |
1372 | sub conn::item_update { |
1395 | my ($self, $item) = @_; |
1373 | my ($self, $item) = @_; |
1396 | |
1374 | |
1397 | update_floorbox if $item->{container} == 0; |
1375 | update_floorbox if $item->{container} == 0; |
|
|
1376 | if ($self->{player}{tag} == $item->{container}) { |
|
|
1377 | $INV->set_items ($self->{container}{$item->{container}}); |
|
|
1378 | } |
1398 | } |
1379 | } |
1399 | |
1380 | |
1400 | %SDL_CB = ( |
1381 | %SDL_CB = ( |
1401 | CFClient::SDL_QUIT => sub { |
1382 | CFClient::SDL_QUIT => sub { |
1402 | Event::unloop -1; |
1383 | Event::unloop -1; |
… | |
… | |
1426 | |
1407 | |
1427 | ############################################################################# |
1408 | ############################################################################# |
1428 | |
1409 | |
1429 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1410 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1430 | |
1411 | |
|
|
1412 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1413 | |
1431 | $TILECACHE = CFClient::db_table "tilecache"; |
1414 | $TILECACHE = CFClient::db_table "tilecache"; |
1432 | $FACEMAP = CFClient::db_table "facemap"; |
1415 | $FACEMAP = CFClient::db_table "facemap"; |
1433 | |
|
|
1434 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1435 | |
1416 | |
1436 | my %DEF_CFG = ( |
1417 | my %DEF_CFG = ( |
1437 | sdl_mode => 0, |
1418 | sdl_mode => 0, |
1438 | width => 640, |
1419 | width => 640, |
1439 | height => 480, |
1420 | height => 480, |