--- deliantra/Deliantra-Client/bin/cfplus 2006/07/23 16:11:12 1.100 +++ deliantra/Deliantra-Client/bin/cfplus 2006/08/22 06:37:30 1.118 @@ -34,26 +34,34 @@ use Compress::LZF; -use CFClient; -use CFClient::OpenGL (); -use CFClient::Protocol; -use CFClient::UI; -use CFClient::Pod; -use CFClient::BindingEditor; -use CFClient::MapWidget; +use CFPlus; +use CFPlus::OpenGL (); +use CFPlus::Protocol; +use CFPlus::UI; +use CFPlus::Pod; +use CFPlus::BindingEditor; +use CFPlus::MapWidget; $SIG{QUIT} = sub { Carp::cluck "QUIT" }; $SIG{PIPE} = 'IGNORE'; +$Event::Eval = 0; $Event::DIED = sub { # TODO: display dialog box or so - Carp::confess $_[1];#d#TODO: remove when stable - CFClient::error $_[1]; + Carp::cluck $_[1];#d#TODO: remove when stable + CFPlus::error $_[1]; }; -#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# +$SIG{__DIE__} = sub { + return if CFPlus::in_destruct; + Carp::cluck $_[0]; + CFPlus::error $_[0]; + return;#d# + #return unless defined $^S && !$^S; + $Event::DIED->(undef, $_[0]); +}; -our $VERSION = '0.1'; +our $VERSION = '0.9'; my $MAX_FPS = 60; my $MIN_FPS = 5; # unused as of yet @@ -133,7 +141,7 @@ our $PICKUP_CFG; sub status { - $STATUSBOX->add (CFClient::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); + $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); } sub debug { @@ -149,22 +157,22 @@ sub server_query { my ($conn, $flags, $prompt) = @_; - $conn->{query_dialog} = my $dialog = new CFClient::UI::FancyFrame + $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel x => "center", y => "center", title => "Server Query", - child => my $vbox = new CFClient::UI::VBox, + child => my $vbox = new CFPlus::UI::VBox, ; - my @dialog = my $label = new CFClient::UI::Label + my @dialog = my $label = new CFPlus::UI::Label max_w => $::WIDTH * 0.4, ellipsise => 0, text => $prompt; if ($flags & CS_QUERY_YESNO) { - push @dialog, my $hbox = new CFClient::UI::HBox; + push @dialog, my $hbox = new CFPlus::UI::HBox; - $hbox->add (new CFClient::UI::Button + $hbox->add (new CFPlus::UI::Button text => "No", on_activate => sub { $conn->send ("reply n"); @@ -172,7 +180,7 @@ 0 } ); - $hbox->add (new CFClient::UI::Button + $hbox->add (new CFPlus::UI::Button text => "Yes", on_activate => sub { $conn->send ("reply y"); @@ -184,19 +192,19 @@ $dialog->grab_focus; } elsif ($flags & CS_QUERY_SINGLECHAR) { - $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; + $dialog->{tooltip} = "#charcreation_focus"; if ($prompt =~ /Now choose a character|Press any key for the next race/i) { $MESSAGE_WINDOW->show; - unshift @dialog, new CFClient::UI::Label + unshift @dialog, new CFPlus::UI::Label max_w => $::WIDTH * 0.4, ellipsise => 0, markup => "\nOr use your keyboard and the text entry below:\n"; - unshift @dialog, my $table = new CFClient::UI::Table; + unshift @dialog, my $table = new CFPlus::UI::Table; - $table->add (0, 0, new CFClient::UI::Button + $table->add (0, 0, new CFPlus::UI::Button text => "Next Race", on_activate => sub { $conn->send ("reply n"); @@ -204,7 +212,7 @@ 0 }, ); - $table->add (2, 0, new CFClient::UI::Button + $table->add (2, 0, new CFPlus::UI::Button text => "Accept", on_activate => sub { $conn->send ("reply d"); @@ -213,17 +221,10 @@ }, ); - unshift @dialog, new CFClient::UI::Label + unshift @dialog, new CFPlus::UI::Label max_w => $::WIDTH * 0.4, ellipsise => 0, - markup => - "Character Creation: Race\n\n" - . "Look at the Messages window to see a description of this race " - . "and the center of the screen to see how this race looks like " - . "(below this dialog window: you may need to move the dialog away and " - . "click into the display area to make it visible).\n\n" - . "You can look at another race, or accept this race (you will cycle back to " - . "this race eventually, so you can take your time making this important choice." + markup => (CFPlus::Pod::section_label ui => "chargen_race"), ; } elsif ($prompt =~ /roll new stats/) { @@ -236,15 +237,15 @@ $STATS_PAGE->show; $MESSAGE_WINDOW->hide; - unshift @dialog, new CFClient::UI::Label + unshift @dialog, new CFPlus::UI::Label max_w => $::WIDTH * 0.4, ellipsise => 0, markup => "\nOr use your keyboard and the text entry below:\n"; - unshift @dialog, my $table = new CFClient::UI::Table; + unshift @dialog, my $table = new CFPlus::UI::Table; # left: re-roll - $table->add (0, 0, new CFClient::UI::Button + $table->add (0, 0, new CFPlus::UI::Button text => "Roll Again", on_activate => sub { $conn->send ("reply y"); @@ -254,7 +255,7 @@ ); # center: swap stats - my ($sw1, $sw2) = map +(new CFClient::UI::Combobox + my ($sw1, $sw2) = map +(new CFPlus::UI::Selector expand => 1, value => $_, options => [ @@ -268,7 +269,7 @@ ], ), 1 .. 2; - $table->add (2, 0, new CFClient::UI::Button + $table->add (2, 0, new CFPlus::UI::Button text => "Swap Stats", on_activate => sub { $conn->{stat_change_with} = $sw2->{value}; @@ -277,10 +278,10 @@ 0 }, ); - $table->add (2, 1, new CFClient::UI::HBox children => [$sw1, $sw2]); + $table->add (2, 1, new CFPlus::UI::HBox children => [$sw1, $sw2]); # right: accept - $table->add (4, 0, new CFClient::UI::Button + $table->add (4, 0, new CFPlus::UI::Button text => "Accept", on_activate => sub { $conn->send ("reply n"); @@ -290,7 +291,7 @@ }, ); - unshift @dialog, my $hbox = new CFClient::UI::HBox; + unshift @dialog, my $hbox = new CFPlus::UI::HBox; for ( [Str => CS_STAT_STR], [Dex => CS_STAT_DEX], @@ -301,29 +302,24 @@ [Cha => CS_STAT_CHA], ) { my ($name, $id) = @$_; - $hbox->add (new CFClient::UI::Label + $hbox->add (new CFPlus::UI::Label markup => "$conn->{stat}{$id} $name", align => 0, expand => 1, can_events => 1, can_hover => 1, - tooltip => $CFClient::STAT_TOOLTIP{$name}, + tooltip => "#stat_$name", ); } - unshift @dialog, new CFClient::UI::Label + unshift @dialog, new CFPlus::UI::Label max_w => $::WIDTH * 0.4, ellipsise => 0, - markup => - "Character Creation: Stats\n\n" - . "Stats are a very important aspect of your character. You can use the tooltips to learn what each Stat governs.\n\n" - . "The stats generated by the server are always sorted from Str (highest) to Cha (lowest). " - . "They will be modified later by both the race and the class you choose.\n\n" - . "You can create another set of stats, swap two stat values with each other or accept the stats as shown below and continue.\n" + markup => (CFPlus::Pod::section_label ui => "chargen_stats"), ; } - push @dialog, my $entry = new CFClient::UI::Entry + push @dialog, my $entry = new CFPlus::UI::Entry on_changed => sub { $conn->send ("reply $_[1]"); destroy_query_dialog $conn; @@ -336,7 +332,7 @@ } else { $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; - push @dialog, my $entry = new CFClient::UI::Entry + push @dialog, my $entry = new CFPlus::UI::Entry $flags & CS_QUERY_HIDEINPUT ? (hidden => "*") : (), on_activate => sub { $conn->send ("reply $_[1]"); @@ -362,10 +358,10 @@ my ($host, $port) = split /:/, $CFG->{profile}{default}{host}; - $MAP = new CFClient::Map $mapsize, $mapsize; + $MAP = new CFPlus::Map $mapsize, $mapsize; $CONN = eval { - new CFClient::Protocol + new CFPlus::Protocol host => $host, port => $port || 13327, user => $CFG->{profile}{default}{user}, @@ -373,6 +369,8 @@ mapw => $mapsize, maph => $mapsize, + client => "cfplus $VERSION $] $^O", + map_widget => $MAPWIDGET, logview => $LOGVIEW, statusbox => $STATUSBOX, @@ -394,7 +392,7 @@ }; if ($CONN) { - CFClient::lowdelay fileno $CONN->{fh}; + CFPlus::lowdelay fileno $CONN->{fh}; status "login successful"; } else { @@ -422,15 +420,15 @@ } sub graphics_setup { - my $vbox = new CFClient::UI::VBox; + my $vbox = new CFPlus::UI::VBox; - $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); + $vbox->add (my $table = new CFPlus::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); + $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); - $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"); + $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"); $mode_slider->connect (changed => sub { my ($self, $value) = @_; @@ -442,69 +440,69 @@ my $row = 1; - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); - $table->add (1, $row++, $FULLSCREEN_ENABLE = new CFClient::UI::CheckBox + $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}, tooltip => "Bring the client into fullscreen mode.", on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); - $table->add (1, $row++, new CFClient::UI::CheckBox + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); + $table->add (1, $row++, new CFPlus::UI::CheckBox state => $CFG->{fast}, tooltip => "Lower the visual quality considerably to speed up rendering.", on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Scale"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [(log $CFG->{map_scale}) / (log 2), -3, 1, 0, 1], tooltip => "Enlarge or shrink the displayed map. Changes are instant.", on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); - $table->add (1, $row++, new CFClient::UI::CheckBox + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); + $table->add (1, $row++, new CFPlus::UI::CheckBox state => $CFG->{fow_enable}, tooltip => "Fog-of-War marks areas that cannot be seen by the player. Changes are instant.", on_changed => sub { my ($self, $value) = @_; $CFG->{fow_enable} = $value; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Intensity"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [$CFG->{fow_intensity}, 0, 1, 0, 1 / 256], tooltip => "Fog of War Lightness. The higher the intensity, the lighter the Fog-of-War color. Changes are instant.", on_changed => sub { my ($self, $value) = @_; $CFG->{fow_intensity} = $value; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); - $table->add (1, $row++, new CFClient::UI::CheckBox + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Smooth"); + $table->add (1, $row++, new CFPlus::UI::CheckBox state => $CFG->{fow_smooth}, tooltip => "Smooth the Fog-of-War a bit to make it more realistic. Changes are instant.", on_changed => sub { my ($self, $value) = @_; $CFG->{fow_smooth} = $value; - status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::OpenGL::GL_VERSION < 1.2; + status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFPlus::OpenGL::GL_VERSION < 1.2; 0 } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1], tooltip => "The base font size used by most GUI elements that do not have their own setting.", on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 }, ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Message Fontsize"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], tooltip => "The font size used by the message/server log window only. Changes are instant.", on_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1], tooltip => "Adjusts the fontsize of the gauges at the bottom right. Changes are instant.", on_changed => sub { @@ -514,8 +512,8 @@ } ); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size"); - $table->add (1, $row++, new CFClient::UI::Slider + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge size"); + $table->add (1, $row++, new CFPlus::UI::Slider range => [$CFG->{gauge_size}, 0.2, 0.8], tooltip => "Adjust the size of the stats gauges at the bottom right. Changes are instant.", on_changed => sub { @@ -525,7 +523,7 @@ } ); - $table->add (1, $row++, new CFClient::UI::Button + $table->add (1, $row++, new CFPlus::UI::Button expand => 1, align => 0, text => "Apply", tooltip => "Apply the video settings", on_activate => sub { @@ -539,36 +537,36 @@ } sub audio_setup { - my $vbox = new CFClient::UI::VBox; + my $vbox = new CFPlus::UI::VBox; - $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); + $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); my $row = 0; - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); - $table->add (1, $row++, new CFClient::UI::CheckBox + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); + $table->add (1, $row++, new CFPlus::UI::CheckBox state => $CFG->{audio_enable}, tooltip => "Master Audio Enable. If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", on_changed => sub { $CFG->{audio_enable} = $_[1]; 0 } ); -# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); -# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { +# $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); +# $table->add (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { # $CFG->{effects_volume} = $_[1]; # }); - $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); - $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); - $hbox->add (new CFClient::UI::CheckBox + $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); + $table->add (1, $row++, my $hbox = new CFPlus::UI::HBox); + $hbox->add (new CFPlus::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } ); - $hbox->add (new CFClient::UI::Slider + $hbox->add (new CFPlus::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], tooltip => "The volume of the background music. Changes are instant.", - on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFClient::MixMusic::volume $_[1] * 128; 0 } + on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 } ); - $table->add (1, $row++, new CFClient::UI::Button + $table->add (1, $row++, new CFPlus::UI::Button expand => 1, align => 0, text => "Apply", tooltip => "Apply the audio settings", on_activate => sub { @@ -590,45 +588,39 @@ sub make_gauge_window { my $gh = int $HEIGHT * $CFG->{gauge_size}; - my $win = new CFClient::UI::Frame ( + my $win = new CFPlus::UI::Frame ( force_x => 0, force_y => "max", force_w => $WIDTH, force_h => $gh, ); - $win->add (my $hbox = new CFClient::UI::HBox + $win->add (my $hbox = new CFPlus::UI::HBox children => [ - (new CFClient::UI::HBox expand => 1), - (new CFClient::UI::VBox children => [ - (new CFClient::UI::Empty expand => 1), - (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::Table)), + (new CFPlus::UI::HBox expand => 1), + (new CFPlus::UI::VBox children => [ + (new CFPlus::UI::Empty expand => 1), + (new CFPlus::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFPlus::UI::Table)), ]), - (my $vbox = new CFClient::UI::VBox), + (my $vbox = new CFPlus::UI::VBox), ], ); - $vbox->add (new CFClient::UI::HBox + $vbox->add (new CFPlus::UI::HBox expand => 1, children => [ - (new CFClient::UI::Empty expand => 1), - (my $hb = new CFClient::UI::HBox), + (new CFPlus::UI::Empty expand => 1), + (my $hb = new CFPlus::UI::HBox), ], ); - $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', - tooltip => "Health points. Measures of how much damage you can take before dying. Hit points are determined from your level and are influenced by the value of your Con. Hp value may range between 1 to beyond 500 and higher values indicate a greater ability to withstand punishment."); - $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', - tooltip => "Spell points. Measures of how much \"fuel\" you have for casting spells and incantations. Mana is calculated from your level and your Pow. Mana values can range between 1 to beyond 500 (glowing crystals can increase the current spell points beyond your normal maximum). Higher values indicate greater amounts of mana."); - $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', - tooltip => "Grace points - how favored you are by your god. In game terms, how much divine magic you can cast. Your level, Wis and Pow effect what the value of grace is. Prayong on an altar of your god can increase this value beyond your normal maximum. Grace can take on large positive and negative values. Positive values indicate favor by the gods."); - $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', - tooltip => "Food. Ranges between 0 (starving) and 999 (satiated). At a value of 0 the character begins to die. Some magic can speed up or slow down the character digestion. Healing wounds will speed up digestion too."); - - $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, - tooltip => "Experience points and overall level - experience is increased as a reward for appropriate action (such as killing monsters) and may decrease as a result of a magical attack or dying. Level is directly derived from the experience value. As the level of the character increases, the character becomes able to succeed at more difficult tasks. A character's level starts at a value of 0 and may range up beyond 100."); - $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, - tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)"); + $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); + $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); + $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); + $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); + + $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); + $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); $GAUGES = { exp => $exp, win => $win, range => $rng, @@ -641,23 +633,23 @@ } sub debug_setup { - my $table = new CFClient::UI::Table; + my $table = new CFPlus::UI::Table; - $table->add (0, 0, new CFClient::UI::Label text => "Widget Borders"); - $table->add (1, 0, new CFClient::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 1; 0 }); - $table->add (0, 1, new CFClient::UI::Label text => "Tooltip Widget Info"); - $table->add (1, 1, new CFClient::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 }); - $table->add (0, 2, new CFClient::UI::Label text => "Show FPS"); - $table->add (1, 2, new CFClient::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 }); - $table->add (0, 3, new CFClient::UI::Label text => "Suppress Tooltips"); - $table->add (1, 3, new CFClient::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); + $table->add (0, 0, new CFPlus::UI::Label text => "Widget Borders"); + $table->add (1, 0, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 1; 0 }); + $table->add (0, 1, new CFPlus::UI::Label text => "Tooltip Widget Info"); + $table->add (1, 1, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 2; 0 }); + $table->add (0, 2, new CFPlus::UI::Label text => "Show FPS"); + $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 }); + $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips"); + $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05); for my $x (0..2) { for my $y (0 .. 2) { $table->add ($x + 3, $y, - new CFClient::UI::Entry + new CFPlus::UI::Entry text => $default_smooth[$x * 3 + $y], on_changed => sub { $MAP->{smooth_matrix}[$x * 3 + $y] = $_[1] if $MAP; 0 }, ); @@ -669,30 +661,37 @@ } sub stats_window { - my $r = new CFClient::UI::ScrolledWindow ( + my $r = new CFPlus::UI::ScrolledWindow ( expand => 1, scroll_y => 1 ); - $r->add (my $vb = new CFClient::UI::VBox); + $r->add (my $vb = new CFPlus::UI::VBox); + + $vb->add (new CFPlus::UI::FancyFrame + label => "Player", + child => (my $pi = new CFPlus::UI::VBox), + ); - $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1, + $pi->add ($STATWIDS->{title} = new CFPlus::UI::Label valign => 0, align => -1, text => "Title:", expand => 1, can_hover => 1, can_events => 1, tooltip => "Your name and title. You can change your title by using the title command, if supported by the server."); - $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1, + $pi->add ($STATWIDS->{map} = new CFPlus::UI::Label valign => 0, align => -1, text => "Map:", expand => 1, can_hover => 1, can_events => 1, tooltip => "The map you are currently on (if supported by the server)."); - $vb->add (my $hb0 = new CFClient::UI::HBox); - $hb0->add ($STATWIDS->{weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1, + $pi->add (my $hb0 = new CFPlus::UI::HBox); + $hb0->add ($STATWIDS->{weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1, can_hover => 1, can_events => 1, tooltip => "The weight of the player including all inventory items."); - $hb0->add ($STATWIDS->{m_weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1, + $hb0->add ($STATWIDS->{m_weight} = new CFPlus::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1, can_hover => 1, can_events => 1, tooltip => "The weight limit: you cannot carry more than this."); - - $vb->add (my $hb = new CFClient::UI::HBox expand => 1); - $hb->add (my $tbl = new CFClient::UI::Table expand => 1); + $vb->add (new CFPlus::UI::FancyFrame + label => "Primary/Secondary Statistics", + child => (my $hb = new CFPlus::UI::HBox expand => 1), + ); + $hb->add (my $tbl = new CFPlus::UI::Table expand => 1); my $color2 = [1, 1, 0]; @@ -714,15 +713,18 @@ ) { my ($col, $row, $id, $label, $template) = @$_; - $tbl->add ($col , $row, $STATWIDS->{$id} = new CFClient::UI::Label + $tbl->add ($col , $row, $STATWIDS->{$id} = new CFPlus::UI::Label font => $FONT_FIXED, can_hover => 1, can_events => 1, valign => 0, - align => +1, template => $template, tooltip => $CFClient::STAT_TOOLTIP{$label}); - $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFClient::UI::Label + align => +1, template => $template, tooltip => "#stat_$label"); + $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFPlus::UI::Label font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2, valign => 0, - align => -1, text => $label, tooltip => $CFClient::STAT_TOOLTIP{$label}); + align => -1, text => $label, tooltip => "#stat_$label"); } - $vb->add (my $tbl2 = new CFClient::UI::Table expand => 1); + $vb->add (new CFPlus::UI::FancyFrame + label => "Resistancies", + child => (my $tbl2 = new CFPlus::UI::Table expand => 1), + ); my $row = 0; my $col = 0; @@ -771,7 +773,7 @@ { $tbl2->add ($col, $row, $STATWIDS->{"res_$_"} = - new CFClient::UI::Label + new CFPlus::UI::Label font => $FONT_FIXED, template => "-100%", align => +1, @@ -780,14 +782,14 @@ can_hover => 1, tooltip => $resist_names{$_}->[1], ); - $tbl2->add ($col + 1, $row, new CFClient::UI::Image + $tbl2->add ($col + 1, $row, new CFPlus::UI::Image font => $FONT_FIXED, can_hover => 1, can_events => 1, path => "ui/resist/resist_$_.png", tooltip => $resist_names{$_}->[1], ); - $tbl2->add ($col + 2, $row, new CFClient::UI::Label + $tbl2->add ($col + 2, $row, new CFPlus::UI::Label text => $resist_names{$_}->[0], font => $FONT_FIXED, can_hover => 1, @@ -808,8 +810,8 @@ } sub skill_window { - my $sw = new CFClient::UI::ScrolledWindow (expand => 1); - $sw->add ($STATWIDS->{skill_tbl} = new CFClient::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); + my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); + $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); $sw } @@ -830,7 +832,7 @@ my $table = $METASERVER->{table}; $table->clear; - $table->add (0, 0, my $label = new CFClient::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list..."); + $table->add (0, 0, my $label = new CFPlus::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list..."); my $buf; @@ -863,7 +865,7 @@ "Short information about this server provided by its admins.", ); my @col = qw(#Users Host Uptime Version Description); - $table->add ($_, 0, new CFClient::UI::Label + $table->add ($_, 0, new CFPlus::UI::Label can_hover => 1, can_events => 1, align => 0, fg => [1, 1, 0], text => $col[$_], tooltip => $tip[$_]) @@ -894,8 +896,8 @@ $y++; - $table->add (scalar @$m, $y, new CFClient::UI::VBox children => [ - (new CFClient::UI::Button + $table->add (scalar @$m, $y, new CFPlus::UI::VBox children => [ + (new CFPlus::UI::Button text => "Use", tooltip => "Put this server into the Host:Port field", on_activate => sub { @@ -904,10 +906,10 @@ 0 }, ), - (new CFClient::UI::Empty expand => 1), + (new CFPlus::UI::Empty expand => 1), ]); - $table->add ($_, $y, new CFClient::UI::Label + $table->add ($_, $y, new CFPlus::UI::Label ellipsise => 0, align => $align[$_], text => $m->[$_], @@ -922,11 +924,11 @@ } sub metaserver_dialog { - my $vbox = new CFClient::UI::VBox; - my $table = new CFClient::UI::Table; - $vbox->add (new CFClient::UI::ScrolledWindow expand => 1, child => $table); + my $vbox = new CFPlus::UI::VBox; + my $table = new CFPlus::UI::Table; + $vbox->add (new CFPlus::UI::ScrolledWindow expand => 1, child => $table); - my $dialog = new CFClient::UI::FancyFrame + my $dialog = new CFPlus::UI::Toplevel title => "Server List", name => 'metaserver_dialog', x => 'center', @@ -946,16 +948,19 @@ } sub server_setup { - my $vbox = new CFClient::UI::VBox; + my $vbox = new CFPlus::UI::VBox; - $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); - $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); + $vbox->add (new CFPlus::UI::FancyFrame + label => "Connection Settings", + child => (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]), + ); + $table->add (0, 2, new CFPlus::UI::Label valign => 0, align => 1, text => "Host:Port"); { - $table->add (1, 2, my $vbox = new CFClient::UI::VBox); + $table->add (1, 2, my $vbox = new CFPlus::UI::VBox); $vbox->add ( - $HOST_ENTRY = new CFClient::UI::Entry + $HOST_ENTRY = new CFPlus::UI::Entry expand => 1, text => $CFG->{profile}{default}{host}, tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", @@ -966,7 +971,7 @@ } ); - $vbox->add (new CFClient::UI::Button + $vbox->add (new CFPlus::UI::Button expand => 1, text => "Server List", other => $METASERVER, @@ -976,23 +981,23 @@ ); } - $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); - $table->add (1, 4, new CFClient::UI::Entry + $table->add (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); + $table->add (1, 4, new CFPlus::UI::Entry text => $CFG->{profile}{default}{user}, tooltip => "The name of your character on the server", on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } ); - $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); - $table->add (1, 5, new CFClient::UI::Entry + $table->add (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); + $table->add (1, 5, new CFPlus::UI::Entry text => $CFG->{profile}{default}{password}, hidden => 1, tooltip => "The password for your character", on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } ); - $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); - $table->add (1, 7, new CFClient::UI::Slider + $table->add (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); + $table->add (1, 7, new CFPlus::UI::Slider 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. " @@ -1002,8 +1007,8 @@ on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, ); - $table->add (0, 8, new CFClient::UI::Label valign => 0, align => 1, text => "Face Prefetch"); - $table->add (1, 8, new CFClient::UI::CheckBox + $table->add (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch"); + $table->add (1, 8, new CFPlus::UI::CheckBox state => $CFG->{face_prefetch}, tooltip => "Background Image Prefetch\n\n" . "If enabled, the client automatically pre-fetches images from the server. " @@ -1015,21 +1020,21 @@ on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 }, ); - $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Output-Count"); - $table->add (1, 9, new CFClient::UI::Entry + $table->add (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); + $table->add (1, 9, 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 CFClient::UI::Label valign => 0, align => 1, text => "Output-Sync"); - $table->add (1, 10, new CFClient::UI::Entry + $table->add (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); + $table->add (1, 10, 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 CFClient::UI::Button + $table->add (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button expand => 1, align => 0, text => "Login", @@ -1040,8 +1045,8 @@ }, ); - $table->add (0, 12, new CFClient::UI::Label valign => 0, align => 1, text => "Chat Command"); - $table->add (1, 12, my $saycmd = new CFClient::UI::Entry + $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 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. " @@ -1053,20 +1058,16 @@ } ); - $vbox->add (new CFClient::UI::Label - text => "Server Info", - fontsize => 1.2, - padding_y => 8, - fg => [1, 1, 0, 1], + $vbox->add (new CFPlus::UI::FancyFrame + label => "Server Info", + child => ($SERVER_INFO = new CFPlus::UI::Label ellipsise => 0), ); - $vbox->add ($SERVER_INFO = new CFClient::UI::Label ellipsise => 0); - $vbox } sub message_window { - my $window = new CFClient::UI::FancyFrame + my $window = new CFPlus::UI::Toplevel name => "message_window", title => "Messages", border_bg => [1, 1, 1, 1], @@ -1074,12 +1075,12 @@ y => 0, force_w => $::WIDTH * 0.4, force_h => $::HEIGHT * 0.5, - child => (my $vbox = new CFClient::UI::VBox), + child => (my $vbox = new CFPlus::UI::VBox), has_close_button => 1; $vbox->add ($LOGVIEW); - $vbox->add (my $input = new CFClient::UI::Entry + $vbox->add (my $input = new CFPlus::UI::Entry tooltip => "Chat Box. If you enter a text and press return/enter here, the current communication command " . "from the client setup will be prepended (e.g. shout, chat...). " . "If you prepend a slash (/), you will submit a command instead (similar to IRC). " @@ -1128,29 +1129,54 @@ $window } +sub open_string_query { + my ($title, $cb, $txt, $tooltip) = @_; + my $dialog = new CFPlus::UI::Toplevel + x => "center", + y => "center", + z => 50, + force_w => $WIDTH * 4/5, + title => $title; + + $dialog->add ( + my $e = new CFPlus::UI::Entry + on_activate => sub { $cb->(@_); $dialog->hide; 0 }, + on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 }, + tooltip => $tooltip + ); + + $e->grab_focus; + $e->set_text ($txt) if $txt; + $dialog->show; +} + sub open_quit_dialog { unless ($QUIT_DIALOG) { - $QUIT_DIALOG = new CFClient::UI::FancyFrame + $QUIT_DIALOG = new CFPlus::UI::Toplevel x => "center", y => "center", z => 50, title => "Really Quit?", + on_key_down => sub { + my ($dialog, $ev) = @_; + $ev->{sym} == 27 and $dialog->hide; + } ; - $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); + $QUIT_DIALOG->add (my $vb = new CFPlus::UI::VBox expand => 1); - $vb->add (new CFClient::UI::Label + $vb->add (new CFPlus::UI::Label text => "You should find a savebed and apply it first!", max_w => $WIDTH * 0.25, ellipsize => 0, ); - $vb->add (my $hb = new CFClient::UI::HBox expand => 1); - $hb->add (new CFClient::UI::Button + $vb->add (my $hb = new CFPlus::UI::HBox expand => 1); + $hb->add (new CFPlus::UI::Button text => "Ok", expand => 1, on_activate => sub { $QUIT_DIALOG->hide; 0 }, ); - $hb->add (new CFClient::UI::Button + $hb->add (new CFPlus::UI::Button text => "Quit anyway", expand => 1, on_activate => sub { exit }, @@ -1158,10 +1184,11 @@ } $QUIT_DIALOG->show; + $QUIT_DIALOG->grab_focus; } sub autopickup_setup { - my $table = new CFClient::UI::Table; + my $table = new CFPlus::UI::Table; for ( ["General", 0, 0, @@ -1205,14 +1232,14 @@ ) { my ($title, $x, $y, @bits) = @$_; - $table->add ($x, $y, new CFClient::UI::Label text => $title, align => 1, fg => [1, 1, 0]); + $table->add ($x, $y, new CFPlus::UI::Label text => $title, align => 1, fg => [1, 1, 0]); for (@bits) { ++$y; my $mask = $_->[1]; - $table->add ($x , $y, new CFClient::UI::Label text => $_->[0], align => 1, expand => 1); - $table->add ($x+1, $y, my $checkbox = new CFClient::UI::CheckBox + $table->add ($x , $y, new CFPlus::UI::Label text => $_->[0], align => 1, expand => 1); + $table->add ($x+1, $y, my $checkbox = new CFPlus::UI::CheckBox state => $::CFG->{pickup} & $mask, on_changed => sub { my ($box, $value) = @_; @@ -1233,7 +1260,7 @@ } } - $table->add (2, 18, new CFClient::UI::ValSlider + $table->add (2, 18, new CFPlus::UI::ValSlider range => [$::CFG->{pickup} & 0xF, 0, 16, 1, 1], template => ">= 99", to_value => sub { ">= " . 5 * $_[0] }, @@ -1246,7 +1273,7 @@ 1; }); - $table->add (3, 18, new CFClient::UI::Button + $table->add (3, 18, new CFPlus::UI::Button text => "set", on_activate => sub { $::CONN->send_command ("pickup $::CFG->{pickup}") @@ -1257,49 +1284,57 @@ $table } +my %SORT_ORDER = ( + type => undef, + mtime => sub { sort { + ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED) + or $b->{mtime} <=> $a->{mtime} + or $a->{type} <=> $b->{type} + } @_ }, + weight => sub { sort { + $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) + or $a->{type} <=> $b->{type} + } @_ }, +); + sub inventory_widget { - my $hb = new CFClient::UI::HBox homogeneous => 1; + my $hb = new CFPlus::UI::HBox homogeneous => 1; - $hb->add (my $vb1 = new CFClient::UI::VBox); - $vb1->add (new CFClient::UI::Label align => 0, text => "Player"); + $hb->add (my $vb1 = new CFPlus::UI::VBox); + $vb1->add (new CFPlus::UI::Label align => 0, text => "Player"); - $vb1->add (my $hb1 = new CFClient::UI::HBox); + $vb1->add (my $hb1 = new CFPlus::UI::HBox); use sort 'stable'; - $hb1->add (new CFClient::UI::Combobox - value => undef, + $hb1->add (new CFPlus::UI::Selector + value => $::CFG->{inv_sort}, options => [ - [undef, "Type/Name"], - [ - sub { sort { - $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) - or $a->{type} <=> $b->{type} - } @_ }, - "Weight/Type", - ], - [sub { } => "#TODO#"], + [type => "Type/Name"], + [mtime => "Recent/Normal/Locked"], + [weight => "Weight/Type"], ], on_changed => sub { - $INV->set_sort_order ($_[1]); + $::CFG->{inv_sort} = $_[1]; + $INV->set_sort_order ($SORT_ORDER{$_[1]}); }, ); - $hb1->add (new CFClient::UI::Label text => "Weight: ", align => 1, expand => 1); + $hb1->add (new CFPlus::UI::Label text => "Weight: ", align => 1, expand => 1); #TODO# update to weigh/maxweight - $hb1->add ($STATWIDS->{i_weight} = new CFClient::UI::Label align => -1); + $hb1->add ($STATWIDS->{i_weight} = new CFPlus::UI::Label align => -1); - $vb1->add (my $sw1 = new CFClient::UI::ScrolledWindow expand => 1, scroll_y => 1); - $sw1->add ($INV = new CFClient::UI::Inventory); + $vb1->add (my $sw1 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); + $sw1->add ($INV = new CFPlus::UI::Inventory); - $hb->add (my $vb2 = new CFClient::UI::VBox); + $hb->add (my $vb2 = new CFPlus::UI::VBox); - $vb2->add ($INV_RIGHT_HB = new CFClient::UI::HBox); + $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); - $vb2->add (my $sw2 = new CFClient::UI::ScrolledWindow expand => 1, scroll_y => 1); - $sw2->add ($INVR = new CFClient::UI::Inventory); + $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); + $sw2->add ($INVR = new CFPlus::UI::Inventory); # XXX: Call after $INVR = ... because set_opencont sets the items - CFClient::Protocol::set_opencont ($::CONN, 0, "Floor"); + CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); $hb } @@ -1316,7 +1351,7 @@ } sub player_window { - my $plwin = $PL_WINDOW = new CFClient::UI::FancyFrame + my $plwin = $PL_WINDOW = new CFPlus::UI::Toplevel x => "center", y => "center", force_w => $WIDTH * 9/10, @@ -1328,7 +1363,7 @@ my $ntb = $PL_NOTEBOOK = - new CFClient::UI::Notebook expand => 1, debug => 1; + new CFPlus::UI::Notebook expand => 1, debug => 1; $ntb->add ( "Statistics (F2)" => $STATS_PAGE = stats_window, @@ -1339,8 +1374,8 @@ "Shows all your Skills." ); - my $spellsw = new CFClient::UI::ScrolledWindow (expand => 1, scroll_y => 1); - $spellsw->add ($SPELL_PAGE = new CFClient::UI::SpellList); + my $spellsw = new CFPlus::UI::ScrolledWindow (expand => 1, scroll_y => 1); + $spellsw->add ($SPELL_PAGE = new CFPlus::UI::SpellList); $ntb->add ( "Spellbook (F4)" => $spellsw, "Displays all spells you have and lets you edit keyboard shortcuts for them." @@ -1362,7 +1397,7 @@ } sub keyboard_setup { - my $binding_list = new CFClient::UI::VBox; + my $binding_list = new CFPlus::UI::VBox; my $refresh; $refresh = $BIND_UPD_CB = sub { @@ -1374,9 +1409,9 @@ next unless ref $cmds eq 'ARRAY' and @$cmds > 0; my $lbl = join "; ", @$cmds; - my $nam = CFClient::BindingEditor::keycombo_to_name ($mod, $sym); - $binding_list->add (my $hb = new CFClient::UI::HBox); - $hb->add (new CFClient::UI::Button + 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 { @@ -1385,7 +1420,7 @@ 0 }); - $hb->add (new CFClient::UI::Button + $hb->add (new CFPlus::UI::Button text => "edit", tooltip => "Edits the binding", on_activate => sub { @@ -1408,16 +1443,19 @@ 0 }); - $hb->add (new CFClient::UI::Label text => "(Key: $nam)"); - $hb->add (new CFClient::UI::Label text => $lbl, expand => 1); + $hb->add (new CFPlus::UI::Label text => "(Key: $nam)"); + $hb->add (new CFPlus::UI::Label text => $lbl, expand => 1); } } }; - my $vb = new CFClient::UI::VBox; - $vb->add (my $hb = new CFClient::UI::HBox); - $hb->add (new CFClient::UI::Label text => "only shift-up stops fire"); - $hb->add (new CFClient::UI::CheckBox + 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", @@ -1427,10 +1465,12 @@ 0 }); - $vb->add ($binding_list); - $vb->add (my $hb = new CFClient::UI::HBox); + $vb->add (new CFPlus::UI::FancyFrame + label => "Bindings", + child => $binding_list); + $vb->add (my $hb = new CFPlus::UI::HBox); - $hb->add (new CFClient::UI::Button + $hb->add (new CFPlus::UI::Button text => "record new", expand => 1, tooltip => "This button opens the binding editor with an empty binding.", @@ -1454,7 +1494,7 @@ }, ); - $hb->add (new CFClient::UI::Button + $hb->add (new CFPlus::UI::Button text => "close", tooltip => "Closes the binding window", expand => 1, @@ -1469,85 +1509,8 @@ $vb } -# just weirdness, pls. ignore -sub load_html_page { - my ($viewer, $base) = @_; - - $viewer->clear; - - require LWP::Simple; - require HTML::Parser; - require URI; - - my $page = LWP::Simple::get ($base) - or return; - - my @s = { }; - my %passthrough = map ($_ => undef), qw(b i u s tt big small sub sup); - - my $parser = HTML::Parser->new ( - text_h => [sub { - my ($text) = @_; - $text =~ s/\s+/ /g; - $s[-1]{text} .= CFClient::asxml $text; - }, "dtext"], - start_h => [sub { - my ($tag, $attr) = @_; - if ($passthrough{$tag}) { - $s[-1]{text} .= "<$tag>"; - } elsif ($tag eq "h1") { - push @s, { text => "" }; - } elsif ($tag eq "h2") { - push @s, { text => "" }; - } elsif ($tag eq "h3") { - push @s, { text => "" }; - } elsif ($tag eq "a") { - push @s, { text => "", url => $attr->{href} }; - } elsif ($tag eq "p") { - push @s, { }; - } elsif ($tag eq "img") { - eval { - push @{$s[-1]{obj}}, new CFClient::UI::Image - tex => (new_from_image CFClient::Texture LWP::Simple::get (URI->new ($attr->{src}, $base)->abs ($base))); - $s[-1]{text} .= "\x{fffc}"; - }; - } - }, "tagname, attr"], - end_h => [sub { - my ($tag) = @_; - if ($passthrough{$tag}) { - $s[-1]{text} .= ""; - } elsif ($tag =~ /^h\d$/) { - $s[-1]{text} .= ""; - push @s, { }; - } elsif ($tag eq "a") { - my $S = pop @s; - $s[-1]{text} .= "\x{fffc}"; - push @{$s[-1]{obj}}, new CFClient::UI::Label - fg => [0.8, 0.8, 1], - markup => "$S->{text}", - fontsize => 0.8, - can_events => 1, - can_focus => 1, - on_button_up => sub { - load_html_page ($viewer, URI->new ($S->{url}, $base)->abs ($base)); - }, - ; - } - }, "tagname"], - ); - - $parser->parse ($page); - $parser->eof; - - $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent}) - for @s; - - $viewer->set_offset (0); -} - sub help_window { - my $win = new CFClient::UI::FancyFrame + my $win = new CFPlus::UI::Toplevel x => 'center', y => 'center', z => 2, @@ -1557,68 +1520,99 @@ title => "Help Browser", has_close_button => 1; - $win->add (my $vbox = new CFClient::UI::VBox); + $win->add (my $vbox = new CFPlus::UI::VBox); - $vbox->add (my $buttons = new CFClient::UI::HBox); - $vbox->add (my $viewer = new CFClient::UI::TextScroller - expand => 1, fontsize => 0.8, padding_x => 4); - - $buttons->add (new CFClient::UI::Label text => "Choose a document to display: "); - $buttons->add (my $combo = new CFClient::UI::Combobox - value => undef, - options => [ - [intro => "Introduction"], - [manual => "Main Manual"], - [skill_help => "Skill Reference"], - [command_help => "Command Reference"], - [dmcommand_help => "DM Commands"], - [COPYING => "License Terms"], - [test => "test (do not select)"], #d#TODO - ], - on_changed => sub { - my ($self, $pod) = @_; + $vbox->add (new CFPlus::UI::FancyFrame + label => "Navigation", + child => (my $buttons = new CFPlus::UI::HBox), + ); + $vbox->add (my $viewer = new CFPlus::UI::TextScroller + expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4); - if ($pod eq "test") {#d#TODO - eval { - load_html_page $viewer, "http://crossfire.real-time.com/guides/walkthrough/newbie-tower.html"; - }; - warn "$@" if $@; - return; - } + my @history; + my @future; + my $curnode; - my $pom = CFClient::Pod::load CFClient::find_rcfile "pod/$pod.pod", - doc_viewer => 1, sub { CFClient::Pod::as_paragraphs $_[0] }; + my $load_node; $load_node = sub { + my ($node, $para) = @_; - #use Data::Dumper; warn Dumper $pom;#d# + $buttons->clear; - $viewer->clear; + $buttons->add (new CFPlus::UI::Button + text => "⇤", + tooltip => "back to the starting page", + on_activate => sub { + unshift @future, [$curnode, $viewer->current_paragraph] if $curnode; + unshift @future, @history; + @history = (); + $load_node->(@{shift @future}); + }, + ); -# $viewer->add_paragraph ([1, 1, 1, 1], ["Test\n\n \x{fffc} \x{fffc}\n", -# (new CFClient::UI::Image path => "x.png", can_hover => 1, can_events => 1), -# (new CFClient::UI::Label text => "üüüü", can_hover => 1, can_events => 1, tooltip => "??"), -# ]);#d# - - $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent}) - for @$pom; + if (@history) { + $buttons->add (new CFPlus::UI::Button + text => "⋘", + tooltip => "back to " . (CFPlus::asxml CFPlus::Pod::full_path $history[-1][0]) . "", + on_activate => sub { + unshift @future, [$curnode, $viewer->current_paragraph] if $curnode; + $load_node->(@{pop @history}); + }, + ); + } - $viewer->set_offset (0); + if (@future) { + $buttons->add (new CFPlus::UI::Button + text => "⋙", + tooltip => "forward to " . (CFPlus::asxml CFPlus::Pod::full_path $future[0][0]) . "", + on_activate => sub { + push @history, [$curnode, $viewer->current_paragraph]; + $load_node->(@{shift @future}); + }, + ); + } - 0 - }, - on_visibility_change => sub { - my ($self, $visible) = @_; - return unless $visible; - return if $self->{value}; - $self->set_value ("intro"); - 0 - }, - ); + $buttons->add (new CFPlus::UI::Label text => " "); + + my @path = CFPlus::Pod::full_path_of $node; + pop @path; # drop current node + + for my $node (@path) { + $buttons->add (new CFPlus::UI::Button + text => $node->{kw}[0], + tooltip => "go to " . (CFPlus::asxml CFPlus::Pod::full_path $node) . "", + on_activate => sub { + push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); + $load_node->($node); + }, + ); + $buttons->add (new CFPlus::UI::Label text => "/"); + } + + $buttons->add (new CFPlus::UI::Label text => $node->{kw}[0], padding_x => 4, padding_y => 4); + + $curnode = $node; + + $viewer->clear; + $viewer->add_paragraph (CFPlus::Pod::as_paragraphs CFPlus::Pod::section_of $curnode); + $viewer->scroll_to ($para); + }; + + $load_node->(CFPlus::Pod::find pod => "mainpage"); + + $CFPlus::Pod::goto_document = sub { + my (@path) = @_; + + push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = (); + + $load_node->((CFPlus::Pod::find @path)[0]); + $win->show; + }; $win } sub sdl_init { - CFClient::SDL_Init + CFPlus::SDL_Init and die "SDL::Init failed!\n"; } @@ -1633,57 +1627,57 @@ $FULLSCREEN = $CFG->{fullscreen}; $FAST = $CFG->{fast}; - CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN - or die "SDL_SetVideoMode failed: " . (CFClient::SDL_GetError) . "\n"; + CFPlus::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN + or die "SDL_SetVideoMode failed: " . (CFPlus::SDL_GetError) . "\n"; $SDL_ACTIVE = 1; $LAST_REFRESH = time - 0.01; - CFClient::OpenGL::init; + CFPlus::OpenGL::init; $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; - $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# + $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# ############################################################################# if ($DEBUG_STATUS) { - CFClient::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; + CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; } else { # create the widgets - $DEBUG_STATUS = new CFClient::UI::Label + $DEBUG_STATUS = new CFPlus::UI::Label padding => 0, z => 100, force_x => "max", force_y => 0; $DEBUG_STATUS->show; - $BIND_EDITOR = new CFClient::BindingEditor (x => "max", y => 0); + $BIND_EDITOR = new CFPlus::BindingEditor (x => "max", y => 0); - $STATUSBOX = new CFClient::UI::Statusbox; + $STATUSBOX = new CFPlus::UI::Statusbox; $STATUSBOX->add ("Use Alt-Enter to toggle fullscreen mode", timeout => 864000, pri => -100, color => [1, 1, 1, 0.8]); - (new CFClient::UI::Frame + (new CFPlus::UI::Frame bg => [0, 0, 0, 0.4], force_x => 0, force_y => "max", child => $STATUSBOX, )->show; - CFClient::UI::FancyFrame->new ( + CFPlus::UI::Toplevel->new ( title => "Map", name => "mapmap", x => 0, y => $FONTSIZE + 8, border_bg => [1, 1, 1, 192/255], bg => [1, 1, 1, 0], - child => ($MAPMAP = new CFClient::MapWidget::MapMap + child => ($MAPMAP = new CFPlus::MapWidget::MapMap tooltip => "Map. On servers that support this feature, this will display an overview of the surrounding areas.", ), )->show; - $MAPWIDGET = new CFClient::MapWidget; + $MAPWIDGET = new CFPlus::MapWidget; $MAPWIDGET->connect (activate_console => sub { my ($mapwidget, $preset) = @_; @@ -1699,7 +1693,7 @@ $MAPWIDGET->show; $MAPWIDGET->grab_focus; - $LOGVIEW = new CFClient::UI::TextScroller + $LOGVIEW = new CFPlus::UI::TextScroller expand => 1, font => $FONT_FIXED, fontsize => $::CFG->{log_fontsize}, @@ -1709,7 +1703,7 @@ tooltip => "Server Log. This text viewer contains all the messages sent by the server.", ; - $SETUP_DIALOG = new CFClient::UI::FancyFrame + $SETUP_DIALOG = new CFPlus::UI::Toplevel title => "Setup", name => "setup_dialog", x => 'center', @@ -1722,8 +1716,8 @@ $METASERVER = metaserver_dialog; - $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFClient::UI::Notebook expand => 1, debug => 1, - filter => new CFClient::UI::ScrolledWindow expand => 1, scroll_y => 1); + $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new CFPlus::UI::Notebook expand => 1, debug => 1, + filter => new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); $SETUP_NOTEBOOK->add (Server => $SETUP_SERVER = server_setup, "Configure the server to play on, your username, password and other server-related options."); @@ -1743,34 +1737,34 @@ $SETUP_NOTEBOOK->add (Debug => debug_setup, "Some debuggin' options. Do not ask."); - $BUTTONBAR = new CFClient::UI::Buttonbar x => 0, y => 0, z => 200; # put on top + $BUTTONBAR = new CFPlus::UI::Buttonbar x => 0, y => 0, z => 200; # put on top - $BUTTONBAR->add (new CFClient::UI::Flopper text => "Setup", other => $SETUP_DIALOG, + $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Setup", other => $SETUP_DIALOG, tooltip => "Toggles a dialog where you can configure all aspects of this client."); - $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW = message_window, + $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW = 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 - $BUTTONBAR->add (new CFClient::UI::Flopper text => "Playerbook", other => player_window, + $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Playerbook", other => player_window, tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats."); - $BUTTONBAR->add (new CFClient::UI::Button + $BUTTONBAR->add (new CFPlus::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/cfplusrc"; + $::CFG->{layout} = CFPlus::UI::get_layout; + CFPlus::write_cfg "$Crossfire::VARDIR/cfplusrc"; status "Configuration Saved"; 0 }, ); - $BUTTONBAR->add (new CFClient::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, + $BUTTONBAR->add (new CFPlus::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, tooltip => "View Documentation"); - $BUTTONBAR->add (new CFClient::UI::Button + $BUTTONBAR->add (new CFPlus::UI::Button text => "Quit", tooltip => "Terminates the program", on_activate => sub { @@ -1791,7 +1785,7 @@ } sub video_shutdown { - CFClient::OpenGL::shutdown; + CFPlus::OpenGL::shutdown; undef $SDL_ACTIVE; } @@ -1809,7 +1803,7 @@ return unless $CFG->{bgm_enable}; # TODO: hack, do play loop and mood music - $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; + $bgmusic = new_from_file CFPlus::MixMusic CFPlus::find_rcfile "music/$bgmusic[0]"; $bgmusic->play (0); push @bgmusic, shift @bgmusic; @@ -1817,16 +1811,16 @@ sub audio_init { if ($CFG->{audio_enable}) { - if (open my $fh, "<", CFClient::find_rcfile "sounds/config") { - $SDL_MIXER = !CFClient::Mix_OpenAudio; + if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { + $SDL_MIXER = !CFPlus::Mix_OpenAudio; unless ($SDL_MIXER) { status "Unable to open sound device: there will be no sound"; return; } - CFClient::Mix_AllocateChannels 8; - CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; + CFPlus::Mix_AllocateChannels 8; + CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128; audio_music_finished; @@ -1839,7 +1833,7 @@ push @SOUNDS, "$volume,$file"; $AUDIO_CHUNKS{"$volume,$file"} ||= do { - my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; + my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file"; $chunk->volume ($volume * 128 / 100); $chunk }; @@ -1851,7 +1845,7 @@ } sub audio_shutdown { - CFClient::Mix_CloseAudio if $SDL_MIXER; + CFPlus::Mix_CloseAudio if $SDL_MIXER; undef $SDL_MIXER; @SOUNDS = (); %AUDIO_CHUNKS = (); @@ -1868,20 +1862,20 @@ $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; - $CFClient::UI::ROOT->draw; + $CFPlus::UI::ROOT->draw; $WANT_REFRESH = 0; $CAN_REFRESH = 0; $LAST_REFRESH = $NOW; - CFClient::SDL_GL_SwapBuffers; + CFPlus::SDL_GL_SwapBuffers; } my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { $NOW = time; ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) - for CFClient::SDL_PollEvent; + for CFPlus::SDL_PollEvent; if (%animate_object) { $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; @@ -1915,32 +1909,32 @@ }); %SDL_CB = ( - CFClient::SDL_QUIT => sub { + CFPlus::SDL_QUIT => sub { Event::unloop -1; }, - CFClient::SDL_VIDEORESIZE => sub { + CFPlus::SDL_VIDEORESIZE => sub { }, - CFClient::SDL_VIDEOEXPOSE => sub { - CFClient::UI::full_refresh; + CFPlus::SDL_VIDEOEXPOSE => sub { + CFPlus::UI::full_refresh; }, - CFClient::SDL_ACTIVEEVENT => sub { + CFPlus::SDL_ACTIVEEVENT => sub { # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# }, - CFClient::SDL_KEYDOWN => sub { - if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { + CFPlus::SDL_KEYDOWN => sub { + if ($_[0]{mod} & CFPlus::KMOD_ALT && $_[0]{sym} == 13) { # alt-enter $FULLSCREEN_ENABLE->toggle; video_shutdown; video_init; } else { - CFClient::UI::feed_sdl_key_down_event ($_[0]); + CFPlus::UI::feed_sdl_key_down_event ($_[0]); } }, - CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, - CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, - CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, - CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, - CFClient::SDL_USEREVENT => sub { + CFPlus::SDL_KEYUP => \&CFPlus::UI::feed_sdl_key_up_event, + CFPlus::SDL_MOUSEMOTION => \&CFPlus::UI::feed_sdl_motion_event, + CFPlus::SDL_MOUSEBUTTONDOWN => \&CFPlus::UI::feed_sdl_button_down_event, + CFPlus::SDL_MOUSEBUTTONUP => \&CFPlus::UI::feed_sdl_button_up_event, + CFPlus::SDL_USEREVENT => sub { if ($_[0]{code} == 1) { audio_channel_finished $_[0]{data1}; } elsif ($_[0]{code} == 0) { @@ -1954,14 +1948,8 @@ $SIG{INT} = $SIG{TERM} = sub { exit }; { - local $SIG{__DIE__} = sub { - return unless defined $^S && !$^S; - Carp::confess $_[0];#d#TODO: remove when stable - CFClient::fatal $_[0]; - }; - - CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc"; - CFClient::UI::set_layout ($::CFG->{layout}); + CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc"; + CFPlus::UI::set_layout ($::CFG->{layout}); my %DEF_CFG = ( sdl_mode => 0, @@ -1987,6 +1975,7 @@ output_sync => 1, output_count => 1, pickup => 0, + inv_sort => "mtime", default => "profile", # default profile ); @@ -2000,14 +1989,14 @@ @SDL_MODES = reverse grep $_->[0] >= 640 && $_->[1] >= 480, - CFClient::SDL_ListModes; + CFPlus::SDL_ListModes; - @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; + @SDL_MODES or CFPlus::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; { - my @fonts = map CFClient::find_rcfile "fonts/$_", qw( + my @fonts = map CFPlus::find_rcfile "fonts/$_", qw( DejaVuSans.ttf DejaVuSansMono.ttf DejaVuSans-Bold.ttf @@ -2018,12 +2007,12 @@ DejaVuSansMono-BoldOblique.ttf ); - CFClient::add_font $_ for @fonts; + CFPlus::add_font $_ for @fonts; - CFClient::pango_init; + CFPlus::pango_init; - $FONT_PROP = new_from_file CFClient::Font $fonts[0]; - $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; + $FONT_PROP = new_from_file CFPlus::Font $fonts[0]; + $FONT_FIXED = new_from_file CFPlus::Font $fonts[1]; $FONT_PROP->make_default; } @@ -2033,7 +2022,7 @@ # for my $rgba (0..1) { # my $t1 = Time::HiRes::time; # for (1..1000) { -# my $layout = CFClient::Layout->new ($rgba); +# my $layout = CFPlus::Layout->new ($rgba); # $layout->set_text ("hallo" x 100); # $layout->render; # } @@ -2046,10 +2035,10 @@ } Event::loop; -#CFClient::SDL_Quit; -#CFClient::_exit 0; +#CFPlus::SDL_Quit; +#CFPlus::_exit 0; -END { CFClient::SDL_Quit } +END { CFPlus::SDL_Quit } =head1 NAME