ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/deliantra (file contents):
Revision 1.78 by root, Tue Sep 30 03:05:07 2008 UTC vs.
Revision 1.94 by root, Sun Mar 29 22:28:13 2009 UTC

17 $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp"); 17 $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp");
18 } 18 }
19 19
20 require Win32::GUI::SplashScreen; 20 require Win32::GUI::SplashScreen;
21 21
22 # initialise the resolver now, as vista forces us back to the desktop
23 # when doing this.
24 use AnyEvent::DNS ();
25 AnyEvent::DNS::resolver;
26
22 Win32::GUI::SplashScreen::Show ( 27 Win32::GUI::SplashScreen::Show (
23 -file => "$ENV{PAR_TEMP}/SPLASH.bmp", 28 -file => "$ENV{PAR_TEMP}/SPLASH.bmp",
24 ); 29 );
25 30
26 $startup_done = sub { 31 $startup_done = sub {
51 56
52 if ($^O eq "MSWin32") { 57 if ($^O eq "MSWin32") {
53 # pango is relocatable on win32 58 # pango is relocatable on win32
54 } else { 59 } else {
55 # OS X 60 # OS X
56 $ENV{FONTCONFIG_FILE} = "$root/fonts.conf"; # no effect??!?!
57 $ENV{FONTCONFIG_DIR} = $root; # no effect??!?!
58 $ENV{PANGO_RC_FILE} = "$root/pango.rc"; 61 $ENV{PANGO_RC_FILE} = "$root/pango.rc";
59 $ENV{DYLD_LIBRARY_PATH} = $root; 62 $ENV{DYLD_LIBRARY_PATH} = $root;
60 chdir $root; # for pango modules, maybe other things 63 chdir $root; # for pango modules, maybe other things
61 } 64 }
62 65
63 unshift @INC, $root; 66 unshift @INC, $root;
64 } 67 }
65} 68}
66 69
67# prepend private library directory 70# prepend private library directory and prepare env
68BEGIN { 71BEGIN {
69 for (grep !ref, @INC) { 72 for (grep !ref, @INC) {
70 my $path = "$_/Deliantra/Client/private"; 73 my $path = "$_/Deliantra/Client/private";
71 if (-d $path) { 74 if (-d $path) {
72 unshift @INC, $path; 75 unshift @INC, $path;
86 89
87use Deliantra; 90use Deliantra;
88use Deliantra::Protocol::Constants; 91use Deliantra::Protocol::Constants;
89 92
90use AnyEvent::Util (); 93use AnyEvent::Util ();
91use AnyEvent::DNS;
92use AnyEvent::Socket (); 94use AnyEvent::Socket ();
95use AnyEvent::DNS ();
93 96
94use Compress::LZF; 97use Compress::LZF;
95use JSON::XS; 98use JSON::XS;
96 99
97use DC; 100use DC;
125 128
126$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 129$SIG{QUIT} = sub { Carp::cluck "QUIT" };
127$SIG{PIPE} = 'IGNORE'; 130$SIG{PIPE} = 'IGNORE';
128 131
129$EV::DIED = sub { 132$EV::DIED = sub {
130 crash "CRASH/EV::DIED: $@" => 1; 133 crash "CRASH/EV::DIED: $@" => 0;
131 DC::fatal Carp::longmess $@; 134 DC::fatal Carp::longmess $@;
132}; 135};
133 136
134my $MAX_FPS = 60; 137my $MAX_FPS = 60;
135 138
161 164
162our $MAP; 165our $MAP;
163our $MAPMAP; 166our $MAPMAP;
164our $MAPWIDGET; 167our $MAPWIDGET;
165our $COMPLETER; 168our $COMPLETER;
166our $BUTTONBAR; 169our $MENUFRAME; # the rectangle at the top
170our $MENUBAR; # the hbox at the top
171our $MENUPOPUP;
172our $BUTTONBAR; # the menu buttons
167our $METASERVER; 173our $METASERVER;
168our $LOGIN_BUTTON; 174our $LOGIN_BUTTON;
169our $QUIT_DIALOG; 175our $QUIT_DIALOG;
170our $HOST_ENTRY; 176our $HOST_ENTRY;
171our $FULLSCREEN_ENABLE; 177our $FULLSCREEN_ENABLE;
197our $FLOORBOX; 203our $FLOORBOX;
198our $GAUGES; 204our $GAUGES;
199our $STATWIDS; 205our $STATWIDS;
200 206
201our $SDL_ACTIVE; 207our $SDL_ACTIVE;
202our %SDL_CB; 208our @SDL_CB;
203 209
204our $ALT_ENTER_MESSAGE; 210our $ALT_ENTER_MESSAGE;
205our $STATUSBOX; 211our $STATUSBOX;
206our $MODBOX; 212our $MODBOX;
207our $DEBUG_STATUS; 213our $DEBUG_STATUS;
215# write a crash message blockingly to the socket, if possible 221# write a crash message blockingly to the socket, if possible
216# this is a bit too complicated for my tastes, but it was easy. 222# this is a bit too complicated for my tastes, but it was easy.
217*crash = sub($;$) { 223*crash = sub($;$) {
218 my ($msg, $backtrace) = @_; 224 my ($msg, $backtrace) = @_;
219 225
226 warn $msg;
227
220 return unless $CONN; 228 return unless $CONN;
221 229
222 my $fh = $CONN->{fh} 230 my $fh = $CONN->{fh}
223 or return; 231 or return;
224 232
234 242
235 # backtrace as second step, in case it crashes, too 243 # backtrace as second step, in case it crashes, too
236 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 244 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated"
237 if $backtrace; 245 if $backtrace;
238}; 246};
247
248sub clienterror($;$) {
249 my ($msg, $backtrace) = @_;
250
251 warn $msg;
252
253 return unless $CONN;
254
255 $CONN->send_exti_msg (clientlog => $msg);
256 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace;
257}
239 258
240############################################################################# 259#############################################################################
241 260
242sub status { 261sub status {
243 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 262 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
325 or return; 344 or return;
326 345
327 $meta->{data} 346 $meta->{data}
328 or return; 347 or return;
329 348
330 # if its a jingle, play it as ambient music 349 # if it's a jingle, play it as ambient music
331 if ($meta->{data}{jingle}) { 350 if ($meta->{data}{jingle}) {
332 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue 351 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
333 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 352 push @MUSIC_JINGLE, $meta; # push it unto the music/jingle queue
334 &audio_music_push ($face); 353 &audio_music_push ($face);
335 } 354 }
336 } else { 355 } else {
337 # fetch from database 356 # fetch from database
338 DC::DB::get res_data => $meta->{name}, sub { 357 DC::DB::get res_data => $meta->{name}, sub {
339 my $rwops = new DC::RW $_[0]; 358 my $rwops = new DC::RW $_[0];
340 my $chunk = new DC::MixChunk $rwops 359 my $chunk = new DC::MixChunk $rwops
341 or Carp::confess "sound face " . (JSON::XS::encode_json $meta) . " unloadable: " . DC::Mix_GetError; 360 or Carp::confess "sound face " . (JSON::XS::encode_json $meta) . " (" . (unpack "H64", $_[0]) . ") unloadable: " . DC::Mix_GetError;
342 $chunk->volume (($meta->{data}{volume} || 1) * 128); 361 $chunk->volume (($meta->{data}{volume} || 1) * 128);
343 $AUDIO_CHUNK{$face} = $chunk; 362 $AUDIO_CHUNK{$face} = $chunk;
344 363
345 audio_sound_push ($face); 364 audio_sound_push ($face);
346 }; 365 };
393 412
394 audio_music_update_volume; 413 audio_music_update_volume;
395 414
396 $MUSIC_PLAYING_DATA = \$_[0]; 415 $MUSIC_PLAYING_DATA = \$_[0];
397 416
417 $meta->{path} or length $_[0]
418 or return clienterror "empty music face from res_data ($meta->{face})";#d#
419
398 my $rwops = $meta->{path} 420 my $rwops = $meta->{path}
399 ? new_from_file DC::RW $meta->{path} 421 ? (new_from_file DC::RW $meta->{path} or return clienterror "unable to load music face $meta->{path}: $!")#d#clienterror
400 : new DC::RW $$MUSIC_PLAYING_DATA; 422 : new DC::RW $$MUSIC_PLAYING_DATA;
401 423
402 $MUSIC_PLAYER = new DC::MixMusic $rwops 424 $MUSIC_PLAYER = new DC::MixMusic $rwops
403 or Carp::confess "music face $meta->{face} unloadable: " . DC::Mix_GetError; 425 or return clienterror "music face $meta->{face} unloadable: " . DC::Mix_GetError => 1;
404 426
405 my $NOW = time; 427 my $NOW = time;
406 428
407 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 429 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
408 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 430 my $pos = $MUSIC_PLAYING_META->{stop_pos};
766} 788}
767 789
768sub dc_connect { 790sub dc_connect {
769 my ($host, $port) = @_; 791 my ($host, $port) = @_;
770 792
771 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 793 my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32;
794 my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
772 795
773 $CONN = 796 $CONN =
774 new DC::Protocol 797 new DC::Protocol
775 host => $host, 798 host => $host,
776 port => $port, 799 port => $port,
777 user => $PROFILE->{user}, 800 user => $PROFILE->{user},
778 pass => $PROFILE->{password}, 801 pass => $PROFILE->{password},
779 mapw => $mapsize, 802 mapw => $mapw,
780 maph => $mapsize, 803 maph => $maph,
781 804
782 client => "$DC::VERSION $] $^O", 805 client => "$DC::VERSION $] $^O",
783 806
784 map_widget => $MAPWIDGET, 807 map_widget => $MAPWIDGET,
785 statusbox => $STATUSBOX, 808 statusbox => $STATUSBOX,
793 816
794 on_connect => sub { 817 on_connect => sub {
795 if ($_[0]) { 818 if ($_[0]) {
796 DC::lowdelay fileno $CONN->{fh}; 819 DC::lowdelay fileno $CONN->{fh};
797 820
798 status "login successful"; 821 status "successfully connected to the server";
799 } else { 822 } else {
800 undef $CONN; 823 undef $CONN;
801 status "unable to connect: $!"; 824 status "unable to connect: $!";
802 stop_game(); 825 stop_game();
803 } 826 }
896 919
897 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode"); 920 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode");
898 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox); 921 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox);
899 922
900 $hbox->add ($MODE_SLIDER = new DC::UI::Slider 923 $hbox->add ($MODE_SLIDER = new DC::UI::Slider
924 c_rescale => 1,
901 force_w => $WIDTH * 0.1, expand => 1, 925 force_w => $WIDTH * 0.1, expand => 1,
902 range => [ ($CFG->{sdl_mode}) x 3 ], 926 range => [ ($CFG->{sdl_mode}) x 3 ],
903 tooltip => $vidmode_tooltip); 927 tooltip => $vidmode_tooltip);
904 $hbox->add (my $mode_label = new DC::UI::Label 928 $hbox->add (my $mode_label = new DC::UI::Label
905 height => 0.8, template => "9999x9999@9+9", 929 height => 0.8, template => "9999x9999@9+9",
933 ); 957 );
934 958
935 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha"); 959 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha");
936 $table->add_at (1, $row++, new DC::UI::CheckBox 960 $table->add_at (1, $row++, new DC::UI::CheckBox
937 state => $CFG->{disable_alpha}, 961 state => $CFG->{disable_alpha},
938 tooltip => "Forbid off the use of the alpha channel. This makes Deliantra look a lot worse " 962 tooltip => "Forbid the use of the alpha channel. This makes Deliantra look a lot worse "
939 . "by disabling a number of textures and transparency effects. Normally, these " 963 . "by disabling a number of textures and transparency effects. Normally, these "
940 . "effects do not cost a lot of resources, but some graphics cards might fall " 964 . "effects do not cost a lot of resources, but some graphics cards might fall "
941 . "back to extremely slow rendering if this is enabled. If disabling this option " 965 . "back to extremely slow rendering if this is enabled. If disabling this option "
942 . "noticably improves the framerate of the client please report this! " 966 . "noticably improves the framerate of the client please report this! "
943 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>", 967 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>",
1229} 1253}
1230 1254
1231sub make_gauge_window { 1255sub make_gauge_window {
1232 my $gh = int $HEIGHT * $CFG->{gauge_size}; 1256 my $gh = int $HEIGHT * $CFG->{gauge_size};
1233 1257
1234 my $win = new DC::UI::Frame ( 1258 $GAUGES->{win} = my $win = new DC::UI::Frame (
1235 force_x => 0, 1259 force_x => 0,
1236 force_y => "max", 1260 force_y => "max",
1237 force_w => $WIDTH, 1261 force_w => $WIDTH,
1238 force_h => $gh, 1262 force_h => $gh,
1239 ); 1263 );
1255 (new DC::UI::Empty expand => 1), 1279 (new DC::UI::Empty expand => 1),
1256 (my $hb = new DC::UI::HBox), 1280 (my $hb = new DC::UI::HBox),
1257 ], 1281 ],
1258 ); 1282 );
1259 1283
1260 $hb->add (my $hg = new DC::UI::Gauge type => 'hp', tooltip => "#stat_health"); 1284 $hb->add ($GAUGES->{hp} = new DC::UI::Gauge type => 'hp', tooltip => "#stat_health");
1261 $hb->add (my $mg = new DC::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 1285 $hb->add ($GAUGES->{mana} = new DC::UI::Gauge type => 'mana', tooltip => "#stat_mana");
1262 $hb->add (my $gg = new DC::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 1286 $hb->add ($GAUGES->{grace} = new DC::UI::Gauge type => 'grace', tooltip => "#stat_grace");
1263 $hb->add (my $fg = new DC::UI::Gauge type => 'food', tooltip => "#stat_food"); 1287 $hb->add ($GAUGES->{food} = new DC::UI::Gauge type => 'food', tooltip => "#stat_food");
1264
1265 $vbox->add (my $exp = new DC::UI::Label align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
1266 $vbox->add (my $prg = new DC::UI::ExperienceProgress);
1267 $vbox->add (my $sklprg = new DC::UI::ExperienceProgress);
1268 $vbox->add (my $rng = new DC::UI::Label align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
1269
1270 $GAUGES = {
1271 exp => $exp, prg => $prg, sklprg => $sklprg,
1272 win => $win, range => $rng,
1273 hp => $hg, mana => $mg, grace => $gg, food => $fg,
1274 };
1275 1288
1276 &set_gauge_window_fontsize; 1289 &set_gauge_window_fontsize;
1277 1290
1278 $win 1291 $win
1279} 1292}
1621 ); 1634 );
1622 1635
1623 $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); 1636 $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username");
1624 $table->add_at (1, 4, new DC::UI::Entry 1637 $table->add_at (1, 4, new DC::UI::Entry
1625 text => $CFG->{profile}{default}{user}, 1638 text => $CFG->{profile}{default}{user},
1626 tooltip => "The name of your character on the server.", 1639 tooltip => "The name of your character on the server. The name is case-sensitive!",
1627 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 } 1640 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1628 ); 1641 );
1629 1642
1630 $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); 1643 $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password");
1631 $table->add_at (1, 5, new DC::UI::Entry 1644 $table->add_at (1, 5, new DC::UI::Entry
1733 1746
1734 my $row = 0; 1747 my $row = 0;
1735 1748
1736 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day"); 1749 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day");
1737 $table->add_at (1, $row++, new DC::UI::CheckBox 1750 $table->add_at (1, $row++, new DC::UI::CheckBox
1751 c_colspan => 2,
1738 state => $CFG->{show_tips}, 1752 state => $CFG->{show_tips},
1739 tooltip => "Show the <b>Tip of the day</b> window at startup?", 1753 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1740 on_changed => sub { 1754 on_changed => sub {
1741 my ($self, $value) = @_; 1755 my ($self, $value) = @_;
1742 $CFG->{show_tips} = $value; 1756 $CFG->{show_tips} = $value;
1744 } 1758 }
1745 ); 1759 );
1746 1760
1747 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); 1761 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size");
1748 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry 1762 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1763 c_colspan => 2,
1749 text => $CFG->{logview_max_par}, 1764 text => $CFG->{logview_max_par},
1750 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " 1765 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server "
1751 . "sends more messages than this number, older messages get removed to save memory and " 1766 . "sends more messages than this number, older messages get removed to save memory and "
1752 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", 1767 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1753 on_changed => sub { 1768 on_changed => sub {
1755 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 1770 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1756 0 1771 0
1757 }, 1772 },
1758 ); 1773 );
1759 1774
1775 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave");
1776 $table->add_at (1, $row, new DC::UI::CheckBox
1777 state => $CFG->{config_autosave},
1778 tooltip => "Normally, configuration settings and the user interface layout "
1779 . "are saved on client exit. You can disable this behaviour by "
1780 . "unchecking this checkbox.",
1781 on_changed => sub {
1782 my ($self, $value) = @_;
1783 $CFG->{config_autosave} = $value;
1784 0
1785 }
1786 );
1787 $table->add_at (2, $row++, new DC::UI::Button
1788 text => "Save Now",
1789 tooltip => "Use this to manually save configuration and UI layout when "
1790 . "autosave is disabled.",
1791 on_activate => sub {
1792 DC::write_cfg;
1793 0
1794 }
1795 );
1796
1760 $table 1797 $table
1761} 1798}
1762 1799
1763sub autopickup_setup { 1800sub autopickup_setup {
1764 my $r = new DC::UI::ScrolledWindow ( 1801 my $r = new DC::UI::ScrolledWindow (
1770 col_expand => [0, 1, 0, 1], 1807 col_expand => [0, 1, 0, 1],
1771 ); 1808 );
1772 1809
1773 for ( 1810 for (
1774 ["General", 0, 0, 1811 ["General", 0, 0,
1775 ["Enable autopickup" => PICKUP_NEWMODE, \$PICKUP_ENABLE],
1776 ["Inhibit autopickup" => PICKUP_INHIBIT], 1812# ["Inhibit autopickup" => PICKUP_INHIBIT],
1777 ["Stop before pickup" => PICKUP_STOP], 1813 ["Stop before pickup" => PICKUP_STOP],
1778 ["Debug autopickup" => PICKUP_DEBUG], 1814 ["Debug autopickup" => PICKUP_DEBUG],
1779 ], 1815 ],
1780 ["Weapons", 0, 6, 1816 ["Weapons", 0, 6,
1781 ["All weapons" => PICKUP_ALLWEAPON], 1817 ["All weapons" => PICKUP_ALLWEAPON],
1829 $::CFG->{pickup} |= $mask; 1865 $::CFG->{pickup} |= $mask;
1830 } else { 1866 } else {
1831 $::CFG->{pickup} &= ~$mask; 1867 $::CFG->{pickup} &= ~$mask;
1832 } 1868 }
1833 1869
1834 $::CONN->send_command ("pickup $::CFG->{pickup}") 1870 $::CONN->send_pickup ($::CFG->{pickup})
1835 if defined $::CONN; 1871 if defined $::CONN;
1836 1872
1837 0 1873 0
1838 }); 1874 });
1839 1875
1856 }); 1892 });
1857 1893
1858 $table->add_at (3, 18, new DC::UI::Button 1894 $table->add_at (3, 18, new DC::UI::Button
1859 text => "set", 1895 text => "set",
1860 on_activate => sub { 1896 on_activate => sub {
1861 $::CONN->send_command ("pickup $::CFG->{pickup}") 1897 $::CONN->send_pickup ($::CFG->{pickup})
1862 if defined $::CONN; 1898 if defined $::CONN;
1863 0 1899 0
1864 }); 1900 });
1865 1901
1866 $r 1902 $r
1979 $PL_NOTEBOOK->set_current_page ($widget); 2015 $PL_NOTEBOOK->set_current_page ($widget);
1980 $PL_WINDOW->show; 2016 $PL_WINDOW->show;
1981 } 2017 }
1982} 2018}
1983 2019
1984sub player_window { 2020sub make_playerbook {
1985 my $plwin = $PL_WINDOW = new DC::UI::Toplevel 2021 my $plwin = $PL_WINDOW = new DC::UI::Toplevel
1986 x => "center", 2022 x => "center",
1987 y => "center", 2023 y => "center",
1988 force_w => $WIDTH * 9/10, 2024 force_w => $WIDTH * 9/10,
1989 force_h => $HEIGHT * 9/10, 2025 force_h => $HEIGHT * 9/10,
2023 "License, Author and Source info for media sent by the server."); 2059 "License, Author and Source info for media sent by the server.");
2024 2060
2025 $ntb->set_current_page ($INVENTORY_PAGE); 2061 $ntb->set_current_page ($INVENTORY_PAGE);
2026 2062
2027 $plwin->add ($ntb); 2063 $plwin->add ($ntb);
2028 $plwin
2029} 2064}
2030 2065
2031sub keyboard_setup { 2066sub keyboard_setup {
2032 DC::Macro::keyboard_setup 2067 DC::Macro::keyboard_setup
2033} 2068}
2034 2069
2035sub help_window { 2070sub make_help_window {
2036 my $win = new DC::UI::Toplevel 2071 my $win = new DC::UI::Toplevel
2037 x => 'center', 2072 x => 'center',
2038 y => 'center', 2073 y => 'center',
2039 z => 4, 2074 z => 4,
2040 name => 'doc_browser', 2075 name => 'doc_browser',
2129 2164
2130 $load_node->((DC::Pod::find @path)[0]); 2165 $load_node->((DC::Pod::find @path)[0]);
2131 $win->show; 2166 $win->show;
2132 }; 2167 };
2133 2168
2134 $win 2169 $HELP_WINDOW = $win;
2135}
2136
2137sub open_string_query {
2138 my ($title, $cb, $txt, $tooltip) = @_;
2139 my $dialog = new DC::UI::Toplevel
2140 x => "center",
2141 y => "center",
2142 z => 50,
2143 force_w => $WIDTH * 4/5,
2144 title => $title;
2145
2146 $dialog->add (
2147 my $e = new DC::UI::Entry
2148 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
2149 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
2150 tooltip => $tooltip
2151 );
2152
2153 $e->grab_focus;
2154 $e->set_text ($txt) if $txt;
2155 $dialog->show;
2156} 2170}
2157 2171
2158sub open_quit_dialog { 2172sub open_quit_dialog {
2159 unless ($QUIT_DIALOG) { 2173 unless ($QUIT_DIALOG) {
2160 $QUIT_DIALOG = new DC::UI::Toplevel 2174 $QUIT_DIALOG = new DC::UI::Toplevel
2193 2207
2194 $QUIT_DIALOG->show; 2208 $QUIT_DIALOG->show;
2195 $QUIT_DIALOG->grab_focus; 2209 $QUIT_DIALOG->grab_focus;
2196} 2210}
2197 2211
2212sub make_menubar {
2213 $MENUFRAME = new DC::UI::Toplevel
2214 border => 0,
2215 force_x => 0,
2216 force_y => 0,
2217 force_w => $::WIDTH,
2218 child => ($MENUBAR = new DC::UI::HBox),
2219 ;
2220
2221 $MENUBAR->add ($BUTTONBAR = new DC::UI::Buttonbar);
2222
2223 # XXX: this has to be done before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
2224 make_gauge_window->show;
2225
2226# $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
2227# tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
2228
2229 make_playerbook;
2230
2231 $MENUPOPUP = DC::UI::Menu->new (items => [
2232 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2233 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2234 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2235 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2236 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2237 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2238 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2239 ["Quit…" , sub {
2240 if ($CONN) {
2241 open_quit_dialog;
2242 } else {
2243 EV::unloop EV::UNLOOP_ALL;
2244 }
2245 }],
2246 ]);
2247
2248 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2249 tooltip => "Shows the main menu",
2250 on_button_down => sub {
2251 my ($self, $ev) = @_;
2252 local $ev->{x} = 0;
2253 local $ev->{y} = 0;
2254 $MENUPOPUP->popup ($ev);
2255 },
2256 );
2257
2258 $MENUBAR->add ($GAUGES->{exp} = new DC::UI::ExperienceProgress
2259 padding_x => 6,
2260 padding_y => 3,
2261 tooltip => "This progress bar shows your overall experience and your progress towards the next character level.",
2262 template => " Exp: 888,888,888,888 (lvl 188) ",
2263 );
2264
2265 $MENUBAR->add ($PICKUP_ENABLE = new DC::UI::CheckBox # checkbox bad, button better?
2266 tooltip => "Automatic Pickup Enable - when this checkbox is enabled, then your character "
2267 . "will automatically pick up items as defined by your item pickup settings "
2268 . "in the playerbook. Often (e.g. in apartments) you want to temporarily "
2269 . "disable autopickup by disabling this checkbox.",
2270 state => $CFG->{pickup} & PICKUP_INHIBIT ? 0 : 1,
2271 on_changed => sub {
2272 my ($self, $value) = @_;
2273 $CFG->{pickup} &= ~PICKUP_INHIBIT;
2274 $CFG->{pickup} |= PICKUP_INHIBIT unless $_[1];
2275 $CONN->send_pickup ($CFG->{pickup})
2276 if $CONN;
2277 },
2278 );
2279
2280 $MENUBAR->add ($GAUGES->{skillexp} = new DC::UI::ExperienceProgress
2281 c_rescale => 1,
2282 padding_x => 6,
2283 padding_y => 3,
2284 force_w => $::WIDTH * 0.2,
2285 tooltip => "This progress bar shows the currently used skill and your progress towards the next skill level of that skill.",
2286 template => "two handed weapons 99%",
2287 );
2288
2289 $MENUBAR->add ($GAUGES->{range} = new DC::UI::Label
2290 expand => 1,
2291 align => 1, can_hover => 1, can_events => 1,
2292 text => "Range and Combat Slots",
2293 tooltip => "#stat_ranged",
2294 );
2295
2296 $MENUFRAME->show;
2297}
2298
2299sub open_string_query {
2300 my ($title, $cb, $txt, $tooltip) = @_;
2301 my $dialog = new DC::UI::Toplevel
2302 x => "center",
2303 y => "center",
2304 z => 50,
2305 force_w => $WIDTH * 4/5,
2306 title => $title;
2307
2308 $dialog->add (
2309 my $e = new DC::UI::Entry
2310 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
2311 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
2312 tooltip => $tooltip
2313 );
2314
2315 $e->grab_focus;
2316 $e->set_text ($txt) if $txt;
2317 $dialog->show;
2318}
2319
2198sub show_tip_of_the_day { 2320sub show_tip_of_the_day {
2199 # find all tips 2321 # find all tips
2200 my @tod = DC::Pod::find tip_of_the_day => "*"; 2322 my @tod = DC::Pod::find tip_of_the_day => "*";
2201 2323
2202 DC::DB::get state => "tip_of_the_day", sub { 2324 DC::DB::get state => "tip_of_the_day", sub {
2341 2463
2342 (new DC::UI::Frame 2464 (new DC::UI::Frame
2343 bg => [0, 0, 0, 0.4], 2465 bg => [0, 0, 0, 0.4],
2344 force_x => 0, 2466 force_x => 0,
2345 force_y => "max", 2467 force_y => "max",
2346 child => (my $LR = new DC::UI::VBox), 2468 child => (my $LL = new DC::UI::VBox),
2347 )->show; 2469 )->show;
2348 2470
2349 $LR->add ($STATUSBOX); 2471 $LL->add ($STATUSBOX);
2350 $LR->add ($MODBOX); 2472 $LL->add ($MODBOX);
2351 $LR->add (new DC::UI::Label 2473 $LL->add (new DC::UI::Label
2352 align => 0, 2474 align => 0,
2353 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode", 2475 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode",
2354 fontsize => 0.5, 2476 fontsize => 0.5,
2355 fg => [1, 1, 0, 0.7], 2477 fg => [1, 1, 0, 0.7],
2356 ); 2478 );
2357 2479
2358 DC::UI::Toplevel->new ( 2480 DC::UI::Toplevel->new (
2359 title => "Minimap", 2481 title => "Minimap",
2360 name => "mapmap", 2482 name => "mapmap",
2361 x => 0, 2483 x => 0,
2362 y => $FONTSIZE + 8, 2484 y => $::FONTSIZE + 8,#d# hack to move messages window below the menubar
2363 border_bg => [1, 1, 1, 192/255], 2485 border_bg => [1, 1, 1, 192/255],
2364 bg => [1, 1, 1, 0], 2486 bg => [1, 1, 1, 0],
2365 child => ($MAPMAP = new DC::MapWidget::MapMap 2487 child => ($MAPMAP = new DC::MapWidget::MapMap
2366 tooltip => "<b>Minimap</b>. This will display an overview of the surrounding areas.", 2488 tooltip => "<b>Minimap</b>. This will display an overview of the surrounding areas.",
2367 ), 2489 ),
2396 $METASERVER = metaserver_dialog; 2518 $METASERVER = metaserver_dialog;
2397 # the name is changed to not conflict with the older name as users could have hidden it 2519 # the name is changed to not conflict with the older name as users could have hidden it
2398 $MESSAGE_WINDOW = new DC::UI::Dockbar 2520 $MESSAGE_WINDOW = new DC::UI::Dockbar
2399 name => "message_window2", 2521 name => "message_window2",
2400 title => 'Messages', 2522 title => 'Messages',
2523 y => $::FONTSIZE + 8,#d# hack to move messages window below the menubar
2401 force_w => $::WIDTH * 0.6, 2524 force_w => $::WIDTH * 0.6,
2402 force_h => $::HEIGHT * 0.25, 2525 force_h => $::HEIGHT * 0.25,
2403 ; 2526 ;
2404 2527
2405 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; 2528 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW;
2425 . "After pressing the combo the binding will be saved automatically and the " 2548 . "After pressing the combo the binding will be saved automatically and the "
2426 . "binding editor closes"); 2549 . "binding editor closes");
2427 $SETUP_NOTEBOOK->add_tab (Debug => debug_setup, 2550 $SETUP_NOTEBOOK->add_tab (Debug => debug_setup,
2428 "Some debuggin' options. Do not ask."); 2551 "Some debuggin' options. Do not ask.");
2429 2552
2430 $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top 2553 make_help_window;
2554 make_menubar;
2431 2555
2432 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
2433 tooltip => "Toggles a dialog where you can configure all aspects of this client.");
2434
2435# $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
2436# tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
2437
2438 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
2439
2440 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window,
2441 tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats.");
2442
2443 $BUTTONBAR->add (new DC::UI::Button
2444 text => "Save Config",
2445 tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.",
2446 on_activate => sub {
2447 $::CFG->{layout} = DC::UI::get_layout;
2448 DC::write_cfg;
2449 status "Configuration Saved";
2450 0
2451 },
2452 );
2453
2454 $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window,
2455 tooltip => "View Documentation");
2456
2457 $BUTTONBAR->add (new DC::UI::Button
2458 text => "Quit",
2459 tooltip => "Terminates the program",
2460 on_activate => sub {
2461 if ($CONN) {
2462 open_quit_dialog;
2463 } else {
2464 EV::unloop EV::UNLOOP_ALL;
2465 }
2466 0
2467 },
2468 );
2469
2470 $BUTTONBAR->show;
2471 $SETUP_DIALOG->show; 2556 $SETUP_DIALOG->show;
2472 $MESSAGE_WINDOW->show; 2557 $MESSAGE_WINDOW->show;
2473 } 2558 }
2474 2559
2475 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]); 2560 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]);
2511my $want_refresh = EV::prepare_ns \&force_refresh; 2596my $want_refresh = EV::prepare_ns \&force_refresh;
2512 2597
2513my $input = EV::periodic 0, 1 / $MAX_FPS, undef, sub { 2598my $input = EV::periodic 0, 1 / $MAX_FPS, undef, sub {
2514 $NOW = EV::now; 2599 $NOW = EV::now;
2515 2600
2516 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2601 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_)
2517 for DC::poll_events; 2602 for DC::poll_events;
2518 2603
2519 if (%animate_object) { 2604 if (%animate_object) {
2520 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2605 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2521 $WANT_REFRESH = 1; 2606 $WANT_REFRESH = 1;
2533sub animation_stop { 2618sub animation_stop {
2534 my ($widget) = @_; 2619 my ($widget) = @_;
2535 delete $animate_object{$widget}; 2620 delete $animate_object{$widget};
2536} 2621}
2537 2622
2538%SDL_CB = (
2539 DC::SDL_QUIT => sub { 2623$SDL_CB[DC::SDL_QUIT] = sub {
2540 crash "SDL_QUIT"; 2624 crash "SDL_QUIT";
2541 EV::unloop EV::UNLOOP_ALL; 2625 EV::unloop EV::UNLOOP_ALL;
2542 }, 2626};
2543 DC::SDL_VIDEORESIZE => sub { 2627$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2544 },
2545 DC::SDL_VIDEOEXPOSE => sub { 2628$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2546 DC::UI::full_refresh; 2629 DC::UI::full_refresh;
2547 }, 2630};
2548 DC::SDL_ACTIVEEVENT => sub { 2631$SDL_CB[DC::SDL_ACTIVEEVENT] = sub {
2549# not useful, as APPACTIVE includes only iconified state, not unmapped 2632# not useful, as APPACTIVE includes only iconified state, not unmapped
2550# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, DC::SDL_GetAppState;#d# 2633# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, DC::SDL_GetAppState;#d#
2551# printf "a %x\n", DC::SDL_GetAppState & DC::SDL_APPACTIVE;#d# 2634# printf "a %x\n", DC::SDL_GetAppState & DC::SDL_APPACTIVE;#d#
2552# printf "A\n" if $_[0]{state} & DC::SDL_APPACTIVE; 2635# printf "A\n" if $_[0]{state} & DC::SDL_APPACTIVE;
2553# printf "K\n" if $_[0]{state} & DC::SDL_APPINPUTFOCUS; 2636# printf "K\n" if $_[0]{state} & DC::SDL_APPINPUTFOCUS;
2554# printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS; 2637# printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS;
2555 }, 2638};
2556 DC::SDL_KEYDOWN => sub { 2639$SDL_CB[DC::SDL_KEYDOWN] = sub {
2557 if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) { 2640 if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) {
2558 # alt-enter 2641 # alt-enter
2559 video_shutdown; 2642 video_shutdown;
2560 $FULLSCREEN_ENABLE->toggle; 2643 $FULLSCREEN_ENABLE->toggle;
2561 video_init; 2644 video_init;
2562 } else { 2645 } else {
2563 &DC::UI::feed_sdl_key_down_event; 2646 &DC::UI::feed_sdl_key_down_event;
2564 } 2647 }
2565 update_modbox; 2648 update_modbox;
2566 }, 2649};
2567 DC::SDL_KEYUP => sub { 2650$SDL_CB[DC::SDL_KEYUP] = sub {
2568 &DC::UI::feed_sdl_key_up_event; 2651 &DC::UI::feed_sdl_key_up_event;
2569 update_modbox; 2652 update_modbox;
2570 }, 2653};
2571 DC::SDL_MOUSEMOTION => \&DC::UI::feed_sdl_motion_event, 2654$SDL_CB[DC::SDL_MOUSEMOTION] = \&DC::UI::feed_sdl_motion_event,
2572 DC::SDL_MOUSEBUTTONDOWN => \&DC::UI::feed_sdl_button_down_event, 2655$SDL_CB[DC::SDL_MOUSEBUTTONDOWN] = \&DC::UI::feed_sdl_button_down_event,
2573 DC::SDL_MOUSEBUTTONUP => \&DC::UI::feed_sdl_button_up_event, 2656$SDL_CB[DC::SDL_MOUSEBUTTONUP] = \&DC::UI::feed_sdl_button_up_event,
2574 DC::SDL_USEREVENT => sub { 2657$SDL_CB[DC::SDL_USEREVENT] = sub {
2575 if ($_[0]{code} == 1) { 2658 if ($_[0]{code} == 1) {
2576 audio_channel_finished $_[0]{data1}; 2659 audio_channel_finished $_[0]{data1};
2577 } elsif ($_[0]{code} == 0) { 2660 } elsif ($_[0]{code} == 0) {
2578 audio_music_finished; 2661 audio_music_finished;
2579 }
2580 }, 2662 }
2581); 2663};
2582 2664
2583############################################################################# 2665#############################################################################
2584 2666
2585$SIG{INT} = $SIG{TERM} = sub { 2667$SIG{INT} = $SIG{TERM} = sub {
2586 EV::unloop; 2668 EV::unloop;
2587 #d# TODO calling exit here hangs the process in some futex 2669 #d# TODO calling exit here hangs the process in some futex
2588}; 2670};
2589 2671
2590# due to mac os x + sdl combined briandamage, we need this contortion 2672# due to mac os x + sdl combined braindamage, we need this contortion
2591sub main { 2673sub main {
2592 { 2674 {
2593 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2675 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2594 2676
2595 if (-e "$Deliantra::VARDIR/client.cf") { 2677 if (-e "$Deliantra::VARDIR/client.cf") {
2612 DC::DB::open_db; 2694 DC::DB::open_db;
2613 2695
2614 DC::UI::set_layout ($::CFG->{layout}); 2696 DC::UI::set_layout ($::CFG->{layout});
2615 2697
2616 my %DEF_CFG = ( 2698 my %DEF_CFG = (
2699 config_autosave => 1,
2617 sdl_mode => undef, 2700 sdl_mode => undef,
2618 fullscreen => 1, 2701 fullscreen => 1,
2619 fast => 0, 2702 fast => 0,
2620 force_opengl11 => undef, 2703 force_opengl11 => undef,
2621 disable_alpha => 0, 2704 disable_alpha => 0,
2639 effects_enable => 1, 2722 effects_enable => 1,
2640 effects_volume => 1, 2723 effects_volume => 1,
2641 bgm_enable => 1, 2724 bgm_enable => 1,
2642 bgm_volume => 0.5, 2725 bgm_volume => 0.5,
2643 output_rate => "", 2726 output_rate => "",
2644 pickup => 0, 2727 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2645 inv_sort => "mtime", 2728 inv_sort => "mtime",
2646 default => "profile", # default profile 2729 default => "profile", # default profile
2647 show_tips => 1, 2730 show_tips => 1,
2648 logview_max_par => 1000, 2731 logview_max_par => 1000,
2649 shift_fire_stop => 0, 2732 shift_fire_stop => 0,
2650 uitheme => "wood", 2733 uitheme => "wood",
2734 map_shift_x => -24, # arbitrary
2735 map_shift_y => +24, # arbitrary
2651 ); 2736 );
2652 2737
2653 while (my ($k, $v) = each %DEF_CFG) { 2738 while (my ($k, $v) = each %DEF_CFG) {
2654 $CFG->{$k} = $v unless exists $CFG->{$k}; 2739 $CFG->{$k} = $v unless exists $CFG->{$k};
2655 } 2740 }
2669 } 2754 }
2670 } 2755 }
2671 2756
2672 sdl_init; 2757 sdl_init;
2673 2758
2759 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf";
2760 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts";
2761
2674 { 2762 {
2675 my @fonts = map DC::find_rcfile "fonts/$_", qw( 2763 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2676 DejaVuSans.ttf 2764 DejaVuSans.ttf
2677 DejaVuSansMono.ttf 2765 DejaVuSansMono.ttf
2678 DejaVuSans-Bold.ttf 2766 DejaVuSans-Bold.ttf
2679 DejaVuSansMono-Bold.ttf 2767 DejaVuSansMono-Bold.ttf
2680 DejaVuSans-Oblique.ttf 2768 DejaVuSans-Oblique.ttf
2681 DejaVuSansMono-Oblique.ttf 2769 DejaVuSansMono-Oblique.ttf
2682 DejaVuSans-BoldOblique.ttf 2770 DejaVuSans-BoldOblique.ttf
2683 DejaVuSansMono-BoldOblique.ttf 2771 DejaVuSansMono-BoldOblique.ttf
2772 mona.ttf
2684 ); 2773 );
2685 2774
2686 DC::add_font $_ for @fonts; 2775 DC::add_font $_ for @fonts;
2687 2776
2688 $FONT_PROP = new_from_file DC::Font $fonts[0]; 2777 $FONT_PROP = new_from_file DC::Font $fonts[0];
2718 }; 2807 };
2719 2808
2720 delete $SIG{__DIE__}; 2809 delete $SIG{__DIE__};
2721 EV::loop; 2810 EV::loop;
2722 2811
2812 DC::write_cfg if $CFG->{config_autosave};
2813
2723#video_shutdown; 2814 #video_shutdown;
2724#audio_shutdown; 2815 #audio_shutdown;
2816
2725 DC::OpenGL::quit; 2817 DC::OpenGL::quit;
2726 DC::SDL_Quit; 2818 DC::SDL_Quit;
2727 DC::DB::Server::stop; 2819 DC::DB::Server::stop;
2728} 2820}
2729 2821

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines