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.109 by root, Sun Aug 13 14:30:07 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
155 146
156# server query dialog 147# server query dialog
157sub server_query { 148sub server_query {
158 my ($conn, $flags, $prompt) = @_; 149 my ($conn, $flags, $prompt) = @_;
159 150
160 $conn->{query_dialog} = my $dialog = new CFPlus::UI::FancyFrame 151 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel
161 x => "center", 152 x => "center",
162 y => "center", 153 y => "center",
163 title => "Server Query", 154 title => "Server Query",
164 child => my $vbox = new CFPlus::UI::VBox, 155 child => my $vbox = new CFPlus::UI::VBox,
165 ; 156 ;
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,
663 expand => 1, 658 expand => 1,
664 scroll_y => 1 659 scroll_y => 1
665 ); 660 );
666 $r->add (my $vb = new CFPlus::UI::VBox); 661 $r->add (my $vb = new CFPlus::UI::VBox);
667 662
663 $vb->add (new CFPlus::UI::FancyFrame
664 label => "Player",
665 child => (my $pi = new CFPlus::UI::VBox),
666 );
667
668 $vb->add ($STATWIDS->{title} = new CFPlus::UI::Label valign => 0, align => -1, text => "Title:", expand => 1, 668 $pi->add ($STATWIDS->{title} = new CFPlus::UI::Label valign => 0, align => -1, text => "Title:", expand => 1,
669 can_hover => 1, can_events => 1, 669 can_hover => 1, can_events => 1,
670 tooltip => "Your name and title. You can change your title by using the <b>title</b> command, if supported by the server."); 670 tooltip => "Your name and title. You can change your title by using the <b>title</b> command, if supported by the server.");
671 $vb->add ($STATWIDS->{map} = new CFPlus::UI::Label valign => 0, align => -1, text => "Map:", expand => 1, 671 $pi->add ($STATWIDS->{map} = new CFPlus::UI::Label valign => 0, align => -1, text => "Map:", expand => 1,
672 can_hover => 1, can_events => 1, 672 can_hover => 1, can_events => 1,
673 tooltip => "The map you are currently on (if supported by the server)."); 673 tooltip => "The map you are currently on (if supported by the server).");
674 674
675 $vb->add (my $hb0 = new CFPlus::UI::HBox); 675 $pi->add (my $hb0 = new CFPlus::UI::HBox);
676 $hb0->add ($STATWIDS->{weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1, 676 $hb0->add ($STATWIDS->{weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1,
677 can_hover => 1, can_events => 1, 677 can_hover => 1, can_events => 1,
678 tooltip => "The weight of the player including all inventory items."); 678 tooltip => "The weight of the player including all inventory items.");
679 $hb0->add ($STATWIDS->{m_weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1, 679 $hb0->add ($STATWIDS->{m_weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1,
680 can_hover => 1, can_events => 1, 680 can_hover => 1, can_events => 1,
681 tooltip => "The weight limit: you cannot carry more than this."); 681 tooltip => "The weight limit: you cannot carry more than this.");
682 682
683 $vb->add (new CFPlus::UI::FancyFrame
684 label => "Primary/Secondary Statistics",
683 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1); 685 child => (my $hb = new CFPlus::UI::HBox expand => 1),
686 );
684 $hb->add (my $tbl = new CFPlus::UI::Table expand => 1); 687 $hb->add (my $tbl = new CFPlus::UI::Table expand => 1);
685 688
686 my $color2 = [1, 1, 0]; 689 my $color2 = [1, 1, 0];
687 690
688 for ( 691 for (
709 $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFPlus::UI::Label 712 $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFPlus::UI::Label
710 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2, valign => 0, 713 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2, valign => 0,
711 align => -1, text => $label, tooltip => "#stat_$label"); 714 align => -1, text => $label, tooltip => "#stat_$label");
712 } 715 }
713 716
717 $vb->add (new CFPlus::UI::FancyFrame
718 label => "Resistancies",
714 $vb->add (my $tbl2 = new CFPlus::UI::Table expand => 1); 719 child => (my $tbl2 = new CFPlus::UI::Table expand => 1),
720 );
715 721
716 my $row = 0; 722 my $row = 0;
717 my $col = 0; 723 my $col = 0;
718 724
719 my %resist_names = ( 725 my %resist_names = (
913sub metaserver_dialog { 919sub metaserver_dialog {
914 my $vbox = new CFPlus::UI::VBox; 920 my $vbox = new CFPlus::UI::VBox;
915 my $table = new CFPlus::UI::Table; 921 my $table = new CFPlus::UI::Table;
916 $vbox->add (new CFPlus::UI::ScrolledWindow expand => 1, child => $table); 922 $vbox->add (new CFPlus::UI::ScrolledWindow expand => 1, child => $table);
917 923
918 my $dialog = new CFPlus::UI::FancyFrame 924 my $dialog = new CFPlus::UI::Toplevel
919 title => "Server List", 925 title => "Server List",
920 name => 'metaserver_dialog', 926 name => 'metaserver_dialog',
921 x => 'center', 927 x => 'center',
922 y => 'center', 928 y => 'center',
923 z => 3, 929 z => 3,
935} 941}
936 942
937sub server_setup { 943sub server_setup {
938 my $vbox = new CFPlus::UI::VBox; 944 my $vbox = new CFPlus::UI::VBox;
939 945
946 $vbox->add (new CFPlus::UI::FancyFrame
947 label => "Connection Settings",
940 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); 948 child => (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]),
949 );
941 $table->add (0, 2, new CFPlus::UI::Label valign => 0, align => 1, text => "Host:Port"); 950 $table->add (0, 2, new CFPlus::UI::Label valign => 0, align => 1, text => "Host:Port");
942 951
943 { 952 {
944 $table->add (1, 2, my $vbox = new CFPlus::UI::VBox); 953 $table->add (1, 2, my $vbox = new CFPlus::UI::VBox);
945 954
1029 }, 1038 },
1030 ); 1039 );
1031 1040
1032 $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");
1033 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry 1042 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry
1034 text => $CFG->{say_command}, 1043 text => $CFG->{say_command},
1035 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. "
1036 . "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. "
1037 . "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.",
1038 on_changed => sub { 1047 on_changed => sub {
1039 my ($self, $value) = @_; 1048 my ($self, $value) = @_;
1040 $CFG->{say_command} = $value; 1049 $CFG->{say_command} = $value;
1041 0 1050 0
1042 } 1051 }
1043 ); 1052 );
1044 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;
1061 0
1062 }
1063 );
1064
1045 $vbox->add (new CFPlus::UI::Label 1065 $vbox->add (new CFPlus::UI::FancyFrame
1046 text => "Server Info", 1066 label => "Server Info",
1047 fontsize => 1.2,
1048 padding_y => 8,
1049 fg => [1, 1, 0, 1],
1050 );
1051
1052 $vbox->add ($SERVER_INFO = new CFPlus::UI::Label ellipsise => 0); 1067 child => ($SERVER_INFO = new CFPlus::UI::Label ellipsise => 0),
1068 );
1053 1069
1054 $vbox 1070 $vbox
1055} 1071}
1056 1072
1057sub message_window { 1073sub message_window {
1058 my $window = new CFPlus::UI::FancyFrame 1074 my $window = new CFPlus::UI::Toplevel
1059 name => "message_window", 1075 name => "message_window",
1060 title => "Messages", 1076 title => "Messages",
1061 border_bg => [1, 1, 1, 1], 1077 border_bg => [1, 1, 1, 1],
1062 x => "max", 1078 x => "max",
1063 y => 0, 1079 y => 0,
1113 window => $window, 1129 window => $window,
1114 input => $input, 1130 input => $input,
1115 }; 1131 };
1116 1132
1117 $window 1133 $window
1118}
1119
1120sub open_string_query {
1121 my $cb = $_[1];
1122 my $dialog = new CFPlus::UI::FancyFrame
1123 x => "center",
1124 y => "center",
1125 z => 50,
1126 force_w => $WIDTH * 4/5,
1127 title => $_[0];
1128
1129 $dialog->add (
1130 my $e = new CFPlus::UI::Entry
1131 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
1132 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
1133 );
1134
1135 $e->grab_focus;
1136 $dialog->show;
1137}
1138
1139sub open_quit_dialog {
1140 unless ($QUIT_DIALOG) {
1141 $QUIT_DIALOG = new CFPlus::UI::FancyFrame
1142 x => "center",
1143 y => "center",
1144 z => 50,
1145 title => "Really Quit?",
1146 on_key_down => sub {
1147 my ($dialog, $ev) = @_;
1148 $ev->{sym} == 27 and $dialog->hide;
1149 }
1150 ;
1151
1152 $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1);
1153
1154 $vb->add (new CFPlus::UI::Label
1155 text => "You should find a savebed and apply it first!",
1156 max_w => $WIDTH * 0.25,
1157 ellipsize => 0,
1158 );
1159 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1160 $hb->add (new CFPlus::UI::Button
1161 text => "Ok",
1162 expand => 1,
1163 on_activate => sub { $QUIT_DIALOG->hide; 0 },
1164 );
1165 $hb->add (new CFPlus::UI::Button
1166 text => "Quit anyway",
1167 expand => 1,
1168 on_activate => sub { exit },
1169 );
1170 }
1171
1172 $QUIT_DIALOG->show;
1173 $QUIT_DIALOG->grab_focus;
1174} 1134}
1175 1135
1176sub autopickup_setup { 1136sub autopickup_setup {
1177 my $table = new CFPlus::UI::Table; 1137 my $table = new CFPlus::UI::Table;
1178 1138
1335 $PL_WINDOW->show; 1295 $PL_WINDOW->show;
1336 } 1296 }
1337} 1297}
1338 1298
1339sub player_window { 1299sub player_window {
1340 my $plwin = $PL_WINDOW = new CFPlus::UI::FancyFrame 1300 my $plwin = $PL_WINDOW = new CFPlus::UI::Toplevel
1341 x => "center", 1301 x => "center",
1342 y => "center", 1302 y => "center",
1343 force_w => $WIDTH * 9/10, 1303 force_w => $WIDTH * 9/10,
1344 force_h => $HEIGHT * 9/10, 1304 force_h => $HEIGHT * 9/10,
1345 title => "Player", 1305 title => "Player",
1387 1347
1388 my $refresh; 1348 my $refresh;
1389 $refresh = $BIND_UPD_CB = sub { 1349 $refresh = $BIND_UPD_CB = sub {
1390 $binding_list->clear (); 1350 $binding_list->clear ();
1391 1351
1352 return unless $PROFILE;
1353
1392 for my $mod (keys %{$::CFG->{profile}{default}{bindings}}) { 1354 for my $mod (keys %{$PROFILE->{bindings}}) {
1393 for my $sym (keys %{$::CFG->{profile}{default}{bindings}{$mod}}) { 1355 for my $sym (keys %{$PROFILE->{bindings}{$mod}}) {
1394 my $cmds = $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1356 my $cmds = $PROFILE->{bindings}{$mod}{$sym};
1395 next unless ref $cmds eq 'ARRAY' and @$cmds > 0; 1357 next unless ref $cmds eq 'ARRAY' and @$cmds > 0;
1396 1358
1397 my $lbl = join "; ", @$cmds; 1359 my $lbl = join "; ", @$cmds;
1398 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym); 1360 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym);
1399 $binding_list->add (my $hb = new CFPlus::UI::HBox); 1361 $binding_list->add (my $hb = new CFPlus::UI::HBox);
1400 $hb->add (new CFPlus::UI::Button 1362 $hb->add (new CFPlus::UI::Button
1401 text => "delete", 1363 text => "delete",
1402 tooltip => "Deletes the binding", 1364 tooltip => "Deletes the binding",
1403 on_activate => sub { 1365 on_activate => sub {
1404 $binding_list->remove ($hb); 1366 $binding_list->remove ($hb);
1405 delete $::CFG->{profile}{default}{bindings}{$mod}{$sym}; 1367 delete $PROFILE->{bindings}{$mod}{$sym};
1406 0 1368 0
1407 }); 1369 });
1408 1370
1409 $hb->add (new CFPlus::UI::Button 1371 $hb->add (new CFPlus::UI::Button
1410 text => "edit", 1372 text => "edit",
1411 tooltip => "Edits the binding", 1373 tooltip => "Edits the binding",
1412 on_activate => sub { 1374 on_activate => sub {
1413 $::BIND_EDITOR->set_binding ( 1375 $::BIND_EDITOR->set_binding (
1414 $mod, $sym, $::CFG->{profile}{default}{bindings}{$mod}{$sym}, 1376 $mod, $sym, $PROFILE->{bindings}{$mod}{$sym},
1415 sub { 1377 sub {
1416 my ($nmod, $nsym, $ncmds) = @_; 1378 my ($nmod, $nsym, $ncmds) = @_;
1417 $::BIND_EDITOR->cfg_unbind ($mod, $sym); 1379 $::BIND_EDITOR->cfg_unbind ($mod, $sym);
1418 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds); 1380 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds);
1419 $refresh->(); 1381 $refresh->();
1434 } 1396 }
1435 } 1397 }
1436 }; 1398 };
1437 1399
1438 my $vb = new CFPlus::UI::VBox; 1400 my $vb = new CFPlus::UI::VBox;
1401 $vb->add (new CFPlus::UI::FancyFrame
1402 label => "Options",
1439 $vb->add (my $hb = new CFPlus::UI::HBox); 1403 child => (my $hb = new CFPlus::UI::HBox),
1404 );
1440 $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire"); 1405 $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire");
1441 $hb->add (new CFPlus::UI::CheckBox 1406 $hb->add (new CFPlus::UI::CheckBox
1442 expand => 1, 1407 expand => 1,
1443 state => $CFG->{shift_fire_stop}, 1408 state => $CFG->{shift_fire_stop},
1444 tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift", 1409 tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift",
1446 my ($cbox, $value) = @_; 1411 my ($cbox, $value) = @_;
1447 $CFG->{shift_fire_stop} = $value; 1412 $CFG->{shift_fire_stop} = $value;
1448 0 1413 0
1449 }); 1414 });
1450 1415
1451 $vb->add ($binding_list); 1416 $vb->add (new CFPlus::UI::FancyFrame
1417 label => "Bindings",
1418 child => $binding_list);
1452 $vb->add (my $hb = new CFPlus::UI::HBox); 1419 $vb->add (my $hb = new CFPlus::UI::HBox);
1453 1420
1454 $hb->add (new CFPlus::UI::Button 1421 $hb->add (new CFPlus::UI::Button
1455 text => "record new", 1422 text => "record new",
1456 expand => 1, 1423 expand => 1,
1489 1456
1490 $vb 1457 $vb
1491} 1458}
1492 1459
1493sub help_window { 1460sub help_window {
1494 my $win = new CFPlus::UI::FancyFrame 1461 my $win = new CFPlus::UI::Toplevel
1495 x => 'center', 1462 x => 'center',
1496 y => 'center', 1463 y => 'center',
1497 z => 2, 1464 z => 4,
1498 name => 'doc_browser', 1465 name => 'doc_browser',
1499 force_w => int $WIDTH * 7/8, 1466 force_w => int $WIDTH * 7/8,
1500 force_h => int $HEIGHT * 7/8, 1467 force_h => int $HEIGHT * 7/8,
1501 title => "Help Browser", 1468 title => "Help Browser",
1502 has_close_button => 1; 1469 has_close_button => 1;
1503 1470
1504 $win->add (my $vbox = new CFPlus::UI::VBox); 1471 $win->add (my $vbox = new CFPlus::UI::VBox);
1505 1472
1473 $vbox->add (new CFPlus::UI::FancyFrame
1474 label => "Navigation",
1506 $vbox->add (my $buttons = new CFPlus::UI::HBox); 1475 child => (my $buttons = new CFPlus::UI::HBox),
1476 );
1507 $vbox->add (my $viewer = new CFPlus::UI::TextScroller 1477 $vbox->add (my $viewer = new CFPlus::UI::TextScroller
1508 expand => 1, fontsize => 0.8, padding_x => 4); 1478 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1509 1479
1510 $buttons->add (new CFPlus::UI::Label text => "Choose a document to display: "); 1480 my @history;
1511 $buttons->add (my $combo = new CFPlus::UI::Selector 1481 my @future;
1512 value => undef, 1482 my $curnode;
1513 options => [ 1483
1514 [intro => "Introduction"], 1484 my $load_node; $load_node = sub {
1515 [manual => "Main Manual"], 1485 my ($node, $para) = @_;
1516 [skill_help => "Skill Reference"], 1486
1517 [command_help => "Command Reference"], 1487 $buttons->clear;
1518 [dmcommand_help => "DM Commands"], 1488
1519 [COPYING => "License Terms"], 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 );
1499
1500 if (@history) {
1501 $buttons->add (new CFPlus::UI::Button
1502 text => "⋘",
1503 tooltip => "back to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $history[-1][0]) . "</i>",
1504 on_activate => sub {
1505 unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
1506 $load_node->(@{pop @history});
1507 },
1508 );
1520 ], 1509 }
1521 on_changed => sub {
1522 my ($self, $pod) = @_;
1523 1510
1511 if (@future) {
1512 $buttons->add (new CFPlus::UI::Button
1513 text => "⋙",
1514 tooltip => "forward to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $future[0][0]) . "</i>",
1515 on_activate => sub {
1516 push @history, [$curnode, $viewer->current_paragraph];
1517 $load_node->(@{shift @future});
1518 },
1519 );
1520 }
1521
1522 $buttons->add (new CFPlus::UI::Label text => " ");
1523
1524 my @path = CFPlus::Pod::full_path_of $node;
1525 pop @path; # drop current node
1526
1527 for my $node (@path) {
1528 $buttons->add (new CFPlus::UI::Button
1529 text => $node->{kw}[0],
1530 tooltip => "go to <i>" . (CFPlus::asxml CFPlus::Pod::full_path $node) . "</i>",
1531 on_activate => sub {
1532 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
1533 $load_node->($node);
1534 },
1535 );
1536 $buttons->add (new CFPlus::UI::Label text => "/");
1537 }
1538
1539 $buttons->add (new CFPlus::UI::Label text => $node->{kw}[0], padding_x => 4, padding_y => 4);
1540
1541 $curnode = $node;
1542
1524 $viewer->clear; 1543 $viewer->clear;
1525 $viewer->add_paragraph (CFPlus::Pod::section pod => $pod); 1544 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode);
1526 $viewer->set_offset (0); 1545 $viewer->scroll_to ($para);
1546 };
1527 1547
1548 $load_node->(CFPlus::Pod::find pod => "mainpage");
1549
1550 $CFPlus::Pod::goto_document = sub {
1551 my (@path) = @_;
1552
1553 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
1554
1555 $load_node->((CFPlus::Pod::find @path)[0]);
1556 $win->show;
1557 };
1558
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;
1528 0 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;
1529 }, 1666 },
1530 on_visibility_change => sub {
1531 my ($self, $visible) = @_;
1532 return unless $visible;
1533 return if $self->{value};
1534 $self->set_value ("intro");
1535 0
1536 },
1537 ); 1667 );
1538 1668
1539 $win 1669 $dialog->show;
1540} 1670}
1541 1671
1542sub sdl_init { 1672sub sdl_init {
1543 CFPlus::SDL_Init 1673 CFPlus::SDL_Init
1544 and die "SDL::Init failed!\n"; 1674 and die "SDL::Init failed!\n";
1591 force_x => 0, 1721 force_x => 0,
1592 force_y => "max", 1722 force_y => "max",
1593 child => $STATUSBOX, 1723 child => $STATUSBOX,
1594 )->show; 1724 )->show;
1595 1725
1596 CFPlus::UI::FancyFrame->new ( 1726 CFPlus::UI::Toplevel->new (
1597 title => "Map", 1727 title => "Map",
1598 name => "mapmap", 1728 name => "mapmap",
1599 x => 0, 1729 x => 0,
1600 y => $FONTSIZE + 8, 1730 y => $FONTSIZE + 8,
1601 border_bg => [1, 1, 1, 192/255], 1731 border_bg => [1, 1, 1, 192/255],
1629 can_hover => 1, 1759 can_hover => 1,
1630 can_events => 1, 1760 can_events => 1,
1631 tooltip => "<b>Server Log</b>. This text viewer contains all the messages sent by the server.", 1761 tooltip => "<b>Server Log</b>. This text viewer contains all the messages sent by the server.",
1632 ; 1762 ;
1633 1763
1634 $SETUP_DIALOG = new CFPlus::UI::FancyFrame 1764 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1635 title => "Setup", 1765 title => "Setup",
1636 name => "setup_dialog", 1766 name => "setup_dialog",
1637 x => 'center', 1767 x => 'center',
1638 y => 'center', 1768 y => 'center',
1639 z => 2, 1769 z => 2,
1903 output_sync => 1, 2033 output_sync => 1,
1904 output_count => 1, 2034 output_count => 1,
1905 pickup => 0, 2035 pickup => 0,
1906 inv_sort => "mtime", 2036 inv_sort => "mtime",
1907 default => "profile", # default profile 2037 default => "profile", # default profile
2038 show_tips => 1,
1908 ); 2039 );
1909 2040
1910 while (my ($k, $v) = each %DEF_CFG) { 2041 while (my ($k, $v) = each %DEF_CFG) {
1911 $CFG->{$k} = $v unless exists $CFG->{$k}; 2042 $CFG->{$k} = $v unless exists $CFG->{$k};
1912 } 2043 }
1960 2091
1961 video_init; 2092 video_init;
1962 audio_init; 2093 audio_init;
1963} 2094}
1964 2095
2096show_tip_of_the_day if $CFG->{show_tips};
2097
1965Event::loop; 2098Event::loop;
1966#CFPlus::SDL_Quit; 2099#CFPlus::SDL_Quit;
1967#CFPlus::_exit 0; 2100#CFPlus::_exit 0;
1968 2101
1969END { CFPlus::SDL_Quit } 2102END { CFPlus::SDL_Quit }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines