--- deliantra/Deliantra-Client/bin/cfplus 2006/12/08 14:59:54 1.136 +++ deliantra/Deliantra-Client/bin/cfplus 2007/04/01 01:19:19 1.145 @@ -61,14 +61,16 @@ use CFPlus::OpenGL (); use CFPlus::Protocol; use CFPlus::UI; +use CFPlus::UI::Inventory; +use CFPlus::UI::SpellList; use CFPlus::Pod; -use CFPlus::BindingEditor; use CFPlus::MapWidget; +use CFPlus::Macro; $SIG{QUIT} = sub { Carp::cluck "QUIT" }; $SIG{PIPE} = 'IGNORE'; -$Event::Eval = 0; +$Event::Eval = 1; $Event::DIED = sub { CFPlus::fatal Carp::longmess $_[1] }; @@ -147,9 +149,6 @@ our $INVR; our $INV_RIGHT_HB; -our $BIND_EDITOR; -our $BIND_UPD_CB; - our $PICKUP_CFG; our $IN_BUILD_MODE; @@ -179,10 +178,28 @@ if $_[0]{query_dialog}; } +# FIXME: a very ugly hack to wait for stat update look below! #d# +our $QUERY_TIMER; #d# + # server query dialog sub server_query { my ($conn, $flags, $prompt) = @_; + # FIXME: a very ugly hack to wait for stat update #d# + if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) { + unless ($QUERY_TIMER) { + $QUERY_TIMER = + Event->timer ( + after => 1, + cb => sub { + server_query ($conn, $flags, $prompt, 1); + $QUERY_TIMER = undef + } + ); + return; + } + } + $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel x => "center", y => "center", @@ -380,9 +397,7 @@ $LOGIN_BUTTON->set_text ("Logout"); $SETUP_DIALOG->hide; - $PROFILE = $CFG->{profile}{default}; - - my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; + my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / ::T; my ($host, $port) = split /:/, $PROFILE->{host}; @@ -452,8 +467,15 @@ $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); - $table->add (0, 0, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode"); - $table->add (1, 0, my $hbox = new CFPlus::UI::HBox); + my $row = 0; + + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "OpenGL Info"); + $table->add (1, $row++, new CFPlus::UI::Label valign => 0, fontsize => 0.8, text => CFPlus::OpenGL::gl_vendor . ", " . CFPlus::OpenGL::gl_version, + can_events => 1, + tooltip => "" . (CFPlus::OpenGL::gl_extensions) . ""); + + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode"); + $table->add (1, $row++, my $hbox = new CFPlus::UI::HBox); $hbox->add (my $mode_slider = new CFPlus::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]); $hbox->add (my $mode_label = new CFPlus::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); @@ -466,8 +488,6 @@ }); $mode_slider->emit (changed => $mode_slider->{range}[0]); - my $row = 1; - $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fullscreen"); $table->add (1, $row++, $FULLSCREEN_ENABLE = new CFPlus::UI::CheckBox state => $CFG->{fullscreen}, @@ -892,15 +912,9 @@ my @align = qw(1 0 1 1 -1); my $y = 0; - for my $m ( - sort { - $b->{version} <=> $a->{version} - or $b->{users} <=> $a->{users} - } - @{ $msg->{servers} } - ) { - my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = - @$m{qw(ip age hostname users version description ibytes obytes uptime)}; + for my $m (@{ $msg->{servers} }) { + my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime, $highlight) = + @$m{qw(ip age hostname users version description ibytes obytes uptime highlight)}; for ($desc) { s/
/\n/gi; @@ -940,7 +954,7 @@ align => $align[$_], text => $m->[$_], tooltip => $tip[$_], - fg => ($m->[3] =~ /\+$/ ? [1, 1, 1] : [.7, .7, .7]), + fg => ($highlight ? [1, 1, 1] : [.7, .7, .7]), can_hover => 1, can_events => 1, fontsize => 0.8) @@ -1051,21 +1065,30 @@ on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 }, ); - $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); + $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); $table->add (1, 9, new CFPlus::UI::Entry + text => $CFG->{output_rate}, + tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " + . "when sending images, to ensure interactiveness. When 0 or unset, the server " + . "default will be used, which is usually around 100kb/s.", + on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, + ); + + $table->add (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); + $table->add (1, 10, new CFPlus::UI::Entry text => $CFG->{output_count}, tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, ); - $table->add (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); - $table->add (1, 10, new CFPlus::UI::Entry + $table->add (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); + $table->add (1, 11, new CFPlus::UI::Entry text => $CFG->{output_sync}, tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, ); - $table->add (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button + $table->add (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button expand => 1, align => 0, text => "Login", @@ -1076,8 +1099,8 @@ }, ); - $table->add (0, 12, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); - $table->add (1, 12, my $saycmd = new CFPlus::UI::Entry + $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Chat Command"); + $table->add (1, 13, my $saycmd = new CFPlus::UI::Entry text => $CFG->{say_command}, tooltip => "This is the command that will be used if you write a line in the message window entry or press \" in the map window. " . "Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " @@ -1089,8 +1112,8 @@ } ); - $table->add (0, 13, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); - $table->add (1, 13, my $saycmd = new CFPlus::UI::CheckBox + $table->add (0, 14, new CFPlus::UI::Label valign => 0, align => 1, text => "Tip of the day"); + $table->add (1, 14, my $saycmd = new CFPlus::UI::CheckBox state => $CFG->{show_tips}, tooltip => "Show the Tip of the day window at startup?", on_changed => sub { @@ -1384,123 +1407,8 @@ $plwin } -sub update_bindings { - $BIND_UPD_CB->() if $BIND_UPD_CB; -} - sub keyboard_setup { - my $binding_list = new CFPlus::UI::VBox; - - my $refresh; - $refresh = $BIND_UPD_CB = sub { - $binding_list->clear (); - - return unless $PROFILE; - - for my $mod (keys %{$PROFILE->{bindings}}) { - for my $sym (keys %{$PROFILE->{bindings}{$mod}}) { - my $cmds = $PROFILE->{bindings}{$mod}{$sym}; - next unless ref $cmds eq 'ARRAY' and @$cmds > 0; - - my $lbl = join "; ", @$cmds; - my $nam = CFPlus::BindingEditor::keycombo_to_name ($mod, $sym); - $binding_list->add (my $hb = new CFPlus::UI::HBox); - $hb->add (new CFPlus::UI::Button - text => "delete", - tooltip => "Deletes the binding", - on_activate => sub { - $binding_list->remove ($hb); - delete $PROFILE->{bindings}{$mod}{$sym}; - 0 - }); - - $hb->add (new CFPlus::UI::Button - text => "edit", - tooltip => "Edits the binding", - on_activate => sub { - $::BIND_EDITOR->set_binding ( - $mod, $sym, $PROFILE->{bindings}{$mod}{$sym}, - sub { - my ($nmod, $nsym, $ncmds) = @_; - $::BIND_EDITOR->cfg_unbind ($mod, $sym); - $::BIND_EDITOR->cfg_bind ($nmod, $nsym, $ncmds); - $refresh->(); - $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD); - $SETUP_DIALOG->show; - }, - sub { - $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD); - $SETUP_DIALOG->show; - }); - $::BIND_EDITOR->show; - $SETUP_DIALOG->hide; - 0 - }); - - $hb->add (new CFPlus::UI::Label text => "(Key: $nam)"); - $hb->add (new CFPlus::UI::Label text => $lbl, expand => 1); - } - } - }; - - my $vb = new CFPlus::UI::VBox; - $vb->add (new CFPlus::UI::FancyFrame - label => "Options", - child => (my $hb = new CFPlus::UI::HBox), - ); - $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire"); - $hb->add (new CFPlus::UI::CheckBox - expand => 1, - state => $CFG->{shift_fire_stop}, - tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift", - on_changed => sub { - my ($cbox, $value) = @_; - $CFG->{shift_fire_stop} = $value; - 0 - }); - - $vb->add (new CFPlus::UI::FancyFrame - label => "Bindings", - child => $binding_list); - $vb->add (my $hb = new CFPlus::UI::HBox); - - $hb->add (new CFPlus::UI::Button - text => "record new", - expand => 1, - tooltip => "This button opens the binding editor with an empty binding.", - on_activate => sub { - $::BIND_EDITOR->set_binding (undef, undef, [], - sub { - my ($mod, $sym, $cmds) = @_; - $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); - $refresh->(); - $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD); - $SETUP_DIALOG->show; - }, - sub { - $SETUP_NOTEBOOK->set_current_page ($SETUP_KEYBOARD); - $SETUP_DIALOG->show; - }, - ); - $SETUP_DIALOG->hide; - $::BIND_EDITOR->show; - 0 - }, - ); - - $hb->add (new CFPlus::UI::Button - text => "close", - tooltip => "Closes the binding window", - expand => 1, - on_activate => sub { - $SETUP_DIALOG->hide; - 0 - } - ); - - $refresh->(); - - $vb + CFPlus::Macro::keyboard_setup } sub help_window { @@ -1695,16 +1603,16 @@ expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4); $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $tod[$todindex]); - $vbox->add (my $table = new CFPlus::UI::Table); + $vbox->add (my $table = new CFPlus::UI::Table col_expand => [0, 1]); $table->add (0, 0, new CFPlus::UI::Button - text => "Close", + text => "Close", tooltip => "Close the tip of the day window. To never see it again, disable the tip of the day in the Server Setup.", on_activate => $close, ); $table->add (2, 0, new CFPlus::UI::Button - text => "Next", + text => "Next", tooltip => "Show the next Tip of the day.", on_activate => sub { $close->(); @@ -1757,8 +1665,6 @@ force_y => 0; $DEBUG_STATUS->show; - $BIND_EDITOR = new CFPlus::BindingEditor (x => "max", y => 0); - $STATUSBOX = new CFPlus::UI::Statusbox; $STATUSBOX->add ("Use Alt-Enter to toggle fullscreen mode", timeout => 864000, pri => -100, color => [1, 1, 1, 0.8]); @@ -1892,6 +1798,7 @@ sub setup_build_button { my ($enabled) = @_; if ($enabled) { + $BUILD_BUTTON->hide if $BUILD_BUTTON; $BUILD_BUTTON ||= new CFPlus::UI::Button text => "Build", tooltip => "Opens the ingame builder", @@ -2142,7 +2049,11 @@ CFPlus::UI::full_refresh; }, CFPlus::SDL_ACTIVEEVENT => sub { -# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# +# not useful, as APPACTIVE include sonly iconified state, not unmapped +# printf "active %x %x\n", $_[0]{gain}, $_[0]{state};#d# +# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; +# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; +# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; }, CFPlus::SDL_KEYDOWN => sub { if ($_[0]{mod} & CFPlus::KMOD_ALT && $_[0]{sym} == 13) { @@ -2198,6 +2109,7 @@ face_prefetch => 0, output_sync => 1, output_count => 1, + output_rate => "", pickup => 0, inv_sort => "mtime", default => "profile", # default profile @@ -2209,6 +2121,19 @@ } $CFG->{profile}{default}{host} ||= "crossfire.schmorp.de"; + $PROFILE = $CFG->{profile}{default}; + + # convert old bindings (only default profile matters) + if (my $bindings = delete $PROFILE->{bindings}) { + while (my ($mod, $syms) = each %$bindings) { + while (my ($sym, $cmds) = each %$syms) { + push @{ $PROFILE->{macro} }, { + accelkey => [$mod*1, $sym*1], + action => $cmds, + }; + } + } + } sdl_init;