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.135 by elmex, Tue Dec 5 16:53:29 2006 UTC vs.
Revision 1.151 by root, Mon Apr 16 21:12:51 2007 UTC

58use Compress::LZF; 58use Compress::LZF;
59 59
60use CFPlus; 60use CFPlus;
61use CFPlus::OpenGL (); 61use CFPlus::OpenGL ();
62use CFPlus::Protocol; 62use CFPlus::Protocol;
63use CFPlus::DB;
63use CFPlus::UI; 64use CFPlus::UI;
65use CFPlus::UI::Inventory;
66use CFPlus::UI::SpellList;
64use CFPlus::Pod; 67use CFPlus::Pod;
65use CFPlus::BindingEditor;
66use CFPlus::MapWidget; 68use CFPlus::MapWidget;
69use CFPlus::Macro;
67 70
68$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 71$SIG{QUIT} = sub { Carp::cluck "QUIT" };
69$SIG{PIPE} = 'IGNORE'; 72$SIG{PIPE} = 'IGNORE';
70 73
71$Event::Eval = 0; 74$Event::Eval = 1;
72$Event::DIED = sub { 75$Event::DIED = sub {
73 CFPlus::fatal Carp::longmess $_[1] 76 CFPlus::fatal Carp::longmess $_[1]
74}; 77};
75 78
76my $MAX_FPS = 60; 79my $MAX_FPS = 60;
145 148
146our $INV; 149our $INV;
147our $INVR; 150our $INVR;
148our $INV_RIGHT_HB; 151our $INV_RIGHT_HB;
149 152
150our $BIND_EDITOR;
151our $BIND_UPD_CB;
152
153our $PICKUP_CFG; 153our $PICKUP_CFG;
154 154
155our $IN_BUILD_MODE; 155our $IN_BUILD_MODE;
156our $BUILD_BUTTON; 156our $BUILD_BUTTON;
157 157
177sub destroy_query_dialog { 177sub destroy_query_dialog {
178 (delete $_[0]{query_dialog})->destroy 178 (delete $_[0]{query_dialog})->destroy
179 if $_[0]{query_dialog}; 179 if $_[0]{query_dialog};
180} 180}
181 181
182# FIXME: a very ugly hack to wait for stat update look below! #d#
183our $QUERY_TIMER; #d#
184
182# server query dialog 185# server query dialog
183sub server_query { 186sub server_query {
184 my ($conn, $flags, $prompt) = @_; 187 my ($conn, $flags, $prompt) = @_;
188
189 # FIXME: a very ugly hack to wait for stat update #d#
190 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) {
191 unless ($QUERY_TIMER) {
192 $QUERY_TIMER =
193 Event->timer (
194 after => 1,
195 cb => sub {
196 server_query ($conn, $flags, $prompt, 1);
197 $QUERY_TIMER = undef
198 }
199 );
200 return;
201 }
202 }
185 203
186 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel 204 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel
187 x => "center", 205 x => "center",
188 y => "center", 206 y => "center",
189 title => "Server Query", 207 title => "Server Query",
378 status "logging in..."; 396 status "logging in...";
379 397
380 $LOGIN_BUTTON->set_text ("Logout"); 398 $LOGIN_BUTTON->set_text ("Logout");
381 $SETUP_DIALOG->hide; 399 $SETUP_DIALOG->hide;
382 400
383 $PROFILE = $CFG->{profile}{default};
384
385 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 401 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
386 402
387 my ($host, $port) = split /:/, $PROFILE->{host}; 403 my ($host, $port) = split /:/, $PROFILE->{host};
388 404
389 $MAP = new CFPlus::Map; 405 $MAP = new CFPlus::Map;
404 statusbox => $STATUSBOX, 420 statusbox => $STATUSBOX,
405 map => $MAP, 421 map => $MAP,
406 mapmap => $MAPMAP, 422 mapmap => $MAPMAP,
407 query => \&server_query, 423 query => \&server_query,
408 424
425 setup_req => {
426 smoothing => $CFG->{map_smoothing}*1,
427 },
428
409 sound_play => sub { 429 sound_play => sub {
410 my ($x, $y, $soundnum, $type) = @_; 430 my ($x, $y, $soundnum, $type) = @_;
411 431
412 $SDL_MIXER 432 $SDL_MIXER
413 or return; 433 or return;
450sub graphics_setup { 470sub graphics_setup {
451 my $vbox = new CFPlus::UI::VBox; 471 my $vbox = new CFPlus::UI::VBox;
452 472
453 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); 473 $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]);
454 474
475 my $row = 0;
476
477 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "OpenGL Info");
478 $table->add (1, $row++, new CFPlus::UI::Label valign => 0, fontsize => 0.8, text => CFPlus::OpenGL::gl_vendor . ", " . CFPlus::OpenGL::gl_version,
479 can_events => 1,
480 tooltip => "<tt><span size='8192'>" . (CFPlus::OpenGL::gl_extensions) . "</span></tt>");
481
455 $table->add (0, 0, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode"); 482 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode");
456 $table->add (1, 0, my $hbox = new CFPlus::UI::HBox); 483 $table->add (1, $row++, my $hbox = new CFPlus::UI::HBox);
457 484
458 $hbox->add (my $mode_slider = new CFPlus::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]); 485 $hbox->add (my $mode_slider = new CFPlus::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]);
459 $hbox->add (my $mode_label = new CFPlus::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); 486 $hbox->add (my $mode_label = new CFPlus::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
460 487
461 $mode_slider->connect (changed => sub { 488 $mode_slider->connect (changed => sub {
463 490
464 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 491 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
465 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 492 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
466 }); 493 });
467 $mode_slider->emit (changed => $mode_slider->{range}[0]); 494 $mode_slider->emit (changed => $mode_slider->{range}[0]);
468
469 my $row = 1;
470 495
471 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fullscreen"); 496 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fullscreen");
472 $table->add (1, $row++, $FULLSCREEN_ENABLE = new CFPlus::UI::CheckBox 497 $table->add (1, $row++, $FULLSCREEN_ENABLE = new CFPlus::UI::CheckBox
473 state => $CFG->{fullscreen}, 498 state => $CFG->{fullscreen},
474 tooltip => "Bring the client into fullscreen mode.", 499 tooltip => "Bring the client into fullscreen mode.",
480 state => $CFG->{fast}, 505 state => $CFG->{fast},
481 tooltip => "Lower the visual quality considerably to speed up rendering.", 506 tooltip => "Lower the visual quality considerably to speed up rendering.",
482 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } 507 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
483 ); 508 );
484 509
510 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
511 $table->add (1, $row++, new CFPlus::UI::Slider
512 range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1],
513 tooltip => "The base font size used by most GUI elements that do not have their own setting.",
514 on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 },
515 );
516
517 $table->add (1, $row++, new CFPlus::UI::Button
518 expand => 1, align => 0, text => "Apply",
519 tooltip => "Apply the video settings above.",
520 on_activate => sub {
521 video_shutdown ();
522 video_init ();
523 0
524 }
525 );
526
485 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Scale"); 527 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Scale");
486 $table->add (1, $row++, new CFPlus::UI::Slider 528 $table->add (1, $row++, new CFPlus::UI::Slider
487 range => [(log $CFG->{map_scale}) / (log 2), -3, 1, 0, 1], 529 range => [(log $CFG->{map_scale}) / (log 2), -3, 1, 0, 1],
488 tooltip => "Enlarge or shrink the displayed map. Changes are instant.", 530 tooltip => "Enlarge or shrink the displayed map. Changes are instant.",
489 on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 } 531 on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 }
532 );
533
534 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Smoothing");
535 $table->add (1, $row++, new CFPlus::UI::CheckBox
536 state => $CFG->{map_smoothing},
537 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
538 . "This increases load on the graphics subsystem and works only with 2.x servers. "
539 . "Changes take effect at next connection only.",
540 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
490 ); 541 );
491 542
492 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); 543 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War");
493 $table->add (1, $row++, new CFPlus::UI::CheckBox 544 $table->add (1, $row++, new CFPlus::UI::CheckBox
494 state => $CFG->{fow_enable}, 545 state => $CFG->{fow_enable},
513 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFPlus::OpenGL::GL_VERSION < 1.2; 564 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFPlus::OpenGL::GL_VERSION < 1.2;
514 0 565 0
515 } 566 }
516 ); 567 );
517 568
518 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
519 $table->add (1, $row++, new CFPlus::UI::Slider
520 range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1],
521 tooltip => "The base font size used by most GUI elements that do not have their own setting.",
522 on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 },
523 );
524
525 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 569 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
526 $table->add (1, $row++, new CFPlus::UI::Slider 570 $table->add (1, $row++, new CFPlus::UI::Slider
527 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 571 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
528 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 572 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.",
529 on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 573 on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
545 range => [$CFG->{gauge_size}, 0.2, 0.8], 589 range => [$CFG->{gauge_size}, 0.2, 0.8],
546 tooltip => "Adjust the size of the stats gauges at the bottom right. Changes are instant.", 590 tooltip => "Adjust the size of the stats gauges at the bottom right. Changes are instant.",
547 on_changed => sub { 591 on_changed => sub {
548 $CFG->{gauge_size} = $_[1]; 592 $CFG->{gauge_size} = $_[1];
549 $GAUGES->{win}->set_size ($WIDTH, int $HEIGHT * $CFG->{gauge_size}); 593 $GAUGES->{win}->set_size ($WIDTH, int $HEIGHT * $CFG->{gauge_size});
550 0
551 }
552 );
553
554 $table->add (1, $row++, new CFPlus::UI::Button
555 expand => 1, align => 0, text => "Apply",
556 tooltip => "Apply the video settings",
557 on_activate => sub {
558 video_shutdown ();
559 video_init ();
560 0 594 0
561 } 595 }
562 ); 596 );
563 597
564 $vbox 598 $vbox
683 on_changed => sub { $MAP->{smooth_matrix}[$x * 3 + $y] = $_[1] if $MAP; 0 }, 717 on_changed => sub { $MAP->{smooth_matrix}[$x * 3 + $y] = $_[1] if $MAP; 0 },
684 ); 718 );
685 } 719 }
686 } 720 }
687 721
722 $table->add (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
688 723
689 $table 724 $table
690} 725}
691 726
692sub stats_window { 727sub stats_window {
889 for 0 .. $#col; 924 for 0 .. $#col;
890 925
891 my @align = qw(1 0 1 1 -1); 926 my @align = qw(1 0 1 1 -1);
892 927
893 my $y = 0; 928 my $y = 0;
894 for my $m (
895 sort {
896 $b->{version} <=> $a->{version}
897 or $b->{users} <=> $a->{users}
898 }
899 @{ $msg->{servers} } 929 for my $m (@{ $msg->{servers} }) {
900 ) {
901 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = 930 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime, $highlight) =
902 @$m{qw(ip age hostname users version description ibytes obytes uptime)}; 931 @$m{qw(ip age hostname users version description ibytes obytes uptime highlight)};
903 932
904 for ($desc) { 933 for ($desc) {
905 s/<br>/\n/gi; 934 s/<br>/\n/gi;
906 s/<li>/\n· /gi; 935 s/<li>/\n· /gi;
907 s/<.*?>//sgi; 936 s/<.*?>//sgi;
937 max_w => $::WIDTH * 0.4, 966 max_w => $::WIDTH * 0.4,
938 ellipsise => 0, 967 ellipsise => 0,
939 align => $align[$_], 968 align => $align[$_],
940 text => $m->[$_], 969 text => $m->[$_],
941 tooltip => $tip[$_], 970 tooltip => $tip[$_],
942 fg => ($m->[3] =~ /\+$/ ? [1, 1, 1] : [.7, .7, .7]), 971 fg => ($highlight ? [1, 1, 1] : [.7, .7, .7]),
943 can_hover => 1, 972 can_hover => 1,
944 can_events => 1, 973 can_events => 1,
945 fontsize => 0.8) 974 fontsize => 0.8)
946 for 0 .. $#$m; 975 for 0 .. $#$m;
947 } 976 }
1048 . "so only set it if you really need to prefetch images. " 1077 . "so only set it if you really need to prefetch images. "
1049 . "This option can be set and unset any time.", 1078 . "This option can be set and unset any time.",
1050 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 }, 1079 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
1051 ); 1080 );
1052 1081
1053 $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1082 $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1054 $table->add (1, 9, new CFPlus::UI::Entry 1083 $table->add (1, 9, new CFPlus::UI::Entry
1084 text => $CFG->{output_rate},
1085 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
1086 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1087 . "default will be used, which is usually around 100kb/s.",
1088 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1089 );
1090
1091 $table->add (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1092 $table->add (1, 10, new CFPlus::UI::Entry
1055 text => $CFG->{output_count}, 1093 text => $CFG->{output_count},
1056 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1094 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1057 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1095 on_changed => sub { $CFG->{output_count} = $_[1]; 0 },
1058 ); 1096 );
1059 1097
1060 $table->add (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1098 $table->add (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1061 $table->add (1, 10, new CFPlus::UI::Entry 1099 $table->add (1, 11, new CFPlus::UI::Entry
1062 text => $CFG->{output_sync}, 1100 text => $CFG->{output_sync},
1063 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1101 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1064 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1102 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 },
1065 ); 1103 );
1066 1104
1067 $table->add (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button 1105 $table->add (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button
1068 expand => 1, 1106 expand => 1,
1069 align => 0, 1107 align => 0,
1070 text => "Login", 1108 text => "Login",
1071 on_activate => sub { 1109 on_activate => sub {
1072 $CONN ? stop_game 1110 $CONN ? stop_game
1073 : start_game; 1111 : start_game;
1074 0 1112 0
1075 }, 1113 },
1076 ); 1114 );
1077 1115
1116 $vbox->add (new CFPlus::UI::FancyFrame
1117 label => "Server Info",
1118 child => ($SERVER_INFO = new CFPlus::UI::Label ellipsise => 0),
1119 );
1120
1121 $vbox
1122}
1123
1124sub client_setup {
1125 my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1];
1126
1127 my $row = 0;
1128
1078 $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); 1129 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command");
1079 $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry 1130 $table->add (1, $row++, my $saycmd = new CFPlus::UI::Entry
1080 text => $CFG->{say_command}, 1131 text => $CFG->{say_command},
1081 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. " 1132 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. "
1082 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " 1133 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
1083 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.", 1134 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.",
1084 on_changed => sub { 1135 on_changed => sub {
1085 my ($self, $value) = @_; 1136 my ($self, $value) = @_;
1086 $CFG->{say_command} = $value; 1137 $CFG->{say_command} = $value;
1087 0 1138 0
1088 } 1139 }
1089 ); 1140 );
1090 1141
1091 $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); 1142 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day");
1092 $table->add (1, 13, my $saycmd = new CFPlus::UI::CheckBox 1143 $table->add (1, $row++, new CFPlus::UI::CheckBox
1093 state => $CFG->{show_tips}, 1144 state => $CFG->{show_tips},
1094 tooltip => "Show the <b>Tip of the day</b> window at startup?", 1145 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1095 on_changed => sub { 1146 on_changed => sub {
1096 my ($self, $value) = @_; 1147 my ($self, $value) = @_;
1097 $CFG->{show_tips} = $value; 1148 $CFG->{show_tips} = $value;
1098 0 1149 0
1099 } 1150 }
1100 ); 1151 );
1101 1152
1102 $vbox->add (new CFPlus::UI::FancyFrame 1153 $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Messages Window Size");
1103 label => "Server Info", 1154 $table->add (1, $row++, my $saycmd = new CFPlus::UI::Entry
1104 child => ($SERVER_INFO = new CFPlus::UI::Label ellipsise => 0), 1155 text => $CFG->{logview_max_par},
1156 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server "
1157 . "sends more messages than this number, older messages get removed to save memory and "
1158 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1159 on_changed => sub {
1160 my ($self, $value) = @_;
1161 $LOGVIEW->{max_par} = $CFG->{logview_max_par} = $value*1;
1162 0
1163 },
1105 ); 1164 );
1106 1165
1107 $vbox 1166 $table
1108} 1167}
1109 1168
1110sub message_window { 1169sub message_window {
1111 my $window = new CFPlus::UI::Toplevel 1170 my $window = new CFPlus::UI::Toplevel
1112 name => "message_window", 1171 name => "message_window",
1381 1440
1382 $plwin->add ($ntb); 1441 $plwin->add ($ntb);
1383 $plwin 1442 $plwin
1384} 1443}
1385 1444
1386sub update_bindings {
1387 $BIND_UPD_CB->() if $BIND_UPD_CB;
1388}
1389
1390sub keyboard_setup { 1445sub keyboard_setup {
1391 my $binding_list = new CFPlus::UI::VBox; 1446 CFPlus::Macro::keyboard_setup
1392
1393 my $refresh;
1394 $refresh = $BIND_UPD_CB = sub {
1395 $binding_list->clear ();
1396
1397 return unless $PROFILE;
1398
1399 for my $mod (keys %{$PROFILE->{bindings}}) {
1400 for my $sym (keys %{$PROFILE->{bindings}{$mod}}) {
1401 my $cmds = $PROFILE->{bindings}{$mod}{$sym};
1402 next unless ref $cmds eq 'ARRAY' and @$cmds > 0;
1403
1404 my $lbl = join "; ", @$cmds;
1405 my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym);
1406 $binding_list->add (my $hb = new CFPlus::UI::HBox);
1407 $hb->add (new CFPlus::UI::Button
1408 text => "delete",
1409 tooltip => "Deletes the binding",
1410 on_activate => sub {
1411 $binding_list->remove ($hb);
1412 delete $PROFILE->{bindings}{$mod}{$sym};
1413 0
1414 });
1415
1416 $hb->add (new CFPlus::UI::Button
1417 text => "edit",
1418 tooltip => "Edits the binding",
1419 on_activate => sub {
1420 $::BIND_EDITOR->set_binding (
1421 $mod, $sym, $PROFILE->{bindings}{$mod}{$sym},
1422 sub {
1423 my ($nmod, $nsym, $ncmds) = @_;
1424 $::BIND_EDITOR->cfg_unbind ($mod, $sym);
1425 $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds);
1426 $refresh->();
1427 $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD);
1428 $SETUP_DIALOG->show;
1429 },
1430 sub {
1431 $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD);
1432 $SETUP_DIALOG->show;
1433 });
1434 $::BIND_EDITOR->show;
1435 $SETUP_DIALOG->hide;
1436 0
1437 });
1438
1439 $hb->add (new CFPlus::UI::Label text => "(Key: $nam)");
1440 $hb->add (new CFPlus::UI::Label text => $lbl, expand => 1);
1441 }
1442 }
1443 };
1444
1445 my $vb = new CFPlus::UI::VBox;
1446 $vb->add (new CFPlus::UI::FancyFrame
1447 label => "Options",
1448 child => (my $hb = new CFPlus::UI::HBox),
1449 );
1450 $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire");
1451 $hb->add (new CFPlus::UI::CheckBox
1452 expand => 1,
1453 state => $CFG->{shift_fire_stop},
1454 tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift",
1455 on_changed => sub {
1456 my ($cbox, $value) = @_;
1457 $CFG->{shift_fire_stop} = $value;
1458 0
1459 });
1460
1461 $vb->add (new CFPlus::UI::FancyFrame
1462 label => "Bindings",
1463 child => $binding_list);
1464 $vb->add (my $hb = new CFPlus::UI::HBox);
1465
1466 $hb->add (new CFPlus::UI::Button
1467 text => "record new",
1468 expand => 1,
1469 tooltip => "This button opens the binding editor with an empty binding.",
1470 on_activate => sub {
1471 $::BIND_EDITOR->set_binding (undef, undef, [],
1472 sub {
1473 my ($mod, $sym, $cmds) = @_;
1474 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
1475 $refresh->();
1476 $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD);
1477 $SETUP_DIALOG->show;
1478 },
1479 sub {
1480 $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD);
1481 $SETUP_DIALOG->show;
1482 },
1483 );
1484 $SETUP_DIALOG->hide;
1485 $::BIND_EDITOR->show;
1486 0
1487 },
1488 );
1489
1490 $hb->add (new CFPlus::UI::Button
1491 text => "close",
1492 tooltip => "Closes the binding window",
1493 expand => 1,
1494 on_activate => sub {
1495 $SETUP_DIALOG->hide;
1496 0
1497 }
1498 );
1499
1500 $refresh->();
1501
1502 $vb
1503} 1447}
1504 1448
1505sub help_window { 1449sub help_window {
1506 my $win = new CFPlus::UI::Toplevel 1450 my $win = new CFPlus::UI::Toplevel
1507 x => 'center', 1451 x => 'center',
1664 1608
1665sub show_tip_of_the_day { 1609sub show_tip_of_the_day {
1666 # find all tips 1610 # find all tips
1667 my @tod = CFPlus::Pod::find tip_of_the_day => "*"; 1611 my @tod = CFPlus::Pod::find tip_of_the_day => "*";
1668 1612
1669 my $todindex = $CFPlus::DB_STATE->get ("tip_of_the_day"); 1613 CFPlus::DB::get state => "tip_of_the_day", sub {
1614 my ($todindex) = @_;
1670 $todindex = 0 if $todindex >= @tod; 1615 $todindex = 0 if $todindex >= @tod;
1671 $CFPlus::DB_STATE->put (tip_of_the_day => $todindex + 1); 1616 CFPlus::DB::put state => tip_of_the_day => $todindex + 1, sub { };
1672 1617
1673 # create dialog 1618 # create dialog
1674 my $dialog; 1619 my $dialog;
1675 1620
1676 my $close = sub { 1621 my $close = sub {
1677 $dialog->destroy; 1622 $dialog->destroy;
1623 };
1624
1625 $dialog = new CFPlus::UI::Toplevel
1626 x => "center",
1627 y => "center",
1628 z => 3,
1629 name => 'tip_of_the_day',
1630 force_w => int $WIDTH * 4/9,
1631 force_h => int $WIDTH * 2/9,
1632 title => "Tip of the day #" . (1 + $todindex),
1633 child => my $vbox = new CFPlus::UI::VBox,
1634 has_close_button => 1,
1635 on_delete => $close,
1636 ;
1637
1638 $vbox->add (my $viewer = new CFPlus::UI::TextScroller
1639 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1640 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]);
1641
1642 $vbox->add (my $table = new CFPlus::UI::Table col_expand => [0, 1]);
1643
1644 $table->add (0, 0, new CFPlus::UI::Button
1645 text => "Close",
1646 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>.",
1647 on_activate => $close,
1648 );
1649
1650 $table->add (2, 0, new CFPlus::UI::Button
1651 text => "Next",
1652 tooltip => "Show the next <b>Tip of the day</b>.",
1653 on_activate => sub {
1654 $close->();
1655 &show_tip_of_the_day;
1656 },
1657 );
1658
1659 $dialog->show;
1678 }; 1660 };
1679
1680 $dialog = new CFPlus::UI::Toplevel
1681 x => "center",
1682 y => "center",
1683 z => 3,
1684 name => 'tip_of_the_day',
1685 force_w => int $WIDTH * 4/9,
1686 force_h => int $WIDTH * 2/9,
1687 title => "Tip of the day #" . (1 + $todindex),
1688 child => my $vbox = new CFPlus::UI::VBox,
1689 has_close_button => 1,
1690 on_delete => $close,
1691 ;
1692
1693 $vbox->add (my $viewer = new CFPlus::UI::TextScroller
1694 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1695 $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]);
1696
1697 $vbox->add (my $table = new CFPlus::UI::Table);
1698
1699 $table->add (0, 0, new CFPlus::UI::Button
1700 text => "Close",
1701 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>.",
1702 on_activate => $close,
1703 );
1704
1705 $table->add (2, 0, new CFPlus::UI::Button
1706 text => "Next",
1707 tooltip => "Show the next <b>Tip of the day</b>.",
1708 on_activate => sub {
1709 $close->();
1710 &show_tip_of_the_day;
1711 },
1712 );
1713
1714 $dialog->show;
1715} 1661}
1716 1662
1717sub sdl_init { 1663sub sdl_init {
1718 CFPlus::SDL_Init 1664 CFPlus::SDL_Init
1719 and die "SDL::Init failed!\n"; 1665 and die "SDL::Init failed!\n";
1753 padding => 0, 1699 padding => 0,
1754 z => 100, 1700 z => 100,
1755 force_x => "max", 1701 force_x => "max",
1756 force_y => 0; 1702 force_y => 0;
1757 $DEBUG_STATUS->show; 1703 $DEBUG_STATUS->show;
1758
1759 $BIND_EDITOR = new CFPlus::BindingEditor (x => "max", y => 0);
1760 1704
1761 $STATUSBOX = new CFPlus::UI::Statusbox; 1705 $STATUSBOX = new CFPlus::UI::Statusbox;
1762 $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", timeout => 864000, pri => -100, color => [1, 1, 1, 0.8]); 1706 $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", timeout => 864000, pri => -100, color => [1, 1, 1, 0.8]);
1763 1707
1764 (new CFPlus::UI::Frame 1708 (new CFPlus::UI::Frame
1801 font => $FONT_FIXED, 1745 font => $FONT_FIXED,
1802 fontsize => $::CFG->{log_fontsize}, 1746 fontsize => $::CFG->{log_fontsize},
1803 indent => -4, 1747 indent => -4,
1804 can_hover => 1, 1748 can_hover => 1,
1805 can_events => 1, 1749 can_events => 1,
1750 max_par => $CFG->{logview_max_par},
1806 tooltip => "<b>Server Log</b>. This text viewer contains all the messages sent by the server.", 1751 tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
1807 ; 1752 ;
1808 1753
1809 $SETUP_DIALOG = new CFPlus::UI::Toplevel 1754 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1810 title => "Setup", 1755 title => "Setup",
1811 name => "setup_dialog", 1756 name => "setup_dialog",
1822 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, 1767 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1,
1823 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1768 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1824 1769
1825 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, 1770 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup,
1826 "Configure the server to play on, your username, password and other server-related options."); 1771 "Configure the server to play on, your username, password and other server-related options.");
1772 $SETUP_NOTEBOOK->add (Client => client_setup,
1773 "Configure various client-specific settings.");
1827 $SETUP_NOTEBOOK->add (Pickup => autopickup_setup, 1774 $SETUP_NOTEBOOK->add (Pickup => autopickup_setup,
1828 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1775 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1829 $SETUP_NOTEBOOK->add (Graphics => graphics_setup, 1776 $SETUP_NOTEBOOK->add (Graphics => graphics_setup,
1830 "Configure the video mode, performance, fonts and other graphical aspects of the game."); 1777 "Configure the video mode, performance, fonts and other graphical aspects of the game.");
1831 $SETUP_NOTEBOOK->add (Audio => audio_setup, 1778 $SETUP_NOTEBOOK->add (Audio => audio_setup,
1889} 1836}
1890 1837
1891sub setup_build_button { 1838sub setup_build_button {
1892 my ($enabled) = @_; 1839 my ($enabled) = @_;
1893 if ($enabled) { 1840 if ($enabled) {
1841 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1894 $BUILD_BUTTON ||= new CFPlus::UI::Button 1842 $BUILD_BUTTON ||= new CFPlus::UI::Button
1895 text => "Build", 1843 text => "Build",
1896 tooltip => "Opens the ingame builder", 1844 tooltip => "Opens the ingame builder",
1897 on_activate => sub { 1845 on_activate => sub {
1898 if ($CONN) { 1846 if ($CONN) {
2131 if $CONN; 2079 if $CONN;
2132}); 2080});
2133 2081
2134%SDL_CB = ( 2082%SDL_CB = (
2135 CFPlus::SDL_QUIT => sub { 2083 CFPlus::SDL_QUIT => sub {
2136 Event::unloop -1; 2084 exit;
2137 }, 2085 },
2138 CFPlus::SDL_VIDEORESIZE => sub { 2086 CFPlus::SDL_VIDEORESIZE => sub {
2139 }, 2087 },
2140 CFPlus::SDL_VIDEOEXPOSE => sub { 2088 CFPlus::SDL_VIDEOEXPOSE => sub {
2141 CFPlus::UI::full_refresh; 2089 CFPlus::UI::full_refresh;
2142 }, 2090 },
2143 CFPlus::SDL_ACTIVEEVENT => sub { 2091 CFPlus::SDL_ACTIVEEVENT => sub {
2144# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 2092# not useful, as APPACTIVE include sonly iconified state, not unmapped
2093# printf "active %x %x\n", $_[0]{gain}, $_[0]{state};#d#
2094# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
2095# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
2096# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
2145 }, 2097 },
2146 CFPlus::SDL_KEYDOWN => sub { 2098 CFPlus::SDL_KEYDOWN => sub {
2147 if ($_[0]{mod} & CFPlus::KMOD_ALT && $_[0]{sym} == 13) { 2099 if ($_[0]{mod} & CFPlus::KMOD_ALT && $_[0]{sym} == 13) {
2148 # alt-enter 2100 # alt-enter
2149 $FULLSCREEN_ENABLE->toggle; 2101 $FULLSCREEN_ENABLE->toggle;
2170 2122
2171$SIG{INT} = $SIG{TERM} = sub { exit }; 2123$SIG{INT} = $SIG{TERM} = sub { exit };
2172 2124
2173{ 2125{
2174 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc"; 2126 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc";
2127 CFPlus::DB::Server::run;
2128
2175 CFPlus::UI::set_layout ($::CFG->{layout}); 2129 CFPlus::UI::set_layout ($::CFG->{layout});
2176 2130
2177 my %DEF_CFG = ( 2131 my %DEF_CFG = (
2178 sdl_mode => 0, 2132 sdl_mode => 0,
2179 width => 640, 2133 width => 640,
2180 height => 480, 2134 height => 480,
2181 fullscreen => 0, 2135 fullscreen => 0,
2182 fast => 0, 2136 fast => 0,
2183 map_scale => 1, 2137 map_scale => 1,
2184 fow_enable => 1, 2138 fow_enable => 1,
2185 fow_intensity => 0.45, 2139 fow_intensity => 0.45,
2186 fow_smooth => 0, 2140 fow_smooth => 0,
2141 map_smoothing => 1,
2187 gui_fontsize => 1, 2142 gui_fontsize => 1,
2188 log_fontsize => 0.7, 2143 log_fontsize => 0.7,
2189 gauge_fontsize => 1, 2144 gauge_fontsize => 1,
2190 gauge_size => 0.35, 2145 gauge_size => 0.35,
2191 stat_fontsize => 0.7, 2146 stat_fontsize => 0.7,
2192 mapsize => 100, 2147 mapsize => 100,
2193 say_command => 'chat', 2148 say_command => 'chat',
2194 audio_enable => 1, 2149 audio_enable => 1,
2195 bgm_enable => 1, 2150 bgm_enable => 1,
2196 bgm_volume => 0.25, 2151 bgm_volume => 0.25,
2197 face_prefetch => 0, 2152 face_prefetch => 0,
2198 output_sync => 1, 2153 output_sync => 1,
2199 output_count => 1, 2154 output_count => 1,
2155 output_rate => "",
2200 pickup => 0, 2156 pickup => 0,
2201 inv_sort => "mtime", 2157 inv_sort => "mtime",
2202 default => "profile", # default profile 2158 default => "profile", # default profile
2203 show_tips => 1, 2159 show_tips => 1,
2160 logview_max_par => 1000,
2204 ); 2161 );
2205 2162
2206 while (my ($k, $v) = each %DEF_CFG) { 2163 while (my ($k, $v) = each %DEF_CFG) {
2207 $CFG->{$k} = $v unless exists $CFG->{$k}; 2164 $CFG->{$k} = $v unless exists $CFG->{$k};
2208 } 2165 }
2209 2166
2210 $CFG->{profile}{default}{host} ||= "crossfire.schmorp.de"; 2167 $CFG->{profile}{default}{host} ||= "crossfire.schmorp.de";
2168 $PROFILE = $CFG->{profile}{default};
2169
2170 # convert old bindings (only default profile matters)
2171 if (my $bindings = delete $PROFILE->{bindings}) {
2172 while (my ($mod, $syms) = each %$bindings) {
2173 while (my ($sym, $cmds) = each %$syms) {
2174 push @{ $PROFILE->{macro} }, {
2175 accelkey => [$mod*1, $sym*1],
2176 action => $cmds,
2177 };
2178 }
2179 }
2180 }
2211 2181
2212 sdl_init; 2182 sdl_init;
2213 2183
2214 @SDL_MODES = reverse 2184 @SDL_MODES = reverse
2215 grep $_->[0] >= 640 && $_->[1] >= 480, 2185 grep $_->[0] >= 640 && $_->[1] >= 480,
2264 2234
2265Event::loop; 2235Event::loop;
2266#CFPlus::SDL_Quit; 2236#CFPlus::SDL_Quit;
2267#CFPlus::_exit 0; 2237#CFPlus::_exit 0;
2268 2238
2239END {
2269END { CFPlus::SDL_Quit } 2240 CFPlus::SDL_Quit;
2241 CFPlus::DB::Server::stop;
2242}
2270 2243
2271=head1 NAME 2244=head1 NAME
2272 2245
2273cfplus - A Crossfire+ and Crossfire game client 2246cfplus - A Crossfire+ and Crossfire game client
2274 2247

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines