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.181 by root, Sat Jul 21 16:07:53 2007 UTC vs.
Revision 1.191 by root, Sun Jul 29 21:31:48 2007 UTC

71unshift @INC, $ENV{PAR_TEMP} 71unshift @INC, $ENV{PAR_TEMP}
72 if %PAR::LibCache; 72 if %PAR::LibCache;
73 73
74use Time::HiRes 'time'; 74use Time::HiRes 'time';
75use Event; 75use Event;
76use List::Util qw(max min);
76 77
77use Crossfire; 78use Crossfire;
78use Crossfire::Protocol::Constants; 79use Crossfire::Protocol::Constants;
79 80
80use Compress::LZF; 81use Compress::LZF;
85use CFPlus::DB; 86use CFPlus::DB;
86use CFPlus::UI; 87use CFPlus::UI;
87use CFPlus::UI::Canvas; 88use CFPlus::UI::Canvas;
88use CFPlus::UI::Inventory; 89use CFPlus::UI::Inventory;
89use CFPlus::UI::SpellList; 90use CFPlus::UI::SpellList;
91use CFPlus::UI::MessageWindow;
90use CFPlus::Pod; 92use CFPlus::Pod;
91use CFPlus::MapWidget; 93use CFPlus::MapWidget;
92use CFPlus::Macro; 94use CFPlus::Macro;
93 95
94$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 96$SIG{QUIT} = sub { Carp::cluck "QUIT" };
126 128
127our $MAP; 129our $MAP;
128our $MAPMAP; 130our $MAPMAP;
129our $MAPWIDGET; 131our $MAPWIDGET;
130our $BUTTONBAR; 132our $BUTTONBAR;
131our $LOGVIEW;
132our $CONSOLE;
133our $METASERVER; 133our $METASERVER;
134our $LOGIN_BUTTON; 134our $LOGIN_BUTTON;
135our $QUIT_DIALOG; 135our $QUIT_DIALOG;
136our $HOST_ENTRY; 136our $HOST_ENTRY;
137our $FULLSCREEN_ENABLE; 137our $FULLSCREEN_ENABLE;
163 163
164our $SDL_MIXER; 164our $SDL_MIXER;
165our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 165our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
166our @MUSIC_WANT; 166our @MUSIC_WANT;
167our $MUSIC_START; 167our $MUSIC_START;
168our $MUSIC_PLAYING; 168our $MUSIC_PLAYING_DATA;
169our $MUSIC_PLAYING_META;
169our $MUSIC_PLAYER; 170our $MUSIC_PLAYER;
170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 171our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
171our @SOUNDS; # event => file mapping 172our @SOUNDS; # event => file mapping
172our %AUDIO_CHUNKS; # audio files 173our %AUDIO_CHUNKS; # audio files
173 174
179our $INVR; 180our $INVR;
180our $INV_RIGHT_HB; 181our $INV_RIGHT_HB;
181 182
182our $PICKUP_CFG; 183our $PICKUP_CFG;
183 184
184our $IN_BUILD_MODE;
185our $BUILD_BUTTON;
186
187sub status { 185sub status {
188 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 186 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
189} 187}
190 188
191sub debug { 189sub debug {
192 $DEBUG_STATUS->set_text ($_[0]); 190 $DEBUG_STATUS->set_text ($_[0]);
193} 191}
194 192
195sub message { 193sub message {
196 my ($para) = @_; 194 my ($para) = @_;
197 195 $MESSAGE_WINDOW->message ($para);
198 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
199
200 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
201
202 $LOGVIEW->add_paragraph ($para);
203 $LOGVIEW->scroll_to_bottom;
204} 196}
205 197
206sub destroy_query_dialog { 198sub destroy_query_dialog {
207 (delete $_[0]{query_dialog})->destroy 199 (delete $_[0]{query_dialog})->destroy
208 if $_[0]{query_dialog}; 200 if $_[0]{query_dialog};
461 maph => $mapsize, 453 maph => $mapsize,
462 454
463 client => "cfplus $CFPlus::VERSION $] $^O", 455 client => "cfplus $CFPlus::VERSION $] $^O",
464 456
465 map_widget => $MAPWIDGET, 457 map_widget => $MAPWIDGET,
466 logview => $LOGVIEW,
467 statusbox => $STATUSBOX, 458 statusbox => $STATUSBOX,
468 map => $MAP, 459 map => $MAP,
469 mapmap => $MAPMAP, 460 mapmap => $MAPMAP,
470 query => \&server_query, 461 query => \&server_query,
471 462
472 setup_req => { 463 setup_req => {
473 smoothing => $CFG->{map_smoothing}*1, 464 smoothing => $CFG->{map_smoothing}*1,
474 },
475
476 sound_play => sub {
477 my ($x, $y, $soundnum, $type) = @_;
478
479 $SDL_MIXER
480 or return;
481
482 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
483 or return;
484
485 $chunk->play;
486 }, 465 },
487 }; 466 };
488 467
489 if ($CONN) { 468 if ($CONN) {
490 CFPlus::lowdelay fileno $CONN->{fh}; 469 CFPlus::lowdelay fileno $CONN->{fh};
614 593
615 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 594 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
616 $table->add_at (1, $row++, new CFPlus::UI::Slider 595 $table->add_at (1, $row++, new CFPlus::UI::Slider
617 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 596 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
618 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 597 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.",
619 on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 598 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
620 ); 599 );
621 600
622 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 601 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
623 $table->add_at (1, $row++, new CFPlus::UI::Slider 602 $table->add_at (1, $row++, new CFPlus::UI::Slider
624 range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1], 603 range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1],
1132 . "but you also increase bandwidth requirements and latency. " 1111 . "but you also increase bandwidth requirements and latency. "
1133 . "This option is only used once at log-in.", 1112 . "This option is only used once at log-in.",
1134 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1113 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 },
1135 ); 1114 );
1136 1115
1137 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch");
1138 $table->add_at (1, 8, new CFPlus::UI::CheckBox
1139 state => $CFG->{face_prefetch},
1140 tooltip => "<b>Background Image Prefetch</b>\n\n"
1141 . "If enabled, the client automatically pre-fetches images from the server. "
1142 . "This might increase or create lag, but increases the chances "
1143 . "of faces being ready for display when you encounter them. "
1144 . "It also uses up server bandwidth on every connect, "
1145 . "so only set it if you really need to prefetch images. "
1146 . "This option can be set and unset any time.",
1147 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
1148 );
1149
1150 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1116 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1151 $table->add_at (1, 9, new CFPlus::UI::Entry 1117 $table->add_at (1, 8, new CFPlus::UI::Entry
1152 text => $CFG->{output_rate}, 1118 text => $CFG->{output_rate},
1153 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1119 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
1154 . "when sending images, to ensure interactiveness. When 0 or unset, the server " 1120 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1155 . "default will be used, which is usually around 100kb/s.", 1121 . "default will be used, which is usually around 100kb/s.",
1156 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1122 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1157 ); 1123 );
1158 1124
1159 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1125 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1160 $table->add_at (1, 10, new CFPlus::UI::Entry 1126 $table->add_at (1, 9, new CFPlus::UI::Entry
1161 text => $CFG->{output_count}, 1127 text => $CFG->{output_count},
1162 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1128 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1163 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1129 on_changed => sub { $CFG->{output_count} = $_[1]; 0 },
1164 ); 1130 );
1165 1131
1166 $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1132 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1167 $table->add_at (1, 11, new CFPlus::UI::Entry 1133 $table->add_at (1, 10, new CFPlus::UI::Entry
1168 text => $CFG->{output_sync}, 1134 text => $CFG->{output_sync},
1169 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1135 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1170 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1136 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 },
1171 ); 1137 );
1172 1138
1173 $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button 1139 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1174 expand => 1, 1140 expand => 1,
1175 align => 0, 1141 align => 0,
1176 text => "Login", 1142 text => "Login",
1177 on_activate => sub { 1143 on_activate => sub {
1178 $CONN ? stop_game 1144 $CONN ? stop_game
1191 1157
1192sub client_setup { 1158sub client_setup {
1193 my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]; 1159 my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1];
1194 1160
1195 my $row = 0; 1161 my $row = 0;
1196
1197 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command");
1198 $table->add_at (1, $row++, my $saycmd = new CFPlus::UI::Entry
1199 text => $CFG->{say_command},
1200 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. "
1201 . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
1202 . "But you could also set it to <b>tell <i>playername</i></b> to only chat with that user.",
1203 on_changed => sub {
1204 my ($self, $value) = @_;
1205 $CFG->{say_command} = $value;
1206 0
1207 }
1208 );
1209 1162
1210 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); 1163 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day");
1211 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 1164 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
1212 state => $CFG->{show_tips}, 1165 state => $CFG->{show_tips},
1213 tooltip => "Show the <b>Tip of the day</b> window at startup?", 1166 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1224 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server " 1177 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server "
1225 . "sends more messages than this number, older messages get removed to save memory and " 1178 . "sends more messages than this number, older messages get removed to save memory and "
1226 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", 1179 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1227 on_changed => sub { 1180 on_changed => sub {
1228 my ($self, $value) = @_; 1181 my ($self, $value) = @_;
1229 $LOGVIEW->{max_par} = $CFG->{logview_max_par} = $value*1; 1182 $MESSAGE_WINDOW->set_max_para ($CFG->{logview_max_par} = $value*1);
1230 0 1183 0
1231 }, 1184 },
1232 ); 1185 );
1233 1186
1234 $table 1187 $table
1235}
1236
1237sub message_window {
1238 my $window = new CFPlus::UI::Toplevel
1239 name => "message_window",
1240 title => "Messages",
1241 border_bg => [1, 1, 1, 1],
1242 x => "max",
1243 y => 0,
1244 force_w => $::WIDTH * 0.4,
1245 force_h => $::HEIGHT * 0.5,
1246 child => (my $vbox = new CFPlus::UI::VBox),
1247 has_close_button => 1;
1248
1249 $vbox->add ($LOGVIEW);
1250
1251 $vbox->add (my $input = new CFPlus::UI::Entry
1252 tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
1253 . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
1254 . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
1255 . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
1256 on_focus_in => sub {
1257 my ($input, $prev_focus) = @_;
1258
1259 delete $input->{refocus_map};
1260
1261 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
1262 $input->{refocus_map} = 1;
1263 }
1264 delete $input->{auto_activated};
1265
1266 0
1267 },
1268 on_activate => sub {
1269 my ($input, $text) = @_;
1270 $input->set_text ('');
1271
1272 if ($text =~ /^\/(.*)/) {
1273 $::CONN->user_send ($1);
1274 } else {
1275 my $say_cmd = $::CFG->{say_command} || 'say';
1276 $::CONN->user_send ("$say_cmd $text");
1277 }
1278 if ($input->{refocus_map}) {
1279 delete $input->{refocus_map};
1280 $MAPWIDGET->focus_in
1281 }
1282
1283 0
1284 },
1285 on_escape => sub {
1286 $MAPWIDGET->grab_focus;
1287
1288 0
1289 },
1290 );
1291
1292 $CONSOLE = {
1293 window => $window,
1294 input => $input,
1295 };
1296
1297 $window
1298} 1188}
1299 1189
1300sub autopickup_setup { 1190sub autopickup_setup {
1301 my $r = new CFPlus::UI::ScrolledWindow ( 1191 my $r = new CFPlus::UI::ScrolledWindow (
1302 expand => 1, 1192 expand => 1,
1488 1378
1489 my $ntb = 1379 my $ntb =
1490 $PL_NOTEBOOK = 1380 $PL_NOTEBOOK =
1491 new CFPlus::UI::Notebook expand => 1; 1381 new CFPlus::UI::Notebook expand => 1;
1492 1382
1493 $ntb->add ( 1383 $ntb->add_tab (
1494 "Statistics (F2)" => $STATS_PAGE = stats_window, 1384 "Statistics (F2)" => $STATS_PAGE = stats_window,
1495 "Shows statistics, where all your Stats and Resistances are shown." 1385 "Shows statistics, where all your Stats and Resistances are shown."
1496 ); 1386 );
1497 $ntb->add ( 1387 $ntb->add_tab (
1498 "Skills (F3)" => $SKILL_PAGE = skill_window, 1388 "Skills (F3)" => $SKILL_PAGE = skill_window,
1499 "Shows all your Skills." 1389 "Shows all your Skills."
1500 ); 1390 );
1501 1391
1502 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); 1392 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1);
1503 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList); 1393 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList);
1504 $ntb->add ( 1394 $ntb->add_tab (
1505 "Spellbook (F4)" => $spellsw, 1395 "Spellbook (F4)" => $spellsw,
1506 "Displays all spells you have and lets you edit keyboard shortcuts for them." 1396 "Displays all spells you have and lets you edit keyboard shortcuts for them."
1507 ); 1397 );
1508 $ntb->add ( 1398 $ntb->add_tab (
1509 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1399 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1510 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1400 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1511 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1401 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1512 ); 1402 );
1513 $ntb->add (Pickup => autopickup_setup, 1403 $ntb->add_tab (Pickup => autopickup_setup,
1514 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1404 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1515 1405
1516 $ntb->set_current_page ($INVENTORY_PAGE); 1406 $ntb->set_current_page ($INVENTORY_PAGE);
1517 1407
1518 $plwin->add ($ntb); 1408 $plwin->add ($ntb);
1801 1691
1802 $MAPWIDGET = new CFPlus::MapWidget; 1692 $MAPWIDGET = new CFPlus::MapWidget;
1803 $MAPWIDGET->connect (activate_console => sub { 1693 $MAPWIDGET->connect (activate_console => sub {
1804 my ($mapwidget, $preset) = @_; 1694 my ($mapwidget, $preset) = @_;
1805 1695
1806 if ($CONSOLE) { 1696 $MESSAGE_WINDOW->activate_console ($preset)
1807 $CONSOLE->{input}->{auto_activated} = 1; 1697 if $MESSAGE_WINDOW;
1808 $CONSOLE->{input}->grab_focus;
1809
1810 if ($preset && $CONSOLE->{input}->get_text eq '') {
1811 $CONSOLE->{input}->set_text ($preset);
1812 }
1813 }
1814 }); 1698 });
1815 $MAPWIDGET->show; 1699 $MAPWIDGET->show;
1816 $MAPWIDGET->grab_focus; 1700 $MAPWIDGET->grab_focus;
1817
1818 $LOGVIEW = new CFPlus::UI::TextScroller
1819 expand => 1,
1820 font => $FONT_FIXED,
1821 fontsize => $::CFG->{log_fontsize},
1822 indent => -4,
1823 can_hover => 1,
1824 can_events => 1,
1825 max_par => $CFG->{logview_max_par},
1826 tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
1827 ;
1828 1701
1829 $SETUP_DIALOG = new CFPlus::UI::Toplevel 1702 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1830 title => "Setup", 1703 title => "Setup",
1831 name => "setup_dialog", 1704 name => "setup_dialog",
1832 x => 'center', 1705 x => 'center',
1836 force_h => $::HEIGHT * 0.6, 1709 force_h => $::HEIGHT * 0.6,
1837 has_close_button => 1, 1710 has_close_button => 1,
1838 ; 1711 ;
1839 1712
1840 $METASERVER = metaserver_dialog; 1713 $METASERVER = metaserver_dialog;
1714 $MESSAGE_WINDOW = new CFPlus::UI::MessageWindow;
1841 1715
1842 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, 1716 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1,
1843 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1717 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1844 1718
1845 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, 1719 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
1846 "Configure the server to play on, your username, password and other server-related options."); 1720 "Configure the server to play on, your username, password and other server-related options.");
1847 $SETUP_NOTEBOOK->add (Client => client_setup, 1721 $SETUP_NOTEBOOK->add_tab (Client => client_setup,
1848 "Configure various client-specific settings."); 1722 "Configure various client-specific settings.");
1849 $SETUP_NOTEBOOK->add (Graphics => graphics_setup, 1723 $SETUP_NOTEBOOK->add_tab (Graphics => graphics_setup,
1850 "Configure the video mode, performance, fonts and other graphical aspects of the game."); 1724 "Configure the video mode, performance, fonts and other graphical aspects of the game.");
1851 $SETUP_NOTEBOOK->add (Audio => audio_setup, 1725 $SETUP_NOTEBOOK->add_tab (Audio => audio_setup,
1852 "Configure the use of audio, sound effects and background music."); 1726 "Configure the use of audio, sound effects and background music.");
1853 $SETUP_NOTEBOOK->add (Keyboard => $SETUP_KEYBOARD = keyboard_setup, 1727 $SETUP_NOTEBOOK->add_tab (Keyboard => $SETUP_KEYBOARD = keyboard_setup,
1854 "Lets you define, edit and delete key bindings." 1728 "Lets you define, edit and delete key bindings."
1855 . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor " 1729 . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor "
1856 . "with nothing set and the recording started. After doing the actions you " 1730 . "with nothing set and the recording started. After doing the actions you "
1857 . "want to record press <b>Insert</b> and you will be asked to press a key-combo. " 1731 . "want to record press <b>Insert</b> and you will be asked to press a key-combo. "
1858 . "After pressing the combo the binding will be saved automatically and the " 1732 . "After pressing the combo the binding will be saved automatically and the "
1859 . "binding editor closes"); 1733 . "binding editor closes");
1860 $SETUP_NOTEBOOK->add (Debug => debug_setup, 1734 $SETUP_NOTEBOOK->add_tab (Debug => debug_setup,
1861 "Some debuggin' options. Do not ask."); 1735 "Some debuggin' options. Do not ask.");
1862 1736
1863 $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top 1737 $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top
1864 1738
1865 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG, 1739 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
1866 tooltip => "Toggles a dialog where you can configure all aspects of this client."); 1740 tooltip => "Toggles a dialog where you can configure all aspects of this client.");
1867 1741
1868 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW = message_window, 1742 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
1869 tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); 1743 tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
1870 1744
1871 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 1745 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
1872 1746
1873 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window, 1747 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window,
1906 } 1780 }
1907 1781
1908 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 1782 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
1909} 1783}
1910 1784
1911sub setup_build_button {
1912 my ($enabled) = @_;
1913 if ($enabled) {
1914 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1915 $BUILD_BUTTON ||= new CFPlus::UI::Button
1916 text => "Build",
1917 tooltip => "Opens the ingame builder",
1918 on_activate => sub {
1919 if ($CONN) {
1920 $CONN->send_ext_req (builder_player_items => sub {
1921 open_ingame_editor ($_[0]) if exists $_[0]->{items};
1922 });
1923 }
1924 0
1925 };
1926 $BUTTONBAR->add ($BUILD_BUTTON);
1927 } else {
1928 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1929 }
1930}
1931
1932sub open_ingame_editor {
1933 my ($msg) = @_;
1934
1935 my $win = new CFPlus::UI::Toplevel
1936 x => 0,
1937 y => 'center',
1938 z => 4,
1939 name => 'builder_window',
1940 force_w => int $WIDTH * 1/4,
1941 force_h => int $HEIGHT * 3/4,
1942 title => "In game builder",
1943 has_close_button => 1;
1944
1945 my $r = new CFPlus::UI::ScrolledWindow (
1946 expand => 1,
1947 scroll_y => 1
1948 );
1949 $r->add (my $vb = new CFPlus::UI::VBox);
1950 $win->add ($r);
1951
1952
1953 $vb->add (
1954 new CFPlus::UI::Button
1955 text => "Disable build mode",
1956 on_activate => sub { $::IN_BUILD_MODE = undef }
1957 );
1958 $vb->add (
1959 new CFPlus::UI::Button
1960 text => "ERASE",
1961 on_activate => sub { $::IN_BUILD_MODE = { do_erase => 1 } }
1962 );
1963
1964 for my $itemarchname (
1965 sort {
1966 $msg->{items}->{$a}->{build_arch_name}
1967 cmp $msg->{items}->{$b}->{build_arch_name}
1968 } keys %{$msg->{items}}
1969 ) {
1970 my $info = $msg->{items}->{$itemarchname};
1971 $vb->add (
1972 new CFPlus::UI::Button text => $info->{build_arch_name},
1973 on_activate => sub {
1974 $::IN_BUILD_MODE = { item => $itemarchname, info => $info };
1975
1976 if (grep { $msg->{items}->{$itemarchname}->{$_} } qw/has_connection has_name has_text/) {
1977 build_mode_query_arch_info ();
1978 }
1979 }
1980 );
1981 }
1982
1983 $win->show;
1984}
1985
1986sub build_mode_query_arch_info {
1987 my ($iteminfo) = $::IN_BUILD_MODE;
1988 my $itemarchname = $iteminfo->{item};
1989 my $info = $iteminfo->{info};
1990
1991 my $dialog = new CFPlus::UI::Toplevel
1992 x => "center",
1993 y => "center",
1994 z => 50,
1995 force_w => int $WIDTH * 1/2,
1996 title => "Enter information for placement of '$itemarchname'",
1997 has_close_button => 1;
1998
1999 $dialog->add (my $vb = new CFPlus::UI::VBox expand => 1);
2000
2001 $vb->add (my $table = new CFPlus::UI::Table expand => 1);
2002 my $row = 0;
2003 if ($info->{has_name}) {
2004 $table->add_at (0, $row, new CFPlus::UI::Label text => "Name:");
2005 $table->add_at (1, $row++, new CFPlus::UI::Entry expand => 1, on_changed => sub { $::IN_BUILD_MODE->{name} = $_[1]; 0 });
2006 }
2007 if ($info->{has_text}) {
2008 $table->add_at (0, $row, new CFPlus::UI::Label text => "Text:");
2009 $table->add_at (1, $row++, new CFPlus::UI::Entry expand => 1, on_changed => sub { $::IN_BUILD_MODE->{text} = $_[1]; 0 });
2010 }
2011 if ($info->{has_connection}) {
2012 $table->add_at (0, $row, new CFPlus::UI::Label text => "Connection ID:");
2013 $table->add_at (1, $row++,
2014 new CFPlus::UI::Entry
2015 expand => 1,
2016 on_changed => sub { $::IN_BUILD_MODE->{connection} = $_[1]; 0 },
2017 tooltip => "Enter the connection ID here. The connection ID connects actors like a lever to a gate or a magic ear to a gate"
2018 );
2019 }
2020
2021 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
2022 $hb->add (new CFPlus::UI::Button
2023 text => "Close",
2024 expand => 1,
2025 on_activate => sub { $dialog->hide; 0 },
2026 );
2027 $dialog->show;
2028}
2029
2030sub video_shutdown { 1785sub video_shutdown {
2031 CFPlus::OpenGL::shutdown; 1786 CFPlus::OpenGL::shutdown;
2032 1787
2033 undef $SDL_ACTIVE; 1788 undef $SDL_ACTIVE;
2034} 1789}
2035 1790
2036sub audio_channel_finished { 1791sub audio_channel_finished {
2037 my ($channel) = @_; 1792 my ($channel) = @_;
2038 1793
2039 #warn "channel $channel finished\n";#d# 1794# warn "channel $channel finished\n";#d#
1795}
1796
1797our %AUDIO_PLAY;
1798our %AUDIO_CHUNK;
1799
1800sub audio_sound_push($) {
1801 my ($face) = @_;
1802
1803 if (my $chunk = $AUDIO_CHUNK{$face}) {
1804 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
1805 my (undef, $dx, $dy, $vol) = @$_;
1806
1807 my $channel = $chunk->play
1808 or return;
1809
1810 $channel->volume (128 + $vol);
1811 $dx = $dx / 10 * 255;
1812 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
1813# my $angle = $dx ? : $dx < 0 ?
1814# my $distance = -$vol;
1815# $channel->set_position ($angle, $distance);
1816 }
1817 } else {
1818 # sound_meta not set means data is in flight either way
1819 my $meta = $CONN->{sound_meta}{$face}
1820 or return;
1821
1822 # fetch from database
1823 CFPlus::DB::get res_data => $meta->{name}, sub {
1824 my $vol = $meta->{meta}{volume} || 100;
1825 my $rwops = new CFPlus::RW $_[0];
1826 my $chunk = new CFPlus::MixChunk $rwops;
1827 $chunk->volume ($vol * 128 / 100);
1828 $AUDIO_CHUNK{$face} = $chunk;
1829
1830 audio_sound_push ($face);
1831 };
1832 }
1833}
1834
1835sub audio_sound_play {
1836 my ($face, $dx, $dy, $vol) = @_;
1837
1838 $SDL_MIXER
1839 or return;
1840
1841 my $queue = $AUDIO_PLAY{$face} ||= [];
1842 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
1843 audio_sound_push $face
1844 unless @$queue > 1;
2040} 1845}
2041 1846
2042sub audio_music_set { 1847sub audio_music_set {
2043 my ($songs) = @_; 1848 my ($songs) = @_;
2044 1849
2052 &audio_music_changed (); 1857 &audio_music_changed ();
2053 } 1858 }
2054} 1859}
2055 1860
2056sub audio_music_start { 1861sub audio_music_start {
2057 my $path = $MUSIC_PLAYING->{path} 1862 my $meta = $MUSIC_PLAYING_META;
2058 or return;
2059 1863
2060 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1864 CFPlus::DB::get res_data => $meta->{name}, sub {
1865 return unless $SDL_MIXER;
1866
2061 # music might have changed... 1867 # music might have changed...
2062 $path eq $MUSIC_PLAYING->{path} 1868 $meta eq $MUSIC_PLAYING_META
2063 or return &audio_music_start (); 1869 or return &audio_music_start ();
2064 1870
1871 $MUSIC_PLAYING_DATA = \$_[0];
1872
1873 my $rwops = $meta->{path}
1874 ? new_from_file CFPlus::RW $meta->{path}
1875 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1876
2065 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; 1877 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1878 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
2066 1879
2067 my $NOW = time; 1880 my $NOW = time;
2068 1881
2069 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { 1882 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
2070 my $pos = $MUSIC_PLAYING->{stop_pos}; 1883 my $pos = $MUSIC_PLAYING_META->{stop_pos};
2071 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 1884 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
2072 $MUSIC_START = time - $pos; 1885 $MUSIC_START = time - $pos;
2073 } else { 1886 } else {
2074 $MUSIC_PLAYER->play (0); 1887 $MUSIC_PLAYER->play (0);
2075 $MUSIC_START = time; 1888 $MUSIC_START = time;
2076 } 1889 }
2077 1890
2078 delete $MUSIC_PLAYING->{stop_time}; 1891 delete $MUSIC_PLAYING_META->{stop_time};
2079 delete $MUSIC_PLAYING->{stop_pos}; 1892 delete $MUSIC_PLAYING_META->{stop_pos};
2080 } 1893 }
2081} 1894}
2082 1895
2083sub audio_music_changed { 1896sub audio_music_changed {
2084 return unless $CFG->{bgm_enable}; 1897 return unless $CFG->{bgm_enable};
1898 return unless $SDL_MIXER;
2085 1899
2086 # default MUSIC_WANT == MUSIC_DEFAULT 1900 # default MUSIC_WANT == MUSIC_DEFAULT
2087 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 1901 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
2088 1902
2089 # if the currently playing song is acceptable, let it continue 1903 # if the currently playing song is acceptable, let it continue
2090 return if $MUSIC_PLAYING 1904 return if $MUSIC_PLAYING_META
2091 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 1905 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
2092 1906
2093 my $NOW = time; 1907 my $NOW = time;
2094 1908
2095 if ($MUSIC_PLAYING) { 1909 if ($MUSIC_PLAYING_META) {
2096 $MUSIC_PLAYING->{stop_time} = $NOW; 1910 $MUSIC_PLAYING_META->{stop_time} = $NOW;
2097 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; 1911 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
2098 CFPlus::MixMusic::fade_out 1000; 1912 CFPlus::MixMusic::fade_out 1000;
2099 } else { 1913 } else {
2100 # sort by stop time, oldest first 1914 # sort by stop time, oldest first
2101 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 1915 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
2102 1916
2103 # if the most recently-played piece played very recently, 1917 # if the most recently-played piece played very recently,
2104 # resume it, else choose the oldest piece for rotation. 1918 # resume it, else choose the oldest piece for rotation.
2105 $MUSIC_PLAYING = 1919 $MUSIC_PLAYING_META =
2106 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 1920 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
2107 ? $MUSIC_WANT[-1] 1921 ? $MUSIC_WANT[-1]
2108 : $MUSIC_WANT[0]; 1922 : $MUSIC_WANT[0];
2109 1923
2110 audio_music_start; 1924 audio_music_start;
2111 } 1925 }
2112} 1926}
2113 1927
2114sub audio_music_finished { 1928sub audio_music_finished {
2115 $MUSIC_PLAYING = undef;
2116 undef $MUSIC_PLAYER; 1929 undef $MUSIC_PLAYER;
1930 undef $MUSIC_PLAYING_META;
1931 undef $MUSIC_PLAYING_DATA;
2117 1932
2118 audio_music_changed; 1933 audio_music_changed;
2119} 1934}
2120 1935
2121sub audio_init { 1936sub audio_init {
2122 if ($CFG->{audio_enable}) { 1937 if ($CFG->{audio_enable}) {
2123 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 1938 $ENV{MIX_EFFECTSMAXSPEED} = 1;
2124 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1939 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
2125 1940
2126 unless ($SDL_MIXER) { 1941 unless ($SDL_MIXER) {
2127 status "Unable to open sound device: there will be no sound"; 1942 status "Unable to open sound device: there will be no sound";
2128 return; 1943 return;
2129 }
2130
2131 CFPlus::Mix_AllocateChannels 8;
2132 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
2133
2134 audio_music_finished;
2135
2136 local $_;
2137 while (<$fh>) {
2138 next if /^\s*#/;
2139 next if /^\s*$/;
2140
2141 my ($file, $volume, $event) = split /\s+/, $_, 3;
2142
2143 push @SOUNDS, "$volume,$file";
2144
2145 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
2146 my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file";
2147 $chunk->volume ($volume * 128 / 100);
2148 $chunk
2149 };
2150 }
2151 } else {
2152 status "unable to open sound config: $!";
2153 } 1944 }
1945
1946 CFPlus::Mix_AllocateChannels 16;
1947 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1948
1949 audio_music_finished;
1950 } else {
1951 undef $SDL_MIXER;
2154 } 1952 }
2155} 1953}
2156 1954
2157sub audio_shutdown { 1955sub audio_shutdown {
2158 CFPlus::Mix_CloseAudio if $SDL_MIXER; 1956 CFPlus::Mix_CloseAudio if $SDL_MIXER;
2206 2004
2207sub animation_stop { 2005sub animation_stop {
2208 my ($widget) = @_; 2006 my ($widget) = @_;
2209 delete $animate_object{$widget}; 2007 delete $animate_object{$widget};
2210} 2008}
2211
2212# check once/second for faces that need to be prefetched
2213# this should, of course, only run on demand, but
2214# SDL forces worse things on us....
2215
2216Event->timer (after => 1, interval => 0.25, cb => sub {
2217 $CONN->face_prefetch
2218 if $CONN;
2219});
2220 2009
2221%SDL_CB = ( 2010%SDL_CB = (
2222 CFPlus::SDL_QUIT => sub { 2011 CFPlus::SDL_QUIT => sub {
2223 exit; 2012 exit;
2224 }, 2013 },
2282 log_fontsize => 0.7, 2071 log_fontsize => 0.7,
2283 gauge_fontsize => 1, 2072 gauge_fontsize => 1,
2284 gauge_size => 0.35, 2073 gauge_size => 0.35,
2285 stat_fontsize => 0.7, 2074 stat_fontsize => 0.7,
2286 mapsize => 100, 2075 mapsize => 100,
2287 say_command => 'chat',
2288 audio_enable => 1, 2076 audio_enable => 1,
2289 bgm_enable => 1, 2077 bgm_enable => 1,
2290 bgm_volume => 0.25, 2078 bgm_volume => 0.25,
2291 face_prefetch => 0,
2292 output_sync => 1, 2079 output_sync => 1,
2293 output_count => 1, 2080 output_count => 1,
2294 output_rate => "", 2081 output_rate => "",
2295 pickup => 0, 2082 pickup => 0,
2296 inv_sort => "mtime", 2083 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines