… | |
… | |
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 | |
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 | |
|
|
64 | our $VERSION = '0.1'; |
56 | our $VERSION = '0.9'; |
65 | |
57 | |
66 | my $MAX_FPS = 60; |
58 | my $MAX_FPS = 60; |
67 | my $MIN_FPS = 5; # unused as of yet |
59 | my $MIN_FPS = 5; # unused as of yet |
68 | |
60 | |
69 | our $META_SERVER = "crossfire.real-time.com:13326"; |
61 | our $META_SERVER = "crossfire.real-time.com:13326"; |
… | |
… | |
366 | port => $port || 13327, |
358 | port => $port || 13327, |
367 | user => $CFG->{profile}{default}{user}, |
359 | user => $CFG->{profile}{default}{user}, |
368 | pass => $CFG->{profile}{default}{password}, |
360 | pass => $CFG->{profile}{default}{password}, |
369 | mapw => $mapsize, |
361 | mapw => $mapsize, |
370 | maph => $mapsize, |
362 | maph => $mapsize, |
|
|
363 | |
|
|
364 | client => "cfplus $VERSION $] $^O", |
371 | |
365 | |
372 | map_widget => $MAPWIDGET, |
366 | map_widget => $MAPWIDGET, |
373 | logview => $LOGVIEW, |
367 | logview => $LOGVIEW, |
374 | statusbox => $STATUSBOX, |
368 | statusbox => $STATUSBOX, |
375 | map => $MAP, |
369 | map => $MAP, |
… | |
… | |
1043 | }, |
1037 | }, |
1044 | ); |
1038 | ); |
1045 | |
1039 | |
1046 | $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); |
1040 | $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 |
1041 | $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry |
1048 | text => $CFG->{say_command}, |
1042 | 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. " |
1043 | 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. " |
1044 | . "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.", |
1045 | . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.", |
1052 | on_changed => sub { |
1046 | on_changed => sub { |
1053 | my ($self, $value) = @_; |
1047 | my ($self, $value) = @_; |
1054 | $CFG->{say_command} = $value; |
1048 | $CFG->{say_command} = $value; |
|
|
1049 | 0 |
|
|
1050 | } |
|
|
1051 | ); |
|
|
1052 | |
|
|
1053 | $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); |
|
|
1054 | $table->add (1, 13, my $saycmd = new CFPlus::UI::CheckBox |
|
|
1055 | state => $CFG->{show_tips}, |
|
|
1056 | tooltip => "Show the <b>Tip of the day</b> window at startup?", |
|
|
1057 | on_changed => sub { |
|
|
1058 | my ($self, $value) = @_; |
|
|
1059 | $CFG->{shop_tips} = $value; |
1055 | 0 |
1060 | 0 |
1056 | } |
1061 | } |
1057 | ); |
1062 | ); |
1058 | |
1063 | |
1059 | $vbox->add (new CFPlus::UI::FancyFrame |
1064 | $vbox->add (new CFPlus::UI::FancyFrame |
… | |
… | |
1123 | window => $window, |
1128 | window => $window, |
1124 | input => $input, |
1129 | input => $input, |
1125 | }; |
1130 | }; |
1126 | |
1131 | |
1127 | $window |
1132 | $window |
1128 | } |
|
|
1129 | |
|
|
1130 | sub 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 | |
|
|
1149 | sub 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 | } |
1133 | } |
1185 | |
1134 | |
1186 | sub autopickup_setup { |
1135 | sub autopickup_setup { |
1187 | my $table = new CFPlus::UI::Table; |
1136 | my $table = new CFPlus::UI::Table; |
1188 | |
1137 | |
… | |
… | |
1507 | |
1456 | |
1508 | sub help_window { |
1457 | sub help_window { |
1509 | my $win = new CFPlus::UI::Toplevel |
1458 | my $win = new CFPlus::UI::Toplevel |
1510 | x => 'center', |
1459 | x => 'center', |
1511 | y => 'center', |
1460 | y => 'center', |
1512 | z => 2, |
1461 | z => 4, |
1513 | name => 'doc_browser', |
1462 | name => 'doc_browser', |
1514 | force_w => int $WIDTH * 7/8, |
1463 | force_w => int $WIDTH * 7/8, |
1515 | force_h => int $HEIGHT * 7/8, |
1464 | force_h => int $HEIGHT * 7/8, |
1516 | title => "Help Browser", |
1465 | title => "Help Browser", |
1517 | has_close_button => 1; |
1466 | has_close_button => 1; |
… | |
… | |
1528 | my @history; |
1477 | my @history; |
1529 | my @future; |
1478 | my @future; |
1530 | my $curnode; |
1479 | my $curnode; |
1531 | |
1480 | |
1532 | my $load_node; $load_node = sub { |
1481 | my $load_node; $load_node = sub { |
1533 | my ($node) = @_; |
1482 | my ($node, $para) = @_; |
1534 | |
1483 | |
1535 | $buttons->clear; |
1484 | $buttons->clear; |
|
|
1485 | |
|
|
1486 | $buttons->add (new CFPlus::UI::Button |
|
|
1487 | text => "⇤", |
|
|
1488 | tooltip => "back to the starting page", |
|
|
1489 | on_activate => sub { |
|
|
1490 | unshift @future, [$curnode, $viewer->current_paragraph] if $curnode; |
|
|
1491 | unshift @future, @history; |
|
|
1492 | @history = (); |
|
|
1493 | $load_node->(@{shift @future}); |
|
|
1494 | }, |
|
|
1495 | ); |
1536 | |
1496 | |
1537 | if (@history) { |
1497 | if (@history) { |
1538 | $buttons->add (new CFPlus::UI::Button |
1498 | $buttons->add (new CFPlus::UI::Button |
1539 | text => "⋘", |
1499 | text => "⋘", |
1540 | tooltip => "back to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $history[-1]) . "</i>", |
1500 | tooltip => "back to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $history[-1][0]) . "</i>", |
1541 | on_activate => sub { |
1501 | on_activate => sub { |
1542 | unshift @future, $curnode if $curnode; |
1502 | unshift @future, [$curnode, $viewer->current_paragraph] if $curnode; |
1543 | $load_node->(pop @history); |
1503 | $load_node->(@{pop @history}); |
1544 | }, |
1504 | }, |
1545 | ); |
1505 | ); |
1546 | } |
1506 | } |
1547 | |
1507 | |
1548 | if (@future) { |
1508 | if (@future) { |
1549 | $buttons->add (new CFPlus::UI::Button |
1509 | $buttons->add (new CFPlus::UI::Button |
1550 | text => "⋙", |
1510 | text => "⋙", |
1551 | tooltip => "forward to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $future[0]) . "</i>", |
1511 | tooltip => "forward to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $future[0][0]) . "</i>", |
1552 | on_activate => sub { |
1512 | on_activate => sub { |
1553 | push @history, $curnode; |
1513 | push @history, [$curnode, $viewer->current_paragraph]; |
1554 | $load_node->(shift @future); |
1514 | $load_node->(@{shift @future}); |
1555 | }, |
1515 | }, |
1556 | ); |
1516 | ); |
1557 | } |
1517 | } |
1558 | |
1518 | |
1559 | $buttons->add (new CFPlus::UI::Label text => " "); |
1519 | $buttons->add (new CFPlus::UI::Label text => " "); |
… | |
… | |
1564 | for my $node (@path) { |
1524 | for my $node (@path) { |
1565 | $buttons->add (new CFPlus::UI::Button |
1525 | $buttons->add (new CFPlus::UI::Button |
1566 | text => $node->{kw}[0], |
1526 | text => $node->{kw}[0], |
1567 | tooltip => "go to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $node) . "</i>", |
1527 | tooltip => "go to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $node) . "</i>", |
1568 | on_activate => sub { |
1528 | on_activate => sub { |
1569 | push @history, $curnode if $curnode; @future = (); |
1529 | push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); |
1570 | $load_node->($node); |
1530 | $load_node->($node); |
1571 | }, |
1531 | }, |
1572 | ); |
1532 | ); |
1573 | $buttons->add (new CFPlus::UI::Label text => "/"); |
1533 | $buttons->add (new CFPlus::UI::Label text => "/"); |
1574 | } |
1534 | } |
… | |
… | |
1577 | |
1537 | |
1578 | $curnode = $node; |
1538 | $curnode = $node; |
1579 | |
1539 | |
1580 | $viewer->clear; |
1540 | $viewer->clear; |
1581 | $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode); |
1541 | $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode); |
1582 | $viewer->set_offset (0); |
1542 | $viewer->scroll_to ($para); |
1583 | }; |
1543 | }; |
1584 | |
1544 | |
1585 | $load_node->(CFPlus::Pod::find pod => "mainpage"); |
1545 | $load_node->(CFPlus::Pod::find pod => "mainpage"); |
1586 | |
1546 | |
1587 | $CFPlus::Pod::goto_document = sub { |
1547 | $CFPlus::Pod::goto_document = sub { |
1588 | my (@path) = @_; |
1548 | my (@path) = @_; |
1589 | |
1549 | |
1590 | push @history, $curnode if $curnode; @future = (); |
1550 | push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); |
1591 | |
1551 | |
1592 | $load_node->(CFPlus::Pod::find @path); |
1552 | $load_node->((CFPlus::Pod::find @path)[0]); |
1593 | $win->show; |
1553 | $win->show; |
1594 | }; |
1554 | }; |
1595 | |
1555 | |
1596 | $win |
1556 | $win |
|
|
1557 | } |
|
|
1558 | |
|
|
1559 | sub open_string_query { |
|
|
1560 | my ($title, $cb, $txt, $tooltip) = @_; |
|
|
1561 | my $dialog = new CFPlus::UI::Toplevel |
|
|
1562 | x => "center", |
|
|
1563 | y => "center", |
|
|
1564 | z => 50, |
|
|
1565 | force_w => $WIDTH * 4/5, |
|
|
1566 | title => $title; |
|
|
1567 | |
|
|
1568 | $dialog->add ( |
|
|
1569 | my $e = new CFPlus::UI::Entry |
|
|
1570 | on_activate => sub { $cb->(@_); $dialog->hide; 0 }, |
|
|
1571 | on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 }, |
|
|
1572 | tooltip => $tooltip |
|
|
1573 | ); |
|
|
1574 | |
|
|
1575 | $e->grab_focus; |
|
|
1576 | $e->set_text ($txt) if $txt; |
|
|
1577 | $dialog->show; |
|
|
1578 | } |
|
|
1579 | |
|
|
1580 | sub open_quit_dialog { |
|
|
1581 | unless ($QUIT_DIALOG) { |
|
|
1582 | $QUIT_DIALOG = new CFPlus::UI::Toplevel |
|
|
1583 | x => "center", |
|
|
1584 | y => "center", |
|
|
1585 | z => 50, |
|
|
1586 | title => "Really Quit?", |
|
|
1587 | on_key_down => sub { |
|
|
1588 | my ($dialog, $ev) = @_; |
|
|
1589 | $ev->{sym} == 27 and $dialog->hide; |
|
|
1590 | } |
|
|
1591 | ; |
|
|
1592 | |
|
|
1593 | $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1); |
|
|
1594 | |
|
|
1595 | $vb->add (new CFPlus::UI::Label |
|
|
1596 | text => "You should find a savebed and apply it first!", |
|
|
1597 | max_w => $WIDTH * 0.25, |
|
|
1598 | ellipsize => 0, |
|
|
1599 | ); |
|
|
1600 | $vb->add (my $hb = new CFPlus::UI::HBox expand => 1); |
|
|
1601 | $hb->add (new CFPlus::UI::Button |
|
|
1602 | text => "Ok", |
|
|
1603 | expand => 1, |
|
|
1604 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
|
|
1605 | ); |
|
|
1606 | $hb->add (new CFPlus::UI::Button |
|
|
1607 | text => "Quit anyway", |
|
|
1608 | expand => 1, |
|
|
1609 | on_activate => sub { exit }, |
|
|
1610 | ); |
|
|
1611 | } |
|
|
1612 | |
|
|
1613 | $QUIT_DIALOG->show; |
|
|
1614 | $QUIT_DIALOG->grab_focus; |
|
|
1615 | } |
|
|
1616 | |
|
|
1617 | sub show_tip_of_the_day { |
|
|
1618 | # find all tips |
|
|
1619 | my @tod = CFPlus::Pod::find tip_of_the_day => "*"; |
|
|
1620 | |
|
|
1621 | my $todindex = $CFPlus::DB_STATE->get ("tip_of_the_day"); |
|
|
1622 | $todindex = 0 if $todindex >= @tod; |
|
|
1623 | $CFPlus::DB_STATE->put (tip_of_the_day => $todindex + 1); |
|
|
1624 | |
|
|
1625 | # create dialog |
|
|
1626 | my $dialog; |
|
|
1627 | |
|
|
1628 | my $close = sub { |
|
|
1629 | $dialog->destroy; |
|
|
1630 | }; |
|
|
1631 | |
|
|
1632 | $dialog = new CFPlus::UI::Toplevel |
|
|
1633 | x => "center", |
|
|
1634 | y => "center", |
|
|
1635 | z => 3, |
|
|
1636 | name => 'tip_of_the_day', |
|
|
1637 | force_w => int $WIDTH * 4/9, |
|
|
1638 | force_h => int $WIDTH * 2/9, |
|
|
1639 | title => "Tip of the day #" . (1 + $todindex), |
|
|
1640 | child => my $vbox = new CFPlus::UI::VBox, |
|
|
1641 | has_close_button => 1, |
|
|
1642 | on_delete => $close, |
|
|
1643 | ; |
|
|
1644 | |
|
|
1645 | $vbox->add (my $viewer = new CFPlus::UI::TextScroller |
|
|
1646 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4); |
|
|
1647 | $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]); |
|
|
1648 | |
|
|
1649 | $vbox->add (my $table = new CFPlus::UI::Table); |
|
|
1650 | |
|
|
1651 | $table->add (0, 0, new CFPlus::UI::Button |
|
|
1652 | text => "Close", |
|
|
1653 | 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>.", |
|
|
1654 | on_activate => $close, |
|
|
1655 | ); |
|
|
1656 | |
|
|
1657 | $table->add (2, 0, new CFPlus::UI::Button |
|
|
1658 | text => "Next", |
|
|
1659 | tooltip => "Show the next <b>Tip of the day</b>.", |
|
|
1660 | on_activate => sub { |
|
|
1661 | $close->(); |
|
|
1662 | &show_tip_of_the_day; |
|
|
1663 | }, |
|
|
1664 | ); |
|
|
1665 | |
|
|
1666 | $dialog->show; |
1597 | } |
1667 | } |
1598 | |
1668 | |
1599 | sub sdl_init { |
1669 | sub sdl_init { |
1600 | CFPlus::SDL_Init |
1670 | CFPlus::SDL_Init |
1601 | and die "SDL::Init failed!\n"; |
1671 | and die "SDL::Init failed!\n"; |
… | |
… | |
1960 | output_sync => 1, |
2030 | output_sync => 1, |
1961 | output_count => 1, |
2031 | output_count => 1, |
1962 | pickup => 0, |
2032 | pickup => 0, |
1963 | inv_sort => "mtime", |
2033 | inv_sort => "mtime", |
1964 | default => "profile", # default profile |
2034 | default => "profile", # default profile |
|
|
2035 | show_tips => 1, |
1965 | ); |
2036 | ); |
1966 | |
2037 | |
1967 | while (my ($k, $v) = each %DEF_CFG) { |
2038 | while (my ($k, $v) = each %DEF_CFG) { |
1968 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2039 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
1969 | } |
2040 | } |
… | |
… | |
2017 | |
2088 | |
2018 | video_init; |
2089 | video_init; |
2019 | audio_init; |
2090 | audio_init; |
2020 | } |
2091 | } |
2021 | |
2092 | |
|
|
2093 | show_tip_of_the_day if $CFG->{show_tips}; |
|
|
2094 | |
2022 | Event::loop; |
2095 | Event::loop; |
2023 | #CFPlus::SDL_Quit; |
2096 | #CFPlus::SDL_Quit; |
2024 | #CFPlus::_exit 0; |
2097 | #CFPlus::_exit 0; |
2025 | |
2098 | |
2026 | END { CFPlus::SDL_Quit } |
2099 | END { CFPlus::SDL_Quit } |