--- deliantra/Deliantra-Client/bin/cfplus 2006/05/29 19:30:28 1.24 +++ deliantra/Deliantra-Client/bin/cfplus 2006/06/01 03:42:58 1.39 @@ -103,9 +103,12 @@ our $INV_WINDOW; our $INV; our $INVR; -our $INVR_LBL; +our $INV_RIGHT_HB; our $BIND_WINDOW; +our $BIND_EDITOR; + +our $SPELL_LIST; sub status { $STATUSBOX->add (CFClient::UI::Label::escape $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); @@ -113,8 +116,6 @@ sub debug { $DEBUG_STATUS->set_text ($_[0]); - my ($w, $h) = $DEBUG_STATUS->size_request; - $DEBUG_STATUS->move ($WIDTH - $w, 0); } sub start_game { @@ -183,17 +184,18 @@ sub client_setup { my $dialog = new CFClient::UI::FancyFrame - req_x => 1, - req_y => $HEIGHT * (1/8), - name => "client_setup", + x => 1, + y => $HEIGHT * (1/8), + name => "client_setup", title => "Client Setup", child => (my $vbox = new CFClient::UI::VBox); + $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); $table->add (1, 0, my $hbox = new CFClient::UI::HBox); - $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]); + $hbox->add (my $mode_slider = new CFClient::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]); $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); $mode_slider->connect (changed => sub { @@ -391,10 +393,10 @@ my $gh = int $HEIGHT * $CFG->{gauge_size}; my $win = new CFClient::UI::Frame ( - req_x => 0, - req_y => -1, - def_w => $WIDTH, - def_h => $gh, + force_x => 0, + force_y => "max", + force_w => $WIDTH, + force_h => $gh, ); $win->add (my $hbox = new CFClient::UI::HBox @@ -443,10 +445,10 @@ sub make_stats_window { my $tgw = new CFClient::UI::FancyFrame - req_y => $HEIGHT * (2/8), - req_x => -1, + y => $HEIGHT * (2/8), + x => "max", title => "Stats", - name => "stats_window"; + name => "stats_window"; $tgw->add (new CFClient::UI::Window child => my $vb = new CFClient::UI::VBox); $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1, @@ -719,15 +721,11 @@ sub server_setup { my $dialog = $SERVER_SETUP = new CFClient::UI::FancyFrame - x => $WIDTH * (1/3), - y => $HEIGHT * (1/8), - name => "server_setup", - title => "Server Setup", - child => (my $vbox = new CFClient::UI::VBox), - on_visibility_change => sub { - my ($self, $visible) = @_; - $self->center if $visible; - }, + x => "center", + y => "center", + name => "server_setup", + title => "Server Setup", + child => (my $vbox = new CFClient::UI::VBox), ; $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); @@ -783,7 +781,7 @@ $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); $table->add (1, 7, new CFClient::UI::Slider - req_w => 100, + force_w => 100, range => [$CFG->{mapsize}, 10, 100, 0, 1], tooltip => "This is the size of the portion of the map update the server sends you. " . "If you set this to a high value you will be able to see further, " @@ -842,10 +840,10 @@ title => "Messages", border_bg => [1, 1, 1, 1], bg => [0, 0, 0, 0.75], - req_x => -1, - req_y => 0, - def_w => int $::WIDTH / 3, - def_h => int $::HEIGHT / 5, + x => "max", + y => 0, + force_w => $::WIDTH / 3, + force_h => $::HEIGHT / 5, child => (my $vbox = new CFClient::UI::VBox); $vbox->add ($LOGVIEW); @@ -870,7 +868,10 @@ $input->set_text (''); if ($text =~ /^\/bind\s+(.*)$/) { - CFClient::Recorder::open_binding_dialog ([$1]); + CFClient::Binder::open_binding_dialog (sub { + my ($mod, $sym) = @_; + $::CFG->{bindings}->{$mod}->{$sym} = [$1]; + }); } elsif ($text =~ /^\/(.*)/) { $::CONN->user_send ($1); } else { @@ -889,7 +890,7 @@ $CONSOLE = { window => $window, - input => $input + input => $input, }; $window @@ -897,7 +898,11 @@ sub open_quit_dialog { unless ($QUIT_DIALOG) { - $QUIT_DIALOG = new CFClient::UI::FancyFrame title => "Really Quit?"; + $QUIT_DIALOG = new CFClient::UI::FancyFrame + x => "center", + y => "center", + title => "Really Quit?", + ; $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); @@ -920,19 +925,15 @@ } $QUIT_DIALOG->show; - $QUIT_DIALOG->center; } sub make_inventory_window { my $invwin = $INV_WINDOW = new CFClient::UI::FancyFrame - def_w => $WIDTH * 7/8, - def_h => $HEIGHT * 7/8, - title => "Inventory", - name => "inventory_window", - on_visibility_change => sub { - my ($self, $visible) = @_; - $self->center if $visible; - }, + x => "center", + y => "center", + force_w => $WIDTH * 9/10, + force_h => $HEIGHT * 9/10, + title => "Inventory", ; $invwin->add (my $hb = new CFClient::UI::HBox homogeneous => 1); @@ -943,26 +944,28 @@ $hb->add (my $vb2 = new CFClient::UI::VBox); - $vb2->add (my $hb2 = new CFClient::UI::HBox); - $hb2->add ($INVR_LBL = new CFClient::UI::Label align => 0, expand => 1, text => "Floor"); - $hb2->add (new CFClient::UI::Button - text => "Close", - tooltip => "Close the currently open container (if one is open)", - on_activate => sub { - $CONN->send ("apply $CONN->{open_container}") - if $CONN->{open_container} != 0; - }, - ); + $vb2->add ($INV_RIGHT_HB = new CFClient::UI::HBox); $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); + # XXX: Call after $INVR = ... because set_opencont sets the items + CFClient::Protocol::set_opencont ($::CONN, 0, "Floor"); + $invwin } +sub make_spell_list { + $SPELL_LIST = new CFClient::UI::SpellList + force_w => $WIDTH * (9/10), + force_h => $HEIGHT * (9/10); + $SPELL_LIST +} + sub make_binding_window { my $binding_list = new CFClient::UI::VBox; - my $refresh = sub { + my $refresh; + $refresh = sub { $binding_list->clear (); for my $mod (keys %{$::CFG->{bindings}}) { @@ -971,15 +974,37 @@ next unless ref $cmds eq 'ARRAY' and @$cmds > 0; my $lbl = join "; ", @$cmds; - my $nam = CFClient::Recorder::keycombo_to_name ($mod, $sym); + my $nam = CFClient::Binder::keycombo_to_name ($mod, $sym); $binding_list->add (my $hb = new CFClient::UI::HBox); $hb->add (new CFClient::UI::Button - text => "del", + text => "delete", + tooltip => "Deletes the binding", on_activate => sub { $binding_list->remove ($hb); delete $::CFG->{bindings}->{$mod}->{$sym}; }); - $hb->add (new CFClient::UI::Label text => "($nam)"); + + $hb->add (new CFClient::UI::Button + text => "edit", + tooltip => "Edits the binding", + on_activate => sub { + $::BIND_EDITOR->set_binding ( + $mod, $sym, $::CFG->{bindings}->{$mod}->{$sym}, + sub { + my ($nmod, $nsym, $ncmds) = @_; + delete $::CFG->{bindings}->{$mod}->{$sym}; + $::CFG->{bindings}->{$nmod}->{$nsym} = $ncmds; + $refresh->(); + $::BIND_WINDOW->show; + }, + sub { + $::BIND_WINDOW->show; + }); + $::BIND_EDITOR->show; + $::BIND_WINDOW->hide; + }); + + $hb->add (new CFClient::UI::Label text => "(Key: $nam)"); $hb->add (new CFClient::UI::Label text => $lbl, expand => 1); } } @@ -987,17 +1012,46 @@ $BIND_WINDOW = new CFClient::UI::FancyFrame title => "Bindings", - def_w => int $WIDTH * 7/8, - def_h => int $HEIGHT * 7/8, + x => "center", + y => "center", + def_w => int $WIDTH * 9/10, + def_h => int $HEIGHT * 9/10, on_visibility_change => sub { my ($self, $visible) = @_; - if ($visible) { - $self->center; - $refresh->() - } + $refresh->() if $visible; }; - $BIND_WINDOW->add ($binding_list); + $BIND_WINDOW->add (my $vb = new CFClient::UI::VBox); + $vb->add ($binding_list); + $vb->add (my $hb = new CFClient::UI::HBox); + $hb->add (new CFClient::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) = @_; + $::CFG->{bindings}->{$mod}->{$sym} = $cmds; + $refresh->(); + $::BIND_WINDOW->show; + }, + sub { + $::BIND_WINDOW->show; + }); + $::BIND_WINDOW->hide; + $::BIND_EDITOR->show; + }, + ); + $hb->add (new CFClient::UI::Button + text => "close", + tooltip => "Closes the binding window", + expand => 1, + on_activate => sub { + $::BIND_WINDOW->hide; + } + ); + $refresh->(); $BIND_WINDOW } @@ -1077,19 +1131,28 @@ } else { # create the widgets - $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1; + $DEBUG_STATUS = new CFClient::UI::Label + padding => 0, + z => 100, + force_x => "max", + force_y => 0; $DEBUG_STATUS->show; - + + $BIND_EDITOR = new CFClient::UI::BindEditor (x => "max", y => 0); + $STATUSBOX = new CFClient::UI::Statusbox; $STATUSBOX->add ("Use Alt-Enter to toggle fullscreen mode", pri => -100, color => [1, 1, 1, 0.8]); (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], - req_y => -1, + force_x => 0, + force_y => "max", child => $STATUSBOX, )->show; CFClient::UI::FancyFrame->new ( + x => 0, + y => $FONTSIZE + 8, border_bg => [1, 1, 1, 192/255], bg => [1, 1, 1, 0], child => ($MAPMAP = new CFClient::MapWidget::MapMap @@ -1122,7 +1185,7 @@ tooltip => "Server Log. This text viewer contains all the messages sent by the server.", ; - $BUTTONBAR = new CFClient::UI::HBox; + $BUTTONBAR = new CFClient::UI::HBox x => 0, y => 0; $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup, tooltip => "Toggles a dialog where you can configure various aspects of the client, such as graphics mode, performance, and audio options."); @@ -1136,14 +1199,15 @@ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window, tooltip => "Toggles the statistics window, where all your Stats and Resistances are being displayed at all times."); $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window, - tooltip => "Toggles the inventory window, where you can manage your loot (or treaures :)."); + tooltip => "Toggles the inventory window, where you can manage your loot (or treaures :)." + ."You can also hit the Tab-key to show/hide the Inventory."); $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", 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} = CFClient::UI::get_layout; - CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; + CFClient::write_cfg "$Crossfire::VARDIR/cfplusrc"; status "Configuration Saved"; }, ); @@ -1154,10 +1218,18 @@ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Bindings", other => make_binding_window, - tooltip => "Lets you delete bindings you have made with the recorder" - ); - $BUTTONBAR->add (new CFClient::UI::Flopper text => "[Rec]", other => CFClient::Recorder::make_window, - tooltip => "This feature lets you record a series of actions (eg. walking a path or ready a skill) and bind them to keys"); + tooltip => + "Lets you define, edit and delete bindings." + ."There is a shortcut for making bindings: LCTRL+Insert opens the binding editor " + ."with nothing set and the recording started. After doing the actions you " + ."want to record press Insert and you will be asked to press a key-combo." + ."After pressing the combo the binding will be saved automatically and the " + ."binding editor closes"); + + $BUTTONBAR->add (new CFClient::UI::Flopper + text => "Spells", + other => make_spell_list, + tooltip => "The spell list"); $BUTTONBAR->add (new CFClient::UI::Button text => "Quit", @@ -1172,10 +1244,9 @@ ); $BUTTONBAR->show; + $SERVER_SETUP->show; $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); - - $SERVER_SETUP->show; } } @@ -1253,7 +1324,7 @@ sub force_refresh { $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; - debug sprintf "%3.2f", $fps; + debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; $CFClient::UI::ROOT->draw; @@ -1395,9 +1466,9 @@ $SIG{INT} = $SIG{TERM} = sub { exit }; { - local $SIG{__DIE__} = sub { CFClient::fatal $_[0] }; + local $SIG{__DIE__} = sub { CFClient::fatal $_[0] if defined $^S && !$^S }; - CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; + CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc"; CFClient::UI::set_layout ($::CFG->{layout}); my %DEF_CFG = ( @@ -1485,7 +1556,7 @@ =head1 NAME -pclient - A Crossfire+ and Crossfire game client +cfplus - A Crossfire+ and Crossfire game client =head1 SYNOPSIS @@ -1493,9 +1564,19 @@ =head1 USAGE -Pclient utilises OpenGL for all UI elements and the game. It is supposed to be used +cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used fullscreen and interactively. +=head1 DEBUGGING + + +CFPLUS_DEBUG - environment variable + + 1 draw borders around widgets + 2 add low-level widget info to tooltips + 4 show fps + 8 suppress tooltips + =head1 AUTHOR Marc Lehmann , Robin Redeker