--- deliantra/Deliantra-Client/bin/deliantra 2008/01/06 16:28:50 1.23 +++ deliantra/Deliantra-Client/bin/deliantra 2008/07/07 12:56:07 1.49 @@ -80,7 +80,7 @@ # prepend private library directory BEGIN { for (grep !ref, @INC) { - my $path = "$_/Deliantra/Client/private/dc"; + my $path = "$_/Deliantra/Client/private"; if (-d $path) { unshift @INC, $path; last; @@ -99,9 +99,12 @@ use Deliantra; use Deliantra::Protocol::Constants; +use AnyEvent::DNS; + use Compress::LZF; use DC; +BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } use DC::OpenGL (); use DC::Protocol; use DC::DB; @@ -192,6 +195,7 @@ our $ALT_ENTER_MESSAGE; our $STATUSBOX; +our $MODBOX; our $DEBUG_STATUS; our $INV; @@ -212,6 +216,32 @@ $MESSAGE_DIST->message (@_); } +sub update_modbox { + my $mod = DC::SDL_GetModState; + + my $markup; + + $markup .= $mod & DC::KMOD_CTRL + ? ($MAPWIDGET->{ctrl} ? "[REPEAT]" : "[REPEAT]") + : "[ once ]"; + + $markup .= $mod & DC::KMOD_SHIFT + ? ($MAPWIDGET->{shft} ? "[FIRE]" : "[FIRE]") + : "[move]"; + + $markup .= $mod & (DC::KMOD_ALT | DC::KMOD_META) + ? "[ALT]" + : "[alt]"; + + $markup .= $mod & DC::KMOD_NUM + ? "[NUM]" + : "[num]"; + + # around next statement works around some bug that keeps the + # "font =>" from being used on windows + $MODBOX->set_markup ("$markup"); +} + ############################################################################# #TODO: maybe move into own audio module... @@ -639,7 +669,6 @@ text => "Accept", on_activate => sub { $conn->send ("reply n"); - $STATS_PAGE->hide; destroy_query_dialog $conn; 0 }, @@ -701,19 +730,12 @@ $dialog->show; } -sub start_game { - status "logging in..."; - - $LOGIN_BUTTON->set_text ("Logout"); - $SETUP_DIALOG->hide; +sub dc_connect { + my ($host, $port) = @_; my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; - my ($host, $port) = split /:/, $PROFILE->{host}; - - $MAP = new DC::Map; - - $CONN = eval { + $CONN = new DC::Protocol host => $host, port => $port || 13327, @@ -722,7 +744,7 @@ mapw => $mapsize, maph => $mapsize, - client => "cfplus $DC::VERSION $] $^O", + client => "$DC::VERSION $] $^O", map_widget => $MAPWIDGET, statusbox => $STATUSBOX, @@ -733,15 +755,44 @@ setup_req => { smoothing => $CFG->{map_smoothing}*1, }, - }; - if ($CONN) { - DC::lowdelay fileno $CONN->{fh}; + on_connect => sub { + if ($_[0]) { + DC::lowdelay fileno $CONN->{fh}; + + status "login successful"; + } else { + undef $CONN; + status "unable to connect: $!"; + stop_game(); + } + }, + ; +} + +sub start_game { + status "logging in..."; + + $LOGIN_BUTTON->set_text ("Logout"); + $SETUP_DIALOG->hide; + + my ($host, $port) = split /:/, $PROFILE->{host}; + + $MAP = new DC::Map; - status "login successful"; + # hack to make SURE we find the IP address all right + # can be removed once AnyEvent::DNS is proven stable. + if ($host eq "gameserver.deliantra.net") { + AnyEvent::DNS::a "dnstest.deliantra.net", sub { + if ($_[0] ne "80.101.114.108") { # Perl + status "dns failure, using hardcoded address"; + $host = "129.13.162.95"; + } + + dc_connect $host, $port; + }; } else { - status "unable to connect"; - stop_game(); + dc_connect $host, $port; } } @@ -1530,7 +1581,7 @@ $HOST_ENTRY = new DC::UI::Entry expand => 1, text => $CFG->{profile}{default}{host}, - tooltip => "The hostname or ip address of the Deliantra server to connect to", + tooltip => "The hostname or ip address of the Deliantra server to connect to (e.g. gameserver.deliantra.net)", on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{host} = $value; @@ -1543,7 +1594,7 @@ expand => 1, text => "Server List", other => $METASERVER, - tooltip => "Show a list of available crossfire servers", + tooltip => "Show a list of available Deliantra servers", on_activate => sub { $METASERVER->toggle_visibility; 0 }, on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 }, ); @@ -1595,15 +1646,15 @@ } ); - $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Messages Window Size"); + $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry text => $CFG->{logview_max_par}, - tooltip => "This is maximum number of messages remembered in the Messages window. If the server " + tooltip => "This is maximum number of messages remembered in the Message window. If the server " . "sends more messages than this number, older messages get removed to save memory and " . "computing time. A value of 0 disables this feature, but that is not recommended.", on_changed => sub { my ($self, $value) = @_; - $MESSAGE_DIST->set_max_para ($CFG->{logview_max_par} = $value*1); + $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 0 }, ); @@ -1717,7 +1768,9 @@ } my %SORT_ORDER = ( - type => undef, + type => sub { + sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_ + }, mtime => sub { my $NOW = time; sort { @@ -1949,7 +2002,7 @@ for my $node (@path) { $buttons->add (new DC::UI::Button - text => $node->{kw}[0], + text => $node->[DC::Pod::N_KW][0], tooltip => "go to " . (DC::asxml DC::Pod::full_path $node) . "", on_activate => sub { push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); @@ -1959,7 +2012,7 @@ $buttons->add (new DC::UI::Label text => "/"); } - $buttons->add (new DC::UI::Label text => $node->{kw}[0], padding_x => 4, padding_y => 4); + $buttons->add (new DC::UI::Label text => $node->[DC::Pod::N_KW][0], padding_x => 4, padding_y => 4); $curnode = $node; @@ -2148,15 +2201,35 @@ $DEBUG_STATUS->show; $STATUSBOX = new DC::UI::Statusbox; - $STATUSBOX->add ("Use Alt-Enter to toggle fullscreen mode", timeout => 864000, pri => -100, color => [1, 1, 1, 0.8]); + + $MODBOX = new DC::UI::Label + can_events => 1, + can_hover => 1, + markup => "", + align => 0, + font => $FONT_FIXED, + tooltip => "#modifier_box", + tooltip_width => 0.67, + ; + + update_modbox; (new DC::UI::Frame bg => [0, 0, 0, 0.4], force_x => 0, force_y => "max", - child => $STATUSBOX, + child => (my $LR = new DC::UI::VBox), )->show; + $LR->add ($STATUSBOX); + $LR->add ($MODBOX); + $LR->add (new DC::UI::Label + align => 0, + markup => "Use Alt-Enter to toggle fullscreen mode", + fontsize => 0.5, + fg => [1, 1, 0, 0.7], + ); + DC::UI::Toplevel->new ( title => "Minimap", name => "mapmap", @@ -2196,10 +2269,17 @@ ; $METASERVER = metaserver_dialog; - $MESSAGE_WINDOW = new DC::UI::Dockbar; + # the name is changed to not conflict with the older name as users could have hidden it + $MESSAGE_WINDOW = new DC::UI::Dockbar + name => "message_window2", + title => 'Messages', + force_w => $::WIDTH * 0.6, + force_h => $::HEIGHT * 0.25, + ; + $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; - $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, debug => 1, + $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, @@ -2227,8 +2307,8 @@ $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, tooltip => "Toggles a dialog where you can configure all aspects of this client."); - $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, - tooltip => "Toggles the server message log, where the client collects all messages from the server."); +# $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, +# tooltip => "Toggles the server message log, where the client collects all messages from the server."); 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 @@ -2240,7 +2320,7 @@ tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", on_activate => sub { $::CFG->{layout} = DC::UI::get_layout; - DC::write_cfg "$Deliantra::VARDIR/client.cf"; + DC::write_cfg; status "Configuration Saved"; 0 }, @@ -2249,7 +2329,6 @@ $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, tooltip => "View Documentation"); - $BUTTONBAR->add (new DC::UI::Button text => "Quit", tooltip => "Terminates the program", @@ -2347,10 +2426,14 @@ video_shutdown; video_init; } else { - DC::UI::feed_sdl_key_down_event ($_[0]); + &DC::UI::feed_sdl_key_down_event; } + update_modbox; + }, + DC::SDL_KEYUP => sub { + &DC::UI::feed_sdl_key_up_event; + update_modbox; }, - DC::SDL_KEYUP => \&DC::UI::feed_sdl_key_up_event, DC::SDL_MOUSEMOTION => \&DC::UI::feed_sdl_motion_event, DC::SDL_MOUSEBUTTONDOWN => \&DC::UI::feed_sdl_button_down_event, DC::SDL_MOUSEBUTTONUP => \&DC::UI::feed_sdl_button_up_event, @@ -2371,16 +2454,27 @@ }; { + DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; + if (-e "$Deliantra::VARDIR/client.cf") { DC::read_cfg "$Deliantra::VARDIR/client.cf"; } else { #TODO: compatibility cruft DC::read_cfg "$Deliantra::OLDDIR/cfplusrc"; - print STDERR "INFO: used old configuratrion file\n"; + print STDERR "INFO: used old configuration file\n"; } DC::DB::Server::run; + if ($CFG->{db_schema} < 1) { + warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; + DC::DB::nuke_db; + $CFG->{db_schema} = 1; + DC::write_cfg; + } + + DC::DB::open_db; + DC::UI::set_layout ($::CFG->{layout}); my %DEF_CFG = ( @@ -2414,6 +2508,7 @@ default => "profile", # default profile show_tips => 1, logview_max_par => 1000, + shift_fire_stop => 0, ); while (my ($k, $v) = each %DEF_CFG) { @@ -2459,12 +2554,12 @@ DC::add_font $_ for @fonts; - DC::pango_init; - $FONT_PROP = new_from_file DC::Font $fonts[0]; $FONT_FIXED = new_from_file DC::Font $fonts[1]; $FONT_PROP->make_default; + + DC::pango_init; } # compare mono (ft) vs. rgba (cairo) @@ -2491,6 +2586,7 @@ $startup_done->(); }; +delete $SIG{__DIE__}; EV::loop; #video_shutdown;