… | |
… | |
85 | use CFPlus::DB; |
85 | use CFPlus::DB; |
86 | use CFPlus::UI; |
86 | use CFPlus::UI; |
87 | use CFPlus::UI::Canvas; |
87 | use CFPlus::UI::Canvas; |
88 | use CFPlus::UI::Inventory; |
88 | use CFPlus::UI::Inventory; |
89 | use CFPlus::UI::SpellList; |
89 | use CFPlus::UI::SpellList; |
|
|
90 | use CFPlus::UI::MessageWindow; |
90 | use CFPlus::Pod; |
91 | use CFPlus::Pod; |
91 | use CFPlus::MapWidget; |
92 | use CFPlus::MapWidget; |
92 | use CFPlus::Macro; |
93 | use CFPlus::Macro; |
93 | |
94 | |
94 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
95 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
… | |
… | |
126 | |
127 | |
127 | our $MAP; |
128 | our $MAP; |
128 | our $MAPMAP; |
129 | our $MAPMAP; |
129 | our $MAPWIDGET; |
130 | our $MAPWIDGET; |
130 | our $BUTTONBAR; |
131 | our $BUTTONBAR; |
131 | our $LOGVIEW; |
|
|
132 | our $CONSOLE; |
|
|
133 | our $METASERVER; |
132 | our $METASERVER; |
134 | our $LOGIN_BUTTON; |
133 | our $LOGIN_BUTTON; |
135 | our $QUIT_DIALOG; |
134 | our $QUIT_DIALOG; |
136 | our $HOST_ENTRY; |
135 | our $HOST_ENTRY; |
137 | our $FULLSCREEN_ENABLE; |
136 | our $FULLSCREEN_ENABLE; |
… | |
… | |
163 | |
162 | |
164 | our $SDL_MIXER; |
163 | our $SDL_MIXER; |
165 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
164 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
166 | our @MUSIC_WANT; |
165 | our @MUSIC_WANT; |
167 | our $MUSIC_START; |
166 | our $MUSIC_START; |
168 | our $MUSIC_PLAYING; |
167 | our $MUSIC_PLAYING_DATA; |
|
|
168 | our $MUSIC_PLAYING_META; |
169 | our $MUSIC_PLAYER; |
169 | our $MUSIC_PLAYER; |
170 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
170 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
171 | our @SOUNDS; # event => file mapping |
171 | our @SOUNDS; # event => file mapping |
172 | our %AUDIO_CHUNKS; # audio files |
172 | our %AUDIO_CHUNKS; # audio files |
173 | |
173 | |
… | |
… | |
179 | our $INVR; |
179 | our $INVR; |
180 | our $INV_RIGHT_HB; |
180 | our $INV_RIGHT_HB; |
181 | |
181 | |
182 | our $PICKUP_CFG; |
182 | our $PICKUP_CFG; |
183 | |
183 | |
184 | our $IN_BUILD_MODE; |
|
|
185 | our $BUILD_BUTTON; |
|
|
186 | |
|
|
187 | sub status { |
184 | sub status { |
188 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
185 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
189 | } |
186 | } |
190 | |
187 | |
191 | sub debug { |
188 | sub debug { |
192 | $DEBUG_STATUS->set_text ($_[0]); |
189 | $DEBUG_STATUS->set_text ($_[0]); |
193 | } |
190 | } |
194 | |
191 | |
195 | sub message { |
192 | sub message { |
196 | my ($para) = @_; |
193 | my ($para) = @_; |
197 | |
194 | $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 | } |
195 | } |
205 | |
196 | |
206 | sub destroy_query_dialog { |
197 | sub destroy_query_dialog { |
207 | (delete $_[0]{query_dialog})->destroy |
198 | (delete $_[0]{query_dialog})->destroy |
208 | if $_[0]{query_dialog}; |
199 | if $_[0]{query_dialog}; |
… | |
… | |
461 | maph => $mapsize, |
452 | maph => $mapsize, |
462 | |
453 | |
463 | client => "cfplus $CFPlus::VERSION $] $^O", |
454 | client => "cfplus $CFPlus::VERSION $] $^O", |
464 | |
455 | |
465 | map_widget => $MAPWIDGET, |
456 | map_widget => $MAPWIDGET, |
466 | logview => $LOGVIEW, |
|
|
467 | statusbox => $STATUSBOX, |
457 | statusbox => $STATUSBOX, |
468 | map => $MAP, |
458 | map => $MAP, |
469 | mapmap => $MAPMAP, |
459 | mapmap => $MAPMAP, |
470 | query => \&server_query, |
460 | query => \&server_query, |
471 | |
461 | |
… | |
… | |
614 | |
604 | |
615 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
605 | $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 |
606 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
617 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
607 | 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.", |
608 | 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 }, |
609 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
620 | ); |
610 | ); |
621 | |
611 | |
622 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
612 | $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 |
613 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
624 | range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1], |
614 | range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1], |
… | |
… | |
1132 | . "but you also increase bandwidth requirements and latency. " |
1122 | . "but you also increase bandwidth requirements and latency. " |
1133 | . "This option is only used once at log-in.", |
1123 | . "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 }, |
1124 | on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, |
1135 | ); |
1125 | ); |
1136 | |
1126 | |
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"); |
1127 | $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 |
1128 | $table->add_at (1, 8, new CFPlus::UI::Entry |
1152 | text => $CFG->{output_rate}, |
1129 | text => $CFG->{output_rate}, |
1153 | tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " |
1130 | 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 " |
1131 | . "when sending images, to ensure interactiveness. When 0 or unset, the server " |
1155 | . "default will be used, which is usually around 100kb/s.", |
1132 | . "default will be used, which is usually around 100kb/s.", |
1156 | on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, |
1133 | on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, |
1157 | ); |
1134 | ); |
1158 | |
1135 | |
1159 | $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); |
1136 | $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 |
1137 | $table->add_at (1, 9, new CFPlus::UI::Entry |
1161 | text => $CFG->{output_count}, |
1138 | 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.", |
1139 | 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 }, |
1140 | on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, |
1164 | ); |
1141 | ); |
1165 | |
1142 | |
1166 | $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); |
1143 | $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 |
1144 | $table->add_at (1, 10, new CFPlus::UI::Entry |
1168 | text => $CFG->{output_sync}, |
1145 | 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.", |
1146 | 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 }, |
1147 | on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, |
1171 | ); |
1148 | ); |
1172 | |
1149 | |
1173 | $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button |
1150 | $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button |
1174 | expand => 1, |
1151 | expand => 1, |
1175 | align => 0, |
1152 | align => 0, |
1176 | text => "Login", |
1153 | text => "Login", |
1177 | on_activate => sub { |
1154 | on_activate => sub { |
1178 | $CONN ? stop_game |
1155 | $CONN ? stop_game |
… | |
… | |
1191 | |
1168 | |
1192 | sub client_setup { |
1169 | sub client_setup { |
1193 | my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]; |
1170 | my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]; |
1194 | |
1171 | |
1195 | my $row = 0; |
1172 | 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 | |
1173 | |
1210 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); |
1174 | $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 |
1175 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
1212 | state => $CFG->{show_tips}, |
1176 | state => $CFG->{show_tips}, |
1213 | tooltip => "Show the <b>Tip of the day</b> window at startup?", |
1177 | 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 " |
1188 | 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 " |
1189 | . "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.", |
1190 | . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", |
1227 | on_changed => sub { |
1191 | on_changed => sub { |
1228 | my ($self, $value) = @_; |
1192 | my ($self, $value) = @_; |
1229 | $LOGVIEW->{max_par} = $CFG->{logview_max_par} = $value*1; |
1193 | $MESSAGE_WINDOW->set_max_para ($CFG->{logview_max_par} = $value*1); |
1230 | 0 |
1194 | 0 |
1231 | }, |
1195 | }, |
1232 | ); |
1196 | ); |
1233 | |
1197 | |
1234 | $table |
1198 | $table |
1235 | } |
|
|
1236 | |
|
|
1237 | sub 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 | } |
1199 | } |
1299 | |
1200 | |
1300 | sub autopickup_setup { |
1201 | sub autopickup_setup { |
1301 | my $r = new CFPlus::UI::ScrolledWindow ( |
1202 | my $r = new CFPlus::UI::ScrolledWindow ( |
1302 | expand => 1, |
1203 | expand => 1, |
… | |
… | |
1488 | |
1389 | |
1489 | my $ntb = |
1390 | my $ntb = |
1490 | $PL_NOTEBOOK = |
1391 | $PL_NOTEBOOK = |
1491 | new CFPlus::UI::Notebook expand => 1; |
1392 | new CFPlus::UI::Notebook expand => 1; |
1492 | |
1393 | |
1493 | $ntb->add ( |
1394 | $ntb->add_tab ( |
1494 | "Statistics (F2)" => $STATS_PAGE = stats_window, |
1395 | "Statistics (F2)" => $STATS_PAGE = stats_window, |
1495 | "Shows statistics, where all your Stats and Resistances are shown." |
1396 | "Shows statistics, where all your Stats and Resistances are shown." |
1496 | ); |
1397 | ); |
1497 | $ntb->add ( |
1398 | $ntb->add_tab ( |
1498 | "Skills (F3)" => $SKILL_PAGE = skill_window, |
1399 | "Skills (F3)" => $SKILL_PAGE = skill_window, |
1499 | "Shows all your Skills." |
1400 | "Shows all your Skills." |
1500 | ); |
1401 | ); |
1501 | |
1402 | |
1502 | my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); |
1403 | my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); |
1503 | $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList); |
1404 | $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList); |
1504 | $ntb->add ( |
1405 | $ntb->add_tab ( |
1505 | "Spellbook (F4)" => $spellsw, |
1406 | "Spellbook (F4)" => $spellsw, |
1506 | "Displays all spells you have and lets you edit keyboard shortcuts for them." |
1407 | "Displays all spells you have and lets you edit keyboard shortcuts for them." |
1507 | ); |
1408 | ); |
1508 | $ntb->add ( |
1409 | $ntb->add_tab ( |
1509 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1410 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1510 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1411 | "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." |
1412 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1512 | ); |
1413 | ); |
1513 | $ntb->add (Pickup => autopickup_setup, |
1414 | $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."); |
1415 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1515 | |
1416 | |
1516 | $ntb->set_current_page ($INVENTORY_PAGE); |
1417 | $ntb->set_current_page ($INVENTORY_PAGE); |
1517 | |
1418 | |
1518 | $plwin->add ($ntb); |
1419 | $plwin->add ($ntb); |
… | |
… | |
1801 | |
1702 | |
1802 | $MAPWIDGET = new CFPlus::MapWidget; |
1703 | $MAPWIDGET = new CFPlus::MapWidget; |
1803 | $MAPWIDGET->connect (activate_console => sub { |
1704 | $MAPWIDGET->connect (activate_console => sub { |
1804 | my ($mapwidget, $preset) = @_; |
1705 | my ($mapwidget, $preset) = @_; |
1805 | |
1706 | |
1806 | if ($CONSOLE) { |
1707 | $MESSAGE_WINDOW->activate_console ($preset) |
1807 | $CONSOLE->{input}->{auto_activated} = 1; |
1708 | 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 | }); |
1709 | }); |
1815 | $MAPWIDGET->show; |
1710 | $MAPWIDGET->show; |
1816 | $MAPWIDGET->grab_focus; |
1711 | $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 | |
1712 | |
1829 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
1713 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
1830 | title => "Setup", |
1714 | title => "Setup", |
1831 | name => "setup_dialog", |
1715 | name => "setup_dialog", |
1832 | x => 'center', |
1716 | x => 'center', |
… | |
… | |
1836 | force_h => $::HEIGHT * 0.6, |
1720 | force_h => $::HEIGHT * 0.6, |
1837 | has_close_button => 1, |
1721 | has_close_button => 1, |
1838 | ; |
1722 | ; |
1839 | |
1723 | |
1840 | $METASERVER = metaserver_dialog; |
1724 | $METASERVER = metaserver_dialog; |
|
|
1725 | $MESSAGE_WINDOW = new CFPlus::UI::MessageWindow; |
1841 | |
1726 | |
1842 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, |
1727 | $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, |
1843 | filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1728 | filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1844 | |
1729 | |
1845 | $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, |
1730 | $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup, |
1846 | "Configure the server to play on, your username, password and other server-related options."); |
1731 | "Configure the server to play on, your username, password and other server-related options."); |
1847 | $SETUP_NOTEBOOK->add (Client => client_setup, |
1732 | $SETUP_NOTEBOOK->add_tab (Client => client_setup, |
1848 | "Configure various client-specific settings."); |
1733 | "Configure various client-specific settings."); |
1849 | $SETUP_NOTEBOOK->add (Graphics => graphics_setup, |
1734 | $SETUP_NOTEBOOK->add_tab (Graphics => graphics_setup, |
1850 | "Configure the video mode, performance, fonts and other graphical aspects of the game."); |
1735 | "Configure the video mode, performance, fonts and other graphical aspects of the game."); |
1851 | $SETUP_NOTEBOOK->add (Audio => audio_setup, |
1736 | $SETUP_NOTEBOOK->add_tab (Audio => audio_setup, |
1852 | "Configure the use of audio, sound effects and background music."); |
1737 | "Configure the use of audio, sound effects and background music."); |
1853 | $SETUP_NOTEBOOK->add (Keyboard => $SETUP_KEYBOARD = keyboard_setup, |
1738 | $SETUP_NOTEBOOK->add_tab (Keyboard => $SETUP_KEYBOARD = keyboard_setup, |
1854 | "Lets you define, edit and delete key bindings." |
1739 | "Lets you define, edit and delete key bindings." |
1855 | . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor " |
1740 | . "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 " |
1741 | . "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. " |
1742 | . "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 " |
1743 | . "After pressing the combo the binding will be saved automatically and the " |
1859 | . "binding editor closes"); |
1744 | . "binding editor closes"); |
1860 | $SETUP_NOTEBOOK->add (Debug => debug_setup, |
1745 | $SETUP_NOTEBOOK->add_tab (Debug => debug_setup, |
1861 | "Some debuggin' options. Do not ask."); |
1746 | "Some debuggin' options. Do not ask."); |
1862 | |
1747 | |
1863 | $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top |
1748 | $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top |
1864 | |
1749 | |
1865 | $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG, |
1750 | $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."); |
1751 | tooltip => "Toggles a dialog where you can configure all aspects of this client."); |
1867 | |
1752 | |
1868 | $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW = message_window, |
1753 | $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."); |
1754 | tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); |
1870 | |
1755 | |
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 |
1756 | 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 | |
1757 | |
1873 | $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window, |
1758 | $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window, |
… | |
… | |
1906 | } |
1791 | } |
1907 | |
1792 | |
1908 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
1793 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
1909 | } |
1794 | } |
1910 | |
1795 | |
1911 | sub 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 | |
|
|
1932 | sub 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 | |
|
|
1986 | sub 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 | |
|
|
2030 | sub video_shutdown { |
1796 | sub video_shutdown { |
2031 | CFPlus::OpenGL::shutdown; |
1797 | CFPlus::OpenGL::shutdown; |
2032 | |
1798 | |
2033 | undef $SDL_ACTIVE; |
1799 | undef $SDL_ACTIVE; |
2034 | } |
1800 | } |
… | |
… | |
2052 | &audio_music_changed (); |
1818 | &audio_music_changed (); |
2053 | } |
1819 | } |
2054 | } |
1820 | } |
2055 | |
1821 | |
2056 | sub audio_music_start { |
1822 | sub audio_music_start { |
2057 | my $path = $MUSIC_PLAYING->{path} |
1823 | my $meta = $MUSIC_PLAYING_META; |
2058 | or return; |
|
|
2059 | |
1824 | |
2060 | CFPlus::DB::prefetch_file $path, 1024_000, sub { |
1825 | CFPlus::DB::get res_data => $meta->{name}, sub { |
|
|
1826 | return unless $SDL_MIXER; |
|
|
1827 | |
2061 | # music might have changed... |
1828 | # music might have changed... |
2062 | $path eq $MUSIC_PLAYING->{path} |
1829 | $meta eq $MUSIC_PLAYING_META |
2063 | or return &audio_music_start (); |
1830 | or return &audio_music_start (); |
2064 | |
1831 | |
|
|
1832 | $MUSIC_PLAYING_DATA = \$_[0]; |
|
|
1833 | |
|
|
1834 | my $rwops = $meta->{path} |
|
|
1835 | ? new_from_file CFPlus::RW $meta->{path} |
|
|
1836 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
|
|
1837 | |
2065 | $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; |
1838 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
|
|
1839 | or ((warn CFPlus::Mix_GetError), return); # pretty fatal error |
2066 | |
1840 | |
2067 | my $NOW = time; |
1841 | my $NOW = time; |
2068 | |
1842 | |
2069 | if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { |
1843 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
2070 | my $pos = $MUSIC_PLAYING->{stop_pos}; |
1844 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
2071 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
1845 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
2072 | $MUSIC_START = time - $pos; |
1846 | $MUSIC_START = time - $pos; |
2073 | } else { |
1847 | } else { |
2074 | $MUSIC_PLAYER->play (0); |
1848 | $MUSIC_PLAYER->play (0); |
2075 | $MUSIC_START = time; |
1849 | $MUSIC_START = time; |
2076 | } |
1850 | } |
2077 | |
1851 | |
2078 | delete $MUSIC_PLAYING->{stop_time}; |
1852 | delete $MUSIC_PLAYING_META->{stop_time}; |
2079 | delete $MUSIC_PLAYING->{stop_pos}; |
1853 | delete $MUSIC_PLAYING_META->{stop_pos}; |
2080 | } |
1854 | } |
2081 | } |
1855 | } |
2082 | |
1856 | |
2083 | sub audio_music_changed { |
1857 | sub audio_music_changed { |
2084 | return unless $CFG->{bgm_enable}; |
1858 | return unless $CFG->{bgm_enable}; |
|
|
1859 | return unless $SDL_MIXER; |
2085 | |
1860 | |
2086 | # default MUSIC_WANT == MUSIC_DEFAULT |
1861 | # default MUSIC_WANT == MUSIC_DEFAULT |
2087 | @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; |
1862 | @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; |
2088 | |
1863 | |
2089 | # if the currently playing song is acceptable, let it continue |
1864 | # if the currently playing song is acceptable, let it continue |
2090 | return if $MUSIC_PLAYING |
1865 | return if $MUSIC_PLAYING_META |
2091 | && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; |
1866 | && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT; |
2092 | |
1867 | |
2093 | my $NOW = time; |
1868 | my $NOW = time; |
2094 | |
1869 | |
2095 | if ($MUSIC_PLAYING) { |
1870 | if ($MUSIC_PLAYING_META) { |
2096 | $MUSIC_PLAYING->{stop_time} = $NOW; |
1871 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
2097 | $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; |
1872 | $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START; |
2098 | CFPlus::MixMusic::fade_out 1000; |
1873 | CFPlus::MixMusic::fade_out 1000; |
2099 | } else { |
1874 | } else { |
2100 | # sort by stop time, oldest first |
1875 | # sort by stop time, oldest first |
2101 | @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; |
1876 | @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; |
2102 | |
1877 | |
2103 | # if the most recently-played piece played very recently, |
1878 | # if the most recently-played piece played very recently, |
2104 | # resume it, else choose the oldest piece for rotation. |
1879 | # resume it, else choose the oldest piece for rotation. |
2105 | $MUSIC_PLAYING = |
1880 | $MUSIC_PLAYING_META = |
2106 | $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME |
1881 | $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME |
2107 | ? $MUSIC_WANT[-1] |
1882 | ? $MUSIC_WANT[-1] |
2108 | : $MUSIC_WANT[0]; |
1883 | : $MUSIC_WANT[0]; |
2109 | |
1884 | |
2110 | audio_music_start; |
1885 | audio_music_start; |
2111 | } |
1886 | } |
2112 | } |
1887 | } |
2113 | |
1888 | |
2114 | sub audio_music_finished { |
1889 | sub audio_music_finished { |
2115 | $MUSIC_PLAYING = undef; |
|
|
2116 | undef $MUSIC_PLAYER; |
1890 | undef $MUSIC_PLAYER; |
|
|
1891 | undef $MUSIC_PLAYING_META; |
|
|
1892 | undef $MUSIC_PLAYING_DATA; |
2117 | |
1893 | |
2118 | audio_music_changed; |
1894 | audio_music_changed; |
2119 | } |
1895 | } |
2120 | |
1896 | |
2121 | sub audio_init { |
1897 | sub audio_init { |
2122 | if ($CFG->{audio_enable}) { |
1898 | if ($CFG->{audio_enable}) { |
2123 | if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { |
1899 | if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { |
|
|
1900 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
2124 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
1901 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
2125 | |
1902 | |
2126 | unless ($SDL_MIXER) { |
1903 | unless ($SDL_MIXER) { |
2127 | status "Unable to open sound device: there will be no sound"; |
1904 | status "Unable to open sound device: there will be no sound"; |
2128 | return; |
1905 | return; |
… | |
… | |
2141 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
1918 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
2142 | |
1919 | |
2143 | push @SOUNDS, "$volume,$file"; |
1920 | push @SOUNDS, "$volume,$file"; |
2144 | |
1921 | |
2145 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
1922 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
2146 | my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file"; |
1923 | my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file"; |
|
|
1924 | my $chunk = new CFPlus::MixChunk $rwops; |
2147 | $chunk->volume ($volume * 128 / 100); |
1925 | $chunk->volume ($volume * 128 / 100); |
2148 | $chunk |
1926 | $chunk |
2149 | }; |
1927 | }; |
2150 | } |
1928 | } |
2151 | } else { |
1929 | } else { |
2152 | status "unable to open sound config: $!"; |
1930 | status "unable to open sound config: $!"; |
2153 | } |
1931 | } |
|
|
1932 | } else { |
|
|
1933 | undef $SDL_MIXER; |
2154 | } |
1934 | } |
2155 | } |
1935 | } |
2156 | |
1936 | |
2157 | sub audio_shutdown { |
1937 | sub audio_shutdown { |
2158 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
1938 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
… | |
… | |
2206 | |
1986 | |
2207 | sub animation_stop { |
1987 | sub animation_stop { |
2208 | my ($widget) = @_; |
1988 | my ($widget) = @_; |
2209 | delete $animate_object{$widget}; |
1989 | delete $animate_object{$widget}; |
2210 | } |
1990 | } |
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 | |
|
|
2216 | Event->timer (after => 1, interval => 0.25, cb => sub { |
|
|
2217 | $CONN->face_prefetch |
|
|
2218 | if $CONN; |
|
|
2219 | }); |
|
|
2220 | |
1991 | |
2221 | %SDL_CB = ( |
1992 | %SDL_CB = ( |
2222 | CFPlus::SDL_QUIT => sub { |
1993 | CFPlus::SDL_QUIT => sub { |
2223 | exit; |
1994 | exit; |
2224 | }, |
1995 | }, |
… | |
… | |
2282 | log_fontsize => 0.7, |
2053 | log_fontsize => 0.7, |
2283 | gauge_fontsize => 1, |
2054 | gauge_fontsize => 1, |
2284 | gauge_size => 0.35, |
2055 | gauge_size => 0.35, |
2285 | stat_fontsize => 0.7, |
2056 | stat_fontsize => 0.7, |
2286 | mapsize => 100, |
2057 | mapsize => 100, |
2287 | say_command => 'chat', |
|
|
2288 | audio_enable => 1, |
2058 | audio_enable => 1, |
2289 | bgm_enable => 1, |
2059 | bgm_enable => 1, |
2290 | bgm_volume => 0.25, |
2060 | bgm_volume => 0.25, |
2291 | face_prefetch => 0, |
|
|
2292 | output_sync => 1, |
2061 | output_sync => 1, |
2293 | output_count => 1, |
2062 | output_count => 1, |
2294 | output_rate => "", |
2063 | output_rate => "", |
2295 | pickup => 0, |
2064 | pickup => 0, |
2296 | inv_sort => "mtime", |
2065 | inv_sort => "mtime", |