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.114 by root, Mon Aug 14 01:21:02 2006 UTC vs.
Revision 1.121 by root, Sun Oct 1 18:17:38 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]; 52 return;#d#
53 CFPlus::fatal ($_[1]);
53}; 54};
54
55$SIG{__DIE__} = sub {
56 return if CFPlus::in_destruct;
57 Carp::cluck $_[0];
58 CFPlus::error $_[0];
59 return;#d#
60 #return unless defined $^S && !$^S;
61 $Event::DIED->(undef, $_[0]);
62};
63
64our $VERSION = '0.1';
65 55
66my $MAX_FPS = 60; 56my $MAX_FPS = 60;
67my $MIN_FPS = 5; # unused as of yet 57my $MIN_FPS = 5; # unused as of yet
68 58
69our $META_SERVER = "crossfire.real-time.com:13326"; 59our $META_SERVER = "crossfire.real-time.com:13326";
71our $LAST_REFRESH; 61our $LAST_REFRESH;
72our $NOW; 62our $NOW;
73 63
74our $CFG; 64our $CFG;
75our $CONN; 65our $CONN;
66our $PROFILE; # current profile
76our $FAST; # fast, low-quality mode, possibly useful for software-rendering 67our $FAST; # fast, low-quality mode, possibly useful for software-rendering
77 68
78our $WANT_REFRESH; 69our $WANT_REFRESH;
79our $CAN_REFRESH; 70our $CAN_REFRESH;
80 71
352 status "logging in..."; 343 status "logging in...";
353 344
354 $LOGIN_BUTTON->set_text ("Logout"); 345 $LOGIN_BUTTON->set_text ("Logout");
355 $SETUP_DIALOG->hide; 346 $SETUP_DIALOG->hide;
356 347
348 $PROFILE = $CFG->{profile}{default};
349
357 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 350 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
358 351
359 my ($host, $port) = split /:/, $CFG->{profile}{default}{host}; 352 my ($host, $port) = split /:/, $PROFILE->{host};
360 353
361 $MAP = new CFPlus::Map $mapsize, $mapsize; 354 $MAP = new CFPlus::Map $mapsize, $mapsize;
362 355
363 $CONN = eval { 356 $CONN = eval {
364 new CFPlus::Protocol 357 new CFPlus::Protocol
365 host => $host, 358 host => $host,
366 port => $port || 13327, 359 port => $port || 13327,
367 user => $CFG->{profile}{default}{user}, 360 user => $PROFILE->{user},
368 pass => $CFG->{profile}{default}{password}, 361 pass => $PROFILE->{password},
369 mapw => $mapsize, 362 mapw => $mapsize,
370 maph => $mapsize, 363 maph => $mapsize,
364
365 client => "cfplus $CFPlus::VERSION $] $^O",
371 366
372 map_widget => $MAPWIDGET, 367 map_widget => $MAPWIDGET,
373 logview => $LOGVIEW, 368 logview => $LOGVIEW,
374 statusbox => $STATUSBOX, 369 statusbox => $STATUSBOX,
375 map => $MAP, 370 map => $MAP,
1043 }, 1038 },
1044 ); 1039 );
1045 1040
1046 $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); 1041 $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command");
1047 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry 1042 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry
1048 text => $CFG->{say_command}, 1043 text => $CFG->{say_command},
1049 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. " 1044 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. "
1050 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " 1045 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
1051 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.", 1046 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.",
1052 on_changed => sub { 1047 on_changed => sub {
1053 my ($self, $value) = @_; 1048 my ($self, $value) = @_;
1054 $CFG->{say_command} = $value; 1049 $CFG->{say_command} = $value;
1050 0
1051 }
1052 );
1053
1054 $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day");
1055 $table->add (1, 13, my $saycmd = new CFPlus::UI::CheckBox
1056 state => $CFG->{show_tips},
1057 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1058 on_changed => sub {
1059 my ($self, $value) = @_;
1060 $CFG->{show_tips} = $value;
1055 0 1061 0
1056 } 1062 }
1057 ); 1063 );
1058 1064
1059 $vbox->add (new CFPlus::UI::FancyFrame 1065 $vbox->add (new CFPlus::UI::FancyFrame
1123 window => $window, 1129 window => $window,
1124 input => $input, 1130 input => $input,
1125 }; 1131 };
1126 1132
1127 $window 1133 $window
1128}
1129
1130sub open_string_query {
1131 my $cb = $_[1];
1132 my $dialog = new CFPlus::UI::Toplevel
1133 x => "center",
1134 y => "center",
1135 z => 50,
1136 force_w => $WIDTH * 4/5,
1137 title => $_[0];
1138
1139 $dialog->add (
1140 my $e = new CFPlus::UI::Entry
1141 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
1142 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
1143 );
1144
1145 $e->grab_focus;
1146 $dialog->show;
1147}
1148
1149sub open_quit_dialog {
1150 unless ($QUIT_DIALOG) {
1151 $QUIT_DIALOG = new CFPlus::UI::Toplevel
1152 x => "center",
1153 y => "center",
1154 z => 50,
1155 title => "Really Quit?",
1156 on_key_down => sub {
1157 my ($dialog, $ev) = @_;
1158 $ev->{sym} == 27 and $dialog->hide;
1159 }
1160 ;
1161
1162 $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1);
1163
1164 $vb->add (new CFPlus::UI::Label
1165 text => "You should find a savebed and apply it first!",
1166 max_w => $WIDTH * 0.25,
1167 ellipsize => 0,
1168 );
1169 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1170 $hb->add (new CFPlus::UI::Button
1171 text => "Ok",
1172 expand => 1,
1173 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1174 );
1175 $hb->add (new CFPlus::UI::Button
1176 text => "Quit anyway",
1177 expand => 1,
1178 on_activate => sub { exit },
1179 );
1180 }
1181
1182 $QUIT_DIALOG->show;
1183 $QUIT_DIALOG->grab_focus;
1184} 1134}
1185 1135
1186sub autopickup_setup { 1136sub autopickup_setup {
1187 my $table = new CFPlus::UI::Table; 1137 my $table = new CFPlus::UI::Table;
1188 1138
1397 1347
1398 my $refresh; 1348 my $refresh;
1399 $refresh = $BIND_UPD_CB = sub { 1349 $refresh = $BIND_UPD_CB = sub {
1400 $binding_list->clear (); 1350 $binding_list->clear ();
1401 1351
1352 return unless $PROFILE;
1353
1402 for my $mod (keys %{$::CFG->{profile}{default}{bindings}}) { 1354 for my $mod (keys %{$PROFILE->{bindings}}) {
1403 for my $sym (keys %{$::CFG->{profile}{default}{bindings}{$mod}}) { 1355 for my $sym (keys %{$PROFILE->{bindings}{$mod}}) {
1404 my $cmds = $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1356 my $cmds = $PROFILE->{bindings}{$mod}{$sym};
1405 next unless ref $cmds eq 'ARRAY' and @$cmds > 0; 1357 next unless ref $cmds eq 'ARRAY' and @$cmds > 0;
1406 1358
1407 my $lbl = join "; ", @$cmds; 1359 my $lbl = join "; ", @$cmds;
1408 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym); 1360 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym);
1409 $binding_list->add (my $hb = new CFPlus::UI::HBox); 1361 $binding_list->add (my $hb = new CFPlus::UI::HBox);
1410 $hb->add (new CFPlus::UI::Button 1362 $hb->add (new CFPlus::UI::Button
1411 text => "delete", 1363 text => "delete",
1412 tooltip => "Deletes the binding", 1364 tooltip => "Deletes the binding",
1413 on_activate => sub { 1365 on_activate => sub {
1414 $binding_list->remove ($hb); 1366 $binding_list->remove ($hb);
1415 delete $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1367 delete $PROFILE->{bindings}{$mod}{$sym};
1416 0 1368 0
1417 }); 1369 });
1418 1370
1419 $hb->add (new CFPlus::UI::Button 1371 $hb->add (new CFPlus::UI::Button
1420 text => "edit", 1372 text => "edit",
1421 tooltip => "Edits the binding", 1373 tooltip => "Edits the binding",
1422 on_activate => sub { 1374 on_activate => sub {
1423 $::BIND_EDITOR->set_binding ( 1375 $::BIND_EDITOR->set_binding (
1424 $mod, $sym, $::CFG->{profile}{default}{bindings}{$mod}{$sym}, 1376 $mod, $sym, $PROFILE->{bindings}{$mod}{$sym},
1425 sub { 1377 sub {
1426 my ($nmod, $nsym, $ncmds) = @_; 1378 my ($nmod, $nsym, $ncmds) = @_;
1427 $::BIND_EDITOR->cfg_unbind ($mod, $sym); 1379 $::BIND_EDITOR->cfg_unbind ($mod, $sym);
1428 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds); 1380 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds);
1429 $refresh->(); 1381 $refresh->();
1507 1459
1508sub help_window { 1460sub help_window {
1509 my $win = new CFPlus::UI::Toplevel 1461 my $win = new CFPlus::UI::Toplevel
1510 x => 'center', 1462 x => 'center',
1511 y => 'center', 1463 y => 'center',
1512 z => 2, 1464 z => 4,
1513 name => 'doc_browser', 1465 name => 'doc_browser',
1514 force_w => int $WIDTH * 7/8, 1466 force_w => int $WIDTH * 7/8,
1515 force_h => int $HEIGHT * 7/8, 1467 force_h => int $HEIGHT * 7/8,
1516 title => "Help Browser", 1468 title => "Help Browser",
1517 has_close_button => 1; 1469 has_close_button => 1;
1528 my @history; 1480 my @history;
1529 my @future; 1481 my @future;
1530 my $curnode; 1482 my $curnode;
1531 1483
1532 my $load_node; $load_node = sub { 1484 my $load_node; $load_node = sub {
1533 my ($node) = @_; 1485 my ($node, $para) = @_;
1534 1486
1535 $buttons->clear; 1487 $buttons->clear;
1488
1489 $buttons->add (new CFPlus::UI::Button
1490 text => "⇤",
1491 tooltip => "back to the starting page",
1492 on_activate => sub {
1493 unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
1494 unshift @future, @history;
1495 @history = ();
1496 $load_node->(@{shift @future});
1497 },
1498 );
1536 1499
1537 if (@history) { 1500 if (@history) {
1538 $buttons->add (new CFPlus::UI::Button 1501 $buttons->add (new CFPlus::UI::Button
1539 text => "⋘", 1502 text => "⋘",
1540 tooltip => "back to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $history[-1]) . "</i>", 1503 tooltip => "back to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $history[-1][0]) . "</i>",
1541 on_activate => sub { 1504 on_activate => sub {
1542 unshift @future, $curnode if $curnode; 1505 unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
1543 $load_node->(pop @history); 1506 $load_node->(@{pop @history});
1544 }, 1507 },
1545 ); 1508 );
1546 } 1509 }
1547 1510
1548 if (@future) { 1511 if (@future) {
1549 $buttons->add (new CFPlus::UI::Button 1512 $buttons->add (new CFPlus::UI::Button
1550 text => "⋙", 1513 text => "⋙",
1551 tooltip => "forward to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $future[0]) . "</i>", 1514 tooltip => "forward to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $future[0][0]) . "</i>",
1552 on_activate => sub { 1515 on_activate => sub {
1553 push @history, $curnode; 1516 push @history, [$curnode, $viewer->current_paragraph];
1554 $load_node->(shift @future); 1517 $load_node->(@{shift @future});
1555 }, 1518 },
1556 ); 1519 );
1557 } 1520 }
1558 1521
1559 $buttons->add (new CFPlus::UI::Label text => " "); 1522 $buttons->add (new CFPlus::UI::Label text => " ");
1564 for my $node (@path) { 1527 for my $node (@path) {
1565 $buttons->add (new CFPlus::UI::Button 1528 $buttons->add (new CFPlus::UI::Button
1566 text => $node->{kw}[0], 1529 text => $node->{kw}[0],
1567 tooltip => "go to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $node) . "</i>", 1530 tooltip => "go to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $node) . "</i>",
1568 on_activate => sub { 1531 on_activate => sub {
1569 push @history, $curnode if $curnode; @future = (); 1532 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
1570 $load_node->($node); 1533 $load_node->($node);
1571 }, 1534 },
1572 ); 1535 );
1573 $buttons->add (new CFPlus::UI::Label text => "/"); 1536 $buttons->add (new CFPlus::UI::Label text => "/");
1574 } 1537 }
1577 1540
1578 $curnode = $node; 1541 $curnode = $node;
1579 1542
1580 $viewer->clear; 1543 $viewer->clear;
1581 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode); 1544 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode);
1582 $viewer->set_offset (0); 1545 $viewer->scroll_to ($para);
1583 }; 1546 };
1584 1547
1585 $load_node->(CFPlus::Pod::find pod => "mainpage"); 1548 $load_node->(CFPlus::Pod::find pod => "mainpage");
1586 1549
1587 $CFPlus::Pod::goto_document = sub { 1550 $CFPlus::Pod::goto_document = sub {
1588 my (@path) = @_; 1551 my (@path) = @_;
1589 1552
1590 push @history, $curnode if $curnode; @future = (); 1553 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
1591 1554
1592 $load_node->(CFPlus::Pod::find @path); 1555 $load_node->((CFPlus::Pod::find @path)[0]);
1593 $win->show; 1556 $win->show;
1594 }; 1557 };
1595 1558
1596 $win 1559 $win
1560}
1561
1562sub open_string_query {
1563 my ($title, $cb, $txt, $tooltip) = @_;
1564 my $dialog = new CFPlus::UI::Toplevel
1565 x => "center",
1566 y => "center",
1567 z => 50,
1568 force_w => $WIDTH * 4/5,
1569 title => $title;
1570
1571 $dialog->add (
1572 my $e = new CFPlus::UI::Entry
1573 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
1574 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
1575 tooltip => $tooltip
1576 );
1577
1578 $e->grab_focus;
1579 $e->set_text ($txt) if $txt;
1580 $dialog->show;
1581}
1582
1583sub open_quit_dialog {
1584 unless ($QUIT_DIALOG) {
1585 $QUIT_DIALOG = new CFPlus::UI::Toplevel
1586 x => "center",
1587 y => "center",
1588 z => 50,
1589 title => "Really Quit?",
1590 on_key_down => sub {
1591 my ($dialog, $ev) = @_;
1592 $ev->{sym} == 27 and $dialog->hide;
1593 }
1594 ;
1595
1596 $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1);
1597
1598 $vb->add (new CFPlus::UI::Label
1599 text => "You should find a savebed and apply it first!",
1600 max_w => $WIDTH * 0.25,
1601 ellipsize => 0,
1602 );
1603 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1604 $hb->add (new CFPlus::UI::Button
1605 text => "Ok",
1606 expand => 1,
1607 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1608 );
1609 $hb->add (new CFPlus::UI::Button
1610 text => "Quit anyway",
1611 expand => 1,
1612 on_activate => sub { exit },
1613 );
1614 }
1615
1616 $QUIT_DIALOG->show;
1617 $QUIT_DIALOG->grab_focus;
1618}
1619
1620sub show_tip_of_the_day {
1621 # find all tips
1622 my @tod = CFPlus::Pod::find tip_of_the_day => "*";
1623
1624 my $todindex = $CFPlus::DB_STATE->get ("tip_of_the_day");
1625 $todindex = 0 if $todindex >= @tod;
1626 $CFPlus::DB_STATE->put (tip_of_the_day => $todindex + 1);
1627
1628 # create dialog
1629 my $dialog;
1630
1631 my $close = sub {
1632 $dialog->destroy;
1633 };
1634
1635 $dialog = new CFPlus::UI::Toplevel
1636 x => "center",
1637 y => "center",
1638 z => 3,
1639 name => 'tip_of_the_day',
1640 force_w => int $WIDTH * 4/9,
1641 force_h => int $WIDTH * 2/9,
1642 title => "Tip of the day #" . (1 + $todindex),
1643 child => my $vbox = new CFPlus::UI::VBox,
1644 has_close_button => 1,
1645 on_delete => $close,
1646 ;
1647
1648 $vbox->add (my $viewer = new CFPlus::UI::TextScroller
1649 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1650 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]);
1651
1652 $vbox->add (my $table = new CFPlus::UI::Table);
1653
1654 $table->add (0, 0, new CFPlus::UI::Button
1655 text => "Close",
1656 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>.",
1657 on_activate => $close,
1658 );
1659
1660 $table->add (2, 0, new CFPlus::UI::Button
1661 text => "Next",
1662 tooltip => "Show the next <b>Tip of the day</b>.",
1663 on_activate => sub {
1664 $close->();
1665 &show_tip_of_the_day;
1666 },
1667 );
1668
1669 $dialog->show;
1597} 1670}
1598 1671
1599sub sdl_init { 1672sub sdl_init {
1600 CFPlus::SDL_Init 1673 CFPlus::SDL_Init
1601 and die "SDL::Init failed!\n"; 1674 and die "SDL::Init failed!\n";
1960 output_sync => 1, 2033 output_sync => 1,
1961 output_count => 1, 2034 output_count => 1,
1962 pickup => 0, 2035 pickup => 0,
1963 inv_sort => "mtime", 2036 inv_sort => "mtime",
1964 default => "profile", # default profile 2037 default => "profile", # default profile
2038 show_tips => 1,
1965 ); 2039 );
1966 2040
1967 while (my ($k, $v) = each %DEF_CFG) { 2041 while (my ($k, $v) = each %DEF_CFG) {
1968 $CFG->{$k} = $v unless exists $CFG->{$k}; 2042 $CFG->{$k} = $v unless exists $CFG->{$k};
1969 } 2043 }
2017 2091
2018 video_init; 2092 video_init;
2019 audio_init; 2093 audio_init;
2020} 2094}
2021 2095
2096show_tip_of_the_day if $CFG->{show_tips};
2097
2022Event::loop; 2098Event::loop;
2023#CFPlus::SDL_Quit; 2099#CFPlus::SDL_Quit;
2024#CFPlus::_exit 0; 2100#CFPlus::_exit 0;
2025 2101
2026END { CFPlus::SDL_Quit } 2102END { CFPlus::SDL_Quit }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines