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.118 by root, Tue Aug 22 06:37:30 2006 UTC vs.
Revision 1.120 by root, Sun Oct 1 14:48:51 2006 UTC

47 47
48$Event::Eval = 0; 48$Event::Eval = 0;
49$Event::DIED = sub { 49$Event::DIED = sub {
50 # TODO: display dialog box or so 50 # TODO: display dialog box or so
51 Carp::cluck $_[1];#d#TODO: remove when stable 51 Carp::cluck $_[1];#d#TODO: remove when stable
52 CFPlus::error $_[1];
53};
54
55$SIG{__DIE__} = sub {
56 return if CFPlus::in_destruct;
57 Carp::cluck $_[0];
58 CFPlus::error $_[0];
59 return;#d# 52 return;#d#
60 #return unless defined $^S && !$^S; 53 CFPlus::fatal ($_[1]);
61 $Event::DIED->(undef, $_[0]);
62}; 54};
63 55
64our $VERSION = '0.9'; 56our $VERSION = '0.9';
65 57
66my $MAX_FPS = 60; 58my $MAX_FPS = 60;
71our $LAST_REFRESH; 63our $LAST_REFRESH;
72our $NOW; 64our $NOW;
73 65
74our $CFG; 66our $CFG;
75our $CONN; 67our $CONN;
68our $PROFILE; # current profile
76our $FAST; # fast, low-quality mode, possibly useful for software-rendering 69our $FAST; # fast, low-quality mode, possibly useful for software-rendering
77 70
78our $WANT_REFRESH; 71our $WANT_REFRESH;
79our $CAN_REFRESH; 72our $CAN_REFRESH;
80 73
352 status "logging in..."; 345 status "logging in...";
353 346
354 $LOGIN_BUTTON->set_text ("Logout"); 347 $LOGIN_BUTTON->set_text ("Logout");
355 $SETUP_DIALOG->hide; 348 $SETUP_DIALOG->hide;
356 349
350 $PROFILE = $CFG->{profile}{default};
351
357 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 352 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
358 353
359 my ($host, $port) = split /:/, $CFG->{profile}{default}{host}; 354 my ($host, $port) = split /:/, $PROFILE->{host};
360 355
361 $MAP = new CFPlus::Map $mapsize, $mapsize; 356 $MAP = new CFPlus::Map $mapsize, $mapsize;
362 357
363 $CONN = eval { 358 $CONN = eval {
364 new CFPlus::Protocol 359 new CFPlus::Protocol
365 host => $host, 360 host => $host,
366 port => $port || 13327, 361 port => $port || 13327,
367 user => $CFG->{profile}{default}{user}, 362 user => $PROFILE->{user},
368 pass => $CFG->{profile}{default}{password}, 363 pass => $PROFILE->{password},
369 mapw => $mapsize, 364 mapw => $mapsize,
370 maph => $mapsize, 365 maph => $mapsize,
371 366
372 client => "cfplus $VERSION $] $^O", 367 client => "cfplus $VERSION $] $^O",
373 368
415 destroy_query_dialog $CONN; 410 destroy_query_dialog $CONN;
416 $CONN->destroy; 411 $CONN->destroy;
417 $CONN = 0; # false, does not autovivify 412 $CONN = 0; # false, does not autovivify
418 413
419 undef $MAP; 414 undef $MAP;
415 undef $PROFILE;
420} 416}
421 417
422sub graphics_setup { 418sub graphics_setup {
423 my $vbox = new CFPlus::UI::VBox; 419 my $vbox = new CFPlus::UI::VBox;
424 420
1045 }, 1041 },
1046 ); 1042 );
1047 1043
1048 $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); 1044 $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command");
1049 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry 1045 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry
1050 text => $CFG->{say_command}, 1046 text => $CFG->{say_command},
1051 tooltip => "This is the command that will be used if you write a line in the message window entry or press <b>\"</b> in the map window. " 1047 tooltip => "This is the command that will be used if you write a line in the message window entry or press <b>\"</b> in the map window. "
1052 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " 1048 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
1053 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.", 1049 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.",
1054 on_changed => sub { 1050 on_changed => sub {
1055 my ($self, $value) = @_; 1051 my ($self, $value) = @_;
1056 $CFG->{say_command} = $value; 1052 $CFG->{say_command} = $value;
1053 0
1054 }
1055 );
1056
1057 $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day");
1058 $table->add (1, 13, my $saycmd = new CFPlus::UI::CheckBox
1059 state => $CFG->{show_tips},
1060 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1061 on_changed => sub {
1062 my ($self, $value) = @_;
1063 $CFG->{shop_tips} = $value;
1057 0 1064 0
1058 } 1065 }
1059 ); 1066 );
1060 1067
1061 $vbox->add (new CFPlus::UI::FancyFrame 1068 $vbox->add (new CFPlus::UI::FancyFrame
1125 window => $window, 1132 window => $window,
1126 input => $input, 1133 input => $input,
1127 }; 1134 };
1128 1135
1129 $window 1136 $window
1130}
1131
1132sub open_string_query {
1133 my ($title, $cb, $txt, $tooltip) = @_;
1134 my $dialog = new CFPlus::UI::Toplevel
1135 x => "center",
1136 y => "center",
1137 z => 50,
1138 force_w => $WIDTH * 4/5,
1139 title => $title;
1140
1141 $dialog->add (
1142 my $e = new CFPlus::UI::Entry
1143 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
1144 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
1145 tooltip => $tooltip
1146 );
1147
1148 $e->grab_focus;
1149 $e->set_text ($txt) if $txt;
1150 $dialog->show;
1151}
1152
1153sub open_quit_dialog {
1154 unless ($QUIT_DIALOG) {
1155 $QUIT_DIALOG = new CFPlus::UI::Toplevel
1156 x => "center",
1157 y => "center",
1158 z => 50,
1159 title => "Really Quit?",
1160 on_key_down => sub {
1161 my ($dialog, $ev) = @_;
1162 $ev->{sym} == 27 and $dialog->hide;
1163 }
1164 ;
1165
1166 $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1);
1167
1168 $vb->add (new CFPlus::UI::Label
1169 text => "You should find a savebed and apply it first!",
1170 max_w => $WIDTH * 0.25,
1171 ellipsize => 0,
1172 );
1173 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1174 $hb->add (new CFPlus::UI::Button
1175 text => "Ok",
1176 expand => 1,
1177 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1178 );
1179 $hb->add (new CFPlus::UI::Button
1180 text => "Quit anyway",
1181 expand => 1,
1182 on_activate => sub { exit },
1183 );
1184 }
1185
1186 $QUIT_DIALOG->show;
1187 $QUIT_DIALOG->grab_focus;
1188} 1137}
1189 1138
1190sub autopickup_setup { 1139sub autopickup_setup {
1191 my $table = new CFPlus::UI::Table; 1140 my $table = new CFPlus::UI::Table;
1192 1141
1401 1350
1402 my $refresh; 1351 my $refresh;
1403 $refresh = $BIND_UPD_CB = sub { 1352 $refresh = $BIND_UPD_CB = sub {
1404 $binding_list->clear (); 1353 $binding_list->clear ();
1405 1354
1355 return unless $PROFILE;
1356
1406 for my $mod (keys %{$::CFG->{profile}{default}{bindings}}) { 1357 for my $mod (keys %{$PROFILE->{bindings}}) {
1407 for my $sym (keys %{$::CFG->{profile}{default}{bindings}{$mod}}) { 1358 for my $sym (keys %{$PROFILE->{bindings}{$mod}}) {
1408 my $cmds = $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1359 my $cmds = $PROFILE->{bindings}{$mod}{$sym};
1409 next unless ref $cmds eq 'ARRAY' and @$cmds > 0; 1360 next unless ref $cmds eq 'ARRAY' and @$cmds > 0;
1410 1361
1411 my $lbl = join "; ", @$cmds; 1362 my $lbl = join "; ", @$cmds;
1412 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym); 1363 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym);
1413 $binding_list->add (my $hb = new CFPlus::UI::HBox); 1364 $binding_list->add (my $hb = new CFPlus::UI::HBox);
1414 $hb->add (new CFPlus::UI::Button 1365 $hb->add (new CFPlus::UI::Button
1415 text => "delete", 1366 text => "delete",
1416 tooltip => "Deletes the binding", 1367 tooltip => "Deletes the binding",
1417 on_activate => sub { 1368 on_activate => sub {
1418 $binding_list->remove ($hb); 1369 $binding_list->remove ($hb);
1419 delete $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1370 delete $PROFILE->{bindings}{$mod}{$sym};
1420 0 1371 0
1421 }); 1372 });
1422 1373
1423 $hb->add (new CFPlus::UI::Button 1374 $hb->add (new CFPlus::UI::Button
1424 text => "edit", 1375 text => "edit",
1425 tooltip => "Edits the binding", 1376 tooltip => "Edits the binding",
1426 on_activate => sub { 1377 on_activate => sub {
1427 $::BIND_EDITOR->set_binding ( 1378 $::BIND_EDITOR->set_binding (
1428 $mod, $sym, $::CFG->{profile}{default}{bindings}{$mod}{$sym}, 1379 $mod, $sym, $PROFILE->{bindings}{$mod}{$sym},
1429 sub { 1380 sub {
1430 my ($nmod, $nsym, $ncmds) = @_; 1381 my ($nmod, $nsym, $ncmds) = @_;
1431 $::BIND_EDITOR->cfg_unbind ($mod, $sym); 1382 $::BIND_EDITOR->cfg_unbind ($mod, $sym);
1432 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds); 1383 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds);
1433 $refresh->(); 1384 $refresh->();
1511 1462
1512sub help_window { 1463sub help_window {
1513 my $win = new CFPlus::UI::Toplevel 1464 my $win = new CFPlus::UI::Toplevel
1514 x => 'center', 1465 x => 'center',
1515 y => 'center', 1466 y => 'center',
1516 z => 2, 1467 z => 4,
1517 name => 'doc_browser', 1468 name => 'doc_browser',
1518 force_w => int $WIDTH * 7/8, 1469 force_w => int $WIDTH * 7/8,
1519 force_h => int $HEIGHT * 7/8, 1470 force_h => int $HEIGHT * 7/8,
1520 title => "Help Browser", 1471 title => "Help Browser",
1521 has_close_button => 1; 1472 has_close_button => 1;
1607 $load_node->((CFPlus::Pod::find @path)[0]); 1558 $load_node->((CFPlus::Pod::find @path)[0]);
1608 $win->show; 1559 $win->show;
1609 }; 1560 };
1610 1561
1611 $win 1562 $win
1563}
1564
1565sub open_string_query {
1566 my ($title, $cb, $txt, $tooltip) = @_;
1567 my $dialog = new CFPlus::UI::Toplevel
1568 x => "center",
1569 y => "center",
1570 z => 50,
1571 force_w => $WIDTH * 4/5,
1572 title => $title;
1573
1574 $dialog->add (
1575 my $e = new CFPlus::UI::Entry
1576 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
1577 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
1578 tooltip => $tooltip
1579 );
1580
1581 $e->grab_focus;
1582 $e->set_text ($txt) if $txt;
1583 $dialog->show;
1584}
1585
1586sub open_quit_dialog {
1587 unless ($QUIT_DIALOG) {
1588 $QUIT_DIALOG = new CFPlus::UI::Toplevel
1589 x => "center",
1590 y => "center",
1591 z => 50,
1592 title => "Really Quit?",
1593 on_key_down => sub {
1594 my ($dialog, $ev) = @_;
1595 $ev->{sym} == 27 and $dialog->hide;
1596 }
1597 ;
1598
1599 $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1);
1600
1601 $vb->add (new CFPlus::UI::Label
1602 text => "You should find a savebed and apply it first!",
1603 max_w => $WIDTH * 0.25,
1604 ellipsize => 0,
1605 );
1606 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1607 $hb->add (new CFPlus::UI::Button
1608 text => "Ok",
1609 expand => 1,
1610 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1611 );
1612 $hb->add (new CFPlus::UI::Button
1613 text => "Quit anyway",
1614 expand => 1,
1615 on_activate => sub { exit },
1616 );
1617 }
1618
1619 $QUIT_DIALOG->show;
1620 $QUIT_DIALOG->grab_focus;
1621}
1622
1623sub show_tip_of_the_day {
1624 # find all tips
1625 my @tod = CFPlus::Pod::find tip_of_the_day => "*";
1626
1627 my $todindex = $CFPlus::DB_STATE->get ("tip_of_the_day");
1628 $todindex = 0 if $todindex >= @tod;
1629 $CFPlus::DB_STATE->put (tip_of_the_day => $todindex + 1);
1630
1631 # create dialog
1632 my $dialog;
1633
1634 my $close = sub {
1635 $dialog->destroy;
1636 };
1637
1638 $dialog = new CFPlus::UI::Toplevel
1639 x => "center",
1640 y => "center",
1641 z => 3,
1642 name => 'tip_of_the_day',
1643 force_w => int $WIDTH * 4/9,
1644 force_h => int $WIDTH * 2/9,
1645 title => "Tip of the day #" . (1 + $todindex),
1646 child => my $vbox = new CFPlus::UI::VBox,
1647 has_close_button => 1,
1648 on_delete => $close,
1649 ;
1650
1651 $vbox->add (my $viewer = new CFPlus::UI::TextScroller
1652 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1653 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]);
1654
1655 $vbox->add (my $table = new CFPlus::UI::Table);
1656
1657 $table->add (0, 0, new CFPlus::UI::Button
1658 text => "Close",
1659 tooltip => "Close the tip of the day window. To never see it again, disable the tip of the day in the <b>Server Setup</b>.",
1660 on_activate => $close,
1661 );
1662
1663 $table->add (2, 0, new CFPlus::UI::Button
1664 text => "Next",
1665 tooltip => "Show the next <b>Tip of the day</b>.",
1666 on_activate => sub {
1667 $close->();
1668 &show_tip_of_the_day;
1669 },
1670 );
1671
1672 $dialog->show;
1612} 1673}
1613 1674
1614sub sdl_init { 1675sub sdl_init {
1615 CFPlus::SDL_Init 1676 CFPlus::SDL_Init
1616 and die "SDL::Init failed!\n"; 1677 and die "SDL::Init failed!\n";
1975 output_sync => 1, 2036 output_sync => 1,
1976 output_count => 1, 2037 output_count => 1,
1977 pickup => 0, 2038 pickup => 0,
1978 inv_sort => "mtime", 2039 inv_sort => "mtime",
1979 default => "profile", # default profile 2040 default => "profile", # default profile
2041 show_tips => 1,
1980 ); 2042 );
1981 2043
1982 while (my ($k, $v) = each %DEF_CFG) { 2044 while (my ($k, $v) = each %DEF_CFG) {
1983 $CFG->{$k} = $v unless exists $CFG->{$k}; 2045 $CFG->{$k} = $v unless exists $CFG->{$k};
1984 } 2046 }
2032 2094
2033 video_init; 2095 video_init;
2034 audio_init; 2096 audio_init;
2035} 2097}
2036 2098
2099show_tip_of_the_day if $CFG->{show_tips};
2100
2101use Data::Dumper; warn Dumper [CFPlus::win32_proxy_info()];#d#
2102
2037Event::loop; 2103Event::loop;
2038#CFPlus::SDL_Quit; 2104#CFPlus::SDL_Quit;
2039#CFPlus::_exit 0; 2105#CFPlus::_exit 0;
2040 2106
2041END { CFPlus::SDL_Quit } 2107END { CFPlus::SDL_Quit }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines