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.179 by root, Sat Jul 21 13:02:07 2007 UTC vs.
Revision 1.184 by root, Mon Jul 23 15:30:46 2007 UTC

82use CFPlus; 82use CFPlus;
83use CFPlus::OpenGL (); 83use CFPlus::OpenGL ();
84use CFPlus::Protocol; 84use CFPlus::Protocol;
85use CFPlus::DB; 85use CFPlus::DB;
86use CFPlus::UI; 86use CFPlus::UI;
87use CFPlus::UI::Canvas;
87use CFPlus::UI::Inventory; 88use CFPlus::UI::Inventory;
88use CFPlus::UI::SpellList; 89use CFPlus::UI::SpellList;
90use CFPlus::UI::MessageWindow;
89use CFPlus::Pod; 91use CFPlus::Pod;
90use CFPlus::MapWidget; 92use CFPlus::MapWidget;
91use CFPlus::Macro; 93use CFPlus::Macro;
92 94
93$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 95$SIG{QUIT} = sub { Carp::cluck "QUIT" };
125 127
126our $MAP; 128our $MAP;
127our $MAPMAP; 129our $MAPMAP;
128our $MAPWIDGET; 130our $MAPWIDGET;
129our $BUTTONBAR; 131our $BUTTONBAR;
130our $LOGVIEW;
131our $CONSOLE;
132our $METASERVER; 132our $METASERVER;
133our $LOGIN_BUTTON; 133our $LOGIN_BUTTON;
134our $QUIT_DIALOG; 134our $QUIT_DIALOG;
135our $HOST_ENTRY; 135our $HOST_ENTRY;
136our $FULLSCREEN_ENABLE; 136our $FULLSCREEN_ENABLE;
191 $DEBUG_STATUS->set_text ($_[0]); 191 $DEBUG_STATUS->set_text ($_[0]);
192} 192}
193 193
194sub message { 194sub message {
195 my ($para) = @_; 195 my ($para) = @_;
196 196 $MESSAGE_WINDOW->message ($para);
197 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
198
199 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
200
201 $LOGVIEW->add_paragraph ($para);
202 $LOGVIEW->scroll_to_bottom;
203} 197}
204 198
205sub destroy_query_dialog { 199sub destroy_query_dialog {
206 (delete $_[0]{query_dialog})->destroy 200 (delete $_[0]{query_dialog})->destroy
207 if $_[0]{query_dialog}; 201 if $_[0]{query_dialog};
460 maph => $mapsize, 454 maph => $mapsize,
461 455
462 client => "cfplus $CFPlus::VERSION $] $^O", 456 client => "cfplus $CFPlus::VERSION $] $^O",
463 457
464 map_widget => $MAPWIDGET, 458 map_widget => $MAPWIDGET,
465 logview => $LOGVIEW,
466 statusbox => $STATUSBOX, 459 statusbox => $STATUSBOX,
467 map => $MAP, 460 map => $MAP,
468 mapmap => $MAPMAP, 461 mapmap => $MAPMAP,
469 query => \&server_query, 462 query => \&server_query,
470 463
613 606
614 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); 607 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
615 $table->add_at (1, $row++, new CFPlus::UI::Slider 608 $table->add_at (1, $row++, new CFPlus::UI::Slider
616 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], 609 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
617 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", 610 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.",
618 on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, 611 on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
619 ); 612 );
620 613
621 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 614 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
622 $table->add_at (1, $row++, new CFPlus::UI::Slider 615 $table->add_at (1, $row++, new CFPlus::UI::Slider
623 range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1], 616 range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1],
752 $table->add_at (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); 745 $table->add_at (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
753 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); 746 $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
754 747
755 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# 748 $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
756 749
757 $table->add_at (7,7, my $t = new CFPlus::UI::Table); 750 $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
758 $t->add_at (0,0, new CFPlus::UI::Label text => "a", rowspan => 1, colspan => 2); 751 $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2);
759 $t->add_at (2,0, new CFPlus::UI::Label text => "b", rowspan => 2, colspan => 1); 752 $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1);
760 $t->add_at (1,2, new CFPlus::UI::Label text => "c", rowspan => 1, colspan => 2); 753 $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2);
761 $t->add_at (0,1, new CFPlus::UI::Label text => "d", rowspan => 2, colspan => 1); 754 $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1);
762 $t->add_at (1,1, new CFPlus::UI::Label text => "e"); 755 $t->add_at (1,1, new CFPlus::UI::Label text => "e");
756
757 $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
758
759 $c->add_items ({
760 type => "line_loop",
761 color => [0, 1, 0],
762 width => 9,
763 coord_mode => "abs",
764 coord => [[10, 5], [5, 50], [20, 5], [5, 60]],
765 });
766
767 $c->add_items ({
768 type => "lines",
769 color => [1, 1, 0],
770 width => 2,
771 coord_mode => "rel",
772 coord => [[0,0], [1,1], [1,0], [0,1]],
773 });
774
775 $c->add_items ({
776 type => "polygon",
777 color => [0, 0.43, 0],
778 width => 2,
779 coord_mode => "rel",
780 coord => [[0,0.2], [1,.4], [1,.6], [0,.8]],
781 });
763 782
764 $table 783 $table
765} 784}
766 785
767sub stats_window { 786sub stats_window {
1197 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server " 1216 tooltip => "This is maximum number of messages remembered in the <b>Messages</b> window. If the server "
1198 . "sends more messages than this number, older messages get removed to save memory and " 1217 . "sends more messages than this number, older messages get removed to save memory and "
1199 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", 1218 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1200 on_changed => sub { 1219 on_changed => sub {
1201 my ($self, $value) = @_; 1220 my ($self, $value) = @_;
1202 $LOGVIEW->{max_par} = $CFG->{logview_max_par} = $value*1; 1221 $MESSAGE_WINDOW->set_max_para ($CFG->{logview_max_par} = $value*1);
1203 0 1222 0
1204 }, 1223 },
1205 ); 1224 );
1206 1225
1207 $table 1226 $table
1208}
1209
1210sub message_window {
1211 my $window = new CFPlus::UI::Toplevel
1212 name => "message_window",
1213 title => "Messages",
1214 border_bg => [1, 1, 1, 1],
1215 x => "max",
1216 y => 0,
1217 force_w => $::WIDTH * 0.4,
1218 force_h => $::HEIGHT * 0.5,
1219 child => (my $vbox = new CFPlus::UI::VBox),
1220 has_close_button => 1;
1221
1222 $vbox->add ($LOGVIEW);
1223
1224 $vbox->add (my $input = new CFPlus::UI::Entry
1225 tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
1226 . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
1227 . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
1228 . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
1229 on_focus_in => sub {
1230 my ($input, $prev_focus) = @_;
1231
1232 delete $input->{refocus_map};
1233
1234 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
1235 $input->{refocus_map} = 1;
1236 }
1237 delete $input->{auto_activated};
1238
1239 0
1240 },
1241 on_activate => sub {
1242 my ($input, $text) = @_;
1243 $input->set_text ('');
1244
1245 if ($text =~ /^\/(.*)/) {
1246 $::CONN->user_send ($1);
1247 } else {
1248 my $say_cmd = $::CFG->{say_command} || 'say';
1249 $::CONN->user_send ("$say_cmd $text");
1250 }
1251 if ($input->{refocus_map}) {
1252 delete $input->{refocus_map};
1253 $MAPWIDGET->focus_in
1254 }
1255
1256 0
1257 },
1258 on_escape => sub {
1259 $MAPWIDGET->grab_focus;
1260
1261 0
1262 },
1263 );
1264
1265 $CONSOLE = {
1266 window => $window,
1267 input => $input,
1268 };
1269
1270 $window
1271} 1227}
1272 1228
1273sub autopickup_setup { 1229sub autopickup_setup {
1274 my $r = new CFPlus::UI::ScrolledWindow ( 1230 my $r = new CFPlus::UI::ScrolledWindow (
1275 expand => 1, 1231 expand => 1,
1461 1417
1462 my $ntb = 1418 my $ntb =
1463 $PL_NOTEBOOK = 1419 $PL_NOTEBOOK =
1464 new CFPlus::UI::Notebook expand => 1; 1420 new CFPlus::UI::Notebook expand => 1;
1465 1421
1466 $ntb->add ( 1422 $ntb->add_tab (
1467 "Statistics (F2)" => $STATS_PAGE = stats_window, 1423 "Statistics (F2)" => $STATS_PAGE = stats_window,
1468 "Shows statistics, where all your Stats and Resistances are shown." 1424 "Shows statistics, where all your Stats and Resistances are shown."
1469 ); 1425 );
1470 $ntb->add ( 1426 $ntb->add_tab (
1471 "Skills (F3)" => $SKILL_PAGE = skill_window, 1427 "Skills (F3)" => $SKILL_PAGE = skill_window,
1472 "Shows all your Skills." 1428 "Shows all your Skills."
1473 ); 1429 );
1474 1430
1475 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); 1431 my $spellsw = $SPELL_PAGE = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1);
1476 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList); 1432 $spellsw->add ($SPELL_LIST = new CFPlus::UI::SpellList);
1477 $ntb->add ( 1433 $ntb->add_tab (
1478 "Spellbook (F4)" => $spellsw, 1434 "Spellbook (F4)" => $spellsw,
1479 "Displays all spells you have and lets you edit keyboard shortcuts for them." 1435 "Displays all spells you have and lets you edit keyboard shortcuts for them."
1480 ); 1436 );
1481 $ntb->add ( 1437 $ntb->add_tab (
1482 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1438 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1483 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1439 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1484 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1440 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1485 ); 1441 );
1486 $ntb->add (Pickup => autopickup_setup, 1442 $ntb->add_tab (Pickup => autopickup_setup,
1487 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1443 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1488 1444
1489 $ntb->set_current_page ($INVENTORY_PAGE); 1445 $ntb->set_current_page ($INVENTORY_PAGE);
1490 1446
1491 $plwin->add ($ntb); 1447 $plwin->add ($ntb);
1774 1730
1775 $MAPWIDGET = new CFPlus::MapWidget; 1731 $MAPWIDGET = new CFPlus::MapWidget;
1776 $MAPWIDGET->connect (activate_console => sub { 1732 $MAPWIDGET->connect (activate_console => sub {
1777 my ($mapwidget, $preset) = @_; 1733 my ($mapwidget, $preset) = @_;
1778 1734
1779 if ($CONSOLE) { 1735 $MESSAGE_WINDOW->activate_console ($preset)
1780 $CONSOLE->{input}->{auto_activated} = 1; 1736 if $MESSAGE_WINDOW;
1781 $CONSOLE->{input}->grab_focus;
1782
1783 if ($preset && $CONSOLE->{input}->get_text eq '') {
1784 $CONSOLE->{input}->set_text ($preset);
1785 }
1786 }
1787 }); 1737 });
1788 $MAPWIDGET->show; 1738 $MAPWIDGET->show;
1789 $MAPWIDGET->grab_focus; 1739 $MAPWIDGET->grab_focus;
1790
1791 $LOGVIEW = new CFPlus::UI::TextScroller
1792 expand => 1,
1793 font => $FONT_FIXED,
1794 fontsize => $::CFG->{log_fontsize},
1795 indent => -4,
1796 can_hover => 1,
1797 can_events => 1,
1798 max_par => $CFG->{logview_max_par},
1799 tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
1800 ;
1801 1740
1802 $SETUP_DIALOG = new CFPlus::UI::Toplevel 1741 $SETUP_DIALOG = new CFPlus::UI::Toplevel
1803 title => "Setup", 1742 title => "Setup",
1804 name => "setup_dialog", 1743 name => "setup_dialog",
1805 x => 'center', 1744 x => 'center',
1809 force_h => $::HEIGHT * 0.6, 1748 force_h => $::HEIGHT * 0.6,
1810 has_close_button => 1, 1749 has_close_button => 1,
1811 ; 1750 ;
1812 1751
1813 $METASERVER = metaserver_dialog; 1752 $METASERVER = metaserver_dialog;
1753 $MESSAGE_WINDOW = new CFPlus::UI::MessageWindow;
1814 1754
1815 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, 1755 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1,
1816 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); 1756 filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
1817 1757
1818 $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, 1758 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
1819 "Configure the server to play on, your username, password and other server-related options."); 1759 "Configure the server to play on, your username, password and other server-related options.");
1820 $SETUP_NOTEBOOK->add (Client => client_setup, 1760 $SETUP_NOTEBOOK->add_tab (Client => client_setup,
1821 "Configure various client-specific settings."); 1761 "Configure various client-specific settings.");
1822 $SETUP_NOTEBOOK->add (Graphics => graphics_setup, 1762 $SETUP_NOTEBOOK->add_tab (Graphics => graphics_setup,
1823 "Configure the video mode, performance, fonts and other graphical aspects of the game."); 1763 "Configure the video mode, performance, fonts and other graphical aspects of the game.");
1824 $SETUP_NOTEBOOK->add (Audio => audio_setup, 1764 $SETUP_NOTEBOOK->add_tab (Audio => audio_setup,
1825 "Configure the use of audio, sound effects and background music."); 1765 "Configure the use of audio, sound effects and background music.");
1826 $SETUP_NOTEBOOK->add (Keyboard => $SETUP_KEYBOARD = keyboard_setup, 1766 $SETUP_NOTEBOOK->add_tab (Keyboard => $SETUP_KEYBOARD = keyboard_setup,
1827 "Lets you define, edit and delete key bindings." 1767 "Lets you define, edit and delete key bindings."
1828 . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor " 1768 . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor "
1829 . "with nothing set and the recording started. After doing the actions you " 1769 . "with nothing set and the recording started. After doing the actions you "
1830 . "want to record press <b>Insert</b> and you will be asked to press a key-combo. " 1770 . "want to record press <b>Insert</b> and you will be asked to press a key-combo. "
1831 . "After pressing the combo the binding will be saved automatically and the " 1771 . "After pressing the combo the binding will be saved automatically and the "
1832 . "binding editor closes"); 1772 . "binding editor closes");
1833 $SETUP_NOTEBOOK->add (Debug => debug_setup, 1773 $SETUP_NOTEBOOK->add_tab (Debug => debug_setup,
1834 "Some debuggin' options. Do not ask."); 1774 "Some debuggin' options. Do not ask.");
1835 1775
1836 $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top 1776 $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top
1837 1777
1838 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG, 1778 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
1839 tooltip => "Toggles a dialog where you can configure all aspects of this client."); 1779 tooltip => "Toggles a dialog where you can configure all aspects of this client.");
1840 1780
1841 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW = message_window, 1781 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
1842 tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server."); 1782 tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
1843 1783
1844 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 1784 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
1845 1785
1846 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window, 1786 $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window,
2029sub audio_music_start { 1969sub audio_music_start {
2030 my $path = $MUSIC_PLAYING->{path} 1970 my $path = $MUSIC_PLAYING->{path}
2031 or return; 1971 or return;
2032 1972
2033 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1973 CFPlus::DB::prefetch_file $path, 1024_000, sub {
1974 return unless $SDL_MIXER;
1975
2034 # music might have changed... 1976 # music might have changed...
2035 $path eq $MUSIC_PLAYING->{path} 1977 $path eq $MUSIC_PLAYING->{path}
2036 or return &audio_music_start (); 1978 or return &audio_music_start ();
2037 1979
2038 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; 1980 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path;
2053 } 1995 }
2054} 1996}
2055 1997
2056sub audio_music_changed { 1998sub audio_music_changed {
2057 return unless $CFG->{bgm_enable}; 1999 return unless $CFG->{bgm_enable};
2000 return unless $SDL_MIXER;
2058 2001
2059 # default MUSIC_WANT == MUSIC_DEFAULT 2002 # default MUSIC_WANT == MUSIC_DEFAULT
2060 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 2003 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
2061 2004
2062 # if the currently playing song is acceptable, let it continue 2005 # if the currently playing song is acceptable, let it continue
2122 }; 2065 };
2123 } 2066 }
2124 } else { 2067 } else {
2125 status "unable to open sound config: $!"; 2068 status "unable to open sound config: $!";
2126 } 2069 }
2070 } else {
2071 undef $SDL_MIXER;
2127 } 2072 }
2128} 2073}
2129 2074
2130sub audio_shutdown { 2075sub audio_shutdown {
2131 CFPlus::Mix_CloseAudio if $SDL_MIXER; 2076 CFPlus::Mix_CloseAudio if $SDL_MIXER;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines