--- deliantra/Deliantra-Client/bin/pclient 2006/05/08 15:12:39 1.199
+++ deliantra/Deliantra-Client/bin/pclient 2006/05/15 00:15:08 1.215
@@ -39,6 +39,7 @@
use CFClient::MapWidget;
$Event::DIED = sub {
+ # TODO: display dialog box or so
CFClient::error $_[1];
};
@@ -62,6 +63,9 @@
our $CONN;
our $FAST; # fast, low-quality mode, possibly useful for software-rendering
+our $WANT_REFRESH;
+our $CAN_REFRESH;
+
our @SDL_MODES;
our $WIDTH;
our $HEIGHT;
@@ -92,31 +96,28 @@
our %AUDIO_CHUNKS; # audio files
our $ALT_ENTER_MESSAGE;
-our $STATUS_LINE;
+our $STATUSBOX;
our $DEBUG_STATUS;
our $INVWIN;
our $INV;
sub status {
- $STATUS_LINE->set_text ($_[0]);
- $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
+ $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]);
}
sub debug {
$DEBUG_STATUS->set_text ($_[0]);
- $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
+ my ($w, $h) = $DEBUG_STATUS->size_request;
+ $DEBUG_STATUS->move ($WIDTH - $w, 0);
}
sub start_game {
- $LOGIN_BUTTON->set_text ("Logout");
-
status "logging in...";
my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
$MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
-
$MAP = new CFClient::Map $mapsize, $mapsize;
my ($host, $port) = split /:/, $CFG->{host};
@@ -133,6 +134,8 @@
};
if ($CONN) {
+ $LOGIN_BUTTON->set_text ("Logout");
+
status "login successful";
CFClient::lowdelay fileno $CONN->{fh};
@@ -143,9 +146,15 @@
}
sub stop_game {
+ return unless $CONN;
+
status "connection closed";
$LOGIN_BUTTON->set_text ("Login");
- undef $CONN;
+ $CONN->destroy;
+ $CONN = 0; # false, does not autovivify
+
+ undef $MAPCACHE;
+ undef $MAP;
}
sub client_setup {
@@ -362,16 +371,21 @@
}
sub make_gauge_window {
- my $gh = int ($HEIGHT * $CFG->{gauge_size});
-# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
+ my $gh = int $HEIGHT * $CFG->{gauge_size};
my $win = new CFClient::UI::Frame (
- y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh
+ req_y => -1,
+ user_w => $WIDTH,
+ user_h => $gh,
);
+
$win->add (my $hbox = new CFClient::UI::HBox
children => [
(new CFClient::UI::HBox expand => 1),
- ($FLOORBOX = new CFClient::UI::VBox),
+ (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::VBox)),
+ ]),
(my $vbox = new CFClient::UI::VBox),
],
);
@@ -691,9 +705,9 @@
$vbox->add (new CFClient::UI::Flopper
expand => 1,
- text => "Metaserver",
+ text => "Server List",
other => $METASERVER,
- tooltip => "Show a list of avaible crossfire servers",
+ tooltip => "Show a list of available crossfire servers",
connect_open => sub {
update_metaserver $HOST;
}
@@ -825,77 +839,84 @@
or die "SDL_SetVideoMode failed!\n";
$SDL_ACTIVE = 1;
-
$LAST_REFRESH = time - 0.01;
CFClient::gl_init;
$FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
+ $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
+
#############################################################################
- $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
- $DEBUG_STATUS->show;
-
- $STATUS_LINE = new CFClient::UI::Label
- padding => 0,
- y => $HEIGHT - $FONTSIZE * 1.8;
- $STATUS_LINE->show;
-
- $ALT_ENTER_MESSAGE = new CFClient::UI::Label
- padding => 0,
- fontsize => 0.8,
- markup => "Use Alt-Enter to toggle fullscreen mode";
- $ALT_ENTER_MESSAGE->show;
- $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
-
- CFClient::UI::FancyFrame->new (
- border_bg => [1, 1, 1, 192/255],
- bg => [1, 1, 1, 0],
- child => ($MAPMAP = new CFClient::MapWidget::MapMap),
- )->show;
-
- $MAPWIDGET = new CFClient::MapWidget;
- $MAPWIDGET->connect (activate_console => sub {
- my ($mapwidget, $preset) = @_;
-
- if ($CONSOLE) {
- $CONSOLE->{input}->{auto_activated} = 1;
- $CONSOLE->{input}->focus_in;
+ unless ($DEBUG_STATUS) {
+ # create the widgets
- if ($preset && $CONSOLE->{input}->get_text eq '') {
- $CONSOLE->{input}->set_text ($preset);
+ $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1;
+ $DEBUG_STATUS->show;
+
+ $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,
+ child => $STATUSBOX,
+ )->show;
+
+ CFClient::UI::FancyFrame->new (
+ border_bg => [1, 1, 1, 192/255],
+ bg => [1, 1, 1, 0],
+ child => ($MAPMAP = new CFClient::MapWidget::MapMap),
+ )->show;
+
+ $MAPWIDGET = new CFClient::MapWidget;
+ $MAPWIDGET->connect (activate_console => sub {
+ my ($mapwidget, $preset) = @_;
+
+ if ($CONSOLE) {
+ $CONSOLE->{input}->{auto_activated} = 1;
+ $CONSOLE->{input}->focus_in;
+
+ if ($preset && $CONSOLE->{input}->get_text eq '') {
+ $CONSOLE->{input}->set_text ($preset);
+ }
}
- }
- });
- $MAPWIDGET->show;
- $MAPWIDGET->focus_in;
+ });
+ $MAPWIDGET->show;
+ $MAPWIDGET->focus_in;
- $BUTTONBAR = new CFClient::UI::HBox;
+ $BUTTONBAR = new CFClient::UI::HBox;
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
- 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
+ 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 => "Stats Window", other => make_stats_window);
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
- $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
- CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
- status "Configuration Saved";
- });
+ $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
+ CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
+ status "Configuration Saved";
+ });
+
+ $BUTTONBAR->show;
- $BUTTONBAR->show;
+ $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
- $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
+ # delay till geometry is constant
+ $CFClient::UI::ROOT->on_post_alloc (startup => sub {
+ $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
+ my $widget = $GAUGES->{win};
+ $widget->move (0, $HEIGHT - $widget->{h});#d# to in toplevel
+ });
+ force_refresh ();
+ }
}
sub video_shutdown {
- $CFClient::UI::ROOT->{children} = [];
- undef $CFClient::UI::GRAB;
- undef $CFClient::UI::HOVER;
undef $SDL_ACTIVE;
}
@@ -957,22 +978,17 @@
my %animate_object;
my $animate_timer;
-my $want_refresh;
-my $can_refresh;
-
my $fps = 9;
sub force_refresh {
- $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
+ $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
debug sprintf "%3.2f", $fps;
- $want_refresh = 0;
- $can_refresh = 0;
-
$CFClient::UI::ROOT->draw;
-
CFClient::SDL_GL_SwapBuffers;
+ $WANT_REFRESH = 0;
+ $CAN_REFRESH = 0;
$LAST_REFRESH = $NOW;
}
@@ -984,20 +1000,16 @@
if (%animate_object) {
$_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
- $want_refresh++;
+ $WANT_REFRESH++;
}
- if ($want_refresh) {
+ if ($WANT_REFRESH) {
force_refresh;
} else {
- $can_refresh = 1;
+ $CAN_REFRESH = 1;
}
});
-sub refresh {
- $want_refresh++;
-}
-
sub animation_start {
my ($widget) = @_;
$animate_object{$widget} = $widget;
@@ -1318,7 +1330,27 @@
[0.74, 0.65, 0.41],
);
- $LOGVIEW->add_paragraph ($color[$color], $text);
+ my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
+
+ $text =~ s/&/&/g; $text =~ s/</g;
+ $text =~ s/\[b\](.*?)\[\/b\]/\1<\/b>/g;
+ $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/\2<\/span>/g;
+
+ $LOGVIEW->add_paragraph ($color[$color],
+ join "\n", map "$time $_", split /\n/, $text);
+
+ $STATUSBOX->add ($text,
+ group => $text,
+ fg => $color[$color],
+ timeout => 60,
+ tooltip_font => $::FONT_FIXED,
+ );
+}
+
+sub conn::drawextinfo {
+ my ($self, $color, $type, $subtype, $message) = @_;
+
+ $self->drawinfo ($color, $message);
}
sub conn::spell_add {
@@ -1341,39 +1373,57 @@
$MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
$MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
}
+
+ $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
+ $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
+ $MAPWIDGET->add_command ("pet\\_mode sad", "Search & Destroy - tell pets to roam about and attack enemies");
+ $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
+}
+
+sub conn::eof {
+ stop_game;
}
sub update_floorbox {
$CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
+ return unless $CONN;
+
$FLOORBOX->clear;
$FLOORBOX->add (new CFClient::UI::Empty expand => 1);
- # we basically have to use the same sorting as everybody else
- for my $item (@{ $CONN->{container}{0} }) {
- $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item);
+ my $count = 4;
+ for (@{ $CONN->{container}{0} }) {
+ if (--$count) {
+ $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
+ } else {
+ $FLOORBOX->add (new CFClient::UI::Label text => "More...");
+ last;
+ }
}
});
- refresh;
+
+ $WANT_REFRESH++;
}
sub conn::container_add {
- my ($self, $id, $items) = @_;
+ my ($self, $tag, $items) = @_;
+
+ update_floorbox if $tag == 0;
+
+ $INV->set_items ($self->{container}{$self->{player}{tag}})
+ if $tag == $self->{player}{tag};
- update_floorbox if $id == 0;
- if ($self->{player}{tag} == $id) {
- $INV->set_items ($self->{container}{$self->{player}{tag}});
- }
# $self-<{player}{tag} => player inv
#use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
}
sub conn::container_clear {
- my ($self, $id) = @_;
+ my ($self, $tag) = @_;
- update_floorbox if $id == 0;
- if ($self->{player}{tag} == $id) {
- $INV->set_items ($self->{container}{$id});
- }
+ update_floorbox if $tag == 0;
+
+ $INV->set_items ($self->{container}{$tag})
+ if $tag == $self->{player}{tag};
# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
}
@@ -1383,9 +1433,9 @@
for (@items) {
update_floorbox if $_->{container} == 0;
- if ($self->{player}{tag} == $_->{container}) {
- $INV->set_items ($self->{container}{$_->{container}});
- }
+
+ $INV->set_items ($self->{container}{$_->{container}})
+ if $_->{container} == $self->{player}{tag};
}
}
@@ -1393,9 +1443,9 @@
my ($self, $item) = @_;
update_floorbox if $item->{container} == 0;
- if ($self->{player}{tag} == $item->{container}) {
- $INV->set_items ($self->{container}{$item->{container}});
- }
+
+ $INV->set_items ($self->{container}{$item->{container}})
+ if $item->{container} == $self->{player}{tag};
}
%SDL_CB = (
@@ -1404,7 +1454,9 @@
},
CFClient::SDL_VIDEORESIZE => sub {
},
- CFClient::SDL_VIDEOEXPOSE => \&refresh,
+ CFClient::SDL_VIDEOEXPOSE => sub {
+ $WANT_REFRESH++;
+ },
CFClient::SDL_ACTIVEEVENT => sub {
# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
},
@@ -1435,70 +1487,76 @@
$SIG{INT} = $SIG{TERM} = sub { exit };
-CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
+{
+ local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
+
+ CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
-$TILECACHE = CFClient::db_table "tilecache";
-$FACEMAP = CFClient::db_table "facemap";
+ $TILECACHE = CFClient::db_table "tilecache";
+ $FACEMAP = CFClient::db_table "facemap";
-my %DEF_CFG = (
- sdl_mode => 0,
- width => 640,
- height => 480,
- fullscreen => 0,
- fast => 0,
- map_scale => 0.5,
- fow_enable => 1,
- fow_intensity => 0.45,
- fow_smooth => 0,
- gui_fontsize => 1,
- log_fontsize => 1,
- gauge_fontsize => 1,
- gauge_size => 0.35,
- stat_fontsize => 1,
- mapsize => 100,
- host => "crossfire.schmorp.de",
- say_command => 'say',
- audio_enable => 1,
- bgm_enable => 1,
- bgm_volume => 0.25,
-);
+ my %DEF_CFG = (
+ sdl_mode => 0,
+ width => 640,
+ height => 480,
+ fullscreen => 0,
+ fast => 0,
+ map_scale => 0.5,
+ fow_enable => 1,
+ fow_intensity => 0.45,
+ fow_smooth => 0,
+ gui_fontsize => 1,
+ log_fontsize => 1,
+ gauge_fontsize=> 1,
+ gauge_size => 0.35,
+ stat_fontsize => 1,
+ mapsize => 100,
+ host => "crossfire.schmorp.de",
+ say_command => 'say',
+ audio_enable => 1,
+ bgm_enable => 1,
+ bgm_volume => 0.25,
+ );
-while (my ($k, $v) = each %DEF_CFG) {
- $CFG->{$k} = $v unless exists $CFG->{$k};
-}
+ while (my ($k, $v) = each %DEF_CFG) {
+ $CFG->{$k} = $v unless exists $CFG->{$k};
+ }
-sdl_init;
+ sdl_init;
-@SDL_MODES = reverse
- grep $_->[0] >= 640 && $_->[1] >= 480,
- CFClient::SDL_ListModes;
+ @SDL_MODES = reverse
+ grep $_->[0] >= 640 && $_->[1] >= 480,
+ CFClient::SDL_ListModes;
-@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
+ @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
-$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
+ $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
-{
- my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
- DejaVuSans.ttf
- DejaVuSansMono.ttf
- DejaVuSans-Bold.ttf
- DejaVuSansMono-Bold.ttf
- DejaVuSans-Oblique.ttf
- DejaVuSansMono-Oblique.ttf
- DejaVuSans-BoldOblique.ttf
- DejaVuSansMono-BoldOblique.ttf
- );
+ {
+ my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
+ DejaVuSans.ttf
+ DejaVuSansMono.ttf
+ DejaVuSans-Bold.ttf
+ DejaVuSansMono-Bold.ttf
+ DejaVuSans-Oblique.ttf
+ DejaVuSansMono-Oblique.ttf
+ DejaVuSans-BoldOblique.ttf
+ DejaVuSansMono-BoldOblique.ttf
+ );
- CFClient::add_font $_ for @fonts;
-
- $FONT_PROP = new_from_file CFClient::Font $fonts[0];
- $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
+ CFClient::add_font $_ for @fonts;
+
+ CFClient::pango_init;
- $FONT_PROP->make_default;
-}
+ $FONT_PROP = new_from_file CFClient::Font $fonts[0];
+ $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
-video_init;
-audio_init;
+ $FONT_PROP->make_default;
+ }
+
+ video_init;
+ audio_init;
+}
Event::loop;