… | |
… | |
116 | |
116 | |
117 | $MAP = new CFClient::Map $mapsize, $mapsize; |
117 | $MAP = new CFClient::Map $mapsize, $mapsize; |
118 | |
118 | |
119 | my ($host, $port) = split /:/, $CFG->{host}; |
119 | my ($host, $port) = split /:/, $CFG->{host}; |
120 | |
120 | |
121 | $CONN = new conn |
121 | $CONN = eval { |
|
|
122 | new conn |
122 | host => $host, |
123 | host => $host, |
123 | port => $port || 13327, |
124 | port => $port || 13327, |
124 | user => $CFG->{user}, |
125 | user => $CFG->{user}, |
125 | pass => $CFG->{password}, |
126 | pass => $CFG->{password}, |
126 | mapw => $mapsize, |
127 | mapw => $mapsize, |
127 | maph => $mapsize, |
128 | maph => $mapsize, |
|
|
129 | ; |
128 | ; |
130 | }; |
129 | |
131 | |
|
|
132 | if ($CONN) { |
130 | status "login successful"; |
133 | status "login successful"; |
131 | |
134 | |
132 | CFClient::lowdelay fileno $CONN->{fh}; |
135 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
136 | } else { |
|
|
137 | status "unable to connect"; |
|
|
138 | } |
133 | } |
139 | } |
134 | |
140 | |
135 | sub stop_game { |
141 | sub stop_game { |
136 | undef $CONN; |
142 | undef $CONN; |
137 | } |
143 | } |
… | |
… | |
783 | $window |
789 | $window |
784 | } |
790 | } |
785 | |
791 | |
786 | sub make_inventory_window { |
792 | sub make_inventory_window { |
787 | my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; |
793 | my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; |
788 | $invwin->add (my $hb = new CFClient::UI::HBox); |
|
|
789 | $hb->add ($INV = new CFClient::UI::Inventory expand => 1); |
794 | $invwin->add ($INV = new CFClient::UI::Inventory expand => 1); |
790 | $hb->add (my $rng = new CFClient::UI::Slider vertical => 1); |
|
|
791 | $INV->set_range ($rng); |
|
|
792 | $invwin |
795 | $invwin |
793 | } |
796 | } |
794 | |
797 | |
795 | sub sdl_init { |
798 | sub sdl_init { |
796 | CFClient::SDL_Init |
799 | CFClient::SDL_Init |
797 | and die "SDL::Init failed!\n"; |
800 | and die "SDL::Init failed!\n"; |
798 | } |
801 | } |
799 | |
802 | |
800 | sub video_init { |
803 | sub video_init { |
801 | sdl_init; |
804 | sdl_init; |
|
|
805 | |
|
|
806 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; |
802 | |
807 | |
803 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
808 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
804 | $FULLSCREEN = $CFG->{fullscreen}; |
809 | $FULLSCREEN = $CFG->{fullscreen}; |
805 | $FAST = $CFG->{fast}; |
810 | $FAST = $CFG->{fast}; |
806 | |
811 | |
… | |
… | |
895 | push @bgmusic, shift @bgmusic; |
900 | push @bgmusic, shift @bgmusic; |
896 | } |
901 | } |
897 | |
902 | |
898 | sub audio_init { |
903 | sub audio_init { |
899 | if ($CFG->{audio_enable}) { |
904 | if ($CFG->{audio_enable}) { |
900 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
905 | if (open my $fh, "<", CFClient::find_rcfile "sounds/config") { |
901 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
906 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
902 | CFClient::Mix_AllocateChannels 8; |
907 | CFClient::Mix_AllocateChannels 8; |
903 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
908 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
904 | |
909 | |
905 | audio_music_finished; |
910 | audio_music_finished; |
… | |
… | |
1325 | $FLOORBOX->clear; |
1330 | $FLOORBOX->clear; |
1326 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1331 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1327 | |
1332 | |
1328 | # we basically have to use the same sorting as everybody else |
1333 | # we basically have to use the same sorting as everybody else |
1329 | for my $item (@{ $CONN->{container}{0} }) { |
1334 | for my $item (@{ $CONN->{container}{0} }) { |
1330 | my $desc = $item->{nrof} < 2 |
1335 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); |
1331 | ? $item->{name} |
|
|
1332 | : "$item->{nrof} $item->{name_pl}"; |
|
|
1333 | # todo: animation widget, face widget, weight(?) etc. |
|
|
1334 | $FLOORBOX->add (my $hbox = new CFClient::UI::HBox |
|
|
1335 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
1336 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
1337 | can_hover => 1, |
|
|
1338 | can_events => 1, |
|
|
1339 | connect_button_down => sub { |
|
|
1340 | my ($self, $ev, $x, $y) = @_; |
|
|
1341 | |
|
|
1342 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
1343 | if ($ev->{button} == 1) { |
|
|
1344 | $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0"); |
|
|
1345 | } elsif ($ev->{button} == 2) { |
|
|
1346 | $CONN->send ("apply $item->{tag}"); |
|
|
1347 | } elsif ($ev->{button} == 3) { |
|
|
1348 | CFClient::UI::Menu->new ( |
|
|
1349 | items => [ |
|
|
1350 | ["examine", sub { $CONN->send ("examine $item->{tag}") }], |
|
|
1351 | [ |
|
|
1352 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
1353 | sub { $CONN->send ("lock $item->{tag}") }, |
|
|
1354 | ], |
|
|
1355 | ["mark", sub { $CONN->send ("mark $item->{tag}") }], |
|
|
1356 | ["apply", sub { $CONN->send ("apply $item->{tag}") }], |
|
|
1357 | ], |
|
|
1358 | )->popup ($ev); |
|
|
1359 | } |
|
|
1360 | |
|
|
1361 | 1 |
|
|
1362 | }, |
|
|
1363 | ); |
|
|
1364 | |
|
|
1365 | $hbox->add (new CFClient::UI::Face |
|
|
1366 | can_events => 0, |
|
|
1367 | face => $item->{face}, |
|
|
1368 | anim => $item->{anim}, |
|
|
1369 | animspeed => $item->{animspeed}, |
|
|
1370 | ); |
|
|
1371 | |
|
|
1372 | $hbox->add (new CFClient::UI::Label |
|
|
1373 | can_events => 0, |
|
|
1374 | text => $desc, |
|
|
1375 | ); |
|
|
1376 | } |
1336 | } |
1377 | }); |
1337 | }); |
1378 | refresh; |
1338 | refresh; |
1379 | } |
1339 | } |
1380 | |
1340 | |
… | |
… | |
1449 | |
1409 | |
1450 | ############################################################################# |
1410 | ############################################################################# |
1451 | |
1411 | |
1452 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1412 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1453 | |
1413 | |
|
|
1414 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1415 | |
1454 | $TILECACHE = CFClient::db_table "tilecache"; |
1416 | $TILECACHE = CFClient::db_table "tilecache"; |
1455 | $FACEMAP = CFClient::db_table "facemap"; |
1417 | $FACEMAP = CFClient::db_table "facemap"; |
1456 | |
|
|
1457 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1458 | |
1418 | |
1459 | my %DEF_CFG = ( |
1419 | my %DEF_CFG = ( |
1460 | sdl_mode => 0, |
1420 | sdl_mode => 0, |
1461 | width => 640, |
1421 | width => 640, |
1462 | height => 480, |
1422 | height => 480, |